Skip to content

Commit aa2024c

Browse files
committed
KVM: x86/mmu: Embed direct bits into gpa for KVM_PRE_FAULT_MEMORY
Bug[*] reported for TDX case when enabling KVM_PRE_FAULT_MEMORY in QEMU. It turns out that @gpa passed to kvm_mmu_do_page_fault() doesn't have shared bit set when the memory attribute of it is shared, and it leads to wrong root in tdp_mmu_get_root_for_fault(). Fix it by embedding the direct bits in the gpa that is passed to kvm_tdp_map_page(), when the memory of the gpa is not private. [*] https://lore.kernel.org/qemu-devel/[email protected]/ Reported-by: Xiaoyao Li <[email protected]> Closes: https://lore.kernel.org/qemu-devel/[email protected]/ Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Xiaoyao Li <[email protected]> Message-ID: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 179a842 commit aa2024c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4896,6 +4896,7 @@ long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu,
48964896
{
48974897
u64 error_code = PFERR_GUEST_FINAL_MASK;
48984898
u8 level = PG_LEVEL_4K;
4899+
u64 direct_bits;
48994900
u64 end;
49004901
int r;
49014902

@@ -4910,15 +4911,18 @@ long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu,
49104911
if (r)
49114912
return r;
49124913

4914+
direct_bits = 0;
49134915
if (kvm_arch_has_private_mem(vcpu->kvm) &&
49144916
kvm_mem_is_private(vcpu->kvm, gpa_to_gfn(range->gpa)))
49154917
error_code |= PFERR_PRIVATE_ACCESS;
4918+
else
4919+
direct_bits = gfn_to_gpa(kvm_gfn_direct_bits(vcpu->kvm));
49164920

49174921
/*
49184922
* Shadow paging uses GVA for kvm page fault, so restrict to
49194923
* two-dimensional paging.
49204924
*/
4921-
r = kvm_tdp_map_page(vcpu, range->gpa, error_code, &level);
4925+
r = kvm_tdp_map_page(vcpu, range->gpa | direct_bits, error_code, &level);
49224926
if (r < 0)
49234927
return r;
49244928

0 commit comments

Comments
 (0)