Skip to content

KCSAN shows several btrfs data races, e.g. "BUG: KCSAN: data-race in btrfs_inode_safe_disk_i_size_write / fill_stack_inode_item" (kernel v6.6, amd64) #705

Open
@ernsteiswuerfel

Description

@ernsteiswuerfel

KCSAN throws up several data races when running a btrfs filesystem. For the test run I used a v6.6 kernel built with KCSAN_EARLY_ENABLE=y, KCSAN_REPORT_ONCE_IN_MS=12000, KCSAN_STRICT=y, KCSAN_WEAK_MEMORY=y. I booted the machine and did a kernel build. During this period I got 218 data races.

I know that a data race detected by KCSAN is not necessarily a bug, but as 64 the 218 data races detected prominently mentioned btrfs, either in the trace or in the workqueue I thought it would probably a good idea to report it here.

4 times I got:

BUG: KCSAN: data-race in btrfs_inode_safe_disk_i_size_write / fill_stack_inode_item

write to 0xffff9b7a10739418 of 8 bytes by task 4490 on cpu 14:
 btrfs_inode_safe_disk_i_size_write+0xc1/0x150
 btrfs_finish_one_ordered+0x1ee/0xfb0
 btrfs_finish_ordered_io+0x1a/0x30
 finish_ordered_fn+0x1e/0x30
 btrfs_work_helper+0xfc/0x3f0
 process_one_work+0x35f/0x5d0
 worker_thread+0x415/0x6d0
 kthread+0x181/0x1b0
 ret_from_fork+0x2f/0x50
 ret_from_fork_asm+0x11/0x20

read to 0xffff9b7a10739418 of 8 bytes by task 1497 on cpu 12:
 fill_stack_inode_item+0xb2/0x380
 btrfs_delayed_update_inode+0x1bb/0x290
 btrfs_update_inode+0xe3/0x180
 btrfs_finish_one_ordered+0x236/0xfb0
 btrfs_finish_ordered_io+0x1a/0x30
 finish_ordered_fn+0x1e/0x30
 btrfs_work_helper+0xfc/0x3f0
 process_one_work+0x35f/0x5d0
 worker_thread+0x415/0x6d0
 kthread+0x181/0x1b0
 ret_from_fork+0x2f/0x50
 ret_from_fork_asm+0x11/0x20

Reported by Kernel Concurrency Sanitizer on:
CPU: 12 PID: 1497 Comm: kworker/u66:0 Tainted: G                T  6.6.0-Zen3 #3
Hardware name: To Be Filled By O.E.M. B450M Steel Legend/B450M Steel Legend, BIOS P8.01 03/14/2023
Workqueue: btrfs-endio-write btrfs_work_helper

19 times I got:

BUG: KCSAN: data-race in xas_clear_mark / xas_find_marked

read to 0xffff9b7bd7d5ce30 of 8 bytes by task 58136 on cpu 1:
 xas_find_marked+0x11a/0x4d0
 filemap_get_folios_tag+0x119/0x3d0
 extent_write_cache_pages+0x2a4/0xc50
 extent_writepages+0x7d/0xe0
 btrfs_writepages+0x21/0x40
 do_writepages+0xab/0x2c0
 filemap_fdatawrite_wbc+0xbb/0xf0
 __filemap_fdatawrite_range+0x94/0xc0
 filemap_flush+0x28/0x40
 btrfs_release_file+0xd4/0xf0
 __fput+0x1f8/0x4a0
 __fput_sync+0x5a/0x70
 __x64_sys_close+0x5b/0xa0
 do_syscall_64+0x63/0xa0
 entry_SYSCALL_64_after_hwframe+0x4b/0xb5

read-write to 0xffff9b7bd7d5ce30 of 8 bytes by task 685 on cpu 19:
 xas_clear_mark+0xa1/0x120
 __folio_start_writeback+0x3a3/0x4a0
 set_page_writeback+0x2f/0x90
 btrfs_page_clamp_set_writeback+0x10c/0x130
 __process_pages_contig+0x22b/0x2d0
 extent_clear_unlock_delalloc+0x66/0x90
 submit_compressed_extents+0x24e/0x7f0
 btrfs_work_helper+0x2dd/0x3f0
 process_one_work+0x35f/0x5d0
 worker_thread+0x415/0x6d0
 kthread+0x181/0x1b0
 ret_from_fork+0x2f/0x50
 ret_from_fork_asm+0x11/0x20

Reported by Kernel Concurrency Sanitizer on:
CPU: 19 PID: 685 Comm: kworker/u65:11 Tainted: G                T  6.6.0-Zen3 #3
Hardware name: To Be Filled By O.E.M. B450M Steel Legend/B450M Steel Legend, BIOS P8.01 03/14/2023
Workqueue: btrfs-delalloc btrfs_work_helper

