All of lore.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH v4 0/9] s390x: smp: Improve smp code and reset checks
@ 2020-01-21 13:42 Janosch Frank
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 1/9] s390x: smp: Cleanup smp.c Janosch Frank
                   ` (8 more replies)
  0 siblings, 9 replies; 26+ messages in thread
From: Janosch Frank @ 2020-01-21 13:42 UTC (permalink / raw)
  To: kvm; +Cc: thuth, borntraeger, linux-s390, david, cohuck

Let's extend sigp reset testing and clean up the smp library as well.

GIT: https://github.com/frankjaa/kvm-unit-tests/tree/smp_cleanup

V4:
	* Introduce set_flag() for manipulating testflag
	* Cleanup of stray braces and mb()s

v3:
	* Added patch to introduce cpu loop in cpu setup
	* Added patch that removes cpu loops in favor of the previously introduced one
	* Fixed inline assembly for fpc dirtying
	* Moved cpu stop hunk from first into the second patch
	* Reworked patch #4 commit message and added a comment when waiting for PU

v2:
	* Added cpu stop to test_store_status()
	* Added smp_cpu_destroy() to the end of smp.c main()
	* New patch that prints cpu id on interrupt errors
	* New patch that reworks cpu start in the smp library (needed for lpar)
	* nullp is now an array


Janosch Frank (9):
  s390x: smp: Cleanup smp.c
  s390x: smp: Only use smp_cpu_setup once
  s390x: Add cpu id to interrupt error prints
  s390x: smp: Rework cpu start and active tracking
  s390x: smp: Wait for cpu setup to finish
  s390x: smp: Loop if secondary cpu returns into cpu setup again
  s390x: smp: Remove unneeded cpu loops
  s390x: smp: Test all CRs on initial reset
  s390x: smp: Dirty fpc before initial reset test

 lib/s390x/interrupt.c | 20 +++++-----
 lib/s390x/smp.c       | 53 ++++++++++++++----------
 s390x/cstart64.S      |  4 ++
 s390x/smp.c           | 93 ++++++++++++++++++++++++++++---------------
 4 files changed, 106 insertions(+), 64 deletions(-)

-- 
2.20.1

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [kvm-unit-tests PATCH v4 1/9] s390x: smp: Cleanup smp.c
  2020-01-21 13:42 [kvm-unit-tests PATCH v4 0/9] s390x: smp: Improve smp code and reset checks Janosch Frank
@ 2020-01-21 13:42 ` Janosch Frank
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 2/9] s390x: smp: Only use smp_cpu_setup once Janosch Frank
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 26+ messages in thread
From: Janosch Frank @ 2020-01-21 13:42 UTC (permalink / raw)
  To: kvm; +Cc: thuth, borntraeger, linux-s390, david, cohuck

Let's remove a lot of badly formatted code by introducing the
wait_for_flag() and set_flag functions.

Also let's remove some stray spaces and always set the tesflag before
using it.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
---
 s390x/smp.c | 55 ++++++++++++++++++++++++++++++++---------------------
 1 file changed, 33 insertions(+), 22 deletions(-)

diff --git a/s390x/smp.c b/s390x/smp.c
index ab7e46c..e37eb56 100644
--- a/s390x/smp.c
+++ b/s390x/smp.c
@@ -22,6 +22,19 @@
 
 static int testflag = 0;
 
+static void wait_for_flag(void)
+{
+	while (!testflag)
+		mb();
+}
+
+static void set_flag(int val)
+{
+	mb();
+	testflag = val;
+	mb();
+}
+
 static void cpu_loop(void)
 {
 	for (;;) {}
@@ -29,21 +42,19 @@ static void cpu_loop(void)
 
 static void test_func(void)
 {
-	testflag = 1;
-	mb();
+	set_flag(1);
 	cpu_loop();
 }
 
 static void test_start(void)
 {
 	struct psw psw;
-	psw.mask =  extract_psw_mask();
+	psw.mask = extract_psw_mask();
 	psw.addr = (unsigned long)test_func;
 
+	set_flag(0);
 	smp_cpu_setup(1, psw);
-	while (!testflag) {
-		mb();
-	}
+	wait_for_flag();
 	report(1, "start");
 }
 
@@ -112,27 +123,27 @@ static void ecall(void)
 	mask = extract_psw_mask();
 	mask |= PSW_MASK_EXT;
 	load_psw_mask(mask);
-	testflag = 1;
+	set_flag(1);
 	while (lc->ext_int_code != 0x1202) { mb(); }
 	report(1, "ecall");
-	testflag= 1;
+	set_flag(1);
 }
 
 static void test_ecall(void)
 {
 	struct psw psw;
-	psw.mask =  extract_psw_mask();
+	psw.mask = extract_psw_mask();
 	psw.addr = (unsigned long)ecall;
 
 	report_prefix_push("ecall");
-	testflag= 0;
+	set_flag(0);
 	smp_cpu_destroy(1);
 
 	smp_cpu_setup(1, psw);
-	while (!testflag) { mb(); }
-	testflag= 0;
+	wait_for_flag();
+	set_flag(0);
 	sigp(1, SIGP_EXTERNAL_CALL, 0, NULL);
-	while(!testflag) {mb();}
+	wait_for_flag();
 	smp_cpu_stop(1);
 	report_prefix_pop();
 }
@@ -147,27 +158,27 @@ static void emcall(void)
 	mask = extract_psw_mask();
 	mask |= PSW_MASK_EXT;
 	load_psw_mask(mask);
-	testflag= 1;
+	set_flag(1);
 	while (lc->ext_int_code != 0x1201) { mb(); }
 	report(1, "ecall");
-	testflag = 1;
+	set_flag(1);
 }
 
 static void test_emcall(void)
 {
 	struct psw psw;
-	psw.mask =  extract_psw_mask();
+	psw.mask = extract_psw_mask();
 	psw.addr = (unsigned long)emcall;
 
 	report_prefix_push("emcall");
-	testflag= 0;
+	set_flag(0);
 	smp_cpu_destroy(1);
 
 	smp_cpu_setup(1, psw);
-	while (!testflag) { mb(); }
-	testflag= 0;
+	wait_for_flag();
+	set_flag(0);
 	sigp(1, SIGP_EMERGENCY_SIGNAL, 0, NULL);
-	while(!testflag) { mb(); }
+	wait_for_flag();
 	smp_cpu_stop(1);
 	report_prefix_pop();
 }
@@ -177,7 +188,7 @@ static void test_reset_initial(void)
 	struct cpu_status *status = alloc_pages(0);
 	struct psw psw;
 
-	psw.mask =  extract_psw_mask();
+	psw.mask = extract_psw_mask();
 	psw.addr = (unsigned long)test_func;
 
 	report_prefix_push("reset initial");
@@ -208,7 +219,7 @@ static void test_reset(void)
 {
 	struct psw psw;
 
-	psw.mask =  extract_psw_mask();
+	psw.mask = extract_psw_mask();
 	psw.addr = (unsigned long)test_func;
 
 	report_prefix_push("cpu reset");
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [kvm-unit-tests PATCH v4 2/9] s390x: smp: Only use smp_cpu_setup once
  2020-01-21 13:42 [kvm-unit-tests PATCH v4 0/9] s390x: smp: Improve smp code and reset checks Janosch Frank
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 1/9] s390x: smp: Cleanup smp.c Janosch Frank
@ 2020-01-21 13:42 ` Janosch Frank
  2020-01-23 13:45   ` David Hildenbrand
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 3/9] s390x: Add cpu id to interrupt error prints Janosch Frank
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 26+ messages in thread
From: Janosch Frank @ 2020-01-21 13:42 UTC (permalink / raw)
  To: kvm; +Cc: thuth, borntraeger, linux-s390, david, cohuck

Let's stop and start instead of using setup to run a function on a
cpu.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Acked-by: David Hildenbrand <david@redhat.com>
---
 s390x/smp.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/s390x/smp.c b/s390x/smp.c
index e37eb56..3e8cf3e 100644
--- a/s390x/smp.c
+++ b/s390x/smp.c
@@ -53,7 +53,7 @@ static void test_start(void)
 	psw.addr = (unsigned long)test_func;
 
 	set_flag(0);
-	smp_cpu_setup(1, psw);
+	smp_cpu_start(1, psw);
 	wait_for_flag();
 	report(1, "start");
 }
@@ -109,6 +109,7 @@ static void test_store_status(void)
 	report(1, "status written");
 	free_pages(status, PAGE_SIZE * 2);
 	report_prefix_pop();
+	smp_cpu_stop(1);
 
 	report_prefix_pop();
 }
@@ -137,9 +138,8 @@ static void test_ecall(void)
 
 	report_prefix_push("ecall");
 	set_flag(0);
-	smp_cpu_destroy(1);
 
-	smp_cpu_setup(1, psw);
+	smp_cpu_start(1, psw);
 	wait_for_flag();
 	set_flag(0);
 	sigp(1, SIGP_EXTERNAL_CALL, 0, NULL);
@@ -172,9 +172,8 @@ static void test_emcall(void)
 
 	report_prefix_push("emcall");
 	set_flag(0);
-	smp_cpu_destroy(1);
 
-	smp_cpu_setup(1, psw);
+	smp_cpu_start(1, psw);
 	wait_for_flag();
 	set_flag(0);
 	sigp(1, SIGP_EMERGENCY_SIGNAL, 0, NULL);
@@ -192,7 +191,7 @@ static void test_reset_initial(void)
 	psw.addr = (unsigned long)test_func;
 
 	report_prefix_push("reset initial");
-	smp_cpu_setup(1, psw);
+	smp_cpu_start(1, psw);
 
 	sigp_retry(1, SIGP_INITIAL_CPU_RESET, 0, NULL);
 	sigp(1, SIGP_STORE_STATUS_AT_ADDRESS, (uintptr_t)status, NULL);
@@ -223,7 +222,7 @@ static void test_reset(void)
 	psw.addr = (unsigned long)test_func;
 
 	report_prefix_push("cpu reset");
-	smp_cpu_setup(1, psw);
+	smp_cpu_start(1, psw);
 
 	sigp_retry(1, SIGP_CPU_RESET, 0, NULL);
 	report(smp_cpu_stopped(1), "cpu stopped");
