KVM: x86/mmu: Refactor slot null check in kvm_mmu_hugepage_adjust
PATCH 1/1 KVM: x86/mmu: Refactor slot null check in kvm_mmu_hugepage_adjust
The current code is correct but relies on is_error_noslot_pfn() to ensure slot is not null. The only reason is_error_noslot_pfn() was checked instead is because we did not have the slot before commit 6574422f913e ("KVM: x86/mmu: Pass the memslot around via struct kvm_page_fault") and looking up the memslot is expensive.
Now that the slot is available, explicitly check if it's null and get rid of the redundant is_error_noslot_pfn() check.
--- arch/x86/kvm/mmu/mmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/mmu/mmu.c +2 -2
@@ -2925,10 +2925,10 @@ void kvm_mmu_hugepage_adjust(struct kvm_vcpu *vcpu, struct kvm_page_fault *faultif (unlikely (fault->max_level ==PG_LEVEL_4K ))return ; -if (is_error_noslot_pfn (fault->pfn) ||kvm_is_reserved_pfn (fault->pfn)) +if (!slot ||kvm_slot_dirty_track_enabled (slot))return ; -if (kvm_slot_dirty_track_enabled (slot)) +if (kvm_is_reserved_pfn (fault->pfn))return ;/*
Signature · 1 line
2.33.0.rc2.250.ged5fa647cd-goog
Quoted 6 lines · David Matlack
The current code is correct but relies on
is_error_noslot_pfn()to ensure slot is not null. The only reasonis_error_noslot_pfn()was checked instead is because we did not have the slot before commit6574422f913e("KVM: x86/mmu: Pass the memslot around via structkvm_page_fault") and looking up the memslot is expensive.
Quoted 6 lines
Now that the slot is available, explicitly check if it's null and get rid of the redundant
is_error_noslot_pfn()check.Suggested-by Sean Christopherson <[email protected]>Signed-off-by David Matlack <[email protected]>---
Paolo Bonzini
maintainerQuoted 23 lines · David Matlack
The current code is correct but relies on
is_error_noslot_pfn()to ensure slot is not null. The only reasonis_error_noslot_pfn()was checked instead is because we did not have the slot before commit6574422f913e("KVM: x86/mmu: Pass the memslot around via structkvm_page_fault") and looking up the memslot is expensive.Now that the slot is available, explicitly check if it's null and get rid of the redundant
is_error_noslot_pfn()check.Suggested-by Sean Christopherson <[email protected]>Signed-off-by David Matlack <[email protected]>--- arch/x86/kvm/mmu/mmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/x86/kvm/mmu/mmu.c +0
-0@@ -2925,10 +2925,10 @@ void kvm_mmu_hugepage_adjust(struct kvm_vcpu *vcpu, struct kvm_page_fault *faultif (unlikely (fault->max_level ==PG_LEVEL_4K ))return ;
arch/x86/kvm/mmu/mmu.c void kvm_mmu_hugepage_adjust(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault · line 2934
Quoted 10 lines
arch/x86/kvm/mmu/mmu.c +2
-2-if (is_error_noslot_pfn (fault->pfn) ||kvm_is_reserved_pfn (fault->pfn)) +if (!slot ||kvm_slot_dirty_track_enabled (slot))return ; -if (kvm_slot_dirty_track_enabled (slot)) +if (kvm_is_reserved_pfn (fault->pfn))return ;/*
Squashed, thanks.
Paolo