]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Use PCID to optimize PTI.
authorkib <kib@FreeBSD.org>
Sat, 27 Jan 2018 11:49:37 +0000 (11:49 +0000)
committerkib <kib@FreeBSD.org>
Sat, 27 Jan 2018 11:49:37 +0000 (11:49 +0000)
commit545e25ea753559c8c9a09351f0a8a49d041c9f96
tree6fa18c1e3cbbcd01d48bce73e0d6b73441855d33
parent6f0656b43b57298942098c29bd5ffed260d121df
Use PCID to optimize PTI.

Use PCID to avoid complete TLB shootdown when switching between user
and kernel mode with PTI enabled.

I use the model close to what I read about KAISER, user-mode PCID has
1:1 correspondence to the kernel-mode PCID, by setting bit 11 in PCID.
Full kernel-mode TLB shootdown is performed on context switches, since
KVA TLB invalidation only works in the current pmap. User-mode part of
TLB is flushed on the pmap activations as well.

Similarly, IPI TLB shootdowns must handle both kernel and user address
spaces for each address.  Note that machines which implement PCID but
do not have INVPCID instructions, cause the usual complications in the
IPI handlers, due to the need to switch to the target PCID temporary.
This is racy, but because for PCID/no-INVPCID we disable the
interrupts in pmap_activate_sw(), IPI handler cannot see inconsistent
state of CPU PCID vs PCPU pmap/kcr3/ucr3 pointers.

On the other hand, on kernel/user switches, CR3_PCID_SAVE bit is set
and we do not clear TLB.

I can imagine alternative use of PCID, where there is only one PCID
allocated for the kernel pmap. Then, there is no need to shootdown
kernel TLB entries on context switch. But copyout(3) would need to
either use method similar to proc_rwmem() to access the userspace
data, or (in reverse) provide a temporal mapping for the kernel buffer
into user mode PCID and use trampoline for copy.

Reviewed by: markj (previous version)
Tested by: pho
Discussed with: alc (some aspects)
Sponsored by: The FreeBSD Foundation
MFC after: 3 weeks
Differential revision: https://reviews.freebsd.org/D13985
sys/amd64/amd64/apic_vector.S
sys/amd64/amd64/mp_machdep.c
sys/amd64/amd64/pmap.c
sys/amd64/amd64/support.S
sys/amd64/include/pmap.h
sys/amd64/include/smp.h
sys/i386/i386/pmap.c
sys/i386/i386/vm_machdep.c
sys/x86/include/x86_smp.h
sys/x86/x86/mp_x86.c