mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-07-13 04:39:36 +02:00
KVM: selftests: Add test for uaccesses to non-existent vgic-v2 CPUIF
[ Upstream commit 160933e330
]
Assert that accesses to a non-existent vgic-v2 CPU interface
consistently fail across the various KVM device attr ioctls. This also
serves as a regression test for a bug wherein KVM hits a NULL
dereference when the CPUID specified in the ioctl is invalid.
Note that there is no need to print the observed errno, as TEST_ASSERT()
will take care of it.
Reviewed-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20240424173959.3776798-3-oliver.upton@linux.dev
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
02c36fe481
commit
59e9cd63a5
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
|
#include <linux/bitfield.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <asm/kvm.h>
|
#include <asm/kvm.h>
|
||||||
#include <asm/kvm_para.h>
|
#include <asm/kvm_para.h>
|
||||||
|
@ -84,6 +85,18 @@ static struct vm_gic vm_gic_create_with_vcpus(uint32_t gic_dev_type,
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct vm_gic vm_gic_create_barebones(uint32_t gic_dev_type)
|
||||||
|
{
|
||||||
|
struct vm_gic v;
|
||||||
|
|
||||||
|
v.gic_dev_type = gic_dev_type;
|
||||||
|
v.vm = vm_create_barebones();
|
||||||
|
v.gic_fd = kvm_create_device(v.vm, gic_dev_type);
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void vm_gic_destroy(struct vm_gic *v)
|
static void vm_gic_destroy(struct vm_gic *v)
|
||||||
{
|
{
|
||||||
close(v->gic_fd);
|
close(v->gic_fd);
|
||||||
|
@ -357,6 +370,40 @@ static void test_vcpus_then_vgic(uint32_t gic_dev_type)
|
||||||
vm_gic_destroy(&v);
|
vm_gic_destroy(&v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define KVM_VGIC_V2_ATTR(offset, cpu) \
|
||||||
|
(FIELD_PREP(KVM_DEV_ARM_VGIC_OFFSET_MASK, offset) | \
|
||||||
|
FIELD_PREP(KVM_DEV_ARM_VGIC_CPUID_MASK, cpu))
|
||||||
|
|
||||||
|
#define GIC_CPU_CTRL 0x00
|
||||||
|
|
||||||
|
static void test_v2_uaccess_cpuif_no_vcpus(void)
|
||||||
|
{
|
||||||
|
struct vm_gic v;
|
||||||
|
u64 val = 0;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
v = vm_gic_create_barebones(KVM_DEV_TYPE_ARM_VGIC_V2);
|
||||||
|
subtest_dist_rdist(&v);
|
||||||
|
|
||||||
|
ret = __kvm_has_device_attr(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CPU_REGS,
|
||||||
|
KVM_VGIC_V2_ATTR(GIC_CPU_CTRL, 0));
|
||||||
|
TEST_ASSERT(ret && errno == EINVAL,
|
||||||
|
"accessed non-existent CPU interface, want errno: %i",
|
||||||
|
EINVAL);
|
||||||
|
ret = __kvm_device_attr_get(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CPU_REGS,
|
||||||
|
KVM_VGIC_V2_ATTR(GIC_CPU_CTRL, 0), &val);
|
||||||
|
TEST_ASSERT(ret && errno == EINVAL,
|
||||||
|
"accessed non-existent CPU interface, want errno: %i",
|
||||||
|
EINVAL);
|
||||||
|
ret = __kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CPU_REGS,
|
||||||
|
KVM_VGIC_V2_ATTR(GIC_CPU_CTRL, 0), &val);
|
||||||
|
TEST_ASSERT(ret && errno == EINVAL,
|
||||||
|
"accessed non-existent CPU interface, want errno: %i",
|
||||||
|
EINVAL);
|
||||||
|
|
||||||
|
vm_gic_destroy(&v);
|
||||||
|
}
|
||||||
|
|
||||||
static void test_v3_new_redist_regions(void)
|
static void test_v3_new_redist_regions(void)
|
||||||
{
|
{
|
||||||
struct kvm_vcpu *vcpus[NR_VCPUS];
|
struct kvm_vcpu *vcpus[NR_VCPUS];
|
||||||
|
@ -675,6 +722,9 @@ void run_tests(uint32_t gic_dev_type)
|
||||||
test_vcpus_then_vgic(gic_dev_type);
|
test_vcpus_then_vgic(gic_dev_type);
|
||||||
test_vgic_then_vcpus(gic_dev_type);
|
test_vgic_then_vcpus(gic_dev_type);
|
||||||
|
|
||||||
|
if (VGIC_DEV_IS_V2(gic_dev_type))
|
||||||
|
test_v2_uaccess_cpuif_no_vcpus();
|
||||||
|
|
||||||
if (VGIC_DEV_IS_V3(gic_dev_type)) {
|
if (VGIC_DEV_IS_V3(gic_dev_type)) {
|
||||||
test_v3_new_redist_regions();
|
test_v3_new_redist_regions();
|
||||||
test_v3_typer_accesses();
|
test_v3_typer_accesses();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user