Skip to contentSkip to conversation

lib: s390x: Add more snippet macros

PATCH New Janosch Frank 1 participant 3 messages Sep 1

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

cover lib: s390x: Add more snippet macros

I'm trying to make things easier for developers (and me) before adding arm64 support. The upcoming code will add arch arguments to the macrosso that we won't have to duplicate them.

Janosch Frank (2):
lib: s390x: snippet: Add snippet declaration macro
lib: s390x: snippet: Add setup macro

 lib/s390x/snippet.h | 27 +++++++++++++++++
 s390x/mvpg-sie.c    |  3 +-
 s390x/pv-diags.c    | 33 ++++-----------------
 s390x/pv-edat1.c    | 12 ++------
 s390x/pv-icptcode.c | 72 +++++++++------------------------------------
 s390x/pv-ipl.c      | 12 ++------
 s390x/sie-dat.c     |  3 +-
 s390x/spec_ex-sie.c | 10 ++-----
 s390x/stfle-sie.c   |  7 ++---
 9 files changed, 58 insertions(+), 121 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/2 lib: s390x: snippet: Add snippet declaration macro

Improving readability.

---
 lib/s390x/snippet.h |  9 +++++++++
 s390x/mvpg-sie.c    |  3 +--
 s390x/pv-diags.c    | 15 +++------------
 s390x/pv-edat1.c    |  5 +----
 s390x/pv-icptcode.c | 30 ++++++------------------------
 s390x/pv-ipl.c      |  5 +----
 s390x/sie-dat.c     |  3 +--
 s390x/spec_ex-sie.c |  3 +--
 s390x/stfle-sie.c   |  3 +--
 9 files changed, 24 insertions(+), 52 deletions(-)
lib/s390x/snippet.h +9 -0
index 83d74387..6f82a873 100644
@@ -30,6 +30,15 @@
 #define SNIPPET_HDR_LEN(type, file) \
 	((uintptr_t)SNIPPET_HDR_END(type, file) - (uintptr_t)SNIPPET_HDR_START(type, file))
 
