Skip to contentSkip to conversation

s390x: SCLP Unit test

PATCH Superseded Claudio Imbrenda 2 participants 10 messages Jan 8, 2020 – Jan 9, 2020

Subsystems (2)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v5 cover s390x: SCLP Unit test

This patchset contains some minor cleanup, some preparatory work and then the SCLP unit test itself.

The unit test checks the following:

* Correctly ignoring instruction bits that should be ignored
* Privileged instruction check
* Check for addressing exceptions
* Specification exceptions:
- SCCB size less than 8
- SCCB unaligned
- SCCB overlaps prefix or lowcore
- SCCB address higher than 2GB
* Return codes for
- Invalid command
- SCCB too short (but at least 8)
- SCCB page boundary violation

v4 -> v5
* updated usage of report()
* added SPX and STPX wrappers to the library
* improved readability
* addressed some more comments
v3 -> v4
* export sclp_setup_int instead of copying it
* add more comments
* rename some more variables to improve readability
* improve the prefix test
* improved the invalid address test
* addressed further comments received during review
v2 -> v3
* generally improved the naming of variables
* added and fixed comments
* renamed test_one_run to test_one_simple
* added some const where needed
* addresed many more small comments received during review v1 -> v2
* fix many small issues that came up during the first round of reviews
* add comments to each function
* use a static buffer for the SCCP template when used

Claudio Imbrenda (4):
s390x: export sclp_setup_int
s390x: sclp: add service call instruction wrapper
s390x: lib: add SPX and STPX instruction wrapper
s390x: SCLP unit test

 s390x/Makefile           |   1 +
 lib/s390x/asm/arch_def.h |  26 +++
 lib/s390x/sclp.h         |   1 +
 lib/s390x/sclp.c         |   9 +-
 s390x/sclp.c             | 462 +++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg      |   8 +
 6 files changed, 500 insertions(+), 7 deletions(-)
 create mode 100644 s390x/sclp.c
Signature · 1 line
2.24.1
#1 lore raw

PATCH v5 1/4 s390x: export sclp_setup_int

Export sclp_setup_int() so that it can be used in tests.

Needed for an upcoming unit test.

---
 lib/s390x/sclp.h | 1 +
 lib/s390x/sclp.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
lib/s390x/sclp.h +1 -0
index 6d40fb7..675f07e 100644
@@ -265,6 +265,7 @@ typedef struct ReadEventData {
 } __attribute__((packed)) ReadEventData;
 
 extern char _sccb[];
+void sclp_setup_int(void);
 void sclp_handle_ext(void);
 void sclp_wait_busy(void);
 void sclp_mark_busy(void);
lib/s390x/sclp.c +1 -1
index 7798f04..123b639 100644
@@ -45,7 +45,7 @@ static void mem_init(phys_addr_t mem_end)
 	page_alloc_ops_enable();
 }
 
-static void sclp_setup_int(void)
+void sclp_setup_int(void)
 {
 	uint64_t mask;
 
Signature · 1 line
2.24.1
#2 lore raw

PATCH v5 2/4 s390x: sclp: add service call instruction wrapper

In reply to Claudio Imbrenda

Add a wrapper for the service call instruction, and use it for SCLP interactions instead of using inline assembly everywhere.

---
 lib/s390x/asm/arch_def.h | 13 +++++++++++++
 lib/s390x/sclp.c         |  7 +------
 2 files changed, 14 insertions(+), 6 deletions(-)
lib/s390x/asm/arch_def.h +13 -0
index cf6e1ca..1a5e3c6 100644
@@ -271,4 +271,17 @@ static inline int stsi(void *addr, int fc, int sel1, int sel2)
 	return cc;
 }
 
+static inline int servc(uint32_t command, unsigned long sccb)
+{
+	int cc;
+
+	asm volatile(
+		"       .insn   rre,0xb2200000,%1,%2\n"  /* servc %1,%2 */
+		"       ipm     %0\n"
+		"       srl     %0,28"
+		: "=&d" (cc) : "d" (command), "a" (sccb)
+		: "cc", "memory");
+	return cc;
+}
+
 #endif
lib/s390x/sclp.c +1 -6
index 123b639..4054d0e 100644
@@ -116,12 +116,7 @@ int sclp_service_call(unsigned int command, void *sccb)
 	int cc;
 
 	sclp_setup_int();
-	asm volatile(
-		"       .insn   rre,0xb2200000,%1,%2\n"  /* servc %1,%2 */
-		"       ipm     %0\n"
-		"       srl     %0,28"
-		: "=&d" (cc) : "d" (command), "a" (__pa(sccb))
-		: "cc", "memory");
+	cc = servc(command, __pa(sccb));
 	sclp_wait_busy();
 	if (cc == 3)
 		return -1;
