Skip to content

Commit b8daa7c

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: selftests: Add unsanitised helpers for VGICv3 creation
vgic_v3_setup() has a good bit of sanity checking internally to ensure that vCPUs have actually been created and match the dimensioning of the vgic itself. Spin off an unsanitised setup and initialization helper so vgic initialization can be wired in around a 'default' VM's vCPU creation. Signed-off-by: Oliver Upton <oliver.upton@linux.dev> Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent b712afa commit b8daa7c

2 files changed

Lines changed: 35 additions & 17 deletions

File tree

  • tools/testing/selftests/kvm

tools/testing/selftests/kvm/include/arm64/vgic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
index)
1818

1919
bool kvm_supports_vgic_v3(void);
20+
int __vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs);
21+
void __vgic_v3_init(int fd);
2022
int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs);
2123

2224
#define VGIC_MAX_RESERVED 1023

tools/testing/selftests/kvm/lib/arm64/vgic.c

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,11 @@ bool kvm_supports_vgic_v3(void)
4141
* redistributor regions of the guest. Since it depends on the number of
4242
* vCPUs for the VM, it must be called after all the vCPUs have been created.
4343
*/
44-
int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs)
44+
int __vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs)
4545
{
4646
int gic_fd;
4747
uint64_t attr;
48-
struct list_head *iter;
49-
unsigned int nr_gic_pages, nr_vcpus_created = 0;
50-
51-
TEST_ASSERT(nr_vcpus, "Number of vCPUs cannot be empty");
52-
53-
/*
54-
* Make sure that the caller is infact calling this
55-
* function after all the vCPUs are added.
56-
*/
57-
list_for_each(iter, &vm->vcpus)
58-
nr_vcpus_created++;
59-
TEST_ASSERT(nr_vcpus == nr_vcpus_created,
60-
"Number of vCPUs requested (%u) doesn't match with the ones created for the VM (%u)",
61-
nr_vcpus, nr_vcpus_created);
48+
unsigned int nr_gic_pages;
6249

6350
/* Distributor setup */
6451
gic_fd = __kvm_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3);
@@ -81,10 +68,39 @@ int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs)
8168
KVM_VGIC_V3_REDIST_SIZE * nr_vcpus);
8269
virt_map(vm, GICR_BASE_GPA, GICR_BASE_GPA, nr_gic_pages);
8370

84-
kvm_device_attr_set(gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
71+
return gic_fd;
72+
}
73+
74+
void __vgic_v3_init(int fd)
75+
{
76+
kvm_device_attr_set(fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
8577
KVM_DEV_ARM_VGIC_CTRL_INIT, NULL);
78+
}
8679

87-
return gic_fd;
80+
int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs)
81+
{
82+
unsigned int nr_vcpus_created = 0;
83+
struct list_head *iter;
84+
int fd;
85+
86+
TEST_ASSERT(nr_vcpus, "Number of vCPUs cannot be empty");
87+
88+
/*
89+
* Make sure that the caller is infact calling this
90+
* function after all the vCPUs are added.
91+
*/
92+
list_for_each(iter, &vm->vcpus)
93+
nr_vcpus_created++;
94+
TEST_ASSERT(nr_vcpus == nr_vcpus_created,
95+
"Number of vCPUs requested (%u) doesn't match with the ones created for the VM (%u)",
96+
nr_vcpus, nr_vcpus_created);
97+
98+
fd = __vgic_v3_setup(vm, nr_vcpus, nr_irqs);
99+
if (fd < 0)
100+
return fd;
101+
102+
__vgic_v3_init(fd);
103+
return fd;
88104
}
89105

90106
/* should only work for level sensitive interrupts */

0 commit comments

Comments
 (0)