{"id":2226167,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2226167/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260422101043.1234229-32-alex.bennee@linaro.org/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.2/projects/14/?format=json","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-32-alex.bennee@linaro.org>","list_archive_url":null,"date":"2026-04-22T10:10:42","name":"[v2,31/31] target/arm: implement WFET","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"3ac86cfca90b24005afbd4d1b0f4638756704c88","submitter":{"id":39532,"url":"http://patchwork.ozlabs.org/api/1.2/people/39532/?format=json","name":"Alex Bennée","email":"alex.bennee@linaro.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260422101043.1234229-32-alex.bennee@linaro.org/mbox/","series":[{"id":500957,"url":"http://patchwork.ozlabs.org/api/1.2/series/500957/?format=json","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/2226167/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2226167/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=TzAuik/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=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 4g0wFP0nF3z1yHB\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 20:19:37 +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 1wFUen-0007DH-CN; Wed, 22 Apr 2026 06:18:09 -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 1wFUeM-0006yw-7v\n for qemu-devel@nongnu.org; Wed, 22 Apr 2026 06:17:43 -0400","from mail-wm1-x341.google.com ([2a00:1450:4864:20::341])\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 1wFUeD-0002MU-QL\n for qemu-devel@nongnu.org; Wed, 22 Apr 2026 06:17:39 -0400","by mail-wm1-x341.google.com with SMTP id\n 5b1f17b1804b1-483487335c2so52369385e9.2\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 5b1f17b1804b1-48a55dc9f58sm266229045e9.6.2026.04.22.03.17.24\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 06F3C617D8;\n Wed, 22 Apr 2026 11:10:46 +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=v9TGxTsXQ4q7KQiokEaw8AGBMMJRUq1ldJ+z5GAXPms=;\n b=TzAuik/PUnqDFYwFHFKKGIETYkLHGw1i072RRMtsvIBNcZLzdJ1gG6Tn/nQl1OR7o0\n 1K6jebO9egLjsQBpq0Iu4pV7XnVyEPqOoQ/S4tYzC9V9iH/bIe+ajeXhEMbuLY8BL/FL\n G87EQgK6Q0TKC6X8MpMC4FNlaWaA+OAJW9ewMQOAn6k1piIP5sYLjjsu9yg8saQc5FvE\n J8VgStHzfS9MvYnhQJydMsXzY5UM4fD/OM/hjNqHwuyed4JACPOnoPHb/OPi8M92vAz/\n NxnCdstKjdsgiWPxE+byHsR0VHy1ept2IarBYteygDE7HLe7iRjsxi6TeIXet1rzEz+W\n PHtA==","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=v9TGxTsXQ4q7KQiokEaw8AGBMMJRUq1ldJ+z5GAXPms=;\n b=SPZB+UYVYVzP7CVByEzQgKHi6kdzjepnYDnBI2ni5ctcl1iUMxwHGYPJed8Bgp/nq+\n GRortpeZT8K2h30uyU1JK+fvq7p4oW55LxWKJxd6n9Yx5PvJjxOgx+ILQDH9LUvkJU/e\n oe3rpwF7u/AgyWzB1wNobOjAHe76knZ3zKtKnSlUSh0An3MDm/Jnd8mIcRKSrPYWrMZ+\n eW7Lz07Pa79WoSb48dcG5MLiz3+oiuyXa9SdORcw8A5+CBUxOSZ7/nIpUpfQd1+rkLhH\n f/8PMpGcz2AHD8bRUZ1aeiBFeIST+VM+jYT/3Qo3Fi6+gRvxOP6MFJw98U5yhaCVV2IU\n sfSA==","X-Gm-Message-State":"AOJu0YwH8FNZjcgQ3UWrDd4x4vDrZsOnHQTWbse+5+pA1qarzdDEh08e\n f+GQDOZnJY3tSuYTS4ohFwfcYgbxVNzksgK6B3ktQqm+v7pyUjXJgIE0JAXEyOhQglU=","X-Gm-Gg":"AeBDiety6dvOWpQblshqwjyntNiYZ7gAbXdJ+oSDgeubXSZMBBAmwg6HIoOe+UI6Cfg\n 5YGIOlfW0o41v6znmdbhJUGmv100EBDyLsT4BYT3l9ZORdsE+48HNFJs0HvgNs9oaAMi8kCnVHp\n FoCLfPotR6Hz50auU+SWoHCaCH5dFWjNdPHr7iGyYPFJ5GOaTxb3GVDsTZI49Jc3ng3y4SeDw4J\n Wrh2K00rcNeLFJhIL87XFK5CJjM9/OKf7NbfS+dfOY6Q6cugwNTeUsF4lUPrDF30NR2ZqJD9jXq\n 1BJeq7PkJz8OQ/bAkZf+phmWxPhmnqBI38j3RUDW5xjxYNoaWNcI89//LB7z2Frk9mE2iFUXmwI\n sFyPsn3+rfscuY7KMKZsOr0rCw3EwgTIzyvyEqABl8oaqL8WkCmoiN1LcHCw7DJtfVL1i2ljBc9\n C8UxnOT+Rd/SYKyuoHJjleW2ul7J55fkLBCw==","X-Received":"by 2002:a05:600c:a31a:b0:488:b239:77ec with SMTP id\n 5b1f17b1804b1-488fb778db4mr234699655e9.17.1776853045332;\n Wed, 22 Apr 2026 03:17:25 -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 31/31] target/arm: implement WFET","Date":"Wed, 22 Apr 2026 11:10:42 +0100","Message-ID":"<20260422101043.1234229-32-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::341;\n envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x341.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":"Now we have the event stream and SEV/SEVL implemented we can finally\nenable WFET for Aarch64.\n\nSigned-off-by: Alex Bennée <alex.bennee@linaro.org>\n\n---\nv2\n  - fix exception syndrome by using enum value\n  - use env->halt_reason\n---\n target/arm/tcg/helper-defs.h   |  1 +\n target/arm/tcg/op_helper.c     | 80 ++++++++++++++++++++++++++++++++++\n target/arm/tcg/translate-a64.c | 15 ++++---\n 3 files changed, 89 insertions(+), 7 deletions(-)","diff":"diff --git a/target/arm/tcg/helper-defs.h b/target/arm/tcg/helper-defs.h\nindex a05f2258f29..31ffcbc6448 100644\n--- a/target/arm/tcg/helper-defs.h\n+++ b/target/arm/tcg/helper-defs.h\n@@ -56,6 +56,7 @@ DEF_HELPER_1(setend, void, env)\n DEF_HELPER_2(wfi, void, env, i32)\n DEF_HELPER_1(wfe, void, env)\n DEF_HELPER_2(wfit, void, env, i32)\n+DEF_HELPER_2(wfet, void, env, i32)\n DEF_HELPER_1(yield, void, env)\n DEF_HELPER_1(pre_hvc, void, env)\n DEF_HELPER_2(pre_smc, void, env, i32)\ndiff --git a/target/arm/tcg/op_helper.c b/target/arm/tcg/op_helper.c\nindex 030209360e8..0c7f069a369 100644\n--- a/target/arm/tcg/op_helper.c\n+++ b/target/arm/tcg/op_helper.c\n@@ -607,6 +607,86 @@ void HELPER(wfe)(CPUARMState *env)\n #endif\n }\n \n+void HELPER(wfet)(CPUARMState *env, uint32_t rd)\n+{\n+#ifdef CONFIG_USER_ONLY\n+    /*\n+     * As for WFIT make it NOP here, because trying to raise EXCP_HLT\n+     * would trigger an abort.\n+     */\n+    return;\n+#else\n+    ARMCPU *cpu = env_archcpu(env);\n+    CPUState *cs = env_cpu(env);\n+    uint32_t excp;\n+    int target_el = check_wfx_trap(env, false, &excp);\n+    /* The WFET should time out when CNTVCT_EL0 >= the specified value. */\n+    uint64_t cntval = gt_get_countervalue(env);\n+    uint64_t timeout = env->xregs[rd];\n+    /*\n+     * We want the value that we would get if we read CNTVCT_EL0 from\n+     * the current exception level, so the direct_access offset, not\n+     * the indirect_access one. Compare the pseudocode LocalTimeoutEvent(),\n+     * which calls VirtualCounterTimer().\n+     */\n+    uint64_t offset = gt_direct_access_timer_offset(env, GTIMER_VIRT);\n+    uint64_t cntvct = cntval - offset;\n+    uint64_t nexttick;\n+    int64_t next_event;\n+\n+    /*\n+     * As for WFE if the event register is already set we can consume\n+     * the event and return immediately.\n+     */\n+    if (env->event_register) {\n+        env->event_register = false;\n+        return;\n+    }\n+\n+\n+    if (cpu_has_work(cs) || cntvct >= timeout) {\n+        /*\n+         * Don't bother to go into our \"low power state\" if\n+         * we would just wake up immediately.\n+         */\n+        return;\n+    }\n+\n+    /* We might sleep, so now we check to see if we should trap */\n+    if (target_el) {\n+        env->pc -= 4;\n+        raise_exception(env, excp, syn_wfx(1, 0xe, rd, true, WFET, false), target_el);\n+    }\n+\n+    /*\n+     * Finally work out if the timeout or event stream will kick in\n+     * earlier.\n+     */\n+    if (uadd64_overflow(timeout, offset, &nexttick)) {\n+        nexttick = UINT64_MAX;\n+    }\n+    if (nexttick > INT64_MAX / gt_cntfrq_period_ns(cpu)) {\n+        nexttick = INT64_MAX;\n+    }\n+\n+    next_event = gt_calc_next_event_stream(env);\n+    if (next_event > 0 && next_event < nexttick) {\n+        timer_mod(cpu->wfxt_timer, next_event);\n+    } else {\n+        if (nexttick == INT64_MAX) {\n+            timer_mod_ns(cpu->wfxt_timer, INT64_MAX);\n+        } else {\n+            timer_mod(cpu->wfxt_timer, nexttick);\n+        }\n+    }\n+\n+    env->halt_reason = HALT_WFE;\n+    cs->exception_index = EXCP_HLT;\n+    cs->halted = 1;\n+    cpu_loop_exit(cs);\n+#endif\n+}\n+\n void HELPER(yield)(CPUARMState *env)\n {\n     CPUState *cs = env_cpu(env);\ndiff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c\nindex a1b0cc9508e..19e00573979 100644\n--- a/target/arm/tcg/translate-a64.c\n+++ b/target/arm/tcg/translate-a64.c\n@@ -2093,14 +2093,15 @@ static bool trans_WFET(DisasContext *s, arg_WFET *a)\n         return false;\n     }\n \n-    /*\n-     * We rely here on our WFE implementation being a NOP, so we\n-     * don't need to do anything different to handle the WFET timeout\n-     * from what trans_WFE does.\n-     */\n-    if (!(tb_cflags(s->base.tb) & CF_PARALLEL)) {\n-        s->base.is_jmp = DISAS_WFE;\n+    if (s->ss_active) {\n+        /* Act like a NOP under architectural singlestep */\n+        return true;\n     }\n+\n+    gen_a64_update_pc(s, 4);\n+    gen_helper_wfet(tcg_env, tcg_constant_i32(a->rd));\n+    /* Go back to the main loop to check for interrupts */\n+    s->base.is_jmp = DISAS_EXIT;\n     return true;\n }\n \n","prefixes":["v2","31/31"]}