Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.1/patches/2226457/?format=api
{ "id": 2226457, "url": "http://patchwork.ozlabs.org/api/1.1/patches/2226457/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260422125250.1303100-25-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": "<20260422125250.1303100-25-alex.bennee@linaro.org>", "date": "2026-04-22T12:52:41", "name": "[v3,24/32] 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.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/20260422125250.1303100-25-alex.bennee@linaro.org/mbox/", "series": [ { "id": 501008, "url": "http://patchwork.ozlabs.org/api/1.1/series/501008/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=501008", "date": "2026-04-22T12:52:20", "name": "target/arm: fully model WFxT instructions for A-profile", "version": 3, "mbox": "http://patchwork.ozlabs.org/series/501008/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2226457/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2226457/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=tZ1SOs5f;\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 4g0zhG0wMyz1yD5\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 22:54:38 +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 1wFX5h-0006qE-9X; Wed, 22 Apr 2026 08:54:05 -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 1wFX4r-00065u-0Y\n for qemu-devel@nongnu.org; Wed, 22 Apr 2026 08:53:13 -0400", "from mail-wr1-x443.google.com ([2a00:1450:4864:20::443])\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 1wFX4m-0005XI-J9\n for qemu-devel@nongnu.org; Wed, 22 Apr 2026 08:53:11 -0400", "by mail-wr1-x443.google.com with SMTP id\n ffacd0b85a97d-43cfbd17589so4297287f8f.0\n for <qemu-devel@nongnu.org>; Wed, 22 Apr 2026 05:53:08 -0700 (PDT)", "from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id\n ffacd0b85a97d-43fe4dc24cfsm45215207f8f.16.2026.04.22.05.52.59\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 22 Apr 2026 05:53:02 -0700 (PDT)", "from draig.lan (localhost [IPv6:::1])\n by draig.lan (Postfix) with ESMTP id E34FB614FF;\n Wed, 22 Apr 2026 13:52:52 +0100 (BST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=linaro.org; s=google; t=1776862387; x=1777467187; 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=tZ1SOs5fql6qYW9oVAMguO9mp1voI/L98/BSdUuDe7nQYoWEtGI+zAD8ubaIvVh0Im\n zymKEJPaEtDz0TFDiZo4dhhMxXmL6KXxz2eQsyassROscpOp4e5anrSsDMJWm8CYD9Yd\n JeRFM3IaHMn1HgQstZAOlGQiTkqLIoAdnH6GGrZ1YJPlSFHtrO6w5ewtAJ23ZG/fzt/L\n oXcTemZ/+n0lJyH6Az31N217MMwgIVKlS+Fy+Oshk53UTAgkmPnI1lKunqoc91AC2C8H\n feUJ49PM6Krz+CeUs8eANSsWGRaspSeccdaK2popS7o4vUkF8ErCLRYkHJLlr/jM6TB2\n /dQg==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776862387; x=1777467187;\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=A7ZXl7g63MXEkXMOvV9OHijF+R/9rxwXkdoKlHNYFP64/qOm4l+2xtSboo0eyJ7CbX\n M5EYt9v3E3Qpz+B0l7j3dmKjelbMdZi+7ao6jouVxppvS/ggoemhLIOp+3Kf+OvGpqLc\n HPZ9bugnjhuV4XoFLDz1n7tWjC7D5S/gQt6jj98WZddf7FjHJ2Ixnz7/Aqs7HxgDCA3z\n J2/JZ1OQ9WKKH+UwCGwRgvbZHxKNBDcDombLo8yGEavfoM+Wh7d8EMew4hSBPR/oOk/4\n 0+DFmbbKm22scClt3LN2mYtbuzEF1H4xqpCXuqw5SkMJB3B/yBRiysliN9Hqpgs6G9Si\n tARg==", "X-Gm-Message-State": "AOJu0Yyyy1gX3BUxPOJS91epC2wqGxMcYgY3JaK0T1fgbdcmtxG74MGX\n fjbQgzd41KBIdqARrNPY5WotdROtTfSOHSVVSYKp6ITb2Vi5iMuqNV3llC1jckzCvRc=", "X-Gm-Gg": "AeBDievpv0QXnl2U/R4HtJEaBX7E2O7X1ysPdOJ8/8jMBeBwpBurcQ8PKi5K0UKsmKo\n GOoxDWrmltt2LlnUaonxRwAMKEbtwHVJzQTWe3lxxY1CV9A8izDg59dWLQy9XybsgA7QJ/5lo5x\n DkKKHsJKulfXNZ2Yqyhz7vG1I1QFt5FQbhX4ZekWFnZ4cC1ru1hUyKWc9A11no9tIXBk1mNAriX\n mDmIo4T2+9UJqupuaRgRLVV0gbruYcfxhJknhrX5h1QSvQetGDfaNSIU/1liAS2K1Rd7GmVstLx\n 1azpsuLS/YUI23W4htbM/pHuLe5pz3o8ToWViOSrs7O0ifr/GnaWKMbbo4LBcKZvIDKwdcEzLaj\n 8N1Y4SYOphRxkzim/4wuolvbJ8/y7qrqLmpbHqHeQ0T6HsV/goEbP8ihuvVpDYpT6slyoPREnTA\n b93yPFH68b88ADj9/xxPqAfkvSo/e+veW00w==", "X-Received": "by 2002:adf:fcc9:0:b0:43f:e4f1:bd9b with SMTP id\n ffacd0b85a97d-43fe4f1bdf7mr22720056f8f.30.1776862386869;\n Wed, 22 Apr 2026 05:53:06 -0700 (PDT)", "From": "=?utf-8?q?Alex_Benn=C3=A9e?= <alex.bennee@linaro.org>", "To": "qemu-devel@nongnu.org", "Cc": "Pedro Barbuda <pbarbuda@microsoft.com>, Alexander Graf <agraf@csgraf.de>,\n Peter Maydell <peter.maydell@linaro.org>,\n Paolo Bonzini <pbonzini@redhat.com>,\n Mohamed Mediouni <mohamed@unpredictable.fr>, kvm@vger.kernel.org,\n qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= <alex.bennee@linaro.org>", "Subject": "[PATCH v3 24/32] target/arm: teach arm_cpu_has_work about halting\n reasons", "Date": "Wed, 22 Apr 2026 13:52:41 +0100", "Message-ID": "<20260422125250.1303100-25-alex.bennee@linaro.org>", "X-Mailer": "git-send-email 2.47.3", "In-Reply-To": "<20260422125250.1303100-1-alex.bennee@linaro.org>", "References": "<20260422125250.1303100-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::443;\n envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x443.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": [ "v3", "24/32" ] }