On Wed, Jan 26, 2022 at 07:08:55PM -0800, Ricardo Koller wrote:
> The guest in vgic_irq gets its arguments in a struct. This struct used
> to fit nicely in a single register so vcpu_args_set() was able to pass
> it by value by setting x0 with it.

Ouch.

> Unfortunately, this args struct grew
> after some commits and some guest args became random (specically
> kvm_supports_irqfd).
> 
> Fix this by passing the guest args as a pointer (after allocating some
> guest memory for it).
> 
> Signed-off-by: Ricardo Koller <[email protected]>
> Reported-by: Reiji Watanabe <[email protected]>
> Cc: Andrew Jones <[email protected]>
> ---
>  .../testing/selftests/kvm/aarch64/vgic_irq.c  | 29 ++++++++++---------
>  1 file changed, 16 insertions(+), 13 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/aarch64/vgic_irq.c 
> b/tools/testing/selftests/kvm/aarch64/vgic_irq.c
> index e6c7d7f8fbd1..b701eb80128d 100644
> --- a/tools/testing/selftests/kvm/aarch64/vgic_irq.c
> +++ b/tools/testing/selftests/kvm/aarch64/vgic_irq.c
> @@ -472,10 +472,10 @@ static void test_restore_active(struct test_args *args, 
> struct kvm_inject_desc *
>               guest_restore_active(args, MIN_SPI, 4, f->cmd);
>  }
>  
> -static void guest_code(struct test_args args)
> +static void guest_code(struct test_args *args)
>  {
> -     uint32_t i, nr_irqs = args.nr_irqs;
> -     bool level_sensitive = args.level_sensitive;
> +     uint32_t i, nr_irqs = args->nr_irqs;
> +     bool level_sensitive = args->level_sensitive;
>       struct kvm_inject_desc *f, *inject_fns;
>  
>       gic_init(GIC_V3, 1, dist, redist);
> @@ -484,11 +484,11 @@ static void guest_code(struct test_args args)
>               gic_irq_enable(i);
>  
>       for (i = MIN_SPI; i < nr_irqs; i++)
> -             gic_irq_set_config(i, !args.level_sensitive);
> +             gic_irq_set_config(i, !level_sensitive);
>  
> -     gic_set_eoi_split(args.eoi_split);
> +     gic_set_eoi_split(args->eoi_split);
>  
> -     reset_priorities(&args);
> +     reset_priorities(args);
>       gic_set_priority_mask(CPU_PRIO_MASK);
>  
>       inject_fns  = level_sensitive ? inject_level_fns
> @@ -497,17 +497,17 @@ static void guest_code(struct test_args args)
>       local_irq_enable();
>  
>       /* Start the tests. */
> -     for_each_supported_inject_fn(&args, inject_fns, f) {
> -             test_injection(&args, f);
> -             test_preemption(&args, f);
> -             test_injection_failure(&args, f);
> +     for_each_supported_inject_fn(args, inject_fns, f) {
> +             test_injection(args, f);
> +             test_preemption(args, f);
> +             test_injection_failure(args, f);
>       }
>  
>       /* Restore the active state of IRQs. This would happen when live
>        * migrating IRQs in the middle of being handled.
>        */
> -     for_each_supported_activate_fn(&args, set_active_fns, f)
> -             test_restore_active(&args, f);
> +     for_each_supported_activate_fn(args, set_active_fns, f)
> +             test_restore_active(args, f);
>  
>       GUEST_DONE();
>  }
> @@ -739,6 +739,7 @@ static void test_vgic(uint32_t nr_irqs, bool 
> level_sensitive, bool eoi_split)
>       int gic_fd;
>       struct kvm_vm *vm;
>       struct kvm_inject_args inject_args;
> +     vm_vaddr_t args_gva;
>  
>       struct test_args args = {
>               .nr_irqs = nr_irqs,
> @@ -757,7 +758,9 @@ static void test_vgic(uint32_t nr_irqs, bool 
> level_sensitive, bool eoi_split)
>       vcpu_init_descriptor_tables(vm, VCPU_ID);
>  
>       /* Setup the guest args page (so it gets the args). */
> -     vcpu_args_set(vm, 0, 1, args);
> +     args_gva = vm_vaddr_alloc_page(vm);
> +     memcpy(addr_gva2hva(vm, args_gva), &args, sizeof(args));
> +     vcpu_args_set(vm, 0, 1, args_gva);
>  
>       gic_fd = vgic_v3_setup(vm, 1, nr_irqs,
>                       GICD_BASE_GPA, GICR_BASE_GPA);
> -- 
> 2.35.0.rc0.227.g00780c9af4-goog
>

Reviewed-by: Andrew Jones <[email protected]>

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

Reply via email to