get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/1.2/patches/2226157/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2226157,
    "url": "http://patchwork.ozlabs.org/api/1.2/patches/2226157/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260422101043.1234229-25-alex.bennee@linaro.org/",
    "project": {
        "id": 14,
        "url": "http://patchwork.ozlabs.org/api/1.2/projects/14/?format=api",
        "name": "QEMU Development",
        "link_name": "qemu-devel",
        "list_id": "qemu-devel.nongnu.org",
        "list_email": "qemu-devel@nongnu.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": "",
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20260422101043.1234229-25-alex.bennee@linaro.org>",
    "list_archive_url": null,
    "date": "2026-04-22T10:10:35",
    "name": "[v2,24/31] target/arm: teach arm_cpu_has_work about halting reasons",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "84320027a0944765f757e7a3e5cac1a33b7c923f",
    "submitter": {
        "id": 39532,
        "url": "http://patchwork.ozlabs.org/api/1.2/people/39532/?format=api",
        "name": "Alex Bennée",
        "email": "alex.bennee@linaro.org"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260422101043.1234229-25-alex.bennee@linaro.org/mbox/",
    "series": [
        {
            "id": 500957,
            "url": "http://patchwork.ozlabs.org/api/1.2/series/500957/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=500957",
            "date": "2026-04-22T10:10:11",
            "name": "target/arm: fully model WFxT instructions for A-profile",
            "version": 2,
            "mbox": "http://patchwork.ozlabs.org/series/500957/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2226157/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2226157/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>",
        "X-Original-To": "incoming@patchwork.ozlabs.org",
        "Delivered-To": "patchwork-incoming@legolas.ozlabs.org",
        "Authentication-Results": [
            "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256\n header.s=google header.b=ACbfygdz;\n\tdkim-atps=neutral",
            "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"
        ],
        "Received": [
            "from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g0wD81KJlz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 20:18:32 +1000 (AEST)",
            "from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wFUeR-00071u-Tw; Wed, 22 Apr 2026 06:17:49 -0400",
            "from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <alex.bennee@linaro.org>)\n id 1wFUeG-0006yK-1h\n for qemu-devel@nongnu.org; Wed, 22 Apr 2026 06:17:37 -0400",
            "from mail-wr1-x441.google.com ([2a00:1450:4864:20::441])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <alex.bennee@linaro.org>)\n id 1wFUe9-0002MQ-S7\n for qemu-devel@nongnu.org; Wed, 22 Apr 2026 06:17:35 -0400",
            "by mail-wr1-x441.google.com with SMTP id\n ffacd0b85a97d-43d70b3e159so2645138f8f.0\n for <qemu-devel@nongnu.org>; Wed, 22 Apr 2026 03:17:26 -0700 (PDT)",
            "from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id\n ffacd0b85a97d-43fe4e4d5b1sm48555959f8f.30.2026.04.22.03.17.23\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 22 Apr 2026 03:17:24 -0700 (PDT)",
            "from draig.lan (localhost [IPv6:::1])\n by draig.lan (Postfix) with ESMTP id 5F2015F93F;\n Wed, 22 Apr 2026 11:10:45 +0100 (BST)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=linaro.org; s=google; t=1776853045; x=1777457845; darn=nongnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=4/Ygp/F48dZ3RysrI6Uw/aAqnHQSpp+gk0lyGlg/T44=;\n b=ACbfygdzoYAjqpE/jecAyXS9uYlWDglC7XV3BgEsf5PQsDpr3AZP5N4208DE+W8x+X\n S4KFMiLfDaBhvA+qjJDkxCIIXi6M2VSlubRUBlov+A3L0l6dM6ssUn7/Y4tpnOhl+QAw\n kg6rwYYNIxuVC+HlB9jj1rjQl4p4bUTgijvhrFC5kYkdVDjJ0piqz+qq15FTFOZgm2MK\n f5Sx4essvPXayq4CnsKr1Ah4lAEMrc01T0/lbbdfuwVhQGu0A+4zp54Spc9ZfpU83xRu\n 2yYefelpuxb8jDFB7kP1OaQdYOhdmvwut7XGW/AKKI6+heou6C0cwOAeJklLhNJ503xO\n 6JCQ==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776853045; x=1777457845;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=4/Ygp/F48dZ3RysrI6Uw/aAqnHQSpp+gk0lyGlg/T44=;\n b=BCPuyjdob6MVPUl5IXedFuy6GU2wwSop2zkda1eF4Pm9BYEXg5y5hYBnn0SSqUeVbA\n zHfoWEH2ksfarNtNhuVJmqyp4jh7gk0Vmzr4YfQMIxDsM2HqS6hRli3QbwFi/0jb9Qwj\n nAaLILs0bTNZlcNzpeWhMkdKNOIeZUW9ZQgaP/BF22+Gd4IPkV7EUIYNYMZB4/wqLkPn\n 3Y+cfobmQqk1Y+SIJcayXuoG/KxxRQRD/41AIMXMNMLhLnIniv92/JqvX+agaAPG5YqS\n LsnsS/4Bd8xjjjPRk/6E5iYrjf+NXRgLCg2m4nIndV4ofzlsdwdjML7Fr6etnOel2Az3\n sI8Q==",
        "X-Gm-Message-State": "AOJu0YwRVKQlp5dDtpEpZtoH3/n74YswuFdIG8dG0WFJl3sScDDMRR4p\n Wq8YI9DNU+FVTwq5xEkVryu4x5pZMcnngKm41HB1kiGIFI+XRepahsTNMrc/sQiTSNw=",
        "X-Gm-Gg": "AeBDievZnyyZeeer9ADkfNNWn842ZDP8rP21Au3GfukQ570pxQYGNeTrsxx4xkzi2Ch\n 3lYe39nYTXKov9jgyMzWHQFH6xTr/9mbWJGVSFroWhASi7rbXKdl5/i2P4+xwAGzTnPaOojnJZP\n B1sO0QNwsJAAtPWg5aqljMNMwHexlX4KyBISOz2qeWaWR5aCtTSJY3GmPQofRT5vu7ydqYo0H6r\n tBaZjzfxB/keSu0gtsFiYNRmD4AlQOBTQmaDIFbMf28GokKMl5KOKEuoOD75VGk3C1UyOb5ad4h\n rxjmaqlXnoXxunCLwgjxUR7YTrrbqDRCRB5Pu8tUmPUabxkXlO2uiO2bpm49YIY+HJJWFXWeYSP\n lm2s1G+I1iBmfqlzZElvkvnKf0kcgq9vAyPI4p5JF0BASj9vHdAl5QiauSBaNF42MBjoSaW34j2\n bfzgOpNI633FAdPSlLKg80wkut34lpq/EY0w==",
        "X-Received": "by 2002:a5d:5889:0:b0:43d:7a97:78b5 with SMTP id\n ffacd0b85a97d-43fe3e0a448mr32111190f8f.33.1776853044898;\n Wed, 22 Apr 2026 03:17:24 -0700 (PDT)",
        "From": "=?utf-8?q?Alex_Benn=C3=A9e?= <alex.bennee@linaro.org>",
        "To": "qemu-devel@nongnu.org",
        "Cc": "Alexander Graf <agraf@csgraf.de>, qemu-arm@nongnu.org,\n Peter Maydell <peter.maydell@linaro.org>,\n Paolo Bonzini <pbonzini@redhat.com>,\n Mohamed Mediouni <mohamed@unpredictable.fr>, kvm@vger.kernel.org,\n Pedro Barbuda <pbarbuda@microsoft.com>,\n =?utf-8?q?Alex_Benn=C3=A9e?= <alex.bennee@linaro.org>",
        "Subject": "[PATCH v2 24/31] target/arm: teach arm_cpu_has_work about halting\n reasons",
        "Date": "Wed, 22 Apr 2026 11:10:35 +0100",
        "Message-ID": "<20260422101043.1234229-25-alex.bennee@linaro.org>",
        "X-Mailer": "git-send-email 2.47.3",
        "In-Reply-To": "<20260422101043.1234229-1-alex.bennee@linaro.org>",
        "References": "<20260422101043.1234229-1-alex.bennee@linaro.org>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "Received-SPF": "pass client-ip=2a00:1450:4864:20::441;\n envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x441.google.com",
        "X-Spam_score_int": "-20",
        "X-Spam_score": "-2.1",
        "X-Spam_bar": "--",
        "X-Spam_report": "(-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,\n SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no",
        "X-Spam_action": "no action",
        "X-BeenThere": "qemu-devel@nongnu.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "qemu development <qemu-devel.nongnu.org>",
        "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.nongnu.org/archive/html/qemu-devel>",
        "List-Post": "<mailto:qemu-devel@nongnu.org>",
        "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>",
        "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>",
        "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org",
        "Sender": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"
    },
    "content": "With the advent of WFE and WFI we need to pay closer attention to the\nreason why the vCPU may be sleeping to figure out if we should wake\nit up.\n\nCreate env->halt_reason to track this and then re-order the tests so\nwe:\n\n  - ignore everything is the vCPU is powered off\n  - wake up if the event_register is set and we were in a WFE\n  - otherwise any IRQ event does wake the vCPU up.\n\nSigned-off-by: Alex Bennée <alex.bennee@linaro.org>\n---\n target/arm/cpu.h           | 27 +++++++++++++++++++++++++\n target/arm/arm-powerctl.c  |  4 +++-\n target/arm/cpu.c           | 40 +++++++++++++++++++++++++++-----------\n target/arm/kvm.c           |  5 +++--\n target/arm/machine.c       |  2 +-\n target/arm/tcg/op_helper.c |  3 +++\n 6 files changed, 66 insertions(+), 15 deletions(-)",
    "diff": "diff --git a/target/arm/cpu.h b/target/arm/cpu.h\nindex 657ff4ab20b..98cdfa6f130 100644\n--- a/target/arm/cpu.h\n+++ b/target/arm/cpu.h\n@@ -257,6 +257,19 @@ typedef enum ARMFPStatusFlavour {\n } ARMFPStatusFlavour;\n #define FPST_COUNT  10\n \n+/**\n+ * ARMHaltReason - the reason we have entered halt state\n+ *\n+ * To be able to correctly wake up via arm_cpu_has_work() we need to\n+ * track the reason we went to sleep.\n+ */\n+typedef enum {\n+    NOT_HALTED = 0,\n+    HALT_PSCI,\n+    HALT_WFI,\n+    HALT_WFE\n+} ARMHaltReason;\n+\n typedef struct CPUArchState {\n     /* Regs for current mode.  */\n     uint32_t regs[16];\n@@ -760,6 +773,9 @@ typedef struct CPUArchState {\n     /* Optional fault info across tlb lookup. */\n     ARMMMUFaultInfo *tlb_fi;\n \n+    /* Reason the CPU is halted */\n+    ARMHaltReason halt_reason;\n+\n     /*\n      * The event register is shared by all ARM profiles (A/R/M),\n      * so it is stored in the top-level CPU state.\n@@ -1691,6 +1707,17 @@ static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)\n #endif\n }\n \n+/**\n+ * arm_set_cpu_power_state() - set power state synced with halt_reason\n+ */\n+static inline void arm_set_cpu_power_state(ARMCPU *cpu, ARMPSCIState state)\n+{\n+    CPUARMState *env = &cpu->env;\n+\n+    cpu->power_state = state;\n+    env->halt_reason = (state == PSCI_OFF) ? HALT_PSCI : NOT_HALTED;\n+}\n+\n #define HCR_VM        (1ULL << 0)\n #define HCR_SWIO      (1ULL << 1)\n #define HCR_PTW       (1ULL << 2)\ndiff --git a/target/arm/arm-powerctl.c b/target/arm/arm-powerctl.c\nindex a788376d1d3..4ca63a54443 100644\n--- a/target/arm/arm-powerctl.c\n+++ b/target/arm/arm-powerctl.c\n@@ -78,6 +78,7 @@ static void arm_set_cpu_on_async_work(CPUState *target_cpu_state,\n \n     /* Finally set the power status */\n     assert(bql_locked());\n+    target_cpu->env.halt_reason = NOT_HALTED;\n     target_cpu->power_state = PSCI_ON;\n }\n \n@@ -186,6 +187,7 @@ static void arm_set_cpu_on_and_reset_async_work(CPUState *target_cpu_state,\n \n     /* Finally set the power status */\n     assert(bql_locked());\n+    target_cpu->env.halt_reason = NOT_HALTED;\n     target_cpu->power_state = PSCI_ON;\n }\n \n@@ -239,7 +241,7 @@ static void arm_set_cpu_off_async_work(CPUState *target_cpu_state,\n     ARMCPU *target_cpu = ARM_CPU(target_cpu_state);\n \n     assert(bql_locked());\n-    target_cpu->power_state = PSCI_OFF;\n+    arm_set_cpu_power_state(target_cpu, PSCI_OFF);\n     target_cpu_state->halted = 1;\n     target_cpu_state->exception_index = EXCP_HLT;\n }\ndiff --git a/target/arm/cpu.c b/target/arm/cpu.c\nindex ccc47c8a9ad..124be8c401e 100644\n--- a/target/arm/cpu.c\n+++ b/target/arm/cpu.c\n@@ -144,18 +144,36 @@ static bool arm_cpu_has_work(CPUState *cs)\n {\n     ARMCPU *cpu = ARM_CPU(cs);\n \n-    if (arm_feature(&cpu->env, ARM_FEATURE_M)) {\n-        if (cpu->env.event_register) {\n-            return true;\n-        }\n+    /*\n+     * Only another PSCI call can wake the CPU up in which case the\n+     * power_state would be set by arm_set_cpu_on_and_reset_async_work()\n+     */\n+    if (cpu->power_state == PSCI_OFF) {\n+        g_assert(cpu->env.halt_reason == HALT_PSCI);\n+        return false;\n+    }\n+\n+    /*\n+     * A wake-up event should only wake us if we are halted on a WFE\n+     */\n+    if (cpu->env.halt_reason == HALT_WFE && cpu->env.event_register) {\n+        cpu->env.halt_reason = NOT_HALTED;\n+        return true;\n+    }\n+\n+    /*\n+     * Otherwise pretty much any IRQ would wake us up\n+     */\n+    if (cpu_test_interrupt(cs,\n+                           CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD\n+                           | CPU_INTERRUPT_NMI | CPU_INTERRUPT_VINMI | CPU_INTERRUPT_VFNMI\n+                           | CPU_INTERRUPT_VFIQ | CPU_INTERRUPT_VIRQ | CPU_INTERRUPT_VSERR\n+                           | CPU_INTERRUPT_EXITTB)) {\n+        cpu->env.halt_reason = NOT_HALTED;\n+        return true;\n     }\n \n-    return (cpu->power_state != PSCI_OFF)\n-        && cpu_test_interrupt(cs,\n-               CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD\n-               | CPU_INTERRUPT_NMI | CPU_INTERRUPT_VINMI | CPU_INTERRUPT_VFNMI\n-               | CPU_INTERRUPT_VFIQ | CPU_INTERRUPT_VIRQ | CPU_INTERRUPT_VSERR\n-               | CPU_INTERRUPT_EXITTB);\n+    return false;\n }\n #endif /* !CONFIG_USER_ONLY */\n \n@@ -250,7 +268,7 @@ static void arm_cpu_reset_hold(Object *obj, ResetType type)\n     env->vfp.xregs[ARM_VFP_MVFR1] = cpu->isar.mvfr1;\n     env->vfp.xregs[ARM_VFP_MVFR2] = cpu->isar.mvfr2;\n \n-    cpu->power_state = cs->start_powered_off ? PSCI_OFF : PSCI_ON;\n+    arm_set_cpu_power_state(cpu, cs->start_powered_off ? PSCI_OFF : PSCI_ON);\n \n     if (arm_feature(env, ARM_FEATURE_AARCH64)) {\n         /* 64 bit CPUs always start in 64 bit mode */\ndiff --git a/target/arm/kvm.c b/target/arm/kvm.c\nindex d4a68874b88..c08e4797b32 100644\n--- a/target/arm/kvm.c\n+++ b/target/arm/kvm.c\n@@ -1143,11 +1143,12 @@ static int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu)\n     if (cap_has_mp_state) {\n         struct kvm_mp_state mp_state;\n         int ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MP_STATE, &mp_state);\n+        ARMPSCIState state;\n         if (ret) {\n             return ret;\n         }\n-        cpu->power_state = (mp_state.mp_state == KVM_MP_STATE_STOPPED) ?\n-            PSCI_OFF : PSCI_ON;\n+        state = (mp_state.mp_state == KVM_MP_STATE_STOPPED) ? PSCI_OFF : PSCI_ON;\n+        arm_set_cpu_power_state(cpu, state);\n     }\n     return 0;\n }\ndiff --git a/target/arm/machine.c b/target/arm/machine.c\nindex b0e499515cf..62401c5a3ea 100644\n--- a/target/arm/machine.c\n+++ b/target/arm/machine.c\n@@ -916,7 +916,7 @@ static int get_power(QEMUFile *f, void *opaque, size_t size,\n {\n     ARMCPU *cpu = opaque;\n     bool powered_off = qemu_get_byte(f);\n-    cpu->power_state = powered_off ? PSCI_OFF : PSCI_ON;\n+    arm_set_cpu_power_state(cpu, powered_off ? PSCI_OFF : PSCI_ON);\n     return 0;\n }\n \ndiff --git a/target/arm/tcg/op_helper.c b/target/arm/tcg/op_helper.c\nindex 652611b4313..46c745077d5 100644\n--- a/target/arm/tcg/op_helper.c\n+++ b/target/arm/tcg/op_helper.c\n@@ -403,6 +403,7 @@ void HELPER(wfi)(CPUARMState *env, uint32_t insn_len)\n                         target_el);\n     }\n \n+    env->halt_reason = HALT_WFI;\n     cs->exception_index = EXCP_HLT;\n     cs->halted = 1;\n     cpu_loop_exit(cs);\n@@ -464,6 +465,7 @@ void HELPER(wfit)(CPUARMState *env, uint32_t rd)\n     } else {\n         timer_mod(cpu->wfxt_timer, nexttick);\n     }\n+    env->halt_reason = HALT_WFI;\n     cs->exception_index = EXCP_HLT;\n     cs->halted = 1;\n     cpu_loop_exit(cs);\n@@ -508,6 +510,7 @@ void HELPER(wfe)(CPUARMState *env)\n             return;\n         }\n \n+        env->halt_reason = HALT_WFE;\n         cs->exception_index = EXCP_HLT;\n         cs->halted = 1;\n         cpu_loop_exit(cs);\n",
    "prefixes": [
        "v2",
        "24/31"
    ]
}