Skip to contentSkip to conversation

s390x: uv-host: Fixups and extensions part 1

PATCH New Janosch Frank 1 participant 9 messages Jun 22, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover s390x: uv-host: Fixups and extensions part 1

The uv-host test has a lot of historical growth problems which has largely been overlooked since running it is harder than running a KVM (guest 2) based test.

This series fixes up smaller problems but still leaves the test with fails when running create config base and variable storage tests. Those problems will either be fixed up with the second series or with a firmware fix since I'm unsure on which side of the os/fw fence the problem exists.

The series is based on my other series that introduces pv-ipl and pv-icpt. The memory allocation fix will be added to the new version of that series so all G1 tests are fixed.

v4:
- Re-based on the ipl/icpt series
- Replaced 1024 divisions with SZ_1M
- Instead of making the variable storage test a xfail it's now removed until I understand what's going on
- Since the sigp patch only changed code that I removed, the patch could be dropped
v3:
- Re-based on the ipl/icpt series
- Added review-bys
v2:
- Added patch that exchanges sigp_retry with the smp variant
- Re-worked the create config test handling
- Minor fixups

Janosch Frank (8):
s390x: uv-host: Fix UV init test memory allocation
s390x: uv-host: Check for sufficient amount of memory
s390x: uv-host: Beautify code
s390x: uv-host: Add cpu number check to test_init
s390x: uv-host: Remove create guest variable storage prefix check
s390x: uv-host: Properly handle config creation errors
s390x: uv-host: Fence access checks when UV debug is enabled
s390x: uv-host: Add the test to unittests.conf

 lib/s390x/asm/uv.h  |   1 +
 s390x/unittests.cfg |   7 +++
 s390x/uv-host.c     | 134 ++++++++++++++++++++++++++++++++------------
 3 files changed, 107 insertions(+), 35 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/8 s390x: uv-host: Fix UV init test memory allocation

The init memory has to be above 2G and 1M aligned but we're currently aligning on 2G which means the allocations need a lot of unused memory.

Also the second block of memory was never actually used for the double init test since its address is never put into the uvcb.

Let's fix that.

---
 s390x/uv-host.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
s390x/uv-host.c +14 -9
index 33e6eec6..9dfaebd7 100644
@@ -500,14 +500,17 @@ static void test_config_create(void)
 static void test_init(void)
 {
 	int rc;
-	uint64_t mem;
+	uint64_t tmp;
 
-	/* Donated storage needs to be over 2GB */
-	mem = (uint64_t)memalign_pages_flags(SZ_1M, uvcb_qui.uv_base_stor_len, AREA_NORMAL);
+	/*
+	 * Donated storage needs to be over 2GB, AREA_NORMAL does that
+	 * on s390x.
+	 */
+	tmp = (uint64_t)memalign_pages_flags(SZ_1M, uvcb_qui.uv_base_stor_len, AREA_NORMAL);
 
 	uvcb_init.header.len = sizeof(uvcb_init);
 	uvcb_init.header.cmd = UVC_CMD_INIT_UV;
-	uvcb_init.stor_origin = mem;
+	uvcb_init.stor_origin = tmp;
 	uvcb_init.stor_len = uvcb_qui.uv_base_stor_len;
 
 	report_prefix_push("init");
@@ -528,14 +531,14 @@ static void test_init(void)
 	rc = uv_call(0, (uint64_t)&uvcb_init);
 	report(rc == 1 && (uvcb_init.header.rc == 0x104 || uvcb_init.header.rc == 0x105),
 	       "storage origin invalid");
-	uvcb_init.stor_origin = mem;
+	uvcb_init.stor_origin = tmp;
 
 	if (uvcb_init.stor_len >= HPAGE_SIZE) {
 		uvcb_init.stor_origin = get_max_ram_size() - HPAGE_SIZE;
 		rc = uv_call(0, (uint64_t)&uvcb_init);
 		report(rc == 1 && uvcb_init.header.rc == 0x105,
 		       "storage + length invalid");
-		uvcb_init.stor_origin = mem;
+		uvcb_init.stor_origin = tmp;
 	} else {
 		report_skip("storage + length invalid, stor_len < HPAGE_SIZE");
 	}
@@ -544,7 +547,7 @@ static void test_init(void)
 	rc = uv_call(0, (uint64_t)&uvcb_init);
 	report(rc == 1 && uvcb_init.header.rc == 0x108,
 	       "storage below 2GB");
-	uvcb_init.stor_origin = mem;
+	uvcb_init.stor_origin = tmp;
 
 	smp_cpu_setup(1, PSW_WITH_CUR_MASK(cpu_loop));
 	rc = uv_call(0, (uint64_t)&uvcb_init);
@@ -555,10 +558,12 @@ static void test_init(void)
 	rc = uv_call(0, (uint64_t)&uvcb_init);
 	report(rc == 0 && uvcb_init.header.rc == UVC_RC_EXECUTED, "successful");
 
-	mem = (uint64_t)memalign(1UL << 31, uvcb_qui.uv_base_stor_len);
+	tmp = uvcb_init.stor_origin;
+	uvcb_init.stor_origin =	(uint64_t)memalign_pages_flags(HPAGE_SIZE, uvcb_qui.uv_base_stor_len, AREA_NORMAL);
 	rc = uv_call(0, (uint64_t)&uvcb_init);
 	report(rc == 1 && uvcb_init.header.rc == 0x101, "double init");
-	free((void *)mem);
+	free((void *)uvcb_init.stor_origin);
+	uvcb_init.stor_origin = tmp;
 
 	report_prefix_pop();
 }
