get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 2231088,
    "url": "http://patchwork.ozlabs.org/api/1.1/patches/2231088/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260430104434.1482407-2-alex.bennee@linaro.org/",
    "project": {
        "id": 14,
        "url": "http://patchwork.ozlabs.org/api/1.1/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": ""
    },
    "msgid": "<20260430104434.1482407-2-alex.bennee@linaro.org>",
    "date": "2026-04-30T10:44:28",
    "name": "[v4,1/7] target/arm: teach arm_cpu_has_work about halting reasons",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "328cc9274fd3f8c48c5b8975bf679ae63e0b8d55",
    "submitter": {
        "id": 39532,
        "url": "http://patchwork.ozlabs.org/api/1.1/people/39532/?format=api",
        "name": "Alex Bennée",
        "email": "alex.bennee@linaro.org"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260430104434.1482407-2-alex.bennee@linaro.org/mbox/",
    "series": [
        {
            "id": 502271,
            "url": "http://patchwork.ozlabs.org/api/1.1/series/502271/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=502271",
            "date": "2026-04-30T10:44:31",
            "name": "target/arm: fully model WFxT instructions for A-profile",
            "version": 4,
            "mbox": "http://patchwork.ozlabs.org/series/502271/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2231088/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2231088/checks/",
    "tags": {},
    "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=a16HYuUZ;\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 4g5rTC2G9xz1yHZ\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 30 Apr 2026 20:46:55 +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 1wIOt3-0008K7-Ih; Thu, 30 Apr 2026 06:44:54 -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 1wIOsw-0008GY-RK\n for qemu-devel@nongnu.org; Thu, 30 Apr 2026 06:44:49 -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 1wIOst-0005Jp-HZ\n for qemu-devel@nongnu.org; Thu, 30 Apr 2026 06:44:46 -0400",
            "by mail-wr1-x441.google.com with SMTP id\n ffacd0b85a97d-43d73422431so685375f8f.2\n for <qemu-devel@nongnu.org>; Thu, 30 Apr 2026 03:44:38 -0700 (PDT)",
            "from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id\n ffacd0b85a97d-448af0fa81esm7222907f8f.19.2026.04.30.03.44.35\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Thu, 30 Apr 2026 03:44:35 -0700 (PDT)",
            "from draig.lan (localhost [IPv6:::1])\n by draig.lan (Postfix) with ESMTP id DD4785F92A;\n Thu, 30 Apr 2026 11:44:34 +0100 (BST)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=linaro.org; s=google; t=1777545877; x=1778150677; 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=oXkCjDNNed+tdCztqK2sYupZhfXPPqZLJxXlVw3UrqI=;\n b=a16HYuUZ3/Y0hcc30+I65qrgP/ti5Wb72t4SOWwu2hsCJAbZi0eFP/wBSyQ8s7hqB0\n FEPXCL5jN0fvRHM4G5BTrjTbi1Xe7t3BpDlPEsgHOJng5Dho6Uwjm31kGgpg1YXmM/d/\n OcPNv2hGtySdTXaODrfypTNngFnZxvHBiJ+oc+eoJo9Z9hW3poeplIjOWxB2dP/Ur0/P\n ERZTx2IzcPULXJVj2dgmUz9UEYNN1SklwZenEpOanNWvxvH6P9CGKllI4qZjy9VAbrJ5\n LF+rOTdRAjU6IrO/0WSbiTp5Pkx0OfzFmdVdmkwfTbt7bS61PvrXEsjePFAQBIEItJBm\n As9w==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1777545877; x=1778150677;\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:sub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BG+Q==",
        "X-Received": "by 2002:a05:6000:24c5:b0:43f:e452:f391 with SMTP id\n ffacd0b85a97d-4493cb42f83mr4018286f8f.6.1777545876542;\n Thu, 30 Apr 2026 03:44:36 -0700 (PDT)",
        "From": "=?utf-8?q?Alex_Benn=C3=A9e?= <alex.bennee@linaro.org>",
        "To": "qemu-devel@nongnu.org",
        "Cc": "Mohamed Mediouni <mohamed@unpredictable.fr>, qemu-arm@nongnu.org,\n Pedro Barbuda <pbarbuda@microsoft.com>,\n Peter Maydell <peter.maydell@linaro.org>,\n Paolo Bonzini <pbonzini@redhat.com>, kvm@vger.kernel.org,\n Alexander Graf <agraf@csgraf.de>,\n =?utf-8?q?Alex_Benn=C3=A9e?= <alex.bennee@linaro.org>",
        "Subject": "[PATCH v4 1/7] target/arm: teach arm_cpu_has_work about halting\n reasons",
        "Date": "Thu, 30 Apr 2026 11:44:28 +0100",
        "Message-ID": "<20260430104434.1482407-2-alex.bennee@linaro.org>",
        "X-Mailer": "git-send-email 2.47.3",
        "In-Reply-To": "<20260430104434.1482407-1-alex.bennee@linaro.org>",
        "References": "<20260430104434.1482407-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=ham 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---\nv3\n  - move arm_set_cpu_power_state to internals.h\n  - drop excess brackets\n---\n target/arm/cpu.h           | 16 +++++++++++++++\n target/arm/internals.h     | 11 +++++++++++\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 7 files changed, 66 insertions(+), 15 deletions(-)",
    "diff": "diff --git a/target/arm/cpu.h b/target/arm/cpu.h\nindex be14a47c357..357359011cb 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.\ndiff --git a/target/arm/internals.h b/target/arm/internals.h\nindex a632584a4e0..4a1ea5465d7 100644\n--- a/target/arm/internals.h\n+++ b/target/arm/internals.h\n@@ -1997,4 +1997,15 @@ bool arm_cpu_match_cpreg_mig_tolerance(ARMCPU *cpu, uint64_t kvmidx,\n                                        ARMCPRegMigToleranceType type);\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 #endif\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 10feb639c4d..fb79981338c 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@@ -326,7 +344,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 8dc766d3225..dbd39e7ba76 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 e8f0996ed39..504526153a6 100644\n--- a/target/arm/tcg/op_helper.c\n+++ b/target/arm/tcg/op_helper.c\n@@ -402,6 +402,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@@ -463,6 +464,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@@ -507,6 +509,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": [
        "v4",
        "1/7"
    ]
}