Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b37fbea6 authored by Xiao Guangrong's avatar Xiao Guangrong Committed by Gleb Natapov
Browse files

KVM: MMU: make return value of mmio page fault handler more readable



Define some meaningful names instead of raw code

Signed-off-by: default avatarXiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Reviewed-by: default avatarGleb Natapov <gleb@redhat.com>
Reviewed-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent f2fd125d
Loading
Loading
Loading
Loading
+5 −10
Original line number Original line Diff line number Diff line
@@ -3224,17 +3224,12 @@ static u64 walk_shadow_page_get_mmio_spte(struct kvm_vcpu *vcpu, u64 addr)
	return spte;
	return spte;
}
}


/*
 * If it is a real mmio page fault, return 1 and emulat the instruction
 * directly, return 0 to let CPU fault again on the address, -1 is
 * returned if bug is detected.
 */
int handle_mmio_page_fault_common(struct kvm_vcpu *vcpu, u64 addr, bool direct)
int handle_mmio_page_fault_common(struct kvm_vcpu *vcpu, u64 addr, bool direct)
{
{
	u64 spte;
	u64 spte;


	if (quickly_check_mmio_pf(vcpu, addr, direct))
	if (quickly_check_mmio_pf(vcpu, addr, direct))
		return 1;
		return RET_MMIO_PF_EMULATE;


	spte = walk_shadow_page_get_mmio_spte(vcpu, addr);
	spte = walk_shadow_page_get_mmio_spte(vcpu, addr);


@@ -3247,7 +3242,7 @@ int handle_mmio_page_fault_common(struct kvm_vcpu *vcpu, u64 addr, bool direct)


		trace_handle_mmio_page_fault(addr, gfn, access);
		trace_handle_mmio_page_fault(addr, gfn, access);
		vcpu_cache_mmio_info(vcpu, addr, gfn, access);
		vcpu_cache_mmio_info(vcpu, addr, gfn, access);
		return 1;
		return RET_MMIO_PF_EMULATE;
	}
	}


	/*
	/*
@@ -3255,13 +3250,13 @@ int handle_mmio_page_fault_common(struct kvm_vcpu *vcpu, u64 addr, bool direct)
	 * it's a BUG if the gfn is not a mmio page.
	 * it's a BUG if the gfn is not a mmio page.
	 */
	 */
	if (direct && !check_direct_spte_mmio_pf(spte))
	if (direct && !check_direct_spte_mmio_pf(spte))
		return -1;
		return RET_MMIO_PF_BUG;


	/*
	/*
	 * If the page table is zapped by other cpus, let CPU fault again on
	 * If the page table is zapped by other cpus, let CPU fault again on
	 * the address.
	 * the address.
	 */
	 */
	return 0;
	return RET_MMIO_PF_RETRY;
}
}
EXPORT_SYMBOL_GPL(handle_mmio_page_fault_common);
EXPORT_SYMBOL_GPL(handle_mmio_page_fault_common);


@@ -3271,7 +3266,7 @@ static int handle_mmio_page_fault(struct kvm_vcpu *vcpu, u64 addr,
	int ret;
	int ret;


	ret = handle_mmio_page_fault_common(vcpu, addr, direct);
	ret = handle_mmio_page_fault_common(vcpu, addr, direct);
	WARN_ON(ret < 0);
	WARN_ON(ret == RET_MMIO_PF_BUG);
	return ret;
	return ret;
}
}


+14 −0
Original line number Original line Diff line number Diff line
@@ -52,6 +52,20 @@


int kvm_mmu_get_spte_hierarchy(struct kvm_vcpu *vcpu, u64 addr, u64 sptes[4]);
int kvm_mmu_get_spte_hierarchy(struct kvm_vcpu *vcpu, u64 addr, u64 sptes[4]);
void kvm_mmu_set_mmio_spte_mask(u64 mmio_mask);
void kvm_mmu_set_mmio_spte_mask(u64 mmio_mask);

/*
 * Return values of handle_mmio_page_fault_common:
 * RET_MMIO_PF_EMULATE: it is a real mmio page fault, emulate the instruction
 *			 directly.
 * RET_MMIO_PF_RETRY: let CPU fault again on the address.
 * RET_MMIO_PF_BUG: bug is detected.
 */
enum {
	RET_MMIO_PF_EMULATE = 1,
	RET_MMIO_PF_RETRY = 0,
	RET_MMIO_PF_BUG = -1
};

int handle_mmio_page_fault_common(struct kvm_vcpu *vcpu, u64 addr, bool direct);
int handle_mmio_page_fault_common(struct kvm_vcpu *vcpu, u64 addr, bool direct);
int kvm_init_shadow_mmu(struct kvm_vcpu *vcpu, struct kvm_mmu *context);
int kvm_init_shadow_mmu(struct kvm_vcpu *vcpu, struct kvm_mmu *context);


+2 −2
Original line number Original line Diff line number Diff line
@@ -5366,10 +5366,10 @@ static int handle_ept_misconfig(struct kvm_vcpu *vcpu)
	gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS);
	gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS);


	ret = handle_mmio_page_fault_common(vcpu, gpa, true);
	ret = handle_mmio_page_fault_common(vcpu, gpa, true);
	if (likely(ret == 1))
	if (likely(ret == RET_MMIO_PF_EMULATE))
		return x86_emulate_instruction(vcpu, gpa, 0, NULL, 0) ==
		return x86_emulate_instruction(vcpu, gpa, 0, NULL, 0) ==
					      EMULATE_DONE;
					      EMULATE_DONE;
	if (unlikely(!ret))
	if (unlikely(ret == RET_MMIO_PF_RETRY))
		return 1;
		return 1;


	/* It is the real ept misconfig */
	/* It is the real ept misconfig */