Signature · 1 line
2.24.1
#3 lore raw

PATCH v5 3/4 s390x: lib: add SPX and STPX instruction wrapper

In reply to Claudio Imbrenda

Add a wrapper for the SET PREFIX and STORE PREFIX instructions, and use it instead of using inline assembly everywhere.

---
 lib/s390x/asm/arch_def.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
lib/s390x/asm/arch_def.h +13 -0
index 1a5e3c6..38c9dfa 100644
@@ -284,4 +284,17 @@ static inline int servc(uint32_t command, unsigned long sccb)
 	return cc;
 }
 
+static inline void spx(uint32_t new_prefix)
+{
+	asm volatile("spx %0" : : "Q" (new_prefix) : "memory");
+}
+
+static inline uint32_t stpx(void)
+{
+	uint32_t prefix;
+
+	asm volatile("stpx %0" : "=Q" (prefix));
+	return prefix;
+}
+
 #endif
Signature · 1 line
2.24.1
#4 lore raw

Re: [kvm-unit-tests PATCH v5 3/4] s390x: lib: add SPX and STPX instruction wrapper

Quoted 2 lines · Claudio Imbrenda

Add a wrapper for the SET PREFIX and STORE PREFIX instructions, and use it instead of using inline assembly everywhere.

Either some hunks are missing in this patch, or you should update the patch description and remove the second part of the sentence ? ... at least I did not spot the changes where you "use it instead of using inline assembly everywhere".

Thomas

Quoted 28 lines
---
 lib/s390x/asm/arch_def.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
lib/s390x/asm/arch_def.h +13 -0
index 1a5e3c6..38c9dfa 100644
@@ -284,4 +284,17 @@ static inline int servc(uint32_t command, unsigned long sccb)
 	return cc;
 }
 
+static inline void spx(uint32_t new_prefix)
+{
+	asm volatile("spx %0" : : "Q" (new_prefix) : "memory");
+}
+
+static inline uint32_t stpx(void)
+{
+	uint32_t prefix;
+
+	asm volatile("stpx %0" : "=Q" (prefix));
+	return prefix;
+}
+
 #endif
#5 lore raw

Re: [kvm-unit-tests PATCH v5 3/4] s390x: lib: add SPX and STPX instruction wrapper

Quoted 8 lines · On Wed, 8 Jan 2020 19:58:27 +0100 Thomas Huth <[email protected]> wrote:
Quoted 2 lines · Claudio Imbrenda

Add a wrapper for the SET PREFIX and STORE PREFIX instructions, and use it instead of using inline assembly everywhere.

Either some hunks are missing in this patch, or you should update the patch description and remove the second part of the sentence ? ... at least I did not spot the changes where you "use it instead of using inline assembly everywhere".

oops sorry, the description is a little misleading. I meant everywhere in the specific unit test, not everywhere in the whole source tree.

I should either change the description or actually patch the remaining users of inline assembly to use the wrappers instead. (any preference?)

#6 lore raw

Re: [kvm-unit-tests PATCH v5 3/4] s390x: lib: add SPX and STPX instruction wrapper

Quoted 13 lines · Claudio Imbrenda
Quoted 8 lines · On Wed, 8 Jan 2020 19:58:27 +0100 Thomas Huth <[email protected]> wrote:
Quoted 2 lines · Claudio Imbrenda

Add a wrapper for the SET PREFIX and STORE PREFIX instructions, and use it instead of using inline assembly everywhere.

Either some hunks are missing in this patch, or you should update the patch description and remove the second part of the sentence ? ... at least I did not spot the changes where you "use it instead of using inline assembly everywhere".

Quoted 6 lines

oops sorry, the description is a little misleading. I meant everywhere in the specific unit test, not everywhere in the whole source tree.

I should either change the description or actually patch the remaining users of inline assembly to use the wrappers instead. (any preference?)

No preferences from my side. If you don't want/have to respin, the patch description could be fixed when picking up the patch, otherwise simply do whatever you prefer in v6.

Thomas

#7 lore raw

PATCH v5 4/4 s390x: SCLP unit test

In reply to Claudio Imbrenda

SCLP unit test. Testing the following:

* Correctly ignoring instruction bits that should be ignored
* Privileged instruction check
* Check for addressing exceptions
* Specification exceptions:
- SCCB size less than 8
- SCCB unaligned
- SCCB overlaps prefix or lowcore
- SCCB address higher than 2GB
* Return codes for
- Invalid command
- SCCB too short (but at least 8)
- SCCB page boundary violation

---
 s390x/Makefile      |   1 +
 s390x/sclp.c        | 462 ++++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg |   8 +
 3 files changed, 471 insertions(+)
 create mode 100644 s390x/sclp.c
s390x/Makefile +1 -0
index 3744372..ddb4b48 100644
@@ -16,6 +16,7 @@ tests += $(TEST_DIR)/diag288.elf
 tests += $(TEST_DIR)/stsi.elf
 tests += $(TEST_DIR)/skrf.elf
 tests += $(TEST_DIR)/smp.elf
+tests += $(TEST_DIR)/sclp.elf
 tests_binary = $(patsubst %.elf,%.bin,$(tests))
 
 all: directories test_cases test_cases_binary
s390x/sclp.c new file +462 -0

462 lines not on this page · raw message

s390x/unittests.cfg +8 -0
index f1b07cd..07013b2 100644
@@ -75,3 +75,11 @@ file = stsi.elf
 [smp]
 file = smp.elf
 extra_params =-smp 2
+
+[sclp-1g]
+file = sclp.elf
+extra_params = -m 1G
+
+[sclp-3g]
+file = sclp.elf
+extra_params = -m 3G
Signature · 1 line
2.24.1
Reviewed-by on v5 4/4
#8 lore raw

Re: [kvm-unit-tests PATCH v5 4/4] s390x: SCLP unit test

Quoted 22 lines · Claudio Imbrenda

SCLP unit test. Testing the following:

* Correctly ignoring instruction bits that should be ignored
* Privileged instruction check
* Check for addressing exceptions
* Specification exceptions:
- SCCB size less than 8
- SCCB unaligned
- SCCB overlaps prefix or lowcore
- SCCB address higher than 2GB
* Return codes for
- Invalid command
- SCCB too short (but at least 8)
- SCCB page boundary violation

---
 s390x/Makefile      |   1 +
 s390x/sclp.c        | 462 ++++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg |   8 +
 3 files changed, 471 insertions(+)
 create mode 100644 s390x/sclp.c

[...]

Quoted 29 lines
s390x/sclp.c new file +29 -0
+/**
+ * Test SCCBs whose address is in the lowcore or prefix area.
+ */
+static void test_sccb_prefix(void)
+{
+	uint8_t scratch[2 * PAGE_SIZE];
+	uint32_t prefix, new_prefix;
+	int offset;
+
+	/*
+	 * copy the current lowcore to the future new location, otherwise we
+	 * will not have a valid lowcore after setting the new prefix.
+	 */
+	memcpy(prefix_buf, 0, 2 * PAGE_SIZE);
+	/* save the current prefix (it's probably going to be 0) */
+	prefix = stpx();
+	/*
+	 * save the current content of absolute pages 0 and 1, so we can
+	 * restore them after we trash them later on
+	 */
+	memcpy(scratch, (void *)(intptr_t)prefix, 2 * PAGE_SIZE);
+	/* set the new prefix to prefix_buf */
+	new_prefix = (uint32_t)(intptr_t)prefix_buf;
+	spx(new_prefix);
+
+	/*
+	 * testing with SCCB addresses in the lowcore; since we can't
+	 * actually trash the lowcore (unsurprisingly, things break if we
+	 * do), this will be a read-only test.

s390x/sclp.c line 180

Quoted 10 lines
s390x/sclp.c new file +10 -0
+	 */
+	for (offset = 0; offset < 2 * PAGE_SIZE; offset += 8)
+		if (!test_one_sccb(valid_code, MKPTR(offset), 0, PGM_BIT_SPEC, 0))
+			break;
+	report(offset == 2 * PAGE_SIZE, "SCCB low pages");
+
+	/*
+	 * this will trash the contents of the two pages at absolute
+	 * address 0; we will need to restore them later.
+	 */

I'm still a bit confused by this comment - will SCLP really trash the contents here, or will there be a specification exception (since PGM_BIT_SPEC is given below)? ... maybe you could clarify the comment in case you respin again (or it could be fixed when picking up the patch)?

s390x/sclp.c line 190

Quoted 10 lines
s390x/sclp.c new file +10 -0
+	for (offset = 0; offset < 2 * PAGE_SIZE; offset += 8)
+		if (!test_one_simple(valid_code, MKPTR(new_prefix + offset), 8, 8, PGM_BIT_SPEC, 0))
+			break;
+	report(offset == 2 * PAGE_SIZE, "SCCB prefix pages");
+
+	/* restore the previous contents of absolute pages 0 and 1 */
+	memcpy(prefix_buf, 0, 2 * PAGE_SIZE);
+	/* restore the prefix to the original value */
+	spx(prefix);
+}

Remaining parts look ok to me now, so with the comment clarified:

#9 lore raw

Re: [kvm-unit-tests PATCH v5 4/4] s390x: SCLP unit test

Quoted 66 lines · On Thu, 9 Jan 2020 13:42:34 +0100 Thomas Huth <[email protected]> wrote:
Quoted 22 lines · Claudio Imbrenda

SCLP unit test. Testing the following:

* Correctly ignoring instruction bits that should be ignored
* Privileged instruction check
* Check for addressing exceptions
* Specification exceptions:
- SCCB size less than 8
- SCCB unaligned
- SCCB overlaps prefix or lowcore
- SCCB address higher than 2GB
* Return codes for
- Invalid command
- SCCB too short (but at least 8)
- SCCB page boundary violation

---
 s390x/Makefile      |   1 +
 s390x/sclp.c        | 462
++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg |
 8 + 3 files changed, 471 insertions(+)
 create mode 100644 s390x/sclp.c  

[...]

Quoted 42 lines
s390x/sclp.c new file +11 -0
+/**
+ * Test SCCBs whose address is in the lowcore or prefix area.
+ */
+static void test_sccb_prefix(void)
+{
+	uint8_t scratch[2 * PAGE_SIZE];
+	uint32_t prefix, new_prefix;
+	int offset;
+
+	/*
+	 * copy the current lowcore to the future new location,

otherwise we

(quoted diff) +1 -0
+	 * will not have a valid lowcore after setting the new

prefix.

s390x/sclp.c new file +6 -0
+	 */
+	memcpy(prefix_buf, 0, 2 * PAGE_SIZE);
+	/* save the current prefix (it's probably going to be 0) */
+	prefix = stpx();
+	/*
+	 * save the current content of absolute pages 0 and 1, so

we can

s390x/sclp.c new file +9 -0
+	 * restore them after we trash them later on
+	 */
+	memcpy(scratch, (void *)(intptr_t)prefix, 2 * PAGE_SIZE);
+	/* set the new prefix to prefix_buf */
+	new_prefix = (uint32_t)(intptr_t)prefix_buf;
+	spx(new_prefix);
+
+	/*
+	 * testing with SCCB addresses in the lowcore; since we

can't

(quoted diff) +1 -0
+	 * actually trash the lowcore (unsurprisingly, things

break if we

s390x/sclp.c new file +4 -0
+	 * do), this will be a read-only test.
+	 */
+	for (offset = 0; offset < 2 * PAGE_SIZE; offset += 8)
+		if (!test_one_sccb(valid_code, MKPTR(offset), 0,

PGM_BIT_SPEC, 0))

s390x/sclp.c new file +4 -0
+			break;
+	report(offset == 2 * PAGE_SIZE, "SCCB low pages");
+
+	/*
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +1 -0
+	 * this will trash the contents of the two pages at

absolute

(quoted diff) +2 -0
+	 * address 0; we will need to restore them later.
+	 */  

I'm still a bit confused by this comment - will SCLP really trash the contents here, or will there be a specification exception (since PGM_BIT_SPEC is given below)? ... maybe you could clarify the comment

the SCLP will not touch the pages, because we will receive a specification exception, as you noticed.

on the other hand... WE will trash the area, because WE will write the SCCB at those addresses before calling the SCLP. test_one_simple() will create an SCCB and write it at the address indicated (in our case, starting at PREFIX, thus ending up starting from absolute address 0)

If you look closely, I used a different function for the lowcore, because we can't trash that without crashing everything. this means that the first half of test_sccb_prefix is not as thorough as it could be (we could be more clever and trash only those parts that are not vital for the system, but that's probably overkill for now)

I will add some more comments to explain what is happening, and a new test_one_ro() wrapper to make it more obvious when we are doing a "read-only" test

Quoted 2 lines

in case you respin again (or it could be fixed when picking up the patch)?

I'll need to respin anyway because I noticed a small but important mistake in the test_addressing function

Quoted 17 lines

s390x/sclp.c line 190

Quoted 12 lines
s390x/sclp.c new file +7 -0
+	for (offset = 0; offset < 2 * PAGE_SIZE; offset += 8)
+		if (!test_one_simple(valid_code, MKPTR(new_prefix
+ offset), 8, 8, PGM_BIT_SPEC, 0))
+			break;
+	report(offset == 2 * PAGE_SIZE, "SCCB prefix pages");
+
+	/* restore the previous contents of absolute pages 0 and 1

*/

s390x/sclp.c new file +4 -0
+	memcpy(prefix_buf, 0, 2 * PAGE_SIZE);
+	/* restore the prefix to the original value */
+	spx(prefix);
+}  

Remaining parts look ok to me now, so with the comment clarified: