Skip to contentSkip to conversation

lib: s390x: add PSW and PSW_WITH_CUR_MASK macros

PATCH In review Claudio Imbrenda 2 participants 4 messages Nov 30, 2022 – Dec 1, 2022 KVM

lore
Share & tools
lore
#0 lore raw

v3 cover lib: s390x: add PSW and PSW_WITH_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.

v2->v3
* rename PSW_CUR_MASK to PSW_WITH_CUR_MASK

Claudio Imbrenda (2):
lib: s390x: add PSW and PSW_WITH_CUR_MASK macros
s390x: use the new PSW and PSW_WITH_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 v3 1/2 lib: s390x: add PSW and PSW_WITH_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..bb26e008 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_WITH_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
#2 lore raw

PATCH v3 2/2 s390x: use the new PSW and PSW_WITH_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..2db650a1 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_WITH_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_WITH_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_WITH_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_WITH_CUR_MASK(test_func));
 	smp_cpu_stop(1);
 
 	test_store_adtl_status_unavail();
s390x/firq.c +1 -4
index b4b3542e..0d65d87f 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_WITH_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..a4aa22e7 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_WITH_CUR_MASK(test_func));
 
 	/* wait for thread setup */
 	while(!flag_thread_complete)
s390x/skrf.c +1 -6
index 4cb563c3..e72a2b19 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_WITH_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..33e6eec6 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_WITH_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
Reviewed-by on the v3 series
#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.

Update the existing code to use the newly introduced macros.

Series:

Quoted 18 lines

v2->v3
* rename PSW_CUR_MASK to PSW_WITH_CUR_MASK

Claudio Imbrenda (2):
lib: s390x: add PSW and PSW_WITH_CUR_MASK macros
s390x: use the new PSW and PSW_WITH_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(-)