[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <DM8PR11MB5670F958184509909A1876B892259@DM8PR11MB5670.namprd11.prod.outlook.com>
Date: Tue, 25 May 2021 08:43:07 +0000
From: "Duan, Zhenzhong" <zhenzhong.duan@...el.com>
To: Paolo Bonzini <pbonzini@...hat.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
CC: "linux-kselftest@...r.kernel.org" <linux-kselftest@...r.kernel.org>,
"kvm@...r.kernel.org" <kvm@...r.kernel.org>,
"shuah@...nel.org" <shuah@...nel.org>
Subject: RE: [PATCH] selftests: kvm: Fix a potential elf loading issue
> -----Original Message-----
> From: Paolo Bonzini <pbonzini@...hat.com>
> Sent: Monday, May 24, 2021 8:28 PM
> To: Duan, Zhenzhong <zhenzhong.duan@...el.com>; linux-
> kernel@...r.kernel.org
> Cc: linux-kselftest@...r.kernel.org; kvm@...r.kernel.org; shuah@...nel.org
> Subject: Re: [PATCH] selftests: kvm: Fix a potential elf loading issue
>
> 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@...el.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?
Yes, this is better, thanks for fixing.
Regards
Zhenzhong
Powered by blists - more mailing lists