All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: s390: selftests: Add IRQ injection selftests
@ 2026-08-20 12:20 Janosch Frank
  2026-08-20 12:48 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Janosch Frank @ 2026-08-20 12:20 UTC (permalink / raw)
  To: kvm; +Cc: imbrenda, linux-s390, borntraeger

From: Gabriella Seifert <gseifert@linux.ibm.com>

The IRQ injection selftests haven't been added to the selftests yet so
let's do that now. We start off with a couple simple error checks for
invalid data.

Signed-off-by: Gabriella Seifert <gseifert@linux.ibm.com>
[frankja@linux.ibm.com: Improved formatting and wording]
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---

Written by Gabriela in her internship as a side project. Unfortunately
she wasn't able to send it out herself due to a bit of time crunch.
She did prepare additional code that's more in-depth with guest side
checks but didn't have the time to fully test and clean it up. We'll
see if and when that code will be posted.

I have her permission to fix up review comments and she's in bcc.

---
 tools/testing/selftests/kvm/Makefile.kvm      |  1 +
 .../selftests/kvm/s390/irq_injection.c        | 74 +++++++++++++++++++
 2 files changed, 75 insertions(+)
 create mode 100644 tools/testing/selftests/kvm/s390/irq_injection.c

diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
index 6fc34e9bf8e1..423c0cb6f17d 100644
--- a/tools/testing/selftests/kvm/Makefile.kvm
+++ b/tools/testing/selftests/kvm/Makefile.kvm
@@ -215,6 +215,7 @@ TEST_GEN_PROGS_s390 += rseq_test
 TEST_GEN_PROGS_s390 += s390/irq_routing
 TEST_GEN_PROGS_s390 += mmu_stress_test
 TEST_GEN_PROGS_s390 += pre_fault_memory_test
+TEST_GEN_PROGS_s390 += s390/irq_injection
 
 TEST_GEN_PROGS_riscv = $(TEST_GEN_PROGS_COMMON)
 TEST_GEN_PROGS_riscv += riscv/sbi_pmu_test
diff --git a/tools/testing/selftests/kvm/s390/irq_injection.c b/tools/testing/selftests/kvm/s390/irq_injection.c
new file mode 100644
index 000000000000..75e0528f9b01
--- /dev/null
+++ b/tools/testing/selftests/kvm/s390/irq_injection.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Test for KVM_S390_IRQ - s390x IRQ injection API
+ *
+ * Verifies that VM-level interrupt types are correctly rejected when
+ * injected via the vCPU file descriptor, and that invalid arguments
+ * to vCPU-level interrupts are also rejected.
+ *
+ * Copyright IBM Corp. 2026
+ * Author: Gabriella Seifert <gseifert@linux.ibm.com>
+ */
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include "kvm_util.h"
+#include "test_util.h"
+#include <linux/kvm.h>
+
+static void test_vm_irq_on_vcpu_fails(struct kvm_vcpu *vcpu, __u64 type)
+{
+	struct kvm_s390_irq irq = { .type = type };
+	int rc;
+
+	rc = __vcpu_ioctl(vcpu, KVM_S390_IRQ, &irq);
+	ksft_test_result(rc == -1 && errno == EINVAL,
+			 "VM on VCPU IRQ type 0x%llx: expected %d, got %d\n",
+			 type, EINVAL, errno);
+}
+
+static void test_vcpu_irq_bad_param_fails(struct kvm_vcpu *vcpu,
+					  struct kvm_s390_irq *irq)
+{
+	int rc;
+
+	rc = __vcpu_ioctl(vcpu, KVM_S390_IRQ, irq);
+	ksft_test_result(rc == -1 && errno == EINVAL,
+			 "VCPU IRQ bad param type 0x%llx: expected %d got %d\n",
+			 irq->type, EINVAL, errno);
+}
+
+int main(void)
+{
+	struct kvm_s390_irq irq;
+	struct kvm_vcpu *vcpu;
+	struct kvm_vm *vm;
+
+	ksft_print_header();
+	ksft_set_plan(6);
+	vm = vm_create_with_one_vcpu(&vcpu, NULL);
+
+	test_vm_irq_on_vcpu_fails(vcpu, KVM_S390_INT_VIRTIO);
+	test_vm_irq_on_vcpu_fails(vcpu, KVM_S390_INT_SERVICE);
+	test_vm_irq_on_vcpu_fails(vcpu, KVM_S390_INT_IO_MIN);
+
+	memset(&irq, 0, sizeof(irq));
+	irq.type = KVM_S390_INT_EMERGENCY;
+	irq.u.emerg.code = 0xffff;
+	test_vcpu_irq_bad_param_fails(vcpu, &irq);
+
+	memset(&irq, 0, sizeof(irq));
+	irq.type = KVM_S390_INT_EXTERNAL_CALL;
+	irq.u.extcall.code = 0xffff;
+	test_vcpu_irq_bad_param_fails(vcpu, &irq);
+
+	memset(&irq, 0, sizeof(irq));
+	irq.type = 0xdeadbeef;
+	test_vcpu_irq_bad_param_fails(vcpu, &irq);
+
+	kvm_vm_free(vm);
+	ksft_finished();
+}
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] KVM: s390: selftests: Add IRQ injection selftests
  2026-08-20 12:20 [PATCH] KVM: s390: selftests: Add IRQ injection selftests Janosch Frank
@ 2026-08-20 12:48 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-08-20 12:48 UTC (permalink / raw)
  To: Janosch Frank
  Cc: Christian Borntraeger, kvm, Vasily Gorbik, Alexander Gordeev,
	Heiko Carstens, linux-s390

> From: Gabriella Seifert <gseifert@linux.ibm.com>
> 
> The IRQ injection selftests haven't been added to the selftests yet so
> let's do that now. We start off with a couple simple error checks for
> invalid data.
> 
> Signed-off-by: Gabriella Seifert <gseifert@linux.ibm.com>
> [frankja@linux.ibm.com: Improved formatting and wording]
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260820123728.26284-2-frankja@linux.ibm.com?part=1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-20 12:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-20 12:20 [PATCH] KVM: s390: selftests: Add IRQ injection selftests Janosch Frank
2026-08-20 12:48 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.