freebsd-nq/sys/i386
Konstantin Belousov c8f9c1f3d9 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
2018-01-27 11:49:37 +00:00
..
acpica Minor cleanups found while fixing a bug involving double mapping of low 2017-12-15 03:05:14 +00:00
bios inittodr(0) actually sets the time, so there's no need to call 2018-01-10 17:25:08 +00:00
cloudabi32 Use TO_PTR() to convert integers to pointers. 2017-11-26 14:45:56 +00:00
conf Enable VIMAGE in i386 GENERIC (revert r327840) 2018-01-14 16:04:51 +00:00
i386 Use PCID to optimize PTI. 2018-01-27 11:49:37 +00:00
ibcs2 Use long for the last argument to VOP_PATHCONF rather than a register_t. 2018-01-17 22:36:58 +00:00
include Define PHYS_TO_DMAP() and DMAP_TO_PHYS() as panics on the architectures 2018-01-19 22:17:13 +00:00
linux Use BSD-2-Clause-FreeBSD license on linux_support.s 2018-01-23 20:35:43 +00:00
pci sys/i386: further adoption of SPDX licensing ID tags. 2017-11-27 15:08:52 +00:00
Makefile