Skip to content

Commit ea9fcdf

Browse files
yanzhao56sean-jc
authored andcommitted
KVM: x86/mmu: Further check old SPTE is leaf for spurious prefetch fault
Instead of simply treating a prefetch fault as spurious when there's a shadow-present old SPTE, further check if the old SPTE is leaf to determine if a prefetch fault is spurious. It's not reasonable to treat a prefetch fault as spurious when there's a shadow-present non-leaf SPTE without a corresponding shadow-present leaf SPTE. e.g., in the following sequence, a prefetch fault should not be considered spurious: 1. add a memslot with size 4K 2. prefault GPA A in the memslot 3. delete the memslot (zap all disabled) 4. re-add the memslot with size 2M 5. prefault GPA A again. In step 5, the prefetch fault attempts to install a 2M huge entry. Since step 3 zaps the leaf SPTE for GPA A while keeping the non-leaf SPTE, the leaf entry will remain empty after step 5 if the fetch fault is regarded as spurious due to a shadow-present non-leaf SPTE. Signed-off-by: Yan Zhao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 45eb291 commit ea9fcdf

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3020,7 +3020,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, struct kvm_memory_slot *slot,
30203020
}
30213021

30223022
if (is_shadow_present_pte(*sptep)) {
3023-
if (prefetch)
3023+
if (prefetch && is_last_spte(*sptep, level))
30243024
return RET_PF_SPURIOUS;
30253025

30263026
/*

arch/x86/kvm/mmu/tdp_mmu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,8 @@ static int tdp_mmu_map_handle_target_level(struct kvm_vcpu *vcpu,
11531153
if (WARN_ON_ONCE(sp->role.level != fault->goal_level))
11541154
return RET_PF_RETRY;
11551155

1156-
if (fault->prefetch && is_shadow_present_pte(iter->old_spte))
1156+
if (fault->prefetch && is_shadow_present_pte(iter->old_spte) &&
1157+
is_last_spte(iter->old_spte, iter->level))
11571158
return RET_PF_SPURIOUS;
11581159

11591160
if (is_shadow_present_pte(iter->old_spte) &&

0 commit comments

Comments
 (0)