Skip to contentSkip to conversation

KVM: nSVM: Mark all of vmcb02 dirty when restoring nested state

PATCH Applied Yosry Ahmed 2 participants 2 messages Feb 10 – Mar 5

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: nSVM: Mark all of vmcb02 dirty when restoring nested state

When restoring a vCPU in guest mode, any state restored before KVM_SET_NESTED_STATE (e.g. KVM_SET_SREGS) will mark the corresponding dirty bits in vmcb01, as it is the active VMCB before switching to vmcb02 in svm_set_nested_state().

Hence, mark all fields in vmcb02 dirty in svm_set_nested_state() to capture any previously restored fields.

Fixes cc440cdad5b7 ("KVM: nSVM: implement KVM_GET_NESTED_STATE and KVM_SET_NESTED_STATE")
---
 arch/x86/kvm/svm/nested.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/x86/kvm/svm/nested.c +6 -0
index de90b104a0dd..6ed333fcf0c3 100644
@@ -1909,6 +1909,12 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
 	svm_switch_vmcb(svm, &svm->nested.vmcb02);
 	nested_vmcb02_prepare_control(svm, svm->vmcb->save.rip, svm->vmcb->save.cs.base);
 
+	/*
+	 * Any previously restored state (e.g. KVM_SET_SREGS) would mark fields
+	 * dirty in vmcb01 instead of vmcb02, so mark all of vmcb02 dirty here.
+	 */
+	vmcb_mark_all_dirty(svm->vmcb);
+
 	/*
 	 * While the nested guest CR3 is already checked and set by
 	 * KVM_SET_SREGS, it was set when nested state was yet loaded,

base-commit: e944fe2c09f405a2e2d147145c9b470084bc4c9a

Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
maintainer Applied
#1 lore raw
Quoted 9 lines · Yosry Ahmed

When restoring a vCPU in guest mode, any state restored before KVM_SET_NESTED_STATE (e.g. KVM_SET_SREGS) will mark the corresponding dirty bits in vmcb01, as it is the active VMCB before switching to vmcb02 in svm_set_nested_state().

Hence, mark all fields in vmcb02 dirty in svm_set_nested_state() to capture any previously restored fields.

[...]

Applied to kvm-x86 nested, thanks!

[1/1] KVM: nSVM: Mark all of vmcb02 dirty when restoring nested state

      https://github.com/kvm-x86/linux/commit/e63fb1379f4b

--
https://github.com/kvm-x86/linux/tree/next