Skip to content

Commit 441a5df

Browse files
committed
KVM: x86/mmu: Do not filter address spaces in for_each_tdp_mmu_root_yield_safe()
All callers except the MMU notifier want to process all address spaces. Remove the address space ID argument of for_each_tdp_mmu_root_yield_safe() and switch the MMU notifier to use __for_each_tdp_mmu_root_yield_safe(). Extracted out of a patch by Sean Christopherson <[email protected]> Cc: [email protected] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 50107e8 commit 441a5df

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6246,7 +6246,6 @@ static bool kvm_rmap_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_e
62466246
void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end)
62476247
{
62486248
bool flush;
6249-
int i;
62506249

62516250
if (WARN_ON_ONCE(gfn_end <= gfn_start))
62526251
return;
@@ -6257,11 +6256,8 @@ void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end)
62576256

62586257
flush = kvm_rmap_zap_gfn_range(kvm, gfn_start, gfn_end);
62596258

6260-
if (tdp_mmu_enabled) {
6261-
for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++)
6262-
flush = kvm_tdp_mmu_zap_leafs(kvm, i, gfn_start,
6263-
gfn_end, flush);
6264-
}
6259+
if (tdp_mmu_enabled)
6260+
flush = kvm_tdp_mmu_zap_leafs(kvm, gfn_start, gfn_end, flush);
62656261

62666262
if (flush)
62676263
kvm_flush_remote_tlbs_range(kvm, gfn_start, gfn_end - gfn_start);

arch/x86/kvm/mmu/tdp_mmu.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,12 @@ static struct kvm_mmu_page *tdp_mmu_next_root(struct kvm *kvm,
211211
#define for_each_valid_tdp_mmu_root_yield_safe(_kvm, _root, _as_id, _shared) \
212212
__for_each_tdp_mmu_root_yield_safe(_kvm, _root, _as_id, _shared, true)
213213

214-
#define for_each_tdp_mmu_root_yield_safe(_kvm, _root, _as_id) \
215-
__for_each_tdp_mmu_root_yield_safe(_kvm, _root, _as_id, false, false)
214+
#define for_each_tdp_mmu_root_yield_safe(_kvm, _root) \
215+
for (_root = tdp_mmu_next_root(_kvm, NULL, false, false); \
216+
_root; \
217+
_root = tdp_mmu_next_root(_kvm, _root, false, false)) \
218+
if (!kvm_lockdep_assert_mmu_lock_held(_kvm, false)) { \
219+
} else
216220

217221
/*
218222
* Iterate over all TDP MMU roots. Requires that mmu_lock be held for write,
@@ -877,12 +881,11 @@ static bool tdp_mmu_zap_leafs(struct kvm *kvm, struct kvm_mmu_page *root,
877881
* true if a TLB flush is needed before releasing the MMU lock, i.e. if one or
878882
* more SPTEs were zapped since the MMU lock was last acquired.
879883
*/
880-
bool kvm_tdp_mmu_zap_leafs(struct kvm *kvm, int as_id, gfn_t start, gfn_t end,
881-
bool flush)
884+
bool kvm_tdp_mmu_zap_leafs(struct kvm *kvm, gfn_t start, gfn_t end, bool flush)
882885
{
883886
struct kvm_mmu_page *root;
884887

885-
for_each_tdp_mmu_root_yield_safe(kvm, root, as_id)
888+
for_each_tdp_mmu_root_yield_safe(kvm, root)
886889
flush = tdp_mmu_zap_leafs(kvm, root, start, end, true, flush);
887890

888891
return flush;
@@ -891,7 +894,6 @@ bool kvm_tdp_mmu_zap_leafs(struct kvm *kvm, int as_id, gfn_t start, gfn_t end,
891894
void kvm_tdp_mmu_zap_all(struct kvm *kvm)
892895
{
893896
struct kvm_mmu_page *root;
894-
int i;
895897

896898
/*
897899
* Zap all roots, including invalid roots, as all SPTEs must be dropped
@@ -905,10 +907,8 @@ void kvm_tdp_mmu_zap_all(struct kvm *kvm)
905907
* is being destroyed or the userspace VMM has exited. In both cases,
906908
* KVM_RUN is unreachable, i.e. no vCPUs will ever service the request.
907909
*/
908-
for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) {
909-
for_each_tdp_mmu_root_yield_safe(kvm, root, i)
910-
tdp_mmu_zap_root(kvm, root, false);
911-
}
910+
for_each_tdp_mmu_root_yield_safe(kvm, root)
911+
tdp_mmu_zap_root(kvm, root, false);
912912
}
913913

914914
/*
@@ -1148,7 +1148,7 @@ bool kvm_tdp_mmu_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range,
11481148
{
11491149
struct kvm_mmu_page *root;
11501150

1151-
for_each_tdp_mmu_root_yield_safe(kvm, root, range->slot->as_id)
1151+
__for_each_tdp_mmu_root_yield_safe(kvm, root, range->slot->as_id, false, false)
11521152
flush = tdp_mmu_zap_leafs(kvm, root, range->start, range->end,
11531153
range->may_block, flush);
11541154

arch/x86/kvm/mmu/tdp_mmu.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ __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, gfn_t end,
24-
bool flush);
23+
bool kvm_tdp_mmu_zap_leafs(struct kvm *kvm, gfn_t start, gfn_t end, bool flush);
2524
bool kvm_tdp_mmu_zap_sp(struct kvm *kvm, struct kvm_mmu_page *sp);
2625
void kvm_tdp_mmu_zap_all(struct kvm *kvm);
2726
void kvm_tdp_mmu_invalidate_all_roots(struct kvm *kvm);

0 commit comments

Comments
 (0)