Skip to content

Commit d9f9082

Browse files
committed
KVM: s390: selftests: Add ucontrol flic attr selftests
JIRA: https://issues.redhat.com/browse/RHEL-113440 commit b07f6a3 Author: Christoph Schlameuss <schlameuss@linux.ibm.com> Date: Mon Dec 16 10:21:36 2024 +0100 KVM: s390: selftests: Add ucontrol flic attr selftests Add some superficial selftests for the floating interrupt controller when using ucontrol VMs. These tests are intended to cover very basic calls only. Some of the calls may trigger null pointer dereferences on kernels not containing the fixes in this patch series. Signed-off-by: Christoph Schlameuss <schlameuss@linux.ibm.com> Tested-by: Hariharan Mari <hari55@linux.ibm.com> Reviewed-by: Hariharan Mari <hari55@linux.ibm.com> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Link: https://lore.kernel.org/r/20241216092140.329196-3-schlameuss@linux.ibm.com Message-ID: <20241216092140.329196-3-schlameuss@linux.ibm.com> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
1 parent 31741ed commit d9f9082

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed

tools/testing/selftests/kvm/s390/ucontrol_test.c

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,4 +627,152 @@ TEST_F(uc_kvm, uc_skey)
627627
uc_assert_diag44(self);
628628
}
629629

