Page MenuHomeFreeBSD

Port the NetBSD KCSAN runtime to FreeBSD
ClosedPublic

Authored by andrew on Nov 11 2019, 2:30 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Apr 11, 7:29 PM
Unknown Object (File)
Thu, Apr 11, 10:50 AM
Unknown Object (File)
Wed, Apr 10, 1:03 AM
Unknown Object (File)
Mar 14 2024, 5:33 AM
Unknown Object (File)
Mar 14 2024, 5:33 AM
Unknown Object (File)
Mar 14 2024, 5:33 AM
Unknown Object (File)
Mar 14 2024, 5:33 AM
Unknown Object (File)
Mar 14 2024, 5:33 AM

Details

Summary

This imports the NetBSD KCSan runtime into FreeBSD. KCSAN is the Kernel
Concurrency Sanitizer. It uses the thread sanitizer hooks to check
kernel memory accesses are not racy.

Every 1024 memory accesses a cell is created and the runtime performs a
short wait. If any other memory accesses touch the same memory in a
non-atomic way the runtime warns about a data race.

Test Plan

Booted on amd64 and arm64. Other architectures will need minimal work
in machine/atomic.h and machine/bus.h to port to them.

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 27445
Build 25683: arc lint + arc unit

Event Timeline

There is a GitHub repo with this change in https://github.com/freebsd-sanitizers/freebsd/tree/kcsan.

sys/amd64/conf/GENERIC
109

I won't enable this by default, but will leave it on for now for testing

sys/arm64/conf/GENERIC
28

This is disabled to allow testing on a ThunderX in Sentex.

contrib/llvm/tools/clang/lib/Driver/ToolChains/FreeBSD.cpp
424

Can this be upstreamed?

sys/arm64/conf/GENERIC
28

NUMA doesn't work on ThunderX?

hselasky added inline comments.
sys/amd64/include/csan.h
59

If the delay is small this is fine, else look at pause() how to properly use DELAY().

sys/amd64/include/csan.h
59

It's 10us. It needs to be long enough for the other threads to perform memory accesses on the same location without slowing the execution too much.

sys/arm64/conf/GENERIC
28

Not when booting with fdt.

sys/amd64/include/csan.h
59

Why is the delay argument 64-bit. Maybe make it just 16-bits ?

sys/amd64/include/csan.h
59

I haven't changed that code from NetBSD.

Update to version I expect to commit

sys/arm64/include/bus.h
328

Should this change be committed separately?

sys/sys/systm.h
375

How about:

copystr(...) kcsan_copystr(__VA_ARGS__)

Or you can skip the ()'s around the arguments, because they are already separated by comma.

sys/arm64/include/bus.h
328

Done in rS354851.

sys/sys/systm.h
375

I'm keeping it consistent with the existing style of this file.

This revision was not accepted when it landed; it landed in state Needs Review.Nov 21 2019, 11:22 AM
This revision was automatically updated to reflect the committed changes.