HomeFreeBSD

amd64: Set GS.base before calling init_secondary() on APs

Description

amd64: Set GS.base before calling init_secondary() on APs

KMSAN instrumentation requires thread-local storage to track
initialization state for function parameters and return values. This
buffer is accessed as part of each function prologue. It is provided by
the KMSAN runtime, which looks up a pointer in the current thread's
structure.

When KMSAN is configured, init_secondary() is instrumented, but this
means that GS.base must be initialized first, otherwise the runtime
cannot safely access curthread. Work around this by loading GS.base
before calling init_secondary(), so that the runtime can at least check
curthread == NULL and return a pointer to some dummy storage. Note that
init_secondary() still must reload GS.base after calling lgdt(), which
loads a selector into %gs, which in turn clears the base register.

Reviewed by: kib
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D31336

Details

Provenance
markjAuthored on Jul 29 2021, 2:22 PM
Reviewer
kib
Differential Revision
D31336: amd64: Set GSBASE before calling init_secondary()
Parents
R10:e15374508381: amd64: Set MSR_KGSBASE to 0 during AP startup
Branches
Unknown
Tags
Unknown