Skip to content

Align SVM with APM defined behaviors

Kevin Cheng kvm lkml 4 versions – Applied

Status from this message: Applied patch 2 to kvm-x86 nested (the rest are coming separately). Thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest4 patches 12 repliesApplied
  2. v35 patches 4 repliesSuperseded
  3. v25 patches 12 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v12 patches12 repliesSuperseded

Changes in v4 from the cover letter

- Dropped "KVM: SVM: Inject #UD for STGI if EFER.SVME=0 and SVM Lock and DEV are not available" as per Sean
- Added back STGI and CLGI intercept clearing in init_vmcb to maintain previous behavior on intel guests. Previously intel guests always had STGI and CLGI intercepts cleared if vgif was enabled. In V3, because the clearing of the intercepts was moved from init_vmcb() to the !guest_cpuid_is_intel_compatible() case in svm_recalc_instruction_intercepts(), the CLGI intercept would be indefinitely set on intel guests. I added back the clearing to init_vmcb() to retain intel guest behavior before this patch.
- In "Raise #UD if VMMCALL instruction is not intercepted" patch:
- Exempt Hyper-V L2 TLB flush hypercalls from the #UD injection, as L0 intentionally intercepts these VMMCALLs on behalf of L1 via the direct hypercall enlightenment.
- Added nested_svm_is_l2_tlb_flush_hcall() which just returns true if the hypercall was a Hyper-V L2 TLB flush hypercall.

Patches in v4 Applied

#Subject and filesSizeRepliesApplied
1/4KVM: SVM: Move STGI and CLGI intercept handlingarch/x86/kvm/svm/svm.c+23 -40 replies
2/4KVM: SVM: Inject #UD for INVLPGA if EFER.SVME=0arch/x86/kvm/svm/svm.c+3 -00 replies
3/4KVM: SVM: Recalc instructions intercepts when EFER.SVME is toggledarch/x86/kvm/svm/svm.c+9 -10 replies
4/4KVM: SVM: Raise #UD if VMMCALL instruction is not interceptedarch/x86/kvm/svm/hyperv.h arch/x86/kvm/svm/nested.c arch/x86/kvm/svm/svm.c+30 -42 replies

Reviews trailers per patch

1 of 4 patches has a Reviewed-by or Acked-by.

PatchYosry Ahmed
1/4
2/4R-b
3/4
4/4

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH V4 0/4] Align SVM with APM defined behaviors

The APM lists the following behaviors
- The VMRUN, VMLOAD, VMSAVE, CLGI, VMMCALL, and INVLPGA instructions can be used when the EFER.SVME is set to 1; otherwise, these instructions generate a #UD exception.
- If VMMCALL instruction is not intercepted, the instruction raises a #UD exception.

The patches in this series fix current SVM bugs that do not adhere to the APM listed behaviors.

v3 -> v4:
- Dropped "KVM: SVM: Inject #UD for STGI if EFER.SVME=0 and SVM Lock and DEV are not available" as per Sean
- Added back STGI and CLGI intercept clearing in init_vmcb to maintain previous behavior on intel guests. Previously intel guests always had STGI and CLGI intercepts cleared if vgif was enabled. In V3, because the clearing of the intercepts was moved from init_vmcb() to the !guest_cpuid_is_intel_compatible() case in svm_recalc_instruction_intercepts(), the CLGI intercept would be indefinitely set on intel guests. I added back the clearing to init_vmcb() to retain intel guest behavior before this patch.
- In "Raise #UD if VMMCALL instruction is not intercepted" patch:
- Exempt Hyper-V L2 TLB flush hypercalls from the #UD injection, as L0 intentionally intercepts these VMMCALLs on behalf of L1 via the direct hypercall enlightenment.
- Added nested_svm_is_l2_tlb_flush_hcall() which just returns true if the hypercall was a Hyper-V L2 TLB flush hypercall.

v3: https://lore.kernel.org/kvm/[email protected]/

v2 -> v3:
- Elaborated on 'Move STGI and CLGI intercept handling' commit message as per Sean
- Fixed bug due to interaction with svm_enable_nmi_window() and 'Move STGI and CLGI intercept handling' as pointed out by Yosry. Code changes suggested by Sean/Yosry.
- Removed open-coded nested_svm_check_permissions() in STGI interception function as per Yosry

v2: https://lore.kernel.org/all/[email protected]/

v1 -> v2:
- Split up the series into smaller more logical changes as suggested by Sean
- Added patch for injecting #UD for STGI under APM defined conditions as suggested by Sean
- Combined EFER.SVME=0 conditional with intel CPU logic in svm_recalc_instruction_intercepts

Kevin Cheng (4):
KVM: SVM: Move STGI and CLGI intercept handling
KVM: SVM: Inject #UD for INVLPGA if EFER.SVME=0
KVM: SVM: Recalc instructions intercepts when EFER.SVME is toggled
KVM: SVM: Raise #UD if VMMCALL instruction is not intercepted

 arch/x86/kvm/svm/hyperv.h | 11 ++++++++
 arch/x86/kvm/svm/nested.c |  4 +--
 arch/x86/kvm/svm/svm.c    | 59 +++++++++++++++++++++++++++++++++++----
 3 files changed, 65 insertions(+), 9 deletions(-)

--
2.53.0.473.g4a7958ca14-goog