Skip to contentSkip to conversation

s390x: Add test for STFLE interpretive execution (format-2)

PATCH Superseded Christoph Schlameuss 3 participants 17 messages Mar 24 – Apr 21

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover s390x: Add test for STFLE interpretive execution (format-2)

Test the shadowing of format-2 facility list when running in VSIE.

The tests will skip the format 2 tests
* if running with unpatched kernels or qemu in G1 or G2
* if running on machines prior IBM z16 GA1 (where ASTFLEIE2 is not available)

Cc: Janosch Frank <[email protected]>
Cc: Claudio Imbrenda <[email protected]>
Cc: "Nico Böhr" <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Thomas Huth <[email protected]>
To: [email protected]
Cc: [email protected]

---
The original series was started by Nina and finished by me.

---
Changes in v2:
- Rework sclp_facilities_setup()
- Removed explicit manual padding from struct sclp_facilities
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Christoph Schlameuss (2):

      s390x: sclp: Remove unnecessary padding from struct sclp_facilities
      s390x: sclp: Rework sclp_facilities_setup() for simpler control flow

Nina Schoetterl-Glausch (3):

      s390x: snippets: Add reset_guest() to lib
      s390x: sclp: Add detection of alternate STFLE facilities
      s390x: Add test for STFLE interpretive execution (format-2)
 lib/s390x/sclp.c    | 30 +++++++++++-------
 lib/s390x/sclp.h    |  5 ++-
 lib/s390x/sie.c     | 11 +++++++
 lib/s390x/sie.h     |  1 +
 lib/s390x/snippet.h |  6 ++++
 s390x/spec_ex-sie.c | 10 ++----
 s390x/stfle-sie.c   | 91 ++++++++++++++++++++++++++++++++++++++++++++++-------
 7 files changed, 123 insertions(+), 31 deletions(-)

---
base-commit: 86e53277ac80dabb04f4fa5fa6a6cc7649392bdc
change-id: 20260202-vsie-stfle-fac-403e4467d8e2

Best regards,

Signature · 1 line
Christoph Schlameuss <[email protected]>
#1 lore raw

PATCH v2 1/5 s390x: snippets: Add reset_guest() to lib

From: Nina Schoetterl-Glausch <[email protected]>

Extract reset_guest from spec_ex-sie into the lib. After reset_guest() the snippet can be executed again.

---
 lib/s390x/snippet.h |  6 ++++++
 s390x/spec_ex-sie.c | 10 ++--------
 2 files changed, 8 insertions(+), 8 deletions(-)
lib/s390x/snippet.h +6 -0
index 910849aa186ce2f94c64ac1f40f8d6d7cdc36a1f..6f611de510d832f23384739606da13e71de3d6fd 100644
@@ -83,6 +83,12 @@ static inline void snippet_init(struct vm *vm, const char *gbin,
 	vm->sblk->ictl = ICTL_OPEREXC | ICTL_PINT;
 }
 
