All of lore.kernel.org
 help / color / mirror / Atom feed
From: Janosch Frank <frankja@linux.ibm.com>
To: kvm@vger.kernel.org
Cc: linux-s390@vger.kernel.org, imbrenda@linux.ibm.com,
	borntraeger@linux.ibm.com, nrb@linux.ibm.com
Subject: [kvm-unit-tests PATCH 2/2] lib: s390x: snippet: Add setup macro
Date: Tue,  1 Sep 2026 14:20:26 +0000	[thread overview]
Message-ID: <20260901142538.42553-3-frankja@linux.ibm.com> (raw)
In-Reply-To: <20260901142538.42553-1-frankja@linux.ibm.com>

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

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 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(-)

diff --git a/lib/s390x/snippet.h b/lib/s390x/snippet.h
index 6f82a873..0ff7ad7d 100644
--- a/lib/s390x/snippet.h
+++ b/lib/s390x/snippet.h
@@ -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
diff --git a/s390x/pv-diags.c b/s390x/pv-diags.c
index e7cc0e85..a5f32954 100644
--- a/s390x/pv-diags.c
+++ b/s390x/pv-diags.c
@@ -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");
diff --git a/s390x/pv-edat1.c b/s390x/pv-edat1.c
index 05afbb41..5dc1f42c 100644
--- a/s390x/pv-edat1.c
+++ b/s390x/pv-edat1.c
@@ -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)
diff --git a/s390x/pv-icptcode.c b/s390x/pv-icptcode.c
index 35bfde56..71baef2f 100644
--- a/s390x/pv-icptcode.c
+++ b/s390x/pv-icptcode.c
@@ -34,14 +34,11 @@ static struct vm vm, vm2;
 static void test_validity_timing(void)
 {
 	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;
 
 	report_prefix_push("manipulated cpu time");
-	snippet_pv_init(&vm, SNIPPET_NAME_START(asm, pv_icpt_vir_timing),
-			SNIPPET_HDR_START(asm, pv_icpt_vir_timing),
-			size_gbin, size_hdr, SNIPPET_UNPACK_OFF);
+
+	SNIPPET_SETUP_PV(&vm, asm, pv_icpt_vir_timing);
 
 	sie(&vm);
 	report(sie_is_diag_icpt(&vm, 0x44), "spt done");
@@ -80,8 +77,6 @@ static void run_loop(void)
 static void test_validity_already_running(void)
 {
 	SNIPPET_DECLARE_PV(asm, loop);
-	int size_hdr = SNIPPET_HDR_LEN(asm, loop);
-	int size_gbin = SNIPPET_LEN(asm, loop);
 	struct psw psw = {
 		.mask = PSW_MASK_64,
 		.addr = (uint64_t)run_loop,
@@ -93,9 +88,7 @@ static void test_validity_already_running(void)
 		goto out;
 	}
 
-	snippet_pv_init(&vm, SNIPPET_NAME_START(asm, loop),
-			SNIPPET_HDR_START(asm, loop),
-			size_gbin, size_hdr, SNIPPET_UNPACK_OFF);
+	SNIPPET_SETUP_PV(&vm, asm, loop);
 
 	smp_cpu_setup(1, psw);
 	sie_expect_validity(&vm);
@@ -126,20 +119,13 @@ out:
 static void test_validity_handle_not_in_config(void)
 {
 	SNIPPET_DECLARE_PV(asm, icpt_loop);
-	int size_hdr = SNIPPET_HDR_LEN(asm, icpt_loop);
-	int size_gbin = SNIPPET_LEN(asm, icpt_loop);
 
 	report_prefix_push("handle not in config");
 	/* Setup our primary vm */
-	snippet_pv_init(&vm, SNIPPET_NAME_START(asm, icpt_loop),
-			SNIPPET_HDR_START(asm, icpt_loop),
-			size_gbin, size_hdr, SNIPPET_UNPACK_OFF);
+	SNIPPET_SETUP_PV(&vm, asm, icpt_loop);
 
 	/* Setup secondary vm */
-	snippet_setup_guest(&vm2, true);
-	snippet_pv_init(&vm2, SNIPPET_NAME_START(asm, icpt_loop),
-			SNIPPET_HDR_START(asm, icpt_loop),
-			size_gbin, size_hdr, SNIPPET_UNPACK_OFF);
+	SNIPPET_SETUP_PV(&vm2, asm, icpt_loop);
 
 	vm.sblk->pv_handle_cpu = vm2.sblk->pv_handle_cpu;
 	sie_expect_validity(&vm);
@@ -165,15 +151,11 @@ static void test_validity_handle_not_in_config(void)
 static void test_validity_seid(void)
 {
 	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;
 	int i;
 
 	report_prefix_push("handles");
-	snippet_pv_init(&vm, SNIPPET_NAME_START(asm, icpt_loop),
-			SNIPPET_HDR_START(asm, icpt_loop),
-			size_gbin, size_hdr, SNIPPET_UNPACK_OFF);
+	SNIPPET_SETUP_PV(&vm, asm, icpt_loop);
 
 	for (i = 0; i < 64; i++) {
 		vm.sblk->pv_handle_config ^= 1UL << i;
@@ -213,15 +195,11 @@ static void test_validity_seid(void)
 static void test_validity_asce(void)
 {
 	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;
 	void *pgd_new, *pgd_old;
 
 	report_prefix_push("asce");
-	snippet_pv_init(&vm, SNIPPET_NAME_START(asm, pv_icpt_112),
-			SNIPPET_HDR_START(asm, pv_icpt_112),
-			size_gbin, size_hdr, SNIPPET_UNPACK_OFF);
+	SNIPPET_SETUP_PV(&vm, asm, pv_icpt_112);
 
 	asce_old = vm.save_area.guest.asce;
 	pgd_new = memalign_pages_flags(PAGE_SIZE, PAGE_SIZE * 4, 0);
@@ -297,16 +275,12 @@ static void run_icpt_122_tests_prefix(unsigned long prefix)
 static void test_icpt_112(void)
 {
 	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);
 
 	unsigned long lc_off = 0;
 
 	report_prefix_push("prefix");
 
-	snippet_pv_init(&vm, SNIPPET_NAME_START(asm, pv_icpt_112),
-			SNIPPET_HDR_START(asm, pv_icpt_112),
-			size_gbin, size_hdr, SNIPPET_UNPACK_OFF);
+	SNIPPET_SETUP_PV(&vm, asm, pv_icpt_112);
 
 	/* Setup of the guest's state for 0x0 prefix */
 	sie(&vm);
diff --git a/s390x/pv-ipl.c b/s390x/pv-ipl.c
index af2cfbcf..8affeb1c 100644
--- a/s390x/pv-ipl.c
+++ b/s390x/pv-ipl.c
@@ -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);
diff --git a/s390x/spec_ex-sie.c b/s390x/spec_ex-sie.c
index e79208df..102f0345 100644
--- a/s390x/spec_ex-sie.c
+++ b/s390x/spec_ex-sie.c
@@ -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)
diff --git a/s390x/stfle-sie.c b/s390x/stfle-sie.c
index e3642078..178c6815 100644
--- a/s390x/stfle-sie.c
+++ b/s390x/stfle-sie.c
@@ -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 {
-- 
2.53.0


      parent reply	other threads:[~2026-09-01 14:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01 14:20 [kvm-unit-tests PATCH 0/2] lib: s390x: Add more snippet macros Janosch Frank
2026-09-01 14:20 ` [kvm-unit-tests PATCH 1/2] lib: s390x: snippet: Add snippet declaration macro Janosch Frank
2026-09-01 14:20 ` Janosch Frank [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260901142538.42553-3-frankja@linux.ibm.com \
    --to=frankja@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=nrb@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.