diff mbox series

[v2,038/144] KVM: selftests: Push vm_adjust_num_guest_pages() into "w/o vCPUs" helper

Message ID 20220603004331.1523888-39-seanjc@google.com (mailing list archive)
State New, archived
Headers show
Series KVM: selftests: Overhaul APIs, purge VCPU_ID | expand

Commit Message

Sean Christopherson June 3, 2022, 12:41 a.m. UTC
Move the call to vm_adjust_num_guest_pages() from vm_create_with_vcpus()
down into vm_create_without_vcpus().  This will allow a future patch to
make the "w/o vCPUs" variant the common inner helper, e.g. so that the
"with_vcpus" helper calls the "without_vcpus" helper, instead of having
them be separate paths.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 tools/testing/selftests/kvm/lib/kvm_util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Andrew Jones June 8, 2022, 2:38 p.m. UTC | #1
On Fri, Jun 03, 2022 at 12:41:45AM +0000, Sean Christopherson wrote:
> Move the call to vm_adjust_num_guest_pages() from vm_create_with_vcpus()
> down into vm_create_without_vcpus().  This will allow a future patch to
> make the "w/o vCPUs" variant the common inner helper, e.g. so that the
> "with_vcpus" helper calls the "without_vcpus" helper, instead of having
> them be separate paths.
> 
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
>  tools/testing/selftests/kvm/lib/kvm_util.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index 1c5caf2ddca4..6b0b65c26d4d 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -282,6 +282,8 @@ struct kvm_vm *vm_create_without_vcpus(enum vm_guest_mode mode, uint64_t pages)
>  {
>  	struct kvm_vm *vm;
>  
> +	pages = vm_adjust_num_guest_pages(VM_MODE_DEFAULT, pages);

Hi Sean,

We should pass 'mode' here.

Thanks,
drew

> +
>  	vm = __vm_create(mode, pages);
>  
>  	kvm_vm_elf_load(vm, program_invocation_name);
> @@ -341,8 +343,6 @@ struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus,
>  		    "nr_vcpus = %d too large for host, max-vcpus = %d",
>  		    nr_vcpus, kvm_check_cap(KVM_CAP_MAX_VCPUS));
>  
> -	pages = vm_adjust_num_guest_pages(mode, pages);
> -
>  	vm = vm_create_without_vcpus(mode, pages);
>  
>  	for (i = 0; i < nr_vcpus; ++i) {
> -- 
> 2.36.1.255.ge46751e96f-goog
>
Sean Christopherson June 8, 2022, 7:49 p.m. UTC | #2
On Wed, Jun 08, 2022, Andrew Jones wrote:
> On Fri, Jun 03, 2022 at 12:41:45AM +0000, Sean Christopherson wrote:
> > Move the call to vm_adjust_num_guest_pages() from vm_create_with_vcpus()
> > down into vm_create_without_vcpus().  This will allow a future patch to
> > make the "w/o vCPUs" variant the common inner helper, e.g. so that the
> > "with_vcpus" helper calls the "without_vcpus" helper, instead of having
> > them be separate paths.
> > 
> > Signed-off-by: Sean Christopherson <seanjc@google.com>
> > ---
> >  tools/testing/selftests/kvm/lib/kvm_util.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> > index 1c5caf2ddca4..6b0b65c26d4d 100644
> > --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> > @@ -282,6 +282,8 @@ struct kvm_vm *vm_create_without_vcpus(enum vm_guest_mode mode, uint64_t pages)
> >  {
> >  	struct kvm_vm *vm;
> >  
> > +	pages = vm_adjust_num_guest_pages(VM_MODE_DEFAULT, pages);
> 
> Hi Sean,
> 
> We should pass 'mode' here.

Ouch.  Very nice catch!  Lucky for me, the resulting conflicts later in the series
are obvious and straightfoward.

Thanks much!
diff mbox series

Patch

diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 1c5caf2ddca4..6b0b65c26d4d 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -282,6 +282,8 @@  struct kvm_vm *vm_create_without_vcpus(enum vm_guest_mode mode, uint64_t pages)
 {
 	struct kvm_vm *vm;
 
+	pages = vm_adjust_num_guest_pages(VM_MODE_DEFAULT, pages);
+
 	vm = __vm_create(mode, pages);
 
 	kvm_vm_elf_load(vm, program_invocation_name);
@@ -341,8 +343,6 @@  struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus,
 		    "nr_vcpus = %d too large for host, max-vcpus = %d",
 		    nr_vcpus, kvm_check_cap(KVM_CAP_MAX_VCPUS));
 
-	pages = vm_adjust_num_guest_pages(mode, pages);
-
 	vm = vm_create_without_vcpus(mode, pages);
 
 	for (i = 0; i < nr_vcpus; ++i) {