Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.2/patches/2232955/?format=api
{ "id": 2232955, "url": "http://patchwork.ozlabs.org/api/1.2/patches/2232955/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260505112014.102993-2-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": "<20260505112014.102993-2-alex.bennee@linaro.org>", "list_archive_url": null, "date": "2026-05-05T11:20:07", "name": "[v5,1/7] target/arm: teach arm_cpu_has_work about halting reasons", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "7b7618cfa56694f010890b17f7ae7aad2d9dbedf", "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/20260505112014.102993-2-alex.bennee@linaro.org/mbox/", "series": [ { "id": 502820, "url": "http://patchwork.ozlabs.org/api/1.2/series/502820/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=502820", "date": "2026-05-05T11:20:06", "name": "target/arm: fully model WFxT instructions for A-profile", "version": 5, "mbox": "http://patchwork.ozlabs.org/series/502820/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2232955/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2232955/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=NNFuSSmg;\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 4g8x0C4dhgz1yK2\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 05 May 2026 21:20:59 +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 1wKDpD-0007Hi-Qc; Tue, 05 May 2026 07:20:28 -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 1wKDp8-0007FO-EW\n for qemu-devel@nongnu.org; Tue, 05 May 2026 07:20:22 -0400", "from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a])\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 1wKDp5-0005pO-IW\n for qemu-devel@nongnu.org; Tue, 05 May 2026 07:20:22 -0400", "by mail-wm1-x32a.google.com with SMTP id\n 5b1f17b1804b1-48984d29fe3so74692705e9.0\n for <qemu-devel@nongnu.org>; Tue, 05 May 2026 04:20:19 -0700 (PDT)", "from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id\n 5b1f17b1804b1-48d17ff41a0sm15578735e9.20.2026.05.05.04.20.15\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Tue, 05 May 2026 04:20:15 -0700 (PDT)", "from draig.lan (localhost [IPv6:::1])\n by draig.lan (Postfix) with ESMTP id 6856F5F913;\n Tue, 05 May 2026 12:20:14 +0100 (BST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=linaro.org; s=google; t=1777980017; x=1778584817; 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=DJazhEDPgKRcDHmZKYIM+jso6J9Jwwost9U+BImJW8o=;\n b=NNFuSSmgH7/QoY7nR8yfc4GTshwVziLD1+WmtP7051FcokLAmpcUwB5hAtmtuIX2kL\n D8/YS1OzS6Ww/IWKDzOl120TWYlCtnl3UYYu0rcBnGUysAe3+WMzjaNax1a+GNeknvHN\n zDMZNYBzKxZ66TZHjy14sVbo07DsAes2Ebf19fjjQg1rRMXTnqcWJ1wh3OIleixRnyOW\n MNK7M0pzlFGklHvAKvHtBF5lmKKaFoyf6pl9fo6OkzeY0oNE/2PxVxdvwuERdmFFdBKk\n OwRY/URdPooJtYM1JkV1jhaVjyReXuaNi2+P9hU00fBzXDSTFVdEDyv3nBLVFk08cH5p\n 8rig==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1777980017; x=1778584817;\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=DJazhEDPgKRcDHmZKYIM+jso6J9Jwwost9U+BImJW8o=;\n b=YzKJnyS7feQ1+L5yqm0gJiSFaHTXj30BUR8coYF15mjQbPpTYNY4xsEiVijx8lQrKC\n S0QDpErUgnX8c1wiRu448EDJEC82H+GHpYWdKT1MdovcHKcpUjHd3zJrh+DKQZPWbEct\n BCQl1z0i6rfZLiIQRHGI5I+Gh+cKLoXxXt4/JZFGIxlT4mPGe0IplaQuhQGoQ2e/lOvC\n O2ZISItjanljFdh40fzBHUuoXw/A95vy7RpbzFg1i60CX3EtqOQG59KKjOke1qsug3hg\n jbaoe5UHylJKj+WFt6dW3rPPf7NjNfqPiccncovLWaJzaUPpXIWYiZqUvYje3zscPDtg\n B9Dw==", "X-Gm-Message-State": "AOJu0Yyq90FLsMZMh45KxRnPvOpjoCnXRLS2mR9pu2/DDXI0B8JY01et\n LaJPRahylV52WNNC5LXOUv8PxfRsANktOYgl11Ctn45KdgjN1+37iQ0+Cp5hs5Hm4bU=", "X-Gm-Gg": "AeBDieu/xehDhh56KdfnZXJ5dsD/Iv0Ft9hTt65+YWQVK8NFBF18DeUJSi/OgWv+x6W\n dfKLggvsHJ7VMN9tqDDy/J83En357YNymw5q+b1K7HBw8tfhKy5r2JcqxqMmbt5YDU9ECKX48ey\n l0jUWp2MMtw0Egc2gOHlTfzvHvSTEIa7j2VOR4kgOSqZOCB5I2nc/aU0aiCR4/mvvI1U91X3tnl\n E6CyCyd4KrAf1wPhDE/WtEZtBCQ9xmtk/WQebQ9c8nMZccbYj68Aw2IhRC5g4C/OhI5GY0M9uBw\n 4aW80VtyAIT24lF047lvrken4cnicmFLe4RdTHuBm1YBm/QGbslIGbT/uOIpnTd3amUFJ8Avb4r\n Ubk5+AveejN9LCFsZvOW+S9SPTdj4R/H/tdoJ+OWDfid38J4zG914FGvpX6uPVaPocA8SBfMrDX\n BiCbSkD+d+MG2RLd/AnFI2PW4vkE89dF5vlg==", "X-Received": "by 2002:a05:600c:810a:b0:48a:592c:e655 with SMTP id\n 5b1f17b1804b1-48d18be5ab5mr41738105e9.17.1777980016924;\n Tue, 05 May 2026 04:20:16 -0700 (PDT)", "From": "=?utf-8?q?Alex_Benn=C3=A9e?= <alex.bennee@linaro.org>", "To": "qemu-devel@nongnu.org", "Cc": "Peter Maydell <peter.maydell@linaro.org>, kvm@vger.kernel.org,\n Alexander Graf <agraf@csgraf.de>,\n Mohamed Mediouni <mohamed@unpredictable.fr>,\n Paolo Bonzini <pbonzini@redhat.com>, Pedro Barbuda <pbarbuda@microsoft.com>,\n qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= <alex.bennee@linaro.org>,\n Richard Henderson <richard.henderson@linaro.org>", "Subject": "[PATCH v5 1/7] target/arm: teach arm_cpu_has_work about halting\n reasons", "Date": "Tue, 5 May 2026 12:20:07 +0100", "Message-ID": "<20260505112014.102993-2-alex.bennee@linaro.org>", "X-Mailer": "git-send-email 2.47.3", "In-Reply-To": "<20260505112014.102993-1-alex.bennee@linaro.org>", "References": "<20260505112014.102993-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::32a;\n envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32a.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\nReviewed-by: Richard Henderson <richard.henderson@linaro.org>\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\nv5\n - more arm_set_cpu_power_state cases\n---\n target/arm/cpu.h | 16 +++++++++++++++\n target/arm/internals.h | 11 +++++++++++\n target/arm/arm-powerctl.c | 6 +++---\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(+), 17 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..a06be5cc997 100644\n--- a/target/arm/arm-powerctl.c\n+++ b/target/arm/arm-powerctl.c\n@@ -78,7 +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->power_state = PSCI_ON;\n+ arm_set_cpu_power_state(target_cpu, PSCI_ON);\n }\n \n int arm_set_cpu_on(uint64_t cpuid, uint64_t entry, uint64_t context_id,\n@@ -186,7 +186,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->power_state = PSCI_ON;\n+ arm_set_cpu_power_state(target_cpu, PSCI_ON);\n }\n \n int arm_set_cpu_on_and_reset(uint64_t cpuid)\n@@ -239,7 +239,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": [ "v5", "1/7" ] }