Commit fd04edc3 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

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: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent afcda3dc
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#define GICD_BASE_GPA 0x08000000ULL #define GICD_BASE_GPA 0x08000000ULL
#define GICR_BASE_GPA 0x080A0000ULL #define GICR_BASE_GPA 0x080A0000ULL
#define VCPU_ID 0
/* /*
* Stores the user specified args; it's passed to the guest and to every test * Stores the user specified args; it's passed to the guest and to every test
...@@ -589,7 +588,8 @@ static void kvm_set_gsi_routing_irqchip_check(struct kvm_vm *vm, ...@@ -589,7 +588,8 @@ static void kvm_set_gsi_routing_irqchip_check(struct kvm_vm *vm,
} }
static void kvm_irq_write_ispendr_check(int gic_fd, uint32_t intid, static void kvm_irq_write_ispendr_check(int gic_fd, uint32_t intid,
uint32_t vcpu, bool expect_failure) struct kvm_vcpu *vcpu,
bool expect_failure)
{ {
/* /*
* Ignore this when expecting failure as invalid intids will lead to * Ignore this when expecting failure as invalid intids will lead to
...@@ -659,7 +659,7 @@ static void kvm_routing_and_irqfd_check(struct kvm_vm *vm, ...@@ -659,7 +659,7 @@ static void kvm_routing_and_irqfd_check(struct kvm_vm *vm,
(tmp) < (uint64_t)(first) + (uint64_t)(num); \ (tmp) < (uint64_t)(first) + (uint64_t)(num); \
(tmp)++, (i)++) (tmp)++, (i)++)
static void run_guest_cmd(struct kvm_vm *vm, int gic_fd, static void run_guest_cmd(struct kvm_vcpu *vcpu, int gic_fd,
struct kvm_inject_args *inject_args, struct kvm_inject_args *inject_args,
struct test_args *test_args) struct test_args *test_args)
{ {
...@@ -668,6 +668,7 @@ static void run_guest_cmd(struct kvm_vm *vm, int gic_fd, ...@@ -668,6 +668,7 @@ static void run_guest_cmd(struct kvm_vm *vm, int gic_fd,
uint32_t num = inject_args->num; uint32_t num = inject_args->num;
int level = inject_args->level; int level = inject_args->level;
bool expect_failure = inject_args->expect_failure; bool expect_failure = inject_args->expect_failure;
struct kvm_vm *vm = vcpu->vm;
uint64_t tmp; uint64_t tmp;
uint32_t i; uint32_t i;
...@@ -705,12 +706,12 @@ static void run_guest_cmd(struct kvm_vm *vm, int gic_fd, ...@@ -705,12 +706,12 @@ static void run_guest_cmd(struct kvm_vm *vm, int gic_fd,
break; break;
case KVM_WRITE_ISPENDR: case KVM_WRITE_ISPENDR:
for (i = intid; i < intid + num; i++) for (i = intid; i < intid + num; i++)
kvm_irq_write_ispendr_check(gic_fd, i, kvm_irq_write_ispendr_check(gic_fd, i, vcpu,
VCPU_ID, expect_failure); expect_failure);
break; break;
case KVM_WRITE_ISACTIVER: case KVM_WRITE_ISACTIVER:
for (i = intid; i < intid + num; i++) for (i = intid; i < intid + num; i++)
kvm_irq_write_isactiver(gic_fd, i, VCPU_ID); kvm_irq_write_isactiver(gic_fd, i, vcpu);
break; break;
default: default:
break; break;
...@@ -739,6 +740,7 @@ static void test_vgic(uint32_t nr_irqs, bool level_sensitive, bool eoi_split) ...@@ -739,6 +740,7 @@ static void test_vgic(uint32_t nr_irqs, bool level_sensitive, bool eoi_split)
{ {
struct ucall uc; struct ucall uc;
int gic_fd; int gic_fd;
struct kvm_vcpu *vcpu;
struct kvm_vm *vm; struct kvm_vm *vm;
struct kvm_inject_args inject_args; struct kvm_inject_args inject_args;
vm_vaddr_t args_gva; vm_vaddr_t args_gva;
...@@ -753,16 +755,16 @@ static void test_vgic(uint32_t nr_irqs, bool level_sensitive, bool eoi_split) ...@@ -753,16 +755,16 @@ static void test_vgic(uint32_t nr_irqs, bool level_sensitive, bool eoi_split)
print_args(&args); print_args(&args);
vm = vm_create_default(VCPU_ID, 0, guest_code); vm = vm_create_with_one_vcpu(&vcpu, guest_code);
ucall_init(vm, NULL); ucall_init(vm, NULL);
vm_init_descriptor_tables(vm); vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vm, VCPU_ID); vcpu_init_descriptor_tables(vm, vcpu->id);
/* Setup the guest args page (so it gets the args). */ /* Setup the guest args page (so it gets the args). */
args_gva = vm_vaddr_alloc_page(vm); args_gva = vm_vaddr_alloc_page(vm);
memcpy(addr_gva2hva(vm, args_gva), &args, sizeof(args)); memcpy(addr_gva2hva(vm, args_gva), &args, sizeof(args));
vcpu_args_set(vm, 0, 1, args_gva); vcpu_args_set(vm, vcpu->id, 1, args_gva);
gic_fd = vgic_v3_setup(vm, 1, nr_irqs, gic_fd = vgic_v3_setup(vm, 1, nr_irqs,
GICD_BASE_GPA, GICR_BASE_GPA); GICD_BASE_GPA, GICR_BASE_GPA);
...@@ -775,12 +777,12 @@ static void test_vgic(uint32_t nr_irqs, bool level_sensitive, bool eoi_split) ...@@ -775,12 +777,12 @@ static void test_vgic(uint32_t nr_irqs, bool level_sensitive, bool eoi_split)
guest_irq_handlers[args.eoi_split][args.level_sensitive]); guest_irq_handlers[args.eoi_split][args.level_sensitive]);
while (1) { while (1) {
vcpu_run(vm, VCPU_ID); vcpu_run(vm, vcpu->id);
switch (get_ucall(vm, VCPU_ID, &uc)) { switch (get_ucall(vm, vcpu->id, &uc)) {
case UCALL_SYNC: case UCALL_SYNC:
kvm_inject_get_call(vm, &uc, &inject_args); kvm_inject_get_call(vm, &uc, &inject_args);
run_guest_cmd(vm, gic_fd, &inject_args, &args); run_guest_cmd(vcpu, gic_fd, &inject_args, &args);
break; break;
case UCALL_ABORT: case UCALL_ABORT:
TEST_FAIL("%s at %s:%ld\n\tvalues: %#lx, %#lx", TEST_FAIL("%s at %s:%ld\n\tvalues: %#lx, %#lx",
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <linux/kvm.h> #include <linux/kvm.h>
#include "kvm_util.h"
#define REDIST_REGION_ATTR_ADDR(count, base, flags, index) \ #define REDIST_REGION_ATTR_ADDR(count, base, flags, index) \
(((uint64_t)(count) << 52) | \ (((uint64_t)(count) << 52) | \
((uint64_t)((base) >> 16) << 16) | \ ((uint64_t)((base) >> 16) << 16) | \
...@@ -26,8 +28,8 @@ void kvm_arm_irq_line(struct kvm_vm *vm, uint32_t intid, int level); ...@@ -26,8 +28,8 @@ void kvm_arm_irq_line(struct kvm_vm *vm, uint32_t intid, int level);
int _kvm_arm_irq_line(struct kvm_vm *vm, uint32_t intid, int level); int _kvm_arm_irq_line(struct kvm_vm *vm, uint32_t intid, int level);
/* The vcpu arg only applies to private interrupts. */ /* The vcpu arg only applies to private interrupts. */
void kvm_irq_write_ispendr(int gic_fd, uint32_t intid, uint32_t vcpu); void kvm_irq_write_ispendr(int gic_fd, uint32_t intid, struct kvm_vcpu *vcpu);
void kvm_irq_write_isactiver(int gic_fd, uint32_t intid, uint32_t vcpu); void kvm_irq_write_isactiver(int gic_fd, uint32_t intid, struct kvm_vcpu *vcpu);
#define KVM_IRQCHIP_NUM_PINS (1020 - 32) #define KVM_IRQCHIP_NUM_PINS (1020 - 32)
......
...@@ -127,8 +127,8 @@ void kvm_arm_irq_line(struct kvm_vm *vm, uint32_t intid, int level) ...@@ -127,8 +127,8 @@ void kvm_arm_irq_line(struct kvm_vm *vm, uint32_t intid, int level)
TEST_ASSERT(!ret, KVM_IOCTL_ERROR(KVM_IRQ_LINE, ret)); TEST_ASSERT(!ret, KVM_IOCTL_ERROR(KVM_IRQ_LINE, ret));
} }
static void vgic_poke_irq(int gic_fd, uint32_t intid, static void vgic_poke_irq(int gic_fd, uint32_t intid, struct kvm_vcpu *vcpu,
uint32_t vcpu, uint64_t reg_off) uint64_t reg_off)
{ {
uint64_t reg = intid / 32; uint64_t reg = intid / 32;
uint64_t index = intid % 32; uint64_t index = intid % 32;
...@@ -141,7 +141,7 @@ static void vgic_poke_irq(int gic_fd, uint32_t intid, ...@@ -141,7 +141,7 @@ static void vgic_poke_irq(int gic_fd, uint32_t intid,
if (intid_is_private) { if (intid_is_private) {
/* TODO: only vcpu 0 implemented for now. */ /* TODO: only vcpu 0 implemented for now. */
assert(vcpu == 0); assert(vcpu->id == 0);
attr += SZ_64K; attr += SZ_64K;
} }
...@@ -159,12 +159,12 @@ static void vgic_poke_irq(int gic_fd, uint32_t intid, ...@@ -159,12 +159,12 @@ static void vgic_poke_irq(int gic_fd, uint32_t intid,
kvm_device_attr_set(gic_fd, group, attr, &val); kvm_device_attr_set(gic_fd, group, attr, &val);
} }
void kvm_irq_write_ispendr(int gic_fd, uint32_t intid, uint32_t vcpu) void kvm_irq_write_ispendr(int gic_fd, uint32_t intid, struct kvm_vcpu *vcpu)
{ {
vgic_poke_irq(gic_fd, intid, vcpu, GICD_ISPENDR); vgic_poke_irq(gic_fd, intid, vcpu, GICD_ISPENDR);
} }
void kvm_irq_write_isactiver(int gic_fd, uint32_t intid, uint32_t vcpu) void kvm_irq_write_isactiver(int gic_fd, uint32_t intid, struct kvm_vcpu *vcpu)
{ {
vgic_poke_irq(gic_fd, intid, vcpu, GICD_ISACTIVER); vgic_poke_irq(gic_fd, intid, vcpu, GICD_ISACTIVER);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment