Skip to contentSkip to conversation

s390x: try multiple times to stop CPU

PATCH In review David Hildenbrand 1 participant 2 messages Sep 20, 2017 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390x: try multiple times to stop CPU

In theory, we could get a CC == 3, meaning the SIGP facility is busy and we have to retry. So let's retry quite a number of times and at least print a message about the problem before going into a safe loop.

---

While working on TCG SMP support, I had a BUG whereby the CPU would not directly stop but cotinue running for some instructions. This should no properly detect such scenarios where the CPU keeps running after the SIGP without indicating CC=3.

 lib/s390x/io.c | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)
lib/s390x/io.c +27 -4
index 12f9d26..c48d6b1 100644
@@ -14,6 +14,7 @@
 #include <argv.h>
 #include <asm/spinlock.h>
 #include <asm/facility.h>
+#include <asm/barrier.h>
 #include "sclp.h"
 
 extern char ipl_args[];
@@ -28,14 +29,36 @@ void puts(const char *s)
 	spin_unlock(&lock);
 }
 
-static void sigp_stop()
+static int sigp_stop(void)
 {
 	register unsigned long status asm ("1") = 0;
 	register unsigned long cpu asm ("2") = 0;
+	int cc;
 
 	asm volatile(
-		"	sigp %0,%1,0(%2)\n"
-		: "+d" (status)  : "d" (cpu), "d" (5) : "cc");
+		"	sigp %1,%2,0(%3)\n"
+		"	ipm %0\n"
+		"	srl %0,28\n"
+		: "=d" (cc), "+d" (status) : "d" (cpu), "d" (5) : "cc");
+	return cc;
+}
+
+static void machine_stop(void)
+{
+	int retry = 999999;
+	int cc;
+
+	/* for now we only have 1 CPU to stop */
+	do {
+		cc = sigp_stop();
+		retry--;
+	} while (cc == 3 && retry);
+
+	printf("\nERROR: Could not stop CPU(s)\n");
+	printf("\nEXIT: STATUS=-1\n");
+	while (true) {
+		mb();
+	}
 }
 
 void setup()
@@ -48,5 +71,5 @@ void setup()
 void exit(int code)
 {
 	printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1);
-	sigp_stop();
+	machine_stop();
 }
Signature · 1 line
2.13.5
#1 lore raw

lib/s390x/io.c void puts(const char *s) · line 55

Quoted 11 lines
lib/s390x/io.c +10 -0
+static void machine_stop(void)
+{
+	int retry = 999999;
+	int cc;
+
+	/* for now we only have 1 CPU to stop */
+	do {
+		cc = sigp_stop();
+		retry--;
+	} while (cc == 3 && retry);

This should be 2 instead of 3 ... but I am currently working on SIGP tests and plan to introduce defines for all these, so this patch can wait.

Signature · 3 lines
Thanks,

David