mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] KVM: x86: avoid some unnecessary copy in __x86_set_memory_region()
@ 2020-01-23  3:00 linmiaohe
  2020-01-23 12:15 ` Paolo Bonzini
  2020-01-26  0:39 ` kbuild test robot
  0 siblings, 2 replies; 3+ messages in thread
From: linmiaohe @ 2020-01-23  3:00 UTC (permalink / raw)
  To: pbonzini, rkrcmar, sean.j.christopherson, vkuznets, wanpengli,
	jmattson, joro, tglx, mingo, bp, hpa
  Cc: linmiaohe, kvm, linux-kernel, x86

From: Miaohe Lin <linmiaohe@huawei.com>

Only userspace_addr and npages are passed to vm_munmap() when remove a
memory region. So we shouldn't copy the integral kvm_memory_slot struct.

No functional change intended.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 arch/x86/kvm/x86.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index d1faa74981d9..767f29877938 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -9735,9 +9735,9 @@ void kvm_arch_sync_events(struct kvm *kvm)
 int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size)
 {
 	int i, r;
-	unsigned long hva;
+	unsigned long hva, uaddr, npages;
 	struct kvm_memslots *slots = kvm_memslots(kvm);
-	struct kvm_memory_slot *slot, old;
+	struct kvm_memory_slot *slot;
 
 	/* Called with kvm->slots_lock held.  */
 	if (WARN_ON(id >= KVM_MEM_SLOTS_NUM))
@@ -9761,9 +9761,10 @@ int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size)
 			return 0;
 
 		hva = 0;
+		uaddr = slot->userspace_addr;
+		npages = slot->npages;
 	}
 
-	old = *slot;
 	for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) {
 		struct kvm_userspace_memory_region m;
 
@@ -9778,7 +9779,7 @@ int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size)
 	}
 
 	if (!size)
-		vm_munmap(old.userspace_addr, old.npages * PAGE_SIZE);
+		vm_munmap(uaddr, npages * PAGE_SIZE);
 
 	return 0;
 }
-- 
2.19.1


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

end of thread, other threads:[~2020-01-26  0:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-23  3:00 [PATCH] KVM: x86: avoid some unnecessary copy in __x86_set_memory_region() linmiaohe
2020-01-23 12:15 ` Paolo Bonzini
2020-01-26  0:39 ` kbuild test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®