Skip to content

Commit

Permalink
tcg: Do not elide memory barriers for !CF_PARALLEL in system mode
Browse files Browse the repository at this point in the history
The virtio devices require proper memory ordering between
the vcpus and the iothreads.

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Richard Henderson <[email protected]>

(cherry picked from commit c914d46d0a645e7c633292146f4e38c945d4f847)
  • Loading branch information
rth7680 authored and jrtc27 committed Aug 17, 2023
1 parent 475b990 commit 4fb6c37
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tcg/tcg-op.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,19 @@ 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) {
#ifdef CONFIG_USER_ONLY
bool parallel = tcg_ctx->tb_cflags & CF_PARALLEL;
#else
/*
* It is tempting to elide the barrier in a uniprocessor context.
* 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.
*/
bool parallel = true;
#endif

if (parallel) {
tcg_gen_op1(INDEX_op_mb, mb_type);
}
}
Expand Down

0 comments on commit 4fb6c37

Please sign in to comment.