@@ -232,6 +231,7 @@ static void test_reset(void)
 
 int main(void)
 {
+	struct psw psw;
 	report_prefix_push("smp");
 
 	if (smp_query_num_cpus() == 1) {
@@ -239,6 +239,12 @@ int main(void)
 		goto done;
 	}
 
+	/* Setting up the cpu to give it a stack and lowcore */
+	psw.mask = extract_psw_mask();
+	psw.addr = (unsigned long)cpu_loop;
+	smp_cpu_setup(1, psw);
+	smp_cpu_stop(1);
+
 	test_start();
 	test_stop();
 	test_stop_store_status();
@@ -247,6 +253,7 @@ int main(void)
 	test_emcall();
 	test_reset();
 	test_reset_initial();
+	smp_cpu_destroy(1);
 
 done:
 	report_prefix_pop();
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [kvm-unit-tests PATCH v4 3/9] s390x: Add cpu id to interrupt error prints
  2020-01-21 13:42 [kvm-unit-tests PATCH v4 0/9] s390x: smp: Improve smp code and reset checks Janosch Frank
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 1/9] s390x: smp: Cleanup smp.c Janosch Frank
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 2/9] s390x: smp: Only use smp_cpu_setup once Janosch Frank
@ 2020-01-21 13:42 ` Janosch Frank
  2020-01-23 10:02   ` Janosch Frank
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 4/9] s390x: smp: Rework cpu start and active tracking Janosch Frank
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 26+ messages in thread
From: Janosch Frank @ 2020-01-21 13:42 UTC (permalink / raw)
  To: kvm; +Cc: thuth, borntraeger, linux-s390, david, cohuck

It's good to know which cpu broke the test.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
---
 lib/s390x/interrupt.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/lib/s390x/interrupt.c b/lib/s390x/interrupt.c
index 05f30be..773752a 100644
--- a/lib/s390x/interrupt.c
+++ b/lib/s390x/interrupt.c
@@ -107,8 +107,8 @@ static void fixup_pgm_int(void)
 void handle_pgm_int(void)
 {
 	if (!pgm_int_expected)
-		report_abort("Unexpected program interrupt: %d at %#lx, ilen %d\n",
-			     lc->pgm_int_code, lc->pgm_old_psw.addr,
+		report_abort("Unexpected program interrupt: %d on cpu %d at %#lx, ilen %d\n",
+			     lc->pgm_int_code, stap(), lc->pgm_old_psw.addr,
 			     lc->pgm_int_id);
 
 	pgm_int_expected = false;
@@ -119,8 +119,8 @@ void handle_ext_int(void)
 {
 	if (!ext_int_expected &&
 	    lc->ext_int_code != EXT_IRQ_SERVICE_SIG) {
-		report_abort("Unexpected external call interrupt (code %#x): at %#lx",
-			     lc->ext_int_code, lc->ext_old_psw.addr);
+		report_abort("Unexpected external call interrupt (code %#x): on cpu %d at %#lx",
+			     stap(), lc->ext_int_code, lc->ext_old_psw.addr);
 		return;
 	}
 
@@ -137,18 +137,18 @@ void handle_ext_int(void)
 
 void handle_mcck_int(void)
 {
-	report_abort("Unexpected machine check interrupt: at %#lx",
-		     lc->mcck_old_psw.addr);
+	report_abort("Unexpected machine check interrupt: on cpu %d at %#lx",
+		     stap(), lc->mcck_old_psw.addr);
 }
 
 void handle_io_int(void)
 {
-	report_abort("Unexpected io interrupt: at %#lx",
-		     lc->io_old_psw.addr);
+	report_abort("Unexpected io interrupt: on cpu %d at %#lx",
+		     stap(), lc->io_old_psw.addr);
 }
 
 void handle_svc_int(void)
 {
-	report_abort("Unexpected supervisor call interrupt: at %#lx",
-		     lc->svc_old_psw.addr);
+	report_abort("Unexpected supervisor call interrupt: on cpu %d at %#lx",
+		     stap(), lc->svc_old_psw.addr);
 }
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [kvm-unit-tests PATCH v4 4/9] s390x: smp: Rework cpu start and active tracking
  2020-01-21 13:42 [kvm-unit-tests PATCH v4 0/9] s390x: smp: Improve smp code and reset checks Janosch Frank
                   ` (2 preceding siblings ...)
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 3/9] s390x: Add cpu id to interrupt error prints Janosch Frank
@ 2020-01-21 13:42 ` Janosch Frank
  2020-01-21 17:40   ` David Hildenbrand
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 5/9] s390x: smp: Wait for cpu setup to finish Janosch Frank
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 26+ messages in thread
From: Janosch Frank @ 2020-01-21 13:42 UTC (permalink / raw)
  To: kvm; +Cc: thuth, borntraeger, linux-s390, david, cohuck

The architecture specifies that processing sigp orders may be
asynchronous, and this is indeed the case on some hypervisors, so we
need to wait until the cpu runs before we return from the setup/start
function.

As there was a lot of duplicate code, a common function for cpu
restarts has been introduced.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
---
 lib/s390x/smp.c | 50 ++++++++++++++++++++++++++++---------------------
 1 file changed, 29 insertions(+), 21 deletions(-)

diff --git a/lib/s390x/smp.c b/lib/s390x/smp.c
index f57f420..84e681d 100644
--- a/lib/s390x/smp.c
+++ b/lib/s390x/smp.c
@@ -104,35 +104,46 @@ int smp_cpu_stop_store_status(uint16_t addr)
 	return rc;
 }
 
+static int smp_cpu_restart_nolock(uint16_t addr, struct psw *psw)
+{
+	int rc;
+	struct cpu *cpu = smp_cpu_from_addr(addr);
+
+	if (!cpu)
+		return -1;
+	if (psw) {
+		cpu->lowcore->restart_new_psw.mask = psw->mask;
+		cpu->lowcore->restart_new_psw.addr = psw->addr;
+	}
+	rc = sigp(addr, SIGP_RESTART, 0, NULL);
+	if (rc)
+		return rc;
+	/*
+	 * The order has been accepted, but the actual restart may not
+	 * have been performed yet, so wait until the cpu is running.
+	 */
+	while (!smp_cpu_running(addr))
+		mb();
+	cpu->active = true;
+	return 0;
+}
+
 int smp_cpu_restart(uint16_t addr)
 {
-	int rc = -1;
-	struct cpu *cpu;
+	int rc;
 
 	spin_lock(&lock);
-	cpu = smp_cpu_from_addr(addr);
-	if (cpu) {
-		rc = sigp(addr, SIGP_RESTART, 0, NULL);
-		cpu->active = true;
-	}
+	rc = smp_cpu_restart_nolock(addr, NULL);
 	spin_unlock(&lock);
 	return rc;
 }
 
 int smp_cpu_start(uint16_t addr, struct psw psw)
 {
-	int rc = -1;
-	struct cpu *cpu;
-	struct lowcore *lc;
+	int rc;
 
 	spin_lock(&lock);
-	cpu = smp_cpu_from_addr(addr);
-	if (cpu) {
-		lc = cpu->lowcore;
-		lc->restart_new_psw.mask = psw.mask;
-		lc->restart_new_psw.addr = psw.addr;
-		rc = sigp(addr, SIGP_RESTART, 0, NULL);
-	}
+	rc = smp_cpu_restart_nolock(addr, &psw);
 	spin_unlock(&lock);
 	return rc;
 }
@@ -192,10 +203,7 @@ int smp_cpu_setup(uint16_t addr, struct psw psw)
 	lc->sw_int_crs[0] = 0x0000000000040000UL;
 
 	/* Start processing */
-	rc = sigp_retry(cpu->addr, SIGP_RESTART, 0, NULL);
-	if (!rc)
-		cpu->active = true;
-
+	smp_cpu_restart_nolock(addr, NULL);
 out:
 	spin_unlock(&lock);
 	return rc;
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [kvm-unit-tests PATCH v4 5/9] s390x: smp: Wait for cpu setup to finish
  2020-01-21 13:42 [kvm-unit-tests PATCH v4 0/9] s390x: smp: Improve smp code and reset checks Janosch Frank
                   ` (3 preceding siblings ...)
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 4/9] s390x: smp: Rework cpu start and active tracking Janosch Frank
@ 2020-01-21 13:42 ` Janosch Frank
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 6/9] s390x: smp: Loop if secondary cpu returns into cpu setup again Janosch Frank
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 26+ messages in thread
From: Janosch Frank @ 2020-01-21 13:42 UTC (permalink / raw)
  To: kvm; +Cc: thuth, borntraeger, linux-s390, david, cohuck

We store the user provided psw address into restart new, so a psw
restart does not lead us through setup again.

Also we wait on smp_cpu_setup() until the cpu has finished setup
before returning. This is necessary for z/VM and LPAR where sigp is
asynchronous.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
---
 lib/s390x/smp.c  | 3 +++
 s390x/cstart64.S | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/lib/s390x/smp.c b/lib/s390x/smp.c
index 84e681d..df8ed69 100644
--- a/lib/s390x/smp.c
+++ b/lib/s390x/smp.c
@@ -204,6 +204,9 @@ int smp_cpu_setup(uint16_t addr, struct psw psw)
 
 	/* Start processing */
 	smp_cpu_restart_nolock(addr, NULL);
+	/* Wait until the cpu has finished setup and started the provided psw */
+	while (lc->restart_new_psw.addr != psw.addr)
+		mb();
 out:
 	spin_unlock(&lock);
 	return rc;
diff --git a/s390x/cstart64.S b/s390x/cstart64.S
index 86dd4c4..9af6bb3 100644
--- a/s390x/cstart64.S
+++ b/s390x/cstart64.S
@@ -159,6 +159,8 @@ smp_cpu_setup_state:
 	xgr	%r1, %r1
 	lmg     %r0, %r15, GEN_LC_SW_INT_GRS
 	lctlg   %c0, %c0, GEN_LC_SW_INT_CRS
+	/* We should only go once through cpu setup and not for every restart */
+	stg	%r14, GEN_LC_RESTART_NEW_PSW + 8
 	br	%r14
 
 pgm_int:
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [kvm-unit-tests PATCH v4 6/9] s390x: smp: Loop if secondary cpu returns into cpu setup again
  2020-01-21 13:42 [kvm-unit-tests PATCH v4 0/9] s390x: smp: Improve smp code and reset checks Janosch Frank
                   ` (4 preceding siblings ...)
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 5/9] s390x: smp: Wait for cpu setup to finish Janosch Frank
@ 2020-01-21 13:42 ` Janosch Frank
  2020-01-21 14:28   ` Cornelia Huck
                     ` (2 more replies)
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 7/9] s390x: smp: Remove unneeded cpu loops Janosch Frank
                   ` (2 subsequent siblings)
  8 siblings, 3 replies; 26+ messages in thread
From: Janosch Frank @ 2020-01-21 13:42 UTC (permalink / raw)
  To: kvm; +Cc: thuth, borntraeger, linux-s390, david, cohuck

Up to now a secondary cpu could have returned from the function it was
executing and ending up somewhere in cstart64.S. This was mostly
circumvented by an endless loop in the function that it executed.

Let's add a loop to the end of the cpu setup, so we don't have to rely
on added loops in the tests.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 s390x/cstart64.S | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/s390x/cstart64.S b/s390x/cstart64.S
index 9af6bb3..5fd8d2f 100644
--- a/s390x/cstart64.S
+++ b/s390x/cstart64.S
@@ -162,6 +162,8 @@ smp_cpu_setup_state:
 	/* We should only go once through cpu setup and not for every restart */
 	stg	%r14, GEN_LC_RESTART_NEW_PSW + 8
 	br	%r14
+	/* If the function returns, just loop here */
+0:	j	0
 
 pgm_int:
 	SAVE_REGS
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [kvm-unit-tests PATCH v4 7/9] s390x: smp: Remove unneeded cpu loops
  2020-01-21 13:42 [kvm-unit-tests PATCH v4 0/9] s390x: smp: Improve smp code and reset checks Janosch Frank
                   ` (5 preceding siblings ...)
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 6/9] s390x: smp: Loop if secondary cpu returns into cpu setup again Janosch Frank
@ 2020-01-21 13:42 ` Janosch Frank
  2020-01-21 14:30   ` Cornelia Huck
  2020-01-21 17:36   ` David Hildenbrand
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 8/9] s390x: smp: Test all CRs on initial reset Janosch Frank
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 9/9] s390x: smp: Dirty fpc before initial reset test Janosch Frank
  8 siblings, 2 replies; 26+ messages in thread
