Linux s390 Architecture development
 help / color / mirror / Atom feed
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 5/6] KVM: s390: selftests: Add ucontrol storage key and immediate exit tests
Date: Tue, 10 Nov 2026 06:16:18 -0500	[thread overview]
Message-ID: <20261110111619.61760-6-aaronmbr@linux.ibm.com> (raw)
In-Reply-To: <20261110111619.61760-1-aaronmbr@linux.ibm.com>

Add two more ucontrol tests:

- Storage key: the guest executes SSKE. Check for ICPT_KSS and the key
  in the guest register. Skip if CPUSTAT_KSS is not set, as the
  intercept is not generated then.
- Immediate exit: set immediate_exit and a marker register before
  KVM_RUN. Check for EINTR, exit_reason KVM_EXIT_UNKNOWN, and that the
  marker is unchanged.

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 | 107 ++++++++++++++++++++
 1 file changed, 107 insertions(+)

diff --git a/tools/testing/selftests/kvm/s390/kvm_exit.c b/tools/testing/selftests/kvm/s390/kvm_exit.c
index d0a3894daf0d..4b9b30cd4e2a 100644
--- a/tools/testing/selftests/kvm/s390/kvm_exit.c
+++ b/tools/testing/selftests/kvm/s390/kvm_exit.c
@@ -37,6 +37,10 @@ int capget(cap_user_header_t header, cap_user_data_t data);
 #define STSI_IPA 0xb27d
 #define TSCH_IPA 0xb235
 #define STSCH_IPA 0xb234
+#define EXPECTED_STORAGE_KEY 0x20
+#define IPA_SUBOPCODE_MASK_SKEY 0xff
+#define SSKE_SUBOPCODE 0x2b
+#define SSKE_OPCODE 0xb2
 #define PSW_WAIT_BIT_MASK (1ULL << (63 - 14))
 #define PGM_CODE_GPA_ADDRESS 0x8e
 #define PGM_CODE_MASK        0x7f
@@ -121,6 +125,15 @@ static struct kvm_parameters manual_kvm_creation_execution(struct kvm_parameters
 	param.run->s.regs.gprs[15] = CODE_GPA - 160;
 	param.run->kvm_dirty_regs |= KVM_SYNC_GPRS;
 
+	if (param.manual_parameters.immediate_exit_condition) {
+		param.run->immediate_exit = 1;
+		param.run->s.regs.gprs[3] = 0xdead;
+		param.run->kvm_dirty_regs |= KVM_SYNC_GPRS;
+		rc = ioctl(param.manual_parameters.vcpu_fd, KVM_RUN, NULL);
+		TEST_ASSERT(rc == -1 && errno == EINTR, "KVM_RUN failed (%d)", errno);
+		return param;
+	}
+
 	rc = ioctl(param.manual_parameters.vcpu_fd, KVM_RUN, NULL);
 	TEST_ASSERT(rc == 0, "KVM_RUN failed (%d)", errno);
 
@@ -585,6 +598,90 @@ static bool test_io_instruction_code(void)
 	return true;
 }
 
