Skip to content

KVM: X86: Fix and clean up for register caches

Lai Jiangshan kvm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest15 patches 32 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/15KVM: X86: Ensure the dirty PDPTEs to be loadedarch/x86/kvm/x86.c+2 -00 replies
2/15KVM: VMX: Mark VCPU_EXREG_PDPTR available in ept_save_pdptrs()arch/x86/kvm/vmx/vmx.c+1 -10 replies
3/15KVM: SVM: Always clear available of VCPU_EXREG_PDPTR in svm_vcpu_run()arch/x86/kvm/svm/svm.c+9 -40 replies
4/15KVM: VMX: Add and use X86_CR4_TLB_BITS when !enable_eptarch/x86/kvm/kvm_cache_regs.h arch/x86/kvm/vmx/vmx.c+3 -11 reply
5/15KVM: VMX: Add and use X86_CR4_PDPTR_BITS when !enable_eptarch/x86/kvm/kvm_cache_regs.h arch/x86/kvm/vmx/vmx.c arch/x86/kvm/x86.c+5 -40 replies
6/15KVM: X86: Move CR0 pdptr_bits into header file as X86_CR0_PDPTR_BITSarch/x86/kvm/kvm_cache_regs.h arch/x86/kvm/x86.c+4 -20 replies
7/15KVM: SVM: Remove outdated comment in svm_load_mmu_pgd()arch/x86/kvm/svm/svm.c+0 -10 replies
8/15KVM: SVM: Remove useless check in svm_load_mmu_pgd()arch/x86/kvm/svm/svm.c+0 -20 replies
9/15KVM: SVM: Remove the unneeded code to mark available for CR3arch/x86/kvm/svm/nested.c+0 -11 reply
10/15KVM: X86: Mark CR3 dirty when vcpu->arch.cr3 is changedarch/x86/kvm/vmx/nested.c arch/x86/kvm/x86.c+3 -30 replies
11/15KVM: VMX: Update vmcs.GUEST_CR3 only when the guest CR3 is dirtyarch/x86/kvm/vmx/vmx.c+2 -27 replies
12/15KVM: VMX: Reset the bits that are meaningful to be reset in vmx_register_cache_reset()arch/x86/kvm/vmx/vmx.h+27 -101 reply
13/15KVM: SVM: Add and use svm_register_cache_reset()arch/x86/kvm/svm/svm.c arch/x86/kvm/svm/svm.h+27 -24 replies
14/15KVM: X86: Remove kvm_register_clear_available()arch/x86/kvm/kvm_cache_regs.h+0 -70 replies
15/15KVM: nVMX: Always write vmcs.GUEST_CR3 during nested VM-Exitarch/x86/kvm/vmx/nested.c+21 -111 reply

Reviews trailers per patch

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

PatchLai Jiangshan
1/15
2/15
3/15
4/15
5/15
6/15
7/15
8/15
9/15
10/15
11/15
12/15
13/15R-b
14/15
15/15

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

Read the v1 thread

Cover letter [PATCH 00/15] KVM: X86: Fix and clean up for register caches

From: Lai Jiangshan <[email protected]>

The patchset was started when I read the code of nested_svm_load_cr3() and found that it marks CR3 available other than dirty when changing vcpu->arch.cr3. I thought its caller has ensured that vmcs.GUEST_CR3 will be or already be set to @cr3 so that it doesn't need to be marked dirty. And later I found that it is not true and it must be a bug in a rare case before I realized that all the code just (ab)uses vcpu->arch.regs_avail for VCPU_EXREG_CR3 and there is not such bug of using regs_avail here.
(The above finding becomes a low meaning patch_15 rather than a fix)

The unhappyness of the reading code made me do some cleanup for regs_avail and regs_dirty and kvm_register_xxx() functions in the hope that the code become clearer with less misunderstanding.

Major focus was on VCPU_EXREG_CR3 and VCPU_EXREG_PDPTR. They are ensured to be marked the correct tags (available or dirty), and the value is ensured to be synced to architecture before run if it is marked dirty.

When cleaning VCPU_EXREG_PDPTR, I also checked if the corresponding cr0/cr4 pdptr bits are all intercepted when !tdp_enabled, and I think it is not clear enough, so X86_CR4_PDPTR_BITS is added as self-comments in the code.

Lai Jiangshan (15):
KVM: X86: Ensure the dirty PDPTEs to be loaded
KVM: VMX: Mark VCPU_EXREG_PDPTR available in ept_save_pdptrs()
KVM: SVM: Always clear available of VCPU_EXREG_PDPTR in svm_vcpu_run()
KVM: VMX: Add and use X86_CR4_TLB_BITS when !enable_ept
KVM: VMX: Add and use X86_CR4_PDPTR_BITS when !enable_ept
KVM: X86: Move CR0 pdptr_bits into header file as X86_CR0_PDPTR_BITS
KVM: SVM: Remove outdate comment in svm_load_mmu_pgd()
KVM: SVM: Remove useless check in svm_load_mmu_pgd()
KVM: SVM: Remove the unneeded code to mark available for CR3
KVM: X86: Mark CR3 dirty when vcpu->arch.cr3 is changed
KVM: VMX: Update vmcs.GUEST_CR3 only when the guest CR3 is dirty
KVM: VMX: Reset the bits that are meaningful to be reset in
vmx_register_cache_reset()
KVM: SVM: Add and use svm_register_cache_reset()
KVM: X86: Remove kvm_register_clear_available()
KVM: nVMX: Always write vmcs.GUEST_CR3 during nested VM-Exit

 arch/x86/kvm/kvm_cache_regs.h | 13 ++++++------
 arch/x86/kvm/svm/nested.c     |  1 -
 arch/x86/kvm/svm/svm.c        | 17 ++++++++--------
 arch/x86/kvm/svm/svm.h        | 26 ++++++++++++++++++++++++
 arch/x86/kvm/vmx/nested.c     | 30 ++++++++++++++++++----------
 arch/x86/kvm/vmx/vmx.c        | 12 +++++++-----
 arch/x86/kvm/vmx/vmx.h        | 37 +++++++++++++++++++++++++----------
 arch/x86/kvm/x86.c            | 13 ++++++------
 8 files changed, 101 insertions(+), 48 deletions(-)
Signature · 1 line
2.19.1.6.gb485710b