{"id":2226161,"url":"http://patchwork.ozlabs.org/api/patches/2226161/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260422101043.1234229-28-alex.bennee@linaro.org/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/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-28-alex.bennee@linaro.org>","list_archive_url":null,"date":"2026-04-22T10:10:38","name":"[v2,27/31] target/arm: implements SEV/SEVL for all modes","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"bb2e90cb1d3914eaa81b83a9c6e06550dca015da","submitter":{"id":39532,"url":"http://patchwork.ozlabs.org/api/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-28-alex.bennee@linaro.org/mbox/","series":[{"id":500957,"url":"http://patchwork.ozlabs.org/api/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/2226161/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2226161/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=kM6dT2N1;\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 4g0wDv4cDGz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 20:19:11 +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 1wFUez-0007ZJ-Q8; Wed, 22 Apr 2026 06:18:21 -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 1wFUeN-0006z1-Rk\n for qemu-devel@nongnu.org; Wed, 22 Apr 2026 06:17:45 -0400","from mail-wm1-x332.google.com ([2a00:1450:4864:20::332])\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 1wFUeL-0002RE-Cc\n for qemu-devel@nongnu.org; Wed, 22 Apr 2026 06:17:43 -0400","by mail-wm1-x332.google.com with SMTP id\n 5b1f17b1804b1-4891b0786beso28964915e9.1\n for <qemu-devel@nongnu.org>; Wed, 22 Apr 2026 03:17:36 -0700 (PDT)","from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id\n 5b1f17b1804b1-4891cdfcd50sm84553285e9.9.2026.04.22.03.17.28\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 22 Apr 2026 03:17:33 -0700 (PDT)","from draig.lan (localhost [IPv6:::1])\n by draig.lan (Postfix) with ESMTP id A28A161668;\n Wed, 22 Apr 2026 11:10:45 +0100 (BST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=linaro.org; s=google; t=1776853055; x=1777457855; 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=N9iI3ryke1e2JIQkehVmmVgECgG7zvzI0XvyUC6unRY=;\n b=kM6dT2N1to8hBkSMYQoH0niPGtIFu0HXfyo/r93oL5/SM+KONeVJw6PgAzT6b/obHh\n nV2xJJMJAD0wwLxecwopgVJcRiW58FOhoaFhBxQtwf25fTA3CtUAP+8F8J3stnr5cJCE\n NdQx53E9X8Xw5CTMeGwzoFGwrPUe264I4ArwrRTs/b+XXrmNuefAbHIPA6VpSv7oKvzr\n vwVNZPLCw7CsBxKEn2iVefO5Vj+0QklumFuu3Gf+SZKm0nlYYoxMFOpu2YbhTFDz/ld+\n l96K3Rj+BGPQU48RfJ4WGCWJRRyOXxbwFYEi/cy8rMcAk7i5OIiar9QCmznEl+eTQmiP\n Rrtw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776853055; x=1777457855;\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=N9iI3ryke1e2JIQkehVmmVgECgG7zvzI0XvyUC6unRY=;\n b=ebsD/ENcsY4MN86mhz+mgz3sKcvJM62/A6xs5rhBkd+vwvwnzZLy9LZ2JmlDdZ0ng6\n pa/ELtWRKP3IFNJV6SbzNWEjtLd2LMkL3QzksNGvHANWIfKjhwxr9vZTEMxkokeOBJjs\n 0cXeDBB/CxvxXLF49LK0kJ8q5MInstVzEXxqfzo5EFjGbxV/4wBmIskjg/Ua8e/2qsih\n GM6ByTyF5d1g0IJmWUqVhWz10H+rXJDV8wDugOkteeJSVk8h/BWxEfEzkYHLt5Ywmb8A\n 1EdNuoqgIbVENdNGqGPqhZxCGxLOw/VbsV68m4DxG/fe2XwFaJtARsimsCDEYRon52w5\n pMBQ==","X-Gm-Message-State":"AOJu0YzjRuvPbrVpco9LC8H4eRxlccu4XNLxYVepoF2WC1Ls8C0qdjlC\n YtNNm1K8b3CynGv0Yz6AtHCFurnZnA470uL50qVn61aG4KsvV4Q4XjFUAqPl/ImKkGk=","X-Gm-Gg":"AeBDiet2zjKMO0M3p6vcBuukVs+ca4EsTArauPJxdiFW15QKMX6HX4Kyj3Bi++oTeiO\n vier+a6OvsLxtu3+37DHgtJ4QDCckt4fiNjlJsSLful+X2bZTmkt5S8eFmWTrb9b7DcpnAbU3j9\n nHdKE3t+RQv/Rm+iCnwScaoVYYSvIDQMhpGdGqr1tkGb/i7QHPfwayIaTW4E59cJBPtNxmWf0eQ\n QVnuD4MOCylyxCE8SG8ut3/xFWYm0FAKMI4QOOKjDDdiOVVtrVeqPRKbDEXrf4fbm556o3I0D0c\n HDz6z/EGmCtCBZztkeT91eKujAp85g0b+nr8OR5Y1ImhRBt88mE+Q7ZzMU+Ux94/iQSB1c8quWC\n 80DEcbuR+OWkYWKPR74Wxv4dTIKBn1xwdaNUofRjcOa873wPsuO9PgMGSXJ0Nyt9pJpSAA7Vs63\n XMePoThTOmypQbVLUKWf7s6cJKqCI4u8tLXg==","X-Received":"by 2002:a05:600c:c085:b0:488:acbc:b2e with SMTP id\n 5b1f17b1804b1-488fb765b04mr247121445e9.17.1776853054834;\n Wed, 22 Apr 2026 03:17:34 -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 27/31] target/arm: implements SEV/SEVL for all modes","Date":"Wed, 22 Apr 2026 11:10:38 +0100","Message-ID":"<20260422101043.1234229-28-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::332;\n envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x332.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":"Remove the restrictions that make this a M-profile only operation and\nenable the instructions for all Arm profiles.\n\nSigned-off-by: Alex Bennée <alex.bennee@linaro.org>\n\n---\nv2\n  - fix alignment in a32.decode\n  - set bool directly, defend with QEMU_BUILD_BUG_ON\n  - s/instructions/profiles/\n  - share get_event_reg between translate/translate-a64\n---\n target/arm/tcg/translate.h     | 18 ++++++++++++++++++\n target/arm/tcg/a32.decode      |  5 ++---\n target/arm/tcg/a64.decode      |  5 ++---\n target/arm/tcg/t16.decode      |  4 +---\n target/arm/tcg/t32.decode      |  4 +---\n target/arm/tcg/op_helper.c     |  4 +---\n target/arm/tcg/translate-a64.c | 17 +++++++++++++++++\n target/arm/tcg/translate.c     | 13 ++++++++-----\n 8 files changed, 50 insertions(+), 20 deletions(-)","diff":"diff --git a/target/arm/tcg/translate.h b/target/arm/tcg/translate.h\nindex 3e3094a463e..9bf2701a56b 100644\n--- a/target/arm/tcg/translate.h\n+++ b/target/arm/tcg/translate.h\n@@ -864,6 +864,24 @@ static inline void gen_restore_rmode(TCGv_i32 old, TCGv_ptr fpst)\n     gen_helper_set_rmode(old, old, fpst);\n }\n \n+/*\n+ * Event Register signalling.\n+ *\n+ * A bunch of activities trigger events, we just need to latch on to\n+ * true. The event eventually gets consumed by WFE/WFET.\n+ *\n+ * user-mode treats these as NOPs.\n+ */\n+\n+static inline void gen_event_reg(void)\n+{\n+#ifndef CONFIG_USER_ONLY\n+    TCGv_i32 set_event = tcg_constant_i32(1);\n+    QEMU_BUILD_BUG_ON(sizeof_field(CPUARMState, event_register) != 1);\n+    tcg_gen_st8_i32(set_event, tcg_env, offsetof(CPUARMState, event_register));\n+#endif\n+}\n+\n /*\n  * Helpers for implementing sets of trans_* functions.\n  * Defer the implementation of NAME to FUNC, with optional extra arguments.\ndiff --git a/target/arm/tcg/a32.decode b/target/arm/tcg/a32.decode\nindex f2ca4809495..547aa2b1490 100644\n--- a/target/arm/tcg/a32.decode\n+++ b/target/arm/tcg/a32.decode\n@@ -192,9 +192,8 @@ SMULTT           .... 0001 0110 .... 0000 .... 1110 ....      @rd0mn\n       WFE        ---- 0011 0010 0000 1111 ---- 0000 0010\n       WFI        ---- 0011 0010 0000 1111 ---- 0000 0011\n \n-      # TODO: Implement SEV, SEVL; may help SMP performance.\n-      # SEV      ---- 0011 0010 0000 1111 ---- 0000 0100\n-      # SEVL     ---- 0011 0010 0000 1111 ---- 0000 0101\n+      SEV        ---- 0011 0010 0000 1111 ---- 0000 0100\n+      SEVL       ---- 0011 0010 0000 1111 ---- 0000 0101\n \n       ESB        ---- 0011 0010 0000 1111 ---- 0001 0000\n     ]\ndiff --git a/target/arm/tcg/a64.decode b/target/arm/tcg/a64.decode\nindex 01b1b3e38be..dcb3099dd5c 100644\n--- a/target/arm/tcg/a64.decode\n+++ b/target/arm/tcg/a64.decode\n@@ -237,9 +237,8 @@ ERETA           1101011 0100 11111 00001 m:1 11111 11111 &reta  # ERETAA, ERETAB\n     YIELD       1101 0101 0000 0011 0010 0000 001 11111\n     WFE         1101 0101 0000 0011 0010 0000 010 11111\n     WFI         1101 0101 0000 0011 0010 0000 011 11111\n-    # We implement WFE to never block, so our SEV/SEVL are NOPs\n-    # SEV       1101 0101 0000 0011 0010 0000 100 11111\n-    # SEVL      1101 0101 0000 0011 0010 0000 101 11111\n+    SEV         1101 0101 0000 0011 0010 0000 100 11111\n+    SEVL        1101 0101 0000 0011 0010 0000 101 11111\n     # Our DGL is a NOP because we don't merge memory accesses anyway.\n     # DGL       1101 0101 0000 0011 0010 0000 110 11111\n     XPACLRI     1101 0101 0000 0011 0010 0000 111 11111\ndiff --git a/target/arm/tcg/t16.decode b/target/arm/tcg/t16.decode\nindex 778fbf16275..9a8f89538ac 100644\n--- a/target/arm/tcg/t16.decode\n+++ b/target/arm/tcg/t16.decode\n@@ -228,10 +228,8 @@ REVSH           1011 1010 11 ... ...            @rdm\n     WFE         1011 1111 0010 0000\n     WFI         1011 1111 0011 0000\n \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+    SEVL        1011 1111 0101 0000\n \n     # The canonical nop has the second nibble as 0000, but the whole of the\n     # rest of the space is a reserved hint, behaves as nop.\ndiff --git a/target/arm/tcg/t32.decode b/target/arm/tcg/t32.decode\nindex 49b8d0037ec..8ae277fe112 100644\n--- a/target/arm/tcg/t32.decode\n+++ b/target/arm/tcg/t32.decode\n@@ -369,10 +369,8 @@ 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-        # 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+        SEVL     1111 0011 1010 1111 1000 0000 0000 0101\n \n         ESB      1111 0011 1010 1111 1000 0000 0001 0000\n       ]\ndiff --git a/target/arm/tcg/op_helper.c b/target/arm/tcg/op_helper.c\nindex 46c745077d5..655e3f96e78 100644\n--- a/target/arm/tcg/op_helper.c\n+++ b/target/arm/tcg/op_helper.c\n@@ -477,9 +477,7 @@ void HELPER(sev)(CPUARMState *env)\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+        target_cpu->env.event_register = true;\n         if (!qemu_cpu_is_self(cs)) {\n             qemu_cpu_kick(cs);\n         }\ndiff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c\nindex d79c8ab431b..f30df5dbfed 100644\n--- a/target/arm/tcg/translate-a64.c\n+++ b/target/arm/tcg/translate-a64.c\n@@ -2032,6 +2032,23 @@ static bool trans_WFI(DisasContext *s, arg_WFI *a)\n     return true;\n }\n \n+static bool trans_SEV(DisasContext *s, arg_SEV *a)\n+{\n+    /*\n+     * SEV is a NOP for user-mode emulation.\n+     */\n+#ifndef CONFIG_USER_ONLY\n+    gen_helper_sev(tcg_env);\n+#endif\n+    return true;\n+}\n+\n+static bool trans_SEVL(DisasContext *s, arg_SEV *a)\n+{\n+    gen_event_reg();\n+    return true;\n+}\n+\n static bool trans_WFE(DisasContext *s, arg_WFI *a)\n {\n     /*\ndiff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c\nindex f9d1b8897d2..59925151fc3 100644\n--- a/target/arm/tcg/translate.c\n+++ b/target/arm/tcg/translate.c\n@@ -3244,17 +3244,20 @@ static bool trans_YIELD(DisasContext *s, arg_YIELD *a)\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+     * SEV is a NOP for user-mode emulation.\n      */\n #ifndef CONFIG_USER_ONLY\n-    if (arm_dc_feature(s, ARM_FEATURE_M)) {\n-        gen_helper_sev(tcg_env);\n-    }\n+    gen_helper_sev(tcg_env);\n #endif\n     return true;\n }\n \n+static bool trans_SEVL(DisasContext *s, arg_SEV *a)\n+{\n+    gen_event_reg();\n+    return true;\n+}\n+\n static bool trans_WFE(DisasContext *s, arg_WFE *a)\n {\n     /*\n","prefixes":["v2","27/31"]}