Skip to contentSkip to conversation

s390x: SCLP Unit test

PATCH Superseded Claudio Imbrenda 2 participants 7 messages Nov 11, 2019 – Nov 13, 2019

Subsystems (2)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v3 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

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 (2):
s390x: sclp: add service call instruction wrapper
s390x: SCLP unit test

 s390x/Makefile           |   1 +
 lib/s390x/asm/arch_def.h |  13 ++
 lib/s390x/sclp.c         |   7 +-
 s390x/sclp.c             | 417 +++++++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg      |   3 +
 5 files changed, 435 insertions(+), 6 deletions(-)
 create mode 100644 s390x/sclp.c
Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 1/2 s390x: sclp: add service call instruction wrapper

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 96cca2e..b3caff6 100644
@@ -269,4 +269,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 7798f04..e35c282 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.7.4
#2 lore raw

PATCH v3 2/2 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        | 417 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg |   3 +
 3 files changed, 421 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 +417 -0

417 lines not on this page · raw message

s390x/unittests.cfg +3 -0
index f1b07cd..75e3d37 100644
@@ -75,3 +75,6 @@ file = stsi.elf
 [smp]
 file = smp.elf
 extra_params =-smp 2
+
+[sclp]
+file = sclp.elf
Signature · 1 line
2.7.4
#3 lore raw

Re: [kvm-unit-tests PATCH v3 2/2] s390x: SCLP unit test

Quoted 14 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

[...]

Quoted 15 lines
s390x/sclp.c new file +15 -0
+
+#define PGM_NONE	1
+#define PGM_BIT_SPEC	(1ULL << PGM_INT_CODE_SPECIFICATION)
+#define PGM_BIT_ADDR	(1ULL << PGM_INT_CODE_ADDRESSING)
+#define PGM_BIT_PRIV	(1ULL << PGM_INT_CODE_PRIVILEGED_OPERATION)
+#define MKPTR(x) ((void *)(uint64_t)(x))
+
+static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE * 2)));
+static uint8_t prefix_buf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE * 2)));
+static uint8_t sccb_template[PAGE_SIZE];
+static uint32_t valid_code;
+static struct lowcore *lc;
+
+/**
+ * Enable SCLP interrupt.

s390x/sclp.c line 42

Quoted 10 lines
s390x/sclp.c new file +10 -0
+ */
+static void sclp_setup_int_test(void)
+{
+	uint64_t mask;
+
+	ctl_set_bit(0, 9);
+	mask = extract_psw_mask();
+	mask |= PSW_MASK_EXT;
+	load_psw_mask(mask);
+}

I don't have a strong opinion here, but I think I'd slightly prefer to use the function from lib/s390x/sclp.c instead, too.

Quoted 11 lines
s390x/sclp.c new file +11 -0
+/**
+ * Perform one service call, handling exceptions and interrupts.
+ */
+static int sclp_service_call_test(unsigned int command, void *sccb)
+{
+	int cc;
+
+	sclp_mark_busy();
+	sclp_setup_int_test();
+	cc = servc(command, __pa(sccb));
+	if (lc->pgm_int_code) {

s390x/sclp.c line 64

Quoted 10 lines
s390x/sclp.c new file +10 -0
+		sclp_handle_ext();
+		return 0;
+	}
+	if (!cc)
+		sclp_wait_busy();
+	return cc;
+}
+
+/**
+ * Perform one test at the given address, optionally using the SCCB template,

I think you should at least mention the meaning of the "len" parameter here, otherwise this is rather confusing (see below, my comment to sccb_template).

Quoted 2 lines

+ * checking for the expected program interrupts and return codes.
+ * Returns 1 in case of success or 0 in case of failure

Could use bool with true + false instead.

s390x/sclp.c line 75

Quoted 9 lines

+ */

