Skip to contentSkip to conversation

Fixing infinite loop on SCLP READ SCP INFO error

PATCH Superseded Pierre Morel 3 participants 6 messages May 30, 2023 – Jun 1, 2023

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover Fixing infinite loop on SCLP READ SCP INFO error

Aborting on SCLP READ SCP INFO error leads to a deadloop.

The loop is:
abort() -> exit() -> smp_teardown() -> smp_query_num_cpus() -> sclp_get_cpu_num() -> assert() -> abort()

Since smp_setup() is done after sclp_read_info() inside setup() this loop only happens when only the start processor is running. Let sclp_get_cpu_num() return 1 in this case.

Also implement the SCLP_RC_INSUFFICIENT_SCCB_LENGTH handling and repeat the sclp command.

Pierre Morel (2):
s390x: sclp: consider monoprocessor on read_info error
s390x: sclp: Implement SCLP_RC_INSUFFICIENT_SCCB_LENGTH

 lib/s390x/sclp.c | 69 +++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 59 insertions(+), 10 deletions(-)
Signature · 15 lines
2.31.1

since v3:

- added initial patch and merge with comments
  Sorry for the noise.

since v2:

- use tabs in first patch
  (Nico)

- Added comments

- Added SCLP_RC_INSUFFICIENT_SCCB_LENGTH handling
#1 lore raw

PATCH v4 1/2 s390x: sclp: consider monoprocessor on read_info error

A test would hang if an abort happens before SCLP Read SCP Information has completed.

---
 lib/s390x/sclp.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
lib/s390x/sclp.c +9 -2
index acdc8a9..34a31da 100644
@@ -119,8 +119,15 @@ void sclp_read_info(void)
 
 int sclp_get_cpu_num(void)
 {
-	assert(read_info);
-	return read_info->entries_cpu;
+	if (read_info)
+		return read_info->entries_cpu;
+	/*
+	 * If we fail here and read_info has not being set,
+	 * it means we failed early and we try to abort the test.
+	 * We need to return at least one CPU, and obviously we have
+	 * at least one, for the smp_teardown to correctly work.
+	 */
+	return 1;
 }
 
 CPUEntry *sclp_get_cpu_entries(void)
Signature · 1 line
2.31.1
#3 lore raw

PATCH v4 2/2 s390x: sclp: Implement SCLP_RC_INSUFFICIENT_SCCB_LENGTH

In reply to Pierre Morel

If SCLP_CMDW_READ_SCP_INFO fails due to a short buffer, retry with a greater buffer.

---
 lib/s390x/sclp.c | 58 +++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 50 insertions(+), 8 deletions(-)
lib/s390x/sclp.c +50 -8
index 34a31da..9d51ca4 100644
@@ -17,13 +17,14 @@
 #include "sclp.h"
 #include <alloc_phys.h>
 #include <alloc_page.h>
+#include <asm/facility.h>
 
 extern unsigned long stacktop;
 
 static uint64_t storage_increment_size;
 static uint64_t max_ram_size;
 static uint64_t ram_size;
