kernel - Lower VM_MAX_USER_ADDRESS to finalize work-around for Ryzen bug
commit11ba7f73d6e534d54da55d5c4a1ac1553cc62b45
authorMatthew Dillon <dillon@apollo.backplane.com>
Thu, 10 Aug 2017 05:20:52 +0000 (9 22:20 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Thu, 10 Aug 2017 05:31:35 +0000 (9 22:31 -0700)
treeb17a1032c250497583b581674598ddb6e1ee6bfb
parent903d202e8463ab523909a152c7839826c4edcea7
kernel - Lower VM_MAX_USER_ADDRESS to finalize work-around for Ryzen bug

* Reduce VM_MAX_USER_ADDRESS by 2MB, effectively making the top 2MB of the
  user address space unmappable.  The user stack now starts 2MB down from
  where it did before.  Theoretically we only need to reduce the top of
  the user address space by 4KB, but doing it by 2MB may be more useful for
  future page table optimizations.

* As per AMD, Ryzen has an issue when the instruction pre-fetcher crosses
  from canonical to non-canonical address space.  This can only occur at
  the top of the user stack.

  In DragonFlyBSD, the signal trampoline resides at the top of the user stack
  and an IRETQ into it can cause a Ryzen box to lockup and destabilize due
  to this action.  The bug case was, basically two cpu threads on the same
  core, one in a cpu-bound loop of some sort while the other takes a normal
  UNIX signal (causing the IRETQ into the signal trampoline).  The IRETQ
  microcode freezes until the cpu-bound loop terminates, preventing the
  cpu thread from being able to take any interrupt or IPI whatsoever for
  the duration, and the cpu may destabilize afterwords as well.

* The pre-fetcher is somewhat heuristical, so just moving the trampoline
  down is no guarantee if the top 4KB of the user stack is mapped or mappable.
  It is better to make the boundary unmappable by userland.

* Bug first tracked down by myself in early 2017.  AMD validated the bug
  and determined that unmapping the boundary page completely solves the
  issue.

* Also retain the code which places the signal trampoline in its own page
  so we can maintain separate protection settings for the code, and make it
  read-only (R+X).
sys/cpu/x86_64/include/signal.h
sys/kern/kern_exec.c
sys/platform/pc64/include/vmparam.h
sys/platform/vkernel64/include/vmparam.h