arm64: Handle translation faults for thread structures
authorMark Johnston <markj@FreeBSD.org>
Wed, 2 Nov 2022 17:27:27 +0000 (13:27 -0400)
committerMark Johnston <markj@FreeBSD.org>
Wed, 2 Nov 2022 17:46:25 +0000 (13:46 -0400)
commit2c10be9e06d4577ad8b60a7cb415ecbad60b5370
tree1f4bb9b9030c77171f6acdc1bf9d7129b9d12586
parentc036339ddf0cf80164f41ea31f1d8d27f4a068a9
arm64: Handle translation faults for thread structures

The break-before-make requirement poses a problem when promoting or
demoting mappings containing thread structures: a CPU may raise a
translation fault while accessing curthread, and data_abort() accesses
the thread again before pmap_fault() can translate the address and
return.

Normally this isn't a problem because we have a hack to ensure that
slabs used by the thread zone are always accessed via the direct map,
where promotions and demotions are rare.  However, this hack doesn't
work properly with UMA_MD_SMALL_ALLOC disabled, as is the case with
KASAN configured (since our KASAN implementation does not shadow the
direct map and so tries to force the use of the kernel map wherever
possible).

Fix the problem by modifying data_abort() to handle translation faults
in the kernel map without dereferencing "td", i.e., curthread, and
without enabling interrupts.  pmap_klookup() has special handling for
translation faults which makes it safe to call in this context.  Then,
revert the aforementioned hack.

Reviewed by: kevans, alc, kib, andrew
MFC after: 1 month
Sponsored by: Juniper Networks, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D37231
sys/arm64/arm64/trap.c
sys/kern/kern_thread.c