public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Schlameuss <schlameuss@linux.ibm.com>
To: linux-s390@vger.kernel.org
Cc: "Janosch Frank" <frankja@linux.ibm.com>,
	"Claudio Imbrenda" <imbrenda@linux.ibm.com>,
	"Nico Böhr" <nrb@linux.ibm.com>,
	"David Hildenbrand" <david@kernel.org>,
	"Thomas Huth" <thuth@redhat.com>,
	kvm@vger.kernel.org,
	"Christoph Schlameuss" <schlameuss@linux.ibm.com>,
	"Nina Schoetterl-Glausch" <nsg@linux.ibm.com>
Subject: [kvm-unit-tests PATCH v2 5/5] s390x: Add test for STFLE interpretive execution (format-2)
Date: Tue, 24 Mar 2026 16:28:09 +0100	[thread overview]
Message-ID: <20260324-vsie-stfle-fac-v2-5-5e52be2e4081@linux.ibm.com> (raw)
In-Reply-To: <20260324-vsie-stfle-fac-v2-0-5e52be2e4081@linux.ibm.com>

From: Nina Schoetterl-Glausch <nsg@linux.ibm.com>

The STFLE instruction indicates installed facilities.
SIE has facilities for the interpretive execution of STFLE.
There are multiple possible formats for the control block.
Use a snippet guest executing STFLE to get the result of
interpretive execution and check the result.
With the addition of the format-2 control block invalid format
specifiers are now possible.
Test for the occurrence of optional validity intercepts.

Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Co-developed-by: Christoph Schlameuss <schlameuss@linux.ibm.com>
Signed-off-by: Christoph Schlameuss <schlameuss@linux.ibm.com>
---
 lib/s390x/sie.c   | 11 +++++++
 lib/s390x/sie.h   |  1 +
 s390x/stfle-sie.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 3 files changed, 92 insertions(+), 11 deletions(-)

diff --git a/lib/s390x/sie.c b/lib/s390x/sie.c
index 0fa915cf028a1b35a76aa316dfd97308094a4682..17f0ef7eff427002dd6d74d98f58ed493457a7ce 100644
--- a/lib/s390x/sie.c
+++ b/lib/s390x/sie.c
@@ -42,6 +42,17 @@ void sie_check_validity(struct vm *vm, uint16_t vir_exp)
 	report(vir_exp == vir, "VALIDITY: %x", vir);
 }
 