Signature · 1 line
2.34.1
#2 lore raw

PATCH v4 2/8 s390x: uv-host: Check for sufficient amount of memory

In reply to Janosch Frank

The UV init storage needs to be above 2G so we need a little over 2G of memory when running the test.

---
 s390x/uv-host.c | 8 ++++++++
 1 file changed, 8 insertions(+)
s390x/uv-host.c +8 -0
index 9dfaebd7..ee8e44d1 100644
@@ -15,6 +15,7 @@
 #include <sclp.h>
 #include <smp.h>
 #include <uv.h>
+#include <snippet.h>
 #include <mmu.h>
 #include <asm/page.h>
 #include <asm/sigp.h>
@@ -720,6 +721,13 @@ int main(void)
 	test_invalid();
 	test_uv_uninitialized();
 	test_query();
+
+	if (get_ram_size() < SNIPPET_PV_MIN_MEM_SIZE) {
+		report_skip("Not enough memory. This test needs about %ld MB of memory",
+			    SNIPPET_PV_MIN_MEM_SIZE / SZ_1M);
+		goto done;
+	}
+
 	test_init();
 
 	setup_vmem();
Signature · 1 line
2.34.1
#3 lore raw

PATCH v4 3/8 s390x: uv-host: Beautify code

In reply to Janosch Frank

Fixup top comment and add missing space.

---
 s390x/uv-host.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
s390x/uv-host.c +2 -2
index ee8e44d1..08ef266a 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Guest Ultravisor Call tests
+ * Host Ultravisor Call tests
  *
  * Copyright (c) 2021 IBM Corp
  *
@@ -34,7 +34,7 @@ static struct uv_cb_csc uvcb_csc;
 
 extern int diag308_load_reset(u64 code);
 
-struct cmd_list{
+struct cmd_list {
 	const char *name;
 	uint16_t cmd;
 	uint16_t len;
Signature · 1 line
2.34.1
#4 lore raw

PATCH v4 4/8 s390x: uv-host: Add cpu number check to test_init

In reply to Janosch Frank

We should only run a test that needs more than one cpu if a sufficient number of cpus are available.

---
 s390x/uv-host.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
s390x/uv-host.c +9 -5
index 08ef266a..c04cdd73 100644
@@ -550,11 +550,15 @@ static void test_init(void)
 	       "storage below 2GB");
 	uvcb_init.stor_origin = tmp;
 
-	smp_cpu_setup(1, PSW_WITH_CUR_MASK(cpu_loop));
-	rc = uv_call(0, (uint64_t)&uvcb_init);
-	report(rc == 1 && uvcb_init.header.rc == 0x102,
-	       "too many running cpus");
-	smp_cpu_stop(1);
+	if (smp_query_num_cpus() > 1) {
+		smp_cpu_setup(1, PSW_WITH_CUR_MASK(cpu_loop));
+		rc = uv_call(0, (uint64_t)&uvcb_init);
+		report(rc == 1 && uvcb_init.header.rc == 0x102,
+		       "too many running cpus");
+		smp_cpu_stop(1);
+	} else {
+		report_skip("Not enough cpus for 0x102 test");
+	}
 
 	rc = uv_call(0, (uint64_t)&uvcb_init);
 	report(rc == 0 && uvcb_init.header.rc == UVC_RC_EXECUTED, "successful");
Signature · 1 line
2.34.1
#5 lore raw

PATCH v4 5/8 s390x: uv-host: Remove create guest variable storage prefix check

In reply to Janosch Frank

The test fails and we currently dont know why, so let's remove it so we can add it again once we understand the problem.

---
 s390x/uv-host.c | 10 ----------
 1 file changed, 10 deletions(-)
s390x/uv-host.c +0 -10
index c04cdd73..4112b4b6 100644
@@ -18,7 +18,6 @@
 #include <snippet.h>
 #include <mmu.h>
 #include <asm/page.h>
-#include <asm/sigp.h>
 #include <asm/pgtable.h>
 #include <asm/asm-offsets.h>
 #include <asm/interrupt.h>
@@ -435,15 +434,6 @@ static void test_config_create(void)
 	       "base storage origin contains lowcore");
 	uvcb_cgc.conf_base_stor_origin = tmp;
 