630+
static char uc_flic_b[PAGE_SIZE];
631+
static struct kvm_s390_io_adapter uc_flic_ioa = { .id = 0 };
632+
static struct kvm_s390_io_adapter_req uc_flic_ioam = { .id = 0 };
633+
static struct kvm_s390_ais_req uc_flic_asim = { .isc = 0 };
634+
static struct kvm_s390_ais_all uc_flic_asima = { .simm = 0 };
635+
static struct uc_flic_attr_test {
636+
char *name;
637+
struct kvm_device_attr a;
638+
int hasrc;
639+
int geterrno;
640+
int seterrno;
641+
} uc_flic_attr_tests[] = {
642+
{
643+
.name = "KVM_DEV_FLIC_GET_ALL_IRQS",
644+
.seterrno = EINVAL,
645+
.a = {
646+
.group = KVM_DEV_FLIC_GET_ALL_IRQS,
647+
.addr = (u64)&uc_flic_b,
648+
.attr = PAGE_SIZE,
649+
},
650+
},
651+
{
652+
.name = "KVM_DEV_FLIC_ENQUEUE",
653+
.geterrno = EINVAL,
654+
.a = { .group = KVM_DEV_FLIC_ENQUEUE, },
655+
},
656+
{
657+
.name = "KVM_DEV_FLIC_CLEAR_IRQS",
658+
.geterrno = EINVAL,
659+
.a = { .group = KVM_DEV_FLIC_CLEAR_IRQS, },
660+
},
661+
{
662+
.name = "KVM_DEV_FLIC_ADAPTER_REGISTER",
663+
.geterrno = EINVAL,
664+
.a = {
665+
.group = KVM_DEV_FLIC_ADAPTER_REGISTER,
666+
.addr = (u64)&uc_flic_ioa,
667+
},
668+
},
669+
{
670+
.name = "KVM_DEV_FLIC_ADAPTER_MODIFY",
671+
.geterrno = EINVAL,
672+
.seterrno = EINVAL,
673+
.a = {
674+
.group = KVM_DEV_FLIC_ADAPTER_MODIFY,
675+
.addr = (u64)&uc_flic_ioam,
676+
.attr = sizeof(uc_flic_ioam),
677+
},
678+
},
679+
{
680+
.name = "KVM_DEV_FLIC_CLEAR_IO_IRQ",
681+
.geterrno = EINVAL,
682+
.seterrno = EINVAL,
683+
.a = {
684+
.group = KVM_DEV_FLIC_CLEAR_IO_IRQ,
685+
.attr = 32,
686+
},
687+
},
688+
{
689+
.name = "KVM_DEV_FLIC_AISM",
690+
.geterrno = EINVAL,
691+
.seterrno = ENOTSUP,
692+
.a = {
693+
.group = KVM_DEV_FLIC_AISM,
694+
.addr = (u64)&uc_flic_asim,
695+
},
696+
},
697+
{
698+
.name = "KVM_DEV_FLIC_AIRQ_INJECT",
699+
.geterrno = EINVAL,
700+
.a = { .group = KVM_DEV_FLIC_AIRQ_INJECT, },
701+
},
702+
{
703+
.name = "KVM_DEV_FLIC_AISM_ALL",
704+
.geterrno = ENOTSUP,
705+
.seterrno = ENOTSUP,
706+
.a = {
707+
.group = KVM_DEV_FLIC_AISM_ALL,
708+
.addr = (u64)&uc_flic_asima,
709+
.attr = sizeof(uc_flic_asima),
710+
},
711+
},
712+
{
713+
.name = "KVM_DEV_FLIC_APF_ENABLE",
714+
.geterrno = EINVAL,
715+
.seterrno = EINVAL,
716+
.a = { .group = KVM_DEV_FLIC_APF_ENABLE, },
717+
},
718+
{
719+
.name = "KVM_DEV_FLIC_APF_DISABLE_WAIT",
720+
.geterrno = EINVAL,
721+
.seterrno = EINVAL,
722+
.a = { .group = KVM_DEV_FLIC_APF_DISABLE_WAIT, },
723+
},
724+
};
725+
726+
TEST_F(uc_kvm, uc_flic_attrs)
727+
{
728+
struct kvm_create_device cd = { .type = KVM_DEV_TYPE_FLIC };
729+
struct kvm_device_attr attr;
730+
u64 value;
731+
int rc, i;
732+
733+
rc = ioctl(self->vm_fd, KVM_CREATE_DEVICE, &cd);
734+
ASSERT_EQ(0, rc) TH_LOG("create device failed with err %s (%i)",
735+
strerror(errno), errno);
736+
737+
for (i = 0; i < ARRAY_SIZE(uc_flic_attr_tests); i++) {
738+
TH_LOG("test %s", uc_flic_attr_tests[i].name);
739+
attr = (struct kvm_device_attr) {
740+
.group = uc_flic_attr_tests[i].a.group,
741+
.attr = uc_flic_attr_tests[i].a.attr,
742+
.addr = uc_flic_attr_tests[i].a.addr,
743+
};
744+
if (attr.addr == 0)
745+
attr.addr = (u64)&value;
746+
747+
rc = ioctl(cd.fd, KVM_HAS_DEVICE_ATTR, &attr);
748+
EXPECT_EQ(uc_flic_attr_tests[i].hasrc, !!rc)
749+
TH_LOG("expected dev attr missing %s",
750+
uc_flic_attr_tests[i].name);
751+
752+
rc = ioctl(cd.fd, KVM_GET_DEVICE_ATTR, &attr);
753+
EXPECT_EQ(!!uc_flic_attr_tests[i].geterrno, !!rc)
754+
TH_LOG("get dev attr rc not expected on %s %s (%i)",
755+
uc_flic_attr_tests[i].name,
756+
strerror(errno), errno);
757+
if (uc_flic_attr_tests[i].geterrno)
758+
EXPECT_EQ(uc_flic_attr_tests[i].geterrno, errno)
759+
TH_LOG("get dev attr errno not expected on %s %s (%i)",
760+
uc_flic_attr_tests[i].name,
761+
strerror(errno), errno);
762+
763+
rc = ioctl(cd.fd, KVM_SET_DEVICE_ATTR, &attr);
764+
EXPECT_EQ(!!uc_flic_attr_tests[i].seterrno, !!rc)
765+
TH_LOG("set sev attr rc not expected on %s %s (%i)",
766+
uc_flic_attr_tests[i].name,
767+
strerror(errno), errno);
768+
if (uc_flic_attr_tests[i].seterrno)
769+
EXPECT_EQ(uc_flic_attr_tests[i].seterrno, errno)
770+
TH_LOG("set dev attr errno not expected on %s %s (%i)",
771+
uc_flic_attr_tests[i].name,
772+
strerror(errno), errno);
773+
}
774+
775+
close(cd.fd);
776+
}
777+
630778
TEST_HARNESS_MAIN

0 commit comments

Comments
 (0)