Skip to content

Commit 15b5964

Browse files
rananta468oupton
authored andcommitted
KVM: arm64: selftests: Add test for nASSGIcap attribute
Extend vgic_init to test the nASSGIcap attribute, asserting that it is configurable (within reason) prior to initializing the VGIC. Additionally, check that userspace cannot set the attribute after the VGIC has been initialized. Signed-off-by: Raghavendra Rao Ananta <[email protected]> Reviewed-by: Eric Auger <[email protected]> Reviewed-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent c652887 commit 15b5964

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
#include "kvm_util.h"
1414
#include "processor.h"
1515
#include "vgic.h"
16+
#include "gic_v3.h"
1617

1718
#define NR_VCPUS 4
1819

1920
#define REG_OFFSET(vcpu, offset) (((uint64_t)vcpu << 32) | offset)
2021

21-
#define GICR_TYPER 0x8
22-
2322
#define VGIC_DEV_IS_V2(_d) ((_d) == KVM_DEV_TYPE_ARM_VGIC_V2)
2423
#define VGIC_DEV_IS_V3(_d) ((_d) == KVM_DEV_TYPE_ARM_VGIC_V3)
2524

@@ -675,6 +674,44 @@ static void test_v3_its_region(void)
675674
vm_gic_destroy(&v);
676675
}
677676

677+
static void test_v3_nassgicap(void)
678+
{
679+
struct kvm_vcpu *vcpus[NR_VCPUS];
680+
bool has_nassgicap;
681+
struct vm_gic vm;
682+
u32 typer2;
683+
int ret;
684+
685+
vm = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, NR_VCPUS, vcpus);
686+
kvm_device_attr_get(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
687+
GICD_TYPER2, &typer2);
688+
has_nassgicap = typer2 & GICD_TYPER2_nASSGIcap;
689+
690+
typer2 |= GICD_TYPER2_nASSGIcap;
691+
ret = __kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
692+
GICD_TYPER2, &typer2);
693+
if (has_nassgicap)
694+
TEST_ASSERT(!ret, KVM_IOCTL_ERROR(KVM_DEVICE_ATTR_SET, ret));
695+
else
696+
TEST_ASSERT(ret && errno == EINVAL,
697+
"Enabled nASSGIcap even though it's unavailable");
698+
699+
typer2 &= ~GICD_TYPER2_nASSGIcap;
700+
kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
701+
GICD_TYPER2, &typer2);
702+
703+
kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
704+
KVM_DEV_ARM_VGIC_CTRL_INIT, NULL);
705+
706+
typer2 ^= GICD_TYPER2_nASSGIcap;
707+
ret = __kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
708+
GICD_TYPER2, &typer2);
709+
TEST_ASSERT(ret && errno == EBUSY,
710+
"Changed nASSGIcap after initializing the VGIC");
711+
712+
vm_gic_destroy(&vm);
713+
}
714+
678715
/*
679716
* Returns 0 if it's possible to create GIC device of a given type (V2 or V3).
680717
*/
@@ -730,6 +767,7 @@ void run_tests(uint32_t gic_dev_type)
730767
test_v3_last_bit_single_rdist();
731768
test_v3_redist_ipa_range_check_at_vcpu_run();
732769
test_v3_its_region();
770+
test_v3_nassgicap();
733771
}
734772
}
735773

0 commit comments

Comments
 (0)