+#define SNIPPET_DECLARE(type, file)				\
+	extern const char SNIPPET_NAME_START(type, file)[];	\
+	extern const char SNIPPET_NAME_END(type, file)[]
+
+#define SNIPPET_DECLARE_PV(type, file)				\
+	SNIPPET_DECLARE(type, file);				\
+	extern const char SNIPPET_HDR_START(type, file)[];	\
+	extern const char SNIPPET_HDR_END(type, file)[]
+
 /*
  * Some of the UV memory needs to be allocated with >31 bit
  * addresses which means we need a lot more memory than other
s390x/mvpg-sie.c +1 -2
index 21082c53..ec0737be 100644
@@ -84,8 +84,7 @@ static void test_mvpg(void)
 
 static void setup_guest(void)
 {
-	extern const char SNIPPET_NAME_START(c, mvpg_snippet)[];
-	extern const char SNIPPET_NAME_END(c, mvpg_snippet)[];
+	SNIPPET_DECLARE(c, mvpg_snippet);
 	pgd_t *root;
 
 	setup_vm();
s390x/pv-diags.c +3 -12
index b6f08dd2..e7cc0e85 100644
@@ -18,10 +18,7 @@ static struct vm vm;
 
 static void test_diag_500(void)
 {
-	extern const char SNIPPET_NAME_START(asm, pv_diag_500)[];
-	extern const char SNIPPET_NAME_END(asm, pv_diag_500)[];
-	extern const char SNIPPET_HDR_START(asm, pv_diag_500)[];
-	extern const char SNIPPET_HDR_END(asm, pv_diag_500)[];
+	SNIPPET_DECLARE_PV(asm, pv_diag_500);
 	int size_hdr = SNIPPET_HDR_LEN(asm, pv_diag_500);
 	int size_gbin = SNIPPET_LEN(asm, pv_diag_500);
 
@@ -69,10 +66,7 @@ static void test_diag_500(void)
 
 static void test_diag_288(void)
 {
-	extern const char SNIPPET_NAME_START(asm, pv_diag_288)[];
-	extern const char SNIPPET_NAME_END(asm, pv_diag_288)[];
-	extern const char SNIPPET_HDR_START(asm, pv_diag_288)[];
-	extern const char SNIPPET_HDR_END(asm, pv_diag_288)[];
+	SNIPPET_DECLARE_PV(asm, pv_diag_288);
 	int size_hdr = SNIPPET_HDR_LEN(asm, pv_diag_288);
 	int size_gbin = SNIPPET_LEN(asm, pv_diag_288);
 
@@ -110,10 +104,7 @@ static void test_diag_288(void)
 
 static void test_diag_yield(void)
 {
-	extern const char SNIPPET_NAME_START(asm, pv_diag_yield)[];
-	extern const char SNIPPET_NAME_END(asm, pv_diag_yield)[];
-	extern const char SNIPPET_HDR_START(asm, pv_diag_yield)[];
-	extern const char SNIPPET_HDR_END(asm, pv_diag_yield)[];
+	SNIPPET_DECLARE_PV(asm, pv_diag_yield);
 	int size_hdr = SNIPPET_HDR_LEN(asm, pv_diag_yield);
 	int size_gbin = SNIPPET_LEN(asm, pv_diag_yield);
 
s390x/pv-edat1.c +1 -4
index ff762c75..05afbb41 100644
@@ -36,10 +36,7 @@
 static struct vm vm;
 static pgd_t *root;
 
-extern const char SNIPPET_NAME_START(c, pv_memhog)[];
-extern const char SNIPPET_NAME_END(c, pv_memhog)[];
-extern const char SNIPPET_HDR_START(c, pv_memhog)[];
-extern const char SNIPPET_HDR_END(c, pv_memhog)[];
+SNIPPET_DECLARE_PV(c, pv_memhog);
 
 static void init_snippet(struct vm *vm) {
 	const unsigned long size_hdr = SNIPPET_HDR_LEN(c, pv_memhog);
s390x/pv-icptcode.c +6 -24
index bdef3a05..35bfde56 100644
@@ -33,10 +33,7 @@ static struct vm vm, vm2;
  */
 static void test_validity_timing(void)
 {
-	extern const char SNIPPET_NAME_START(asm, pv_icpt_vir_timing)[];
-	extern const char SNIPPET_NAME_END(asm, pv_icpt_vir_timing)[];
-	extern const char SNIPPET_HDR_START(asm, pv_icpt_vir_timing)[];
-	extern const char SNIPPET_HDR_END(asm, pv_icpt_vir_timing)[];
+	SNIPPET_DECLARE_PV(asm, pv_icpt_vir_timing);
 	int size_hdr = SNIPPET_HDR_LEN(asm, pv_icpt_vir_timing);
 	int size_gbin = SNIPPET_LEN(asm, pv_icpt_vir_timing);
 	uint64_t time_exit, time_entry, tmp;
@@ -82,10 +79,7 @@ static void run_loop(void)
 
 static void test_validity_already_running(void)
 {
-	extern const char SNIPPET_NAME_START(asm, loop)[];
-	extern const char SNIPPET_NAME_END(asm, loop)[];
-	extern const char SNIPPET_HDR_START(asm, loop)[];
-	extern const char SNIPPET_HDR_END(asm, loop)[];
+	SNIPPET_DECLARE_PV(asm, loop);
 	int size_hdr = SNIPPET_HDR_LEN(asm, loop);
 	int size_gbin = SNIPPET_LEN(asm, loop);
 	struct psw psw = {
@@ -131,10 +125,7 @@ out:
 /* Tests if a vcpu handle from another configuration results in a validity intercept. */
 static void test_validity_handle_not_in_config(void)
 {
-	extern const char SNIPPET_NAME_START(asm, icpt_loop)[];
-	extern const char SNIPPET_NAME_END(asm, icpt_loop)[];
-	extern const char SNIPPET_HDR_START(asm, icpt_loop)[];
-	extern const char SNIPPET_HDR_END(asm, icpt_loop)[];
+	SNIPPET_DECLARE_PV(asm, icpt_loop);
 	int size_hdr = SNIPPET_HDR_LEN(asm, icpt_loop);
 	int size_gbin = SNIPPET_LEN(asm, icpt_loop);
 
@@ -173,10 +164,7 @@ static void test_validity_handle_not_in_config(void)
 /* Tests if a wrong vm or vcpu handle results in a validity intercept. */
 static void test_validity_seid(void)
 {
-	extern const char SNIPPET_NAME_START(asm, icpt_loop)[];
-	extern const char SNIPPET_NAME_END(asm, icpt_loop)[];
-	extern const char SNIPPET_HDR_START(asm, icpt_loop)[];
-	extern const char SNIPPET_HDR_END(asm, icpt_loop)[];
+	SNIPPET_DECLARE_PV(asm, icpt_loop);
 	int size_hdr = SNIPPET_HDR_LEN(asm, icpt_loop);
 	int size_gbin = SNIPPET_LEN(asm, icpt_loop);
 	int fails = 0;
@@ -224,10 +212,7 @@ static void test_validity_seid(void)
  */
 static void test_validity_asce(void)
 {
-	extern const char SNIPPET_NAME_START(asm, pv_icpt_112)[];
-	extern const char SNIPPET_NAME_END(asm, pv_icpt_112)[];
-	extern const char SNIPPET_HDR_START(asm, pv_icpt_112)[];
-	extern const char SNIPPET_HDR_END(asm, pv_icpt_112)[];
+	SNIPPET_DECLARE_PV(asm, pv_icpt_112);
 	int size_hdr = SNIPPET_HDR_LEN(asm, pv_icpt_112);
 	int size_gbin = SNIPPET_LEN(asm, pv_icpt_112);
 	uint64_t asce_old, asce_new;
@@ -311,10 +296,7 @@ static void run_icpt_122_tests_prefix(unsigned long prefix)
 
 static void test_icpt_112(void)
 {
-	extern const char SNIPPET_NAME_START(asm, pv_icpt_112)[];
-	extern const char SNIPPET_NAME_END(asm, pv_icpt_112)[];
-	extern const char SNIPPET_HDR_START(asm, pv_icpt_112)[];
-	extern const char SNIPPET_HDR_END(asm, pv_icpt_112)[];
+	SNIPPET_DECLARE_PV(asm, pv_icpt_112);
 	int size_hdr = SNIPPET_HDR_LEN(asm, pv_icpt_112);
 	int size_gbin = SNIPPET_LEN(asm, pv_icpt_112);
 
s390x/pv-ipl.c +1 -4
index 1219573f..af2cfbcf 100644
@@ -19,10 +19,7 @@ static struct vm vm;
 
 static void test_diag_308(int subcode)
 {
-	extern const char SNIPPET_NAME_START(asm, pv_diag_308)[];
-	extern const char SNIPPET_NAME_END(asm, pv_diag_308)[];
-	extern const char SNIPPET_HDR_START(asm, pv_diag_308)[];
-	extern const char SNIPPET_HDR_END(asm, pv_diag_308)[];
+	SNIPPET_DECLARE_PV(asm, pv_diag_308);
 	int size_hdr = SNIPPET_HDR_LEN(asm, pv_diag_308);
 	int size_gbin = SNIPPET_LEN(asm, pv_diag_308);
 	uint16_t rc, rrc;
s390x/sie-dat.c +1 -2
index a5ff0872..46d20dab 100644
@@ -63,8 +63,7 @@ static void test_sie_dat(void)
 
 static void setup_guest(void)
 {
-	extern const char SNIPPET_NAME_START(c, sie_dat)[];
-	extern const char SNIPPET_NAME_END(c, sie_dat)[];
+	SNIPPET_DECLARE(c, sie_dat);
 	uint64_t guest_max_addr;
 	pgd_t *root;
 
s390x/spec_ex-sie.c +1 -2
index dd4ab77e..e79208df 100644
@@ -21,8 +21,7 @@ static bool strict;
 
 static void setup_guest(void)
 {
-	extern const char SNIPPET_NAME_START(c, spec_ex)[];
-	extern const char SNIPPET_NAME_END(c, spec_ex)[];
+	SNIPPET_DECLARE(c, spec_ex);
 
 	setup_vm();
 
s390x/stfle-sie.c +1 -2
index 3697e1ae..e3642078 100644
@@ -20,8 +20,7 @@ static prng_state prng_s;
 
 static void setup_guest(void)
 {
-	extern const char SNIPPET_NAME_START(c, stfle)[];
-	extern const char SNIPPET_NAME_END(c, stfle)[];
+	SNIPPET_DECLARE(c, stfle);
 
 	setup_vm();
 	fac = alloc_pages_flags(0, AREA_DMA31);
Signature · 1 line
2.53.0
#2 lore raw

PATCH 2/2 lib: s390x: snippet: Add setup macro

In reply to Janosch Frank

SNIPPET_SETUP() takes care of guest setup and snippet initialization.

---
 lib/s390x/snippet.h | 18 ++++++++++++++++++
 s390x/pv-diags.c    | 18 +++---------------
 s390x/pv-edat1.c    |  7 +------
 s390x/pv-icptcode.c | 42 ++++++++----------------------------------
 s390x/pv-ipl.c      |  7 ++-----
 s390x/spec_ex-sie.c |  7 +------
 s390x/stfle-sie.c   |  4 +---
 7 files changed, 34 insertions(+), 69 deletions(-)
lib/s390x/snippet.h +18 -0
index 6f82a873..0ff7ad7d 100644
@@ -39,6 +39,24 @@
 	extern const char SNIPPET_HDR_START(type, file)[];	\
 	extern const char SNIPPET_HDR_END(type, file)[]
 
+#define SNIPPET_SETUP_PV(vm, type, file)			\
+do {								\
+	snippet_setup_guest(vm, true);				\
+	snippet_pv_init(vm,					\
+			SNIPPET_NAME_START(type, file),		\
+			SNIPPET_HDR_START(type, file),		\
+			SNIPPET_LEN(type, file),		\
+			SNIPPET_HDR_LEN(type, file),		\
+			0);					\
+} while (0)
+
+#define SNIPPET_SETUP(vm, type, file)				\
+do {								\
+	snippet_setup_guest(vm, false);				\
+	snippet_init(vm, SNIPPET_NAME_START(type, file),	\
+		     SNIPPET_LEN(type, file), 0);		\
+} while (0)
+
 /*
  * Some of the UV memory needs to be allocated with >31 bit
  * addresses which means we need a lot more memory than other
s390x/pv-diags.c +3 -15
index e7cc0e85..a5f32954 100644
@@ -19,14 +19,10 @@ static struct vm vm;
 static void test_diag_500(void)
 {
 	SNIPPET_DECLARE_PV(asm, pv_diag_500);
-	int size_hdr = SNIPPET_HDR_LEN(asm, pv_diag_500);
-	int size_gbin = SNIPPET_LEN(asm, pv_diag_500);
 
 	report_prefix_push("diag 0x500");
 
-	snippet_pv_init(&vm, SNIPPET_NAME_START(asm, pv_diag_500),
-			SNIPPET_HDR_START(asm, pv_diag_500),
-			size_gbin, size_hdr, SNIPPET_UNPACK_OFF);
+	SNIPPET_SETUP_PV(&vm, asm, pv_diag_500);
 
 	sie(&vm);
 	report(sie_is_diag_icpt(&vm, 0x500), "intercept values");
@@ -67,14 +63,10 @@ static void test_diag_500(void)
 static void test_diag_288(void)
 {
 	SNIPPET_DECLARE_PV(asm, pv_diag_288);
-	int size_hdr = SNIPPET_HDR_LEN(asm, pv_diag_288);
-	int size_gbin = SNIPPET_LEN(asm, pv_diag_288);
 
 	report_prefix_push("diag 0x288");
 
-	snippet_pv_init(&vm, SNIPPET_NAME_START(asm, pv_diag_288),
-			SNIPPET_HDR_START(asm, pv_diag_288),
-			size_gbin, size_hdr, SNIPPET_UNPACK_OFF);
+	SNIPPET_SETUP_PV(&vm, asm, pv_diag_288);
 
 	sie(&vm);
 	report(vm.sblk->icptcode == ICPT_PV_INSTR && vm.sblk->ipa == 0x8302 &&
@@ -105,14 +97,10 @@ static void test_diag_288(void)
 static void test_diag_yield(void)
 {
 	SNIPPET_DECLARE_PV(asm, pv_diag_yield);
-	int size_hdr = SNIPPET_HDR_LEN(asm, pv_diag_yield);
-	int size_gbin = SNIPPET_LEN(asm, pv_diag_yield);
 
 	report_prefix_push("diag yield");
 
-	snippet_pv_init(&vm, SNIPPET_NAME_START(asm, pv_diag_yield),
-			SNIPPET_HDR_START(asm, pv_diag_yield),
-			size_gbin, size_hdr, SNIPPET_UNPACK_OFF);
+	SNIPPET_SETUP_PV(&vm, asm, pv_diag_yield);
 
 	/* 0x44 */
 	report_prefix_push("0x44");
s390x/pv-edat1.c +1 -6
index 05afbb41..5dc1f42c 100644
@@ -39,12 +39,7 @@ static pgd_t *root;
 SNIPPET_DECLARE_PV(c, pv_memhog);
 
 static void init_snippet(struct vm *vm) {
-	const unsigned long size_hdr = SNIPPET_HDR_LEN(c, pv_memhog);
-	const unsigned long size_gbin = SNIPPET_LEN(c, pv_memhog);
-
-	snippet_pv_init(vm, SNIPPET_NAME_START(c, pv_memhog),
-			SNIPPET_HDR_START(c, pv_memhog),
-			size_gbin, size_hdr, SNIPPET_UNPACK_OFF);
+	SNIPPET_SETUP_PV(vm, c, pv_memhog);
 }
 
 static uint64_t tod_to_us(uint64_t tod)
s390x/pv-icptcode.c +8 -34

105 lines not on this page · raw message

s390x/pv-ipl.c +2 -5
index af2cfbcf..8affeb1c 100644
@@ -20,15 +20,12 @@ static struct vm vm;
 static void test_diag_308(int subcode)
 {
 	SNIPPET_DECLARE_PV(asm, pv_diag_308);
-	int size_hdr = SNIPPET_HDR_LEN(asm, pv_diag_308);
-	int size_gbin = SNIPPET_LEN(asm, pv_diag_308);
 	uint16_t rc, rrc;
 	int cc;
 
 	report_prefix_pushf("subcode %d", subcode);
-	snippet_pv_init(&vm, SNIPPET_NAME_START(asm, pv_diag_308),
-			SNIPPET_HDR_START(asm, pv_diag_308),
-			size_gbin, size_hdr, SNIPPET_UNPACK_OFF);
+
+	SNIPPET_SETUP_PV(&vm, asm, pv_diag_308);
 
 	/* First exit is a diag 0x500 */
 	sie(&vm);
s390x/spec_ex-sie.c +1 -6
index e79208df..102f0345 100644
@@ -22,12 +22,7 @@ static bool strict;
 static void setup_guest(void)
 {
 	SNIPPET_DECLARE(c, spec_ex);
-
-	setup_vm();
-
-	snippet_setup_guest(&vm, false);
-	snippet_init(&vm, SNIPPET_NAME_START(c, spec_ex),
-		     SNIPPET_LEN(c, spec_ex), SNIPPET_UNPACK_OFF);
+	SNIPPET_SETUP(&vm, c, spec_ex);
 }
 
 static void test_spec_ex_sie(void)
s390x/stfle-sie.c +1 -3
index e3642078..178c6815 100644
@@ -25,9 +25,7 @@ static void setup_guest(void)
 	setup_vm();
 	fac = alloc_pages_flags(0, AREA_DMA31);
 
-	snippet_setup_guest(&vm, false);
-	snippet_init(&vm, SNIPPET_NAME_START(c, stfle),
-		     SNIPPET_LEN(c, stfle), SNIPPET_UNPACK_OFF);
+	SNIPPET_SETUP(&vm, c, stfle);
 }
 
 struct guest_stfle_res {
Signature · 1 line
2.53.0