+static inline void reset_guest(struct vm *vm)
+{
+	vm->sblk->gpsw = snippet_psw;
+	vm->sblk->icptcode = 0;
+}
+
 /*
  * Sets up a snippet UV/PV guest on top of an existing and initialized
  * SIE vm struct.
s390x/spec_ex-sie.c +2 -8
index fe2f23ee3d84fa144416808cb4b353627fe87f3d..75625ecffc4a5a09ff7ef6136b7f1120a831a8c5 100644
@@ -31,12 +31,6 @@ static void setup_guest(void)
 		     SNIPPET_LEN(c, spec_ex), SNIPPET_UNPACK_OFF);
 }
 
-static void reset_guest(void)
-{
-	vm.sblk->gpsw = snippet_psw;
-	vm.sblk->icptcode = 0;
-}
-
 static void test_spec_ex_sie(void)
 {
 	const char *msg;
@@ -45,7 +39,7 @@ static void test_spec_ex_sie(void)
 
 	report_prefix_push("SIE spec ex interpretation");
 	report_prefix_push("off");
-	reset_guest();
+	reset_guest(&vm);
 	sie(&vm);
 	/* interpretation off -> initial exception must cause interception */
 	report(vm.sblk->icptcode == ICPT_PROGI
@@ -56,7 +50,7 @@ static void test_spec_ex_sie(void)
 
 	report_prefix_push("on");
 	vm.sblk->ecb |= ECB_SPECI;
-	reset_guest();
+	reset_guest(&vm);
 	sie(&vm);
 	/* interpretation on -> configuration dependent if initial exception causes
 	 * interception, but invalid new program PSW must
Signature · 1 line
2.53.0
Reviewed-by on v2 1/5
#2 lore raw

Re: [kvm-unit-tests PATCH v2 1/5] s390x: snippets: Add reset_guest() to lib

Quoted 8 lines · Christoph Schlameuss

From: Nina Schoetterl-Glausch <[email protected]>

Extract reset_guest from spec_ex-sie into the lib. After reset_guest() the snippet can be executed again.

#3 lore raw

PATCH v2 2/5 s390x: sclp: Remove unnecessary padding from struct sclp_facilities

In reply to Christoph Schlameuss

Struct sclp_facilities is only used within the guest to keep the facility information. Nothing bad should happen when the struct size changes in the future.

---
 lib/s390x/sclp.h | 1 -
 1 file changed, 1 deletion(-)
lib/s390x/sclp.h +0 -1
index 22f120d1b7ea7d1c3fe822385d0c689e5b3459fe..42a2f2e9f25a45d3ebd71729df0d9d6d93a4fb50 100644
@@ -132,7 +132,6 @@ struct sclp_facilities {
 	uint64_t has_kss : 1;
 	uint64_t has_pfmfi : 1;
 	uint64_t has_ibs : 1;
-	uint64_t : 64 - 15;
 };
 
 /* bit number within a certain byte */
Signature · 1 line
2.53.0
Reviewed-by on v2 2/5
#4 lore raw

Re: [kvm-unit-tests PATCH v2 2/5] s390x: sclp: Remove unnecessary padding from struct sclp_facilities

Quoted 6 lines · Christoph Schlameuss

Struct sclp_facilities is only used within the guest to keep the facility information. Nothing bad should happen when the struct size changes in the future.

Quoted 17 lines
---
  lib/s390x/sclp.h | 1 -
  1 file changed, 1 deletion(-)
lib/s390x/sclp.h +0 -1
index 22f120d1b7ea7d1c3fe822385d0c689e5b3459fe..42a2f2e9f25a45d3ebd71729df0d9d6d93a4fb50 100644
@@ -132,7 +132,6 @@ struct sclp_facilities {
  	uint64_t has_kss : 1;
  	uint64_t has_pfmfi : 1;
  	uint64_t has_ibs : 1;
-	uint64_t : 64 - 15;
  };
 
  /* bit number within a certain byte */
Reviewed-by on v2 2/5
#5 lore raw

Re: [kvm-unit-tests PATCH v2 2/5] s390x: sclp: Remove unnecessary padding from struct sclp_facilities

In reply to Christoph Schlameuss
Quoted 15 lines · Christoph Schlameuss

Struct sclp_facilities is only used within the guest to keep the facility information. Nothing bad should happen when the struct size changes in the future.

---
 lib/s390x/sclp.h | 1 -
 1 file changed, 1 deletion(-)
lib/s390x/sclp.h +0 -0
index 22f120d1b7ea7d1c3fe822385d0c689e5b3459fe..42a2f2e9f25a45d3ebd71729df0d9d6d93a4fb50 100644

lib/s390x/sclp.h struct sclp_facilities { · line 135

Quoted 5 lines
lib/s390x/sclp.h +0 -1
@@ -132,7 +132,6 @@ struct sclp_facilities {
 	uint64_t has_kss : 1;
 	uint64_t has_pfmfi : 1;
 	uint64_t has_ibs : 1;
-	uint64_t : 64 - 15;
 };

If I'm not mistaken this is already wrong if I did proper counting since there are 17 bits and we only subtract 15.

Since bit fields are guaranteed to be allocated left to right (see [1], p 14), this change makes sense.

[1] ELF Application Binary Interface s390x Supplement, Version 1.6

#6 lore raw

PATCH v2 3/5 s390x: sclp: Rework sclp_facilities_setup() for simpler control flow

In reply to Christoph Schlameuss

Reverse the order of operations to allow for early exits with increasing cpu offsets when reading facility bits in the extended range.

---
 lib/s390x/sclp.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
lib/s390x/sclp.c +14 -11
index 2f902e39e785ff4e139a39be2ffe11b5fa01edc0..d624872cba608fcbbd0c482a25f091fe19475a43 100644
@@ -154,17 +154,6 @@ void sclp_facilities_setup(void)
 	assert(read_info);
 
 	cpu = sclp_get_cpu_entries();
-	if (read_info->offset_cpu > 134)
-		sclp_facilities.has_diag318 = read_info->byte_134_diag318;
-	sclp_facilities.has_sop = sclp_feat_check(80, SCLP_FEAT_80_BIT_SOP);
-	sclp_facilities.has_gsls = sclp_feat_check(85, SCLP_FEAT_85_BIT_GSLS);
-	sclp_facilities.has_esop = sclp_feat_check(85, SCLP_FEAT_85_BIT_ESOP);
-	sclp_facilities.has_kss = sclp_feat_check(98, SCLP_FEAT_98_BIT_KSS);
-	sclp_facilities.has_cmma = sclp_feat_check(116, SCLP_FEAT_116_BIT_CMMA);
-	sclp_facilities.has_64bscao = sclp_feat_check(116, SCLP_FEAT_116_BIT_64BSCAO);
-	sclp_facilities.has_esca = sclp_feat_check(116, SCLP_FEAT_116_BIT_ESCA);
-	sclp_facilities.has_ibs = sclp_feat_check(117, SCLP_FEAT_117_BIT_IBS);
-	sclp_facilities.has_pfmfi = sclp_feat_check(117, SCLP_FEAT_117_BIT_PFMFI);
 
 	for (i = 0; i < read_info->entries_cpu; i++, cpu++) {
 		/*
@@ -184,6 +173,20 @@ void sclp_facilities_setup(void)
 			break;
 		}
 	}
+
+	sclp_facilities.has_sop = sclp_feat_check(80, SCLP_FEAT_80_BIT_SOP);
+	sclp_facilities.has_gsls = sclp_feat_check(85, SCLP_FEAT_85_BIT_GSLS);
+	sclp_facilities.has_esop = sclp_feat_check(85, SCLP_FEAT_85_BIT_ESOP);
+	sclp_facilities.has_kss = sclp_feat_check(98, SCLP_FEAT_98_BIT_KSS);
+	sclp_facilities.has_cmma = sclp_feat_check(116, SCLP_FEAT_116_BIT_CMMA);
+	sclp_facilities.has_64bscao = sclp_feat_check(116, SCLP_FEAT_116_BIT_64BSCAO);
+	sclp_facilities.has_esca = sclp_feat_check(116, SCLP_FEAT_116_BIT_ESCA);
+	sclp_facilities.has_ibs = sclp_feat_check(117, SCLP_FEAT_117_BIT_IBS);
+	sclp_facilities.has_pfmfi = sclp_feat_check(117, SCLP_FEAT_117_BIT_PFMFI);
+
+	if (read_info->offset_cpu <= 134)
+		return;
+	sclp_facilities.has_diag318 = read_info->byte_134_diag318;
 }
 
 /* Perform service call. Return 0 on success, non-zero otherwise. */
Signature · 1 line
2.53.0
Reviewed-by on v2 3/5
#7 lore raw

Re: [kvm-unit-tests PATCH v2 3/5] s390x: sclp: Rework sclp_facilities_setup() for simpler control flow

Quoted 2 lines · Christoph Schlameuss

Reverse the order of operations to allow for early exits with increasing cpu offsets when reading facility bits in the extended range.

Would be helpful to add a hint that this is needed for upcoming changes in this series.

Otherwise LGTM.

#8 lore raw

Re: [kvm-unit-tests PATCH v2 3/5] s390x: sclp: Rework sclp_facilities_setup() for simpler control flow

Quoted 10 lines · Nico Boehr
Quoted 2 lines · Christoph Schlameuss

Reverse the order of operations to allow for early exits with increasing cpu offsets when reading facility bits in the extended range.

Would be helpful to add a hint that this is needed for upcoming changes in this series.

Otherwise LGTM.

Sure, wil add a note to the comment about that.

#9 lore raw

PATCH v2 4/5 s390x: sclp: Add detection of alternate STFLE facilities

In reply to Christoph Schlameuss

From: Nina Schoetterl-Glausch <[email protected]>

Detect availability of alternate STFLE interpretive execution facilities 1 and 2.

---
 lib/s390x/sclp.c | 5 +++++
 lib/s390x/sclp.h | 4 ++++
 2 files changed, 9 insertions(+)
lib/s390x/sclp.c +5 -0
index d624872cba608fcbbd0c482a25f091fe19475a43..77b2a5ec00d68ec7ee82da295f2f31c539b5c00c 100644
@@ -181,12 +181,17 @@ void sclp_facilities_setup(void)
 	sclp_facilities.has_cmma = sclp_feat_check(116, SCLP_FEAT_116_BIT_CMMA);
 	sclp_facilities.has_64bscao = sclp_feat_check(116, SCLP_FEAT_116_BIT_64BSCAO);
 	sclp_facilities.has_esca = sclp_feat_check(116, SCLP_FEAT_116_BIT_ESCA);
+	sclp_facilities.has_astfleie1 = sclp_feat_check(116, SCLP_FEAT_116_BIT_ASTFLEIE1);
 	sclp_facilities.has_ibs = sclp_feat_check(117, SCLP_FEAT_117_BIT_IBS);
 	sclp_facilities.has_pfmfi = sclp_feat_check(117, SCLP_FEAT_117_BIT_PFMFI);
 
 	if (read_info->offset_cpu <= 134)
 		return;
 	sclp_facilities.has_diag318 = read_info->byte_134_diag318;
+
+	if (read_info->offset_cpu <= 139)
+		return;
+	sclp_facilities.has_astfleie2 = sclp_feat_check(139, SCLP_FEAT_139_BIT_ASTFLEIE2);
 }
 
 /* Perform service call. Return 0 on success, non-zero otherwise. */
lib/s390x/sclp.h +4 -0
index 42a2f2e9f25a45d3ebd71729df0d9d6d93a4fb50..5345e1ff8057c787f3aaea0245fc1e19096c75e9 100644
@@ -129,9 +129,11 @@ struct sclp_facilities {
 	uint64_t has_cmma : 1;
 	uint64_t has_64bscao : 1;
 	uint64_t has_esca : 1;
+	uint64_t has_astfleie1 : 1;
 	uint64_t has_kss : 1;
 	uint64_t has_pfmfi : 1;
 	uint64_t has_ibs : 1;
+	uint64_t has_astfleie2 : 1;
 };
 
 /* bit number within a certain byte */
@@ -142,8 +144,10 @@ struct sclp_facilities {
 #define SCLP_FEAT_116_BIT_64BSCAO	0
 #define SCLP_FEAT_116_BIT_CMMA		1
 #define SCLP_FEAT_116_BIT_ESCA		4
+#define SCLP_FEAT_116_BIT_ASTFLEIE1	7
 #define SCLP_FEAT_117_BIT_PFMFI		1
 #define SCLP_FEAT_117_BIT_IBS		2
+#define SCLP_FEAT_139_BIT_ASTFLEIE2	1
 
 typedef struct ReadInfo {
 	SCCBHeader h;
Signature · 1 line
2.53.0
#10 lore raw

Re: [kvm-unit-tests PATCH v2 4/5] s390x: sclp: Add detection of alternate STFLE facilities

On Tue Mar 24, 2026 at 4:28 PM CET, Christoph Schlameuss wrote:
[...]

Quoted 4 lines
lib/s390x/sclp.c +0 -0
index d624872cba608fcbbd0c482a25f091fe19475a43..77b2a5ec00d68ec7ee82da295f2f31c539b5c00c 100644

[...]

lib/s390x/sclp.c void sclp_facilities_setup(void) · line 194

Quoted 7 lines
lib/s390x/sclp.c +4 -0
 	if (read_info->offset_cpu <= 134)
 		return;
 	sclp_facilities.has_diag318 = read_info->byte_134_diag318;
+
+	if (read_info->offset_cpu <= 139)
+		return;
+	sclp_facilities.has_astfleie2 = sclp_feat_check(139, SCLP_FEAT_139_BIT_ASTFLEIE2);

Help me understand which case is the odd one, the diag318 one where we access read_info directly or this one where we use sclp_feat_check()?

Or is there a particular reason to do it this way that I didn't see?

#11 lore raw

Re: [kvm-unit-tests PATCH v2 4/5] s390x: sclp: Add detection of alternate STFLE facilities

Quoted 18 lines · Nico Boehr

On Tue Mar 24, 2026 at 4:28 PM CET, Christoph Schlameuss wrote:
[...]

Quoted 4 lines
lib/s390x/sclp.c +0 -0
index d624872cba608fcbbd0c482a25f091fe19475a43..77b2a5ec00d68ec7ee82da295f2f31c539b5c00c 100644

[...]

lib/s390x/sclp.c void sclp_facilities_setup(void) · line 194

Quoted 7 lines
lib/s390x/sclp.c +4 -0
 	if (read_info->offset_cpu <= 134)
 		return;
 	sclp_facilities.has_diag318 = read_info->byte_134_diag318;
+
+	if (read_info->offset_cpu <= 139)
+		return;
+	sclp_facilities.has_astfleie2 = sclp_feat_check(139, SCLP_FEAT_139_BIT_ASTFLEIE2);

Help me understand which case is the odd one, the diag318 one where we access read_info directly or this one where we use sclp_feat_check()?

Quoted 1 line

Or is there a particular reason to do it this way that I didn't see?

Both methods will read from the location read_info is pointing to. Which actually is pointing to _read_info, which is a 2 page buffer. The actual sclp info is read into _read_info dependent on facility 140 as either 1 or 2 pages.

So the data will then in either case be there in _read_info, either from the 2 page sclp read or as zeros behind the 1 page sclp read.
As for byte_134_diag318 in struct ReadInfo I dont think there is a golden way. Without fac140 byte_134_diag318 does not exist but is in the struct. And with fac140 and using sclp_feat_check we are reaching behind struct ReadInfo into _read_info.
Both not optimal.

In the end the difference is if we go the extra mile and define all the feature bits in struct ReadInfo or just use sclp_feat_check to check the bit directly. Simply because I think clp_facilities_setup looks cleaner that way and it is easier to add more feature bits.
I agree that we should use the same method for all high feature bits.

So I propose to add another patch here to use sclp_feat_check directly for diag318 as well. And also remove byte_134_diag318 from struct ReadInfo.

Cheers,

Christoph

#12 lore raw

Re: [kvm-unit-tests PATCH v2 4/5] s390x: sclp: Add detection of alternate STFLE facilities

Quoted 33 lines · Christoph Schlameuss
Quoted 18 lines · Nico Boehr

On Tue Mar 24, 2026 at 4:28 PM CET, Christoph Schlameuss wrote:
[...]

Quoted 4 lines
lib/s390x/sclp.c +0 -0
index d624872cba608fcbbd0c482a25f091fe19475a43..77b2a5ec00d68ec7ee82da295f2f31c539b5c00c 100644

[...]

lib/s390x/sclp.c void sclp_facilities_setup(void) · line 194

Quoted 7 lines
lib/s390x/sclp.c +4 -0
 	if (read_info->offset_cpu <= 134)
 		return;
 	sclp_facilities.has_diag318 = read_info->byte_134_diag318;
+
+	if (read_info->offset_cpu <= 139)
+		return;
+	sclp_facilities.has_astfleie2 = sclp_feat_check(139, SCLP_FEAT_139_BIT_ASTFLEIE2);

Help me understand which case is the odd one, the diag318 one where we access read_info directly or this one where we use sclp_feat_check()?

Quoted 1 line

Or is there a particular reason to do it this way that I didn't see?

Both methods will read from the location read_info is pointing to. Which actually is pointing to _read_info, which is a 2 page buffer. The actual sclp info is read into _read_info dependent on facility 140 as either 1 or 2 pages.

So the data will then in either case be there in _read_info, either from the 2 page sclp read or as zeros behind the 1 page sclp read.
As for byte_134_diag318 in struct ReadInfo I dont think there is a golden way. Without fac140 byte_134_diag318 does not exist but is in the struct. And with fac140 and using sclp_feat_check we are reaching behind struct ReadInfo into _read_info.
Both not optimal.

Quoted 8 lines

In the end the difference is if we go the extra mile and define all the feature bits in struct ReadInfo or just use sclp_feat_check to check the bit directly. Simply because I think clp_facilities_setup looks cleaner that way and it is easier to add more feature bits.
I agree that we should use the same method for all high feature bits.

So I propose to add another patch here to use sclp_feat_check directly for diag318 as well. And also remove byte_134_diag318 from struct ReadInfo.

Thank you, makes sense to me. Do you want to take this as part of this series or should I send a patch you can base your series on?

#13 lore raw

Re: [kvm-unit-tests PATCH v2 4/5] s390x: sclp: Add detection of alternate STFLE facilities

Quoted 40 lines · Nico Boehr
Quoted 39 lines · Christoph Schlameuss
Quoted 18 lines · Nico Boehr

On Tue Mar 24, 2026 at 4:28 PM CET, Christoph Schlameuss wrote:
[...]

Quoted 4 lines
lib/s390x/sclp.c +0 -0
index d624872cba608fcbbd0c482a25f091fe19475a43..77b2a5ec00d68ec7ee82da295f2f31c539b5c00c 100644

[...]

lib/s390x/sclp.c void sclp_facilities_setup(void) · line 194

Quoted 7 lines
lib/s390x/sclp.c +4 -0
 	if (read_info->offset_cpu <= 134)
 		return;
 	sclp_facilities.has_diag318 = read_info->byte_134_diag318;
+
+	if (read_info->offset_cpu <= 139)
+		return;
+	sclp_facilities.has_astfleie2 = sclp_feat_check(139, SCLP_FEAT_139_BIT_ASTFLEIE2);

Help me understand which case is the odd one, the diag318 one where we access read_info directly or this one where we use sclp_feat_check()?

Quoted 1 line

Or is there a particular reason to do it this way that I didn't see?

Both methods will read from the location read_info is pointing to. Which actually is pointing to _read_info, which is a 2 page buffer. The actual sclp info is read into _read_info dependent on facility 140 as either 1 or 2 pages.

So the data will then in either case be there in _read_info, either from the 2 page sclp read or as zeros behind the 1 page sclp read.
As for byte_134_diag318 in struct ReadInfo I dont think there is a golden way. Without fac140 byte_134_diag318 does not exist but is in the struct. And with fac140 and using sclp_feat_check we are reaching behind struct ReadInfo into _read_info.
Both not optimal.

In the end the difference is if we go the extra mile and define all the feature bits in struct ReadInfo or just use sclp_feat_check to check the bit directly. Simply because I think clp_facilities_setup looks cleaner that way and it is easier to add more feature bits.
I agree that we should use the same method for all high feature bits.

Quoted 5 lines
Quoted 2 lines

So I propose to add another patch here to use sclp_feat_check directly for diag318 as well. And also remove byte_134_diag318 from struct ReadInfo.

Thank you, makes sense to me. Do you want to take this as part of this series or should I send a patch you can base your series on?

I did include my proposal in the v3 I sent earlier today.

#14 lore raw

PATCH v2 5/5 s390x: Add test for STFLE interpretive execution (format-2)

In reply to Christoph Schlameuss

From: Nina Schoetterl-Glausch <[email protected]>

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.

---
 lib/s390x/sie.c   | 11 +++++++
 lib/s390x/sie.h   |  1 +
 s390x/stfle-sie.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 3 files changed, 92 insertions(+), 11 deletions(-)
lib/s390x/sie.c +11 -0
index 0fa915cf028a1b35a76aa316dfd97308094a4682..17f0ef7eff427002dd6d74d98f58ed493457a7ce 100644
@@ -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)
lib/s390x/sie.h +1 -0
index 3ec49ed0da6459a70689ce5a1a8a027a4113f2a4..8bea0b10b0a6894096ee83933a8bda11711a1949 100644
@@ -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)
s390x/stfle-sie.c +80 -11

124 lines not on this page · raw message

Signature · 1 line
2.53.0
#15 lore raw
Quoted 76 lines · Christoph Schlameuss

From: Nina Schoetterl-Glausch <[email protected]>

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.

---
  lib/s390x/sie.c   | 11 +++++++
  lib/s390x/sie.h   |  1 +
  s390x/stfle-sie.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++-------
  3 files changed, 92 insertions(+), 11 deletions(-)
lib/s390x/sie.c +11 -0
index 0fa915cf028a1b35a76aa316dfd97308094a4682..17f0ef7eff427002dd6d74d98f58ed493457a7ce 100644
@@ -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)
lib/s390x/sie.h +1 -0
index 3ec49ed0da6459a70689ce5a1a8a027a4113f2a4..8bea0b10b0a6894096ee83933a8bda11711a1949 100644
@@ -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)
s390x/stfle-sie.c +2 -3
index 21cf8ff8b6f6e9d61ee304c5748c36f718da65ab..5b642d9e8c3d775e078c1f09b87ad6822cd28a32 100644
@@ -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;

s390x/stfle-sie.c static struct guest_stfle_res run_guest(void) · line 67

Quoted 10 lines
s390x/stfle-sie.c +6 -4
-	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;

Without the KVM patches format_mask is 0.

s390x/stfle-sie.c static struct guest_stfle_res run_guest(void) · line 68

Quoted 1 line
s390x/stfle-sie.c +1 -0
+	for (int i = 0; i < 4; i++) {

Why?
This test is only for format 0, no?

s390x/stfle-sie.c static struct guest_stfle_res run_guest(void) · line 70

Quoted 2 lines
s390x/stfle-sie.c +2 -0
+		if (i & format_mask)
+			continue;

i & 0 is always false.

s390x/stfle-sie.c static struct guest_stfle_res run_guest(void) · line 74

Quoted 4 lines
s390x/stfle-sie.c +4 -0
+		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;

Since my mask is 0 and i can be 0 - 3 where values >0 can lead to validities (optional) this test can run into a validity at any point.

Quoted 40 lines
s390x/stfle-sie.c +37 -0
+		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();

s390x/stfle-sie.c static struct guest_stfle_res run_guest(void) · line 124

Quoted 10 lines
s390x/stfle-sie.c +10 -0
+}
+
+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);
+}

This needs a prefix, right now I see three of these skip reports and I don't know which format was tested:
PASS: optional VALIDITY: no

