kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Zhenzhong Duan <zhenzhong.duan@intel.com>, linux-kernel@vger.kernel.org
Cc: linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, shuah@kernel.org
Subject: Re: [PATCH] selftests: kvm: Fix a potential elf loading issue
Date: Mon, 24 May 2021 14:27:54 +0200	[thread overview]
Message-ID: <2b16869a-7518-529b-9cbe-fb2e5f61a6e9@redhat.com> (raw)
In-Reply-To: <20210512043107.30076-2-zhenzhong.duan@intel.com>

On 12/05/21 06:31, Zhenzhong Duan wrote:
> vm_vaddr_alloc() setup GVA to GPA mapping page by page, then GPA may not be
> continuous if same memslot is used for data and page table allocation.
> 
> kvm_vm_elf_load() expects a continuous memory of GPA or else it need to
> read file data page by page. Fix it by adding a check in vm_vaddr_alloc()
> to ensure memory is allocated in a whole if same memslot is used for data
> and page table.
> 
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> ---
Why not do

diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 7426163d448a..f362a066f37a 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -1170,6 +1170,9 @@ vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min,
  	uint64_t pages = (sz >> vm->page_shift) + ((sz % vm->page_size) != 0);
  
  	virt_pgd_alloc(vm, pgd_memslot);
+	vm_paddr_t paddr = vm_phy_pages_alloc(vm, pages,
+					      KVM_UTIL_MIN_PFN * vm->page_size,
+					      data_memslot);
  
  	/*
  	 * Find an unused range of virtual page addresses of at least
@@ -1179,11 +1182,7 @@ vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min,
  
  	/* Map the virtual pages. */
  	for (vm_vaddr_t vaddr = vaddr_start; pages > 0;
-		pages--, vaddr += vm->page_size) {
-		vm_paddr_t paddr;
-
-		paddr = vm_phy_page_alloc(vm,
-				KVM_UTIL_MIN_PFN * vm->page_size, data_memslot);
+		pages--, vaddr += vm->page_size, paddr += vm->page_size) {
  
  		virt_pg_map(vm, vaddr, paddr, pgd_memslot);
  

instead?

Paolo


  reply	other threads:[~2021-05-24 12:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-12  4:31 [PATCH] selftests: kvm: make allocation of extra memory take effect Zhenzhong Duan
2021-05-11 19:18 ` Andrew Jones
2021-05-12  4:31 ` [PATCH] selftests: kvm: Fix a potential elf loading issue Zhenzhong Duan
2021-05-24 12:27   ` Paolo Bonzini [this message]
2021-05-25  8:43     ` Duan, Zhenzhong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2b16869a-7518-529b-9cbe-fb2e5f61a6e9@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=zhenzhong.duan@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).