From: Janosch Frank @ 2020-01-21 13:42 UTC (permalink / raw)
  To: kvm; +Cc: thuth, borntraeger, linux-s390, david, cohuck

Now that we have a loop which is executed after we return from the
main function of a secondary cpu, we can remove the surplus loops.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 s390x/smp.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/s390x/smp.c b/s390x/smp.c
index 3e8cf3e..45f1d80 100644
--- a/s390x/smp.c
+++ b/s390x/smp.c
@@ -35,15 +35,9 @@ static void set_flag(int val)
 	mb();
 }
 
-static void cpu_loop(void)
-{
-	for (;;) {}
-}
-
 static void test_func(void)
 {
 	set_flag(1);
-	cpu_loop();
 }
 
 static void test_start(void)
@@ -241,7 +235,7 @@ int main(void)
 
 	/* Setting up the cpu to give it a stack and lowcore */
 	psw.mask = extract_psw_mask();
-	psw.addr = (unsigned long)cpu_loop;
+	psw.addr = (unsigned long)test_func;
 	smp_cpu_setup(1, psw);
 	smp_cpu_stop(1);
 
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [kvm-unit-tests PATCH v4 8/9] s390x: smp: Test all CRs on initial reset
  2020-01-21 13:42 [kvm-unit-tests PATCH v4 0/9] s390x: smp: Improve smp code and reset checks Janosch Frank
                   ` (6 preceding siblings ...)
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 7/9] s390x: smp: Remove unneeded cpu loops Janosch Frank
@ 2020-01-21 13:42 ` Janosch Frank
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 9/9] s390x: smp: Dirty fpc before initial reset test Janosch Frank
  8 siblings, 0 replies; 26+ messages in thread
From: Janosch Frank @ 2020-01-21 13:42 UTC (permalink / raw)
  To: kvm; +Cc: thuth, borntraeger, linux-s390, david, cohuck

All CRs are set to 0 and CRs 0 and 14 are set to pre-defined values,
so we also need to test 1-13 and 15 for 0.

And while we're at it, let's also set some values to cr 1, 7 and 13, so
we can actually be sure that they will be zeroed.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
---
 s390x/smp.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/s390x/smp.c b/s390x/smp.c
index 45f1d80..e36ab8c 100644
--- a/s390x/smp.c
+++ b/s390x/smp.c
@@ -176,16 +176,28 @@ static void test_emcall(void)
 	report_prefix_pop();
 }
 
+/* Used to dirty registers of cpu #1 before it is reset */
+static void test_func_initial(void)
+{
+	lctlg(1, 0x42000UL);
+	lctlg(7, 0x43000UL);
+	lctlg(13, 0x44000UL);
+	set_flag(1);
+}
+
 static void test_reset_initial(void)
 {
 	struct cpu_status *status = alloc_pages(0);
+	uint64_t nullp[12] = {};
 	struct psw psw;
 
 	psw.mask = extract_psw_mask();
-	psw.addr = (unsigned long)test_func;
+	psw.addr = (unsigned long)test_func_initial;
 
 	report_prefix_push("reset initial");
+	set_flag(0);
 	smp_cpu_start(1, psw);
+	wait_for_flag();
 
 	sigp_retry(1, SIGP_INITIAL_CPU_RESET, 0, NULL);
 	sigp(1, SIGP_STORE_STATUS_AT_ADDRESS, (uintptr_t)status, NULL);
@@ -196,6 +208,8 @@ static void test_reset_initial(void)
 	report(!status->fpc, "fpc");
 	report(!status->cputm, "cpu timer");
 	report(!status->todpr, "todpr");
+	report(!memcmp(&status->crs[1], nullp, sizeof(status->crs[1]) * 12), "cr1-13 == 0");
+	report(status->crs[15] == 0, "cr15 == 0");
 	report_prefix_pop();
 
 	report_prefix_push("initialized");
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [kvm-unit-tests PATCH v4 9/9] s390x: smp: Dirty fpc before initial reset test
  2020-01-21 13:42 [kvm-unit-tests PATCH v4 0/9] s390x: smp: Improve smp code and reset checks Janosch Frank
                   ` (7 preceding siblings ...)
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 8/9] s390x: smp: Test all CRs on initial reset Janosch Frank
@ 2020-01-21 13:42 ` Janosch Frank
  8 siblings, 0 replies; 26+ messages in thread
From: Janosch Frank @ 2020-01-21 13:42 UTC (permalink / raw)
  To: kvm; +Cc: thuth, borntraeger, linux-s390, david, cohuck

Let's dirty the fpc, before we test if the initial reset sets it to 0.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
---
 s390x/smp.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/s390x/smp.c b/s390x/smp.c
index e36ab8c..6357ac4 100644
--- a/s390x/smp.c
+++ b/s390x/smp.c
@@ -179,6 +179,7 @@ static void test_emcall(void)
 /* Used to dirty registers of cpu #1 before it is reset */
 static void test_func_initial(void)
 {
+	asm volatile("sfpc %0" :: "d" (0x11));
 	lctlg(1, 0x42000UL);
 	lctlg(7, 0x43000UL);
 	lctlg(13, 0x44000UL);
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [kvm-unit-tests PATCH v4 6/9] s390x: smp: Loop if secondary cpu returns into cpu setup again
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 6/9] s390x: smp: Loop if secondary cpu returns into cpu setup again Janosch Frank
@ 2020-01-21 14:28   ` Cornelia Huck
  2020-01-21 17:36   ` David Hildenbrand
  2020-01-23 13:32   ` David Hildenbrand
  2 siblings, 0 replies; 26+ messages in thread
From: Cornelia Huck @ 2020-01-21 14:28 UTC (permalink / raw)
  To: Janosch Frank; +Cc: kvm, thuth, borntraeger, linux-s390, david

On Tue, 21 Jan 2020 08:42:51 -0500
Janosch Frank <frankja@linux.ibm.com> wrote:

> Up to now a secondary cpu could have returned from the function it was
> executing and ending up somewhere in cstart64.S. This was mostly
> circumvented by an endless loop in the function that it executed.
> 
> Let's add a loop to the end of the cpu setup, so we don't have to rely
> on added loops in the tests.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> ---
>  s390x/cstart64.S | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/s390x/cstart64.S b/s390x/cstart64.S
> index 9af6bb3..5fd8d2f 100644
> --- a/s390x/cstart64.S
> +++ b/s390x/cstart64.S
> @@ -162,6 +162,8 @@ smp_cpu_setup_state:
>  	/* We should only go once through cpu setup and not for every restart */
>  	stg	%r14, GEN_LC_RESTART_NEW_PSW + 8
>  	br	%r14
> +	/* If the function returns, just loop here */
> +0:	j	0
>  
>  pgm_int:
>  	SAVE_REGS

Acked-by: Cornelia Huck <cohuck@redhat.com>

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [kvm-unit-tests PATCH v4 7/9] s390x: smp: Remove unneeded cpu loops
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 7/9] s390x: smp: Remove unneeded cpu loops Janosch Frank
@ 2020-01-21 14:30   ` Cornelia Huck
  2020-01-21 17:36   ` David Hildenbrand
  1 sibling, 0 replies; 26+ messages in thread
From: Cornelia Huck @ 2020-01-21 14:30 UTC (permalink / raw)
  To: Janosch Frank; +Cc: kvm, thuth, borntraeger, linux-s390, david

On Tue, 21 Jan 2020 08:42:52 -0500
Janosch Frank <frankja@linux.ibm.com> wrote:

> Now that we have a loop which is executed after we return from the
> main function of a secondary cpu, we can remove the surplus loops.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> ---
>  s390x/smp.c | 8 +-------
>  1 file changed, 1 insertion(+), 7 deletions(-)

Reviewed-by: Cornelia Huck <cohuck@redhat.com>

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [kvm-unit-tests PATCH v4 6/9] s390x: smp: Loop if secondary cpu returns into cpu setup again
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 6/9] s390x: smp: Loop if secondary cpu returns into cpu setup again Janosch Frank
  2020-01-21 14:28   ` Cornelia Huck
@ 2020-01-21 17:36   ` David Hildenbrand
  2020-01-23 13:32   ` David Hildenbrand
  2 siblings, 0 replies; 26+ messages in thread
From: David Hildenbrand @ 2020-01-21 17:36 UTC (permalink / raw)
  To: Janosch Frank, kvm; +Cc: thuth, borntraeger, linux-s390, cohuck

On 21.01.20 14:42, Janosch Frank wrote:
> Up to now a secondary cpu could have returned from the function it was
> executing and ending up somewhere in cstart64.S. This was mostly
> circumvented by an endless loop in the function that it executed.
> 
> Let's add a loop to the end of the cpu setup, so we don't have to rely
> on added loops in the tests.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> ---
>  s390x/cstart64.S | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/s390x/cstart64.S b/s390x/cstart64.S
> index 9af6bb3..5fd8d2f 100644
> --- a/s390x/cstart64.S
> +++ b/s390x/cstart64.S
> @@ -162,6 +162,8 @@ smp_cpu_setup_state:
>  	/* We should only go once through cpu setup and not for every restart */
>  	stg	%r14, GEN_LC_RESTART_NEW_PSW + 8
>  	br	%r14
> +	/* If the function returns, just loop here */
> +0:	j	0
>  
>  pgm_int:
>  	SAVE_REGS
> 

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [kvm-unit-tests PATCH v4 7/9] s390x: smp: Remove unneeded cpu loops
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 7/9] s390x: smp: Remove unneeded cpu loops Janosch Frank
  2020-01-21 14:30   ` Cornelia Huck
@ 2020-01-21 17:36   ` David Hildenbrand
  1 sibling, 0 replies; 26+ messages in thread
From: David Hildenbrand @ 2020-01-21 17:36 UTC (permalink / raw)
  To: Janosch Frank, kvm; +Cc: thuth, borntraeger, linux-s390, cohuck

