mirror of
https://github.com/torvalds/linux.git
synced 2026-05-31 02:24:24 +02:00
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 <rananta@google.com> Reviewed-by: Eric Auger <eric.auger@redhat.com> Reviewed-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20250724062805.2658919-6-oliver.upton@linux.dev Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
This commit is contained in:
parent
c652887a92
commit
15b5964a41
|
|
@ -13,13 +13,12 @@
|
|||
#include "kvm_util.h"
|
||||
#include "processor.h"
|
||||
#include "vgic.h"
|
||||
#include "gic_v3.h"
|
||||
|
||||
#define NR_VCPUS 4
|
||||
|
||||
#define REG_OFFSET(vcpu, offset) (((uint64_t)vcpu << 32) | offset)
|
||||
|
||||
#define GICR_TYPER 0x8
|
||||
|
||||
#define VGIC_DEV_IS_V2(_d) ((_d) == KVM_DEV_TYPE_ARM_VGIC_V2)
|
||||
#define VGIC_DEV_IS_V3(_d) ((_d) == KVM_DEV_TYPE_ARM_VGIC_V3)
|
||||
|
||||
|
|
@ -675,6 +674,44 @@ static void test_v3_its_region(void)
|
|||
vm_gic_destroy(&v);
|
||||
}
|
||||
|
||||
static void test_v3_nassgicap(void)
|
||||
{
|
||||
struct kvm_vcpu *vcpus[NR_VCPUS];
|
||||
bool has_nassgicap;
|
||||
struct vm_gic vm;
|
||||
u32 typer2;
|
||||
int ret;
|
||||
|
||||
vm = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, NR_VCPUS, vcpus);
|
||||
kvm_device_attr_get(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
|
||||
GICD_TYPER2, &typer2);
|
||||
has_nassgicap = typer2 & GICD_TYPER2_nASSGIcap;
|
||||
|
||||
typer2 |= GICD_TYPER2_nASSGIcap;
|
||||
ret = __kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
|
||||
GICD_TYPER2, &typer2);
|
||||
if (has_nassgicap)
|
||||
TEST_ASSERT(!ret, KVM_IOCTL_ERROR(KVM_DEVICE_ATTR_SET, ret));
|
||||
else
|
||||
TEST_ASSERT(ret && errno == EINVAL,
|
||||
"Enabled nASSGIcap even though it's unavailable");
|
||||
|
||||
typer2 &= ~GICD_TYPER2_nASSGIcap;
|
||||
kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
|
||||
GICD_TYPER2, &typer2);
|
||||
|
||||
kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
|
||||
KVM_DEV_ARM_VGIC_CTRL_INIT, NULL);
|
||||
|
||||
typer2 ^= GICD_TYPER2_nASSGIcap;
|
||||
ret = __kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
|
||||
GICD_TYPER2, &typer2);
|
||||
TEST_ASSERT(ret && errno == EBUSY,
|
||||
"Changed nASSGIcap after initializing the VGIC");
|
||||
|
||||
vm_gic_destroy(&vm);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns 0 if it's possible to create GIC device of a given type (V2 or V3).
|
||||
*/
|
||||
|
|
@ -730,6 +767,7 @@ void run_tests(uint32_t gic_dev_type)
|
|||
test_v3_last_bit_single_rdist();
|
||||
test_v3_redist_ipa_range_check_at_vcpu_run();
|
||||
test_v3_its_region();
|
||||
test_v3_nassgicap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user