Skip to content

Commit 619b507

Browse files
dmatlackMarc Zyngier
authored andcommitted
KVM: Move kvm_arch_flush_remote_tlbs_memslot() to common code
Move kvm_arch_flush_remote_tlbs_memslot() to common code and drop "arch_" from the name. kvm_arch_flush_remote_tlbs_memslot() is just a range-based TLB invalidation where the range is defined by the memslot. Now that kvm_flush_remote_tlbs_range() can be called from common code we can just use that and drop a bunch of duplicate code from the arch directories. Note this adds a lockdep assertion for slots_lock being held when calling kvm_flush_remote_tlbs_memslot(), which was previously only asserted on x86. MIPS has calls to kvm_flush_remote_tlbs_memslot(), but they all hold the slots_lock, so the lockdep assertion continues to hold true. Also drop the CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT ifdef gating kvm_flush_remote_tlbs_memslot(), since it is no longer necessary. Signed-off-by: David Matlack <[email protected]> Signed-off-by: Raghavendra Rao Ananta <[email protected]> Reviewed-by: Gavin Shan <[email protected]> Reviewed-by: Shaoqin Huang <[email protected]> Acked-by: Anup Patel <[email protected]> Acked-by: Sean Christopherson <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d478899 commit 619b507

File tree

7 files changed

+23
-42
lines changed

7 files changed

+23
-42
lines changed

arch/arm64/kvm/arm.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,12 +1532,6 @@ void kvm_arch_sync_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot)
15321532

15331533
}
15341534

1535-
void kvm_arch_flush_remote_tlbs_memslot(struct kvm *kvm,
1536-
const struct kvm_memory_slot *memslot)
1537-
{
1538-
kvm_flush_remote_tlbs(kvm);
1539-
}
1540-
15411535
static int kvm_vm_ioctl_set_device_addr(struct kvm *kvm,
15421536
struct kvm_arm_device_addr *dev_addr)
15431537
{

arch/mips/kvm/mips.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
199199
/* Flush slot from GPA */
200200
kvm_mips_flush_gpa_pt(kvm, slot->base_gfn,
201201
slot->base_gfn + slot->npages - 1);
202-
kvm_arch_flush_remote_tlbs_memslot(kvm, slot);
202+
kvm_flush_remote_tlbs_memslot(kvm, slot);
203203
spin_unlock(&kvm->mmu_lock);
204204
}
205205

@@ -235,7 +235,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
235235
needs_flush = kvm_mips_mkclean_gpa_pt(kvm, new->base_gfn,
236236
new->base_gfn + new->npages - 1);
237237
if (needs_flush)
238-
kvm_arch_flush_remote_tlbs_memslot(kvm, new);
238+
kvm_flush_remote_tlbs_memslot(kvm, new);
239239
spin_unlock(&kvm->mmu_lock);
240240
}
241241
}
@@ -987,12 +987,6 @@ int kvm_arch_flush_remote_tlbs(struct kvm *kvm)
987987
return 1;
988988
}
989989

990-
void kvm_arch_flush_remote_tlbs_memslot(struct kvm *kvm,
991-
const struct kvm_memory_slot *memslot)
992-
{
993-
kvm_flush_remote_tlbs(kvm);
994-
}
995-
996990
int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
997991
{
998992
int r;

arch/riscv/kvm/mmu.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,6 @@ void kvm_arch_sync_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot)
406406
{
407407
}
408408

409-
void kvm_arch_flush_remote_tlbs_memslot(struct kvm *kvm,
410-
const struct kvm_memory_slot *memslot)
411-
{
412-
kvm_flush_remote_tlbs(kvm);
413-
}
414-
415409
void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free)
416410
{
417411
}

arch/x86/kvm/mmu/mmu.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6666,7 +6666,7 @@ static void kvm_rmap_zap_collapsible_sptes(struct kvm *kvm,
66666666
*/
66676667
if (walk_slot_rmaps(kvm, slot, kvm_mmu_zap_collapsible_spte,
66686668
PG_LEVEL_4K, KVM_MAX_HUGEPAGE_LEVEL - 1, true))
6669-
kvm_arch_flush_remote_tlbs_memslot(kvm, slot);
6669+
kvm_flush_remote_tlbs_memslot(kvm, slot);
66706670
}
66716671

66726672
void kvm_mmu_zap_collapsible_sptes(struct kvm *kvm,
@@ -6685,20 +6685,6 @@ void kvm_mmu_zap_collapsible_sptes(struct kvm *kvm,
66856685
}
66866686
}
66876687

