Skip to contentSkip to conversation

KVM: MMU: handle invalid root_hpa at __direct_map

PATCH Applied Marcelo Tosatti 3 participants 4 messages Dec 19, 2013 – Dec 20, 2013

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

It is possible for __direct_map to be called on invalid root_hpa (-1), two examples:

1) try_async_pf -> can_do_async_pf

    -> vmx_interrupt_allowed -> nested_vmx_vmexit

2) vmx_handle_exit -> vmx_interrupt_allowed -> nested_vmx_vmexit

Then to load_vmcs12_host_state and kvm_mmu_reset_context.

Check for this possibility, let fault exception be regenerated.

BZ: https://bugzilla.redhat.com/show_bug.cgi?id=924916

arch/x86/kvm/mmu.c +3 -0
index 40772ef..31a5702 100644
@@ -2659,6 +2659,9 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write,
 	int emulate = 0;
 	gfn_t pseudo_gfn;
 
+	if (!VALID_PAGE(vcpu->arch.mmu.root_hpa))
+		return 0;
+
 	for_each_shadow_entry(vcpu, (u64)gfn << PAGE_SHIFT, iterator) {
 		if (iterator.level == level) {
 			mmu_set_spte(vcpu, iterator.sptep, ACC_ALL,
#1 lore raw
Quoted 5 lines · Marcelo Tosatti

It is possible for __direct_map to be called on invalid root_hpa (-1), two examples:

1) try_async_pf -> can_do_async_pf

Quoted 9 lines
    -> vmx_interrupt_allowed -> nested_vmx_vmexit

2) vmx_handle_exit -> vmx_interrupt_allowed -> nested_vmx_vmexit

Then to load_vmcs12_host_state and kvm_mmu_reset_context.

Check for this possibility, let fault exception be regenerated.

BZ: https://bugzilla.redhat.com/show_bug.cgi?id=924916

Nice catch, Marcelo!

Isn't it better to do kvm_mmu_reload() before calling page_fault handler? Then a #PF can be avoided.

#2 lore raw
Quoted 11 lines · Xiao Guangrong
Quoted 10 lines · Marcelo Tosatti

It is possible for __direct_map to be called on invalid root_hpa (-1), two examples:

1) try_async_pf -> can_do_async_pf

    -> vmx_interrupt_allowed -> nested_vmx_vmexit

2) vmx_handle_exit -> vmx_interrupt_allowed -> nested_vmx_vmexit

Then to load_vmcs12_host_state and kvm_mmu_reset_context.

Quoted 8 lines
Quoted 4 lines

Check for this possibility, let fault exception be regenerated.

BZ: https://bugzilla.redhat.com/show_bug.cgi?id=924916

Nice catch, Marcelo!
Isn't it better to do kvm_mmu_reload() before calling page_fault handler? Then a #PF can be avoided.

try_async_pf can be called from within the page fault handler.

maintainer Applied
#3 lore raw
In reply to Marcelo Tosatti

Il 19/12/2013 18:28, Marcelo Tosatti ha scritto:

Quoted 23 lines

It is possible for __direct_map to be called on invalid root_hpa (-1), two examples:

1) try_async_pf -> can_do_async_pf

    -> vmx_interrupt_allowed -> nested_vmx_vmexit

2) vmx_handle_exit -> vmx_interrupt_allowed -> nested_vmx_vmexit

Then to load_vmcs12_host_state and kvm_mmu_reset_context.

Check for this possibility, let fault exception be regenerated.

BZ: https://bugzilla.redhat.com/show_bug.cgi?id=924916

arch/x86/kvm/mmu.c +0 -0
index 40772ef..31a5702 100644

arch/x86/kvm/mmu.c static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write, · line 2667

Quoted 9 lines
arch/x86/kvm/mmu.c +3 -0
@@ -2659,6 +2659,9 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write,
 	int emulate = 0;
 	gfn_t pseudo_gfn;
 
+	if (!VALID_PAGE(vcpu->arch.mmu.root_hpa))
+		return 0;
+
 	for_each_shadow_entry(vcpu, (u64)gfn << PAGE_SHIFT, iterator) {
 		if (iterator.level == level) {
 			mmu_set_spte(vcpu, iterator.sptep, ACC_ALL,

Applied to queue, thanks.

Paolo