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
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 4b136ef259cefedc9b6404afc09138aeb8acbd91)

Details

Provenance
markjAuthored on Jul 29 2021, 2:22 PM
Parents
rGc7b5abde5389: Add vn_lktype_write()
Branches
Unknown
Tags
Unknown