kvmarm.lists.cs.columbia.edu archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] KVM: arm64: Minor page fault handler improvement
@ 2021-03-16  4:11 Gavin Shan
  2021-03-16  4:11 ` [PATCH v2 1/3] KVM: arm64: Hide kvm_mmu_wp_memory_region() Gavin Shan
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Gavin Shan @ 2021-03-16  4:11 UTC (permalink / raw)
  To: kvmarm; +Cc: maz, will, linux-kernel, shan.gavin

The series includes several minior improvements to stage-2 page fault
handler: PATCH[1/2] are cleaning up the code. PATCH[3] don't retrieve
the memory slot again in the page fault handler to save a bit CPU cycles.

Changelog
=========
v2:
   * Rebased to 5.12.rc3 and include r-bs from Keqian  (Gavin)
   * Drop patch to fix IPA limit boundary issue        (Keqian)
   * Comments on why we use __gfn_to_pfn_memslot()     (Keqian)

Gavin Shan (3):
  KVM: arm64: Hide kvm_mmu_wp_memory_region()
  KVM: arm64: Use find_vma_intersection()
  KVM: arm64: Don't retrieve memory slot again in page fault handler

 arch/arm64/include/asm/kvm_host.h |  1 -
 arch/arm64/kvm/mmu.c              | 21 ++++++++++++++-------
 2 files changed, 14 insertions(+), 8 deletions(-)

-- 
2.23.0

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/3] KVM: arm64: Hide kvm_mmu_wp_memory_region()
  2021-03-16  4:11 [PATCH v2 0/3] KVM: arm64: Minor page fault handler improvement Gavin Shan
@ 2021-03-16  4:11 ` Gavin Shan
  2021-03-16  4:11 ` [PATCH v2 2/3] KVM: arm64: Use find_vma_intersection() Gavin Shan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Gavin Shan @ 2021-03-16  4:11 UTC (permalink / raw)
  To: kvmarm; +Cc: maz, will, linux-kernel, shan.gavin

We needn't expose the function as it's only used by mmu.c since it
was introduced by commit c64735554c0a ("KVM: arm: Add initial dirty
page locking support").

Signed-off-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: Keqian Zhu <zhukeqian1@huawei.com>
---
 arch/arm64/include/asm/kvm_host.h | 1 -
 arch/arm64/kvm/mmu.c              | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 3d10e6527f7d..688f2df1957b 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -632,7 +632,6 @@ void kvm_arm_resume_guest(struct kvm *kvm);
 	})
 
 void force_vm_exit(const cpumask_t *mask);
-void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot);
 
 int handle_exit(struct kvm_vcpu *vcpu, int exception_index);
 void handle_exit_early(struct kvm_vcpu *vcpu, int exception_index);
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 8711894db8c2..28f3b3736dc8 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -555,7 +555,7 @@ static void stage2_wp_range(struct kvm_s2_mmu *mmu, phys_addr_t addr, phys_addr_
  * Acquires kvm_mmu_lock. Called with kvm->slots_lock mutex acquired,
  * serializing operations for VM memory regions.
  */
-void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot)
+static void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot)
 {
 	struct kvm_memslots *slots = kvm_memslots(kvm);
 	struct kvm_memory_slot *memslot = id_to_memslot(slots, slot);
-- 
2.23.0

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/3] KVM: arm64: Use find_vma_intersection()
  2021-03-16  4:11 [PATCH v2 0/3] KVM: arm64: Minor page fault handler improvement Gavin Shan
  2021-03-16  4:11 ` [PATCH v2 1/3] KVM: arm64: Hide kvm_mmu_wp_memory_region() Gavin Shan