6688-
void kvm_arch_flush_remote_tlbs_memslot(struct kvm *kvm,
6689-
const struct kvm_memory_slot *memslot)
6690-
{
6691-
/*
6692-
* All current use cases for flushing the TLBs for a specific memslot
6693-
* related to dirty logging, and many do the TLB flush out of mmu_lock.
6694-
* The interaction between the various operations on memslot must be
6695-
* serialized by slots_locks to ensure the TLB flush from one operation
6696-
* is observed by any other operation on the same memslot.
6697-
*/
6698-
lockdep_assert_held(&kvm->slots_lock);
6699-
kvm_flush_remote_tlbs_range(kvm, memslot->base_gfn, memslot->npages);
6700-
}
6701-
67026688
void kvm_mmu_slot_leaf_clear_dirty(struct kvm *kvm,
67036689
const struct kvm_memory_slot *memslot)
67046690
{

arch/x86/kvm/x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12751,7 +12751,7 @@ static void kvm_mmu_slot_apply_flags(struct kvm *kvm,
1275112751
* See is_writable_pte() for more details (the case involving
1275212752
* access-tracked SPTEs is particularly relevant).
1275312753
*/
12754-
kvm_arch_flush_remote_tlbs_memslot(kvm, new);
12754+
kvm_flush_remote_tlbs_memslot(kvm, new);
1275512755
}
1275612756
}
1275712757

include/linux/kvm_host.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,8 @@ void kvm_vcpu_on_spin(struct kvm_vcpu *vcpu, bool yield_to_kernel_mode);
13601360

13611361
void kvm_flush_remote_tlbs(struct kvm *kvm);
13621362
void kvm_flush_remote_tlbs_range(struct kvm *kvm, gfn_t gfn, u64 nr_pages);
1363+
void kvm_flush_remote_tlbs_memslot(struct kvm *kvm,
1364+
const struct kvm_memory_slot *memslot);
13631365

13641366
#ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE
13651367
int kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int min);
@@ -1388,10 +1390,7 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm,
13881390
unsigned long mask);
13891391
void kvm_arch_sync_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot);
13901392

1391-
#ifdef CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT
1392-
void kvm_arch_flush_remote_tlbs_memslot(struct kvm *kvm,
1393-
const struct kvm_memory_slot *memslot);
1394-
#else /* !CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT */
1393+
#ifndef CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT
13951394
int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log);
13961395
int kvm_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log,
13971396
int *is_dirty, struct kvm_memory_slot **memslot);

virt/kvm/kvm_main.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,20 @@ void kvm_flush_remote_tlbs_range(struct kvm *kvm, gfn_t gfn, u64 nr_pages)
379379
kvm_flush_remote_tlbs(kvm);
380380
}
381381

382+
void kvm_flush_remote_tlbs_memslot(struct kvm *kvm,
383+
const struct kvm_memory_slot *memslot)
384+
{
385+
/*
386+
* All current use cases for flushing the TLBs for a specific memslot
387+
* are related to dirty logging, and many do the TLB flush out of
388+
* mmu_lock. The interaction between the various operations on memslot
389+
* must be serialized by slots_locks to ensure the TLB flush from one
390+
* operation is observed by any other operation on the same memslot.
391+
*/
392+
lockdep_assert_held(&kvm->slots_lock);
393+
kvm_flush_remote_tlbs_range(kvm, memslot->base_gfn, memslot->npages);
394+
}
395+
382396
static void kvm_flush_shadow_all(struct kvm *kvm)
383397
{
384398
kvm_arch_flush_shadow_all(kvm);
@@ -2191,7 +2205,7 @@ static int kvm_get_dirty_log_protect(struct kvm *kvm, struct kvm_dirty_log *log)
21912205
}
21922206

21932207
if (flush)
2194-
kvm_arch_flush_remote_tlbs_memslot(kvm, memslot);
2208+
kvm_flush_remote_tlbs_memslot(kvm, memslot);
21952209

21962210
if (copy_to_user(log->dirty_bitmap, dirty_bitmap_buffer, n))
21972211
return -EFAULT;
@@ -2308,7 +2322,7 @@ static int kvm_clear_dirty_log_protect(struct kvm *kvm,
23082322
KVM_MMU_UNLOCK(kvm);
23092323

23102324
if (flush)
2311-
kvm_arch_flush_remote_tlbs_memslot(kvm, memslot);
2325+
kvm_flush_remote_tlbs_memslot(kvm, memslot);
23122326

23132327
return 0;
23142328
}

0 commit comments

Comments
 (0)