KCSAN + KVM = host reset

From: Qian Cai
Date: Wed Apr 08 2020 - 17:00:01 EST


Running a simple thing on this AMD host would trigger a reset right away.
Unselect KCSAN kconfig makes everything work fine (the host would also
reset If only "echo off > /sys/kernel/debug/kcsanâ before running qemu-kvm).

/usr/libexec/qemu-kvm -name ubuntu-18.04-server-cloudimg -cpu host -smp 2 -m 2G -hda ubuntu-18.04-server-cloudimg.qcow2 -cdrom ubuntu-18.04-server-cloudimg.iso -nic user,hostfwd=tcp::2222-:22 -serial mon:stdio -nographic

With this config on todayâs linux-next,

https://raw.githubusercontent.com/cailca/linux-mm/master/kcsan.config

Cherry-picked a few commits from -rcu (in case if it ever matters)

48b1fc1 kcsan: Add option to allow watcher interruptions
2402d0e kcsan: Add option for verbose reporting
43f7646 x86/mm/pat: Mark an intentional data race

=== console output ===
Kernel 5.6.0-next-20200408+ on an x86_64

hp-dl385g10-05 login:

<...host reset...>

=======================
HPE ProLiant System BIOS A40 v1.20 (03/09/2018)
(C) Copyright 1982-2018 Hewlett Packard Enterprise Development LP
Early system initialization, please wait...


iLO 5 IPv4: 10.73.196.44
iLO 5 IPv6: FE80::D6C9:EFFF:FECE:717E

2%: Early Processor Initialization
4%: Processor Root Ports Initialization
8%: SMBIOS Table Initialization
12%: HPE SmartMemory Initialization
17%: iLO Embedded Health Initialization
21%: ACPI Table Initialization
25%: System Security Initialization
30%: BIOS Configuration Initialization
39%: Early PCI Initialization - Start
47%: Early PCI Initialization - Complete
60%: Switching console output to Primary Video. Please waitâ
========

# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 32
On-line CPU(s) list: 0-31
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 2
NUMA node(s): 8
Vendor ID: AuthenticAMD
CPU family: 23
Model: 1
Model name: AMD EPYC 7251 8-Core Processor
Stepping: 2
CPU MHz: 2830.383
CPU max MHz: 2100.0000
CPU min MHz: 1200.0000
BogoMIPS: 4191.58
Virtualization: AMD-V
L1d cache: 32K
L1i cache: 64K
L2 cache: 512K
L3 cache: 4096K
NUMA node0 CPU(s): 0,1,16,17
NUMA node1 CPU(s): 2,3,18,19
NUMA node2 CPU(s): 4,5,20,21
NUMA node3 CPU(s): 6,7,22,23
NUMA node4 CPU(s): 8,9,24,25
NUMA node5 CPU(s): 10,11,26,27
NUMA node6 CPU(s): 12,13,28,29
NUMA node7 CPU(s): 14,15,30,31
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid amd_dcm aperfmperf pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb hw_pstate ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 xsaves clzero irperf xsaveerptr arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif overflow_recov succor smca

# cat /sys/kernel/debug/kcsan
enabled: 1
used_watchpoints: 0
setup_watchpoints: 13777602
data_races: 47
assert_failures: 0
no_capacity: 598865
report_races: 0
races_unknown_origin: 226
unencodable_accesses: 0
encoding_false_positives: 0