diff mbox series

[02/13] fixup! KVM: selftests: Add support for vcpu_args_set to aarch64 and s390x

Message ID 20200214145920.30792-3-drjones@redhat.com (mailing list archive)
State New, archived
Headers show
Series KVM: selftests: Various fixes and cleanups | expand

Commit Message

Andrew Jones Feb. 14, 2020, 2:59 p.m. UTC
[Fixed array index (num => i) and made some style changes.]
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 .../selftests/kvm/lib/aarch64/processor.c     | 24 ++++---------------
 1 file changed, 4 insertions(+), 20 deletions(-)

Comments

Christian Borntraeger Feb. 14, 2020, 8:35 p.m. UTC | #1
On 14.02.20 15:59, Andrew Jones wrote:
> [Fixed array index (num => i) and made some style changes.]
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> ---
>  .../selftests/kvm/lib/aarch64/processor.c     | 24 ++++---------------

subject says s390, the patch not.
Andrew Jones Feb. 15, 2020, 7:04 a.m. UTC | #2
On Fri, Feb 14, 2020 at 09:35:06PM +0100, Christian Borntraeger wrote:
> 
> 
> On 14.02.20 15:59, Andrew Jones wrote:
> > [Fixed array index (num => i) and made some style changes.]
> > Signed-off-by: Andrew Jones <drjones@redhat.com>
> > ---
> >  .../selftests/kvm/lib/aarch64/processor.c     | 24 ++++---------------
> 
> subject says s390, the patch not.
>

It's a "fixup!" patch. The original subject has s390, so this one must as
well.

Thanks,
drew
Ben Gardon Feb. 18, 2020, 5:30 p.m. UTC | #3
On Fri, Feb 14, 2020 at 6:59 AM Andrew Jones <drjones@redhat.com> wrote:
>
> [Fixed array index (num => i) and made some style changes.]
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> ---
>  .../selftests/kvm/lib/aarch64/processor.c     | 24 ++++---------------
>  1 file changed, 4 insertions(+), 20 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c
> index 839a76c96f01..f7dffccea12c 100644
> --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c
> +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c
> @@ -334,36 +334,20 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
>         aarch64_vcpu_add_default(vm, vcpuid, NULL, guest_code);
>  }
>
> -/* VM VCPU Args Set
> - *
> - * Input Args:
> - *   vm - Virtual Machine
> - *   vcpuid - VCPU ID
> - *   num - number of arguments
> - *   ... - arguments, each of type uint64_t
> - *
> - * Output Args: None
> - *
> - * Return: None
> - *
> - * Sets the first num function input arguments to the values
> - * given as variable args.  Each of the variable args is expected to
> - * be of type uint64_t. The registers set by this function are r0-r7.
> - */
I'm sad to see this comment go. I realize it might be more verbose
than necessary, but calling out that the args will all be interpreted
as uint_64s and which registers are set feels like useful context to
have here.

>  void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...)
>  {
>         va_list ap;
>         int i;
>
>         TEST_ASSERT(num >= 1 && num <= 8, "Unsupported number of args,\n"
> -                   "  num: %u\n",
> -                   num);
> +                   "  num: %u\n", num);
>
>         va_start(ap, num);
>
> -       for (i = 0; i < num; i++)
> -               set_reg(vm, vcpuid, ARM64_CORE_REG(regs.regs[num]),
> +       for (i = 0; i < num; i++) {
> +               set_reg(vm, vcpuid, ARM64_CORE_REG(regs.regs[i]),
>                         va_arg(ap, uint64_t));
> +       }
Woops, I should have caught this in the original demand paging test
series, but didn't notice because this function was only ever called
with one argument.
Thank you for fixing this.

>
>         va_end(ap);
>  }
> --
> 2.21.1
>
Andrew Jones Feb. 18, 2020, 5:38 p.m. UTC | #4
On Tue, Feb 18, 2020 at 09:30:25AM -0800, Ben Gardon wrote:
> On Fri, Feb 14, 2020 at 6:59 AM Andrew Jones <drjones@redhat.com> wrote:
> >
> > [Fixed array index (num => i) and made some style changes.]
> > Signed-off-by: Andrew Jones <drjones@redhat.com>
> > ---
> >  .../selftests/kvm/lib/aarch64/processor.c     | 24 ++++---------------
> >  1 file changed, 4 insertions(+), 20 deletions(-)
> >
> > diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c
> > index 839a76c96f01..f7dffccea12c 100644
> > --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c
> > +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c
> > @@ -334,36 +334,20 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
> >         aarch64_vcpu_add_default(vm, vcpuid, NULL, guest_code);
> >  }
> >
> > -/* VM VCPU Args Set
> > - *
> > - * Input Args:
> > - *   vm - Virtual Machine
> > - *   vcpuid - VCPU ID
> > - *   num - number of arguments
> > - *   ... - arguments, each of type uint64_t
> > - *
> > - * Output Args: None
> > - *
> > - * Return: None
> > - *
> > - * Sets the first num function input arguments to the values
> > - * given as variable args.  Each of the variable args is expected to
> > - * be of type uint64_t. The registers set by this function are r0-r7.
> > - */
> I'm sad to see this comment go. I realize it might be more verbose
> than necessary, but calling out that the args will all be interpreted
> as uint_64s and which registers are set feels like useful context to
> have here.

For me the code makes that super obvious, and I prefer not to describe what
code does. Also, I'd put these type of comment blocks, written more
generally, in the header files if they're functions that are implemented
by all architectures, rather than duplicating them in each source file.

> 
> >  void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...)
> >  {
> >         va_list ap;
> >         int i;
> >
> >         TEST_ASSERT(num >= 1 && num <= 8, "Unsupported number of args,\n"
> > -                   "  num: %u\n",
> > -                   num);
> > +                   "  num: %u\n", num);
> >
> >         va_start(ap, num);
> >
> > -       for (i = 0; i < num; i++)
> > -               set_reg(vm, vcpuid, ARM64_CORE_REG(regs.regs[num]),
> > +       for (i = 0; i < num; i++) {
> > +               set_reg(vm, vcpuid, ARM64_CORE_REG(regs.regs[i]),
> >                         va_arg(ap, uint64_t));
> > +       }
> Woops, I should have caught this in the original demand paging test
> series, but didn't notice because this function was only ever called
> with one argument.
> Thank you for fixing this.
> 
> >
> >         va_end(ap);
> >  }
> > --
> > 2.21.1
> >
>

Thanks,
drew
Paolo Bonzini Feb. 20, 2020, 4:40 p.m. UTC | #5
On 18/02/20 18:38, Andrew Jones wrote:
> For me the code makes that super obvious, and I prefer not to describe what
> code does. Also, I'd put these type of comment blocks, written more
> generally, in the header files if they're functions that are implemented
> by all architectures, rather than duplicating them in each source file.

This makes sense.  For now I've restored the comment, but moving them to
the .h files is a good idea.

Paolo
diff mbox series

Patch

diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c
index 839a76c96f01..f7dffccea12c 100644
--- a/tools/testing/selftests/kvm/lib/aarch64/processor.c
+++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c
@@ -334,36 +334,20 @@  void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
 	aarch64_vcpu_add_default(vm, vcpuid, NULL, guest_code);
 }
 
-/* VM VCPU Args Set
- *
- * Input Args:
- *   vm - Virtual Machine
- *   vcpuid - VCPU ID
- *   num - number of arguments
- *   ... - arguments, each of type uint64_t
- *
- * Output Args: None
- *
- * Return: None
- *
- * Sets the first num function input arguments to the values
- * given as variable args.  Each of the variable args is expected to
- * be of type uint64_t. The registers set by this function are r0-r7.
- */
 void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...)
 {
 	va_list ap;
 	int i;
 
 	TEST_ASSERT(num >= 1 && num <= 8, "Unsupported number of args,\n"
-		    "  num: %u\n",
-		    num);
+		    "  num: %u\n", num);
 
 	va_start(ap, num);
 
-	for (i = 0; i < num; i++)
-		set_reg(vm, vcpuid, ARM64_CORE_REG(regs.regs[num]),
+	for (i = 0; i < num; i++) {
+		set_reg(vm, vcpuid, ARM64_CORE_REG(regs.regs[i]),
 			va_arg(ap, uint64_t));
+	}
 
 	va_end(ap);
 }