[kvm-unit-tests 4/5] lib: s390x: snippet: Add function to create a guest of specific length

Janosch Frank
2026-04-15T08:52:38Z

While 1MB is certainly enough to store the guest code, it's often not
enough for memory tests. Let's add a separate function to allow
arbitrary guest sizes.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
lib/s390x/snippet.h | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/lib/s390x/snippet.h b/lib/s390x/snippet.h
index 910849aa..c58ae135 100644
--- a/lib/s390x/snippet.h
+++ b/lib/s390x/snippet.h
@@ -123,13 +123,17 @@ static inline void snippet_pv_init(struct vm *vm, const char *gbin,
}

/* Allocates and sets up a snippet based guest */
-static inline void snippet_setup_guest(struct vm *vm, bool is_pv)
+static inline void snippet_setup_guest_len(struct vm *vm, bool is_pv,
+ unsigned long len)
{
- const unsigned long guest_size = SZ_1M;
- uint8_t *guest_start = sie_guest_alloc(guest_size);
+ uint8_t *guest_start;
+
+ /* Guest sizes are specified in megabyte chunks */
+ assert(!(len & ~HPAGE_MASK));
+ guest_start = sie_guest_alloc(len);

/* Initialize the vm struct and allocate control blocks */
- sie_guest_create(vm, (uint64_t)guest_start, guest_size);
+ sie_guest_create(vm, (uint64_t)guest_start, len);

if (is_pv) {
/* FMT4 needs a ESCA */
@@ -144,4 +148,10 @@ static inline void snippet_setup_guest(struct vm *vm, bool is_pv)
}
}

+/* Allocates and sets up a snippet based guest */
+static inline void snippet_setup_guest(struct vm *vm, bool is_pv)
+{
+ snippet_setup_guest_len(vm, is_pv, SZ_1M);
+}
+
#endif
--
2.51.0