s390x/sclp.c new file +8 -0
+static int test_one_sccb(uint32_t cmd, uint8_t *addr, uint16_t len, uint64_t exp_pgm, uint16_t exp_rc)
+{
+	SCCBHeader *h = (SCCBHeader *)addr;
+	int res, pgm;
+
+	/* Copy the template to the test address if needed */
+	if (len)
+		memcpy(addr, sccb_template, len);

Honestly, that sccb_template is rather confusing. Why does the caller has to provide both, the data in the sccb_template and the "addr" variable for yet another buffer? Wouldn't it be simpler if the caller simply sets up everything in a place of choice and then only passes the "addr" to the buffer?

Quoted 4 lines
s390x/sclp.c new file +4 -0
+	expect_pgm_int();
+	res = sclp_service_call_test(cmd, h);
+	if (res) {
+		report_info("SCLP not ready (command %#x, address %p, cc %d)", cmd, addr, res);

s390x/sclp.c line 89

Quoted 10 lines
s390x/sclp.c new file +10 -0
+		return 0;
+	}
+	pgm = clear_pgm_int();
+	/* Check if the program exception was one of the expected ones */
+	if (!((1ULL << pgm) & exp_pgm)) {
+		report_info("First failure at addr %p, size %d, cmd %#x, pgm code %d", addr, len, cmd, pgm);
+		return 0;
+	}
+	/* Check if the response code is the one expected */
+	if (exp_rc && (exp_rc != h->response_code)) {

You can drop the parentheses around "exp_rc != h->response_code".

Quoted 19 lines
s390x/sclp.c new file +19 -0
+		report_info("First failure at addr %p, size %d, cmd %#x, resp code %#x",
+				addr, len, cmd, h->response_code);
+		return 0;
+	}
+	return 1;
+}
+
+/**
+ * Wrapper for test_one_sccb to set up a simple SCCB template.
+ * Returns 1 in case of success or 0 in case of failure
+ */
+static int test_one_simple(uint32_t cmd, uint8_t *addr, uint16_t sccb_len,
+			uint16_t buf_len, uint64_t exp_pgm, uint16_t exp_rc)
+{
+	if (buf_len)
+		memset(sccb_template, 0, sizeof(sccb_template));
+	((SCCBHeader *)sccb_template)->length = sccb_len;
+	return test_one_sccb(cmd, addr, buf_len, exp_pgm, exp_rc);
+}

[...]

Quoted 15 lines
s390x/sclp.c new file +15 -0
+/**
+ * Test SCCBs whose address is in the lowcore or prefix area.
+ */
+static void test_sccb_prefix(void)
+{
+	uint32_t prefix, new_prefix;
+	int offset;
+
+	/* can't actually trash the lowcore, unsurprisingly things break if we do */
+	for (offset = 0; offset < 8192; offset += 8)
+		if (!test_one_sccb(valid_code, MKPTR(offset), 0, PGM_BIT_SPEC, 0))
+			break;
+	report("SCCB low pages", offset == 8192);
+
+	memcpy(prefix_buf, 0, 8192);

s390x/sclp.c line 161

Quoted 10 lines
s390x/sclp.c new file +10 -0
+	new_prefix = (uint32_t)(intptr_t)prefix_buf;
+	asm volatile("stpx %0" : "=Q" (prefix));
+	asm volatile("spx %0" : : "Q" (new_prefix) : "memory");
+
+	for (offset = 0; offset < 8192; offset += 8)
+		if (!test_one_simple(valid_code, MKPTR(new_prefix + offset), 8, 8, PGM_BIT_SPEC, 0))
+			break;
+	report("SCCB prefix pages", offset == 8192);
+
+	memcpy(prefix_buf, 0, 8192);

What's that memcpy() good for? A comment would be helpful.

Quoted 20 lines
s390x/sclp.c new file +20 -0
+	asm volatile("spx %0" : : "Q" (prefix) : "memory");
+}
+
+/**
+ * Test SCCBs that are above 2GB. If outside of memory, an addressing
+ * exception is also allowed.
+ */
+static void test_sccb_high(void)
+{
+	SCCBHeader *h = (SCCBHeader *)pagebuf;
+	uintptr_t a[33 * 4 * 2 + 2];
+	uint64_t maxram;
+	int i, pgm, len = 0;
+
+	h->length = 8;
+
+	for (i = 0; i < 33; i++)
+		a[len++] = 1UL << (i + 31);
+	for (i = 0; i < 33; i++)
+		a[len++] = 3UL << (i + 31);

s390x/sclp.c line 191

Quoted 10 lines
s390x/sclp.c new file +10 -0
+	for (i = 0; i < 33; i++)
+		a[len++] = 0xffffffff80000000UL << i;
+	a[len++] = 0x80000000;
+	for (i = 1; i < 33; i++, len++)
+		a[len] = a[len - 1] | (1UL << (i + 31));
+	for (i = 0; i < len; i++)
+		a[len + i] = a[i] + (intptr_t)h;
+	len += i;
+	a[len++] = 0xdeadbeef00000000;
+	a[len++] = 0xdeaddeadbeef0000;

IMHO a short comment in the code right in front of the above code block would be helpful to understand what you're doing here.

Quoted 12 lines
s390x/sclp.c new file +12 -0
+	maxram = get_ram_size();
+	for (i = 0; i < len; i++) {
+		pgm = PGM_BIT_SPEC | (a[i] >= maxram ? PGM_BIT_ADDR : 0);
+		if (!test_one_sccb(valid_code, (void *)a[i], 0, pgm, 0))
+			break;
+	}
+	report("SCCB high addresses", i == len);
+}
+
+/**
+ * Test invalid commands, both invalid command detail codes and valid
+ * ones with invalid command class code.

s390x/sclp.c line 214

Quoted 10 lines
s390x/sclp.c new file +10 -0
+ */
+static void test_inval(void)
+{
+	const uint16_t res = SCLP_RC_INVALID_SCLP_COMMAND;
+	uint32_t cmd;
+	int i;
+
+	report_prefix_push("Invalid command");
+	for (i = 0; i < 65536; i++) {
+		cmd = (0xdead0000) | i;

Please remove the parentheses around 0xdead0000

Quoted 5 lines
s390x/sclp.c new file +5 -0
+		if (!test_one_simple(cmd, pagebuf, PAGE_SIZE, PAGE_SIZE, PGM_NONE, res))
+			break;
+	}
+	report("Command detail code", i == 65536);
+

s390x/sclp.c line 229

Quoted 10 lines
s390x/sclp.c new file +10 -0
+	for (i = 0; i < 256; i++) {
+		cmd = (valid_code & ~0xff) | i;
+		if (cmd == valid_code)
+			continue;
+		if (!test_one_simple(cmd, pagebuf, PAGE_SIZE, PAGE_SIZE, PGM_NONE, res))
+			break;
+	}
+	report("Command class code", i == 256);
+	report_prefix_pop();
+}

