All of lore.kernel.org
 help / color / mirror / Atom feed
From: Janosch Frank <frankja@linux.ibm.com>
To: kvm@vger.kernel.org
Cc: imbrenda@linux.ibm.com, linux-s390@vger.kernel.org,
	borntraeger@linux.ibm.com
Subject: [PATCH] KVM: s390: selftests: Add IRQ injection selftests
Date: Thu, 20 Aug 2026 12:20:35 +0000	[thread overview]
Message-ID: <20260820123728.26284-2-frankja@linux.ibm.com> (raw)

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


             reply	other threads:[~2026-08-20 12:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-20 12:20 Janosch Frank [this message]
2026-08-20 12:48 ` [PATCH] KVM: s390: selftests: Add IRQ injection selftests sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260820123728.26284-2-frankja@linux.ibm.com \
    --to=frankja@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.