[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2cb1c43c-932e-d587-bc0d-5d433649abb1@redhat.com>
Date: Thu, 23 Jan 2020 13:15:32 +0100
From: Paolo Bonzini <pbonzini@...hat.com>
To: linmiaohe <linmiaohe@...wei.com>, rkrcmar@...hat.com,
sean.j.christopherson@...el.com, vkuznets@...hat.com,
wanpengli@...cent.com, jmattson@...gle.com, joro@...tes.org,
tglx@...utronix.de, mingo@...hat.com, bp@...en8.de, hpa@...or.com
Cc: kvm@...r.kernel.org, linux-kernel@...r.kernel.org, x86@...nel.org
Subject: Re: [PATCH] KVM: x86: avoid some unnecessary copy in
__x86_set_memory_region()
On 23/01/20 04:00, linmiaohe wrote:
> From: Miaohe Lin <linmiaohe@...wei.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.
The compiler should be able to do this change, so I prefer to keep the
old code. Also, moving the assignments inside the "if" risks causing
uninitialized variable warnings, even though indeed they are only used
if size == 0.
Thanks,
Paolo
> No functional change intended.
>
> Signed-off-by: Miaohe Lin <linmiaohe@...wei.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;
> }
>
Powered by blists - more mailing lists