[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/5] tcg: Do not elide memory barriers for CF_PARALLEL
From: |
Richard Henderson |
Subject: |
[PATCH 2/5] tcg: Do not elide memory barriers for CF_PARALLEL |
Date: |
Tue, 16 Mar 2021 16:07:32 -0600 |
The virtio devices require proper memory ordering between
the vcpus and the iothreads.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tcg/tcg-op.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 70475773f4..76dc7d8dc5 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -97,9 +97,13 @@ void tcg_gen_op6(TCGOpcode opc, TCGArg a1, TCGArg a2, TCGArg
a3,
void tcg_gen_mb(TCGBar mb_type)
{
- if (tcg_ctx->tb_cflags & CF_PARALLEL) {
- tcg_gen_op1(INDEX_op_mb, mb_type);
- }
+ /*
+ * It is tempting to elide the barrier in a single-threaded context
+ * (i.e. !(tb_cflags & CF_PARALLEL)), however, even with a single cpu
+ * we have i/o threads running in parallel, and lack of memory order
+ * can result in e.g. virtio queue entries being read incorrectly.
+ */
+ tcg_gen_op1(INDEX_op_mb, mb_type);
}
/* 32 bit ops */
--
2.25.1
- [PATCH 0/5] tcg: Issue memory barriers for guest memory model, Richard Henderson, 2021/03/16
- [PATCH 1/5] tcg: Decode the operand to INDEX_op_mb in dumps, Richard Henderson, 2021/03/16
- [PATCH 2/5] tcg: Do not elide memory barriers for CF_PARALLEL,
Richard Henderson <=
- [PATCH 3/5] tcg: Elide memory barriers implied by the host memory model, Richard Henderson, 2021/03/16
- [PATCH 5/5] tcg: Add host memory barriers to cpu_ldst.h interfaces, Richard Henderson, 2021/03/16
- [PATCH 4/5] tcg: Create tcg_req_mo, Richard Henderson, 2021/03/16
- Re: [PATCH 0/5] tcg: Issue memory barriers for guest memory model, no-reply, 2021/03/16