Skip to contentSkip to conversation

KVM: arm/arm64: release kvm->mmu_lock in loop to prevent starvation

PATCH In review Jiang Yi 2 participants 2 messages Apr 15, 2020 – May 7, 2020 KVM arm64

lore
Share & tools
lore

Jiang Yi

author
#0 lore raw

PATCH 1/1 KVM: arm/arm64: release kvm->mmu_lock in loop to prevent starvation

Do cond_resched_lock() in stage2_flush_memslot() like what is done in unmap_stage2_range() and other places holding mmu_lock while processing a possibly large range of memory.

---
 virt/kvm/arm/mmu.c | 3 +++
 1 file changed, 3 insertions(+)
virt/kvm/arm/mmu.c +3 -0
index e3b9ee268823..7315af2c52f8 100644
@@ -417,16 +417,19 @@ static void stage2_flush_memslot(struct kvm *kvm,
 	phys_addr_t next;
 	pgd_t *pgd;
 
 	pgd = kvm->arch.pgd + stage2_pgd_index(kvm, addr);
 	do {
 		next = stage2_pgd_addr_end(kvm, addr, end);
 		if (!stage2_pgd_none(kvm, *pgd))
 			stage2_flush_puds(kvm, pgd, addr, next);
+
+		if (next != end)
+			cond_resched_lock(&kvm->mmu_lock);
 	} while (pgd++, addr = next, addr != end);
 }
 
 /**
  * stage2_flush_vm - Invalidate cache for pages mapped in stage 2
  * @kvm: The struct kvm pointer
  *
  * Go through the stage 2 page tables and invalidate any cache lines
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Jiang Yi

Do cond_resched_lock() in stage2_flush_memslot() like what is done in unmap_stage2_range() and other places holding mmu_lock while processing a possibly large range of memory.

---
  virt/kvm/arm/mmu.c | 3 +++
  1 file changed, 3 insertions(+)
virt/kvm/arm/mmu.c +0 -0
index e3b9ee268823..7315af2c52f8 100644
@@ -417,16 +417,19 @@ static void stage2_flush_memslot(struct kvm *kvm,
  	phys_addr_t next;
  	pgd_t *pgd;
 

virt/kvm/arm/mmu.c static void stage2_flush_memslot(struct kvm *kvm, · line 429

Quoted 10 lines
virt/kvm/arm/mmu.c +3 -0
  	pgd = kvm->arch.pgd + stage2_pgd_index(kvm, addr);
  	do {
  		next = stage2_pgd_addr_end(kvm, addr, end);
  		if (!stage2_pgd_none(kvm, *pgd))
  			stage2_flush_puds(kvm, pgd, addr, next);
+
+		if (next != end)
+			cond_resched_lock(&kvm->mmu_lock);
  	} while (pgd++, addr = next, addr != end);
  }

Given that this is called under the srcu_lock this looks good to me:

Quoted 7 lines
virt/kvm/arm/mmu.c +0 -0
  /**
   * stage2_flush_vm - Invalidate cache for pages mapped in stage 2
   * @kvm: The struct kvm pointer
   *
   * Go through the stage 2 page tables and invalidate any cache lines