Skip to contentSkip to conversation

lib: s390x: add PSW and PSW_CUR_MASK macros

PATCH Superseded Claudio Imbrenda 4 participants 8 messages Nov 29, 2022 – Nov 30, 2022 KVM

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover lib: s390x: add PSW and PSW_CUR_MASK macros

Since a lot of code starts new CPUs using the current PSW mask, add two macros to streamline the creation of generic PSWs and PSWs with the current program mask.

Update the existing code to use the newly introduced macros.

Claudio Imbrenda (2):
lib: s390x: add PSW and PSW_CUR_MASK macros
s390x: use the new PSW and PSW_CUR_MASK macros

 lib/s390x/asm/arch_def.h |  4 +++
 s390x/adtl-status.c      | 24 +++---------------
 s390x/firq.c             |  5 +---
 s390x/migration.c        |  6 +----
 s390x/skrf.c             |  7 +-----
 s390x/smp.c              | 53 +++++++++-------------------------------
 s390x/uv-host.c          |  5 +---
 7 files changed, 23 insertions(+), 81 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH v2 1/2 lib: s390x: add PSW and PSW_CUR_MASK macros

Since a lot of code starts new CPUs using the current PSW mask, add two macros to streamline the creation of generic PSWs and PSWs with the current program mask.

---
 lib/s390x/asm/arch_def.h | 4 ++++
 1 file changed, 4 insertions(+)
lib/s390x/asm/arch_def.h +4 -0
index 783a7eaa..43137d5f 100644
@@ -41,6 +41,8 @@ struct psw {
 	uint64_t	addr;
 };
 
+#define PSW(m, a) ((struct psw){ .mask = (m), .addr = (uint64_t)(a) })
+
 struct short_psw {
 	uint32_t	mask;
 	uint32_t	addr;
@@ -321,6 +323,8 @@ static inline uint64_t extract_psw_mask(void)
 	return (uint64_t) mask_upper << 32 | mask_lower;
 }
 
