* [PATCH 1/3] target/riscv: Fix RCsc ordering of Zalasr store-release
2026-08-21 6:40 [PATCH 0/3] Fix RCsc store->load ordering of release stores LIU Zhiwei
@ 2026-08-21 6:40 ` LIU Zhiwei
2026-08-24 12:30 ` Daniel Henrique Barboza
2026-08-21 6:40 ` [PATCH 2/3] target/arm: Fix RCsc ordering of store-release instructions LIU Zhiwei
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: LIU Zhiwei @ 2026-08-21 6:40 UTC (permalink / raw)
To: qemu-devel, qemu-riscv, qemu-arm
Cc: palmer, alistair.francis, liwei1518, daniel.barboza, chao.liu,
zhiwei_liu, peter.maydell, richard.henderson, TANG TianCheng
The Zalasr load-acquire instructions carry an acquire-RCsc annotation
and the store-release instructions carry a release-RCsc annotation;
the extension has no RCpc variant (Zalasr specification, chapter 2).
Per Rule 7 of the RVWMO preserved program order rules ("a and b both
have RCsc annotations"), a Zalasr store-release must precede any
subsequent RCsc memory operation of the same hart in the global
memory order. In particular "sw.rl X=1; lw.aq r1=Y" must be ordered,
which is what forbids the [0,0] outcome of a Store Buffering litmus
test that runs this pair on two harts.
gen_store_release() only emits a barrier before the store, which
orders the memory operations preceding the store before the store
itself (Rule 6, release semantics). Nothing prevents the store from
being reordered with the memory operations that follow it, so under
MTTCG the host CPU may execute the load-acquire that immediately
follows a store-release before the store has left its store buffer:
* on an x86 host (TSO), store-load is the only reordering the
hardware may perform, and it is exactly the ordering that is
missing here;
* on an aarch64 host, no dmb follows the store either.
The defect is easily observed with a bare-metal Store Buffering
litmus test on a 4 vCPU guest: "sw.rl X=1; lw.aq r1=Y" on hart 0 and
"sw.rl Y=1; lw.aq r2=X" on hart 1 produce the architecturally
forbidden [0,0] result in 89881 out of 100000 iterations.
Fix this by emitting a full barrier after the store as well, which
mirrors the FENCE translation. The TCG_MO_ST_LD bit included in
TCG_MO_ALL makes the x86 backend emit a serializing lock-prefixed
instruction after the store, draining the store buffer before any
subsequent load executes, and the aarch64 backend emit dmb ish; the
store therefore becomes globally visible before any subsequent memory
operation of the same vCPU, and Rule 7 is satisfied. This is
stronger than Rule 7 strictly requires, since the barrier also orders
the store with respect to subsequent non-RCsc operations, but this
matches how QEMU already implements FENCE and keeps the fix simple.
The load-acquire side needs no change: the barrier emitted after the
load already orders it with all subsequent memory operations, which
covers Rule 5 and the remaining Rule 7 combinations (load-load and
load-store).
Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
Co-authored-by: TANG TianCheng <tangtiancheng.ttc@alibaba-inc.com>
Signed-off-by: TANG TianCheng <tangtiancheng.ttc@alibaba-inc.com>
---
target/riscv/tcg/insn_trans/trans_rvzalasr.c.inc | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/target/riscv/tcg/insn_trans/trans_rvzalasr.c.inc b/target/riscv/tcg/insn_trans/trans_rvzalasr.c.inc
index 79b0b2c63b..28d9b13c55 100644
--- a/target/riscv/tcg/insn_trans/trans_rvzalasr.c.inc
+++ b/target/riscv/tcg/insn_trans/trans_rvzalasr.c.inc
@@ -86,6 +86,14 @@ static bool gen_store_release(DisasContext *ctx, arg_sb_aqrl *a, MemOp memop)
tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL | bar);
tcg_gen_qemu_st_tl(data, addr, ctx->mem_idx, memop);
+
+ /*
+ * Zalasr annotations are always RCsc: per RVWMO Rule 7, the store
+ * must also be ordered before any subsequent memory operation,
+ * e.g. a load-acquire in a Store Buffering litmus test. The
+ * barrier above only orders previous memory ops before the store.
+ */
+ tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
return true;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 1/3] target/riscv: Fix RCsc ordering of Zalasr store-release
2026-08-21 6:40 ` [PATCH 1/3] target/riscv: Fix RCsc ordering of Zalasr store-release LIU Zhiwei
@ 2026-08-24 12:30 ` Daniel Henrique Barboza
0 siblings, 0 replies; 10+ messages in thread
From: Daniel Henrique Barboza @ 2026-08-24 12:30 UTC (permalink / raw)
To: LIU Zhiwei, qemu-devel, qemu-riscv, qemu-arm
Cc: palmer, alistair.francis, liwei1518, chao.liu, peter.maydell,
richard.henderson, TANG TianCheng
On 8/21/2026 3:40 AM, LIU Zhiwei wrote:
> The Zalasr load-acquire instructions carry an acquire-RCsc annotation
> and the store-release instructions carry a release-RCsc annotation;
> the extension has no RCpc variant (Zalasr specification, chapter 2).
>
> Per Rule 7 of the RVWMO preserved program order rules ("a and b both
> have RCsc annotations"), a Zalasr store-release must precede any
> subsequent RCsc memory operation of the same hart in the global
> memory order. In particular "sw.rl X=1; lw.aq r1=Y" must be ordered,
> which is what forbids the [0,0] outcome of a Store Buffering litmus
> test that runs this pair on two harts.
>
> gen_store_release() only emits a barrier before the store, which
> orders the memory operations preceding the store before the store
> itself (Rule 6, release semantics). Nothing prevents the store from
> being reordered with the memory operations that follow it, so under
> MTTCG the host CPU may execute the load-acquire that immediately
> follows a store-release before the store has left its store buffer:
>
> * on an x86 host (TSO), store-load is the only reordering the
> hardware may perform, and it is exactly the ordering that is
> missing here;
>
> * on an aarch64 host, no dmb follows the store either.
>
> The defect is easily observed with a bare-metal Store Buffering
> litmus test on a 4 vCPU guest: "sw.rl X=1; lw.aq r1=Y" on hart 0 and
> "sw.rl Y=1; lw.aq r2=X" on hart 1 produce the architecturally
> forbidden [0,0] result in 89881 out of 100000 iterations.
>
> Fix this by emitting a full barrier after the store as well, which
> mirrors the FENCE translation. The TCG_MO_ST_LD bit included in
> TCG_MO_ALL makes the x86 backend emit a serializing lock-prefixed
> instruction after the store, draining the store buffer before any
> subsequent load executes, and the aarch64 backend emit dmb ish; the
> store therefore becomes globally visible before any subsequent memory
> operation of the same vCPU, and Rule 7 is satisfied. This is
> stronger than Rule 7 strictly requires, since the barrier also orders
> the store with respect to subsequent non-RCsc operations, but this
> matches how QEMU already implements FENCE and keeps the fix simple.
>
> The load-acquire side needs no change: the barrier emitted after the
> load already orders it with all subsequent memory operations, which
> covers Rule 5 and the remaining Rule 7 combinations (load-load and
> load-store).
>
> Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
> Co-authored-by: TANG TianCheng <tangtiancheng.ttc@alibaba-inc.com>
> Signed-off-by: TANG TianCheng <tangtiancheng.ttc@alibaba-inc.com>
> ---
Reviewed-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
> target/riscv/tcg/insn_trans/trans_rvzalasr.c.inc | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/target/riscv/tcg/insn_trans/trans_rvzalasr.c.inc b/target/riscv/tcg/insn_trans/trans_rvzalasr.c.inc
> index 79b0b2c63b..28d9b13c55 100644
> --- a/target/riscv/tcg/insn_trans/trans_rvzalasr.c.inc
> +++ b/target/riscv/tcg/insn_trans/trans_rvzalasr.c.inc
> @@ -86,6 +86,14 @@ static bool gen_store_release(DisasContext *ctx, arg_sb_aqrl *a, MemOp memop)
> tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL | bar);
>
> tcg_gen_qemu_st_tl(data, addr, ctx->mem_idx, memop);
> +
> + /*
> + * Zalasr annotations are always RCsc: per RVWMO Rule 7, the store
> + * must also be ordered before any subsequent memory operation,
> + * e.g. a load-acquire in a Store Buffering litmus test. The
> + * barrier above only orders previous memory ops before the store.
> + */
> + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
> return true;
> }
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/3] target/arm: Fix RCsc ordering of store-release instructions
2026-08-21 6:40 [PATCH 0/3] Fix RCsc store->load ordering of release stores LIU Zhiwei
2026-08-21 6:40 ` [PATCH 1/3] target/riscv: Fix RCsc ordering of Zalasr store-release LIU Zhiwei
@ 2026-08-21 6:40 ` LIU Zhiwei
2026-11-16 18:41 ` Alex Bennée
2026-11-16 18:53 ` Alex Bennée
2026-08-21 6:40 ` [PATCH 3/3] target/arm: Fix barrier polarity of A32 LDA load-acquire LIU Zhiwei
2026-11-16 19:31 ` [PATCH 0/3] Fix RCsc store->load ordering of release stores Peter Maydell
3 siblings, 2 replies; 10+ messages in thread
From: LIU Zhiwei @ 2026-08-21 6:40 UTC (permalink / raw)
To: qemu-devel, qemu-riscv, qemu-arm
Cc: palmer, alistair.francis, liwei1518, daniel.barboza, chao.liu,
zhiwei_liu, peter.maydell, richard.henderson
The Armv8 memory model has no RCpc store: every store-release in the
architecture, including the AArch64 STLR and STLPUR and the A32/T32
STL, STLB and STLH, carries RCsc semantics (Arm Architecture Reference
Manual, DDI 0487, section B2.3.8 "Acquire and release semantics").
The architecture therefore orders a Store-Release tagged RCsc before
any subsequent Load-Acquire tagged RCsc of the same shareability
domain, which is what forbids the [0,0] outcome of a Store Buffering
litmus test that pairs "STLR X=1; LDAR Y" on one PE with
"STLR Y=1; LDAR X" on another.
The translators only emit a barrier before the store, which orders the
memory operations preceding the store before the store itself (release
semantics). Nothing prevents the store from being reordered with the
memory operations that follow it, so under MTTCG the host CPU may
execute the load-acquire that immediately follows a store-release
before the store has left its store buffer:
* on an x86 host (TSO), store-load is the only reordering the
hardware may perform, and it is exactly the ordering that is
missing here;
* on an aarch64 host, no dmb follows the store either.
The defect is easily observed with a bare-metal Store Buffering litmus
test on a 2 vCPU virt guest: "STLR X=1; LDAR Y" on CPU 0 and
"STLR Y=1; LDAR X" on CPU 1 produce the architecturally forbidden [0,0]
result in 6 to 7 out of 100000 iterations, while inserting a DMB ISH
between the store and the load on each CPU brings the number to 0,
which validates the harness.
Fix this by emitting a full barrier after the store as well, for
STLR/STLLR and STLPUR on the AArch64 side and STL/STLB/STLH on the
A32/T32 side. The TCG_MO_ST_LD bit included in TCG_MO_ALL makes the
x86 backend emit a serializing lock-prefixed instruction after the
store, draining the store buffer before any subsequent load executes,
and the aarch64 backend emit dmb ish; the store therefore becomes
globally visible before any subsequent memory operation of the same
vCPU, and the RCsc store->load ordering is satisfied. This is
stronger than the architecture strictly requires, since the barrier
also orders the store with respect to subsequent RCpc operations such
as LDAPR, but this matches how QEMU already implements FENCE-like
ordering and keeps the fix simple. After the fix the litmus test no
longer produces the forbidden outcome.
The load-acquire side needs no change: the barrier emitted after an
RCsc LDAR already orders it with all subsequent memory operations, and
QEMU deliberately implements the RCpc LDAPR family as full load-acquire.
Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
---
target/arm/tcg/translate-a64.c | 13 +++++++++++++
target/arm/tcg/translate.c | 6 ++++++
2 files changed, 19 insertions(+)
diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c
index 4f9a93950b..b5bf977910 100644
--- a/target/arm/tcg/translate-a64.c
+++ b/target/arm/tcg/translate-a64.c
@@ -3672,6 +3672,13 @@ static bool trans_STLR(DisasContext *s, arg_stlr *a)
true, a->rn != 31, memop);
do_gpr_st(s, cpu_reg(s, a->rt), clean_addr, memop, true, a->rt,
iss_sf, a->lasr);
+ /*
+ * STLR is an RCsc store-release: the Armv8 architecture orders it
+ * before any subsequent RCsc load-acquire, which is what forbids the
+ * store-buffering litmus test. The barrier above only orders
+ * previous accesses before the store.
+ */
+ tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
return true;
}
@@ -4415,6 +4422,12 @@ static bool trans_STLR_i(DisasContext *s, arg_ldapr_stlr_i *a)
/* Store-Release semantics */
tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
do_gpr_st(s, cpu_reg(s, a->rt), clean_addr, mop, true, a->rt, iss_sf, true);
+ /*
+ * Like STLR, STLPUR is an RCsc store-release and must be ordered
+ * before any subsequent RCsc load-acquire, so it needs a barrier
+ * after the store as well.
+ */
+ tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
return true;
}
diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c
index 1770428d3c..bddac41bf9 100644
--- a/target/arm/tcg/translate.c
+++ b/target/arm/tcg/translate.c
@@ -4259,6 +4259,12 @@ static bool op_stl(DisasContext *s, arg_STL *a, MemOp mop)
tmp = load_reg(s, a->rt);
tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
gen_aa32_st_i32(s, tmp, addr, get_mem_index(s), mop | MO_ALIGN);
+ /*
+ * STL has the same RCsc store-release semantics as the AArch64 STLR
+ * and must be ordered before a subsequent RCsc load-acquire (LDA).
+ * The barrier above only orders previous accesses before the store.
+ */
+ tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
disas_set_da_iss(s, mop, a->rt | ISSIsAcqRel | ISSIsWrite);
return true;
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 2/3] target/arm: Fix RCsc ordering of store-release instructions
2026-08-21 6:40 ` [PATCH 2/3] target/arm: Fix RCsc ordering of store-release instructions LIU Zhiwei
@ 2026-11-16 18:41 ` Alex Bennée
2026-11-16 18:53 ` Alex Bennée
1 sibling, 0 replies; 10+ messages in thread
From: Alex Bennée @ 2026-11-16 18:41 UTC (permalink / raw)
To: LIU Zhiwei
Cc: qemu-devel, qemu-riscv, qemu-arm, palmer, alistair.francis,
liwei1518, daniel.barboza, chao.liu, peter.maydell,
richard.henderson
LIU Zhiwei <zhiwei_liu@linux.alibaba.com> writes:
> The Armv8 memory model has no RCpc store: every store-release in the
> architecture, including the AArch64 STLR and STLPUR and the A32/T32
> STL, STLB and STLH, carries RCsc semantics (Arm Architecture Reference
> Manual, DDI 0487, section B2.3.8 "Acquire and release semantics").
> The architecture therefore orders a Store-Release tagged RCsc before
> any subsequent Load-Acquire tagged RCsc of the same shareability
> domain, which is what forbids the [0,0] outcome of a Store Buffering
> litmus test that pairs "STLR X=1; LDAR Y" on one PE with
> "STLR Y=1; LDAR X" on another.
>
> The translators only emit a barrier before the store, which orders the
> memory operations preceding the store before the store itself (release
> semantics). Nothing prevents the store from being reordered with the
> memory operations that follow it, so under MTTCG the host CPU may
> execute the load-acquire that immediately follows a store-release
> before the store has left its store buffer:
>
> * on an x86 host (TSO), store-load is the only reordering the
> hardware may perform, and it is exactly the ordering that is
> missing here;
>
> * on an aarch64 host, no dmb follows the store either.
>
> The defect is easily observed with a bare-metal Store Buffering litmus
> test on a 2 vCPU virt guest: "STLR X=1; LDAR Y" on CPU 0 and
> "STLR Y=1; LDAR X" on CPU 1 produce the architecturally forbidden [0,0]
> result in 6 to 7 out of 100000 iterations, while inserting a DMB ISH
> between the store and the load on each CPU brings the number to 0,
> which validates the harness.
>
> Fix this by emitting a full barrier after the store as well, for
> STLR/STLLR and STLPUR on the AArch64 side and STL/STLB/STLH on the
> A32/T32 side. The TCG_MO_ST_LD bit included in TCG_MO_ALL makes the
> x86 backend emit a serializing lock-prefixed instruction after the
> store, draining the store buffer before any subsequent load executes,
> and the aarch64 backend emit dmb ish; the store therefore becomes
> globally visible before any subsequent memory operation of the same
> vCPU, and the RCsc store->load ordering is satisfied. This is
> stronger than the architecture strictly requires, since the barrier
> also orders the store with respect to subsequent RCpc operations such
> as LDAPR, but this matches how QEMU already implements FENCE-like
> ordering and keeps the fix simple. After the fix the litmus test no
> longer produces the forbidden outcome.
>
> The load-acquire side needs no change: the barrier emitted after an
> RCsc LDAR already orders it with all subsequent memory operations, and
> QEMU deliberately implements the RCpc LDAPR family as full load-acquire.
>
> Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
> ---
> target/arm/tcg/translate-a64.c | 13 +++++++++++++
> target/arm/tcg/translate.c | 6 ++++++
> 2 files changed, 19 insertions(+)
>
> diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c
> index 4f9a93950b..b5bf977910 100644
> --- a/target/arm/tcg/translate-a64.c
> +++ b/target/arm/tcg/translate-a64.c
> @@ -3672,6 +3672,13 @@ static bool trans_STLR(DisasContext *s, arg_stlr *a)
> true, a->rn != 31, memop);
> do_gpr_st(s, cpu_reg(s, a->rt), clean_addr, memop, true, a->rt,
> iss_sf, a->lasr);
> + /*
> + * STLR is an RCsc store-release: the Armv8 architecture orders it
> + * before any subsequent RCsc load-acquire, which is what forbids the
> + * store-buffering litmus test. The barrier above only orders
> + * previous accesses before the store.
> + */
> + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
> return true;
> }
>
> @@ -4415,6 +4422,12 @@ static bool trans_STLR_i(DisasContext *s, arg_ldapr_stlr_i *a)
> /* Store-Release semantics */
> tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
> do_gpr_st(s, cpu_reg(s, a->rt), clean_addr, mop, true, a->rt, iss_sf, true);
> + /*
> + * Like STLR, STLPUR is an RCsc store-release and must be ordered
> + * before any subsequent RCsc load-acquire, so it needs a barrier
> + * after the store as well.
> + */
> + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
> return true;
> }
>
> diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c
> index 1770428d3c..bddac41bf9 100644
> --- a/target/arm/tcg/translate.c
> +++ b/target/arm/tcg/translate.c
> @@ -4259,6 +4259,12 @@ static bool op_stl(DisasContext *s, arg_STL *a, MemOp mop)
> tmp = load_reg(s, a->rt);
> tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
> gen_aa32_st_i32(s, tmp, addr, get_mem_index(s), mop | MO_ALIGN);
> + /*
> + * STL has the same RCsc store-release semantics as the AArch64 STLR
> + * and must be ordered before a subsequent RCsc load-acquire (LDA).
> + * The barrier above only orders previous accesses before the store.
> + */
> + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
> disas_set_da_iss(s, mop, a->rt | ISSIsAcqRel | ISSIsWrite);
>
> return true;
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4872
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/3] target/arm: Fix RCsc ordering of store-release instructions
2026-08-21 6:40 ` [PATCH 2/3] target/arm: Fix RCsc ordering of store-release instructions LIU Zhiwei
2026-11-16 18:41 ` Alex Bennée
@ 2026-11-16 18:53 ` Alex Bennée
1 sibling, 0 replies; 10+ messages in thread
From: Alex Bennée @ 2026-11-16 18:53 UTC (permalink / raw)
To: LIU Zhiwei
Cc: qemu-devel, qemu-riscv, qemu-arm, palmer, alistair.francis,
liwei1518, daniel.barboza, chao.liu, peter.maydell,
richard.henderson
LIU Zhiwei <zhiwei_liu@linux.alibaba.com> writes:
> The Armv8 memory model has no RCpc store: every store-release in the
> architecture, including the AArch64 STLR and STLPUR and the A32/T32
> STL, STLB and STLH, carries RCsc semantics (Arm Architecture Reference
> Manual, DDI 0487, section B2.3.8 "Acquire and release semantics").
> The architecture therefore orders a Store-Release tagged RCsc before
> any subsequent Load-Acquire tagged RCsc of the same shareability
> domain, which is what forbids the [0,0] outcome of a Store Buffering
> litmus test that pairs "STLR X=1; LDAR Y" on one PE with
> "STLR Y=1; LDAR X" on another.
<snip>
Tested-by: Alex Bennée <alex.bennee@linaro.org>
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/3] target/arm: Fix barrier polarity of A32 LDA load-acquire
2026-08-21 6:40 [PATCH 0/3] Fix RCsc store->load ordering of release stores LIU Zhiwei
2026-08-21 6:40 ` [PATCH 1/3] target/riscv: Fix RCsc ordering of Zalasr store-release LIU Zhiwei
2026-08-21 6:40 ` [PATCH 2/3] target/arm: Fix RCsc ordering of store-release instructions LIU Zhiwei
@ 2026-08-21 6:40 ` LIU Zhiwei
2026-11-16 19:31 ` [PATCH 0/3] Fix RCsc store->load ordering of release stores Peter Maydell
3 siblings, 0 replies; 10+ messages in thread
From: LIU Zhiwei @ 2026-08-21 6:40 UTC (permalink / raw)
To: qemu-devel, qemu-riscv, qemu-arm
Cc: palmer, alistair.francis, liwei1518, daniel.barboza, chao.liu,
zhiwei_liu, peter.maydell, richard.henderson
The A32 and T32 load-acquire instructions LDA, LDAB and LDAH must be
ordered before the memory accesses that follow them, so their
translator has to emit a trailing barrier. op_lda() emits that barrier
with TCG_BAR_STRL instead of TCG_BAR_LDAQ, inverting the polarity:
TCG_BAR_STRL annotates a leading barrier ("previous ops will not be
delayed") and TCG_BAR_LDAQ a trailing one ("following ops will not come
forward"), as documented in include/tcg/tcg-mo.h.
The x86 and aarch64 backends only look at the TCG_MO_* bits, which the
wrong annotation does not affect, so the generated host code is
unchanged on those hosts. The annotation is still wrong: it violates
the TCG barrier contract, it lets the optimizer's barrier merging in
fold_mb() combine the barriers of an "LDA; STL" pair into a weaker one
than the correctly annotated form (STRL|STRL stays STRL instead of
LDAQ|STRL = SC), and it diverges from every other load-acquire
translation in the target, which all use TCG_BAR_LDAQ.
Fix the polarity.
Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
---
target/arm/tcg/translate.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c
index bddac41bf9..a81b8d3852 100644
--- a/target/arm/tcg/translate.c
+++ b/target/arm/tcg/translate.c
@@ -4421,7 +4421,7 @@ static bool op_lda(DisasContext *s, arg_LDA *a, MemOp mop)
disas_set_da_iss(s, mop, a->rt | ISSIsAcqRel);
store_reg(s, a->rt, tmp);
- tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
+ tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ);
return true;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 0/3] Fix RCsc store->load ordering of release stores
2026-08-21 6:40 [PATCH 0/3] Fix RCsc store->load ordering of release stores LIU Zhiwei
` (2 preceding siblings ...)
2026-08-21 6:40 ` [PATCH 3/3] target/arm: Fix barrier polarity of A32 LDA load-acquire LIU Zhiwei
@ 2026-11-16 19:31 ` Peter Maydell
2026-11-17 2:31 ` Alistair Francis
3 siblings, 1 reply; 10+ messages in thread
From: Peter Maydell @ 2026-11-16 19:31 UTC (permalink / raw)
To: LIU Zhiwei
Cc: qemu-devel, qemu-riscv, qemu-arm, palmer, alistair.francis,
liwei1518, daniel.barboza, chao.liu, richard.henderson
On Fri, 21 Aug 2026 at 07:40, LIU Zhiwei <zhiwei_liu@linux.alibaba.com> wrote:
>
> Several guest architectures give their store-release instructions RCsc
> semantics, which requires the store to be ordered not only after the
> memory operations that precede it, but also before any subsequent
> load-acquire with RCsc semantics. The TCG translators, however, only
> emit the leading barrier before the store, so under MTTCG nothing
> prevents the host CPU from executing the load-acquire that follows a
> store-release before the store has left its store buffer. On an x86
> host (TSO), store-load is the only reordering the hardware may
> perform, and it is exactly the ordering that is missing, so the
> architecturally forbidden [0,0] outcome of the Store Buffering litmus
> test is easy to observe:
>
> CPU 0 CPU 1
> store-release X = 1 store-release Y = 1
> load-acquire r0 = Y load-acquire r1 = X
>
> The affected instructions are the RISC-V Zalasr store-release
> instructions and the Arm STLR, STLPUR and A32/T32 STL store-release
> instructions. Neither architecture defines an RCpc store, so every
> store-release is RCsc (RVWMO preserved program order Rule 7; Arm
> Architecture Reference Manual DDI 0487, section B2.3.8 "Acquire and
> release semantics").
>
> Patch 1 fixes the RISC-V side and patch 2 the Arm side by emitting a
> full barrier after the store as well. Patch 3 fixes an inverted
> barrier polarity found in the A32 LDA load-acquire translator while
> auditing the load-acquire side.
> LIU Zhiwei (3):
> target/riscv: Fix RCsc ordering of Zalasr store-release
> target/arm: Fix RCsc ordering of store-release instructions
> target/arm: Fix barrier polarity of A32 LDA load-acquire
This series seems to have been accidentally missed, possibly
because it included both arm and riscv patches in the same
patchset. RTH tells me that the Arm patches are correct, and
Daniel has reviewed the riscv one.
riscv maintainers: are you OK with me queuing the whole set
including the riscv patch in target-arm.next, or would you
prefer to take the riscv patch yourself through your queue?
thanks
-- PMM
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 0/3] Fix RCsc store->load ordering of release stores
2026-11-16 19:31 ` [PATCH 0/3] Fix RCsc store->load ordering of release stores Peter Maydell
@ 2026-11-17 2:31 ` Alistair Francis
2026-11-17 10:34 ` Peter Maydell
0 siblings, 1 reply; 10+ messages in thread
From: Alistair Francis @ 2026-11-17 2:31 UTC (permalink / raw)
To: peter.maydell@linaro.org, zhiwei_liu@linux.alibaba.com
Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org,
daniel.barboza@oss.qualcomm.com, qemu-riscv@nongnu.org,
chao.liu@processmission.com, palmer@dabbelt.com,
richard.henderson@linaro.org, liwei1518@gmail.com
On Mon, 2026-11-16 at 19:31 +0000, Peter Maydell wrote:
> On Fri, 21 Aug 2026 at 07:40, LIU Zhiwei
> <zhiwei_liu@linux.alibaba.com> wrote:
> >
> > Several guest architectures give their store-release instructions
> > RCsc
> > semantics, which requires the store to be ordered not only after
> > the
> > memory operations that precede it, but also before any subsequent
> > load-acquire with RCsc semantics. The TCG translators, however,
> > only
> > emit the leading barrier before the store, so under MTTCG nothing
> > prevents the host CPU from executing the load-acquire that follows
> > a
> > store-release before the store has left its store buffer. On an
> > x86
> > host (TSO), store-load is the only reordering the hardware may
> > perform, and it is exactly the ordering that is missing, so the
> > architecturally forbidden [0,0] outcome of the Store Buffering
> > litmus
> > test is easy to observe:
> >
> > CPU 0 CPU 1
> > store-release X = 1 store-release Y = 1
> > load-acquire r0 = Y load-acquire r1 = X
> >
> > The affected instructions are the RISC-V Zalasr store-release
> > instructions and the Arm STLR, STLPUR and A32/T32 STL store-release
> > instructions. Neither architecture defines an RCpc store, so every
> > store-release is RCsc (RVWMO preserved program order Rule 7; Arm
> > Architecture Reference Manual DDI 0487, section B2.3.8 "Acquire and
> > release semantics").
> >
> > Patch 1 fixes the RISC-V side and patch 2 the Arm side by emitting
> > a
> > full barrier after the store as well. Patch 3 fixes an inverted
> > barrier polarity found in the A32 LDA load-acquire translator while
> > auditing the load-acquire side.
>
> > LIU Zhiwei (3):
> > target/riscv: Fix RCsc ordering of Zalasr store-release
> > target/arm: Fix RCsc ordering of store-release instructions
> > target/arm: Fix barrier polarity of A32 LDA load-acquire
>
> This series seems to have been accidentally missed, possibly
> because it included both arm and riscv patches in the same
> patchset. RTH tells me that the Arm patches are correct, and
> Daniel has reviewed the riscv one.
>
> riscv maintainers: are you OK with me queuing the whole set
> including the riscv patch in target-arm.next, or would you
> prefer to take the riscv patch yourself through your queue?
Thanks for checking, this is fine to go via target-arm.next
Alistair
>
> thanks
> -- PMM
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/3] Fix RCsc store->load ordering of release stores
2026-11-17 2:31 ` Alistair Francis
@ 2026-11-17 10:34 ` Peter Maydell
0 siblings, 0 replies; 10+ messages in thread
From: Peter Maydell @ 2026-11-17 10:34 UTC (permalink / raw)
To: Alistair Francis
Cc: zhiwei_liu@linux.alibaba.com, qemu-devel@nongnu.org,
qemu-arm@nongnu.org, daniel.barboza@oss.qualcomm.com,
qemu-riscv@nongnu.org, chao.liu@processmission.com,
palmer@dabbelt.com, richard.henderson@linaro.org,
liwei1518@gmail.com
On Tue, 17 Nov 2026 at 02:31, Alistair Francis <Alistair.Francis@wdc.com> wrote:
>
> On Mon, 2026-11-16 at 19:31 +0000, Peter Maydell wrote:
> > On Fri, 21 Aug 2026 at 07:40, LIU Zhiwei
> > <zhiwei_liu@linux.alibaba.com> wrote:
> > >
> > > Several guest architectures give their store-release instructions
> > > RCsc
> > > semantics, which requires the store to be ordered not only after
> > > the
> > > memory operations that precede it, but also before any subsequent
> > > load-acquire with RCsc semantics. The TCG translators, however,
> > > only
> > > emit the leading barrier before the store, so under MTTCG nothing
> > > prevents the host CPU from executing the load-acquire that follows
> > > a
> > > store-release before the store has left its store buffer. On an
> > > x86
> > > host (TSO), store-load is the only reordering the hardware may
> > > perform, and it is exactly the ordering that is missing, so the
> > > architecturally forbidden [0,0] outcome of the Store Buffering
> > > litmus
> > > test is easy to observe:
> > >
> > > CPU 0 CPU 1
> > > store-release X = 1 store-release Y = 1
> > > load-acquire r0 = Y load-acquire r1 = X
> > >
> > > The affected instructions are the RISC-V Zalasr store-release
> > > instructions and the Arm STLR, STLPUR and A32/T32 STL store-release
> > > instructions. Neither architecture defines an RCpc store, so every
> > > store-release is RCsc (RVWMO preserved program order Rule 7; Arm
> > > Architecture Reference Manual DDI 0487, section B2.3.8 "Acquire and
> > > release semantics").
> > >
> > > Patch 1 fixes the RISC-V side and patch 2 the Arm side by emitting
> > > a
> > > full barrier after the store as well. Patch 3 fixes an inverted
> > > barrier polarity found in the A32 LDA load-acquire translator while
> > > auditing the load-acquire side.
> >
> > > LIU Zhiwei (3):
> > > target/riscv: Fix RCsc ordering of Zalasr store-release
> > > target/arm: Fix RCsc ordering of store-release instructions
> > > target/arm: Fix barrier polarity of A32 LDA load-acquire
> >
> > This series seems to have been accidentally missed, possibly
> > because it included both arm and riscv patches in the same
> > patchset. RTH tells me that the Arm patches are correct, and
> > Daniel has reviewed the riscv one.
> >
> > riscv maintainers: are you OK with me queuing the whole set
> > including the riscv patch in target-arm.next, or would you
> > prefer to take the riscv patch yourself through your queue?
>
> Thanks for checking, this is fine to go via target-arm.next
OK, I've queued it there. I added a cc:stable tag on all the
patches since they look like bug fixes that deserve backporting.
-- PMM
^ permalink raw reply [flat|nested] 10+ messages in thread