Skip to content

Commit 1de9992

Browse files
Li zemingsean-jc
authored andcommitted
KVM: x86/mmu: Remove unnecessary ‘NULL’ values from sptep
Don't initialize "spte" and "sptep" in fast_page_fault() as they are both guaranteed (for all intents and purposes) to be written at the start of every loop iteration. Add a sanity check that "sptep" is non-NULL after walking the shadow page tables, as encountering a NULL root would result in "spte" not being written, i.e. would lead to uninitialized data or the previous value being consumed. Signed-off-by: Li zeming <zeming@nfschina.com> Link: https://lore.kernel.org/r/20230905182006.2964-1-zeming@nfschina.com [sean: rewrite changelog with --verbose] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent c9f65a3 commit 1de9992

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,8 +3425,8 @@ static int fast_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
34253425
{
34263426
struct kvm_mmu_page *sp;
34273427
int ret = RET_PF_INVALID;
3428-
u64 spte = 0ull;
3429-
u64 *sptep = NULL;
3428+
u64 spte;
3429+
u64 *sptep;
34303430
uint retry_count = 0;
34313431

34323432
if (!page_fault_can_be_fast(fault))
@@ -3442,6 +3442,14 @@ static int fast_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
34423442
else
34433443
sptep = fast_pf_get_last_sptep(vcpu, fault->addr, &spte);
34443444

3445+
/*
3446+
* It's entirely possible for the mapping to have been zapped
3447+
* by a different task, but the root page should always be
3448+
* available as the vCPU holds a reference to its root(s).
3449+
*/
3450+
if (WARN_ON_ONCE(!sptep))
3451+
spte = REMOVED_SPTE;
3452+
34453453
if (!is_shadow_present_pte(spte))
34463454
break;
34473455

0 commit comments

Comments
 (0)