x86/spec-ctrl: Skip RSB overwriting when safe to do so
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 19 Aug 2021 12:53:15 +0000 (13:53 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 27 Aug 2021 13:19:02 +0000 (14:19 +0100)
commitafab477fba3b4de4ad3887c27677737b96488091
tree747440a0811042c623e5c39b68f807012d6859a3
parentb6da9d0414d69c2682214ee3ecf9816fcac500d0
x86/spec-ctrl: Skip RSB overwriting when safe to do so

In some configurations, it is safe to not overwrite the RSB on entry to Xen.
Both Intel and AMD have guidelines in this area, because of the performance
difference it makes for native kernels.

A simple microperf test, measuring the amount of time a XENVER_version
hypercall takes, shows the following improvements:

  KabyLake:     -13.9175% +/- 6.85387%
  CoffeeLake-R:  -9.1183% +/- 5.04519%
  Milan:        -17.7803% +/- 1.29808%

This is best case improvement, because no real workloads are making
XENVER_version hypercalls in a tight loop.  However, this is the hypercall
used by PV kernels to force evtchn delivery if one is pending, so it is a
common hypercall to see, especially in dom0.

The avoidance of RSB-overwriting speeds up all interrupts, exceptions and
system calls from PV or Xen context.  RSB-overwriting is still required on
VMExit from HVM guests for now.

In terms of more realistic testing, LMBench in dom0 on an AMD Rome system
shows improvements across the board, with the best improvement at 8% for
simple syscall and simple write.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/spec_ctrl.c