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)
Thu, Sep 26, 6:53 AM
Unknown Object (File)
Sat, Sep 21, 5:54 AM
Unknown Object (File)
Thu, Sep 19, 3:16 AM
Unknown Object (File)
Mon, Sep 16, 11:15 AM
Unknown Object (File)
Sun, Sep 15, 2:14 AM
Unknown Object (File)
Fri, Sep 6, 12:05 AM
Unknown Object (File)
Sep 2 2024, 5:47 PM
Unknown Object (File)
Aug 31 2024, 6:50 AM
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.