@ 2021-03-16  4:11 ` Gavin Shan
  2021-03-16  4:11 ` [PATCH v2 3/3] KVM: arm64: Don't retrieve memory slot again in page fault handler Gavin Shan
  2021-04-07 13:46 ` [PATCH v2 0/3] KVM: arm64: Minor page fault handler improvement Marc Zyngier
  3 siblings, 0 replies; 5+ messages in thread
From: Gavin Shan @ 2021-03-16  4:11 UTC (permalink / raw)
  To: kvmarm; +Cc: maz, will, linux-kernel, shan.gavin

find_vma_intersection() has been existing to search the intersected
vma. This uses the function where it's applicable, to simplify the
code.

Signed-off-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: Keqian Zhu <zhukeqian1@huawei.com>
---
 arch/arm64/kvm/mmu.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 28f3b3736dc8..192e0df2fc8e 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -421,10 +421,11 @@ static void stage2_unmap_memslot(struct kvm *kvm,
 	 *     +--------------------------------------------+
 	 */
 	do {
-		struct vm_area_struct *vma = find_vma(current->mm, hva);
+		struct vm_area_struct *vma;
 		hva_t vm_start, vm_end;
 
-		if (!vma || vma->vm_start >= reg_end)
+		vma = find_vma_intersection(current->mm, hva, reg_end);
+		if (!vma)
 			break;
 
 		/*
@@ -1329,10 +1330,11 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
 	 *     +--------------------------------------------+
 	 */
 	do {
-		struct vm_area_struct *vma = find_vma(current->mm, hva);
+		struct vm_area_struct *vma;
 		hva_t vm_start, vm_end;
 
-		if (!vma || vma->vm_start >= reg_end)
+		vma = find_vma_intersection(current->mm, hva, reg_end);
+		if (!vma)
 			break;
 
 		/*
-- 
2.23.0

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 3/3] KVM: arm64: Don't retrieve memory slot again in page fault handler
  2021-03-16  4:11 [PATCH v2 0/3] KVM: arm64: Minor page fault handler improvement Gavin Shan
  2021-03-16  4:11 ` [PATCH v2 1/3] KVM: arm64: Hide kvm_mmu_wp_memory_region() Gavin Shan
  2021-03-16  4:11 ` [PATCH v2 2/3] KVM: arm64: Use find_vma_intersection() Gavin Shan
@ 2021-03-16  4:11 ` Gavin Shan
  2021-04-07 13:46 ` [PATCH v2 0/3] KVM: arm64: Minor page fault handler improvement Marc Zyngier
  3 siblings, 0 replies; 5+ messages in thread
From: Gavin Shan @ 2021-03-16  4:11 UTC (permalink / raw)
  To: kvmarm; +Cc: maz, will, linux-kernel, shan.gavin

We needn't retrieve the memory slot again in user_mem_abort() because
the corresponding memory slot has been passed from the caller. This
would save some CPU cycles. For example, the time used to write 1GB
memory, which is backed by 2MB hugetlb pages and write-protected, is
dropped by 6.8% from 928ms to 864ms.

Signed-off-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: Keqian Zhu <zhukeqian1@huawei.com>
---
 arch/arm64/kvm/mmu.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 192e0df2fc8e..2491b40a294a 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -843,10 +843,15 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 	 * unmapped afterwards, the call to kvm_unmap_hva will take it away
 	 * from us again properly. This smp_rmb() interacts with the smp_wmb()
 	 * in kvm_mmu_notifier_invalidate_<page|range_end>.
+	 *
+	 * Besides, __gfn_to_pfn_memslot() instead of gfn_to_pfn_prot() is
+	 * used to avoid unnecessary overhead introduced to locate the memory
+	 * slot because it's always fixed even @gfn is adjusted for huge pages.
 	 */
 	smp_rmb();
 
-	pfn = gfn_to_pfn_prot(kvm, gfn, write_fault, &writable);
+	pfn = __gfn_to_pfn_memslot(memslot, gfn, false, NULL,
+				   write_fault, &writable, NULL);
 	if (pfn == KVM_PFN_ERR_HWPOISON) {
 		kvm_send_hwpoison_signal(hva, vma_shift);
 		return 0;
@@ -912,7 +917,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 	/* Mark the page dirty only if the fault is handled successfully */
 	if (writable && !ret) {
 		kvm_set_pfn_dirty(pfn);
-		mark_page_dirty(kvm, gfn);
+		mark_page_dirty_in_slot(kvm, memslot, gfn);
 	}
 
 out_unlock:
-- 
2.23.0

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/3] KVM: arm64: Minor page fault handler improvement
  2021-03-16  4:11 [PATCH v2 0/3] KVM: arm64: Minor page fault handler improvement Gavin Shan
                   ` (2 preceding siblings ...)
  2021-03-16  4:11 ` [PATCH v2 3/3] KVM: arm64: Don't retrieve memory slot again in page fault handler Gavin Shan
@ 2021-04-07 13:46 ` Marc Zyngier
  3 siblings, 0 replies; 5+ messages in thread
From: Marc Zyngier @ 2021-04-07 13:46 UTC (permalink / raw)
  To: kvmarm, Gavin Shan; +Cc: will, linux-kernel, shan.gavin

On Tue, 16 Mar 2021 12:11:23 +0800, Gavin Shan wrote:
> The series includes several minior improvements to stage-2 page fault
> handler: PATCH[1/2] are cleaning up the code. PATCH[3] don't retrieve
> the memory slot again in the page fault handler to save a bit CPU cycles.
> 
> Changelog
> =========
> v2:
>    * Rebased to 5.12.rc3 and include r-bs from Keqian  (Gavin)
>    * Drop patch to fix IPA limit boundary issue        (Keqian)
>    * Comments on why we use __gfn_to_pfn_memslot()     (Keqian)
> 
> [...]

Applied to kvm-arm64/memslot-fixes, thanks!

[1/3] KVM: arm64: Hide kvm_mmu_wp_memory_region()
      commit: eab62148478d339a37c7a6b37d34182ccf5056ad
[2/3] KVM: arm64: Use find_vma_intersection()
      commit: c728fd4ce75e9c342ea96facc5a2fe5ddb976a67
[3/3] KVM: arm64: Don't retrieve memory slot again in page fault handler
      commit: 10ba2d17d2972926c60e01dace6d7a3f8d968c4f

Cheers,

	M.
-- 
Without deviation from the norm, progress is not possible.


_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-07 13:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-16  4:11 [PATCH v2 0/3] KVM: arm64: Minor page fault handler improvement Gavin Shan
2021-03-16  4:11 ` [PATCH v2 1/3] KVM: arm64: Hide kvm_mmu_wp_memory_region() Gavin Shan
2021-03-16  4:11 ` [PATCH v2 2/3] KVM: arm64: Use find_vma_intersection() Gavin Shan
2021-03-16  4:11 ` [PATCH v2 3/3] KVM: arm64: Don't retrieve memory slot again in page fault handler Gavin Shan
2021-04-07 13:46 ` [PATCH v2 0/3] KVM: arm64: Minor page fault handler improvement Marc Zyngier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).