mbox series

[00/11] KVM: VMX: Clean up VM-Enter/VM-Exit asm code

Message ID 20181220202518.21442-1-sean.j.christopherson@intel.com (mailing list archive)
Headers show
Series KVM: VMX: Clean up VM-Enter/VM-Exit asm code | expand

Message

Sean Christopherson Dec. 20, 2018, 8:25 p.m. UTC
Despite all but one patch being KVM cleanup, that one outlier is the
true catalyst for this series.  The outlier, patch 3/11, removes an
optimization tweak from the __noclone macro that was added by commit
95272c29378e ("compiler-gcc: disable -ftracer for __noclone functions")
to workaround a compiler error in KVM's esoteric VMX assembly code.

Unbeknownst at the time, using the __optimize__ attribute causes GCC
to reset to -O2 optimization defaults, which has several unintended
side effects including dropping -fno-omit-frame-pointer and preventing
GCC from properly inlining function calls due to the functions having
incompatible optimization attributes.

Patches 1/11 and 2/11 fix the offending KVM code and eliminate its
usage of __noclone, allowing patch 3/11 to remove "no-tracer" from the
__noclone macro.

Patches 4/11 and beyond are a mix of cleanup, fixes and optimizations
for a variety of low hanging fruit that were (unsurprisingly) revealed
when revisiting KVM's inline assembly blob.

FYI, I cc'd everyone involved for all patches up until the -ftracer
revert, after that I limited the cc/to list to KVM folks.

Sean Christopherson (11):
  KVM: VMX: Explicitly reference RCX as the vmx_vcpu pointer in asm
    blobs
  KVM: VMX: Move VM-Enter + VM-Exit handling to non-inline sub-routines
  Revert "compiler-gcc: disable -ftracer for __noclone functions"
  KVM: VMX: Modify only RSP when creating a placeholder for guest's RCX
  KVM: VMX: Save RSI to an unused output in vmx_vcpu_run() asm blob
  KVM: VMX: Manually load RDX in vmx_vcpu_run() asm blob
  KVM: VMX: Let the compiler save/load RDX around VM-Enter
  KVM: nVMX: Cache host_rsp on a per-VMCS basis
  KVM: nVMX: Add eVMCS support to nested_vmx_check_vmentry_hw()
  KVM: VMX: Add macros to handle HOST_RSP updates at VM-Enter
  KVM: nVMX: Remove a rogue "rax" clobber from
    nested_vmx_check_vmentry_hw()

 arch/x86/kvm/Makefile               |   2 +-
 arch/x86/kvm/vmx/nested.c           |  57 ++++---------
 arch/x86/kvm/vmx/vmcs.h             |   1 +
 arch/x86/kvm/vmx/vmenter.S          |  57 +++++++++++++
 arch/x86/kvm/vmx/vmx.c              | 127 +++++++++++++---------------
 arch/x86/kvm/vmx/vmx.h              |  30 ++++++-
 include/linux/compiler_attributes.h |   8 +-
 7 files changed, 164 insertions(+), 118 deletions(-)
 create mode 100644 arch/x86/kvm/vmx/vmenter.S

Comments

Sean Christopherson Dec. 20, 2018, 8:27 p.m. UTC | #1
Despite all but one patch being KVM cleanup, that one outlier is the
true catalyst for this series.  The outlier, patch 3/11, removes an
optimization tweak from the __noclone macro that was added by commit
95272c29378e ("compiler-gcc: disable -ftracer for __noclone functions")
to workaround a compiler error in KVM's esoteric VMX assembly code.

Unbeknownst at the time, using the __optimize__ attribute causes GCC
to reset to -O2 optimization defaults, which has several unintended
side effects including dropping -fno-omit-frame-pointer and preventing
GCC from properly inlining function calls due to the functions having
incompatible optimization attributes.

Patches 1/11 and 2/11 fix the offending KVM code and eliminate its
usage of __noclone, allowing patch 3/11 to remove "no-tracer" from the
__noclone macro.

