Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2195158/?format=api
{ "id": 2195158, "url": "http://patchwork.ozlabs.org/api/patches/2195158/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260210135206.229528-26-peter.maydell@linaro.org/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/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": "<20260210135206.229528-26-peter.maydell@linaro.org>", "list_archive_url": null, "date": "2026-02-10T13:52:05", "name": "[PULL,25/26] target/arm: Implement WFE, SEV and SEVONPEND for Cortex-M", "commit_ref": null, "pull_url": null, "state": "not-applicable", "archived": false, "hash": "126e6fdbb85aa17b1995c68895a4607c7add578d", "submitter": { "id": 5111, "url": "http://patchwork.ozlabs.org/api/people/5111/?format=api", "name": "Peter Maydell", "email": "peter.maydell@linaro.org" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260210135206.229528-26-peter.maydell@linaro.org/mbox/", "series": [ { "id": 491680, "url": "http://patchwork.ozlabs.org/api/series/491680/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=491680", "date": "2026-02-10T13:51:40", "name": "[PULL,01/26] target/arm/kvm: add constants for new PSCI versions", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/491680/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2195158/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2195158/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=PgZeUo+p;\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=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)" ], "Received": [ "from lists.gnu.org (lists.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 4f9NLz1bL3z1xtV\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 11 Feb 2026 00:53:31 +1100 (AEDT)", "from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1vpoAN-0002FZ-SN; Tue, 10 Feb 2026 08:52:35 -0500", "from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <peter.maydell@linaro.org>)\n id 1vpoAM-0002FA-Kw\n for qemu-devel@nongnu.org; Tue, 10 Feb 2026 08:52:34 -0500", "from mail-wm1-x331.google.com ([2a00:1450:4864:20::331])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <peter.maydell@linaro.org>)\n id 1vpoAK-0006OQ-2g\n for qemu-devel@nongnu.org; Tue, 10 Feb 2026 08:52:34 -0500", "by mail-wm1-x331.google.com with SMTP id\n 5b1f17b1804b1-47edd6111b4so82577805e9.1\n for <qemu-devel@nongnu.org>; Tue, 10 Feb 2026 05:52:31 -0800 (PST)", "from lanath.. (wildly.archaic.org.uk. [81.2.115.145])\n by smtp.gmail.com with ESMTPSA id\n 5b1f17b1804b1-4834d5d77f9sm64344875e9.3.2026.02.10.05.52.29\n for <qemu-devel@nongnu.org>\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Tue, 10 Feb 2026 05:52:29 -0800 (PST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=linaro.org; s=google; t=1770731551; x=1771336351; darn=nongnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:to:from:from:to:cc:subject:date:message-id\n :reply-to; bh=i8xU8YorGAD8nVtQ3t6PaTQzkBHPBasWYnnVTTO1ehA=;\n b=PgZeUo+prUeRTIfh5zDFUWBKhufDTT83FmEOEfrYnPZKq7HS4cC1shJdEXlLaQoIH4\n O0RcQ+ecQWXy507TztEqA/NBQKqpCVqeFkdaLud1B9MdePG3/0hAIitPTuuWJca/ShIs\n A1WJZCYKsrCyUZ3uMZDMiaSHEoLuB+FRu2V/+sNCb0Y37NnfTkg8bMiHD8epfdctm8aI\n s93spxKpAWbxYtMpbcsAFcz5uriTvYeEDfg1E3ZG04OMq/s1mozcjiVJJ04OOyOd7FwW\n frv0R8HDn/+Nx7NK5ehVYTgOa5qCOEncMiahtGP3pbaf41gWYiWXGTPpKQM/d6XGVjde\n YaRg==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1770731551; x=1771336351;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to\n :cc:subject:date:message-id:reply-to;\n bh=i8xU8YorGAD8nVtQ3t6PaTQzkBHPBasWYnnVTTO1ehA=;\n b=L2UW/Ui6qXkh8E33b9Sj0JsufXSDjW3q/ybr+yWWKa2cAZFnPVRcE2NXfHOEPw1VxP\n yzB3Pk8dLeq3bg/Xy7QrYj+FzXzcYs8FhQ0mt+vQBS/bykQoI//x55TDCo4cx+pTFqME\n 33Pl8eeINWWxWdkvp+l/08OThy8dVMrxilsR9AAqv43F8c1yq6dcpDVRQX3ZlNW3/eKP\n kNCukQK9MqkcxjsnLXv79rC0msdhEhxejKQoJhnkJI1GiIZsQPMdMNqR1QaAKz+gEnZY\n plOLoTOt50hHV3LFW5NW680qJNgJxHupzZi5FihG+o3STTKMi4L96e2ACF5M8zT+ILJc\n S/7w==", "X-Gm-Message-State": "AOJu0YyCiRrJ19833KUKefjl04KrwyT9fSXZWHpkXqp843KEWe+FkjX/\n feNWnyVf7U4+3/6E0a9CjEP3ohBhrqHkObE3WM4bQsl0OPyzB2PiJ3E+vfvr93T7eGvaV26GqiS\n fPHfD", "X-Gm-Gg": "AZuq6aJcWSZop1PHnza4IRviICpLs4O6NfTkFtCJErj50PKvXBZVS58E0PazAtxoMHn\n 7fzA1e5DopTmkbw6J02Gs2R2A9TaAy2iL3oyPXAbeta+B9+v/xBEhCxBJP4lqa8sukemCi7xkRz\n bsWlAUHYa2uRo7RmXMH/3sao2+dGu31SHR0YvHGglnNc2Uxw0meEdbbaZemckJXRQz/4nr7PWA0\n Pog3ZdISNaH8jDFkf+JefFebAZ+crKPduwhFBGE0o4DgLhFdS8JGh8HZJn1tB04Mhjv9UtUa/qU\n xzRxXPSFbb/KruJ12t2feJ/z3Ap3f34n91dPnY6PxIoNKPRdfCTg8Wcu608JzajyP3l3Fg8nELF\n 7Sambw39QKADi8/eyxB7t0hM3vZWkYDijv6p1PgnBldWz7Xipy2FYX+XtH2PvCyk0PPdn8UocZO\n wTPlsYAr/hXYTkm9/CObkOXPphkzxT9Vec9QVJ+hr3PeCPTC3HmTWdZkzNsn7PPp7OQ6Qhbhm6J\n O7oFzEGVxXfBlQYHteAqsdnvYWo2ACKxIXiy88JYw==", "X-Received": "by 2002:a05:600c:8b29:b0:471:1717:411 with SMTP id\n 5b1f17b1804b1-4835081ed4fmr35061035e9.24.1770731550298;\n Tue, 10 Feb 2026 05:52:30 -0800 (PST)", "From": "Peter Maydell <peter.maydell@linaro.org>", "To": "qemu-devel@nongnu.org", "Subject": "[PULL 25/26] target/arm: Implement WFE,\n SEV and SEVONPEND for Cortex-M", "Date": "Tue, 10 Feb 2026 13:52:05 +0000", "Message-ID": "<20260210135206.229528-26-peter.maydell@linaro.org>", "X-Mailer": "git-send-email 2.43.0", "In-Reply-To": "<20260210135206.229528-1-peter.maydell@linaro.org>", "References": "<20260210135206.229528-1-peter.maydell@linaro.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Received-SPF": "pass client-ip=2a00:1450:4864:20::331;\n envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x331.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": "From: Ashish Anand <ashish.a6@samsung.com>\n\nCurrently, QEMU implements the 'Wait For Event' (WFE) instruction as a\nsimple yield. This causes high host CPU usage because guest\nRTOS idle loops effectively become busy-wait loops.\n\nTo improve efficiency, this patch transitions WFE to use the architectural\n'Halt' state (EXCP_HLT) for M-profile CPUs. This allows the host thread\nto sleep when the guest is idle.\n\nTo support this transition, we implement the full architectural behavior\nrequired for WFE, specifically the 'Event Register', 'SEVONPEND' logic,\nand 'R_BPBR' exception handling requirements defined in the ARM\nArchitecture Reference Manual.\n\nThis patch enables resource-efficient idle emulation for Cortex-M.\n\nSigned-off-by: Ashish Anand <ashish.a6@samsung.com>\nMessage-id: 20260209051931.122531-1-ashish.a6@samsung.com\nReviewed-by: Peter Maydell <peter.maydell@linaro.org>\nSigned-off-by: Peter Maydell <peter.maydell@linaro.org>\n---\n hw/intc/armv7m_nvic.c | 79 +++++++++++++++++++++++++++++---------\n target/arm/cpu.c | 6 +++\n target/arm/cpu.h | 7 ++++\n target/arm/machine.c | 19 +++++++++\n target/arm/tcg/helper.h | 1 +\n target/arm/tcg/m_helper.c | 5 +++\n target/arm/tcg/op_helper.c | 56 +++++++++++++++++++++++----\n target/arm/tcg/t16.decode | 5 ++-\n target/arm/tcg/t32.decode | 5 ++-\n target/arm/tcg/translate.c | 29 ++++++++++++--\n 10 files changed, 179 insertions(+), 33 deletions(-)", "diff": "diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c\nindex 28b34e9944..a7651f831e 100644\n--- a/hw/intc/armv7m_nvic.c\n+++ b/hw/intc/armv7m_nvic.c\n@@ -221,6 +221,29 @@ static int exc_group_prio(NVICState *s, int rawprio, bool targets_secure)\n return rawprio;\n }\n \n+/*\n+ * Update the pending state of an exception vector.\n+ * This is the central function for all updates to vec->pending.\n+ * Handles SEVONPEND: if this is a 0->1 transition on an external interrupt\n+ * and SEVONPEND is set in the appropriate SCR, sets the event register.\n+ */\n+static void nvic_update_pending_state(NVICState *s, VecInfo *vec,\n+ int irq, uint8_t next_pending_val)\n+{\n+ uint8_t prev_pending_val = vec->pending;\n+ vec->pending = next_pending_val;\n+\n+ /* Check for 0->1 transition on interrupts (>= NVIC_FIRST_IRQ) only */\n+ if (!prev_pending_val && next_pending_val && irq >= NVIC_FIRST_IRQ) {\n+ int scr_bank = exc_targets_secure(s, irq) ? M_REG_S : M_REG_NS;\n+ /* SEVONPEND: interrupt going to pending is a WFE wakeup event */\n+ if (s->cpu->env.v7m.scr[scr_bank] & R_V7M_SCR_SEVONPEND_MASK) {\n+ s->cpu->env.event_register = true;\n+ qemu_cpu_kick(CPU(s->cpu));\n+ }\n+ }\n+}\n+\n /* Recompute vectpending and exception_prio for a CPU which implements\n * the Security extension\n */\n@@ -516,7 +539,7 @@ static void armv7m_nvic_clear_pending(NVICState *s, int irq, bool secure)\n }\n trace_nvic_clear_pending(irq, secure, vec->enabled, vec->prio);\n if (vec->pending) {\n- vec->pending = 0;\n+ nvic_update_pending_state(s, vec, irq, 0);\n nvic_irq_update(s);\n }\n }\n@@ -656,7 +679,7 @@ static void do_armv7m_nvic_set_pending(void *opaque, int irq, bool secure,\n }\n \n if (!vec->pending) {\n- vec->pending = 1;\n+ nvic_update_pending_state(s, vec, irq, 1);\n nvic_irq_update(s);\n }\n }\n@@ -753,7 +776,7 @@ void armv7m_nvic_set_pending_lazyfp(NVICState *s, int irq, bool secure)\n s->cpu->env.v7m.hfsr |= R_V7M_HFSR_FORCED_MASK;\n }\n if (!vec->pending) {\n- vec->pending = 1;\n+ nvic_update_pending_state(s, vec, irq, 1);\n /*\n * We do not call nvic_irq_update(), because we know our caller\n * is going to handle causing us to take the exception by\n@@ -790,7 +813,7 @@ void armv7m_nvic_acknowledge_irq(NVICState *s)\n trace_nvic_acknowledge_irq(pending, s->vectpending_prio);\n \n vec->active = 1;\n- vec->pending = 0;\n+ nvic_update_pending_state(s, vec, pending, 0);\n \n write_v7m_exception(env, s->vectpending);\n \n@@ -898,7 +921,7 @@ int armv7m_nvic_complete_irq(NVICState *s, int irq, bool secure)\n * happens for external IRQs\n */\n assert(irq >= NVIC_FIRST_IRQ);\n- vec->pending = 1;\n+ nvic_update_pending_state(s, vec, irq, 1);\n }\n \n nvic_irq_update(s);\n@@ -1657,7 +1680,7 @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value,\n }\n /* We don't implement deep-sleep so these bits are RAZ/WI.\n * The other bits in the register are banked.\n- * QEMU's implementation ignores SEVONPEND and SLEEPONEXIT, which\n+ * QEMU's implementation ignores SLEEPONEXIT, which\n * is architecturally permitted.\n */\n value &= ~(R_V7M_SCR_SLEEPDEEP_MASK | R_V7M_SCR_SLEEPDEEPS_MASK);\n@@ -1722,38 +1745,57 @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value,\n (value & (1 << 10)) != 0;\n s->sec_vectors[ARMV7M_EXCP_SYSTICK].active =\n (value & (1 << 11)) != 0;\n- s->sec_vectors[ARMV7M_EXCP_USAGE].pending =\n- (value & (1 << 12)) != 0;\n- s->sec_vectors[ARMV7M_EXCP_MEM].pending = (value & (1 << 13)) != 0;\n- s->sec_vectors[ARMV7M_EXCP_SVC].pending = (value & (1 << 15)) != 0;\n+ nvic_update_pending_state(s, &s->sec_vectors[ARMV7M_EXCP_USAGE],\n+ ARMV7M_EXCP_USAGE,\n+ (value & (1 << 12)) != 0);\n+ nvic_update_pending_state(s, &s->sec_vectors[ARMV7M_EXCP_MEM],\n+ ARMV7M_EXCP_MEM,\n+ (value & (1 << 13)) != 0);\n+ nvic_update_pending_state(s, &s->sec_vectors[ARMV7M_EXCP_SVC],\n+ ARMV7M_EXCP_SVC,\n+ (value & (1 << 15)) != 0);\n s->sec_vectors[ARMV7M_EXCP_MEM].enabled = (value & (1 << 16)) != 0;\n s->sec_vectors[ARMV7M_EXCP_BUS].enabled = (value & (1 << 17)) != 0;\n s->sec_vectors[ARMV7M_EXCP_USAGE].enabled =\n (value & (1 << 18)) != 0;\n- s->sec_vectors[ARMV7M_EXCP_HARD].pending = (value & (1 << 21)) != 0;\n+ nvic_update_pending_state(s, &s->sec_vectors[ARMV7M_EXCP_HARD],\n+ ARMV7M_EXCP_HARD,\n+ (value & (1 << 21)) != 0);\n /* SecureFault not banked, but RAZ/WI to NS */\n s->vectors[ARMV7M_EXCP_SECURE].active = (value & (1 << 4)) != 0;\n s->vectors[ARMV7M_EXCP_SECURE].enabled = (value & (1 << 19)) != 0;\n- s->vectors[ARMV7M_EXCP_SECURE].pending = (value & (1 << 20)) != 0;\n+ nvic_update_pending_state(s, &s->vectors[ARMV7M_EXCP_SECURE],\n+ ARMV7M_EXCP_SECURE,\n+ (value & (1 << 20)) != 0);\n } else {\n s->vectors[ARMV7M_EXCP_MEM].active = (value & (1 << 0)) != 0;\n if (arm_feature(&cpu->env, ARM_FEATURE_V8)) {\n /* HARDFAULTPENDED is not present in v7M */\n- s->vectors[ARMV7M_EXCP_HARD].pending = (value & (1 << 21)) != 0;\n+ nvic_update_pending_state(s, &s->vectors[ARMV7M_EXCP_HARD],\n+ ARMV7M_EXCP_HARD,\n+ (value & (1 << 21)) != 0);\n }\n s->vectors[ARMV7M_EXCP_USAGE].active = (value & (1 << 3)) != 0;\n s->vectors[ARMV7M_EXCP_SVC].active = (value & (1 << 7)) != 0;\n s->vectors[ARMV7M_EXCP_PENDSV].active = (value & (1 << 10)) != 0;\n s->vectors[ARMV7M_EXCP_SYSTICK].active = (value & (1 << 11)) != 0;\n- s->vectors[ARMV7M_EXCP_USAGE].pending = (value & (1 << 12)) != 0;\n- s->vectors[ARMV7M_EXCP_MEM].pending = (value & (1 << 13)) != 0;\n- s->vectors[ARMV7M_EXCP_SVC].pending = (value & (1 << 15)) != 0;\n+ nvic_update_pending_state(s, &s->vectors[ARMV7M_EXCP_USAGE],\n+ ARMV7M_EXCP_USAGE,\n+ (value & (1 << 12)) != 0);\n+ nvic_update_pending_state(s, &s->vectors[ARMV7M_EXCP_MEM],\n+ ARMV7M_EXCP_MEM,\n+ (value & (1 << 13)) != 0);\n+ nvic_update_pending_state(s, &s->vectors[ARMV7M_EXCP_SVC],\n+ ARMV7M_EXCP_SVC,\n+ (value & (1 << 15)) != 0);\n s->vectors[ARMV7M_EXCP_MEM].enabled = (value & (1 << 16)) != 0;\n s->vectors[ARMV7M_EXCP_USAGE].enabled = (value & (1 << 18)) != 0;\n }\n if (attrs.secure || (cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK)) {\n s->vectors[ARMV7M_EXCP_BUS].active = (value & (1 << 1)) != 0;\n- s->vectors[ARMV7M_EXCP_BUS].pending = (value & (1 << 14)) != 0;\n+ nvic_update_pending_state(s, &s->vectors[ARMV7M_EXCP_BUS],\n+ ARMV7M_EXCP_BUS,\n+ (value & (1 << 14)) != 0);\n s->vectors[ARMV7M_EXCP_BUS].enabled = (value & (1 << 17)) != 0;\n }\n /* NMIACT can only be written if the write is of a zero, with\n@@ -2389,7 +2431,8 @@ static MemTxResult nvic_sysreg_write(void *opaque, hwaddr addr,\n (attrs.secure || s->itns[startvec + i]) &&\n !(setval == 0 && s->vectors[startvec + i].level &&\n !s->vectors[startvec + i].active)) {\n- s->vectors[startvec + i].pending = setval;\n+ nvic_update_pending_state(s, &s->vectors[startvec + i],\n+ startvec + i, setval);\n }\n }\n nvic_irq_update(s);\ndiff --git a/target/arm/cpu.c b/target/arm/cpu.c\nindex 077f1f9a74..7542444b18 100644\n--- a/target/arm/cpu.c\n+++ b/target/arm/cpu.c\n@@ -144,6 +144,12 @@ 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+\n return (cpu->power_state != PSCI_OFF)\n && cpu_test_interrupt(cs,\n CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD\ndiff --git a/target/arm/cpu.h b/target/arm/cpu.h\nindex e146f7e6c4..657ff4ab20 100644\n--- a/target/arm/cpu.h\n+++ b/target/arm/cpu.h\n@@ -760,6 +760,13 @@ typedef struct CPUArchState {\n /* Optional fault info across tlb lookup. */\n ARMMMUFaultInfo *tlb_fi;\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+ * WFE/SEV handling is currently implemented only for M-profile.\n+ */\n+ bool event_register;\n+\n /* Fields up to this point are cleared by a CPU reset */\n struct {} end_reset_fields;\n \ndiff --git a/target/arm/machine.c b/target/arm/machine.c\nindex 0befdb0b28..bbaae34449 100644\n--- a/target/arm/machine.c\n+++ b/target/arm/machine.c\n@@ -508,6 +508,24 @@ static const VMStateDescription vmstate_m_mve = {\n },\n };\n \n+static bool event_needed(void *opaque)\n+{\n+ ARMCPU *cpu = opaque;\n+\n+ return cpu->env.event_register;\n+}\n+\n+static const VMStateDescription vmstate_event = {\n+ .name = \"cpu/event\",\n+ .version_id = 1,\n+ .minimum_version_id = 1,\n+ .needed = event_needed,\n+ .fields = (const VMStateField[]) {\n+ VMSTATE_BOOL(env.event_register, ARMCPU),\n+ VMSTATE_END_OF_LIST()\n+ }\n+};\n+\n static const VMStateDescription vmstate_m = {\n .name = \"cpu/m\",\n .version_id = 4,\n@@ -1210,6 +1228,7 @@ const VMStateDescription vmstate_arm_cpu = {\n &vmstate_wfxt_timer,\n &vmstate_syndrome64,\n &vmstate_pstate64,\n+ &vmstate_event,\n NULL\n }\n };\ndiff --git a/target/arm/tcg/helper.h b/target/arm/tcg/helper.h\nindex 4636d1bc03..5a10a9fba3 100644\n--- a/target/arm/tcg/helper.h\n+++ b/target/arm/tcg/helper.h\n@@ -60,6 +60,7 @@ DEF_HELPER_1(yield, void, env)\n DEF_HELPER_1(pre_hvc, void, env)\n DEF_HELPER_2(pre_smc, void, env, i32)\n DEF_HELPER_1(vesb, void, env)\n+DEF_HELPER_1(sev, void, env)\n \n DEF_HELPER_3(cpsr_write, void, env, i32, i32)\n DEF_HELPER_2(cpsr_write_eret, void, env, i32)\ndiff --git a/target/arm/tcg/m_helper.c b/target/arm/tcg/m_helper.c\nindex 3fb24c7790..0c3832a47f 100644\n--- a/target/arm/tcg/m_helper.c\n+++ b/target/arm/tcg/m_helper.c\n@@ -962,7 +962,9 @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain,\n * Now we've done everything that might cause a derived exception\n * we can go ahead and activate whichever exception we're going to\n * take (which might now be the derived exception).\n+ * Exception entry sets the event register (ARM ARM R_BPBR)\n */\n+ env->event_register = true;\n armv7m_nvic_acknowledge_irq(env->nvic);\n \n /* Switch to target security state -- must do this before writing SPSEL */\n@@ -1906,6 +1908,9 @@ static void do_v7m_exception_exit(ARMCPU *cpu)\n /* Otherwise, we have a successful exception exit. */\n arm_clear_exclusive(env);\n arm_rebuild_hflags(env);\n+\n+ /* Exception return sets the event register (ARM ARM R_BPBR) */\n+ env->event_register = true;\n qemu_log_mask(CPU_LOG_INT, \"...successful exception return\\n\");\n }\n \ndiff --git a/target/arm/tcg/op_helper.c b/target/arm/tcg/op_helper.c\nindex 4fbd219555..c7ab462d1d 100644\n--- a/target/arm/tcg/op_helper.c\n+++ b/target/arm/tcg/op_helper.c\n@@ -469,16 +469,58 @@ void HELPER(wfit)(CPUARMState *env, uint64_t timeout)\n #endif\n }\n \n+void HELPER(sev)(CPUARMState *env)\n+{\n+ CPUState *cs = env_cpu(env);\n+ CPU_FOREACH(cs) {\n+ ARMCPU *target_cpu = ARM_CPU(cs);\n+ if (arm_feature(&target_cpu->env, ARM_FEATURE_M)) {\n+ target_cpu->env.event_register = true;\n+ }\n+ if (!qemu_cpu_is_self(cs)) {\n+ qemu_cpu_kick(cs);\n+ }\n+ }\n+}\n+\n void HELPER(wfe)(CPUARMState *env)\n {\n- /* This is a hint instruction that is semantically different\n- * from YIELD even though we currently implement it identically.\n- * Don't actually halt the CPU, just yield back to top\n- * level loop. This is not going into a \"low power state\"\n- * (ie halting until some event occurs), so we never take\n- * a configurable trap to a different exception level.\n+#ifdef CONFIG_USER_ONLY\n+ /*\n+ * WFE in the user-mode emulator is a NOP. Real-world user-mode code\n+ * shouldn't execute WFE, but if it does, we make it a NOP rather than\n+ * aborting when we try to raise EXCP_HLT.\n */\n- HELPER(yield)(env);\n+ return;\n+#else\n+ /*\n+ * WFE (Wait For Event) is a hint instruction.\n+ * For Cortex-M (M-profile), we implement the strict architectural behavior:\n+ * 1. Check the Event Register (set by SEV or SEVONPEND).\n+ * 2. If set, clear it and continue (consume the event).\n+ */\n+ if (arm_feature(env, ARM_FEATURE_M)) {\n+ CPUState *cs = env_cpu(env);\n+\n+ if (env->event_register) {\n+ env->event_register = false;\n+ return;\n+ }\n+\n+ cs->exception_index = EXCP_HLT;\n+ cs->halted = 1;\n+ cpu_loop_exit(cs);\n+ } else {\n+ /*\n+ * For A-profile and others, we rely on the existing \"yield\" behavior.\n+ * Don't actually halt the CPU, just yield back to top\n+ * level loop. This is not going into a \"low power state\"\n+ * (ie halting until some event occurs), so we never take\n+ * a configurable trap to a different exception level\n+ */\n+ HELPER(yield)(env);\n+ }\n+#endif\n }\n \n void HELPER(yield)(CPUARMState *env)\ndiff --git a/target/arm/tcg/t16.decode b/target/arm/tcg/t16.decode\nindex 646c74929d..778fbf1627 100644\n--- a/target/arm/tcg/t16.decode\n+++ b/target/arm/tcg/t16.decode\n@@ -228,8 +228,9 @@ REVSH 1011 1010 11 ... ... @rdm\n WFE 1011 1111 0010 0000\n WFI 1011 1111 0011 0000\n \n- # TODO: Implement SEV, SEVL; may help SMP performance.\n- # SEV 1011 1111 0100 0000\n+ # M-profile SEV is implemented.\n+ # TODO: Implement SEV for other profiles, and SEVL for all profiles; may help SMP performance.\n+ SEV 1011 1111 0100 0000\n # SEVL 1011 1111 0101 0000\n \n # The canonical nop has the second nibble as 0000, but the whole of the\ndiff --git a/target/arm/tcg/t32.decode b/target/arm/tcg/t32.decode\nindex d327178829..49b8d0037e 100644\n--- a/target/arm/tcg/t32.decode\n+++ b/target/arm/tcg/t32.decode\n@@ -369,8 +369,9 @@ CLZ 1111 1010 1011 ---- 1111 .... 1000 .... @rdm\n WFE 1111 0011 1010 1111 1000 0000 0000 0010\n WFI 1111 0011 1010 1111 1000 0000 0000 0011\n \n- # TODO: Implement SEV, SEVL; may help SMP performance.\n- # SEV 1111 0011 1010 1111 1000 0000 0000 0100\n+ # M-profile SEV is implemented.\n+ # TODO: Implement SEV for other profiles, and SEVL for all profiles; may help SMP performance.\n+ SEV 1111 0011 1010 1111 1000 0000 0000 0100\n # SEVL 1111 0011 1010 1111 1000 0000 0000 0101\n \n ESB 1111 0011 1010 1111 1000 0000 0001 0000\ndiff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c\nindex 63735d9789..c90b0106f7 100644\n--- a/target/arm/tcg/translate.c\n+++ b/target/arm/tcg/translate.c\n@@ -3241,14 +3241,30 @@ static bool trans_YIELD(DisasContext *s, arg_YIELD *a)\n return true;\n }\n \n+static bool trans_SEV(DisasContext *s, arg_SEV *a)\n+{\n+ /*\n+ * Currently SEV is a NOP for non-M-profile and in user-mode emulation.\n+ * For system-mode M-profile, it sets the event register.\n+ */\n+#ifndef CONFIG_USER_ONLY\n+ if (arm_dc_feature(s, ARM_FEATURE_M)) {\n+ gen_helper_sev(tcg_env);\n+ }\n+#endif\n+ return true;\n+}\n+\n static bool trans_WFE(DisasContext *s, arg_WFE *a)\n {\n /*\n * When running single-threaded TCG code, use the helper to ensure that\n- * the next round-robin scheduled vCPU gets a crack. In MTTCG mode we\n- * just skip this instruction. Currently the SEV/SEVL instructions,\n- * which are *one* of many ways to wake the CPU from WFE, are not\n- * implemented so we can't sleep like WFI does.\n+ * the next round-robin scheduled vCPU gets a crack.\n+ *\n+ * For Cortex-M, we implement the architectural WFE behavior (sleeping\n+ * until an event occurs or the Event Register is set).\n+ * For other profiles, we currently treat this as a NOP or yield,\n+ * to preserve existing performance characteristics.\n */\n if (!(tb_cflags(s->base.tb) & CF_PARALLEL)) {\n gen_update_pc(s, curr_insn_len(s));\n@@ -6807,6 +6823,11 @@ static void arm_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)\n break;\n case DISAS_WFE:\n gen_helper_wfe(tcg_env);\n+ /*\n+ * The helper can return if the event register is set, so we\n+ * must go back to the main loop to check for events.\n+ */\n+ tcg_gen_exit_tb(NULL, 0);\n break;\n case DISAS_YIELD:\n gen_helper_yield(tcg_env);\n", "prefixes": [ "PULL", "25/26" ] }