11 times I got:

BUG: KCSAN: data-race in wq_worker_tick / wq_worker_tick

read to 0xffff9b7a057699a8 of 8 bytes by interrupt on cpu 31:
 wq_worker_tick+0x5f/0x210
 scheduler_tick+0x111/0x120
 update_process_times+0xbf/0xf0
 tick_sched_timer+0xbe/0x130
 __hrtimer_run_queues+0x24f/0x330
 hrtimer_interrupt+0x1cb/0x3e0
 __sysvec_apic_timer_interrupt+0x5f/0xd0
 sysvec_apic_timer_interrupt+0x80/0xc0
 asm_sysvec_apic_timer_interrupt+0x1a/0x20
 kcsan_setup_watchpoint+0x27c/0x4f0
 btrfs_compress_heuristic+0x298/0x8e0
 compress_file_range+0x3ec/0xa40
 btrfs_work_helper+0xfc/0x3f0
 process_one_work+0x35f/0x5d0
 worker_thread+0x415/0x6d0
 kthread+0x181/0x1b0
 ret_from_fork+0x2f/0x50
 ret_from_fork_asm+0x11/0x20

write to 0xffff9b7a057699a8 of 8 bytes by interrupt on cpu 28:
 wq_worker_tick+0x75/0x210
 scheduler_tick+0x111/0x120
 update_process_times+0xbf/0xf0
 tick_sched_timer+0xbe/0x130
 __hrtimer_run_queues+0x24f/0x330
 hrtimer_interrupt+0x1cb/0x3e0
 __sysvec_apic_timer_interrupt+0x5f/0xd0
 sysvec_apic_timer_interrupt+0x80/0xc0
 asm_sysvec_apic_timer_interrupt+0x1a/0x20
 kcsan_setup_watchpoint+0x27c/0x4f0
 HUF_compress1X_usingCTable_internal_bmi2+0xb91/0x2cb0
 HUF_compress4X_usingCTable_internal+0x25e/0x270
 HUF_compressCTable_internal+0xaf/0xc0
 HUF_compress_internal+0x415/0x6c0
 HUF_compress4X_repeat+0x62/0x90
 ZSTD_compressLiterals+0x2a3/0x400
 ZSTD_entropyCompressSeqStore_internal.constprop.0+0x16c/0x3e0
 ZSTD_compressBlock_internal+0xf3/0x340
 ZSTD_compressContinue_internal+0x387/0x1420
 ZSTD_compressEnd+0x43/0x210
 ZSTD_compressStream2+0xb3d/0xc90
 ZSTD_endStream+0x47/0xd0
 zstd_end_stream+0x21/0x40
 zstd_compress_pages+0x689/0x8f0
 btrfs_compress_pages+0x14c/0x170
 compress_file_range+0x4b6/0xa40
 btrfs_work_helper+0xfc/0x3f0
 process_one_work+0x35f/0x5d0
 worker_thread+0x415/0x6d0
 kthread+0x181/0x1b0
 ret_from_fork+0x2f/0x50
 ret_from_fork_asm+0x11/0x20

Reported by Kernel Concurrency Sanitizer on:
CPU: 28 PID: 1512 Comm: kworker/u66:2 Tainted: G                T  6.6.0-Zen3 #3
Hardware name: To Be Filled By O.E.M. B450M Steel Legend/B450M Steel Legend, BIOS P8.01 03/14/2023
Workqueue: btrfs-delalloc btrfs_work_helper

10 times I got:

BUG: KCSAN: data-race in process_one_work / process_one_work

write to 0xffff9b7a082c1da0 of 8 bytes by task 48379 on cpu 21:
 process_one_work+0x37b/0x5d0
 worker_thread+0x415/0x6d0
 kthread+0x181/0x1b0
 ret_from_fork+0x2f/0x50
 ret_from_fork_asm+0x11/0x20

read to 0xffff9b7a082c1da0 of 8 bytes by task 197 on cpu 19:
 process_one_work+0x367/0x5d0
 worker_thread+0x415/0x6d0
 kthread+0x181/0x1b0
 ret_from_fork+0x2f/0x50
 ret_from_fork_asm+0x11/0x20

value changed: 0x0000000000000a41 -> 0x0000000000000a42

Reported by Kernel Concurrency Sanitizer on:
CPU: 19 PID: 197 Comm: kworker/u65:1 Tainted: G                T  6.6.0-Zen3 #3
Hardware name: To Be Filled By O.E.M. B450M Steel Legend/B450M Steel Legend, BIOS P8.01 03/14/2023
Workqueue: btrfs-endio-write btrfs_work_helper

