[kvm-unit-tests PATCH v2 2/4] lib: s390x: sie: Allocate physical guest memory via memalign

Janosch Frank
2026-04-20T08:49:46Z

alloc_pages_flags() alignes the allocation on the same order as its
requested size. Since we use virtual memory for SIE we can instead
align to 1MB by using memalign() which is less wasteful.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
lib/s390x/sie.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/s390x/sie.c b/lib/s390x/sie.c
index 47d4cdde..b1b0a8a0 100644
--- a/lib/s390x/sie.c
+++ b/lib/s390x/sie.c
@@ -171,7 +171,8 @@ uint8_t *sie_guest_alloc(uint64_t guest_size)
guest_virt = (uint8_t *)ALIGN(get_ram_size() + guest_counter * 4UL * SZ_1G, SZ_2G);
guest_counter++;

- guest_phys = alloc_pages(get_order(guest_size) - 12);
+ guest_phys = memalign_pages_flags(SZ_1M, guest_size, 0);
+ assert(guest_phys);
/*
* Establish a new mapping of the guest memory so it can be 2GB aligned
* without actually requiring 2GB physical memory.
--
2.51.0