Thomas

#4 lore raw

Re: [kvm-unit-tests PATCH v3 2/2] s390x: SCLP unit test

On Wed, 13 Nov 2019 10:34:02 +0100
Thomas Huth <[email protected]> wrote:

[...]

Quoted 7 lines
Quoted 7 lines
s390x/sclp.c new file +7 -0
+/**
+ * Enable SCLP interrupt.
+ */
+static void sclp_setup_int_test(void)
+{
+	uint64_t mask;
+
Quoted 8 lines

s390x/sclp.c line 42

Quoted 5 lines
s390x/sclp.c new file +5 -0
+	ctl_set_bit(0, 9);
+	mask = extract_psw_mask();
+	mask |= PSW_MASK_EXT;
+	load_psw_mask(mask);
+}  

I don't have a strong opinion here, but I think I'd slightly prefer to use the function from lib/s390x/sclp.c instead, too.

fine, I'll export it

Quoted 18 lines
Quoted 18 lines
s390x/sclp.c new file +18 -0
+/**
+ * Perform one service call, handling exceptions and interrupts.
+ */
+static int sclp_service_call_test(unsigned int command, void *sccb)
+{
+	int cc;
+
+	sclp_mark_busy();
+	sclp_setup_int_test();
+	cc = servc(command, __pa(sccb));
+	if (lc->pgm_int_code) {
+		sclp_handle_ext();
+		return 0;
+	}
+	if (!cc)
+		sclp_wait_busy();
+	return cc;
+}
Quoted 8 lines
Quoted 4 lines
s390x/sclp.c new file +3 -0
+
+/**
+ * Perform one test at the given address, optionally using the

SCCB template,

I think you should at least mention the meaning of the "len" parameter here, otherwise this is rather confusing (see below, my comment to sccb_template).

I'll rename it and add comments

Quoted 5 lines
Quoted 2 lines

+ * checking for the expected program interrupts and return codes.
+ * Returns 1 in case of success or 0 in case of failure

Could use bool with true + false instead.

Quoted 15 lines

s390x/sclp.c line 75

Quoted 9 lines

+ */
+static int test_one_sccb(uint32_t cmd, uint8_t *addr, uint16_t len, uint64_t exp_pgm, uint16_t exp_rc) +{

s390x/sclp.c new file +6 -0
+	SCCBHeader *h = (SCCBHeader *)addr;
+	int res, pgm;
+
+	/* Copy the template to the test address if needed */
+	if (len)
+		memcpy(addr, sccb_template, len);  

Honestly, that sccb_template is rather confusing. Why does the caller has to provide both, the data in the sccb_template and the "addr" variable for yet another buffer? Wouldn't it be simpler if the caller simply sets up everything in a place of choice and then only passes the "addr" to the buffer?

because you will test the same buffer at different addresses. this mechanism abstracts this. instead of having to clear the buffer and set the values for each address, you can simply set the template once and then call the same function, changing only the target address.

also, the target address is not always a buffer, in many cases it is in fact an invalid address, which should generate exceptions.

Quoted 11 lines
Quoted 11 lines
s390x/sclp.c new file +4 -0
+	expect_pgm_int();
+	res = sclp_service_call_test(cmd, h);
+	if (res) {
+		report_info("SCLP not ready (command %#x, address

%p, cc %d)", cmd, addr, res);

s390x/sclp.c new file +4 -0
+		return 0;
+	}
+	pgm = clear_pgm_int();
+	/* Check if the program exception was one of the expected

ones */

s390x/sclp.c new file +1 -0
+	if (!((1ULL << pgm) & exp_pgm)) {
Quoted 8 lines

s390x/sclp.c line 89

Quoted 6 lines
(quoted diff) +1 -0
+		report_info("First failure at addr %p, size %d,

cmd %#x, pgm code %d", addr, len, cmd, pgm);

s390x/sclp.c new file +4 -0
+		return 0;
+	}
+	/* Check if the response code is the one expected */
+	if (exp_rc && (exp_rc != h->response_code)) {  

You can drop the parentheses around "exp_rc != h->response_code".

fine, although I don't understand you hatred toward parentheses :)

Quoted 44 lines
Quoted 21 lines
(quoted diff) +1 -0
+		report_info("First failure at addr %p, size %d,

cmd %#x, resp code %#x",

s390x/sclp.c new file +11 -0
+				addr, len, cmd, h->response_code);
+		return 0;
+	}
+	return 1;
+}
+
+/**
+ * Wrapper for test_one_sccb to set up a simple SCCB template.
+ * Returns 1 in case of success or 0 in case of failure
+ */
+static int test_one_simple(uint32_t cmd, uint8_t *addr, uint16_t

sccb_len,

(quoted diff) +1 -0
+			uint16_t buf_len, uint64_t exp_pgm,

uint16_t exp_rc) +{

s390x/sclp.c new file +5 -0
+	if (buf_len)
+		memset(sccb_template, 0, sizeof(sccb_template));
+	((SCCBHeader *)sccb_template)->length = sccb_len;
+	return test_one_sccb(cmd, addr, buf_len, exp_pgm, exp_rc);
+}  

[...]

Quoted 22 lines
s390x/sclp.c new file +9 -0
+/**
+ * Test SCCBs whose address is in the lowcore or prefix area.
+ */
+static void test_sccb_prefix(void)
+{
+	uint32_t prefix, new_prefix;
+	int offset;
+
+	/* can't actually trash the lowcore, unsurprisingly things

break if we do */

(quoted diff) +2 -0
+	for (offset = 0; offset < 8192; offset += 8)
+		if (!test_one_sccb(valid_code, MKPTR(offset), 0,

PGM_BIT_SPEC, 0))

s390x/sclp.c new file +9 -0
+			break;
+	report("SCCB low pages", offset == 8192);
+
+	memcpy(prefix_buf, 0, 8192);
+	new_prefix = (uint32_t)(intptr_t)prefix_buf;
+	asm volatile("stpx %0" : "=Q" (prefix));
+	asm volatile("spx %0" : : "Q" (new_prefix) : "memory");
+
+	for (offset = 0; offset < 8192; offset += 8)
Quoted 8 lines

s390x/sclp.c line 161

Quoted 6 lines
s390x/sclp.c new file +6 -0
+		if (!test_one_simple(valid_code, MKPTR(new_prefix
+ offset), 8, 8, PGM_BIT_SPEC, 0))
+			break;
+	report("SCCB prefix pages", offset == 8192);
+
+	memcpy(prefix_buf, 0, 8192);  

What's that memcpy() good for? A comment would be helpful.

we just moved the prefix to a temporary one, and thrashed the old one. we can't simply set the old prefix and call it a day, things will break.

I added multiple comments to that function for v4 to explain what's going on

Quoted 26 lines
Quoted 26 lines
s390x/sclp.c new file +5 -0
+	asm volatile("spx %0" : : "Q" (prefix) : "memory");
+}
+
+/**
+ * Test SCCBs that are above 2GB. If outside of memory, an

addressing
+ * exception is also allowed.
+ */

s390x/sclp.c new file +18 -0
+static void test_sccb_high(void)
+{
+	SCCBHeader *h = (SCCBHeader *)pagebuf;
+	uintptr_t a[33 * 4 * 2 + 2];
+	uint64_t maxram;
+	int i, pgm, len = 0;
+
+	h->length = 8;
+
+	for (i = 0; i < 33; i++)
+		a[len++] = 1UL << (i + 31);
+	for (i = 0; i < 33; i++)
+		a[len++] = 3UL << (i + 31);
+	for (i = 0; i < 33; i++)
+		a[len++] = 0xffffffff80000000UL << i;
+	a[len++] = 0x80000000;
+	for (i = 1; i < 33; i++, len++)
+		a[len] = a[len - 1] | (1UL << (i + 31));
Quoted 8 lines

s390x/sclp.c line 191

Quoted 5 lines
s390x/sclp.c new file +5 -0
+	for (i = 0; i < len; i++)
+		a[len + i] = a[i] + (intptr_t)h;
+	len += i;
+	a[len++] = 0xdeadbeef00000000;
+	a[len++] = 0xdeaddeadbeef0000;  

IMHO a short comment in the code right in front of the above code block would be helpful to understand what you're doing here.

v4 will have comments explaining each of the loops

Quoted 19 lines
Quoted 19 lines
s390x/sclp.c new file +3 -0
+	maxram = get_ram_size();
+	for (i = 0; i < len; i++) {
+		pgm = PGM_BIT_SPEC | (a[i] >= maxram ?

PGM_BIT_ADDR : 0);

(quoted diff) +1 -0
+		if (!test_one_sccb(valid_code, (void *)a[i], 0,

pgm, 0))

s390x/sclp.c new file +7 -0
+			break;
+	}
+	report("SCCB high addresses", i == len);
+}
+
+/**
+ * Test invalid commands, both invalid command detail codes and

valid
+ * ones with invalid command class code.
+ */

s390x/sclp.c new file +3 -0
+static void test_inval(void)
+{
+	const uint16_t res = SCLP_RC_INVALID_SCLP_COMMAND;
Quoted 8 lines

s390x/sclp.c line 214

Quoted 6 lines
s390x/sclp.c new file +6 -0
+	uint32_t cmd;
+	int i;
+
+	report_prefix_push("Invalid command");
+	for (i = 0; i < 65536; i++) {
+		cmd = (0xdead0000) | i;  

Please remove the parentheses around 0xdead0000

ok, these ones were actually superfluous :)
probably a leftover from previous versions

Quoted 20 lines
Quoted 12 lines
(quoted diff) +1 -0
+		if (!test_one_simple(cmd, pagebuf, PAGE_SIZE,

PAGE_SIZE, PGM_NONE, res))

s390x/sclp.c new file +9 -0
+			break;
+	}
+	report("Command detail code", i == 65536);
+
+	for (i = 0; i < 256; i++) {
+		cmd = (valid_code & ~0xff) | i;
+		if (cmd == valid_code)
+			continue;
+		if (!test_one_simple(cmd, pagebuf, PAGE_SIZE,

PAGE_SIZE, PGM_NONE, res))

s390x/sclp.c line 229

Quoted 5 lines
s390x/sclp.c new file +5 -0
+			break;
+	}
+	report("Command class code", i == 256);
+	report_prefix_pop();
+}  

