From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03F8C606A327 for ; Mon, 30 Nov 2026 13:56:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=R9xpxJ3J Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xY1s3-0000hg-GQ; Mon, 30 Nov 2026 08:56:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xY1rn-0000HX-7I for qemu-arm@nongnu.org; Mon, 30 Nov 2026 08:56:28 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xY1ri-0002qp-A0 for qemu-arm@nongnu.org; Mon, 30 Nov 2026 08:56:26 -0500 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4bb702a7548so95601845e9.1 for ; Mon, 30 Nov 2026 05:56:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1796046980; x=1796651780; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :user-agent:references:in-reply-to:subject:cc:to:from:from:to:cc :subject:date:message-id:reply-to:content-type; bh=ecccGcPnav5+IQlyArhu/piMkEKRbo3Df3YrKS0E5uI=; b=R9xpxJ3JglvX+k00PddHU87opKNZwkl0xg4sZ+4zjfn1pyAM1z+3x+KXi+Ip8HatyT xHXt0EzE8/6sE94BlKCX8nsmT+vL5ysPUsT++rxiCc79yXy016vGKj2xZ9HBAz/ZRP5E kD+gHurgbHTqRG/uHzjzhKfz7WfF8vAM6RD/YwmeY5CmmD0EFt3iuGLGZMDglsLerysI oXoCxtaVrqacGX33lRrJLHruKosRwL9emoKf0ZJpLUSRbntBXuv2NVp6f9usa1Zf5ayq 47tNbqL7hB3xSfZKRFau69QYkAE6TIgLSTcixUkRGghMVT491DnVp3TO0JUzIFqkp6sX SrpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796046980; x=1796651780; h=content-transfer-encoding:content-type:mime-version:message-id:date :user-agent:references:in-reply-to:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ecccGcPnav5+IQlyArhu/piMkEKRbo3Df3YrKS0E5uI=; b=nr8JRe5vAyD4n1oEg7TUlc7BGs/UnZkkHz+9iCEKnQq1Zb2zBYMEfZIx6fCig1vG9D FGXvnoLeHHNqS49wOCLZil3awLtns9A9patVMSi2m4aNJlXjWRYxLnc41ByjCFdRTyfw rjyUyB1oZ/fQ+8eGDL3Z3d56SRJ6BDO3rLx5FJPAIoTTyvI3s98bm8lzT5fCzwmzYkyY GATGxIgysWYW8FzM1/uCYyv/vqIzR/CH5afeBUsOZVEseTDA4HO4QzDavsXj1r3AVWHb 6lrBqsoC9cNq7TVSPb9WCaVFMUfrD2B9MHe8koOj4Nupv6/nlYUjLr+LtJTsGY/Xev3A h5rw== X-Forwarded-Encrypted: i=1; AL+hErFZRknU9cK9Zy8Squ0bSMgSQESw47Haf0jVnA/qcXuvg6Fn3oXpX6P4c53fPHgSj6qVMeA18/2NwA==@nongnu.org X-Gm-Message-State: APuU4Z/ZdHjD2pT9iVw2I8WqGivEXsjDZ//QGTJt0TD4j5+XgiHmKhJ1 XGav8NUxxe5SNbTP+9p6S2jGI8V2oJznoQtTbtKfY0PfyUAcMMIdPh5C2lujDxUVtF4= X-Gm-Gg: AZFdTZc+zqE99S4UY0oHVY7GLXczi3cTfYARDpQZG+YiRm7fN/uIKPi7tOLehwTocfX U0ZsAUQV8J/XUwKcHG80IBhjk0R2a9pPboC7iq6jlu4txMsasxDbH/XDzPsopcVVHkjeF+inXRF CJbejoyHy3mwkDUrMOOq4eE/TRRBLSANTWEV9ZsPNrRgHPU32dS4Om7Vxim+voaBhQW7FviFe76 8QzYI3fMV6jnL9DY3EG5iuu38zdKY6LMz+X3IsqchGyZdFuwG3ilOQLKOe65l9mtvryAiGQS0yT dk75gxrELhgI2Jb2F5s0stho9nodcmhWCCdCOF2sPKQWfJ2k/D4hVhgf41fkmGVJpgRyA/iSwZ+ B5YzaC9JoRCa1qaJlaI7HhqqfXo4rSbFCPvarFTzC8kdZ9WkCzr8eBsdQZ0Hsqtm3HKezro3CHL kgxUxgZFQEISBaZL+vb9NxO4q23GAjiIImq64Wq9ogowQDGI14F7FTui6LvdzxFxuanK1tCbb+w 5zsGGDZp5ohE6420h5pBFG3sVB3F5mDYb0S3sJqDayTz5fWZMOOHNqZ1ikP2hAlublXqVuzwxl0 nAbzAo2rkIojk0HWOD4aNAQU4Cf4 X-Received: by 2002:a05:600c:4584:b0:4a7:c366:d791 with SMTP id 5b1f17b1804b1-4bb887e266amr653872255e9.1.1796046980374; Mon, 30 Nov 2026 05:56:20 -0800 (PST) Received: from draig.lan ([185.124.0.158]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb905f1489sm636455825e9.0.2026.11.30.05.56.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 05:56:18 -0800 (PST) Received: from draig (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 575DD5F88E; Mon, 30 Nov 2026 13:56:17 +0000 (GMT) From: =?utf-8?Q?Alex_Benn=C3=A9e?= To: Peter Maydell Cc: Frank Mehnert , qemu-devel@nongnu.org, qemu-arm@nongnu.org, Frank Mehnert , Richard Henderson Subject: Re: [PATCH for-11.2 v2 1/2] target/arm: set the event register on a failed store-exclusive In-Reply-To: (Peter Maydell's message of "Mon, 30 Nov 2026 10:10:06 +0000") References: <20261126143258.1056688-1-frank.mehnert@kernkonzept.com> <20261126143258.1056688-2-frank.mehnert@kernkonzept.com> User-Agent: mu4e 1.14.5-pre2; emacs 30.1 Date: Mon, 30 Nov 2026 13:56:17 +0000 Message-ID: <875wxe5sou.fsf@draig.linaro.org> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x335.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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-arm-bounces+qemu-arm=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-20.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Peter Maydell writes: > On Thu, 26 Nov 2026 at 14:33, Frank Mehnert wro= te: >> >> Since WFE may sleep on A-profile, a WFE executed outside an exclusive >> region halts the vCPU until an event arrives. Lock code commonly >> branches back to WFE after a failed store-exclusive, for example: >> >> 1: wfe >> ldaxr w1, [x0] >> cbnz w1, 1b >> stxr w2, w3, [x0] >> cbnz w2, 1b >> >> The store-exclusive clears exclusive_addr, so the following WFE sleeps. >> On hardware, the store by another PE that made the store-exclusive fail >> cleared the global monitor of this PE, and clearing the global monitor >> sets the Event Register (Arm ARM D1.6.1, R_XRZRK). The WFE then >> completes immediately. QEMU does not model this, so with interrupts >> masked and no event stream the vCPU sleeps until another PE executes >> SEV, which such lock code never does. >> >> Set the Event Register when a store-exclusive fails, in both the >> AArch64 and the AArch32 translator. A failure for another reason causes >> a spurious wakeup, which the architecture permits. >> >> Fixes: 01b223f895a7 ("target/arm: enable WFE sleeping for A-profile") >> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4938 >> Reviewed-by: Alex Benn=C3=A9e >> Signed-off-by: Frank Mehnert >> --- >> target/arm/tcg/translate-a64.c | 7 ++++++- >> target/arm/tcg/translate.c | 7 ++++++- >> 2 files changed, 12 insertions(+), 2 deletions(-) >> >> diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a= 64.c >> index 49472f7d97..45f3b3df03 100644 >> --- a/target/arm/tcg/translate-a64.c >> +++ b/target/arm/tcg/translate-a64.c >> @@ -3531,10 +3531,15 @@ static void gen_store_exclusive(DisasContext *s,= int rd, int rt, int rt2, >> tcg_gen_setcond_i64(TCG_COND_NE, tmp, tmp, cpu_exclusive_val); >> } >> tcg_gen_mov_i64(cpu_reg(s, rd), tmp); >> - tcg_gen_br(done_label); >> + tcg_gen_brcondi_i64(TCG_COND_EQ, tmp, 0, done_label); >> >> gen_set_label(fail_label); >> tcg_gen_movi_i64(cpu_reg(s, rd), 1); >> + /* >> + * A failing store-exclusive means the global monitor was cleared, = which >> + * generates a WFE wakeup event. >> + */ > > We might add "Architecturally the wakeup event should have happened when > the store by the other CPU happened, but we do it here." > >> + gen_event_reg(); >> gen_set_label(done_label); >> tcg_gen_movi_i64(cpu_exclusive_addr, -1); > > The architecture permits the global monitor to be cleared when a > StoreExcl() succeeds as well as when it fails. Given that gen_event_reg() > is just a byte-store, we could also unconditionally do it after the > done_label, to avoid the branching around. Not sure which is > preferable. Isn't the global monitor subtly different from the per-vcpu event register in this case as we are modelling the effect of it being cleared without properly modelling the actual global monitor itself? Or does our messing with cpu_exclusive_addr count? However making the store occur always still passes the test case so I don't have any objection if this is easier. > >> } >> diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c >> index 442c34ce84..2eef2ceef2 100644 >> --- a/target/arm/tcg/translate.c >> +++ b/target/arm/tcg/translate.c >> @@ -2137,10 +2137,15 @@ static void gen_store_exclusive(DisasContext *s,= int rd, int rt, int rt2, >> tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t2); >> } >> tcg_gen_mov_i32(cpu_R[rd], t0); >> - tcg_gen_br(done_label); >> + tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, done_label); >> >> gen_set_label(fail_label); >> tcg_gen_movi_i32(cpu_R[rd], 1); >> + /* >> + * A failing store-exclusive means the global monitor was cleared, = which >> + * generates a WFE wakeup event. >> + */ >> + gen_event_reg(); >> gen_set_label(done_label); >> tcg_gen_movi_i64(cpu_exclusive_addr, -1); >> } >> -- >> 2.55.0 > > -- PMM --=20 Alex Benn=C3=A9e Virtualisation Tech Lead @ Linaro