kernel - Intel user/kernel separation MMU bug fix part 3/3
authorMatthew Dillon <dillon@apollo.backplane.com>
Fri, 5 Jan 2018 08:47:46 +0000 (00:47 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Fri, 5 Jan 2018 18:23:24 +0000 (10:23 -0800)
commit9e24b495eaee8a56a5a8a8a2c8bd5a6fdcd1f722
treebbba251d293d17c7dfee9fd75b31682c8d039152
parentfc92147724be4a0985994579fe0e42c08c03d861
kernel - Intel user/kernel separation MMU bug fix part 3/3

* Implement the isolated pmap template, iso_pmap.  The pmap code will
  generate a dummy iso_pmap containing only the kernel mappings required
  for userland to be able to transition into the kernel and vise-versa.

  The mappings needed are:

  (1) The per-cpu trampoline area for our stack (rsp0)
  (2) The global descriptor table (gdt) for all cpus
  (3) The interrupt descriptor table (idt) for all cpus
  (4) The TSS block for all cpus (we store this in the trampoline page)
  (5) Kernel code addresses for the interrupt vector entry and exit

* In this implementation the 'kernel code' addresses are currently just
  btext to etext.  That is, the kernel's primary text area.  Kernel
  data and bss are not part of the isolation map.

  TODO - just put the vector entry and exit points in the map, and
  not the entire kernel.

* System call performance is reduced when isolation is turned on.
  100ns -> 350ns or so.  However, typical workloads should not lose
  more than 5% performance or so.  System-call heavy and interrupt-heavy
  workloads (network, database, high-speed storage, etc) can lose a lot
  more performance.

  We leave the trampoline code in-place whether isolation is turned on
  or not.  The trampoline overhead, without isolation, is only 5nS or so.

* Fix a missing exec-related trampoline initialization.

* Clean-up kernel page table PTEs a bit. PG_M is ignored on non-terminal
  PTEs, so don't set it.  Also don't set PG_U in non-terminal kernel
  page table pages (PG_U is never set on terminal PTEs so this wasn't
  a problem, but we should be correct).

* Fix a bug in fast_syscall's trampoline stack.  The wrong stack
  pointer was being loaded.

* Move mdglobaldata->gd_common_tss to privatespace->common_tss.
  Place common_tss in the same page as the trampoline to reduce
  exposure to globaldata from the isolated MMU context.

* 16-byte align struct trampframe for convenience.

* Fix a bug in POP_FRAME.  Always cli in order to avoid getting
  an interrupt just at the iretq instruction, which might be
  misinterpreted.
sys/cpu/x86_64/include/asmacros.h
sys/cpu/x86_64/include/frame.h
sys/cpu/x86_64/include/segments.h
sys/platform/pc64/include/globaldata.h
sys/platform/pc64/vmm/vmx.c
sys/platform/pc64/x86_64/exception.S
sys/platform/pc64/x86_64/genassym.c
sys/platform/pc64/x86_64/machdep.c
sys/platform/pc64/x86_64/mp_machdep.c
sys/platform/pc64/x86_64/pmap.c