Thomas

#5 lore raw

Re: [kvm-unit-tests PATCH v3 2/2] s390x: SCLP unit test

Quoted 2 lines · Claudio Imbrenda

On Wed, 13 Nov 2019 10:34:02 +0100
Thomas Huth <[email protected]> wrote:

[...]

Quoted 31 lines
Quoted 7 lines
Quoted 3 lines

+/**
+ * Perform one test at the given address, optionally using the SCCB template,

I think you should at least mention the meaning of the "len" parameter here, otherwise this is rather confusing (see below, my comment to sccb_template).

I'll rename it and add comments

Quoted 5 lines
Quoted 2 lines

+ * checking for the expected program interrupts and return codes.
+ * Returns 1 in case of success or 0 in case of failure

Could use bool with true + false instead.

Quoted 15 lines

s390x/sclp.c line 75

Quoted 9 lines

+ */
+static int test_one_sccb(uint32_t cmd, uint8_t *addr, uint16_t len, uint64_t exp_pgm, uint16_t exp_rc) +{

s390x/sclp.c new file +6 -0
+	SCCBHeader *h = (SCCBHeader *)addr;
+	int res, pgm;
+
+	/* Copy the template to the test address if needed */
+	if (len)
+		memcpy(addr, sccb_template, len);  

Honestly, that sccb_template is rather confusing. Why does the caller has to provide both, the data in the sccb_template and the "addr" variable for yet another buffer? Wouldn't it be simpler if the caller simply sets up everything in a place of choice and then only passes the "addr" to the buffer?

Quoted 7 lines

because you will test the same buffer at different addresses. this mechanism abstracts this. instead of having to clear the buffer and set the values for each address, you can simply set the template once and then call the same function, changing only the target address.

also, the target address is not always a buffer, in many cases it is in fact an invalid address, which should generate exceptions.

Hmm, ok, I guess some additional comments like this in the source code would be helpful.

Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
s390x/sclp.c new file +4 -0
+	expect_pgm_int();
+	res = sclp_service_call_test(cmd, h);
+	if (res) {
+		report_info("SCLP not ready (command %#x, address

%p, cc %d)", cmd, addr, res);

s390x/sclp.c new file +4 -0
+		return 0;
+	}
+	pgm = clear_pgm_int();
+	/* Check if the program exception was one of the expected

ones */

s390x/sclp.c new file +1 -0
+	if (!((1ULL << pgm) & exp_pgm)) {
Quoted 8 lines

s390x/sclp.c line 89

Quoted 6 lines
(quoted diff) +1 -0
+		report_info("First failure at addr %p, size %d,

cmd %#x, pgm code %d", addr, len, cmd, pgm);

s390x/sclp.c new file +4 -0
+		return 0;
+	}
+	/* Check if the response code is the one expected */
+	if (exp_rc && (exp_rc != h->response_code)) {  

You can drop the parentheses around "exp_rc != h->response_code".

Quoted 1 line

fine, although I don't understand you hatred toward parentheses :)

I took a LISP class at university once ... never quite recovered from that...

No, honestly, the problem is rather that these additional parentheses slow me down when I read the source code. If I see such if-statements, my brain starts to think something like "There are parentheses here, so there must be some additional non-trivial logic in this if-statement... let's try to understand that..." and it takes a second to realize that it's not the case and the parentheses are just superfluous.

Quoted 31 lines
Quoted 22 lines
Quoted 22 lines
s390x/sclp.c new file +9 -0
+/**
+ * Test SCCBs whose address is in the lowcore or prefix area.
+ */
+static void test_sccb_prefix(void)
+{
+	uint32_t prefix, new_prefix;
+	int offset;
+
+	/* can't actually trash the lowcore, unsurprisingly things

break if we do */

(quoted diff) +2 -0
+	for (offset = 0; offset < 8192; offset += 8)
+		if (!test_one_sccb(valid_code, MKPTR(offset), 0,

PGM_BIT_SPEC, 0))

s390x/sclp.c new file +9 -0
+			break;
+	report("SCCB low pages", offset == 8192);
+
+	memcpy(prefix_buf, 0, 8192);
+	new_prefix = (uint32_t)(intptr_t)prefix_buf;
+	asm volatile("stpx %0" : "=Q" (prefix));
+	asm volatile("spx %0" : : "Q" (new_prefix) : "memory");
+
+	for (offset = 0; offset < 8192; offset += 8)
Quoted 8 lines

s390x/sclp.c line 161

Quoted 6 lines
s390x/sclp.c new file +6 -0
+		if (!test_one_simple(valid_code, MKPTR(new_prefix
+ offset), 8, 8, PGM_BIT_SPEC, 0))
+			break;
+	report("SCCB prefix pages", offset == 8192);
+
+	memcpy(prefix_buf, 0, 8192);  

What's that memcpy() good for? A comment would be helpful.

Quoted 2 lines

we just moved the prefix to a temporary one, and thrashed the old one. we can't simply set the old prefix and call it a day, things will break.

Did the test really trash the old one? ... hmm, I guess I got the code wrong, that prefix addressing is always so confusing. Is SCLP working with absolute or real addresses?

Thomas

#6 lore raw

Re: [kvm-unit-tests PATCH v3 2/2] s390x: SCLP unit test

On Wed, 13 Nov 2019 14:05:24 +0100
Thomas Huth <[email protected]> wrote:

[...]

Quoted 2 lines

Hmm, ok, I guess some additional comments like this in the source code would be helpful.

ok, I'll add plenty

Quoted 25 lines
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
s390x/sclp.c new file +4 -0
+	expect_pgm_int();
+	res = sclp_service_call_test(cmd, h);
+	if (res) {
+		report_info("SCLP not ready (command %#x, address

%p, cc %d)", cmd, addr, res);

s390x/sclp.c new file +4 -0
+		return 0;
+	}
+	pgm = clear_pgm_int();
+	/* Check if the program exception was one of the expected

ones */

s390x/sclp.c new file +1 -0
+	if (!((1ULL << pgm) & exp_pgm)) {
Quoted 8 lines

s390x/sclp.c line 89

Quoted 6 lines
(quoted diff) +1 -0
+		report_info("First failure at addr %p, size %d,

cmd %#x, pgm code %d", addr, len, cmd, pgm);

s390x/sclp.c new file +4 -0
+		return 0;
+	}
+	/* Check if the response code is the one expected */
+	if (exp_rc && (exp_rc != h->response_code)) {    

You can drop the parentheses around "exp_rc != h->response_code".

Quoted 1 line

fine, although I don't understand you hatred toward parentheses :)

I took a LISP class at university once ... never quite recovered from that...

Quoted 7 lines

No, honestly, the problem is rather that these additional parentheses slow me down when I read the source code. If I see such if-statements, my brain starts to think something like "There are parentheses here, so there must be some additional non-trivial logic in this if-statement... let's try to understand that..." and it takes a second to realize that it's not the case and the parentheses are just superfluous.

on the other hand it helps people who don't remember the C operator precedence by heart :)

but yeah won't be in v4

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
s390x/sclp.c new file +9 -0
+/**
+ * Test SCCBs whose address is in the lowcore or prefix area.
+ */
+static void test_sccb_prefix(void)
+{
+	uint32_t prefix, new_prefix;
+	int offset;
+
+	/* can't actually trash the lowcore, unsurprisingly

things break if we do */

(quoted diff) +2 -0
+	for (offset = 0; offset < 8192; offset += 8)
+		if (!test_one_sccb(valid_code, MKPTR(offset), 0,

PGM_BIT_SPEC, 0))

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

s390x/sclp.c

Quoted 8 lines
s390x/sclp.c new file +8 -0
+	memcpy(prefix_buf, 0, 8192);
+	new_prefix = (uint32_t)(intptr_t)prefix_buf;
+	asm volatile("stpx %0" : "=Q" (prefix));
+	asm volatile("spx %0" : : "Q" (new_prefix) : "memory");
+
+	for (offset = 0; offset < 8192; offset += 8)
+		if (!test_one_simple(valid_code, MKPTR(new_prefix
+ offset), 8, 8, PGM_BIT_SPEC, 0))

here ^ (read below)

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

s390x/sclp.c line 161

Quoted 4 lines
s390x/sclp.c new file +4 -0
+			break;
+	report("SCCB prefix pages", offset == 8192);
+
+	memcpy(prefix_buf, 0, 8192);    

What's that memcpy() good for? A comment would be helpful.

Quoted 5 lines
Quoted 3 lines

we just moved the prefix to a temporary one, and thrashed the old one. we can't simply set the old prefix and call it a day, things will break.

Did the test really trash the old one? ... hmm, I guess I got the code

yes, the default prefix is 0 and we are writing at absolute 0 (see above where exactly). the SCLP call *should* not succeed anyway, but we need to test it

I'm reworking this function because it possibly doesn't test all cases. I added plenty of comments there too to explain what's going on

Quoted 2 lines

wrong, that prefix addressing is always so confusing. Is SCLP working with absolute or real addresses?

yes.

both lowcore (real 0, absolute $PREFIX<<13) and absolute 0 (real $PREFIX<<13, absolute 0) are forbidden for SCLP, so real or absolute does not make a difference.