+static void guestcode_storage_key(void)
+{
+	asm volatile(
+		"lghi %%r3, 0\n"
+		"lghi %%r2, %[skey]\n"
+		"sske %%r2, %%r3\n"
+		:
+		: [skey] "i" (EXPECTED_STORAGE_KEY)
+		: "r3", "r2"
+	);
+}
+
+static bool test_storage_key_interrupt(void)
+{
+	struct kvm_parameters parameters = {
+		.guest_code = guestcode_storage_key,
+		.manual_parameters.immediate_exit_condition = false,
+	};
+
+	if (!ucontrol_available())
+		return false;
+
+	ksft_print_msg("Testing Storage Key Interrupt KVM Exit\n");
+	parameters = manual_kvm_creation_execution(parameters);
+
+	/* Skip on hosts where sclp.has_kss is false. */
+	if (!(parameters.manual_parameters.sie_block->cpuflags & CPUSTAT_KSS)) {
+		manual_cleanup(parameters);
+		return false;
+	}
+
+	TEST_ASSERT(parameters.run->exit_reason == KVM_EXIT_S390_SIEIC,
+		    "Expected KVM_EXIT_S390_SIEIC, got %u\n", parameters.run->exit_reason);
+	TEST_ASSERT(parameters.run->s390_sieic.icptcode == ICPT_KSS,
+		    "Failed with Unexpected Exit Reason of %u and icptcode of 0x%x\n",
+		    parameters.run->exit_reason, parameters.run->s390_sieic.icptcode);
+	TEST_ASSERT((parameters.run->s390_sieic.ipa & IPA_SUBOPCODE_MASK_SKEY) == SSKE_SUBOPCODE,
+		    "Expected SSKE Sub Opcode of 0x2B, Result of 0x%x\n",
+		    parameters.run->s390_sieic.ipa & IPA_SUBOPCODE_MASK_SKEY);
+	TEST_ASSERT((parameters.run->s390_sieic.ipa >> 8) == SSKE_OPCODE,
+		    "Expected SSKE Opcode of 0xb2, Actual of 0x%x\n",
+		    parameters.run->s390_sieic.ipa >> 8);
+	TEST_ASSERT(parameters.run->s.regs.gprs[2] == EXPECTED_STORAGE_KEY,
+		    "Storage Key not stored correctly, got 0x%llx\n",
+		    parameters.run->s.regs.gprs[2]);
+
+	manual_cleanup(parameters);
+	return true;
+}
+
+static void guestcode_immediate_exit(void)
+{
+	asm volatile(
+		"lghi %%r3, 0x3333\n"
+		:
+		:
+		: "r3"
+	);
+}
+
+static bool test_immediate_exit(void)
+{
+	struct kvm_parameters parameters = {
+		.guest_code = guestcode_immediate_exit,
+		.manual_parameters.immediate_exit_condition = true,
+	};
+
+	if (!ucontrol_available())
+		return false;
+
+	ksft_print_msg("Testing KVM Immediate Exit\n");
+	parameters = manual_kvm_creation_execution(parameters);
+
+	TEST_ASSERT(parameters.run->exit_reason == KVM_EXIT_UNKNOWN,
+		    "Expected KVM_EXIT_UNKNOWN (0), got %u\n",
+		    parameters.run->exit_reason);
+	TEST_ASSERT(parameters.run->s.regs.gprs[3] == 0xdead,
+		    "Guest code executed when it should not have: r3=0x%llx\n",
+			parameters.run->s.regs.gprs[3]);
+
+	manual_cleanup(parameters);
+	return true;
+}
+
 static void test(void)
 {
 	int i;
@@ -631,6 +728,16 @@ static void test(void)
 			.test = test_io_instruction_code,
 			.skip_reason = "KVM_CAP_S390_UCONTROL unavailable or insufficient privilege"
 		},
+		{
+			.name = "Testing Storage Key Interrupts",
+			.test = test_storage_key_interrupt,
+			.skip_reason = "KVM_CAP_S390_UCONTROL, privilege or KSS unavailable"
+		},
+		{
+			.name = "Testing Immediate Exit",
+			.test = test_immediate_exit,
+			.skip_reason = "KVM_CAP_S390_UCONTROL unavailable or insufficient privilege"
+		},
 	};
 
 	ksft_print_header();
-- 
2.50.1 (Apple Git-155)


  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 ` Aaron M. Brown [this message]
2026-11-10 11:25   ` [PATCH 5/6] KVM: s390: selftests: Add ucontrol storage key and immediate exit tests sashiko-bot
2026-11-10 11:16 ` [PATCH 6/6] KVM: s390: selftests: Add clock comparator interrupt test Aaron M. Brown
2026-11-10 11:23   ` 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-6-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox