qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

include/qemu: Added tsan.h for annotations.

These annotations will allow us to give tsan
additional hints. For example, we can inform
tsan about reads/writes to ignore to silence certain
classes of warnings.
We can also annotate threads so that the proper thread
naming shows up in tsan warning results.

Signed-off-by: Robert Foley <robert.foley@linaro.org>
Reviewed-by: Emilio G. Cota <cota@braap.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20200609200738.445-11-robert.foley@linaro.org>
Message-Id: <20200612190237.30436-14-alex.bennee@linaro.org>

authored by

Robert Foley and committed by
Alex Bennée
e51345ee df79fd56

+71
+71
include/qemu/tsan.h
··· 1 + #ifndef QEMU_TSAN_H 2 + #define QEMU_TSAN_H 3 + /* 4 + * tsan.h 5 + * 6 + * This file defines macros used to give ThreadSanitizer 7 + * additional information to help suppress warnings. 8 + * This is necessary since TSan does not provide a header file 9 + * for these annotations. The standard way to include these 10 + * is via the below macros. 11 + * 12 + * Annotation examples can be found here: 13 + * https://github.com/llvm/llvm-project/tree/master/compiler-rt/test/tsan 14 + * annotate_happens_before.cpp or ignore_race.cpp are good places to start. 15 + * 16 + * The full set of annotations can be found here in tsan_interface_ann.cpp. 17 + * https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/tsan/rtl/ 18 + * 19 + * This work is licensed under the terms of the GNU GPL, version 2 or later. 20 + * See the COPYING file in the top-level directory. 21 + */ 22 + 23 + #ifdef CONFIG_TSAN 24 + /* 25 + * Informs TSan of a happens before/after relationship. 26 + */ 27 + #define QEMU_TSAN_ANNOTATE_HAPPENS_BEFORE(addr) \ 28 + AnnotateHappensBefore(__FILE__, __LINE__, (void *)(addr)) 29 + #define QEMU_TSAN_ANNOTATE_HAPPENS_AFTER(addr) \ 30 + AnnotateHappensAfter(__FILE__, __LINE__, (void *)(addr)) 31 + /* 32 + * Gives TSan more information about thread names it can report the 33 + * name of the thread in the warning report. 34 + */ 35 + #define QEMU_TSAN_ANNOTATE_THREAD_NAME(name) \ 36 + AnnotateThreadName(__FILE__, __LINE__, (void *)(name)) 37 + /* 38 + * Allows defining a region of code on which TSan will not record memory READS. 39 + * This has the effect of disabling race detection for this section of code. 40 + */ 41 + #define QEMU_TSAN_ANNOTATE_IGNORE_READS_BEGIN() \ 42 + AnnotateIgnoreReadsBegin(__FILE__, __LINE__) 43 + #define QEMU_TSAN_ANNOTATE_IGNORE_READS_END() \ 44 + AnnotateIgnoreReadsEnd(__FILE__, __LINE__) 45 + /* 46 + * Allows defining a region of code on which TSan will not record memory 47 + * WRITES. This has the effect of disabling race detection for this 48 + * section of code. 49 + */ 50 + #define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN() \ 51 + AnnotateIgnoreWritesBegin(__FILE__, __LINE__) 52 + #define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_END() \ 53 + AnnotateIgnoreWritesEnd(__FILE__, __LINE__) 54 + #else 55 + #define QEMU_TSAN_ANNOTATE_HAPPENS_BEFORE(addr) 56 + #define QEMU_TSAN_ANNOTATE_HAPPENS_AFTER(addr) 57 + #define QEMU_TSAN_ANNOTATE_THREAD_NAME(name) 58 + #define QEMU_TSAN_ANNOTATE_IGNORE_READS_BEGIN() 59 + #define QEMU_TSAN_ANNOTATE_IGNORE_READS_END() 60 + #define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN() 61 + #define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_END() 62 + #endif 63 + 64 + void AnnotateHappensBefore(const char *f, int l, void *addr); 65 + void AnnotateHappensAfter(const char *f, int l, void *addr); 66 + void AnnotateThreadName(const char *f, int l, char *name); 67 + void AnnotateIgnoreReadsBegin(const char *f, int l); 68 + void AnnotateIgnoreReadsEnd(const char *f, int l); 69 + void AnnotateIgnoreWritesBegin(const char *f, int l); 70 + void AnnotateIgnoreWritesEnd(const char *f, int l); 71 + #endif