From: Janosch Frank <frankja@linux.ibm.com>
To: pbonzini@redhat.com
Cc: kvm@vger.kernel.org, frankja@linux.ibm.com,
borntraeger@linux.ibm.com, linux-s390@vger.kernel.org,
imbrenda@linux.ibm.com, thuth@redhat.com,
Christoph Schlameuss <schlameuss@linux.ibm.com>
Subject: [kvm-unit-tests GIT PULL 03/13] lib: s390x: sie: Memory rework
Date: Mon, 24 Aug 2026 14:35:35 +0000 [thread overview]
Message-ID: <20260824143740.291583-4-frankja@linux.ibm.com> (raw)
In-Reply-To: <20260824143740.291583-1-frankja@linux.ibm.com>
Make sie_guest_create() directly alloc the guest's memory.
Also we never freed the memory that the sie library allocates as the guest
ram on destruction of the VM. Most tests reuse the VM or just leak the
memory since the standard allocation is one megabyte and tests only
use single digit numbers of VMs.
It's time to add automatic freeing to the sie library when a VM is
destroyed.
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Christoph Schlameuss <schlameuss@linux.ibm.com>
---
lib/s390x/sie.c | 5 ++++-
lib/s390x/sie.h | 2 +-
lib/s390x/snippet.h | 9 +++++----
s390x/mvpg-sie.c | 2 +-
s390x/pv-diags.c | 2 +-
s390x/pv-icptcode.c | 4 ++--
s390x/pv-ipl.c | 2 +-
s390x/sie-dat.c | 2 +-
s390x/sie.c | 13 ++++---------
s390x/spec_ex-sie.c | 2 ++
s390x/stfle-sie.c | 2 ++
11 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/lib/s390x/sie.c b/lib/s390x/sie.c
index 8757f610..ad1f2ade 100644
--- a/lib/s390x/sie.c
+++ b/lib/s390x/sie.c
@@ -122,8 +122,10 @@ void sie_guest_sca_create(struct vm *vm)
}
/* Initializes the struct vm members like the SIE control block. */
-void sie_guest_create(struct vm *vm, uint64_t guest_mem, uint64_t guest_mem_len)
+void sie_guest_create(struct vm *vm, uint64_t guest_mem_len)
{
+ void *guest_mem = sie_guest_alloc(guest_mem_len);
+
vm->sblk = alloc_page();
memset(vm->sblk, 0, PAGE_SIZE);
vm->sblk->cpuflags = CPUSTAT_ZARCH | CPUSTAT_RUNNING;
@@ -192,4 +194,5 @@ void sie_guest_destroy(struct vm *vm)
free_page(vm->sblk);
if (vm->sblk->ecb2 & ECB2_ESCA)
free_page(vm->sca);
+ free_pages((void *)virt_to_pte_phys(get_primary_page_root(), vm->guest_mem));
}
diff --git a/lib/s390x/sie.h b/lib/s390x/sie.h
index 3ec49ed0..85d691d5 100644
--- a/lib/s390x/sie.h
+++ b/lib/s390x/sie.h
@@ -59,7 +59,7 @@ static inline bool sie_is_pv(struct vm *vm)
}
void sie_guest_sca_create(struct vm *vm);
-void sie_guest_create(struct vm *vm, uint64_t guest_mem, uint64_t guest_mem_len);
+void sie_guest_create(struct vm *vm, uint64_t guest_mem_len);
void sie_guest_destroy(struct vm *vm);
uint8_t *sie_guest_alloc(uint64_t guest_size);
diff --git a/lib/s390x/snippet.h b/lib/s390x/snippet.h
index 910849aa..94688f49 100644
--- a/lib/s390x/snippet.h
+++ b/lib/s390x/snippet.h
@@ -125,11 +125,8 @@ 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)
{
- const unsigned long guest_size = SZ_1M;
- uint8_t *guest_start = sie_guest_alloc(guest_size);
-
/* Initialize the vm struct and allocate control blocks */
- sie_guest_create(vm, (uint64_t)guest_start, guest_size);
+ sie_guest_create(vm, SZ_1M);
if (is_pv) {
/* FMT4 needs a ESCA */
@@ -144,4 +141,8 @@ static inline void snippet_setup_guest(struct vm *vm, bool is_pv)
}
}
+static inline void snippet_destroy_guest(struct vm *vm)
+{
+ sie_guest_destroy(vm);
+}
#endif
diff --git a/s390x/mvpg-sie.c b/s390x/mvpg-sie.c
index 920dee29..ac33923c 100644
--- a/s390x/mvpg-sie.c
+++ b/s390x/mvpg-sie.c
@@ -117,7 +117,7 @@ int main(void)
setup_guest();
test_mvpg();
test_mvpg_pei();
- sie_guest_destroy(&vm);
+ snippet_destroy_guest(&vm);
done:
report_prefix_pop();
diff --git a/s390x/pv-diags.c b/s390x/pv-diags.c
index 09b83d59..b6f08dd2 100644
--- a/s390x/pv-diags.c
+++ b/s390x/pv-diags.c
@@ -156,7 +156,7 @@ int main(void)
test_diag_yield();
test_diag_288();
test_diag_500();
- sie_guest_destroy(&vm);
+ snippet_destroy_guest(&vm);
done:
report_prefix_pop();
diff --git a/s390x/pv-icptcode.c b/s390x/pv-icptcode.c
index 5293306b..bdef3a05 100644
--- a/s390x/pv-icptcode.c
+++ b/s390x/pv-icptcode.c
@@ -164,7 +164,7 @@ static void test_validity_handle_not_in_config(void)
/* Destroy the second vm, since we don't need it for further tests */
uv_destroy_guest(&vm2);
- sie_guest_destroy(&vm2);
+ snippet_destroy_guest(&vm2);
uv_destroy_guest(&vm);
report_prefix_pop();
@@ -368,7 +368,7 @@ int main(void)
test_validity_handle_not_in_config();
test_validity_already_running();
test_validity_timing();
- sie_guest_destroy(&vm);
+ snippet_destroy_guest(&vm);
done:
report_prefix_pop();
diff --git a/s390x/pv-ipl.c b/s390x/pv-ipl.c
index 61a1e0c0..1219573f 100644
--- a/s390x/pv-ipl.c
+++ b/s390x/pv-ipl.c
@@ -135,7 +135,7 @@ int main(void)
snippet_setup_guest(&vm, true);
test_diag_308(0);
test_diag_308(1);
- sie_guest_destroy(&vm);
+ snippet_destroy_guest(&vm);
done:
report_prefix_pop();
diff --git a/s390x/sie-dat.c b/s390x/sie-dat.c
index e40e348f..a5ff0872 100644
--- a/s390x/sie-dat.c
+++ b/s390x/sie-dat.c
@@ -101,7 +101,7 @@ int main(void)
setup_guest();
test_sie_dat();
- sie_guest_destroy(&vm);
+ snippet_destroy_guest(&vm);
done:
report_prefix_pop();
diff --git a/s390x/sie.c b/s390x/sie.c
index ce5b6069..f08564b1 100644
--- a/s390x/sie.c
+++ b/s390x/sie.c
@@ -20,7 +20,6 @@
#include <sclp.h>
#include <sie.h>
-static u8 *guest;
static u8 *guest_instr;
static struct vm vm;
@@ -70,7 +69,7 @@ static void test_epoch_ext(void)
return;
}
- guest[0] = 0x00;
+ vm.guest_mem[0] = 0x00;
memcpy(guest_instr, instr, sizeof(instr));
vm.sblk->gpsw.addr = PAGE_SIZE * 2;
@@ -82,19 +81,15 @@ static void test_epoch_ext(void)
sie(&vm);
/* ... should result in the same epoch extension here: */
- report(guest[0] == 0x47, "epdx: different epoch is visible in the guest");
+ report(vm.guest_mem[0] == 0x47, "epdx: different epoch is visible in the guest");
}
static void setup_guest(void)
{
- setup_vm();
-
- guest = sie_guest_alloc(SZ_1M);
+ sie_guest_create(&vm, HPAGE_SIZE);
/* The first two pages are the lowcore */
- guest_instr = guest + PAGE_SIZE * 2;
-
- sie_guest_create(&vm, (uint64_t)guest, HPAGE_SIZE);
+ guest_instr = vm.guest_mem + PAGE_SIZE * 2;
}
int main(void)
diff --git a/s390x/spec_ex-sie.c b/s390x/spec_ex-sie.c
index fe2f23ee..6ab4144c 100644
--- a/s390x/spec_ex-sie.c
+++ b/s390x/spec_ex-sie.c
@@ -71,6 +71,8 @@ static void test_spec_ex_sie(void)
report_info("%s", msg);
else
report_info("Did not interpret initial exception");
+
+ snippet_destroy_guest(&vm);
report_prefix_pop();
report_prefix_pop();
}
diff --git a/s390x/stfle-sie.c b/s390x/stfle-sie.c
index 21cf8ff8..8df1185c 100644
--- a/s390x/stfle-sie.c
+++ b/s390x/stfle-sie.c
@@ -133,6 +133,8 @@ int main(int argc, char **argv)
setup_guest();
if (run_format_0)
test_stfle_format_0();
+
+ snippet_destroy_guest(&vm);
out:
return report_summary();
}
--
2.53.0
next prev parent reply other threads:[~2026-08-24 14:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 14:35 [kvm-unit-tests GIT PULL 00/13] s390x: stflei test, fixes and sie lib rework Janosch Frank
2026-08-24 14:35 ` [kvm-unit-tests GIT PULL 01/13] lib: s390x: Add function to get page root Janosch Frank
2026-08-24 14:35 ` [kvm-unit-tests GIT PULL 02/13] lib: s390x: sie: Allocate physical guest memory via memalign Janosch Frank
2026-08-24 14:35 ` Janosch Frank [this message]
2026-08-24 14:35 ` [kvm-unit-tests GIT PULL 04/13] lib: s390x: snippet: Add function to create a guest of specific length Janosch Frank
2026-08-24 14:35 ` [kvm-unit-tests GIT PULL 05/13] s390x: snippets: Add reset_guest() to lib Janosch Frank
2026-08-24 14:35 ` [kvm-unit-tests GIT PULL 06/13] s390x: sclp: Remove unnecessary padding from struct sclp_facilities Janosch Frank
2026-08-24 14:35 ` [kvm-unit-tests GIT PULL 07/13] s390x: sclp: Check sclp byte before reading feature bits Janosch Frank
2026-08-24 14:35 ` [kvm-unit-tests GIT PULL 08/13] s390x: sclp: Use sclp_feat_check directly to read DIAG318 feature bit Janosch Frank
2026-08-24 14:35 ` [kvm-unit-tests GIT PULL 09/13] s390x: sclp: Add detection of alternate STFLE facilities Janosch Frank
2026-08-24 14:35 ` [kvm-unit-tests GIT PULL 10/13] s390x: Add test for STFLE interpretive execution (format-2) Janosch Frank
2026-08-24 14:35 ` [kvm-unit-tests GIT PULL 11/13] s390x: stsi: regression test for the STSI 3.2.2 count clamp Janosch Frank
2026-08-24 14:35 ` [kvm-unit-tests GIT PULL 12/13] s390x: unittests: Reenable tcg for migration tests Janosch Frank
2026-08-24 14:35 ` [kvm-unit-tests GIT PULL 13/13] s390x: skey: Fence TCG protection checks Janosch Frank
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=20260824143740.291583-4-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=pbonzini@redhat.com \
--cc=schlameuss@linux.ibm.com \
--cc=thuth@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox