qemu-e2k/include
Paolo Bonzini ff00bed189 qatomic: add smp_mb__before/after_rmw()
On ARM, seqcst loads and stores (which QEMU does not use) are compiled
respectively as LDAR and STLR instructions.  Even though LDAR is
also used for load-acquire operations, it also waits for all STLRs to
leave the store buffer.  Thus, LDAR and STLR alone are load-acquire
and store-release operations, but LDAR also provides store-against-load
ordering as long as the previous store is a STLR.

Compare this to ARMv7, where store-release is DMB+STR and load-acquire
is LDR+DMB, but an additional DMB is needed between store-seqcst and
load-seqcst (e.g. DMB+STR+DMB+LDR+DMB); or with x86, where MOV provides
load-acquire and store-release semantics and the two can be reordered.

Likewise, on ARM sequentially consistent read-modify-write operations only
need to use LDAXR and STLXR respectively for the load and the store, while
on x86 they need to use the stronger LOCK prefix.

In a strange twist of events, however, the _stronger_ semantics
of the ARM instructions can end up causing bugs on ARM, not on x86.
The problems occur when seqcst atomics are mixed with relaxed atomics.

QEMU's atomics try to bridge the Linux API (that most of the developers
are familiar with) and the C11 API, and the two have a substantial
difference:

- in Linux, strongly-ordered atomics such as atomic_add_return() affect
  the global ordering of _all_ memory operations, including for example
  READ_ONCE()/WRITE_ONCE()

- in C11, sequentially consistent atomics (except for seq-cst fences)
  only affect the ordering of sequentially consistent operations.
  In particular, since relaxed loads are done with LDR on ARM, they are
  not ordered against seqcst stores (which are done with STLR).

QEMU implements high-level synchronization primitives with the idea that
the primitives contain the necessary memory barriers, and the callers can
use relaxed atomics (qatomic_read/qatomic_set) or even regular accesses.
This is very much incompatible with the C11 view that seqcst accesses
are only ordered against other seqcst accesses, and requires using seqcst
fences as in the following example:

   qatomic_set(&y, 1);            qatomic_set(&x, 1);
   smp_mb();                      smp_mb();
   ... qatomic_read(&x) ...       ... qatomic_read(&y) ...

When a qatomic_*() read-modify write operation is used instead of one
or both stores, developers that are more familiar with the Linux API may
be tempted to omit the smp_mb(), which will work on x86 but not on ARM.

This nasty difference between Linux and C11 read-modify-write operations
has already caused issues in util/async.c and more are being found.
Provide something similar to Linux smp_mb__before/after_atomic(); this
has the double function of documenting clearly why there is a memory
barrier, and avoiding a double barrier on x86 and s390x systems.

The new macro can already be put to use in qatomic_mb_set().

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2023-03-07 12:38:40 +01:00
..
authz Prefer 'on' | 'off' over 'yes' | 'no' for bool options 2021-01-29 17:07:53 +00:00
block block: Mark bdrv_co_refresh_total_sectors() and callers GRAPH_RDLOCK 2023-02-23 19:49:33 +01:00
chardev chardev: src buffer const for write functions 2022-09-29 14:38:05 +04:00
crypto crypto: TLS: introduce check_pending 2023-02-15 11:01:03 -05:00
disas remove unnecessary extern "C" blocks 2023-02-10 14:12:06 +01:00
exec exec/gen-icount: Don't use tcg_temp_local_new_i32 2023-03-01 07:33:28 -10:00
fpu fpu: Add rebias bool, value and operation 2022-08-31 14:08:05 -03:00
hw hw/xen: Subsume xen_be_register_common() into xen_be_init() 2023-03-01 09:09:22 +00:00
io io: Add support for MSG_PEEK for socket channel 2023-02-06 19:22:56 +01:00
libdecnumber Replace config-time define HOST_WORDS_BIGENDIAN 2022-04-06 10:50:37 +02:00
migration migration: Rename res_{postcopy,precopy}_only 2023-02-15 20:04:30 +01:00
monitor i386/xen: add monitor commands to test event injection 2023-03-01 08:22:50 +00:00
net net: Move the code to collect available NIC models to a separate function 2023-02-17 13:31:33 +08:00
qapi rocker: Tweak stubbed out monitor commands' error messages 2023-02-23 14:10:17 +01:00
qemu qatomic: add smp_mb__before/after_rmw() 2023-03-07 12:38:40 +01:00
qom qom/object: Remove circular include dependency 2022-06-28 10:53:32 +02:00
scsi coroutine: Clean up superfluous inclusion of qemu/coroutine.h 2023-01-19 10:18:28 +01:00
semihosting semihosting: Allow optional use of semihosting from userspace 2022-09-13 17:18:21 +01:00
standard-headers linux-headers: Update to v6.2-rc8 2023-02-16 12:13:46 -07:00
sysemu kvm/i386: Add xen-evtchn-max-pirq property 2023-03-01 09:09:22 +00:00
tcg tcg: Remove tcg_temp_local_new_*, tcg_const_local_* 2023-03-01 07:33:28 -10:00
ui Do not include "qemu/error-report.h" in headers that do not need it 2023-02-14 09:11:27 +01:00
user include: Include headers where needed 2023-01-08 01:54:22 -05:00
elf.h include/elf.h: add s390x note types 2022-10-26 12:54:59 +04:00
glib-compat.h compiler.h: replace QEMU_NORETURN with G_NORETURN 2022-04-21 17:03:51 +04:00
qemu-io.h
qemu-main.h ui/cocoa: Run qemu_init in the main thread 2022-09-23 14:36:33 +02:00