On 21.01.20 14:42, Janosch Frank wrote:
> Now that we have a loop which is executed after we return from the
> main function of a secondary cpu, we can remove the surplus loops.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> ---
>  s390x/smp.c | 8 +-------
>  1 file changed, 1 insertion(+), 7 deletions(-)
> 
> diff --git a/s390x/smp.c b/s390x/smp.c
> index 3e8cf3e..45f1d80 100644
> --- a/s390x/smp.c
> +++ b/s390x/smp.c
> @@ -35,15 +35,9 @@ static void set_flag(int val)
>  	mb();
>  }
>  
> -static void cpu_loop(void)
> -{
> -	for (;;) {}
> -}
> -
>  static void test_func(void)
>  {
>  	set_flag(1);
> -	cpu_loop();
>  }
>  
>  static void test_start(void)
> @@ -241,7 +235,7 @@ int main(void)
>  
>  	/* Setting up the cpu to give it a stack and lowcore */
>  	psw.mask = extract_psw_mask();
> -	psw.addr = (unsigned long)cpu_loop;
> +	psw.addr = (unsigned long)test_func;
>  	smp_cpu_setup(1, psw);
>  	smp_cpu_stop(1);
>  
> 

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [kvm-unit-tests PATCH v4 4/9] s390x: smp: Rework cpu start and active tracking
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 4/9] s390x: smp: Rework cpu start and active tracking Janosch Frank
@ 2020-01-21 17:40   ` David Hildenbrand
  2020-01-22  8:25     ` Janosch Frank
  2020-01-23  9:14     ` [kvm-unit-tests PATCH] " Janosch Frank
  0 siblings, 2 replies; 26+ messages in thread
From: David Hildenbrand @ 2020-01-21 17:40 UTC (permalink / raw)
  To: Janosch Frank, kvm; +Cc: thuth, borntraeger, linux-s390, cohuck

On 21.01.20 14:42, Janosch Frank wrote:
> The architecture specifies that processing sigp orders may be
> asynchronous, and this is indeed the case on some hypervisors, so we
> need to wait until the cpu runs before we return from the setup/start
> function.
> 
> As there was a lot of duplicate code, a common function for cpu
> restarts has been introduced.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
> ---
>  lib/s390x/smp.c | 50 ++++++++++++++++++++++++++++---------------------
>  1 file changed, 29 insertions(+), 21 deletions(-)
> 
> diff --git a/lib/s390x/smp.c b/lib/s390x/smp.c
> index f57f420..84e681d 100644
> --- a/lib/s390x/smp.c
> +++ b/lib/s390x/smp.c
> @@ -104,35 +104,46 @@ int smp_cpu_stop_store_status(uint16_t addr)
>  	return rc;
>  }
>  
> +static int smp_cpu_restart_nolock(uint16_t addr, struct psw *psw)
> +{
> +	int rc;
> +	struct cpu *cpu = smp_cpu_from_addr(addr);
> +
> +	if (!cpu)
> +		return -1;
> +	if (psw) {
> +		cpu->lowcore->restart_new_psw.mask = psw->mask;
> +		cpu->lowcore->restart_new_psw.addr = psw->addr;
> +	}
> +	rc = sigp(addr, SIGP_RESTART, 0, NULL);
> +	if (rc)
> +		return rc;
> +	/*
> +	 * The order has been accepted, but the actual restart may not
> +	 * have been performed yet, so wait until the cpu is running.
> +	 */
> +	while (!smp_cpu_running(addr))
> +		mb();
> +	cpu->active = true;
> +	return 0;
> +}
> +

Just wondering what happened to my comment

"Should you make sure to stop the CPU before issuing the restart?
Otherwise you will get false positives if it is still running (but
hasn't processed the RESTART yet)"

?

IOW, should we have a SIGP_STOP before issuing the SIGP_RESTART?

-- 
Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [kvm-unit-tests PATCH v4 4/9] s390x: smp: Rework cpu start and active tracking
  2020-01-21 17:40   ` David Hildenbrand
@ 2020-01-22  8:25     ` Janosch Frank
  2020-01-23  9:14     ` [kvm-unit-tests PATCH] " Janosch Frank
  1 sibling, 0 replies; 26+ messages in thread
From: Janosch Frank @ 2020-01-22  8:25 UTC (permalink / raw)
  To: David Hildenbrand, kvm; +Cc: thuth, borntraeger, linux-s390, cohuck


[-- Attachment #1.1: Type: text/plain, Size: 1976 bytes --]

On 1/21/20 6:40 PM, David Hildenbrand wrote:
> On 21.01.20 14:42, Janosch Frank wrote:
>> The architecture specifies that processing sigp orders may be
>> asynchronous, and this is indeed the case on some hypervisors, so we
>> need to wait until the cpu runs before we return from the setup/start
>> function.
>>
>> As there was a lot of duplicate code, a common function for cpu
>> restarts has been introduced.
>>
>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
>> ---
>>  lib/s390x/smp.c | 50 ++++++++++++++++++++++++++++---------------------
>>  1 file changed, 29 insertions(+), 21 deletions(-)
>>
>> diff --git a/lib/s390x/smp.c b/lib/s390x/smp.c
>> index f57f420..84e681d 100644
>> --- a/lib/s390x/smp.c
>> +++ b/lib/s390x/smp.c
>> @@ -104,35 +104,46 @@ int smp_cpu_stop_store_status(uint16_t addr)
>>  	return rc;
>>  }
>>  
>> +static int smp_cpu_restart_nolock(uint16_t addr, struct psw *psw)
>> +{
>> +	int rc;
>> +	struct cpu *cpu = smp_cpu_from_addr(addr);
>> +
>> +	if (!cpu)
>> +		return -1;
>> +	if (psw) {
>> +		cpu->lowcore->restart_new_psw.mask = psw->mask;
>> +		cpu->lowcore->restart_new_psw.addr = psw->addr;
>> +	}
>> +	rc = sigp(addr, SIGP_RESTART, 0, NULL);
>> +	if (rc)
>> +		return rc;
>> +	/*
>> +	 * The order has been accepted, but the actual restart may not
>> +	 * have been performed yet, so wait until the cpu is running.
>> +	 */
>> +	while (!smp_cpu_running(addr))
>> +		mb();
>> +	cpu->active = true;
>> +	return 0;
>> +}
>> +
> 
> Just wondering what happened to my comment

It probably got lost in your other change requests :)