-char _read_info[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
+char _read_info[2 * PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
 static ReadInfo *read_info;
 struct sclp_facilities sclp_facilities;
 
@@ -89,10 +90,41 @@ void sclp_clear_busy(void)
 	spin_unlock(&sclp_lock);
 }
 
-static void sclp_read_scp_info(ReadInfo *ri, int length)
+static bool sclp_read_scp_info_extended(unsigned int command, ReadInfo *ri)
+{
+	int cc;
+
+	if (!test_facility(140)) {
+		report_abort("S390_FEAT_EXTENDED_LENGTH_SCCB missing");
+		return false;
+	}
+	if (ri->h.length > (2 * PAGE_SIZE)) {
+		report_abort("SCLP_READ_INFO expected size too big");
+		return false;
+	}
+
+	sclp_mark_busy();
+	memset(&ri->h, 0, sizeof(ri->h));
+	ri->h.length = 2 * PAGE_SIZE;
+
+	cc = sclp_service_call(command, ri);
+	if (cc) {
+		report_abort("SCLP_READ_INFO error");
+		return false;
+	}
+	if (ri->h.response_code != SCLP_RC_NORMAL_READ_COMPLETION) {
+		report_abort("SCLP_READ_INFO error %02x", ri->h.response_code);
+		return false;
+	}
+
+	return true;
+}
+
+static void sclp_read_scp_info(ReadInfo *ri)
 {
 	unsigned int commands[] = { SCLP_CMDW_READ_SCP_INFO_FORCED,
 				    SCLP_CMDW_READ_SCP_INFO };
+	int length = PAGE_SIZE;
 	int i, cc;
 
 	for (i = 0; i < ARRAY_SIZE(commands); i++) {
@@ -101,19 +133,29 @@ static void sclp_read_scp_info(ReadInfo *ri, int length)
 		ri->h.length = length;
 
 		cc = sclp_service_call(commands[i], ri);
-		if (cc)
-			break;
-		if (ri->h.response_code == SCLP_RC_NORMAL_READ_COMPLETION)
+		if (cc) {
+			report_abort("SCLP_READ_INFO error");
 			return;
-		if (ri->h.response_code != SCLP_RC_INVALID_SCLP_COMMAND)
+		}
+
+		switch (ri->h.response_code) {
+		case SCLP_RC_NORMAL_READ_COMPLETION:
+			return;
+		case SCLP_RC_INVALID_SCLP_COMMAND:
 			break;
+		case SCLP_RC_INSUFFICIENT_SCCB_LENGTH:
+			sclp_read_scp_info_extended(commands[i], ri);
+			return;
+		default:
+			report_abort("READ_SCP_INFO failed");
+			return;
+		}
 	}
-	report_abort("READ_SCP_INFO failed");
 }
 
 void sclp_read_info(void)
 {
-	sclp_read_scp_info((void *)_read_info, SCCB_SIZE);
+	sclp_read_scp_info((void *)_read_info);
 	read_info = (ReadInfo *)_read_info;
 }
 
Signature · 1 line
2.31.1
#4 lore raw

Re: [kvm-unit-tests PATCH v4 2/2] s390x: sclp: Implement SCLP_RC_INSUFFICIENT_SCCB_LENGTH

Quoted 2 lines · On Tue, 30 May 2023 14:52:43 +0200 Pierre Morel <[email protected]> wrote:

If SCLP_CMDW_READ_SCP_INFO fails due to a short buffer, retry with a greater buffer.

the idea is good, but I wonder if the code can be simplified (see below)

Quoted 13 lines
---
 lib/s390x/sclp.c | 58 +++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 50 insertions(+), 8 deletions(-)
lib/s390x/sclp.c +0 -0
index 34a31da..9d51ca4 100644
@@ -17,13 +17,14 @@
 #include "sclp.h"
 #include <alloc_phys.h>

lib/s390x/sclp.c line 27

Quoted 10 lines
lib/s390x/sclp.c +2 -1
 #include <alloc_page.h>
+#include <asm/facility.h>
 
 extern unsigned long stacktop;
 
 static uint64_t storage_increment_size;
 static uint64_t max_ram_size;
 static uint64_t ram_size;
-char _read_info[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
+char _read_info[2 * PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));

this is ok ^

[skip everything else]

lib/s390x/sclp.c static void sclp_read_scp_info(ReadInfo *ri, int length) · line 116

Quoted 3 lines
lib/s390x/sclp.c +0 -1
 void sclp_read_info(void)
 {
-	sclp_read_scp_info((void *)_read_info, SCCB_SIZE);
	sclp_read_scp_info((void *)_read_info,
		test_facility(140) ? sizeof(_read_info) : SCCB_SIZE;
Quoted 4 lines
lib/s390x/sclp.c +1 -0
+	sclp_read_scp_info((void *)_read_info);

read_info = (ReadInfo *)_read_info;
}

#5 lore raw

Re: [kvm-unit-tests PATCH v4 2/2] s390x: sclp: Implement SCLP_RC_INSUFFICIENT_SCCB_LENGTH

Quoted 39 lines · Claudio Imbrenda
Quoted 2 lines · On Tue, 30 May 2023 14:52:43 +0200 Pierre Morel <[email protected]> wrote:

If SCLP_CMDW_READ_SCP_INFO fails due to a short buffer, retry with a greater buffer.

the idea is good, but I wonder if the code can be simplified (see below)

Quoted 12 lines
---
  lib/s390x/sclp.c | 58 +++++++++++++++++++++++++++++++++++++++++-------
  1 file changed, 50 insertions(+), 8 deletions(-)
lib/s390x/sclp.c +0 -0
index 34a31da..9d51ca4 100644
@@ -17,13 +17,14 @@
  #include "sclp.h"
  #include <alloc_phys.h>

lib/s390x/sclp.c line 27

Quoted 10 lines
lib/s390x/sclp.c +2 -1
  #include <alloc_page.h>
+#include <asm/facility.h>
 
  extern unsigned long stacktop;
 
  static uint64_t storage_increment_size;
  static uint64_t max_ram_size;
  static uint64_t ram_size;
-char _read_info[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
+char _read_info[2 * PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));

this is ok ^

[skip everything else]

lib/s390x/sclp.c static void sclp_read_scp_info(ReadInfo *ri, int length) · line 116

Quoted 3 lines
lib/s390x/sclp.c +0 -1
  void sclp_read_info(void)
  {
-	sclp_read_scp_info((void *)_read_info, SCCB_SIZE);
	sclp_read_scp_info((void *)_read_info,
		test_facility(140) ? sizeof(_read_info) : SCCB_SIZE;
Quoted 4 lines
Quoted 4 lines
lib/s390x/sclp.c +1 -0
+	sclp_read_scp_info((void *)_read_info);
  	read_info = (ReadInfo *)_read_info;
  }

You are right, no need to begin with a short buffer if we can go with a big one at first try.

I take it

thx