Page MenuHomeFreeBSD

amd64: prevent KCSan false positives on LAPIC mapping
ClosedPublic

Authored by jah on Sep 8 2020, 12:56 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Oct 28, 4:59 PM
Unknown Object (File)
Oct 21 2024, 2:39 PM
Unknown Object (File)
Oct 21 2024, 2:39 PM
Unknown Object (File)
Oct 21 2024, 2:39 PM
Unknown Object (File)
Oct 21 2024, 2:38 PM
Unknown Object (File)
Oct 21 2024, 2:24 PM
Unknown Object (File)
Oct 7 2024, 5:35 AM
Unknown Object (File)
Oct 4 2024, 5:36 PM
Subscribers

Details

Summary

For configurations without x2APIC support (guests, older hardware), the global
LAPIC MMIO mapping will trigger false-positive KCSan reports as it will appear
that multiple CPUs are concurrently reading and writing the same address.
This isn't actually true, as the underlying physical access will be performed
on the local CPU's APIC. Additionally, because LAPIC access can happen during
event timer configuration, the resulting KCSan printf can produce a panic due
to attempted recursion on event timer resources.

Add a __nosanitizethread preprocessor define to prevent the compiler from
inserting TSan hooks, and apply it to the x86 LAPIC accessors.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jah requested review of this revision.Sep 8 2020, 12:56 AM
jah added inline comments.
sys/x86/x86/local_apic.c
228 ↗(On Diff #76750)

I'm not sure if this is the preferred way to prevent TSan instrumentation; I didn't see a blacklist or anything similar in our codebase. I really wanted to annotate lapic_map with __nosanitizethread, but clang seems to only allow the attribute on functions.

This revision is now accepted and ready to land.Sep 8 2020, 10:04 AM

Ideally tools like KSAN should exempt all non-WB memory. The normal race definition is not appropriate there.

Normally non-WB memory would be accessed via bus_space. KCSan will ignore these.

This revision was automatically updated to reflect the committed changes.