+void sie_check_optional_validity(struct vm *vm, uint16_t vir_exp)
+{
+	uint16_t vir = sie_get_validity(vm);
+
+	if (vir == 0xffff)
+		report_pass("optional VALIDITY: no");
+	else
+		report(vir_exp == vir, "optional VALIDITY: %x", vir);
+	vm->validity_expected = false;
+}
+
 void sie_handle_validity(struct vm *vm)
 {
 	if (vm->sblk->icptcode != ICPT_VALIDITY)
diff --git a/lib/s390x/sie.h b/lib/s390x/sie.h
index 3ec49ed0da6459a70689ce5a1a8a027a4113f2a4..8bea0b10b0a6894096ee83933a8bda11711a1949 100644
--- a/lib/s390x/sie.h
+++ b/lib/s390x/sie.h
@@ -51,6 +51,7 @@ void sie(struct vm *vm);
 void sie_expect_validity(struct vm *vm);
 uint16_t sie_get_validity(struct vm *vm);
 void sie_check_validity(struct vm *vm, uint16_t vir_exp);
+void sie_check_optional_validity(struct vm *vm, uint16_t vir_exp);
 void sie_handle_validity(struct vm *vm);
 
 static inline bool sie_is_pv(struct vm *vm)
diff --git a/s390x/stfle-sie.c b/s390x/stfle-sie.c
index 21cf8ff8b6f6e9d61ee304c5748c36f718da65ab..5b642d9e8c3d775e078c1f09b87ad6822cd28a32 100644
--- a/s390x/stfle-sie.c
+++ b/s390x/stfle-sie.c
@@ -42,6 +42,7 @@ static struct guest_stfle_res run_guest(void)
 	uint64_t guest_stfle_addr;
 	uint64_t reg;
 
+	reset_guest(&vm);
 	sie(&vm);
 	assert(snippet_is_force_exit_value(&vm));
 	guest_stfle_addr = snippet_get_force_exit_value(&vm);
@@ -55,18 +56,73 @@ static struct guest_stfle_res run_guest(void)
 static void test_stfle_format_0(void)
 {
 	struct guest_stfle_res res;
+	int format_mask;
 
 	report_prefix_push("format-0");
-	for (int j = 0; j < stfle_size(); j++)
-		WRITE_ONCE((*fac)[j], prng64(&prng_s));
-	vm.sblk->fac = (uint32_t)(uint64_t)fac;
-	res = run_guest();
-	report(res.len == stfle_size(), "stfle len correct");
-	report(!memcmp(*fac, res.mem, res.len * sizeof(uint64_t)),
-	       "Guest facility list as specified");
+	/*
+	 * There are multiple valid two bit format control values depending on
+	 * the available facilities.
+	 * The facility introduced last defines the validity of control bits.
+	 */
+	format_mask = sclp_facilities.has_astfleie2 ? 3 : sclp_facilities.has_astfleie1;
+	for (int i = 0; i < 4; i++) {
+		if (i & format_mask)
+			continue;
+		report_prefix_pushf("format control %d", i);
+		for (int j = 0; j < stfle_size(); j++)
+			WRITE_ONCE((*fac)[j], prng64(&prng_s));
+		vm.sblk->fac = (uint32_t)(uint64_t)fac | i;
+		res = run_guest();
+		report(res.len == stfle_size(), "stfle len correct");
+		report(!memcmp(*fac, res.mem, res.len * sizeof(uint64_t)),
+		       "Guest facility list as specified");
+		report_prefix_pop();
+	}
 	report_prefix_pop();
 }
 
+static void test_stfle_format_2(void)
+{
+	const int max_stfle_len = 8;
+	int guest_max_stfle_len = 0;
+	struct guest_stfle_res res;
+	bool saturated = false;
+
+	report_prefix_push("format-2");
+	for (int i = 1; i <= max_stfle_len; i++) {
+		report_prefix_pushf("max STFLE len %d", i);
+
+		WRITE_ONCE((*fac)[0], i - 1);
+		for (int j = 0; j < i; j++)
+			WRITE_ONCE((*fac)[j + 1], prng64(&prng_s));
+		vm.sblk->fac = (uint32_t)(uint64_t)fac | 2;
+		res = run_guest();
+		/* len increases up to maximum (machine specific) */
+		if (res.len < i)
+			saturated = true;
+		if (saturated) {
+			report(res.len == guest_max_stfle_len, "stfle len correct");
+		} else {
+			report(res.len == i, "stfle len correct");
+			guest_max_stfle_len = i;
+		}
+		report(!memcmp(&(*fac)[1], res.mem, guest_max_stfle_len * sizeof(uint64_t)),
+		       "Guest facility list as specified");
+
+		report_prefix_pop();
+	}
+	report_prefix_pop();
+}
+
+static void test_no_stfle_format(int format)
+{
+	reset_guest(&vm);
+	vm.sblk->fac = (uint32_t)(uint64_t)fac | format;
+	sie_expect_validity(&vm);
+	sie(&vm);
+	sie_check_optional_validity(&vm, 0x1330);
+}
+
 struct args {
 	uint64_t seed;
 };
@@ -119,20 +175,33 @@ static struct args parse_args(int argc, char **argv)
 int main(int argc, char **argv)
 {
 	struct args args = parse_args(argc, argv);
-	bool run_format_0 = test_facility(7);
 
 	if (!sclp_facilities.has_sief2) {
 		report_skip("SIEF2 facility unavailable");
 		goto out;
 	}
-	if (!run_format_0)
+	if (!test_facility(7)) {
 		report_skip("STFLE facility not available");
+		goto out;
+	}
 
 	report_info("PRNG seed: 0x%lx", args.seed);
 	prng_s = prng_init(args.seed);
 	setup_guest();
-	if (run_format_0)
-		test_stfle_format_0();
+	test_stfle_format_0();
+
+	if (!sclp_facilities.has_astfleie1)
+		test_no_stfle_format(1);
+
+	if (!sclp_facilities.has_astfleie2) {
+		test_no_stfle_format(2);
+		report_skip("alternate STFLE interpretive-execution facility 2 not available");
+	} else {
+		test_stfle_format_2();
+	}
+
+	test_no_stfle_format(3);
+
 out:
 	return report_summary();
 }

-- 
2.53.0


  parent reply	other threads:[~2026-03-24 15:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-24 15:28 [kvm-unit-tests PATCH v2 0/5] s390x: Add test for STFLE interpretive execution (format-2) Christoph Schlameuss
2026-03-24 15:28 ` [kvm-unit-tests PATCH v2 1/5] s390x: snippets: Add reset_guest() to lib Christoph Schlameuss
2026-04-15 11:00   ` Nico Boehr
2026-03-24 15:28 ` [kvm-unit-tests PATCH v2 2/5] s390x: sclp: Remove unnecessary padding from struct sclp_facilities Christoph Schlameuss
2026-03-25  9:20   ` Janosch Frank
2026-04-15 11:10   ` Nico Boehr
2026-03-24 15:28 ` [kvm-unit-tests PATCH v2 3/5] s390x: sclp: Rework sclp_facilities_setup() for simpler control flow Christoph Schlameuss
2026-04-15 11:27   ` Nico Boehr
2026-04-17 15:28     ` Christoph Schlameuss
2026-03-24 15:28 ` [kvm-unit-tests PATCH v2 4/5] s390x: sclp: Add detection of alternate STFLE facilities Christoph Schlameuss
2026-04-15 11:34   ` Nico Boehr
2026-04-17 15:28     ` Christoph Schlameuss
2026-03-24 15:28 ` Christoph Schlameuss [this message]
2026-03-25 10:18   ` [kvm-unit-tests PATCH v2 5/5] s390x: Add test for STFLE interpretive execution (format-2) Janosch Frank

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=20260324-vsie-stfle-fac-v2-5-5e52be2e4081@linux.ibm.com \
    --to=schlameuss@linux.ibm.com \
    --cc=david@kernel.org \
    --cc=frankja@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=nrb@linux.ibm.com \
    --cc=nsg@linux.ibm.com \
    --cc=thuth@redhat.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