Skip to content

Commit a7d5c7c

Browse files
committed
KVM: nSVM: delay MSR permission processing to first nested VM run
Allow userspace to set up the memory map after KVM_SET_NESTED_STATE; to do so, move the call to nested_svm_vmrun_msrpm inside the KVM_REQ_GET_NESTED_STATE_PAGES handler (which is currently not used by nSVM). This is similar to what VMX does already. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 729c15c commit a7d5c7c

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

arch/x86/kvm/svm/nested.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,20 @@ static bool nested_svm_vmrun_msrpm(struct vcpu_svm *svm)
196196
return true;
197197
}
198198

199+
static bool svm_get_nested_state_pages(struct kvm_vcpu *vcpu)
200+
{
201+
struct vcpu_svm *svm = to_svm(vcpu);
202+
if (!nested_svm_vmrun_msrpm(svm)) {
203+
vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
204+
vcpu->run->internal.suberror =
205+
KVM_INTERNAL_ERROR_EMULATION;
206+
vcpu->run->internal.ndata = 0;
207+
return false;
208+
}
209+
210+
return true;
211+
}
212+
199213
static bool nested_vmcb_check_controls(struct vmcb_control_area *control)
200214
{
201215
if ((vmcb_is_intercept(control, INTERCEPT_VMRUN)) == 0)
@@ -698,6 +712,8 @@ void svm_leave_nested(struct vcpu_svm *svm)
698712
copy_vmcb_control_area(&vmcb->control, &hsave->control);
699713
nested_svm_uninit_mmu_context(&svm->vcpu);
700714
}
715+
716+
kvm_clear_request(KVM_REQ_GET_NESTED_STATE_PAGES, &svm->vcpu);
701717
}
702718

703719
static int nested_svm_exit_handled_msr(struct vcpu_svm *svm)
@@ -1142,9 +1158,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
11421158
load_nested_vmcb_control(svm, ctl);
11431159
nested_prepare_vmcb_control(svm);
11441160

1145-
if (!nested_svm_vmrun_msrpm(svm))
1146-
goto out_free;
1147-
1161+
kvm_make_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu);
11481162
ret = 0;
11491163
out_free:
11501164
kfree(save);
@@ -1155,6 +1169,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
11551169

11561170
struct kvm_x86_nested_ops svm_nested_ops = {
11571171
.check_events = svm_check_nested_events,
1172+
.get_nested_state_pages = svm_get_nested_state_pages,
11581173
.get_state = svm_get_nested_state,
11591174
.set_state = svm_set_nested_state,
11601175
};

0 commit comments

Comments
 (0)