Rather often I got BUG: KCSAN: data-race in __hrtimer_run_queues / hrtimer_active but only some times connected to btrfs, e.g.

BUG: KCSAN: data-race in __hrtimer_run_queues / hrtimer_active

read to 0xffff9b811e819e58 of 8 bytes by interrupt on cpu 17:
 hrtimer_active+0x7d/0xf0
 task_tick_fair+0x2f/0x270
 scheduler_tick+0x70/0x120
 update_process_times+0xbf/0xf0
 tick_sched_timer+0xbe/0x130
 __hrtimer_run_queues+0x24f/0x330
 hrtimer_interrupt+0x1cb/0x3e0
 __sysvec_apic_timer_interrupt+0x5f/0xd0
 sysvec_apic_timer_interrupt+0x80/0xc0
 asm_sysvec_apic_timer_interrupt+0x1a/0x20
 __page_table_check_zero+0xa3/0x190
 get_page_from_freelist+0x4a9/0xf20
 __alloc_pages+0x189/0x280
 __folio_alloc+0x16/0x60
 do_anonymous_page+0xe0/0x820
 __handle_mm_fault+0xaa6/0xab0
 handle_mm_fault+0x259/0x420
 exc_page_fault+0x18b/0x720
 asm_exc_page_fault+0x26/0x30

write to 0xffff9b811e819e58 of 8 bytes by interrupt on cpu 0:
 __hrtimer_run_queues+0x15d/0x330
 hrtimer_interrupt+0x1cb/0x3e0
 __sysvec_apic_timer_interrupt+0x5f/0xd0
 sysvec_apic_timer_interrupt+0x80/0xc0
 asm_sysvec_apic_timer_interrupt+0x1a/0x20
 kcsan_setup_watchpoint+0x27c/0x4f0
 btrfs_get_32+0x90/0x230
 __btrfs_check_leaf+0x188/0x23d0
 btrfs_check_leaf+0x1a/0x30
 btree_csum_one_bio+0x324/0x410
 btrfs_submit_chunk+0x759/0x790
 btrfs_submit_bio+0x1f/0x40
 write_one_eb+0x412/0x680
 btree_write_cache_pages+0x391/0x850
 btree_writepages+0xc6/0xe0
 do_writepages+0xab/0x2c0
 filemap_fdatawrite_wbc+0xbb/0xf0
 __filemap_fdatawrite_range+0x94/0xc0
 filemap_fdatawrite_range+0x2e/0x50
 btrfs_write_marked_extents+0xb4/0x200
 btrfs_write_and_wait_transaction+0x8b/0x140
 btrfs_commit_transaction+0x1151/0x1ac0
 transaction_kthread+0x243/0x2b0
 kthread+0x181/0x1b0
 ret_from_fork+0x2f/0x50
 ret_from_fork_asm+0x11/0x20

Reported by Kernel Concurrency Sanitizer on:
CPU: 0 PID: 405 Comm: btrfs-transacti Tainted: G                T  6.6.0-Zen3 #3
Hardware name: To Be Filled By O.E.M. B450M Steel Legend/B450M Steel Legend, BIOS P8.01 03/14/2023

Some data on the machine:

 # inxi -bz
System:
  Kernel: 6.5.10-gentoo-Zen3 arch: x86_64 bits: 64 Console: pty pts/2
    Distro: Gentoo Base System release 2.14
Machine:
  Type: Desktop Mobo: ASRock model: B450M Steel Legend serial: <filter>
    UEFI: American Megatrends v: P8.01 date: 03/14/2023
CPU:
  Info: 16-core AMD Ryzen 9 5950X [MT MCP] speed (MHz): avg: 3626
    min/max: 550/5084
Graphics:
  Device-1: AMD Navi 22 [Radeon RX 6700/6700 XT/6750 XT / 6800M/6850M XT]
    driver: amdgpu v: kernel
  Device-2: AMD Turks PRO [Radeon HD 6570/7570/8550 / R5 230] driver: radeon
    v: kernel
  Display: x11 server: X.Org v: 21.1.8 driver: X: loaded: amdgpu
    unloaded: fbdev,modesetting,radeon dri: radeonsi gpu: amdgpu,radeon
    resolution: 2560x1600~60Hz
  API: OpenGL v: 4.5 Mesa 23.1.8 renderer: llvmpipe (LLVM 16.0.6 256 bits)
Network:
  Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet
    driver: r8169
Drives:
  Local Storage: total: 931.51 GiB used: 260.46 GiB (28.0%

Full kernel dmesg and kernel v6.6 .config attached.
dmesg_66-van_zen3.txt
config_66-van_zen3.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    kernelsomething in kernel has to be done too

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions