* [PATCH] selftests: kvm: make allocation of extra memory take effect @ 2021-05-12 4:31 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 0 siblings, 2 replies; 5+ messages in thread From: Zhenzhong Duan @ 2021-05-12 4:31 UTC (permalink / raw) To: linux-kernel; +Cc: linux-kselftest, kvm, pbonzini, shuah, Zhenzhong Duan The extra memory pages is missed to be allocated during VM creating. perf_test_util and kvm_page_table_test use it to alloc extra memory currently. Fix it by adding extra_mem_pages to the total memory calculation before allocate. Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com> --- tools/testing/selftests/kvm/lib/kvm_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index fc83f6c5902d..159f4d62241d 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -295,7 +295,7 @@ struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus, */ uint64_t vcpu_pages = (DEFAULT_STACK_PGS + num_percpu_pages) * nr_vcpus; uint64_t extra_pg_pages = (extra_mem_pages + vcpu_pages) / PTES_PER_MIN_PAGE * 2; - uint64_t pages = DEFAULT_GUEST_PHY_PAGES + vcpu_pages + extra_pg_pages; + uint64_t pages = DEFAULT_GUEST_PHY_PAGES + extra_mem_pages + vcpu_pages + extra_pg_pages; struct kvm_vm *vm; int i; -- 2.25.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests: kvm: make allocation of extra memory take effect 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 1 sibling, 0 replies; 5+ messages in thread From: Andrew Jones @ 2021-05-11 19:18 UTC (permalink / raw) To: Zhenzhong Duan; +Cc: linux-kernel, linux-kselftest, kvm, pbonzini, shuah On Wed, May 12, 2021 at 12:31:06PM +0800, Zhenzhong Duan wrote: > The extra memory pages is missed to be allocated during VM creating. > perf_test_util and kvm_page_table_test use it to alloc extra memory > currently. > > Fix it by adding extra_mem_pages to the total memory calculation before > allocate. > > Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com> > --- > tools/testing/selftests/kvm/lib/kvm_util.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c > index fc83f6c5902d..159f4d62241d 100644 > --- a/tools/testing/selftests/kvm/lib/kvm_util.c > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c > @@ -295,7 +295,7 @@ struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus, > */ > uint64_t vcpu_pages = (DEFAULT_STACK_PGS + num_percpu_pages) * nr_vcpus; > uint64_t extra_pg_pages = (extra_mem_pages + vcpu_pages) / PTES_PER_MIN_PAGE * 2; > - uint64_t pages = DEFAULT_GUEST_PHY_PAGES + vcpu_pages + extra_pg_pages; > + uint64_t pages = DEFAULT_GUEST_PHY_PAGES + extra_mem_pages + vcpu_pages + extra_pg_pages; > struct kvm_vm *vm; > int i; > > -- > 2.25.1 > Reviewed-by: Andrew Jones <drjones@redhat.com> Thanks, drew ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] selftests: kvm: Fix a potential elf loading issue 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 ` Zhenzhong Duan 2021-05-24 12:27 ` Paolo Bonzini 1 sibling, 1 reply; 5+ messages in thread From: Zhenzhong Duan @ 2021-05-12 4:31 UTC (permalink / raw) To: linux-kernel; +Cc: linux-kselftest, kvm, pbonzini, shuah, Zhenzhong Duan 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> --- tools/testing/selftests/kvm/lib/kvm_util.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 159f4d62241d..6118a2f8906e 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -1097,9 +1097,14 @@ vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min, uint32_t data_memslot, uint32_t pgd_memslot) { uint64_t pages = (sz >> vm->page_shift) + ((sz % vm->page_size) != 0); + vm_paddr_t paddr_start = 0; virt_pgd_alloc(vm, pgd_memslot); + if (data_memslot == pgd_memslot) + paddr_start = 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 * pages in length. @@ -1111,8 +1116,12 @@ vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min, pages--, vaddr += vm->page_size) { vm_paddr_t paddr; - paddr = vm_phy_page_alloc(vm, - KVM_UTIL_MIN_PFN * vm->page_size, data_memslot); + if (paddr_start) { + paddr = paddr_start; + paddr_start += vm->page_size; + } else + paddr = vm_phy_page_alloc(vm, + KVM_UTIL_MIN_PFN * vm->page_size, data_memslot); virt_pg_map(vm, vaddr, paddr, pgd_memslot); -- 2.25.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests: kvm: Fix a potential elf loading issue 2021-05-12 4:31 ` [PATCH] selftests: kvm: Fix a potential elf loading issue Zhenzhong Duan @ 2021-05-24 12:27 ` Paolo Bonzini 2021-05-25 8:43 ` Duan, Zhenzhong 0 siblings, 1 reply; 5+ messages in thread From: Paolo Bonzini @ 2021-05-24 12:27 UTC (permalink / raw) To: Zhenzhong Duan, linux-kernel; +Cc: linux-kselftest, kvm, shuah 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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* RE: [PATCH] selftests: kvm: Fix a potential elf loading issue 2021-05-24 12:27 ` Paolo Bonzini @ 2021-05-25 8:43 ` Duan, Zhenzhong 0 siblings, 0 replies; 5+ messages in thread From: Duan, Zhenzhong @ 2021-05-25 8:43 UTC (permalink / raw) To: Paolo Bonzini, linux-kernel; +Cc: linux-kselftest, kvm, shuah > -----Original Message----- > From: Paolo Bonzini <pbonzini@redhat.com> > Sent: Monday, May 24, 2021 8:28 PM > To: Duan, Zhenzhong <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 > > 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? Yes, this is better, thanks for fixing. Regards Zhenzhong ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-05-25 8:43 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 2021-05-25 8:43 ` Duan, Zhenzhong
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).