Skip to content

Commit 2dcd9aa

Browse files
Ricardo KollerMarc Zyngier
authored andcommitted
KVM: arm64: selftests: Add tests for GIC redist/cpuif partially above IPA range
Add tests for checking that KVM returns the right error when trying to set GICv2 CPU interfaces or GICv3 Redistributors partially above the addressable IPA range. Also tighten the IPA range by replacing KVM_CAP_ARM_VM_IPA_SIZE with the IPA range currently configured for the guest (i.e., the default). The check for the GICv3 redistributor created using the REDIST legacy API is not sufficient as this new test only checks the check done using vcpus already created when setting the base. The next commit will add the missing test which verifies that the KVM check is done at first vcpu run. Signed-off-by: Ricardo Koller <[email protected]> Reviewed-by: Eric Auger <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent c44df5f commit 2dcd9aa

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

tools/testing/selftests/kvm/aarch64/vgic_init.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct vm_gic {
3131
uint32_t gic_dev_type;
3232
};
3333

34-
static int max_ipa_bits;
34+
static uint64_t max_phys_size;
3535

3636
/* helper to access a redistributor register */
3737
static int access_v3_redist_reg(int gicv3_fd, int vcpu, int offset,
@@ -152,16 +152,21 @@ static void subtest_dist_rdist(struct vm_gic *v)
152152
TEST_ASSERT(ret && errno == EINVAL, "GIC redist/cpu base not aligned");
153153

154154
/* out of range address */
155-
if (max_ipa_bits) {
156-
addr = 1ULL << max_ipa_bits;
157-
ret = _kvm_device_access(v->gic_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
158-
dist.attr, &addr, true);
159-
TEST_ASSERT(ret && errno == E2BIG, "dist address beyond IPA limit");
155+
addr = max_phys_size;
156+
ret = _kvm_device_access(v->gic_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
157+
dist.attr, &addr, true);
158+
TEST_ASSERT(ret && errno == E2BIG, "dist address beyond IPA limit");
160159

161-
ret = _kvm_device_access(v->gic_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
162-
rdist.attr, &addr, true);
163-
TEST_ASSERT(ret && errno == E2BIG, "redist address beyond IPA limit");
164-
}
160+
ret = _kvm_device_access(v->gic_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
161+
rdist.attr, &addr, true);
162+
TEST_ASSERT(ret && errno == E2BIG, "redist address beyond IPA limit");
163+
164+
/* Space for half a rdist (a rdist is: 2 * rdist.alignment). */
165+
addr = max_phys_size - dist.alignment;
166+
ret = _kvm_device_access(v->gic_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
167+
rdist.attr, &addr, true);
168+
TEST_ASSERT(ret && errno == E2BIG,
169+
"half of the redist is beyond IPA limit");
165170

166171
/* set REDIST base address @0x0*/
167172
addr = 0x00000;
@@ -250,12 +255,19 @@ static void subtest_v3_redist_regions(struct vm_gic *v)
250255
kvm_device_access(v->gic_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
251256
KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION, &addr, true);
252257

253-
addr = REDIST_REGION_ATTR_ADDR(1, 1ULL << max_ipa_bits, 0, 2);
258+
addr = REDIST_REGION_ATTR_ADDR(1, max_phys_size, 0, 2);
254259
ret = _kvm_device_access(v->gic_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
255260
KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION, &addr, true);
256261
TEST_ASSERT(ret && errno == E2BIG,
257262
"register redist region with base address beyond IPA range");
258263

264+
/* The last redist is above the pa range. */
265+
addr = REDIST_REGION_ATTR_ADDR(2, max_phys_size - 0x30000, 0, 2);
266+
ret = _kvm_device_access(v->gic_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
267+
KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION, &addr, true);
268+
TEST_ASSERT(ret && errno == E2BIG,
269+
"register redist region with top address beyond IPA range");
270+
259271
addr = 0x260000;
260272
ret = _kvm_device_access(v->gic_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
261273
KVM_VGIC_V3_ADDR_TYPE_REDIST, &addr, true);
@@ -610,8 +622,10 @@ void run_tests(uint32_t gic_dev_type)
610622
int main(int ac, char **av)
611623
{
612624
int ret;
625+
int pa_bits;
613626

614-
max_ipa_bits = kvm_check_cap(KVM_CAP_ARM_VM_IPA_SIZE);
627+
pa_bits = vm_guest_mode_params[VM_MODE_DEFAULT].pa_bits;
628+
max_phys_size = 1ULL << pa_bits;
615629

616630
ret = test_kvm_device(KVM_DEV_TYPE_ARM_VGIC_V3);
617631
if (!ret) {

0 commit comments

Comments
 (0)