Skip to content

Relax canonical checks on some arch msrs

Maxim Levitsky kvm lkml 4 versions – Applied

Status from this message: Applied to kvm-x86 misc, with some massaging (see responsed to individual

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest4 patches 8 repliesApplied
  2. v34 patches 14 repliesSuperseded
  3. v22 patches 6 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v12 patches2 repliesSuperseded

Changes in v4 from the cover letter

- added PT and PEBS msrs
- corrected emulation of SGDT/SIDT/STR/SLDT instructions
- corrected canonical checks for TLB invalidation instructions

Patches in v4 Applied

#Subject and filesSizeRepliesApplied
1/4KVM: x86: drop x86.h include from cpuid.harch/x86/kvm/cpuid.h arch/x86/kvm/mmu.h arch/x86/kvm/vmx/hyperv.c +2 more+4 -41 reply
2/4KVM: x86: implement emul_is_noncanonical_address using is_noncanonical_addressarch/x86/kvm/emulate.c arch/x86/kvm/kvm_emulate.h arch/x86/kvm/x86.c+21 -61 reply
3/4KVM: x86: model canonical checks more preciselyarch/x86/kvm/emulate.c arch/x86/kvm/mmu/mmu.c arch/x86/kvm/vmx/nested.c +5 more+68 -231 reply
4/4KVM: nVMX: fix canonical check of vmcs12 HOST_RIParch/x86/kvm/vmx/nested.c+12 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH v4 0/4] Relax canonical checks on some arch msrs

Recently we came up upon a failure where likely the guest writes 0xff4547ceb1600000 to MSR_KERNEL_GS_BASE and later on, qemu sets this value via KVM_PUT_MSRS, and is rejected by the kernel, likely due to not being canonical in 4 level paging.

One of the way to trigger this is to make the guest enter SMM, which causes paging to be disabled, which SMM bios re-enables but not the whole 5 level. MSR_KERNEL_GS_BASE on the other hand continues to contain old value.

I did some reverse engineering and to my surprise I found out that both Intel and AMD indeed ignore CR4.LA57 when doing canonical checks on this and other msrs and/or other arch registers (like GDT base) which contain linear addresses.

V2: addressed a very good feedback from Chao Gao. Thanks!

V3: also fix the nested VMX, and also fix the
MSR_IA32_SYSENTER_EIP / MSR_IA32_SYSENTER_ESP

V4:
- added PT and PEBS msrs
- corrected emulation of SGDT/SIDT/STR/SLDT instructions
- corrected canonical checks for TLB invalidation instructions

Best regards,
Maxim Levitsky

Maxim Levitsky (4):
KVM: x86: drop x86.h include from cpuid.h
KVM: x86: implement emul_is_noncanonical_address using
is_noncanonical_address
KVM: x86: model canonical checks more precisely
KVM: nVMX: fix canonical check of vmcs12 HOST_RIP

 arch/x86/kvm/cpuid.h         |  1 -
 arch/x86/kvm/emulate.c       | 15 ++++++-----
 arch/x86/kvm/kvm_emulate.h   |  5 ++++
 arch/x86/kvm/mmu.h           |  1 +
 arch/x86/kvm/mmu/mmu.c       |  2 +-
 arch/x86/kvm/vmx/hyperv.c    |  1 +
 arch/x86/kvm/vmx/nested.c    | 35 +++++++++++++++++---------
 arch/x86/kvm/vmx/pmu_intel.c |  2 +-
 arch/x86/kvm/vmx/sgx.c       |  5 ++--
 arch/x86/kvm/vmx/vmx.c       |  4 +--
 arch/x86/kvm/x86.c           | 13 +++++++---
 arch/x86/kvm/x86.h           | 49 ++++++++++++++++++++++++++++++++++--
 12 files changed, 102 insertions(+), 31 deletions(-)
Signature · 1 line
2.26.3