From: "Aaron M. Brown" <aaronmbr@linux.ibm.com>
To: kvm@vger.kernel.org
Cc: Janosch Frank <frankja@linux.ibm.com>,
Claudio Imbrenda <imbrenda@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
linux-s390@vger.kernel.org, linux-kselftest@vger.kernel.org,
Nitya Khamar <nkhamar@linux.ibm.com>
Subject: [PATCH 6/6] KVM: s390: selftests: Add clock comparator interrupt test
Date: Tue, 10 Nov 2026 06:16:19 -0500 [thread overview]
Message-ID: <20261110111619.61760-7-aaronmbr@linux.ibm.com> (raw)
In-Reply-To: <20261110111619.61760-1-aaronmbr@linux.ibm.com>
Add a test that injects a clock comparator interrupt into a ucontrol
VM. The guest sets the clock comparator far in the future, sets the
subclass mask, and waits with the external mask set.
The first KVM_RUN exits with ICPT_WAIT. Inject KVM_S390_INT_CLOCK_COMP
and run again. Check for ICPT_EXTREQ.
Co-developed-by: Nitya Khamar <nkhamar@linux.ibm.com>
Signed-off-by: Nitya Khamar <nkhamar@linux.ibm.com>
Signed-off-by: Aaron M. Brown <aaronmbr@linux.ibm.com>
---
tools/testing/selftests/kvm/s390/kvm_exit.c | 74 +++++++++++++++++++++
1 file changed, 74 insertions(+)
diff --git a/tools/testing/selftests/kvm/s390/kvm_exit.c b/tools/testing/selftests/kvm/s390/kvm_exit.c
index 4b9b30cd4e2a..0d2fd4f39a9c 100644
--- a/tools/testing/selftests/kvm/s390/kvm_exit.c
+++ b/tools/testing/selftests/kvm/s390/kvm_exit.c
@@ -42,6 +42,8 @@ int capget(cap_user_header_t header, cap_user_data_t data);
#define SSKE_SUBOPCODE 0x2b
#define SSKE_OPCODE 0xb2
#define PSW_WAIT_BIT_MASK (1ULL << (63 - 14))
+#define PSW_CLOCK_WAIT 0x0102000180000000ULL
+#define CLK_COMPARATOR_MASK_BIT (1ULL << 11)
#define PGM_CODE_GPA_ADDRESS 0x8e
#define PGM_CODE_MASK 0x7f
#define PGM_NEW_PSW_GPA 0x1d0
@@ -682,6 +684,73 @@ static bool test_immediate_exit(void)
return true;
}
+static void guestcode_clock_comparator(void)
+{
+ asm volatile(
+ /* Set SCKC to the maximum value so it cannot expire on its own */
+ "lghi %%r7, -1\n"
+ "stg %%r7, 0(%%r15)\n"
+ "sckc 0(%%r15)\n"
+ /* Enable clock comparator interrupt in CR0 (bit 52) */
+ "stctg %%c0, %%c0, 0(%%r15)\n"
+ "oi 6(%%r15), 0x8\n"
+ "lctlg %%c0, %%c0, 0(%%r15)\n"
+ /* Load enabled wait PSW: 64-bit, DAT off, wait bit, external interrupt enabled */
+ "larl %%r8, 1f\n"
+ "lpswe 0(%%r8)\n"
+ ".align 8\n"
+ "1: .quad %[wait_psw], 0\n"
+ :
+ : [wait_psw] "i" (PSW_CLOCK_WAIT)
+ : "r7", "r8", "memory"
+ );
+ GUEST_DONE();
+}
+
+static bool test_clock_comparator_interrupt(void)
+{
+ struct kvm_parameters param = {
+ .guest_code = guestcode_clock_comparator,
+ .manual_parameters.immediate_exit_condition = false,
+ };
+ struct kvm_s390_irq irq = {};
+ int rc;
+
+ if (!ucontrol_available())
+ return false;
+
+ ksft_print_msg("Testing Clock Comparator Interrupt Exit\n");
+ param = manual_kvm_creation_execution(param);
+
+ /* On a ucontrol VM, the guest's enabled wait exits to userspace as ICPT_WAIT. */
+ TEST_ASSERT(param.run->exit_reason == KVM_EXIT_S390_SIEIC,
+ "Expected SIEIC, got %u\n", param.run->exit_reason);
+ TEST_ASSERT(param.run->s390_sieic.icptcode == ICPT_WAIT,
+ "Expected ICPT_WAIT (0x1c), got 0x%x\n",
+ param.run->s390_sieic.icptcode);
+ TEST_ASSERT((param.run->s.regs.crs[0] & CLK_COMPARATOR_MASK_BIT) != 0,
+ "CR0 clock comparator bit not set, cr0=0x%llx\n",
+ param.run->s.regs.crs[0]);
+
+ /* Inject clock comparator interrupt as a ucontrol VMM would */
+ irq.type = KVM_S390_INT_CLOCK_COMP;
+ rc = ioctl(param.manual_parameters.vcpu_fd, KVM_S390_IRQ, &irq);
+ TEST_ASSERT(rc == 0, "KVM_S390_IRQ (clock comp) failed (%d)", errno);
+
+ /* With the interrupt pending and external interrupts enabled, expect ICPT_EXTREQ. */
+ rc = ioctl(param.manual_parameters.vcpu_fd, KVM_RUN, NULL);
+ TEST_ASSERT(rc == 0, "KVM_RUN (2) failed (%d)", errno);
+ TEST_ASSERT(param.run->exit_reason == KVM_EXIT_S390_SIEIC,
+ "Expected SIEIC on second run, got %u\n",
+ param.run->exit_reason);
+ TEST_ASSERT(param.run->s390_sieic.icptcode == ICPT_EXTREQ,
+ "Expected ICPT_EXTREQ (0x10), got 0x%x\n",
+ param.run->s390_sieic.icptcode);
+
+ manual_cleanup(param);
+ return true;
+}
+
static void test(void)
{
int i;
@@ -738,6 +807,11 @@ static void test(void)
.test = test_immediate_exit,
.skip_reason = "KVM_CAP_S390_UCONTROL unavailable or insufficient privilege"
},
+ {
+ .name = "Testing Clock Comparator External Interrupts",
+ .test = test_clock_comparator_interrupt,
+ .skip_reason = "KVM_CAP_S390_UCONTROL unavailable or insufficient privilege"
+ },
};
ksft_print_header();
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2026-11-10 11:16 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 11:16 [PATCH 0/6] KVM: s390: selftests: Add selftests for KVM exits on s390x Aaron M. Brown
2026-11-10 11:16 ` [PATCH 1/6] KVM: s390: selftests: Add kvm_exit test for instruction intercepts Aaron M. Brown
2026-11-10 11:30 ` sashiko-bot
2026-11-12 13:45 ` Janosch Frank
2026-11-10 11:16 ` [PATCH 2/6] KVM: s390: selftests: Add SIGP and program exception tests Aaron M. Brown
2026-11-10 11:24 ` sashiko-bot
2026-11-10 11:16 ` [PATCH 3/6] KVM: s390: selftests: Add wait state and VM lifecycle tests Aaron M. Brown
2026-11-10 11:21 ` sashiko-bot
2026-11-10 11:16 ` [PATCH 4/6] KVM: s390: selftests: Add ucontrol helpers and instruction tests Aaron M. Brown
2026-11-10 11:24 ` sashiko-bot
2026-11-10 11:16 ` [PATCH 5/6] KVM: s390: selftests: Add ucontrol storage key and immediate exit tests Aaron M. Brown
2026-11-10 11:25 ` sashiko-bot
2026-11-10 11:16 ` Aaron M. Brown [this message]
2026-11-10 11:23 ` [PATCH 6/6] KVM: s390: selftests: Add clock comparator interrupt test 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=20261110111619.61760-7-aaronmbr@linux.ibm.com \
--to=aaronmbr@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=frankja@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=nkhamar@linux.ibm.com \
/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.