KVM: SVM: Aggressively clear vmcb02 clean bits
cover KVM: SVM: Aggressively clear vmcb02 clean bits
It is unlikely that L1 will toggle the MSR intercept bit in vmcb02, or that L1 will change its own IA32_PAT MSR. However, if it does, the affected fields in vmcb02 should not be marked clean.
An alternative approach would be to implement a set of mutators for vmcb02 fields, and to clear the associated clean bit whenever a field is modified.
Jim Mattson (2):
KVM: SVM: Mark VMCB_PERM_MAP as dirty on nested VMRUN
KVM: SVM: Mark VMCB_NPT as dirty on nested VMRUN
arch/x86/kvm/svm/nested.c | 2 ++ 1 file changed, 2 insertions(+)
Signature · 1 line
2.51.0.470.ga7dc726c21-goog
PATCH 1/2 KVM: SVM: Mark VMCB_PERM_MAP as dirty on nested VMRUN
Mark the VMCB_PERM_MAP bit as dirty in nested_vmcb02_prepare_control() on every nested VMRUN.
If L1 changes MSR interception (INTERCEPT_MSR_PROT) between two VMRUN instructions on the same L1 vCPU, the msrpm_base_pa in the associated vmcb02 will change, and the VMCB_PERM_MAP clean bit should be cleared.
--- arch/x86/kvm/svm/nested.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kvm/svm/nested.c +1 -0
@@ -744,6 +744,7 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm, vmcb02->control.nested_ctl = vmcb01->control.nested_ctl; vmcb02->control.iopm_base_pa = vmcb01->control.iopm_base_pa; vmcb02->control.msrpm_base_pa = vmcb01->control.msrpm_base_pa; +vmcb_mark_dirty (vmcb02,VMCB_PERM_MAP );/* * Stash vmcb02's counter if the guest hasn't moved past the guilty
Signature · 1 line
2.51.0.470.ga7dc726c21-goog
PATCH 2/2 KVM: SVM: Mark VMCB_NPT as dirty on nested VMRUN
In reply to Jim MattsonMark the VMCB_NPT bit as dirty in nested_vmcb02_prepare_save() on every nested VMRUN.
If L1 changes the PAT MSR between two VMRUN instructions on the same L1 vCPU, the g_pat field in the associated vmcb02 will change, and the VMCB_NPT clean bit should be cleared.
--- arch/x86/kvm/svm/nested.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kvm/svm/nested.c +1 -0
@@ -613,6 +613,7 @@ static void nested_vmcb02_prepare_save(struct vcpu_svm *svm, struct vmcb *vmcb12struct kvm_vcpu *vcpu = &svm->vcpu;nested_vmcb02_compute_g_pat (svm); +vmcb_mark_dirty (vmcb02,VMCB_NPT );/* Load the nested guest state */ if (svm->nested.vmcb12_gpa != svm->nested.last_vmcb12_gpa) {
Signature · 1 line
2.51.0.470.ga7dc726c21-goog
Sean Christopherson
maintainerQuoted 7 lines · Jim Mattson
It is unlikely that L1 will toggle the MSR intercept bit in vmcb02, or that L1 will change its own
IA32_PATMSR. However, if it does, the affected fields in vmcb02 should not be marked clean.An alternative approach would be to implement a set of mutators for vmcb02 fields, and to clear the associated clean bit whenever a field is modified.
Any reason not to tag these for stable@? I can't think of any meaningful downsides, so erring on the side of caution seems prudent.
Quoted 6 lines · Sean Christopherson
Quoted 4 lines · Jim Mattson
It is unlikely that L1 will toggle the MSR intercept bit in vmcb02, or that L1 will change its own
IA32_PATMSR. However, if it does, the affected fields in vmcb02 should not be marked clean.
Quoted 6 lines
Quoted 3 lines
An alternative approach would be to implement a set of mutators for vmcb02 fields, and to clear the associated clean bit whenever a field is modified.
Any reason not to tag these for stable@? I can't think of any meaningful downsides, so erring on the side of caution seems prudent.
SGTM. Do you want a new version?
Sean Christopherson
maintainerQuoted 7 lines · Jim Mattson
Quoted 6 lines · Sean Christopherson
Quoted 4 lines · Jim Mattson
It is unlikely that L1 will toggle the MSR intercept bit in vmcb02, or that L1 will change its own
IA32_PATMSR. However, if it does, the affected fields in vmcb02 should not be marked clean.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
An alternative approach would be to implement a set of mutators for vmcb02 fields, and to clear the associated clean bit whenever a field is modified.
Any reason not to tag these for stable@? I can't think of any meaningful downsides, so erring on the side of caution seems prudent.
SGTM. Do you want a new version?
Good gravy, no. :-)
Quoted 9 lines · Jim Mattson
It is unlikely that L1 will toggle the MSR intercept bit in vmcb02, or that L1 will change its own
IA32_PATMSR. However, if it does, the affected fields in vmcb02 should not be marked clean.An alternative approach would be to implement a set of mutators for vmcb02 fields, and to clear the associated clean bit whenever a field is modified.
[...]
Applied to kvm-x86 svm, thanks!
[1/2] KVM: SVM: Mark VMCB_PERM_MAP as dirty on nested VMRUN
https://github.com/kvm-x86/linux/commit/93c9e107386d [2/2] KVM: SVM: Mark VMCB_NPT as dirty on nested VMRUN https://github.com/kvm-x86/linux/commit/7c8b465a1c91