Patches 4/11 and beyond are a mix of cleanup, fixes and optimizations
for a variety of low hanging fruit that were (unsurprisingly) revealed
when revisiting KVM's inline assembly blob.

FYI, I cc'd everyone involved for all patches up until the -ftracer
revert, after that I limited the cc/to list to KVM folks.

Sean Christopherson (11):
  KVM: VMX: Explicitly reference RCX as the vmx_vcpu pointer in asm
    blobs
  KVM: VMX: Move VM-Enter + VM-Exit handling to non-inline sub-routines
  Revert "compiler-gcc: disable -ftracer for __noclone functions"
  KVM: VMX: Modify only RSP when creating a placeholder for guest's RCX
  KVM: VMX: Save RSI to an unused output in vmx_vcpu_run() asm blob
  KVM: VMX: Manually load RDX in vmx_vcpu_run() asm blob
  KVM: VMX: Let the compiler save/load RDX around VM-Enter
  KVM: nVMX: Cache host_rsp on a per-VMCS basis
  KVM: nVMX: Add eVMCS support to nested_vmx_check_vmentry_hw()
  KVM: VMX: Add macros to handle HOST_RSP updates at VM-Enter
  KVM: nVMX: Remove a rogue "rax" clobber from
    nested_vmx_check_vmentry_hw()

 arch/x86/kvm/Makefile               |   2 +-
 arch/x86/kvm/vmx/nested.c           |  57 ++++---------
 arch/x86/kvm/vmx/vmcs.h             |   1 +
 arch/x86/kvm/vmx/vmenter.S          |  57 +++++++++++++
 arch/x86/kvm/vmx/vmx.c              | 127 +++++++++++++---------------
 arch/x86/kvm/vmx/vmx.h              |  30 ++++++-
 include/linux/compiler_attributes.h |   8 +-
 7 files changed, 164 insertions(+), 118 deletions(-)
 create mode 100644 arch/x86/kvm/vmx/vmenter.S
Sean Christopherson Dec. 20, 2018, 8:29 p.m. UTC | #2
Please ignore this duplicate, had a typo in my send script.  Sorry for the noise.
Andi Kleen Dec. 21, 2018, 12:33 a.m. UTC | #3
On Thu, Dec 20, 2018 at 12:25:15PM -0800, Sean Christopherson wrote:
> Despite all but one patch being KVM cleanup, that one outlier is the
> true catalyst for this series.  The outlier, patch 3/11, removes an
> optimization tweak from the __noclone macro that was added by commit
> 95272c29378e ("compiler-gcc: disable -ftracer for __noclone functions")
> to workaround a compiler error in KVM's esoteric VMX assembly code.

Patches look good to me.

Reviewed-by: Andi Kleen <ak@linux.intel.com>

-Andi
Paolo Bonzini Dec. 21, 2018, 10:58 a.m. UTC | #4
On 20/12/18 21:25, Sean Christopherson wrote:
> Despite all but one patch being KVM cleanup, that one outlier is the
> true catalyst for this series.  The outlier, patch 3/11, removes an
> optimization tweak from the __noclone macro that was added by commit
> 95272c29378e ("compiler-gcc: disable -ftracer for __noclone functions")
> to workaround a compiler error in KVM's esoteric VMX assembly code.
> 
> Unbeknownst at the time, using the __optimize__ attribute causes GCC
> to reset to -O2 optimization defaults, which has several unintended
> side effects including dropping -fno-omit-frame-pointer and preventing
> GCC from properly inlining function calls due to the functions having
> incompatible optimization attributes.
> 
> Patches 1/11 and 2/11 fix the offending KVM code and eliminate its
> usage of __noclone, allowing patch 3/11 to remove "no-tracer" from the
> __noclone macro.

Very nice!  I'm applying 1-3 right away, while the rest should wait for
4.22.

Paolo