> 
> "Should you make sure to stop the CPU before issuing the restart?
> Otherwise you will get false positives if it is still running (but
> hasn't processed the RESTART yet)"
> 
> ?
> 
> IOW, should we have a SIGP_STOP before issuing the SIGP_RESTART?

Yes, that would be cleaner.



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [kvm-unit-tests PATCH] s390x: smp: Rework cpu start and active tracking
  2020-01-21 17:40   ` David Hildenbrand
  2020-01-22  8:25     ` Janosch Frank
@ 2020-01-23  9:14     ` Janosch Frank
  1 sibling, 0 replies; 26+ messages in thread
From: Janosch Frank @ 2020-01-23  9:14 UTC (permalink / raw)
  To: kvm; +Cc: thuth, borntraeger, linux-s390, david, cohuck

The architecture specifies that processing sigp orders may be
asynchronous, and this is indeed the case on some hypervisors, so we
need to wait until the cpu runs before we return from the setup/start
function.

As there was a lot of duplicate code, a common function for cpu
restarts has been introduced.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
---
 lib/s390x/smp.c | 56 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 21 deletions(-)

diff --git a/lib/s390x/smp.c b/lib/s390x/smp.c
index f57f420..4578003 100644
--- a/lib/s390x/smp.c
+++ b/lib/s390x/smp.c
@@ -104,35 +104,52 @@ int smp_cpu_stop_store_status(uint16_t addr)
 	return rc;
 }
 
+static int smp_cpu_restart_nolock(uint16_t addr, struct psw *psw)
+{
+	int rc;
+	struct cpu *cpu = smp_cpu_from_addr(addr);
+
+	if (!cpu)
+		return -1;
+	if (psw) {
+		cpu->lowcore->restart_new_psw.mask = psw->mask;
+		cpu->lowcore->restart_new_psw.addr = psw->addr;
+	}
+	/*
+	 * Stop the cpu, so we don't have a race between a running cpu
+	 * and the restart in the test that checks if the cpu is
+	 * running after the restart.
+	 */
+	smp_cpu_stop_nolock(addr, false);
+	rc = sigp(addr, SIGP_RESTART, 0, NULL);
+	if (rc)
+		return rc;
+	/*
+	 * The order has been accepted, but the actual restart may not
+	 * have been performed yet, so wait until the cpu is running.
+	 */
+	while (!smp_cpu_running(addr))
+		mb();
+	cpu->active = true;
+	return 0;
+}
+
 int smp_cpu_restart(uint16_t addr)
 {
-	int rc = -1;
-	struct cpu *cpu;
+	int rc;
 
 	spin_lock(&lock);
-	cpu = smp_cpu_from_addr(addr);
-	if (cpu) {
-		rc = sigp(addr, SIGP_RESTART, 0, NULL);
-		cpu->active = true;
-	}
+	rc = smp_cpu_restart_nolock(addr, NULL);
 	spin_unlock(&lock);
 	return rc;
 }
 
 int smp_cpu_start(uint16_t addr, struct psw psw)
 {
-	int rc = -1;
-	struct cpu *cpu;
-	struct lowcore *lc;
+	int rc;
 
 	spin_lock(&lock);
-	cpu = smp_cpu_from_addr(addr);
-	if (cpu) {
-		lc = cpu->lowcore;
-		lc->restart_new_psw.mask = psw.mask;
-		lc->restart_new_psw.addr = psw.addr;
-		rc = sigp(addr, SIGP_RESTART, 0, NULL);
-	}
+	rc = smp_cpu_restart_nolock(addr, &psw);
 	spin_unlock(&lock);
 	return rc;
 }
@@ -192,10 +209,7 @@ int smp_cpu_setup(uint16_t addr, struct psw psw)
 	lc->sw_int_crs[0] = 0x0000000000040000UL;
 
 	/* Start processing */
-	rc = sigp_retry(cpu->addr, SIGP_RESTART, 0, NULL);
-	if (!rc)
-		cpu->active = true;
-
+	smp_cpu_restart_nolock(addr, NULL);
 out:
 	spin_unlock(&lock);
 	return rc;
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [kvm-unit-tests PATCH v4 3/9] s390x: Add cpu id to interrupt error prints
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 3/9] s390x: Add cpu id to interrupt error prints Janosch Frank
@ 2020-01-23 10:02   ` Janosch Frank
  2020-01-23 10:03     ` [kvm-unit-tests PATCH] " Janosch Frank
  0 siblings, 1 reply; 26+ messages in thread
From: Janosch Frank @ 2020-01-23 10:02 UTC (permalink / raw)
  To: kvm; +Cc: thuth, borntraeger, linux-s390, david, cohuck


[-- Attachment #1.1: Type: text/plain, Size: 2338 bytes --]

On 1/21/20 2:42 PM, Janosch Frank wrote:
> It's good to know which cpu broke the test.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> Reviewed-by: David Hildenbrand <david@redhat.com>
> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
> ---
>  lib/s390x/interrupt.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/lib/s390x/interrupt.c b/lib/s390x/interrupt.c
> index 05f30be..773752a 100644
> --- a/lib/s390x/interrupt.c
> +++ b/lib/s390x/interrupt.c
> @@ -107,8 +107,8 @@ static void fixup_pgm_int(void)
>  void handle_pgm_int(void)
>  {
>  	if (!pgm_int_expected)
> -		report_abort("Unexpected program interrupt: %d at %#lx, ilen %d\n",
> -			     lc->pgm_int_code, lc->pgm_old_psw.addr,
> +		report_abort("Unexpected program interrupt: %d on cpu %d at %#lx, ilen %d\n",
> +			     lc->pgm_int_code, stap(), lc->pgm_old_psw.addr,
>  			     lc->pgm_int_id);
>  
>  	pgm_int_expected = false;
> @@ -119,8 +119,8 @@ void handle_ext_int(void)
>  {
>  	if (!ext_int_expected &&
>  	    lc->ext_int_code != EXT_IRQ_SERVICE_SIG) {
> -		report_abort("Unexpected external call interrupt (code %#x): at %#lx",
> -			     lc->ext_int_code, lc->ext_old_psw.addr);
> +		report_abort("Unexpected external call interrupt (code %#x): on cpu %d at %#lx",
> +			     stap(), lc->ext_int_code, lc->ext_old_psw.addr);

The arguments are in the wrong order, stap() should come after the int
code...


>  		return;
>  	}
>  
> @@ -137,18 +137,18 @@ void handle_ext_int(void)
>  
>  void handle_mcck_int(void)
>  {
> -	report_abort("Unexpected machine check interrupt: at %#lx",
> -		     lc->mcck_old_psw.addr);
> +	report_abort("Unexpected machine check interrupt: on cpu %d at %#lx",
> +		     stap(), lc->mcck_old_psw.addr);
>  }
>  
>  void handle_io_int(void)
>  {
> -	report_abort("Unexpected io interrupt: at %#lx",
> -		     lc->io_old_psw.addr);
> +	report_abort("Unexpected io interrupt: on cpu %d at %#lx",
> +		     stap(), lc->io_old_psw.addr);
>  }
>  
>  void handle_svc_int(void)
>  {
> -	report_abort("Unexpected supervisor call interrupt: at %#lx",
> -		     lc->svc_old_psw.addr);
> +	report_abort("Unexpected supervisor call interrupt: on cpu %d at %#lx",
> +		     stap(), lc->svc_old_psw.addr);
>  }
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [kvm-unit-tests PATCH] s390x: Add cpu id to interrupt error prints
  2020-01-23 10:02   ` Janosch Frank
@ 2020-01-23 10:03     ` Janosch Frank
  0 siblings, 0 replies; 26+ messages in thread
From: Janosch Frank @ 2020-01-23 10:03 UTC (permalink / raw)
  To: kvm; +Cc: thuth, borntraeger, linux-s390, david, cohuck

It's good to know which cpu broke the test.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
---

Fixed stap location in ext handler.


---
 lib/s390x/interrupt.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/lib/s390x/interrupt.c b/lib/s390x/interrupt.c
index 05f30be..3f3de7e 100644
--- a/lib/s390x/interrupt.c
+++ b/lib/s390x/interrupt.c
@@ -107,8 +107,8 @@ static void fixup_pgm_int(void)
 void handle_pgm_int(void)
 {
 	if (!pgm_int_expected)
-		report_abort("Unexpected program interrupt: %d at %#lx, ilen %d\n",
-			     lc->pgm_int_code, lc->pgm_old_psw.addr,
+		report_abort("Unexpected program interrupt: %d on cpu %d at %#lx, ilen %d\n",
+			     lc->pgm_int_code, stap(), lc->pgm_old_psw.addr,
 			     lc->pgm_int_id);
 
 	pgm_int_expected = false;
@@ -119,8 +119,8 @@ void handle_ext_int(void)
 {
 	if (!ext_int_expected &&
 	    lc->ext_int_code != EXT_IRQ_SERVICE_SIG) {
-		report_abort("Unexpected external call interrupt (code %#x): at %#lx",
-			     lc->ext_int_code, lc->ext_old_psw.addr);
+		report_abort("Unexpected external call interrupt (code %#x): on cpu %d at %#lx",
+			     lc->ext_int_code, stap(), lc->ext_old_psw.addr);
 		return;
 	}
 
@@ -137,18 +137,18 @@ void handle_ext_int(void)
 
 void handle_mcck_int(void)
 {
-	report_abort("Unexpected machine check interrupt: at %#lx",
-		     lc->mcck_old_psw.addr);
+	report_abort("Unexpected machine check interrupt: on cpu %d at %#lx",
+		     stap(), lc->mcck_old_psw.addr);
 }
 
 void handle_io_int(void)
 {
-	report_abort("Unexpected io interrupt: at %#lx",
-		     lc->io_old_psw.addr);
+	report_abort("Unexpected io interrupt: on cpu %d at %#lx",
+		     stap(), lc->io_old_psw.addr);
 }
 
 void handle_svc_int(void)
 {
-	report_abort("Unexpected supervisor call interrupt: at %#lx",
-		     lc->svc_old_psw.addr);
+	report_abort("Unexpected supervisor call interrupt: on cpu %d at %#lx",
+		     stap(), lc->svc_old_psw.addr);
 }
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [kvm-unit-tests PATCH v4 6/9] s390x: smp: Loop if secondary cpu returns into cpu setup again
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 6/9] s390x: smp: Loop if secondary cpu returns into cpu setup again Janosch Frank
  2020-01-21 14:28   ` Cornelia Huck
  2020-01-21 17:36   ` David Hildenbrand
@ 2020-01-23 13:32   ` David Hildenbrand
  2020-01-23 13:47     ` Janosch Frank
  2 siblings, 1 reply; 26+ messages in thread
From: David Hildenbrand @ 2020-01-23 13:32 UTC (permalink / raw)
  To: Janosch Frank, kvm; +Cc: thuth, borntraeger, linux-s390, cohuck

On 21.01.20 14:42, Janosch Frank wrote:
> Up to now a secondary cpu could have returned from the function it was
> executing and ending up somewhere in cstart64.S. This was mostly
> circumvented by an endless loop in the function that it executed.
> 
> Let's add a loop to the end of the cpu setup, so we don't have to rely
> on added loops in the tests.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> ---
>  s390x/cstart64.S | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/s390x/cstart64.S b/s390x/cstart64.S
> index 9af6bb3..5fd8d2f 100644
> --- a/s390x/cstart64.S
> +++ b/s390x/cstart64.S
> @@ -162,6 +162,8 @@ smp_cpu_setup_state:
>  	/* We should only go once through cpu setup and not for every restart */
>  	stg	%r14, GEN_LC_RESTART_NEW_PSW + 8
>  	br	%r14
> +	/* If the function returns, just loop here */
> +0:	j	0
>  
>  pgm_int:
>  	SAVE_REGS
> 

This patch collides with a patch I have still queued

Author: Janosch Frank <frankja@linux.ibm.com>
Date:   Wed Dec 11 06:59:22 2019 -0500

    s390x: smp: Use full PSW to bringup new cpu
    
    Up to now we ignored the psw mask and only used the psw address when
    bringing up a new cpu. For DAT we need to also load the mask, so let's
    do that.
    
    Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
    Reviewed-by: David Hildenbrand <david@redhat.com>
    Message-Id: <20191211115923.9191-2-frankja@linux.ibm.com>
    Signed-off-by: David Hildenbrand <david@redhat.com>


In that patch we use a lpswe to jump to the target code, not a br. So the
return address will no longer be stored in %14 and this code here would stop working
AFAIKS.

Shall I drop that patch for now?

-- 
Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [kvm-unit-tests PATCH v4 2/9] s390x: smp: Only use smp_cpu_setup once
  2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 2/9] s390x: smp: Only use smp_cpu_setup once Janosch Frank
@ 2020-01-23 13:45   ` David Hildenbrand
  2020-01-23 13:54     ` Janosch Frank
  0 siblings, 1 reply; 26+ messages in thread
From: David Hildenbrand @ 2020-01-23 13:45 UTC (permalink / raw)
  To: Janosch Frank, kvm; +Cc: thuth, borntraeger, linux-s390, cohuck

On 21.01.20 14:42, Janosch Frank wrote:
> Let's stop and start instead of using setup to run a function on a
> cpu.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
> Acked-by: David Hildenbrand <david@redhat.com>
> ---
>  s390x/smp.c | 21 ++++++++++++++-------
>  1 file changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/s390x/smp.c b/s390x/smp.c
> index e37eb56..3e8cf3e 100644
> --- a/s390x/smp.c
> +++ b/s390x/smp.c
> @@ -53,7 +53,7 @@ static void test_start(void)
>  	psw.addr = (unsigned long)test_func;
>  
>  	set_flag(0);
> -	smp_cpu_setup(1, psw);
> +	smp_cpu_start(1, psw);
>  	wait_for_flag();
>  	report(1, "start");
>  }
> @@ -109,6 +109,7 @@ static void test_store_status(void)
>  	report(1, "status written");
>  	free_pages(status, PAGE_SIZE * 2);
>  	report_prefix_pop();
> +	smp_cpu_stop(1);
>  
>  	report_prefix_pop();
>  }
> @@ -137,9 +138,8 @@ static void test_ecall(void)
>  
>  	report_prefix_push("ecall");
>  	set_flag(0);
> -	smp_cpu_destroy(1);
>  
> -	smp_cpu_setup(1, psw);
> +	smp_cpu_start(1, psw);
>  	wait_for_flag();
>  	set_flag(0);
>  	sigp(1, SIGP_EXTERNAL_CALL, 0, NULL);
> @@ -172,9 +172,8 @@ static void test_emcall(void)
>  
>  	report_prefix_push("emcall");
>  	set_flag(0);
> -	smp_cpu_destroy(1);
>  
> -	smp_cpu_setup(1, psw);
> +	smp_cpu_start(1, psw);
>  	wait_for_flag();
>  	set_flag(0);
>  	sigp(1, SIGP_EMERGENCY_SIGNAL, 0, NULL);
> @@ -192,7 +191,7 @@ static void test_reset_initial(void)
>  	psw.addr = (unsigned long)test_func;
>  
>  	report_prefix_push("reset initial");
> -	smp_cpu_setup(1, psw);
> +	smp_cpu_start(1, psw);
>  
>  	sigp_retry(1, SIGP_INITIAL_CPU_RESET, 0, NULL);
>  	sigp(1, SIGP_STORE_STATUS_AT_ADDRESS, (uintptr_t)status, NULL);
> @@ -223,7 +222,7 @@ static void test_reset(void)
>  	psw.addr = (unsigned long)test_func;
>  
>  	report_prefix_push("cpu reset");
> -	smp_cpu_setup(1, psw);
> +	smp_cpu_start(1, psw);
>  
>  	sigp_retry(1, SIGP_CPU_RESET, 0, NULL);
>  	report(smp_cpu_stopped(1), "cpu stopped");
> @@ -232,6 +231,7 @@ static void test_reset(void)
>  
>  int main(void)
>  {
> +	struct psw psw;
>  	report_prefix_push("smp");
>  
>  	if (smp_query_num_cpus() == 1) {
> @@ -239,6 +239,12 @@ int main(void)
>  		goto done;
>  	}
>  
> +	/* Setting up the cpu to give it a stack and lowcore */
> +	psw.mask = extract_psw_mask();
> +	psw.addr = (unsigned long)cpu_loop;
> +	smp_cpu_setup(1, psw);
> +	smp_cpu_stop(1);
> +
>  	test_start();
>  	test_stop();
>  	test_stop_store_status();
> @@ -247,6 +253,7 @@ int main(void)
>  	test_emcall();
>  	test_reset();
>  	test_reset_initial();
> +	smp_cpu_destroy(1);
>  
>  done:
>  	report_prefix_pop();
> 

With this patch, I get timeouts under TCG. Seems to loop forever.

-- 
Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [kvm-unit-tests PATCH v4 6/9] s390x: smp: Loop if secondary cpu returns into cpu setup again
  2020-01-23 13:32   ` David Hildenbrand
@ 2020-01-23 13:47     ` Janosch Frank
  0 siblings, 0 replies; 26+ messages in thread
From: Janosch Frank @ 2020-01-23 13:47 UTC (permalink / raw)
  To: David Hildenbrand, kvm; +Cc: thuth, borntraeger, linux-s390, cohuck

On 1/23/20 2:32 PM, David Hildenbrand wrote:
> On 21.01.20 14:42, Janosch Frank wrote:
>> Up to now a secondary cpu could have returned from the function it was
>> executing and ending up somewhere in cstart64.S. This was mostly
>> circumvented by an endless loop in the function that it executed.
>>
>> Let's add a loop to the end of the cpu setup, so we don't have to rely
>> on added loops in the tests.
>>
>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>> ---
>>  s390x/cstart64.S | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/s390x/cstart64.S b/s390x/cstart64.S
>> index 9af6bb3..5fd8d2f 100644
>> --- a/s390x/cstart64.S
>> +++ b/s390x/cstart64.S
>> @@ -162,6 +162,8 @@ smp_cpu_setup_state:
>>  	/* We should only go once through cpu setup and not for every restart */
>>  	stg	%r14, GEN_LC_RESTART_NEW_PSW + 8
>>  	br	%r14
>> +	/* If the function returns, just loop here */
>> +0:	j	0
>>  
>>  pgm_int:
>>  	SAVE_REGS
>>
> 
> This patch collides with a patch I have still queued
> 
> Author: Janosch Frank <frankja@linux.ibm.com>
> Date:   Wed Dec 11 06:59:22 2019 -0500
> 
>     s390x: smp: Use full PSW to bringup new cpu
>     
>     Up to now we ignored the psw mask and only used the psw address when
>     bringing up a new cpu. For DAT we need to also load the mask, so let's
>     do that.
>     
>     Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>     Reviewed-by: David Hildenbrand <david@redhat.com>
>     Message-Id: <20191211115923.9191-2-frankja@linux.ibm.com>
>     Signed-off-by: David Hildenbrand <david@redhat.com>
> 
> 
> In that patch we use a lpswe to jump to the target code, not a br. So the
> return address will no longer be stored in %14 and this code here would stop working
> AFAIKS.
> 
> Shall I drop that patch for now?

Please drop "s390x: smp: Use full PSW to bringup new cpu"
I will send out a fixed version of that patch soonish. It will load a
label for lpswe into r14 before doing the lpswe.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [kvm-unit-tests PATCH v4 2/9] s390x: smp: Only use smp_cpu_setup once
  2020-01-23 13:45   ` David Hildenbrand
@ 2020-01-23 13:54     ` Janosch Frank
  2020-01-23 13:56       ` David Hildenbrand
  0 siblings, 1 reply; 26+ messages in thread
From: Janosch Frank @ 2020-01-23 13:54 UTC (permalink / raw)
  To: David Hildenbrand, kvm; +Cc: thuth, borntraeger, linux-s390, cohuck


[-- Attachment #1.1: Type: text/plain, Size: 3136 bytes --]

On 1/23/20 2:45 PM, David Hildenbrand wrote:
> On 21.01.20 14:42, Janosch Frank wrote:
>> Let's stop and start instead of using setup to run a function on a
>> cpu.
>>
>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>> Reviewed-by: Thomas Huth <thuth@redhat.com>
>> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
>> Acked-by: David Hildenbrand <david@redhat.com>
>> ---
>>  s390x/smp.c | 21 ++++++++++++++-------
>>  1 file changed, 14 insertions(+), 7 deletions(-)
>>
>> diff --git a/s390x/smp.c b/s390x/smp.c
>> index e37eb56..3e8cf3e 100644
>> --- a/s390x/smp.c
>> +++ b/s390x/smp.c
>> @@ -53,7 +53,7 @@ static void test_start(void)
>>  	psw.addr = (unsigned long)test_func;
>>  
>>  	set_flag(0);
>> -	smp_cpu_setup(1, psw);
>> +	smp_cpu_start(1, psw);
>>  	wait_for_flag();
>>  	report(1, "start");
>>  }
>> @@ -109,6 +109,7 @@ static void test_store_status(void)
>>  	report(1, "status written");
>>  	free_pages(status, PAGE_SIZE * 2);
>>  	report_prefix_pop();
>> +	smp_cpu_stop(1);
>>  
>>  	report_prefix_pop();
>>  }
>> @@ -137,9 +138,8 @@ static void test_ecall(void)
>>  
>>  	report_prefix_push("ecall");
>>  	set_flag(0);
>> -	smp_cpu_destroy(1);
>>  
>> -	smp_cpu_setup(1, psw);
>> +	smp_cpu_start(1, psw);
>>  	wait_for_flag();
>>  	set_flag(0);
>>  	sigp(1, SIGP_EXTERNAL_CALL, 0, NULL);
>> @@ -172,9 +172,8 @@ static void test_emcall(void)
>>  
>>  	report_prefix_push("emcall");
>>  	set_flag(0);
>> -	smp_cpu_destroy(1);
>>  
>> -	smp_cpu_setup(1, psw);
>> +	smp_cpu_start(1, psw);
>>  	wait_for_flag();
>>  	set_flag(0);
>>  	sigp(1, SIGP_EMERGENCY_SIGNAL, 0, NULL);
>> @@ -192,7 +191,7 @@ static void test_reset_initial(void)
>>  	psw.addr = (unsigned long)test_func;
>>  
>>  	report_prefix_push("reset initial");
>> -	smp_cpu_setup(1, psw);
>> +	smp_cpu_start(1, psw);
>>  
>>  	sigp_retry(1, SIGP_INITIAL_CPU_RESET, 0, NULL);
>>  	sigp(1, SIGP_STORE_STATUS_AT_ADDRESS, (uintptr_t)status, NULL);
>> @@ -223,7 +222,7 @@ static void test_reset(void)
>>  	psw.addr = (unsigned long)test_func;
>>  
>>  	report_prefix_push("cpu reset");
>> -	smp_cpu_setup(1, psw);
>> +	smp_cpu_start(1, psw);
>>  
>>  	sigp_retry(1, SIGP_CPU_RESET, 0, NULL);
>>  	report(smp_cpu_stopped(1), "cpu stopped");
>> @@ -232,6 +231,7 @@ static void test_reset(void)
>>  
>>  int main(void)
>>  {
>> +	struct psw psw;
>>  	report_prefix_push("smp");
>>  
>>  	if (smp_query_num_cpus() == 1) {
>> @@ -239,6 +239,12 @@ int main(void)
>>  		goto done;
>>  	}
>>  
>> +	/* Setting up the cpu to give it a stack and lowcore */
>> +	psw.mask = extract_psw_mask();
>> +	psw.addr = (unsigned long)cpu_loop;
>> +	smp_cpu_setup(1, psw);
>> +	smp_cpu_stop(1);
>> +
>>  	test_start();
>>  	test_stop();
>>  	test_stop_store_status();
>> @@ -247,6 +253,7 @@ int main(void)
>>  	test_emcall();
>>  	test_reset();
>>  	test_reset_initial();
>> +	smp_cpu_destroy(1);
>>  
>>  done:
>>  	report_prefix_pop();
>>
> 
> With this patch, I get timeouts under TCG. Seems to loop forever.
> 
The branch works on lpar and kvm without a problem.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [kvm-unit-tests PATCH v4 2/9] s390x: smp: Only use smp_cpu_setup once
  2020-01-23 13:54     ` Janosch Frank
@ 2020-01-23 13:56       ` David Hildenbrand
  2020-01-24  8:28         ` David Hildenbrand
  0 siblings, 1 reply; 26+ messages in thread
From: David Hildenbrand @ 2020-01-23 13:56 UTC (permalink / raw)
  To: Janosch Frank, kvm; +Cc: thuth, borntraeger, linux-s390, cohuck

On 23.01.20 14:54, Janosch Frank wrote:
> On 1/23/20 2:45 PM, David Hildenbrand wrote:
>> On 21.01.20 14:42, Janosch Frank wrote:
>>> Let's stop and start instead of using setup to run a function on a
>>> cpu.
>>>
>>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>>> Reviewed-by: Thomas Huth <thuth@redhat.com>
>>> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
>>> Acked-by: David Hildenbrand <david@redhat.com>
>>> ---
>>>  s390x/smp.c | 21 ++++++++++++++-------
>>>  1 file changed, 14 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/s390x/smp.c b/s390x/smp.c
>>> index e37eb56..3e8cf3e 100644
>>> --- a/s390x/smp.c
>>> +++ b/s390x/smp.c
>>> @@ -53,7 +53,7 @@ static void test_start(void)
>>>  	psw.addr = (unsigned long)test_func;
>>>  
>>>  	set_flag(0);
>>> -	smp_cpu_setup(1, psw);
>>> +	smp_cpu_start(1, psw);
>>>  	wait_for_flag();
>>>  	report(1, "start");
>>>  }
>>> @@ -109,6 +109,7 @@ static void test_store_status(void)
>>>  	report(1, "status written");
>>>  	free_pages(status, PAGE_SIZE * 2);
>>>  	report_prefix_pop();
>>> +	smp_cpu_stop(1);
>>>  
>>>  	report_prefix_pop();
>>>  }
>>> @@ -137,9 +138,8 @@ static void test_ecall(void)
>>>  
>>>  	report_prefix_push("ecall");
>>>  	set_flag(0);
>>> -	smp_cpu_destroy(1);
>>>  
>>> -	smp_cpu_setup(1, psw);
>>> +	smp_cpu_start(1, psw);
>>>  	wait_for_flag();
>>>  	set_flag(0);
>>>  	sigp(1, SIGP_EXTERNAL_CALL, 0, NULL);
>>> @@ -172,9 +172,8 @@ static void test_emcall(void)
>>>  
>>>  	report_prefix_push("emcall");
>>>  	set_flag(0);
>>> -	smp_cpu_destroy(1);
>>>  
>>> -	smp_cpu_setup(1, psw);
>>> +	smp_cpu_start(1, psw);
>>>  	wait_for_flag();
>>>  	set_flag(0);
>>>  	sigp(1, SIGP_EMERGENCY_SIGNAL, 0, NULL);
>>> @@ -192,7 +191,7 @@ static void test_reset_initial(void)
>>>  	psw.addr = (unsigned long)test_func;
>>>  
>>>  	report_prefix_push("reset initial");
>>> -	smp_cpu_setup(1, psw);
>>> +	smp_cpu_start(1, psw);
>>>  
>>>  	sigp_retry(1, SIGP_INITIAL_CPU_RESET, 0, NULL);
>>>  	sigp(1, SIGP_STORE_STATUS_AT_ADDRESS, (uintptr_t)status, NULL);
>>> @@ -223,7 +222,7 @@ static void test_reset(void)
>>>  	psw.addr = (unsigned long)test_func;
>>>  
>>>  	report_prefix_push("cpu reset");
>>> -	smp_cpu_setup(1, psw);
>>> +	smp_cpu_start(1, psw);
>>>  
>>>  	sigp_retry(1, SIGP_CPU_RESET, 0, NULL);
>>>  	report(smp_cpu_stopped(1), "cpu stopped");
>>> @@ -232,6 +231,7 @@ static void test_reset(void)
>>>  
>>>  int main(void)
>>>  {
>>> +	struct psw psw;
>>>  	report_prefix_push("smp");
>>>  
>>>  	if (smp_query_num_cpus() == 1) {
>>> @@ -239,6 +239,12 @@ int main(void)
>>>  		goto done;
>>>  	}
>>>  
>>> +	/* Setting up the cpu to give it a stack and lowcore */
>>> +	psw.mask = extract_psw_mask();
>>> +	psw.addr = (unsigned long)cpu_loop;
>>> +	smp_cpu_setup(1, psw);
>>> +	smp_cpu_stop(1);
>>> +
>>>  	test_start();
>>>  	test_stop();
>>>  	test_stop_store_status();
>>> @@ -247,6 +253,7 @@ int main(void)
>>>  	test_emcall();
>>>  	test_reset();
>>>  	test_reset_initial();
>>> +	smp_cpu_destroy(1);
>>>  
>>>  done:
>>>  	report_prefix_pop();
>>>
>>
>> With this patch, I get timeouts under TCG. Seems to loop forever.
>>
> The branch works on lpar and kvm without a problem.

Which could mean that either TCG is broken or your test is broken (e.g.,
a race condition that does not trigger under LPAR because it's faster,
or some undocumented/not guaranteed behavior).

-- 
Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [kvm-unit-tests PATCH v4 2/9] s390x: smp: Only use smp_cpu_setup once
  2020-01-23 13:56       ` David Hildenbrand
@ 2020-01-24  8:28         ` David Hildenbrand
  2020-01-24  8:38           ` David Hildenbrand
  0 siblings, 1 reply; 26+ messages in thread
From: David Hildenbrand @ 2020-01-24  8:28 UTC (permalink / raw)
  To: Janosch Frank, kvm; +Cc: thuth, borntraeger, linux-s390, cohuck

On 23.01.20 14:56, David Hildenbrand wrote:
> On 23.01.20 14:54, Janosch Frank wrote:
>> On 1/23/20 2:45 PM, David Hildenbrand wrote:
>>> On 21.01.20 14:42, Janosch Frank wrote:
>>>> Let's stop and start instead of using setup to run a function on a
>>>> cpu.
>>>>
>>>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>>>> Reviewed-by: Thomas Huth <thuth@redhat.com>
>>>> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
>>>> Acked-by: David Hildenbrand <david@redhat.com>
>>>> ---
>>>>  s390x/smp.c | 21 ++++++++++++++-------
>>>>  1 file changed, 14 insertions(+), 7 deletions(-)
>>>>
>>>> diff --git a/s390x/smp.c b/s390x/smp.c
>>>> index e37eb56..3e8cf3e 100644
>>>> --- a/s390x/smp.c
>>>> +++ b/s390x/smp.c
>>>> @@ -53,7 +53,7 @@ static void test_start(void)
>>>>  	psw.addr = (unsigned long)test_func;
>>>>  
>>>>  	set_flag(0);
>>>> -	smp_cpu_setup(1, psw);
>>>> +	smp_cpu_start(1, psw);
>>>>  	wait_for_flag();
>>>>  	report(1, "start");
>>>>  }
>>>> @@ -109,6 +109,7 @@ static void test_store_status(void)
>>>>  	report(1, "status written");
>>>>  	free_pages(status, PAGE_SIZE * 2);
>>>>  	report_prefix_pop();
>>>> +	smp_cpu_stop(1);
>>>>  
>>>>  	report_prefix_pop();
>>>>  }
>>>> @@ -137,9 +138,8 @@ static void test_ecall(void)
>>>>  
>>>>  	report_prefix_push("ecall");
>>>>  	set_flag(0);
>>>> -	smp_cpu_destroy(1);
>>>>  
>>>> -	smp_cpu_setup(1, psw);
>>>> +	smp_cpu_start(1, psw);
>>>>  	wait_for_flag();
>>>>  	set_flag(0);
>>>>  	sigp(1, SIGP_EXTERNAL_CALL, 0, NULL);
>>>> @@ -172,9 +172,8 @@ static void test_emcall(void)
>>>>  
>>>>  	report_prefix_push("emcall");
>>>>  	set_flag(0);
>>>> -	smp_cpu_destroy(1);
>>>>  
>>>> -	smp_cpu_setup(1, psw);
>>>> +	smp_cpu_start(1, psw);
>>>>  	wait_for_flag();
>>>>  	set_flag(0);
>>>>  	sigp(1, SIGP_EMERGENCY_SIGNAL, 0, NULL);
>>>> @@ -192,7 +191,7 @@ static void test_reset_initial(void)
>>>>  	psw.addr = (unsigned long)test_func;
>>>>  
>>>>  	report_prefix_push("reset initial");
>>>> -	smp_cpu_setup(1, psw);
>>>> +	smp_cpu_start(1, psw);
>>>>  
>>>>  	sigp_retry(1, SIGP_INITIAL_CPU_RESET, 0, NULL);
>>>>  	sigp(1, SIGP_STORE_STATUS_AT_ADDRESS, (uintptr_t)status, NULL);
>>>> @@ -223,7 +222,7 @@ static void test_reset(void)
>>>>  	psw.addr = (unsigned long)test_func;
>>>>  
>>>>  	report_prefix_push("cpu reset");
>>>> -	smp_cpu_setup(1, psw);
>>>> +	smp_cpu_start(1, psw);
>>>>  
>>>>  	sigp_retry(1, SIGP_CPU_RESET, 0, NULL);
>>>>  	report(smp_cpu_stopped(1), "cpu stopped");
>>>> @@ -232,6 +231,7 @@ static void test_reset(void)
>>>>  
>>>>  int main(void)
>>>>  {
>>>> +	struct psw psw;
>>>>  	report_prefix_push("smp");
>>>>  
>>>>  	if (smp_query_num_cpus() == 1) {
>>>> @@ -239,6 +239,12 @@ int main(void)
>>>>  		goto done;
>>>>  	}
>>>>  
>>>> +	/* Setting up the cpu to give it a stack and lowcore */
>>>> +	psw.mask = extract_psw_mask();
>>>> +	psw.addr = (unsigned long)cpu_loop;
>>>> +	smp_cpu_setup(1, psw);
>>>> +	smp_cpu_stop(1);
>>>> +
>>>>  	test_start();
>>>>  	test_stop();
>>>>  	test_stop_store_status();
>>>> @@ -247,6 +253,7 @@ int main(void)
>>>>  	test_emcall();
>>>>  	test_reset();
>>>>  	test_reset_initial();
>>>> +	smp_cpu_destroy(1);
>>>>  
>>>>  done:
>>>>  	report_prefix_pop();
>>>>
>>>
>>> With this patch, I get timeouts under TCG. Seems to loop forever.
>>>
>> The branch works on lpar and kvm without a problem.
> 
> Which could mean that either TCG is broken or your test is broken (e.g.,
> a race condition that does not trigger under LPAR because it's faster,
> or some undocumented/not guaranteed behavior).
> 

So, the test works every now and then under TCG.

It seems to work very reliably with "-smp 2"

With smp 8, it sometimes works, sometimes not.

t480s: ~/git/kvm-unit-tests (kein Branch, Rebase von s390x-prep) $
./s390x-run s390x/smp.elf -smp 8
/home/dhildenb/git/qemu/s390x-softmmu/qemu-system-s390x -nodefaults
-nographic -machine s390-ccw-virtio,accel=tcg -chardev stdio,id=con0
-device sclpconsole,chardev=con0 -kernel s390x/smp.elf -smp 8 # -initrd
/tmp/tmp.UL9ZaqoKBW
SMP: Initializing, found 8 cpus
PASS: smp: start
PASS: smp: stop
PASS: smp: stop store status: prefix
PASS: smp: stop store status: stack
PASS: smp: store status at address: running: incorrect state
PASS: smp: store status at address: running: status not written
PASS: smp: store status at address: stopped: status written
PASS: smp: ecall: ecall
PASS: smp: emcall: ecall
PASS: smp: cpu reset: cpu stopped
PASS: smp: reset initial: clear: psw
PASS: smp: reset initial: clear: prefix
PASS: smp: reset initial: clear: fpc
PASS: smp: reset initial: clear: cpu timer
PASS: smp: reset initial: clear: todpr
PASS: smp: reset initial: initialized: cr0 == 0xE0
PASS: smp: reset initial: initialized: cr14 == 0xC2000000
PASS: smp: reset initial: cpu stopped
SUMMARY: 18 tests

EXIT: STATUS=1

t480s: ~/git/kvm-unit-tests (kein Branch, Rebase von s390x-prep) $
./s390x-run s390x/smp.elf -smp 8
/home/dhildenb/git/qemu/s390x-softmmu/qemu-system-s390x -nodefaults
-nographic -machine s390-ccw-virtio,accel=tcg -chardev stdio,id=con0
-device sclpconsole,chardev=con0 -kernel s390x/smp.elf -smp 8 # -initrd
/tmp/tmp.csifrEDgnC
SMP: Initializing, found 8 cpus
PASS: smp: start
PASS: smp: stop
PASS: smp: stop store status: prefix
FAIL: smp: stop store status: stack
PASS: smp: store status at address: running: incorrect state
PASS: smp: store status at address: running: status not written
PASS: smp: store status at address: stopped: status written
[... hang]


Note that there is a previous failure for "smp: stop store status:
stack" whenever the test will hang later.


-- 
Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [kvm-unit-tests PATCH v4 2/9] s390x: smp: Only use smp_cpu_setup once
  2020-01-24  8:28         ` David Hildenbrand
@ 2020-01-24  8:38           ` David Hildenbrand
  0 siblings, 0 replies; 26+ messages in thread
From: David Hildenbrand @ 2020-01-24  8:38 UTC (permalink / raw)
  To: Janosch Frank, kvm; +Cc: thuth, borntraeger, linux-s390, cohuck

On 24.01.20 09:28, David Hildenbrand wrote:
> On 23.01.20 14:56, David Hildenbrand wrote:
>> On 23.01.20 14:54, Janosch Frank wrote:
>>> On 1/23/20 2:45 PM, David Hildenbrand wrote:
>>>> On 21.01.20 14:42, Janosch Frank wrote:
>>>>> Let's stop and start instead of using setup to run a function on a
>>>>> cpu.
>>>>>
>>>>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>>>>> Reviewed-by: Thomas Huth <thuth@redhat.com>
>>>>> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
>>>>> Acked-by: David Hildenbrand <david@redhat.com>
>>>>> ---
>>>>>  s390x/smp.c | 21 ++++++++++++++-------
>>>>>  1 file changed, 14 insertions(+), 7 deletions(-)
>>>>>
>>>>> diff --git a/s390x/smp.c b/s390x/smp.c
>>>>> index e37eb56..3e8cf3e 100644
>>>>> --- a/s390x/smp.c
>>>>> +++ b/s390x/smp.c
>>>>> @@ -53,7 +53,7 @@ static void test_start(void)
>>>>>  	psw.addr = (unsigned long)test_func;
>>>>>  
>>>>>  	set_flag(0);
>>>>> -	smp_cpu_setup(1, psw);
>>>>> +	smp_cpu_start(1, psw);
>>>>>  	wait_for_flag();
>>>>>  	report(1, "start");
>>>>>  }
>>>>> @@ -109,6 +109,7 @@ static void test_store_status(void)
>>>>>  	report(1, "status written");
>>>>>  	free_pages(status, PAGE_SIZE * 2);
>>>>>  	report_prefix_pop();
>>>>> +	smp_cpu_stop(1);
>>>>>  
>>>>>  	report_prefix_pop();
>>>>>  }
>>>>> @@ -137,9 +138,8 @@ static void test_ecall(void)
>>>>>  
>>>>>  	report_prefix_push("ecall");
>>>>>  	set_flag(0);
>>>>> -	smp_cpu_destroy(1);
>>>>>  
>>>>> -	smp_cpu_setup(1, psw);
>>>>> +	smp_cpu_start(1, psw);
>>>>>  	wait_for_flag();
>>>>>  	set_flag(0);
>>>>>  	sigp(1, SIGP_EXTERNAL_CALL, 0, NULL);
>>>>> @@ -172,9 +172,8 @@ static void test_emcall(void)
>>>>>  
>>>>>  	report_prefix_push("emcall");
>>>>>  	set_flag(0);
>>>>> -	smp_cpu_destroy(1);
>>>>>  
>>>>> -	smp_cpu_setup(1, psw);
>>>>> +	smp_cpu_start(1, psw);
>>>>>  	wait_for_flag();
>>>>>  	set_flag(0);
>>>>>  	sigp(1, SIGP_EMERGENCY_SIGNAL, 0, NULL);
>>>>> @@ -192,7 +191,7 @@ static void test_reset_initial(void)
>>>>>  	psw.addr = (unsigned long)test_func;
>>>>>  
>>>>>  	report_prefix_push("reset initial");
>>>>> -	smp_cpu_setup(1, psw);
>>>>> +	smp_cpu_start(1, psw);
>>>>>  
>>>>>  	sigp_retry(1, SIGP_INITIAL_CPU_RESET, 0, NULL);
>>>>>  	sigp(1, SIGP_STORE_STATUS_AT_ADDRESS, (uintptr_t)status, NULL);
>>>>> @@ -223,7 +222,7 @@ static void test_reset(void)
>>>>>  	psw.addr = (unsigned long)test_func;
>>>>>  
>>>>>  	report_prefix_push("cpu reset");
>>>>> -	smp_cpu_setup(1, psw);
>>>>> +	smp_cpu_start(1, psw);
>>>>>  
>>>>>  	sigp_retry(1, SIGP_CPU_RESET, 0, NULL);
>>>>>  	report(smp_cpu_stopped(1), "cpu stopped");
>>>>> @@ -232,6 +231,7 @@ static void test_reset(void)
>>>>>  
>>>>>  int main(void)
>>>>>  {
>>>>> +	struct psw psw;
>>>>>  	report_prefix_push("smp");
>>>>>  
>>>>>  	if (smp_query_num_cpus() == 1) {
>>>>> @@ -239,6 +239,12 @@ int main(void)
>>>>>  		goto done;
>>>>>  	}
>>>>>  
>>>>> +	/* Setting up the cpu to give it a stack and lowcore */
>>>>> +	psw.mask = extract_psw_mask();
>>>>> +	psw.addr = (unsigned long)cpu_loop;
>>>>> +	smp_cpu_setup(1, psw);
>>>>> +	smp_cpu_stop(1);
>>>>> +
>>>>>  	test_start();
>>>>>  	test_stop();
>>>>>  	test_stop_store_status();
>>>>> @@ -247,6 +253,7 @@ int main(void)
>>>>>  	test_emcall();
>>>>>  	test_reset();
>>>>>  	test_reset_initial();
>>>>> +	smp_cpu_destroy(1);
>>>>>  
>>>>>  done:
>>>>>  	report_prefix_pop();
>>>>>
>>>>
>>>> With this patch, I get timeouts under TCG. Seems to loop forever.
>>>>
>>> The branch works on lpar and kvm without a problem.
>>
>> Which could mean that either TCG is broken or your test is broken (e.g.,
>> a race condition that does not trigger under LPAR because it's faster,
>> or some undocumented/not guaranteed behavior).
>>
> 
> So, the test works every now and then under TCG.
> 
> It seems to work very reliably with "-smp 2"
> 
> With smp 8, it sometimes works, sometimes not.
> 
> t480s: ~/git/kvm-unit-tests (kein Branch, Rebase von s390x-prep) $
> ./s390x-run s390x/smp.elf -smp 8
> /home/dhildenb/git/qemu/s390x-softmmu/qemu-system-s390x -nodefaults
> -nographic -machine s390-ccw-virtio,accel=tcg -chardev stdio,id=con0
> -device sclpconsole,chardev=con0 -kernel s390x/smp.elf -smp 8 # -initrd
> /tmp/tmp.UL9ZaqoKBW
> SMP: Initializing, found 8 cpus
> PASS: smp: start
> PASS: smp: stop
> PASS: smp: stop store status: prefix
> PASS: smp: stop store status: stack
> PASS: smp: store status at address: running: incorrect state
> PASS: smp: store status at address: running: status not written
> PASS: smp: store status at address: stopped: status written
> PASS: smp: ecall: ecall
> PASS: smp: emcall: ecall
> PASS: smp: cpu reset: cpu stopped
> PASS: smp: reset initial: clear: psw
> PASS: smp: reset initial: clear: prefix
> PASS: smp: reset initial: clear: fpc
> PASS: smp: reset initial: clear: cpu timer
> PASS: smp: reset initial: clear: todpr
> PASS: smp: reset initial: initialized: cr0 == 0xE0
> PASS: smp: reset initial: initialized: cr14 == 0xC2000000
> PASS: smp: reset initial: cpu stopped
> SUMMARY: 18 tests
> 
> EXIT: STATUS=1
> 
> t480s: ~/git/kvm-unit-tests (kein Branch, Rebase von s390x-prep) $
> ./s390x-run s390x/smp.elf -smp 8
> /home/dhildenb/git/qemu/s390x-softmmu/qemu-system-s390x -nodefaults
> -nographic -machine s390-ccw-virtio,accel=tcg -chardev stdio,id=con0
> -device sclpconsole,chardev=con0 -kernel s390x/smp.elf -smp 8 # -initrd
> /tmp/tmp.csifrEDgnC
> SMP: Initializing, found 8 cpus
> PASS: smp: start
> PASS: smp: stop
> PASS: smp: stop store status: prefix
> FAIL: smp: stop store status: stack
> PASS: smp: store status at address: running: incorrect state
> PASS: smp: store status at address: running: status not written
> PASS: smp: store status at address: stopped: status written
> [... hang]
> 
> 
> Note that there is a previous failure for "smp: stop store status:
> stack" whenever the test will hang later.
> 
> 

In smp_cpu_stop_nolock(), when you do a SIGP_STOP_AND_STORE_STATUS, you
wait until the target CPU is stopped.

This does, however, not guarantee that the state has already been stored
- especially not if the target CPU is already stopped.

Stop and Store Status
The addressed CPU performs the stop function, fol-
lowed by the store-status operation (see “Store Sta-
tus” on page 4-82). The CPU does not necessarily
complete the operation, or even enter the stopped
state, during the execution of SIGNAL PROCES-
SOR ..."

So there is a race in your code. I do wonder how you can test if the
order on the target CPU has been executed, without issuing another SIGP
operation (e.g., restart) or by testing if the content to be stored was
all changed ...

-- 
Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2020-01-24  8:38 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-21 13:42 [kvm-unit-tests PATCH v4 0/9] s390x: smp: Improve smp code and reset checks Janosch Frank
2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 1/9] s390x: smp: Cleanup smp.c Janosch Frank
2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 2/9] s390x: smp: Only use smp_cpu_setup once Janosch Frank
2020-01-23 13:45   ` David Hildenbrand
2020-01-23 13:54     ` Janosch Frank
2020-01-23 13:56       ` David Hildenbrand
2020-01-24  8:28         ` David Hildenbrand
2020-01-24  8:38           ` David Hildenbrand
2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 3/9] s390x: Add cpu id to interrupt error prints Janosch Frank
2020-01-23 10:02   ` Janosch Frank
2020-01-23 10:03     ` [kvm-unit-tests PATCH] " Janosch Frank
2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 4/9] s390x: smp: Rework cpu start and active tracking Janosch Frank
2020-01-21 17:40   ` David Hildenbrand
2020-01-22  8:25     ` Janosch Frank
2020-01-23  9:14     ` [kvm-unit-tests PATCH] " Janosch Frank
2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 5/9] s390x: smp: Wait for cpu setup to finish Janosch Frank
2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 6/9] s390x: smp: Loop if secondary cpu returns into cpu setup again Janosch Frank
2020-01-21 14:28   ` Cornelia Huck
2020-01-21 17:36   ` David Hildenbrand
2020-01-23 13:32   ` David Hildenbrand
2020-01-23 13:47     ` Janosch Frank
2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 7/9] s390x: smp: Remove unneeded cpu loops Janosch Frank
2020-01-21 14:30   ` Cornelia Huck
2020-01-21 17:36   ` David Hildenbrand
2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 8/9] s390x: smp: Test all CRs on initial reset Janosch Frank
2020-01-21 13:42 ` [kvm-unit-tests PATCH v4 9/9] s390x: smp: Dirty fpc before initial reset test Janosch Frank

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.