Skip to content

Commit 83dc037

Browse files
Yufeng Wangmstsirkin
authored andcommitted
tools: virtio/linux/compiler.h: Add data_race() define.
Port over the definition of data_race() so we can build tools/virtio. cc -g -O2 -Werror -Wno-maybe-uninitialized -Wall -I. -I../include/ -I ../../usr/include/ -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE -include ../../include/linux/kconfig.h -mfunction-return=thunk -fcf-protection=none -mindirect-branch-register -pthread -c -o virtio_ring.o ../../drivers/virtio/virtio_ring.c ../../drivers/virtio/virtio_ring.c: in function'vring_interrupt': ../../drivers/virtio/virtio_ring.c:2711:17: error:Implicit declaration function'data_race' [-Wimplicit-function-declaration] 2711 | data_race(vq->event_triggered = true); | ^~~~~~~~~ Signed-off-by: Yufeng Wang <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent ae37691 commit 83dc037

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tools/virtio/linux/compiler.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,29 @@
1010
#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var))))
1111

1212
#define __aligned(x) __attribute((__aligned__(x)))
13+
14+
/**
15+
* data_race - mark an expression as containing intentional data races
16+
*
17+
* This data_race() macro is useful for situations in which data races
18+
* should be forgiven. One example is diagnostic code that accesses
19+
* shared variables but is not a part of the core synchronization design.
20+
* For example, if accesses to a given variable are protected by a lock,
21+
* except for diagnostic code, then the accesses under the lock should
22+
* be plain C-language accesses and those in the diagnostic code should
23+
* use data_race(). This way, KCSAN will complain if buggy lockless
24+
* accesses to that variable are introduced, even if the buggy accesses
25+
* are protected by READ_ONCE() or WRITE_ONCE().
26+
*
27+
* This macro *does not* affect normal code generation, but is a hint
28+
* to tooling that data races here are to be ignored. If the access must
29+
* be atomic *and* KCSAN should ignore the access, use both data_race()
30+
* and READ_ONCE(), for example, data_race(READ_ONCE(x)).
31+
*/
32+
#define data_race(expr) \
33+
({ \
34+
__auto_type __v = (expr); \
35+
__v; \
36+
})
37+
1338
#endif

0 commit comments

Comments
 (0)