Skip to contentSkip to conversation

Fixing infinite loop on SCLP READ SCP INFO error

PATCH Applied Pierre Morel 2 participants 5 messages Jun 1, 2023 – Jun 2, 2023

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

v5 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 provide a bigger buffer for SCLP READ INFO when we have the extended-length-SCCB facility.

Pierre

Pierre Morel (2):
s390x: sclp: treat system as single processor when read_info is NULL
s390x: sclp: Implement extended-length-SCCB facility

 lib/s390x/sclp.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
Signature · 23 lines
2.31.1

since v4:

- changed comments
  (Nico)

- use a big buffer from the start if possible
  (Claudio)

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 v5 1/2 s390x: sclp: treat system as single processor when read_info is NULL

When a test abort()s before SCLP read info is completed, the assertion on read_info in sclp_read_info() will fail. Since abort() eventually calls smp_teardown() which in turn calls sclp_get_cpu_num(), this will cause an infinite abort() chain, causing the test to hang.

Fix this by considering the system single processor when read_info is missing.

---
 lib/s390x/sclp.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
lib/s390x/sclp.c +9 -2
index acdc8a9..adf357b 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;
+	/*
+	 * Don't abort here if read_info is NULL since abort() calls
+	 * smp_teardown() which eventually calls this function and thus
+	 * causes an infinite abort() chain, causing the test to hang.
+	 * Since we obviously have at least one CPU, just return one.
+	 */
+	return 1;
 }
 
 CPUEntry *sclp_get_cpu_entries(void)
Signature · 1 line
2.31.1
#2 lore raw

PATCH v5 2/2 s390x: sclp: Implement extended-length-SCCB facility

In reply to Pierre Morel

When the extended-length-SCCB facility is present use a big buffer already at first try when calling sclp_read_scp_info() to avoid the SCLP_RC_INSUFFICIENT_SCCB_LENGTH error.

---
 lib/s390x/sclp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/s390x/sclp.c +4 -1
index adf357b..e44d299 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;
 
@@ -114,6 +115,8 @@ static void sclp_read_scp_info(ReadInfo *ri, int length)
 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);
 	read_info = (ReadInfo *)_read_info;
 }
 
Signature · 1 line
2.31.1
#3 lore raw

Re: [kvm-unit-tests PATCH v5 2/2] s390x: sclp: Implement extended-length-SCCB facility

Quoted 30 lines · Pierre Morel

When the extended-length-SCCB facility is present use a big buffer already at first try when calling sclp_read_scp_info() to avoid the SCLP_RC_INSUFFICIENT_SCCB_LENGTH error.

---
  lib/s390x/sclp.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
lib/s390x/sclp.c +2 -1
index adf357b..e44d299 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;
 

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

Quoted 2 lines
lib/s390x/sclp.c +0 -0
@@ -114,6 +115,8 @@ static void sclp_read_scp_info(ReadInfo *ri, int length)
  void sclp_read_info(void)
  {

This line must go away.....v

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

Quoted 1 line
lib/s390x/sclp.c +0 -0
  	sclp_read_scp_info((void *)_read_info, SCCB_SIZE);

Sorry for the noise.

Quoted 5 lines
lib/s390x/sclp.c +2 -0
+	sclp_read_scp_info((void *)_read_info,
+		test_facility(140) ? sizeof(_read_info) : SCCB_SIZE);
  	read_info = (ReadInfo *)_read_info;
  }
 
Applied
#4 lore raw
In reply to Pierre Morel

Quoting Pierre Morel (2023-06-01 18:45:35)

Quoted 6 lines

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()

Quoted 8 lines

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 provide a bigger buffer for SCLP READ INFO when we have the extended-length-SCCB facility.

Pierre

Thanks for your patience Pierre.

Pushed to devel with the fixup to patch 2.