kernel - Fix bug in machdep.pmap_mmu_optimize
authorMatthew Dillon <dillon@apollo.backplane.com>
Sat, 21 Oct 2017 06:43:15 +0000 (23:43 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Tue, 31 Oct 2017 17:49:47 +0000 (10:49 -0700)
commitc5030460c671e6a0248bf652a3f6b52590d90916
tree91fe4d8218c8574b7e07c95bb77eaf13219d680c
parentf52708b0e2a001116766cd079f6014ee25d4089f
kernel - Fix bug in machdep.pmap_mmu_optimize

* Fix a bug in the pmap_mmu_optimize feature (default disabled).  When
  enable this feature will automatically share page table pages with
  equivalent permissions for objects covering the whole page table page.

* However, the code which cleaned out the 'old' page table page failed
  to properly lock its pindex across the replacement operation, likely
  allowing threaded programs to sometimes race it and potentially
  lose track of one or more PTEs.

  The code tried to hold onto proc_pd_pv to prevent races, but there is
  still a small window due to the fact that pmap_allocpte() allocates
  pv's from the leaf upward.  So if the pmap optimization is good in
  one thread but the fails in another for the same page table (for
  example, due to a vm_map_entry split), a race can ensue.

* Use the existing pt_placemarker feature to properly lock the empty
  page table page slot while it is being replaced.

* Add a soft-locking mechanism to temporarily work around a
  (usually short-lived) allocation live-lock which can crop up
  when one thread is trying to replace a page table page while
  another is trying to allocate to it.
sys/platform/pc64/include/pmap.h
sys/platform/pc64/x86_64/pmap.c