But looking at the code above I wonder if that should be folded into the test above if the logic is fixed.

Quoted 27 lines
s390x/stfle-sie.c +6 -4
+
  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();
+

s390x/stfle-sie.c static struct args parse_args(int argc, char **argv) · line 202

Quoted 10 lines
s390x/stfle-sie.c +10 -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();
+	}
+

Does this test work on LPAR and zVM?

Quoted 6 lines
s390x/stfle-sie.c +2 -0
+	test_no_stfle_format(3);
+
  out:
  	return report_summary();
  }
#16 lore raw
Quoted 25 lines · Janosch Frank
Quoted 24 lines · Christoph Schlameuss

From: Nina Schoetterl-Glausch <[email protected]>

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.

---
  lib/s390x/sie.c   | 11 +++++++
  lib/s390x/sie.h   |  1 +
  s390x/stfle-sie.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++-------
  3 files changed, 92 insertions(+), 11 deletions(-)
lib/s390x/sie.c +0 -0
index 0fa915cf028a1b35a76aa316dfd97308094a4682..17f0ef7eff427002dd6d74d98f58ed493457a7ce 100644

[...]

Quoted 49 lines
Quoted 10 lines
lib/s390x/sie.c +1 -3
@@ -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;

lib/s390x/sie.c static struct guest_stfle_res run_guest(void) · line 67

Quoted 10 lines
lib/s390x/sie.c +6 -4
-	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;

Without the KVM patches format_mask is 0.

lib/s390x/sie.c static struct guest_stfle_res run_guest(void) · line 68

Quoted 1 line
lib/s390x/sie.c +1 -0
+	for (int i = 0; i < 4; i++) {

Why?
This test is only for format 0, no?

lib/s390x/sie.c static struct guest_stfle_res run_guest(void) · line 70

Quoted 2 lines
lib/s390x/sie.c +2 -0
+		if (i & format_mask)
+			continue;

i & 0 is always false.

lib/s390x/sie.c static struct guest_stfle_res run_guest(void) · line 74

Quoted 4 lines
lib/s390x/sie.c +4 -0
+		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;

Since my mask is 0 and i can be 0 - 3 where values >0 can lead to validities (optional) this test can run into a validity at any point.

Quoted 8 lines
lib/s390x/sie.c +6 -0
+		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();
  }

[...]

Quoted 14 lines

lib/s390x/sie.c

Quoted 9 lines
lib/s390x/sie.c +9 -0
+
+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);
+}

This needs a prefix, right now I see three of these skip reports and I don't know which format was tested:
PASS: optional VALIDITY: no

Quoted 3 lines

But looking at the code above I wonder if that should be folded into the test above if the logic is fixed.

Yes, I added some prefixes and reverted the additional loop from test_stfle_format_0() for v3. That makes the log nice and readable now.

Quoted 31 lines
Quoted 31 lines
lib/s390x/sie.c +10 -4
+
  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) {
Quoted 9 lines

lib/s390x/sie.c static struct args parse_args(int argc, char **argv) · line 202

Quoted 6 lines
lib/s390x/sie.c +6 -0
+		test_no_stfle_format(2);
+		report_skip("alternate STFLE interpretive-execution facility 2 not available");
+	} else {
+		test_stfle_format_2();
+	}
+

Does this test work on LPAR and zVM?

Yes, it does. I did test explicitly on zVM now as well.

Quoted 6 lines
Quoted 6 lines
lib/s390x/sie.c +2 -0
+	test_no_stfle_format(3);
+
  out:
  	return report_summary();
  }