Skip to content

Commit 50107e8

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86/mmu: Open code leaf invalidation from mmu_notifier
The mmu_notifier path is a bit of a special snowflake, e.g. it zaps only a single address space (because it's per-slot), and can't always yield. Because of this, it calls kvm_tdp_mmu_zap_leafs() in ways that no one else does. Iterate manually over the leafs in response to an mmu_notifier invalidation, instead of invoking kvm_tdp_mmu_zap_leafs(). Drop the @can_yield param from kvm_tdp_mmu_zap_leafs() as its sole remaining caller unconditionally passes "true". Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20230916003916.2545000-2-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 7c329bb commit 50107e8

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6260,7 +6260,7 @@ void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end)
62606260
if (tdp_mmu_enabled) {
62616261
for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++)
62626262
flush = kvm_tdp_mmu_zap_leafs(kvm, i, gfn_start,
6263-
gfn_end, true, flush);
6263+
gfn_end, flush);
62646264
}
62656265

62666266
if (flush)

arch/x86/kvm/mmu/tdp_mmu.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -878,12 +878,12 @@ static bool tdp_mmu_zap_leafs(struct kvm *kvm, struct kvm_mmu_page *root,
878878
* more SPTEs were zapped since the MMU lock was last acquired.
879879
*/
880880
bool kvm_tdp_mmu_zap_leafs(struct kvm *kvm, int as_id, gfn_t start, gfn_t end,
881-
bool can_yield, bool flush)
881+
bool flush)
882882
{
883883
struct kvm_mmu_page *root;
884884

885885
for_each_tdp_mmu_root_yield_safe(kvm, root, as_id)
886-
flush = tdp_mmu_zap_leafs(kvm, root, start, end, can_yield, flush);
886+
flush = tdp_mmu_zap_leafs(kvm, root, start, end, true, flush);
887887

888888
return flush;
889889
}
@@ -1146,8 +1146,13 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
11461146
bool kvm_tdp_mmu_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range,
11471147
bool flush)
11481148
{
1149-
return kvm_tdp_mmu_zap_leafs(kvm, range->slot->as_id, range->start,
1150-
range->end, range->may_block, flush);
1149+
struct kvm_mmu_page *root;
1150+
1151+
for_each_tdp_mmu_root_yield_safe(kvm, root, range->slot->as_id)
1152+
flush = tdp_mmu_zap_leafs(kvm, root, range->start, range->end,
1153+
range->may_block, flush);
1154+
1155+
return flush;
11511156
}
11521157

11531158
typedef bool (*tdp_handler_t)(struct kvm *kvm, struct tdp_iter *iter,

arch/x86/kvm/mmu/tdp_mmu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ __must_check static inline bool kvm_tdp_mmu_get_root(struct kvm_mmu_page *root)
2020
void kvm_tdp_mmu_put_root(struct kvm *kvm, struct kvm_mmu_page *root,
2121
bool shared);
2222

23-
bool kvm_tdp_mmu_zap_leafs(struct kvm *kvm, int as_id, gfn_t start,
24-
gfn_t end, bool can_yield, bool flush);
23+
bool kvm_tdp_mmu_zap_leafs(struct kvm *kvm, int as_id, gfn_t start, gfn_t end,
24+
bool flush);
2525
bool kvm_tdp_mmu_zap_sp(struct kvm *kvm, struct kvm_mmu_page *sp);
2626
void kvm_tdp_mmu_zap_all(struct kvm *kvm);
2727
void kvm_tdp_mmu_invalidate_all_roots(struct kvm *kvm);

0 commit comments

Comments
 (0)