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 A3179606A320 for ; Mon, 30 Nov 2026 15:53:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=HZuHvV99 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xY3gp-0002zn-FC; Mon, 30 Nov 2026 10:53:15 -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 1xY3gi-0002xH-N0 for qemu-arm@nongnu.org; Mon, 30 Nov 2026 10:53:10 -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 1xY3gg-0002VO-H7 for qemu-arm@nongnu.org; Mon, 30 Nov 2026 10:53:08 -0500 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4a207b02a2cso76270195e9.1 for ; Mon, 30 Nov 2026 07:53:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1796053985; x=1796658785; 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=hLMynhS0xPc+3Vu0JRF5WPCDR1ZUCtPbgTQ3tg6+AFM=; b=HZuHvV99BHVyvriS+OBstwAKcSRlEYZiLrPjUHoAxUqRvh4G4AJWB49QMDnTXgw9Lj /5whOW3v1CkDEOpUZzHtbEyQF+S/PB8iotyqQZ5dovYldnjFmSjwumFgwjvQZXA7Etqg KJY9NItj2s9HimKTUAZoRAUda77949gCfWxXAE4I35lCSkWDBaerV2x/E6l7NgOE8sAv 9dFANA4i8aIgJHvGDbtWwducq9c9fETTaKjJEhAynHGn+ujwrScGCC6Axtg126DspLjX hEP+nCMxi4xOD1GVvM2+3dAmHj0x9pkvtaKQ2/rjjes0KXfgQIZGciax+YRYQ/Ec1kPu TV3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796053985; x=1796658785; 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=hLMynhS0xPc+3Vu0JRF5WPCDR1ZUCtPbgTQ3tg6+AFM=; b=D3WIuyO8MKS0iwax4XEaaA4MXkNKOvG8lgfeCIbob3lVPd70uSH4pHRkviXDSWKfEu G0ClVTaTVHM36E9jZv1ZN0MlsRh+iLZU8be2ltuztvTvZpqoq09TfsYes5piJ9LEo40g HawU1lNoCbkoNu4hwvgjxw20GKrujXTDy5AxsvH0NtFfP0yrtLl9p7lMM5FtEVEYg8Ga kfKd2U/aFLfgzvz16oBwGpGKkPzTRW4VO9BZYu/zgvuK9kZESDacq/tkKU5V3j2DGBCE Yutcxx4/1/SIM+vpZKPbgzREeL2xlYF0bCwHxVYE5ciS3/7EpexnnITBkpN7rb8A8fvf gZLw== X-Forwarded-Encrypted: i=1; AL+hErF8g3OPV3r9cZR7wtyrUYmxKrk8dWe9wGiVHIHn0WZysjvC/rEA3CqWFRwvu/Djh1xAEBCanvv32Q==@nongnu.org X-Gm-Message-State: APuU4Z9fQRPbD+EchphvW7WUonWPi2lHvWuC5cRt8JqGy9teawxk6gZv IJCmTSPQKqnwB4phQy27ovflfIdg39Qb08MjPjHhcmM9O2iRE2q7NpNq2HhTDNgFqnbW2sRNseQ GIRR7 X-Gm-Gg: AZFdTZdjSJ3K4Qxo5hAugA0q8aUJmmby8zLJ7NQLV7lun+kn8jgH3ErYjxR1qly5EAD iYH2qals34HX7uJTW0NJWPwec7wu6X/JMU4RtXx01Ds7GfCNyLGmr/t06x161idVjqov/yrnY2h WHs/+FkAPs+N+nrdosJJ/zjTfVqdmYbvU1Xp0dAcpZcgxkVT0OWw3r5qpN4ViXjypCcRQkR91rw pMl/fGEh5KgciX9dujiL/g9DwZjJF9psWYxEpUI95oyWc+I403TfXEejZk1nAc+t3UcubncTtl+ lTFSo48sMHbz36Fi61kZ7qAOl+sJOLwTBTNlYPHl82cYRSpHkox3M7+eiM//17ksA6IMxEu6ZbG wB5WSIdQC7GqTgpEf4dsYHJlnPv8thOYr8h/5pA4NXaLt9+EfxHpx7QJm5bBoDqRbb0yceV4c31 s0rqU1QWdl7AKDjEDzXhXyCdqf9/sfmKvQVuqTs2IwqhWn9NdOVGBVswnjAL0X47ial/GDxidzU pBBLRVUGttQXw5BvRNeaznVUoq/TbdUHJdMy54U6dBFj8nL2nCkFMhQV4ds+bOA6B211rJZueFn 3SFY9rGNQMdSVmY53vj2eOLflOB9 X-Received: by 2002:a05:600c:1115:b0:4bb:a602:6c8b with SMTP id 5b1f17b1804b1-4bba60271damr274339265e9.14.1796053984706; Mon, 30 Nov 2026 07:53:04 -0800 (PST) Received: from draig.lan ([185.124.0.158]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6c61e53asm71731797f8f.59.2026.11.30.07.53.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 07:53:04 -0800 (PST) Received: from draig (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id E4D6F5F88E; Mon, 30 Nov 2026 15:53:02 +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 15:00:14 +0000") References: <20261126143258.1056688-1-frank.mehnert@kernkonzept.com> <20261126143258.1056688-2-frank.mehnert@kernkonzept.com> <875wxe5sou.fsf@draig.linaro.org> User-Agent: mu4e 1.14.5-pre2; emacs 30.1 Date: Mon, 30 Nov 2026 15:53:02 +0000 Message-ID: <87zeuq48pt.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=ham 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=unavailable 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 Mon, 30 Nov 2026 at 13:56, Alex Benn=C3=A9e w= rote: >> >> Peter Maydell writes: >> >> > On Thu, 26 Nov 2026 at 14:33, Frank Mehnert = wrote: >> >> >> >> 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 sleep= s. >> >> On hardware, the store by another PE that made the store-exclusive fa= il >> >> 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 caus= es >> >> 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/translat= e-a64.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 cleare= d, which >> >> + * generates a WFE wakeup event. >> >> + */ >> > >> > We might add "Architecturally the wakeup event should have happened wh= en >> > 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_re= g() >> > 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? > > We're quite a long way out of spec on our exclusives handling, so > anything we're doing here is in the realm of "try to make the common > cases continue to work". The interaction here is that the event register > spec defines that the CPU's event register is cleared when the global > monitor for that CPU goes from "exclusive" to "open". Since we don't > really model the global monitor we're trying to patch things up by > doing it after the fact for at least some cases where we notice that > that transition would have happened. There will still be cases > where we should have set the event register and don't, we just hope > they don't matter in practice... > >> However making the store occur always still passes the test case so I >> don't have any objection if this is easier. > > Given that you're allowed to set the event register for any > IMPDEF reason, setting it more often is always safe. The tradeoff > I think is between "every store exclusive takes an extra conditional > branch" and "WFE spuriously wakes up more often". As I say, I don't > know which side of that we should prefer. WFE doesn't wake up here, the event register is local to the PE which is currently executing a StoreExcl - it just skips the first attempt to sleep after the StoreExcl. Only SEV broadcasts causes the other PE's to wake up. > > thanks > -- PMM --=20 Alex Benn=C3=A9e Virtualisation Tech Lead @ Linaro