-	if (smp_query_num_cpus() == 1) {
-		sigp_retry(1, SIGP_SET_PREFIX,
-			   uvcb_cgc.conf_var_stor_origin + PAGE_SIZE, NULL);
-		rc = uv_call(0, (uint64_t)&uvcb_cgc);
-		report(uvcb_cgc.header.rc == 0x10e && rc == 1 &&
-		       !uvcb_cgc.guest_handle, "variable storage area contains lowcore");
-		sigp_retry(1, SIGP_SET_PREFIX, 0x0, NULL);
-	}
-
 	tmp = uvcb_cgc.guest_sca;
 	uvcb_cgc.guest_sca = 0;
 	rc = uv_call(0, (uint64_t)&uvcb_cgc);
Signature · 1 line
2.34.1
#6 lore raw

PATCH v4 6/8 s390x: uv-host: Properly handle config creation errors

In reply to Janosch Frank

If the first bit is set on a error rc, the hypervisor will need to destroy the config before trying again. Let's properly handle those cases so we're not using stale data.

---
 lib/s390x/asm/uv.h |  1 +
 s390x/uv-host.c    | 65 +++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 57 insertions(+), 9 deletions(-)
lib/s390x/asm/uv.h +1 -0
index 38920461..e9fb19af 100644
@@ -24,6 +24,7 @@
 #define UVC_RC_NO_RESUME	0x0007
 #define UVC_RC_INV_GHANDLE	0x0020
 #define UVC_RC_INV_CHANDLE	0x0021
+#define UVC_RC_DSTR_NEEDED_FLG	0x8000
 
 #define UVC_CMD_QUI			0x0001
 #define UVC_CMD_INIT_UV			0x000f
s390x/uv-host.c +56 -9

132 lines not on this page · raw message

Signature · 1 line
2.34.1
#7 lore raw

PATCH v4 7/8 s390x: uv-host: Fence access checks when UV debug is enabled

In reply to Janosch Frank

The debug print directly accesses the UV header which will result in a second accesses exception which will abort the test. Let's fence the access tests instead.

---
 s390x/uv-host.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
s390x/uv-host.c +10 -0
index 65a9c6d3..55b46446 100644
@@ -164,6 +164,15 @@ static void test_access(void)
 
 	report_prefix_push("access");
 
+	/*
+	 * If debug is enabled info from the uv header is printed
+	 * which would lead to a second exception and a test abort.
+	 */
+	if (UVC_ERR_DEBUG) {
+		report_skip("Debug doesn't work with access tests");
+		goto out;
+	}
+
 	report_prefix_push("non-crossing");
 	protect_page(uvcb, PAGE_ENTRY_I);
 	for (i = 0; cmds[i].name; i++) {
@@ -196,6 +205,7 @@ static void test_access(void)
 	uvcb += 1;
 	unprotect_page(uvcb, PAGE_ENTRY_I);
 
+out:
 	free_pages(pages);
 	report_prefix_pop();
 }
Signature · 1 line
2.34.1
#8 lore raw

PATCH v4 8/8 s390x: uv-host: Add the test to unittests.conf

In reply to Janosch Frank

Better to skip than to not run it at all.

---
 s390x/unittests.cfg | 7 +++++++
 1 file changed, 7 insertions(+)
s390x/unittests.cfg +7 -0
index 49b3cee4..3b783fc3 100644
@@ -234,3 +234,10 @@ extra_params = -m 2200
 file = pv-diags.elf
 groups = pv-host
 extra_params = -m 2200
+
+[uv-host]
+file = uv-host.elf
+smp = 2
+groups = pv-host
+extra_params = -m 2200
+
Signature · 1 line
2.34.1