Skip to content

Commit b362c9c

Browse files
author
Maxim Levitsky
committed
KVM: x86/mmu: Embed direct bits into gpa for KVM_PRE_FAULT_MEMORY
JIRA: https://issues.redhat.com/browse/RHEL-47242 commit aa2024c Author: Paolo Bonzini <pbonzini@redhat.com> Date: Tue Jun 10 20:10:18 2025 -0400 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/4a757796-11c2-47f1-ae0d-335626e818fd@intel.com/ Reported-by: Xiaoyao Li <xiaoyao.li@intel.com> Closes: https://lore.kernel.org/qemu-devel/4a757796-11c2-47f1-ae0d-335626e818fd@intel.com/ Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com> Message-ID: <20250611001018.2179964-1-xiaoyao.li@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
1 parent e007308 commit b362c9c

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
@@ -4895,6 +4895,7 @@ long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu,
48954895
{
48964896
u64 error_code = PFERR_GUEST_FINAL_MASK;
48974897
u8 level = PG_LEVEL_4K;
4898+
u64 direct_bits;
48984899
u64 end;
48994900
int r;
49004901

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

4913+
direct_bits = 0;
49124914
if (kvm_arch_has_private_mem(vcpu->kvm) &&
49134915
kvm_mem_is_private(vcpu->kvm, gpa_to_gfn(range->gpa)))
49144916
error_code |= PFERR_PRIVATE_ACCESS;
4917+
else
4918+
direct_bits = gfn_to_gpa(kvm_gfn_direct_bits(vcpu->kvm));
49154919

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

0 commit comments

Comments
 (0)