Skip to content

Commit 9a78e15

Browse files
committed
KVM: x86: allow KVM_REQ_GET_NESTED_STATE_PAGES outside guest mode for VMX
VMX also uses KVM_REQ_GET_NESTED_STATE_PAGES for the Hyper-V eVMCS, which may need to be loaded outside guest mode. Therefore we cannot WARN in that case. However, that part of nested_get_vmcs12_pages is _not_ needed at vmentry time. Split it out of KVM_REQ_GET_NESTED_STATE_PAGES handling, so that both vmentry and migration (and in the latter case, independent of is_guest_mode) do the parts that are needed. Cc: <stable@vger.kernel.org> # 5.10.x: f2c7ef3: KVM: nSVM: cancel KVM_REQ_GET_NESTED_STATE_PAGES Cc: <stable@vger.kernel.org> # 5.10.x Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent aed8941 commit 9a78e15

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

arch/x86/kvm/svm/nested.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ static bool svm_get_nested_state_pages(struct kvm_vcpu *vcpu)
200200
{
201201
struct vcpu_svm *svm = to_svm(vcpu);
202202

203+
if (WARN_ON(!is_guest_mode(vcpu)))
204+
return true;
205+
203206
if (!nested_svm_vmrun_msrpm(svm)) {
204207
vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
205208
vcpu->run->internal.suberror =

arch/x86/kvm/vmx/nested.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3124,13 +3124,9 @@ static int nested_vmx_check_vmentry_hw(struct kvm_vcpu *vcpu)
31243124
return 0;
31253125
}
31263126

3127-
static bool nested_get_vmcs12_pages(struct kvm_vcpu *vcpu)
3127+
static bool nested_get_evmcs_page(struct kvm_vcpu *vcpu)
31283128
{
3129-
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
31303129
struct vcpu_vmx *vmx = to_vmx(vcpu);
3131-
struct kvm_host_map *map;
3132-
struct page *page;
3133-
u64 hpa;
31343130

31353131
/*
31363132
* hv_evmcs may end up being not mapped after migration (when
@@ -3153,6 +3149,17 @@ static bool nested_get_vmcs12_pages(struct kvm_vcpu *vcpu)
31533149
}
31543150
}
31553151

3152+
return true;
3153+
}
3154+
3155+
static bool nested_get_vmcs12_pages(struct kvm_vcpu *vcpu)
3156+
{
3157+
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
3158+
struct vcpu_vmx *vmx = to_vmx(vcpu);
3159+
struct kvm_host_map *map;
3160+
struct page *page;
3161+
u64 hpa;
3162+
31563163
if (nested_cpu_has2(vmcs12, SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES)) {
31573164
/*
31583165
* Translate L1 physical address to host physical
@@ -3221,6 +3228,18 @@ static bool nested_get_vmcs12_pages(struct kvm_vcpu *vcpu)
32213228
exec_controls_setbit(vmx, CPU_BASED_USE_MSR_BITMAPS);
32223229
else
32233230
exec_controls_clearbit(vmx, CPU_BASED_USE_MSR_BITMAPS);
3231+
3232+
return true;
3233+
}
3234+
3235+
static bool vmx_get_nested_state_pages(struct kvm_vcpu *vcpu)
3236+
{
3237+
if (!nested_get_evmcs_page(vcpu))
3238+
return false;
3239+
3240+
if (is_guest_mode(vcpu) && !nested_get_vmcs12_pages(vcpu))
3241+
return false;
3242+
32243243
return true;
32253244
}
32263245

@@ -6605,7 +6624,7 @@ struct kvm_x86_nested_ops vmx_nested_ops = {
66056624
.hv_timer_pending = nested_vmx_preemption_timer_pending,
66066625
.get_state = vmx_get_nested_state,
66076626
.set_state = vmx_set_nested_state,
6608-
.get_nested_state_pages = nested_get_vmcs12_pages,
6627+
.get_nested_state_pages = vmx_get_nested_state_pages,
66096628
.write_log_dirty = nested_vmx_write_pml_buffer,
66106629
.enable_evmcs = nested_enable_evmcs,
66116630
.get_evmcs_version = nested_get_evmcs_version,

arch/x86/kvm/x86.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8806,9 +8806,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
88068806

88078807
if (kvm_request_pending(vcpu)) {
88088808
if (kvm_check_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu)) {
8809-
if (WARN_ON_ONCE(!is_guest_mode(vcpu)))
8810-
;
8811-
else if (unlikely(!kvm_x86_ops.nested_ops->get_nested_state_pages(vcpu))) {
8809+
if (unlikely(!kvm_x86_ops.nested_ops->get_nested_state_pages(vcpu))) {
88128810
r = 0;
88138811
goto out;
88148812
}

0 commit comments

Comments
 (0)