Ensure that arm64 thread structures are allocated from the direct map.

Otherwise we can fail to handle translation faults on curthread, leading
to a panic.

Reviewed by:	alc, rlibby
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D23895
This commit is contained in:
Mark Johnston 2020-02-29 18:41:48 +00:00
parent 8231202bd5
commit 5aa5420ff2

View File

@ -331,6 +331,7 @@ proc_linkup(struct proc *p, struct thread *td)
void
threadinit(void)
{
uint32_t flags;
mtx_init(&tid_lock, "TID lock", NULL, MTX_DEF);
@ -340,9 +341,20 @@ threadinit(void)
*/
tid_unrhdr = new_unrhdr(PID_MAX + 2, INT_MAX, &tid_lock);
flags = UMA_ZONE_NOFREE;
#ifdef __aarch64__
/*
* Force thread structures to be allocated from the direct map.
* Otherwise, superpage promotions and demotions may temporarily
* invalidate thread structure mappings. For most dynamically allocated
* structures this is not a problem, but translation faults cannot be
* handled without accessing curthread.
*/
flags |= UMA_ZONE_CONTIG;
#endif
thread_zone = uma_zcreate("THREAD", sched_sizeof_thread(),
thread_ctor, thread_dtor, thread_init, thread_fini,
32 - 1, UMA_ZONE_NOFREE);
32 - 1, flags);
tidhashtbl = hashinit(maxproc / 2, M_TIDHASH, &tidhash);
rw_init(&tidhash_lock, "tidhash");
}