[PATCH -next] lib: disable KCSAN for XArray

From: Qian Cai
Date: Tue Mar 03 2020 - 22:16:02 EST


Functions like xas_find_marked(), xas_set_mark(), and xas_clear_mark()
could happen concurrently result in data races, but those operate only
on a single bit that are pretty much harmless. For example,

write to 0xffffa0020ee705c8 of 8 bytes by task 39718 on cpu 0:
xas_set_mark+0x8e/0x190
arch___test_and_set_bit at arch/x86/include/asm/bitops.h:152
(inlined by) __test_and_set_bit at include/asm-generic/bitops/instrumented-non-atomic.h:72
(inlined by) node_set_mark at lib/xarray.c:93
(inlined by) xas_set_mark at lib/xarray.c:879
__test_set_page_writeback+0x5de/0x8c0
iomap_writepage_map+0x8c6/0xf90
iomap_do_writepage+0x12b/0x450
write_cache_pages+0x523/0xb20
iomap_writepages+0x47/0x80
xfs_file_fsync+0xeb/0x450 [xfs]
do_writepages+0x5e/0x130
__filemap_fdatawrite_range+0x19e/0x1f0
file_write_and_wait_range+0xc0/0x100
xfs_file_fsync+0xeb/0x450 [xfs]
vfs_fsync_range+0x71/0x110
__x64_sys_msync+0x210/0x2a0
do_syscall_64+0x91/0xb05
entry_SYSCALL_64_after_hwframe+0x49/0xbe

read to 0xffffa0020ee705c8 of 8 bytes by task 39717 on cpu 5:
xas_find_marked+0xe9/0x750
xas_find_chunk at include/linux/xarray.h:1625
(inlined by) xas_find_marked at lib/xarray.c:1198
find_get_pages_range_tag+0x1bf/0xa90
pagevec_lookup_range_tag+0x46/0x70
__filemap_fdatawait_range+0xbb/0x270
file_write_and_wait_range+0xe0/0x100
xfs_file_fsync+0xeb/0x450 [xfs]
vfs_fsync_range+0x71/0x110
__x64_sys_msync+0x210/0x2a0
do_syscall_64+0x91/0xb05
entry_SYSCALL_64_after_hwframe+0x49/0xbe

Signed-off-by: Qian Cai <cai@xxxxxx>
---
lib/Makefile | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/lib/Makefile b/lib/Makefile
index 523dfe2063e2..989e702c275b 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -28,6 +28,11 @@ endif
# Used by KCSAN while enabled, avoid recursion.
KCSAN_SANITIZE_random32.o := n

+# This produces frequent data race reports: most of them are due to races on
+# the same word but accesses to a single bit of that word. Re-enable KCSAN
+# for this when we have more consensus on what to do about them.
+KCSAN_SANITIZE_xarray.o := n
+
lib-y := ctype.o string.o vsprintf.o cmdline.o \
rbtree.o radix-tree.o timerqueue.o xarray.o \
idr.o extable.o sha1.o irq_regs.o argv_split.o \
--
2.21.0 (Apple Git-122.2)