Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: selftests: Convert vgic_irq away from VCPU_ID

Convert vgic_irq to use vm_create_with_one_vcpu() and pass around a
'struct kvm_vcpu' object instead of passing around a vCPU ID (which is
always the global VCPU_ID...).

Opportunstically align the indentation for multiple functions'
parameters.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Sean Christopherson and committed by
Paolo Bonzini
fd04edc3 afcda3dc

+25 -21
+16 -14
tools/testing/selftests/kvm/aarch64/vgic_irq.c
··· 22 22 23 23 #define GICD_BASE_GPA 0x08000000ULL 24 24 #define GICR_BASE_GPA 0x080A0000ULL 25 - #define VCPU_ID 0 26 25 27 26 /* 28 27 * Stores the user specified args; it's passed to the guest and to every test ··· 588 589 } 589 590 590 591 static void kvm_irq_write_ispendr_check(int gic_fd, uint32_t intid, 591 - uint32_t vcpu, bool expect_failure) 592 + struct kvm_vcpu *vcpu, 593 + bool expect_failure) 592 594 { 593 595 /* 594 596 * Ignore this when expecting failure as invalid intids will lead to ··· 659 659 (tmp) < (uint64_t)(first) + (uint64_t)(num); \ 660 660 (tmp)++, (i)++) 661 661 662 - static void run_guest_cmd(struct kvm_vm *vm, int gic_fd, 663 - struct kvm_inject_args *inject_args, 664 - struct test_args *test_args) 662 + static void run_guest_cmd(struct kvm_vcpu *vcpu, int gic_fd, 663 + struct kvm_inject_args *inject_args, 664 + struct test_args *test_args) 665 665 { 666 666 kvm_inject_cmd cmd = inject_args->cmd; 667 667 uint32_t intid = inject_args->first_intid; 668 668 uint32_t num = inject_args->num; 669 669 int level = inject_args->level; 670 670 bool expect_failure = inject_args->expect_failure; 671 + struct kvm_vm *vm = vcpu->vm; 671 672 uint64_t tmp; 672 673 uint32_t i; 673 674 ··· 706 705 break; 707 706 case KVM_WRITE_ISPENDR: 708 707 for (i = intid; i < intid + num; i++) 709 - kvm_irq_write_ispendr_check(gic_fd, i, 710 - VCPU_ID, expect_failure); 708 + kvm_irq_write_ispendr_check(gic_fd, i, vcpu, 709 + expect_failure); 711 710 break; 712 711 case KVM_WRITE_ISACTIVER: 713 712 for (i = intid; i < intid + num; i++) 714 - kvm_irq_write_isactiver(gic_fd, i, VCPU_ID); 713 + kvm_irq_write_isactiver(gic_fd, i, vcpu); 715 714 break; 716 715 default: 717 716 break; ··· 740 739 { 741 740 struct ucall uc; 742 741 int gic_fd; 742 + struct kvm_vcpu *vcpu; 743 743 struct kvm_vm *vm; 744 744 struct kvm_inject_args inject_args; 745 745 vm_vaddr_t args_gva; ··· 755 753 756 754 print_args(&args); 757 755 758 - vm = vm_create_default(VCPU_ID, 0, guest_code); 756 + vm = vm_create_with_one_vcpu(&vcpu, guest_code); 759 757 ucall_init(vm, NULL); 760 758 761 759 vm_init_descriptor_tables(vm); 762 - vcpu_init_descriptor_tables(vm, VCPU_ID); 760 + vcpu_init_descriptor_tables(vm, vcpu->id); 763 761 764 762 /* Setup the guest args page (so it gets the args). */ 765 763 args_gva = vm_vaddr_alloc_page(vm); 766 764 memcpy(addr_gva2hva(vm, args_gva), &args, sizeof(args)); 767 - vcpu_args_set(vm, 0, 1, args_gva); 765 + vcpu_args_set(vm, vcpu->id, 1, args_gva); 768 766 769 767 gic_fd = vgic_v3_setup(vm, 1, nr_irqs, 770 768 GICD_BASE_GPA, GICR_BASE_GPA); ··· 777 775 guest_irq_handlers[args.eoi_split][args.level_sensitive]); 778 776 779 777 while (1) { 780 - vcpu_run(vm, VCPU_ID); 778 + vcpu_run(vm, vcpu->id); 781 779 782 - switch (get_ucall(vm, VCPU_ID, &uc)) { 780 + switch (get_ucall(vm, vcpu->id, &uc)) { 783 781 case UCALL_SYNC: 784 782 kvm_inject_get_call(vm, &uc, &inject_args); 785 - run_guest_cmd(vm, gic_fd, &inject_args, &args); 783 + run_guest_cmd(vcpu, gic_fd, &inject_args, &args); 786 784 break; 787 785 case UCALL_ABORT: 788 786 TEST_FAIL("%s at %s:%ld\n\tvalues: %#lx, %#lx",
+4 -2
tools/testing/selftests/kvm/include/aarch64/vgic.h
··· 8 8 9 9 #include <linux/kvm.h> 10 10 11 + #include "kvm_util.h" 12 + 11 13 #define REDIST_REGION_ATTR_ADDR(count, base, flags, index) \ 12 14 (((uint64_t)(count) << 52) | \ 13 15 ((uint64_t)((base) >> 16) << 16) | \ ··· 28 26 int _kvm_arm_irq_line(struct kvm_vm *vm, uint32_t intid, int level); 29 27 30 28 /* The vcpu arg only applies to private interrupts. */ 31 - void kvm_irq_write_ispendr(int gic_fd, uint32_t intid, uint32_t vcpu); 32 - void kvm_irq_write_isactiver(int gic_fd, uint32_t intid, uint32_t vcpu); 29 + void kvm_irq_write_ispendr(int gic_fd, uint32_t intid, struct kvm_vcpu *vcpu); 30 + void kvm_irq_write_isactiver(int gic_fd, uint32_t intid, struct kvm_vcpu *vcpu); 33 31 34 32 #define KVM_IRQCHIP_NUM_PINS (1020 - 32) 35 33
+5 -5
tools/testing/selftests/kvm/lib/aarch64/vgic.c
··· 127 127 TEST_ASSERT(!ret, KVM_IOCTL_ERROR(KVM_IRQ_LINE, ret)); 128 128 } 129 129 130 - static void vgic_poke_irq(int gic_fd, uint32_t intid, 131 - uint32_t vcpu, uint64_t reg_off) 130 + static void vgic_poke_irq(int gic_fd, uint32_t intid, struct kvm_vcpu *vcpu, 131 + uint64_t reg_off) 132 132 { 133 133 uint64_t reg = intid / 32; 134 134 uint64_t index = intid % 32; ··· 141 141 142 142 if (intid_is_private) { 143 143 /* TODO: only vcpu 0 implemented for now. */ 144 - assert(vcpu == 0); 144 + assert(vcpu->id == 0); 145 145 attr += SZ_64K; 146 146 } 147 147 ··· 159 159 kvm_device_attr_set(gic_fd, group, attr, &val); 160 160 } 161 161 162 - void kvm_irq_write_ispendr(int gic_fd, uint32_t intid, uint32_t vcpu) 162 + void kvm_irq_write_ispendr(int gic_fd, uint32_t intid, struct kvm_vcpu *vcpu) 163 163 { 164 164 vgic_poke_irq(gic_fd, intid, vcpu, GICD_ISPENDR); 165 165 } 166 166 167 - void kvm_irq_write_isactiver(int gic_fd, uint32_t intid, uint32_t vcpu) 167 + void kvm_irq_write_isactiver(int gic_fd, uint32_t intid, struct kvm_vcpu *vcpu) 168 168 { 169 169 vgic_poke_irq(gic_fd, intid, vcpu, GICD_ISACTIVER); 170 170 }