Re: [PATCH v2 1/4] KVM: s390: Replace get_zeroed_page() with kzalloc() for the STHYI buffer
From: Janosch Frank
Date: Mon Sep 07 2026 - 08:39:06 EST
On 9/6/26 10:27 AM, Mike Rapoport (Microsoft) wrote:
handle_sthyi() allocates the buffer that receives the STHYI responseYup, there's no alignment requirement anyway.
block before it is copied to the guest.
This buffer can be allocated with kmalloc() as there's nothing special
about it to go directly to the page allocator.
kmalloc() provides a better API that does not require ugly casts and
kfree() does not need to know the size of the freed object.
Performance difference between kmalloc() and __get_free_pages() is not
measurable as both allocators take an object/page from a per-CPU list for
fast path allocations.
For the slow path the performance is anyway determined by the amount of
reclaim involved rather than by what allocator is used.
The only goto in that function does not unwind anything, it merely skips
to the exit when the function code is invalid. Turn it into an early
return so that the buffer can be freed with __free(kfree).
Replace use of get_zeroed_page() with kzalloc() and free_page() with
kfree().
Assisted-by: copilot:claude-opus
Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
Reviewed-by: Janosch Frank <frankja@xxxxxxxxxxxxx>
Looking at the kernel's sthyi.c there are a couple more locations we could change:
I don't see a need for the syscall to allocate a page and the cache doesn't need page allocation either. We should even be able to have them byte aligned since they are never the destination for one of the diagnose instructions, a kvzalloc should be fine if I didn't miss something...
Diag224 needs a 4k aligned 31-bit physical address for some reason so that needs GFP_DMA. diag204 is vmallocing anyway since subcode 7 uses logical addresses.