+#define PSW_CUR_MASK(addr) PSW(extract_psw_mask(), (addr))
+
 static inline void load_psw_mask(uint64_t mask)
 {
 	struct psw psw = {
Signature · 1 line
2.38.1
Reviewed-by on v2 1/2
#3 lore raw
In reply to Claudio Imbrenda
Quoted 5 lines · Claudio Imbrenda

Since a lot of code starts new CPUs using the current PSW mask, add two macros to streamline the creation of generic PSWs and PSWs with the current program mask.

Quoted 26 lines
---
 lib/s390x/asm/arch_def.h | 4 ++++
 1 file changed, 4 insertions(+)
lib/s390x/asm/arch_def.h +4 -0
index 783a7eaa..43137d5f 100644
@@ -41,6 +41,8 @@ struct psw {
 	uint64_t	addr;
 };
 
+#define PSW(m, a) ((struct psw){ .mask = (m), .addr = (uint64_t)(a) })
+
 struct short_psw {
 	uint32_t	mask;
 	uint32_t	addr;
@@ -321,6 +323,8 @@ static inline uint64_t extract_psw_mask(void)
 	return (uint64_t) mask_upper << 32 | mask_lower;
 }
 
+#define PSW_CUR_MASK(addr) PSW(extract_psw_mask(), (addr))
+
 static inline void load_psw_mask(uint64_t mask)
 {
 	struct psw psw = {
#4 lore raw
In reply to Claudio Imbrenda
Quoted 23 lines · Claudio Imbrenda

Since a lot of code starts new CPUs using the current PSW mask, add two macros to streamline the creation of generic PSWs and PSWs with the current program mask.

---
  lib/s390x/asm/arch_def.h | 4 ++++
  1 file changed, 4 insertions(+)
lib/s390x/asm/arch_def.h +2 -0
index 783a7eaa..43137d5f 100644
@@ -41,6 +41,8 @@ struct psw {
  	uint64_t	addr;
  };
 
+#define PSW(m, a) ((struct psw){ .mask = (m), .addr = (uint64_t)(a) })
+
  struct short_psw {
  	uint32_t	mask;
  	uint32_t	addr;

lib/s390x/asm/arch_def.h static inline uint64_t extract_psw_mask(void) · line 326

Quoted 4 lines
lib/s390x/asm/arch_def.h +1 -0
@@ -321,6 +323,8 @@ static inline uint64_t extract_psw_mask(void)
  	return (uint64_t) mask_upper << 32 | mask_lower;
  }
 
+#define PSW_CUR_MASK(addr) PSW(extract_psw_mask(), (addr))

This sounds too much like what extract_psw_mask() does.
So we should agree on a name that states that we receive a PSW and not a PSW mask.

s/PSW_CUR_MASK/PSW_WITH_CUR_MASK/

Other than that the code looks fine.

Quoted 4 lines
lib/s390x/asm/arch_def.h +1 -0
+
  static inline void load_psw_mask(uint64_t mask)
  {
  	struct psw psw = {
#5 lore raw
Quoted 33 lines · On Tue, 29 Nov 2022 15:17:51 +0100 Janosch Frank <[email protected]> wrote:
Quoted 23 lines · Claudio Imbrenda

Since a lot of code starts new CPUs using the current PSW mask, add two macros to streamline the creation of generic PSWs and PSWs with the current program mask.

---
  lib/s390x/asm/arch_def.h | 4 ++++
  1 file changed, 4 insertions(+)
lib/s390x/asm/arch_def.h +2 -0
index 783a7eaa..43137d5f 100644
@@ -41,6 +41,8 @@ struct psw {
  	uint64_t	addr;
  };
 
+#define PSW(m, a) ((struct psw){ .mask = (m), .addr = (uint64_t)(a) })
+
  struct short_psw {
  	uint32_t	mask;
  	uint32_t	addr;

lib/s390x/asm/arch_def.h static inline uint64_t extract_psw_mask(void) · line 326

Quoted 4 lines
lib/s390x/asm/arch_def.h +1 -0
@@ -321,6 +323,8 @@ static inline uint64_t extract_psw_mask(void)
  	return (uint64_t) mask_upper << 32 | mask_lower;
  }
 
+#define PSW_CUR_MASK(addr) PSW(extract_psw_mask(), (addr))  

This sounds too much like what extract_psw_mask() does.
So we should agree on a name that states that we receive a PSW and not a PSW mask.

Quoted 3 lines

s/PSW_CUR_MASK/PSW_WITH_CUR_MASK/

Other than that the code looks fine.

will do

Quoted 6 lines
Quoted 5 lines
lib/s390x/asm/arch_def.h +1 -0
+
  static inline void load_psw_mask(uint64_t mask)
  {
  	struct psw psw = {  
#6 lore raw

PATCH v2 2/2 s390x: use the new PSW and PSW_CUR_MASK macros

In reply to Claudio Imbrenda

Use the new macros in the existing code. No functional changes intended.

---
 s390x/adtl-status.c | 24 ++++----------------
 s390x/firq.c        |  5 +----
 s390x/migration.c   |  6 +----
 s390x/skrf.c        |  7 +-----
 s390x/smp.c         | 53 ++++++++++-----------------------------------
 s390x/uv-host.c     |  5 +----
 6 files changed, 19 insertions(+), 81 deletions(-)
s390x/adtl-status.c +4 -20
index 9fb76319..ac1ed25f 100644
@@ -205,16 +205,11 @@ static void restart_write_vector(void)
 
 static void cpu_write_magic_to_vector_regs(uint16_t cpu_idx)
 {
-	struct psw new_psw;
-
 	smp_cpu_stop(cpu_idx);
 
-	new_psw.mask = extract_psw_mask();
-	new_psw.addr = (unsigned long)restart_write_vector;
-
 	set_flag(0);
 
-	smp_cpu_start(cpu_idx, new_psw);
+	smp_cpu_start(cpu_idx, PSW_CUR_MASK(restart_write_vector));
 
 	wait_for_flag();
 }
@@ -241,7 +236,6 @@ static int adtl_status_check_unmodified_fields_for_lc(unsigned long lc)
 static void __store_adtl_status_vector_lc(unsigned long lc)
 {
 	uint32_t status = -1;
-	struct psw psw;
 	int cc;
 
 	report_prefix_pushf("LC %lu", lc);
@@ -274,9 +268,7 @@ static void __store_adtl_status_vector_lc(unsigned long lc)
 	 * Destroy and re-initalize the CPU to fix that.
 	 */
 	smp_cpu_destroy(1);
-	psw.mask = extract_psw_mask();
-	psw.addr = (unsigned long)test_func;
-	smp_cpu_setup(1, psw);
+	smp_cpu_setup(1, PSW_CUR_MASK(test_func));
 
 out:
 	report_prefix_pop();
@@ -325,16 +317,11 @@ static void restart_write_gs_regs(void)
 
 static void cpu_write_to_gs_regs(uint16_t cpu_idx)
 {
-	struct psw new_psw;
-
 	smp_cpu_stop(cpu_idx);
 
-	new_psw.mask = extract_psw_mask();
-	new_psw.addr = (unsigned long)restart_write_gs_regs;
-
 	set_flag(0);
 
-	smp_cpu_start(cpu_idx, new_psw);
+	smp_cpu_start(cpu_idx, PSW_CUR_MASK(restart_write_gs_regs));
 
 	wait_for_flag();
 }
@@ -382,7 +369,6 @@ out:
 
 int main(void)
 {
-	struct psw psw;
 	report_prefix_push("adtl_status");
 
 	if (smp_query_num_cpus() == 1) {
@@ -391,9 +377,7 @@ int main(void)
 	}
 
 	/* Setting up the cpu to give it a stack and lowcore */
-	psw.mask = extract_psw_mask();
-	psw.addr = (unsigned long)test_func;
-	smp_cpu_setup(1, psw);
+	smp_cpu_setup(1, PSW_CUR_MASK(test_func));
 	smp_cpu_stop(1);
 
 	test_store_adtl_status_unavail();
s390x/firq.c +1 -4
index b4b3542e..4a1ac84d 100644
@@ -33,7 +33,6 @@ static void wait_for_sclp_int(void)
  */
 static void test_wait_state_delivery(void)
 {
-	struct psw psw;
 	SCCBHeader *h;
 	int ret;
 
@@ -55,9 +54,7 @@ static void test_wait_state_delivery(void)
 	sclp_mark_busy();
 
 	/* Start CPU #1 and let it wait for the interrupt. */
-	psw.mask = extract_psw_mask();
-	psw.addr = (unsigned long)wait_for_sclp_int;
-	ret = smp_cpu_setup(1, psw);
+	ret = smp_cpu_setup(1, PSW_CUR_MASK(wait_for_sclp_int));
 	/* This must not fail because we have at least 3 CPUs */
 	assert(!ret);
 
s390x/migration.c +1 -5
index a4529637..5c4773d6 100644
@@ -158,8 +158,6 @@ static void test_func(void)
 
 int main(void)
 {
-	struct psw psw;
-
 	/* don't say migrate here otherwise we will migrate right away */
 	report_prefix_push("migration");
 
@@ -169,9 +167,7 @@ int main(void)
 	}
 
 	/* Second CPU does the actual tests */
-	psw.mask = extract_psw_mask();
-	psw.addr = (unsigned long)test_func;
-	smp_cpu_setup(1, psw);
+	smp_cpu_setup(1, PSW_CUR_MASK(test_func));
 
 	/* wait for thread setup */
 	while(!flag_thread_complete)
s390x/skrf.c +1 -6
index 4cb563c3..8a7dae5e 100644
@@ -151,11 +151,6 @@ static void ecall_setup(void)
 
 static void test_exception_ext_new(void)
 {
-	struct psw psw = {
-		.mask = extract_psw_mask(),
-		.addr = (unsigned long)ecall_setup
-	};
-
 	report_prefix_push("exception external new");
 	if (smp_query_num_cpus() < 2) {
 		report_skip("Need second cpu for exception external new test.");
@@ -163,7 +158,7 @@ static void test_exception_ext_new(void)
 		return;
 	}
 
-	smp_cpu_setup(1, psw);
+	smp_cpu_setup(1, PSW_CUR_MASK(ecall_setup));
 	wait_for_flag();
 	set_flag(0);
 
s390x/smp.c +11 -42

150 lines not on this page · raw message

s390x/uv-host.c +1 -4
index 9f09f80e..f613218c 100644
@@ -501,7 +501,6 @@ static void test_init(void)
 {
 	int rc;
 	uint64_t mem;
-	struct psw psw;
 
 	/* Donated storage needs to be over 2GB */
 	mem = (uint64_t)memalign_pages_flags(SZ_1M, uvcb_qui.uv_base_stor_len, AREA_NORMAL);
@@ -547,9 +546,7 @@ static void test_init(void)
 	       "storage below 2GB");
 	uvcb_init.stor_origin = mem;
 
-	psw.mask = extract_psw_mask();
-	psw.addr = (unsigned long)cpu_loop;
-	smp_cpu_setup(1, psw);
+	smp_cpu_setup(1, PSW_CUR_MASK(cpu_loop));
 	rc = uv_call(0, (uint64_t)&uvcb_init);
 	report(rc == 1 && uvcb_init.header.rc == 0x102,
 	       "too many running cpus");
Signature · 1 line
2.38.1