* [PATCH 1/6] s390/con3270: replace __get_free_page() with kmalloc()
2026-05-28 7:09 [PATCH 0/6] s390/drivers: replace __get_free_pages() call with kmalloc() Mike Rapoport (Microsoft)
@ 2026-05-28 7:09 ` Mike Rapoport (Microsoft)
2026-05-29 10:26 ` Heiko Carstens
2026-05-28 7:09 ` [PATCH 2/6] s390/dasd: replace get_zeroed_page() with kzalloc() Mike Rapoport (Microsoft)
` (5 subsequent siblings)
6 siblings, 1 reply; 23+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-05-28 7:09 UTC (permalink / raw)
To: Alexander Gordeev, Heiko Carstens, Vasily Gorbik
Cc: Alexandra Winter, Aswin Karuvally, Christian Borntraeger,
Harald Freudenberger, Holger Dengler, Jan Hoeppner, Mike Rapoport,
Stefan Haberland, Sven Schnelle, linux-s390
con3270_alloc_view() allocates a staging buffer used to assemble
3270 datastream content before it is copied into channel program
requests.
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.
Replace use of __get_free_page() with kmalloc() and free_page() with
kfree().
Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/s390/char/con3270.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/s390/char/con3270.c b/drivers/s390/char/con3270.c
index 644d3679748d..c39da2ec22b4 100644
--- a/drivers/s390/char/con3270.c
+++ b/drivers/s390/char/con3270.c
@@ -880,7 +880,7 @@ static void tty3270_free_view(struct tty3270 *tp)
raw3270_request_free(tp->kreset);
raw3270_request_free(tp->read);
raw3270_request_free(tp->write);
- free_page((unsigned long)tp->converted_line);
+ kfree(tp->converted_line);
tty_port_destroy(&tp->port);
kfree(tp);
}
@@ -1063,7 +1063,7 @@ static void tty3270_free(struct raw3270_view *view)
timer_delete_sync(&tp->timer);
tty3270_free_screen(tp->screen, tp->allocated_lines);
- free_page((unsigned long)tp->converted_line);
+ kfree(tp->converted_line);
kfree(tp->input);
kfree(tp->prompt);
tty3270_free_view(tp);
@@ -1121,7 +1121,7 @@ tty3270_create_view(int index, struct tty3270 **newtp)
goto out_put_view;
}
- tp->converted_line = (void *)__get_free_page(GFP_KERNEL);
+ tp->converted_line = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!tp->converted_line) {
rc = -ENOMEM;
goto out_free_screen;
@@ -1167,7 +1167,7 @@ tty3270_create_view(int index, struct tty3270 **newtp)
out_free_input:
kfree(tp->input);
out_free_converted_line:
- free_page((unsigned long)tp->converted_line);
+ kfree(tp->converted_line);
out_free_screen:
tty3270_free_screen(tp->screen, tp->view.rows);
out_put_view:
--
2.53.0
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH 1/6] s390/con3270: replace __get_free_page() with kmalloc()
2026-05-28 7:09 ` [PATCH 1/6] s390/con3270: replace __get_free_page() " Mike Rapoport (Microsoft)
@ 2026-05-29 10:26 ` Heiko Carstens
0 siblings, 0 replies; 23+ messages in thread
From: Heiko Carstens @ 2026-05-29 10:26 UTC (permalink / raw)
To: Mike Rapoport (Microsoft)
Cc: Alexander Gordeev, Vasily Gorbik, Alexandra Winter,
Aswin Karuvally, Christian Borntraeger, Harald Freudenberger,
Holger Dengler, Jan Hoeppner, Stefan Haberland, Sven Schnelle,
linux-s390
On Thu, May 28, 2026 at 10:09:49AM +0300, Mike Rapoport (Microsoft) wrote:
> con3270_alloc_view() allocates a staging buffer used to assemble
> 3270 datastream content before it is copied into channel program
> requests.
>
> 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.
>
> Replace use of __get_free_page() with kmalloc() and free_page() with
> kfree().
>
> Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> drivers/s390/char/con3270.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
Reviewed-by: Heiko Carstens <hca@linux.ibm.com>
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 2/6] s390/dasd: replace get_zeroed_page() with kzalloc()
2026-05-28 7:09 [PATCH 0/6] s390/drivers: replace __get_free_pages() call with kmalloc() Mike Rapoport (Microsoft)
2026-05-28 7:09 ` [PATCH 1/6] s390/con3270: replace __get_free_page() " Mike Rapoport (Microsoft)
@ 2026-05-28 7:09 ` Mike Rapoport (Microsoft)
2026-05-29 10:15 ` Heiko Carstens
2026-05-28 7:09 ` [PATCH 3/6] s390/hvc_iucv: " Mike Rapoport (Microsoft)
` (4 subsequent siblings)
6 siblings, 1 reply; 23+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-05-28 7:09 UTC (permalink / raw)
To: Alexander Gordeev, Heiko Carstens, Vasily Gorbik
Cc: Alexandra Winter, Aswin Karuvally, Christian Borntraeger,
Harald Freudenberger, Holger Dengler, Jan Hoeppner, Mike Rapoport,
Stefan Haberland, Sven Schnelle, linux-s390
DASD driver uses get_zeroed_page() to allocate pages for the Extended Error
Reporting software ring buffer and for a scratch buffer for formatting
sense dump diagnostic text.
These buffers 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.
Replace use of get_zeroed_page() with kzalloc() and free_page() with
kfree().
Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/s390/block/dasd_eckd.c | 12 ++++++------
drivers/s390/block/dasd_eer.c | 4 ++--
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
index 14e58c336baa..3d6cb07e5217 100644
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -5569,7 +5569,7 @@ static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
dev = &device->cdev->dev;
- page = (char *) get_zeroed_page(GFP_ATOMIC);
+ page = kzalloc(PAGE_SIZE, GFP_ATOMIC);
if (page == NULL) {
DBF_DEV_EVENT(DBF_WARNING, device, "%s",
"No memory to dump sense data\n");
@@ -5644,7 +5644,7 @@ static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
}
dasd_eckd_dump_ccw_range(device, from, last, page + len);
}
- free_page((unsigned long) page);
+ kfree(page);
}
@@ -5659,7 +5659,7 @@ static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
struct tsb *tsb;
u8 *sense, *rcq;
- page = (char *) get_zeroed_page(GFP_ATOMIC);
+ page = kzalloc(PAGE_SIZE, GFP_ATOMIC);
if (page == NULL) {
DBF_DEV_EVENT(DBF_WARNING, device, " %s",
"No memory to dump sense data");
@@ -5759,7 +5759,7 @@ static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
sprintf(page + len, "SORRY - NO TSB DATA AVAILABLE\n");
}
dev_err(&device->cdev->dev, "%s", page);
- free_page((unsigned long) page);
+ kfree(page);
}
static void dasd_eckd_dump_sense(struct dasd_device *device,
@@ -6958,7 +6958,7 @@ dasd_eckd_init(void)
kfree(pe_handler_worker);
kfree(dasd_reserve_req);
kfree(dasd_vol_info_req);
- free_page((unsigned long)rawpadpage);
+ kfree(rawpadpage);
}
return ret;
}
@@ -6969,7 +6969,7 @@ dasd_eckd_cleanup(void)
ccw_driver_unregister(&dasd_eckd_driver);
kfree(pe_handler_worker);
kfree(dasd_reserve_req);
- free_page((unsigned long)rawpadpage);
+ kfree(rawpadpage);
}
module_init(dasd_eckd_init);
diff --git a/drivers/s390/block/dasd_eer.c b/drivers/s390/block/dasd_eer.c
index 78d66e2711cd..e96d1805b7bb 100644
--- a/drivers/s390/block/dasd_eer.c
+++ b/drivers/s390/block/dasd_eer.c
@@ -211,7 +211,7 @@ static void dasd_eer_free_buffer_pages(char **buf, int no_pages)
int i;
for (i = 0; i < no_pages; i++)
- free_page((unsigned long) buf[i]);
+ kfree(buf[i]);
}
/*
@@ -222,7 +222,7 @@ static int dasd_eer_allocate_buffer_pages(char **buf, int no_pages)
int i;
for (i = 0; i < no_pages; i++) {
- buf[i] = (char *) get_zeroed_page(GFP_KERNEL);
+ buf[i] = kzalloc(PAGE_SIZE, GFP_KERNEL);
if (!buf[i]) {
dasd_eer_free_buffer_pages(buf, i);
return -ENOMEM;
--
2.53.0
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH 2/6] s390/dasd: replace get_zeroed_page() with kzalloc()
2026-05-28 7:09 ` [PATCH 2/6] s390/dasd: replace get_zeroed_page() with kzalloc() Mike Rapoport (Microsoft)
@ 2026-05-29 10:15 ` Heiko Carstens
2026-05-31 10:35 ` Mike Rapoport
0 siblings, 1 reply; 23+ messages in thread
From: Heiko Carstens @ 2026-05-29 10:15 UTC (permalink / raw)
To: Mike Rapoport (Microsoft)
Cc: Alexander Gordeev, Vasily Gorbik, Alexandra Winter,
Aswin Karuvally, Christian Borntraeger, Harald Freudenberger,
Holger Dengler, Jan Hoeppner, Stefan Haberland, Sven Schnelle,
linux-s390
On Thu, May 28, 2026 at 10:09:50AM +0300, Mike Rapoport (Microsoft) wrote:
> DASD driver uses get_zeroed_page() to allocate pages for the Extended Error
> Reporting software ring buffer and for a scratch buffer for formatting
> sense dump diagnostic text.
>
> These buffers 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.
>
> Replace use of get_zeroed_page() with kzalloc() and free_page() with
> kfree().
>
> Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> drivers/s390/block/dasd_eckd.c | 12 ++++++------
> drivers/s390/block/dasd_eer.c | 4 ++--
> 2 files changed, 8 insertions(+), 8 deletions(-)
...
> static void dasd_eckd_dump_sense(struct dasd_device *device,
> @@ -6958,7 +6958,7 @@ dasd_eckd_init(void)
> kfree(pe_handler_worker);
> kfree(dasd_reserve_req);
> kfree(dasd_vol_info_req);
> - free_page((unsigned long)rawpadpage);
> + kfree(rawpadpage);
> }
> return ret;
> }
> @@ -6969,7 +6969,7 @@ dasd_eckd_cleanup(void)
> ccw_driver_unregister(&dasd_eckd_driver);
> kfree(pe_handler_worker);
> kfree(dasd_reserve_req);
> - free_page((unsigned long)rawpadpage);
> + kfree(rawpadpage);
> }
This is not correct. The allocation is still done with __get_free_page().
I'm not sure about the whole approach / effort, since this allows for subtle
bugs where pages are allocated and freed at non-obvious locations. All of that
works now, but these conversions may lead to subtle bugs (this particular one
is not subtle and easy to spot).
Is the net gain of this conversion really worth it?
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 2/6] s390/dasd: replace get_zeroed_page() with kzalloc()
2026-05-29 10:15 ` Heiko Carstens
@ 2026-05-31 10:35 ` Mike Rapoport
0 siblings, 0 replies; 23+ messages in thread
From: Mike Rapoport @ 2026-05-31 10:35 UTC (permalink / raw)
To: Heiko Carstens
Cc: Alexander Gordeev, Vasily Gorbik, Alexandra Winter,
Aswin Karuvally, Christian Borntraeger, Harald Freudenberger,
Holger Dengler, Jan Hoeppner, Stefan Haberland, Sven Schnelle,
linux-s390
On Fri, May 29, 2026 at 12:15:22PM +0200, Heiko Carstens wrote:
> On Thu, May 28, 2026 at 10:09:50AM +0300, Mike Rapoport (Microsoft) wrote:
> > DASD driver uses get_zeroed_page() to allocate pages for the Extended Error
> > Reporting software ring buffer and for a scratch buffer for formatting
> > sense dump diagnostic text.
> >
> > These buffers 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.
> >
> > Replace use of get_zeroed_page() with kzalloc() and free_page() with
> > kfree().
> >
> > Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> > ---
> > drivers/s390/block/dasd_eckd.c | 12 ++++++------
> > drivers/s390/block/dasd_eer.c | 4 ++--
> > 2 files changed, 8 insertions(+), 8 deletions(-)
>
> ...
>
> > static void dasd_eckd_dump_sense(struct dasd_device *device,
> > @@ -6958,7 +6958,7 @@ dasd_eckd_init(void)
> > kfree(pe_handler_worker);
> > kfree(dasd_reserve_req);
> > kfree(dasd_vol_info_req);
> > - free_page((unsigned long)rawpadpage);
> > + kfree(rawpadpage);
> > }
> > return ret;
> > }
> > @@ -6969,7 +6969,7 @@ dasd_eckd_cleanup(void)
> > ccw_driver_unregister(&dasd_eckd_driver);
> > kfree(pe_handler_worker);
> > kfree(dasd_reserve_req);
> > - free_page((unsigned long)rawpadpage);
> > + kfree(rawpadpage);
> > }
>
> This is not correct. The allocation is still done with __get_free_page().
Right, I didn't mean to touch rawpadpage yet.
cherry-pick from the large set went wrong :(
> I'm not sure about the whole approach / effort, since this allows for subtle
> bugs where pages are allocated and freed at non-obvious locations. All of that
> works now, but these conversions may lead to subtle bugs (this particular one
> is not subtle and easy to spot).
>
> Is the net gain of this conversion really worth it?
My initial intention a few month ago was to remove ugly casts [1], but then
willy pointed out that Linus objected to something like this [2] and it
looks like more than a decade old technical debt.
Largely, anything that doesn't need struct page (or a memdesc in the
future) should just use kmalloc() or kvmalloc() to allocate memory.
kmalloc() guarantees alignment, physical contiguity and working
virt_to_phys() and beside nicer API that returns void * on alloc and
doesn't require to know the allocation size on free, kmalloc() provides
better debugging capabilities than page allocator.
Another thing is that touching these allocation sites gives the reviewers
opportunity to see if a PAGE_SIZE buffer is actually needed or maybe
another size is appropriate.
For larger allocations that don't need physically contiguous memory
kvmalloc() can be a better option that __get_free_pages() because under
memory pressure it's is easier to allocate several order-0 pages than a
physically contiguous chunk with the same number of pages.
And last, but not least, removing needless calls to page allocator should
help with memdesc (aka project folio) conversion. There will be way less
places to audit to see if the user was actually using struct page.
[1] https://lore.kernel.org/all/20251018093002.3660549-1-rppt@kernel.org/
[2] https://lore.kernel.org/all/CA+55aFwp4iy4rtX2gE2WjBGFL=NxMVnoFeHqYa2j1dYOMMGqxg@mail.gmail.com/
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 3/6] s390/hvc_iucv: replace get_zeroed_page() with kzalloc()
2026-05-28 7:09 [PATCH 0/6] s390/drivers: replace __get_free_pages() call with kmalloc() Mike Rapoport (Microsoft)
2026-05-28 7:09 ` [PATCH 1/6] s390/con3270: replace __get_free_page() " Mike Rapoport (Microsoft)
2026-05-28 7:09 ` [PATCH 2/6] s390/dasd: replace get_zeroed_page() with kzalloc() Mike Rapoport (Microsoft)
@ 2026-05-28 7:09 ` Mike Rapoport (Microsoft)
2026-05-29 10:26 ` Heiko Carstens
2026-05-28 7:09 ` [PATCH 4/6] s390/qeth: " Mike Rapoport (Microsoft)
` (3 subsequent siblings)
6 siblings, 1 reply; 23+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-05-28 7:09 UTC (permalink / raw)
To: Alexander Gordeev, Heiko Carstens, Vasily Gorbik
Cc: Alexandra Winter, Aswin Karuvally, Christian Borntraeger,
Harald Freudenberger, Holger Dengler, Jan Hoeppner, Mike Rapoport,
Stefan Haberland, Sven Schnelle, linux-s390
hvc_iucv_alloc() allocates a send staging buffer for accumulating
outbound terminal characters before they are copied into a separate
IUCV message buffer for transmission to the hypervisor. The staging
buffer itself is never passed to any IUCV function.
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.
Replace use of get_zeroed_page() with kzalloc() and free_page() with
kfree().
Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/tty/hvc/hvc_iucv.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/tty/hvc/hvc_iucv.c b/drivers/tty/hvc/hvc_iucv.c
index 37db8a3e5158..d29a86d161f6 100644
--- a/drivers/tty/hvc/hvc_iucv.c
+++ b/drivers/tty/hvc/hvc_iucv.c
@@ -1060,7 +1060,7 @@ static int __init hvc_iucv_alloc(int id, unsigned int is_console)
INIT_DELAYED_WORK(&priv->sndbuf_work, hvc_iucv_sndbuf_work);
init_waitqueue_head(&priv->sndbuf_waitq);
- priv->sndbuf = (void *) get_zeroed_page(GFP_KERNEL);
+ priv->sndbuf = kzalloc(PAGE_SIZE, GFP_KERNEL);
if (!priv->sndbuf) {
kfree(priv);
return -ENOMEM;
@@ -1103,7 +1103,7 @@ static int __init hvc_iucv_alloc(int id, unsigned int is_console)
out_error_dev:
hvc_remove(priv->hvc);
out_error_hvc:
- free_page((unsigned long) priv->sndbuf);
+ kfree(priv->sndbuf);
kfree(priv);
return rc;
@@ -1116,7 +1116,7 @@ static void __init hvc_iucv_destroy(struct hvc_iucv_private *priv)
{
hvc_remove(priv->hvc);
device_unregister(priv->dev);
- free_page((unsigned long) priv->sndbuf);
+ kfree(priv->sndbuf);
kfree(priv);
}
--
2.53.0
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH 3/6] s390/hvc_iucv: replace get_zeroed_page() with kzalloc()
2026-05-28 7:09 ` [PATCH 3/6] s390/hvc_iucv: " Mike Rapoport (Microsoft)
@ 2026-05-29 10:26 ` Heiko Carstens
0 siblings, 0 replies; 23+ messages in thread
From: Heiko Carstens @ 2026-05-29 10:26 UTC (permalink / raw)
To: Mike Rapoport (Microsoft)
Cc: Alexander Gordeev, Vasily Gorbik, Alexandra Winter,
Aswin Karuvally, Christian Borntraeger, Harald Freudenberger,
Holger Dengler, Jan Hoeppner, Stefan Haberland, Sven Schnelle,
linux-s390
On Thu, May 28, 2026 at 10:09:51AM +0300, Mike Rapoport (Microsoft) wrote:
> hvc_iucv_alloc() allocates a send staging buffer for accumulating
> outbound terminal characters before they are copied into a separate
> IUCV message buffer for transmission to the hypervisor. The staging
> buffer itself is never passed to any IUCV function.
>
> 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.
>
> Replace use of get_zeroed_page() with kzalloc() and free_page() with
> kfree().
>
> Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> drivers/tty/hvc/hvc_iucv.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
Reviewed-by: Heiko Carstens <hca@linux.ibm.com>
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 4/6] s390/qeth: replace get_zeroed_page() with kzalloc()
2026-05-28 7:09 [PATCH 0/6] s390/drivers: replace __get_free_pages() call with kmalloc() Mike Rapoport (Microsoft)
` (2 preceding siblings ...)
2026-05-28 7:09 ` [PATCH 3/6] s390/hvc_iucv: " Mike Rapoport (Microsoft)
@ 2026-05-28 7:09 ` Mike Rapoport (Microsoft)
2026-05-28 14:17 ` Alexandra Winter
` (2 more replies)
2026-05-28 7:09 ` [PATCH 5/6] s390/trng: replace __get_free_page() with kmalloc() Mike Rapoport (Microsoft)
` (2 subsequent siblings)
6 siblings, 3 replies; 23+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-05-28 7:09 UTC (permalink / raw)
To: Alexander Gordeev, Heiko Carstens, Vasily Gorbik
Cc: Alexandra Winter, Aswin Karuvally, Christian Borntraeger,
Harald Freudenberger, Holger Dengler, Jan Hoeppner, Mike Rapoport,
Stefan Haberland, Sven Schnelle, linux-s390
qeth_get_trap_id() allocates a temporary buffer for STSI system
information queries used to build trap identification strings.
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.
Replace use of get_zeroed_page() with kzalloc() and free_page() with
kfree().
Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/s390/net/qeth_core_main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index cf5f760d0e02..9274087557ec 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -3362,7 +3362,7 @@ static int qeth_query_setdiagass(struct qeth_card *card)
static void qeth_get_trap_id(struct qeth_card *card, struct qeth_trap_id *tid)
{
- unsigned long info = get_zeroed_page(GFP_KERNEL);
+ unsigned long info = (unsigned long)kzalloc(PAGE_SIZE, GFP_KERNEL);
struct sysinfo_2_2_2 *info222 = (struct sysinfo_2_2_2 *)info;
struct sysinfo_3_2_2 *info322 = (struct sysinfo_3_2_2 *)info;
struct ccw_dev_id ccwid;
@@ -3381,7 +3381,7 @@ static void qeth_get_trap_id(struct qeth_card *card, struct qeth_trap_id *tid)
EBCASC(info322->vm[0].name, sizeof(info322->vm[0].name));
memcpy(tid->vmname, info322->vm[0].name, sizeof(tid->vmname));
}
- free_page(info);
+ kfree((void *)info);
}
static int qeth_hw_trap_cb(struct qeth_card *card,
--
2.53.0
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH 4/6] s390/qeth: replace get_zeroed_page() with kzalloc()
2026-05-28 7:09 ` [PATCH 4/6] s390/qeth: " Mike Rapoport (Microsoft)
@ 2026-05-28 14:17 ` Alexandra Winter
2026-05-29 10:23 ` Heiko Carstens
2026-05-29 11:09 ` Heiko Carstens
2 siblings, 0 replies; 23+ messages in thread
From: Alexandra Winter @ 2026-05-28 14:17 UTC (permalink / raw)
To: Mike Rapoport (Microsoft), Alexander Gordeev, Heiko Carstens,
Vasily Gorbik
Cc: Aswin Karuvally, Christian Borntraeger, Harald Freudenberger,
Holger Dengler, Jan Hoeppner, Stefan Haberland, Sven Schnelle,
linux-s390
On 28.05.26 09:09, Mike Rapoport (Microsoft) wrote:
> qeth_get_trap_id() allocates a temporary buffer for STSI system
> information queries used to build trap identification strings.
>
> 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.
>
> Replace use of get_zeroed_page() with kzalloc() and free_page() with
> kfree().
>
> Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
Acked-by: Alexandra Winter <wintera@linux.ibm.com>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 4/6] s390/qeth: replace get_zeroed_page() with kzalloc()
2026-05-28 7:09 ` [PATCH 4/6] s390/qeth: " Mike Rapoport (Microsoft)
2026-05-28 14:17 ` Alexandra Winter
@ 2026-05-29 10:23 ` Heiko Carstens
2026-05-31 10:17 ` Mike Rapoport
2026-05-29 11:09 ` Heiko Carstens
2 siblings, 1 reply; 23+ messages in thread
From: Heiko Carstens @ 2026-05-29 10:23 UTC (permalink / raw)
To: Mike Rapoport (Microsoft)
Cc: Alexander Gordeev, Vasily Gorbik, Alexandra Winter,
Aswin Karuvally, Christian Borntraeger, Harald Freudenberger,
Holger Dengler, Jan Hoeppner, Stefan Haberland, Sven Schnelle,
linux-s390
On Thu, May 28, 2026 at 10:09:52AM +0300, Mike Rapoport (Microsoft) wrote:
> qeth_get_trap_id() allocates a temporary buffer for STSI system
> information queries used to build trap identification strings.
>
> 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.
>
> Replace use of get_zeroed_page() with kzalloc() and free_page() with
> kfree().
>
> Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> drivers/s390/net/qeth_core_main.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
> index cf5f760d0e02..9274087557ec 100644
> --- a/drivers/s390/net/qeth_core_main.c
> +++ b/drivers/s390/net/qeth_core_main.c
> @@ -3362,7 +3362,7 @@ static int qeth_query_setdiagass(struct qeth_card *card)
>
> static void qeth_get_trap_id(struct qeth_card *card, struct qeth_trap_id *tid)
> {
> - unsigned long info = get_zeroed_page(GFP_KERNEL);
> + unsigned long info = (unsigned long)kzalloc(PAGE_SIZE, GFP_KERNEL);
> struct sysinfo_2_2_2 *info222 = (struct sysinfo_2_2_2 *)info;
> struct sysinfo_3_2_2 *info322 = (struct sysinfo_3_2_2 *)info;
> struct ccw_dev_id ccwid;
> @@ -3381,7 +3381,7 @@ static void qeth_get_trap_id(struct qeth_card *card, struct qeth_trap_id *tid)
> EBCASC(info322->vm[0].name, sizeof(info322->vm[0].name));
> memcpy(tid->vmname, info322->vm[0].name, sizeof(tid->vmname));
> }
> - free_page(info);
> + kfree((void *)info);
Speaking of ugly casts, which seems to be one of the main motivations
of this approach: the above adds casts instead of removing them :)
So I guess the below should be merged into your patch to get some
improvement:
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index 9274087557ec..20fb0d2e02a9 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -3362,9 +3362,9 @@ static int qeth_query_setdiagass(struct qeth_card *card)
static void qeth_get_trap_id(struct qeth_card *card, struct qeth_trap_id *tid)
{
- unsigned long info = (unsigned long)kzalloc(PAGE_SIZE, GFP_KERNEL);
- struct sysinfo_2_2_2 *info222 = (struct sysinfo_2_2_2 *)info;
- struct sysinfo_3_2_2 *info322 = (struct sysinfo_3_2_2 *)info;
+ void *info = kzalloc(PAGE_SIZE, GFP_KERNEL);
+ struct sysinfo_2_2_2 *info222 = info;
+ struct sysinfo_3_2_2 *info322 = info;
struct ccw_dev_id ccwid;
int level;
@@ -3381,7 +3381,7 @@ static void qeth_get_trap_id(struct qeth_card *card, struct qeth_trap_id *tid)
EBCASC(info322->vm[0].name, sizeof(info322->vm[0].name));
memcpy(tid->vmname, info322->vm[0].name, sizeof(tid->vmname));
}
- kfree((void *)info);
+ kfree(info);
}
static int qeth_hw_trap_cb(struct qeth_card *card,
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH 4/6] s390/qeth: replace get_zeroed_page() with kzalloc()
2026-05-29 10:23 ` Heiko Carstens
@ 2026-05-31 10:17 ` Mike Rapoport
0 siblings, 0 replies; 23+ messages in thread
From: Mike Rapoport @ 2026-05-31 10:17 UTC (permalink / raw)
To: Heiko Carstens
Cc: Alexander Gordeev, Vasily Gorbik, Alexandra Winter,
Aswin Karuvally, Christian Borntraeger, Harald Freudenberger,
Holger Dengler, Jan Hoeppner, Stefan Haberland, Sven Schnelle,
linux-s390
On Fri, May 29, 2026 at 12:23:45PM +0200, Heiko Carstens wrote:
> On Thu, May 28, 2026 at 10:09:52AM +0300, Mike Rapoport (Microsoft) wrote:
> > qeth_get_trap_id() allocates a temporary buffer for STSI system
> > information queries used to build trap identification strings.
> >
> > 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.
> >
> > Replace use of get_zeroed_page() with kzalloc() and free_page() with
> > kfree().
> >
> > Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> > ---
> > drivers/s390/net/qeth_core_main.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
> > index cf5f760d0e02..9274087557ec 100644
> > --- a/drivers/s390/net/qeth_core_main.c
> > +++ b/drivers/s390/net/qeth_core_main.c
> > @@ -3362,7 +3362,7 @@ static int qeth_query_setdiagass(struct qeth_card *card)
> >
> > static void qeth_get_trap_id(struct qeth_card *card, struct qeth_trap_id *tid)
> > {
> > - unsigned long info = get_zeroed_page(GFP_KERNEL);
> > + unsigned long info = (unsigned long)kzalloc(PAGE_SIZE, GFP_KERNEL);
> > struct sysinfo_2_2_2 *info222 = (struct sysinfo_2_2_2 *)info;
> > struct sysinfo_3_2_2 *info322 = (struct sysinfo_3_2_2 *)info;
> > struct ccw_dev_id ccwid;
> > @@ -3381,7 +3381,7 @@ static void qeth_get_trap_id(struct qeth_card *card, struct qeth_trap_id *tid)
> > EBCASC(info322->vm[0].name, sizeof(info322->vm[0].name));
> > memcpy(tid->vmname, info322->vm[0].name, sizeof(tid->vmname));
> > }
> > - free_page(info);
> > + kfree((void *)info);
>
> Speaking of ugly casts, which seems to be one of the main motivations
> of this approach: the above adds casts instead of removing them :)
Hmm, I'm sure I made this change. Seems like a rebase fallout :(
> So I guess the below should be merged into your patch to get some
> improvement:
>
> diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
> index 9274087557ec..20fb0d2e02a9 100644
> --- a/drivers/s390/net/qeth_core_main.c
> +++ b/drivers/s390/net/qeth_core_main.c
> @@ -3362,9 +3362,9 @@ static int qeth_query_setdiagass(struct qeth_card *card)
>
> static void qeth_get_trap_id(struct qeth_card *card, struct qeth_trap_id *tid)
> {
> - unsigned long info = (unsigned long)kzalloc(PAGE_SIZE, GFP_KERNEL);
> - struct sysinfo_2_2_2 *info222 = (struct sysinfo_2_2_2 *)info;
> - struct sysinfo_3_2_2 *info322 = (struct sysinfo_3_2_2 *)info;
> + void *info = kzalloc(PAGE_SIZE, GFP_KERNEL);
> + struct sysinfo_2_2_2 *info222 = info;
> + struct sysinfo_3_2_2 *info322 = info;
> struct ccw_dev_id ccwid;
> int level;
>
> @@ -3381,7 +3381,7 @@ static void qeth_get_trap_id(struct qeth_card *card, struct qeth_trap_id *tid)
> EBCASC(info322->vm[0].name, sizeof(info322->vm[0].name));
> memcpy(tid->vmname, info322->vm[0].name, sizeof(tid->vmname));
> }
> - kfree((void *)info);
> + kfree(info);
> }
>
> static int qeth_hw_trap_cb(struct qeth_card *card,
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 4/6] s390/qeth: replace get_zeroed_page() with kzalloc()
2026-05-28 7:09 ` [PATCH 4/6] s390/qeth: " Mike Rapoport (Microsoft)
2026-05-28 14:17 ` Alexandra Winter
2026-05-29 10:23 ` Heiko Carstens
@ 2026-05-29 11:09 ` Heiko Carstens
2026-05-29 11:15 ` Vlastimil Babka (SUSE)
2 siblings, 1 reply; 23+ messages in thread
From: Heiko Carstens @ 2026-05-29 11:09 UTC (permalink / raw)
To: Mike Rapoport (Microsoft)
Cc: Alexander Gordeev, Vasily Gorbik, Alexandra Winter,
Aswin Karuvally, Christian Borntraeger, Harald Freudenberger,
Holger Dengler, Jan Hoeppner, Stefan Haberland, Sven Schnelle,
linux-s390, Vlastimil Babka
On Thu, May 28, 2026 at 10:09:52AM +0300, Mike Rapoport (Microsoft) wrote:
> qeth_get_trap_id() allocates a temporary buffer for STSI system
> information queries used to build trap identification strings.
>
> 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.
>
> Replace use of get_zeroed_page() with kzalloc() and free_page() with
> kfree().
>
> Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> drivers/s390/net/qeth_core_main.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
> index cf5f760d0e02..9274087557ec 100644
> --- a/drivers/s390/net/qeth_core_main.c
> +++ b/drivers/s390/net/qeth_core_main.c
> @@ -3362,7 +3362,7 @@ static int qeth_query_setdiagass(struct qeth_card *card)
>
> static void qeth_get_trap_id(struct qeth_card *card, struct qeth_trap_id *tid)
> {
> - unsigned long info = get_zeroed_page(GFP_KERNEL);
> + unsigned long info = (unsigned long)kzalloc(PAGE_SIZE, GFP_KERNEL);
> struct sysinfo_2_2_2 *info222 = (struct sysinfo_2_2_2 *)info;
> struct sysinfo_3_2_2 *info322 = (struct sysinfo_3_2_2 *)info;
> struct ccw_dev_id ccwid;
> @@ -3381,7 +3381,7 @@ static void qeth_get_trap_id(struct qeth_card *card, struct qeth_trap_id *tid)
> EBCASC(info322->vm[0].name, sizeof(info322->vm[0].name));
> memcpy(tid->vmname, info322->vm[0].name, sizeof(tid->vmname));
> }
> - free_page(info);
> + kfree((void *)info);
> }
Hm, another thing is that Sashiko claims that kmalloc allocations are not
necessarily correctly aligned when slab debugging or KASAN is enabled [1].
I believe that Sashiko is wrong, since Vlastimil addressed that with commit
59bb47985c1d ("mm, sl[aou]b: guarantee natural alignment for kmalloc(power-of-two)")
Can you confirm that Sashiko is wrong?
[1] https://sashiko.dev/#/patchset/20260528-b4-s390-drivers-v1-0-b7108f54d722%40kernel.org?part=4
^ permalink raw reply [flat|nested] 23+ messages in thread* Re: [PATCH 4/6] s390/qeth: replace get_zeroed_page() with kzalloc()
2026-05-29 11:09 ` Heiko Carstens
@ 2026-05-29 11:15 ` Vlastimil Babka (SUSE)
0 siblings, 0 replies; 23+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-05-29 11:15 UTC (permalink / raw)
To: Heiko Carstens, Mike Rapoport (Microsoft), Roman Gushchin
Cc: Alexander Gordeev, Vasily Gorbik, Alexandra Winter,
Aswin Karuvally, Christian Borntraeger, Harald Freudenberger,
Holger Dengler, Jan Hoeppner, Stefan Haberland, Sven Schnelle,
linux-s390
On 5/29/26 13:09, Heiko Carstens wrote:
> On Thu, May 28, 2026 at 10:09:52AM +0300, Mike Rapoport (Microsoft) wrote:
>> }
>
> Hm, another thing is that Sashiko claims that kmalloc allocations are not
> necessarily correctly aligned when slab debugging or KASAN is enabled [1].
>
> I believe that Sashiko is wrong, since Vlastimil addressed that with commit
> 59bb47985c1d ("mm, sl[aou]b: guarantee natural alignment for kmalloc(power-of-two)")
Right.
> Can you confirm that Sashiko is wrong?
Yeah it's wrong.
Roman, can you adjust the prompts perhaps? Or we might have this wrong
feedback on many patches that Mike is doing (or planning to do).
> [1] https://sashiko.dev/#/patchset/20260528-b4-s390-drivers-v1-0-b7108f54d722%40kernel.org?part=4
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 5/6] s390/trng: replace __get_free_page() with kmalloc()
2026-05-28 7:09 [PATCH 0/6] s390/drivers: replace __get_free_pages() call with kmalloc() Mike Rapoport (Microsoft)
` (3 preceding siblings ...)
2026-05-28 7:09 ` [PATCH 4/6] s390/qeth: " Mike Rapoport (Microsoft)
@ 2026-05-28 7:09 ` Mike Rapoport (Microsoft)
2026-05-29 10:29 ` Heiko Carstens
2026-05-28 7:09 ` [PATCH 6/6] s390/zcrypt: replace get_zeroed_page() with kzalloc() Mike Rapoport (Microsoft)
2026-05-28 14:48 ` [PATCH 0/6] s390/drivers: replace __get_free_pages() call with kmalloc() Alexander Gordeev
6 siblings, 1 reply; 23+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-05-28 7:09 UTC (permalink / raw)
To: Alexander Gordeev, Heiko Carstens, Vasily Gorbik
Cc: Alexandra Winter, Aswin Karuvally, Christian Borntraeger,
Harald Freudenberger, Holger Dengler, Jan Hoeppner, Mike Rapoport,
Stefan Haberland, Sven Schnelle, linux-s390
trng_read() allocates a temporary staging buffer for CPACF TRNG
random data before copying it to userspace.
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.
Replace use of __get_free_page() with kmalloc() and free_page() with
kfree().
Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/char/hw_random/s390-trng.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/char/hw_random/s390-trng.c b/drivers/char/hw_random/s390-trng.c
index 3024d5e9fd61..5520f66274b3 100644
--- a/drivers/char/hw_random/s390-trng.c
+++ b/drivers/char/hw_random/s390-trng.c
@@ -20,6 +20,7 @@
#include <linux/atomic.h>
#include <linux/random.h>
#include <linux/sched/signal.h>
+#include <linux/slab.h>
#include <asm/debug.h>
#include <asm/cpacf.h>
#include <asm/archrandom.h>
@@ -67,7 +68,7 @@ static ssize_t trng_read(struct file *file, char __user *ubuf,
*/
if (nbytes > sizeof(buf)) {
- p = (u8 *) __get_free_page(GFP_KERNEL);
+ p = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!p)
return -ENOMEM;
}
@@ -94,7 +95,7 @@ static ssize_t trng_read(struct file *file, char __user *ubuf,
}
if (p != buf)
- free_page((unsigned long) p);
+ kfree(p);
DEBUG_DBG("trng_read()=%zd\n", ret);
return ret;
--
2.53.0
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH 5/6] s390/trng: replace __get_free_page() with kmalloc()
2026-05-28 7:09 ` [PATCH 5/6] s390/trng: replace __get_free_page() with kmalloc() Mike Rapoport (Microsoft)
@ 2026-05-29 10:29 ` Heiko Carstens
0 siblings, 0 replies; 23+ messages in thread
From: Heiko Carstens @ 2026-05-29 10:29 UTC (permalink / raw)
To: Mike Rapoport (Microsoft)
Cc: Alexander Gordeev, Vasily Gorbik, Alexandra Winter,
Aswin Karuvally, Christian Borntraeger, Harald Freudenberger,
Holger Dengler, Jan Hoeppner, Stefan Haberland, Sven Schnelle,
linux-s390
On Thu, May 28, 2026 at 10:09:53AM +0300, Mike Rapoport (Microsoft) wrote:
1;115;0c> trng_read() allocates a temporary staging buffer for CPACF TRNG
> random data before copying it to userspace.
>
> 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.
>
> Replace use of __get_free_page() with kmalloc() and free_page() with
> kfree().
>
> Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> drivers/char/hw_random/s390-trng.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
Reviewed-by: Heiko Carstens <hca@linux.ibm.com>
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 6/6] s390/zcrypt: replace get_zeroed_page() with kzalloc()
2026-05-28 7:09 [PATCH 0/6] s390/drivers: replace __get_free_pages() call with kmalloc() Mike Rapoport (Microsoft)
` (4 preceding siblings ...)
2026-05-28 7:09 ` [PATCH 5/6] s390/trng: replace __get_free_page() with kmalloc() Mike Rapoport (Microsoft)
@ 2026-05-28 7:09 ` Mike Rapoport (Microsoft)
2026-05-29 8:29 ` Harald Freudenberger
2026-05-29 10:28 ` Heiko Carstens
2026-05-28 14:48 ` [PATCH 0/6] s390/drivers: replace __get_free_pages() call with kmalloc() Alexander Gordeev
6 siblings, 2 replies; 23+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-05-28 7:09 UTC (permalink / raw)
To: Alexander Gordeev, Heiko Carstens, Vasily Gorbik
Cc: Alexandra Winter, Aswin Karuvally, Christian Borntraeger,
Harald Freudenberger, Holger Dengler, Jan Hoeppner, Mike Rapoport,
Stefan Haberland, Sven Schnelle, linux-s390
zcrypt_rng_device_add() allocates a buffer for the software random
number generator data cache.
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.
Replace use of get_zeroed_page() with kzalloc() and free_page() with
kfree().
Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/s390/crypto/zcrypt_api.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
index d6a455df228d..f57189c2b839 100644
--- a/drivers/s390/crypto/zcrypt_api.c
+++ b/drivers/s390/crypto/zcrypt_api.c
@@ -1782,7 +1782,7 @@ int zcrypt_rng_device_add(void)
mutex_lock(&zcrypt_rng_mutex);
if (zcrypt_rng_device_count == 0) {
- zcrypt_rng_buffer = (u32 *)get_zeroed_page(GFP_KERNEL);
+ zcrypt_rng_buffer = kzalloc(PAGE_SIZE, GFP_KERNEL);
if (!zcrypt_rng_buffer) {
rc = -ENOMEM;
goto out;
@@ -1799,7 +1799,7 @@ int zcrypt_rng_device_add(void)
return 0;
out_free:
- free_page((unsigned long)zcrypt_rng_buffer);
+ kfree(zcrypt_rng_buffer);
out:
mutex_unlock(&zcrypt_rng_mutex);
return rc;
@@ -1811,7 +1811,7 @@ void zcrypt_rng_device_remove(void)
zcrypt_rng_device_count--;
if (zcrypt_rng_device_count == 0) {
hwrng_unregister(&zcrypt_rng_dev);
- free_page((unsigned long)zcrypt_rng_buffer);
+ kfree(zcrypt_rng_buffer);
}
mutex_unlock(&zcrypt_rng_mutex);
}
--
2.53.0
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH 6/6] s390/zcrypt: replace get_zeroed_page() with kzalloc()
2026-05-28 7:09 ` [PATCH 6/6] s390/zcrypt: replace get_zeroed_page() with kzalloc() Mike Rapoport (Microsoft)
@ 2026-05-29 8:29 ` Harald Freudenberger
2026-05-29 10:28 ` Heiko Carstens
1 sibling, 0 replies; 23+ messages in thread
From: Harald Freudenberger @ 2026-05-29 8:29 UTC (permalink / raw)
To: Mike Rapoport (Microsoft)
Cc: Alexander Gordeev, Heiko Carstens, Vasily Gorbik,
Alexandra Winter, Aswin Karuvally, Christian Borntraeger,
Holger Dengler, Jan Hoeppner, Stefan Haberland, Sven Schnelle,
linux-s390
On 2026-05-28 09:09, Mike Rapoport (Microsoft) wrote:
> zcrypt_rng_device_add() allocates a buffer for the software random
> number generator data cache.
>
> 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.
>
> Replace use of get_zeroed_page() with kzalloc() and free_page() with
> kfree().
>
> Link:
> https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> drivers/s390/crypto/zcrypt_api.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/s390/crypto/zcrypt_api.c
> b/drivers/s390/crypto/zcrypt_api.c
> index d6a455df228d..f57189c2b839 100644
> --- a/drivers/s390/crypto/zcrypt_api.c
> +++ b/drivers/s390/crypto/zcrypt_api.c
> @@ -1782,7 +1782,7 @@ int zcrypt_rng_device_add(void)
>
> mutex_lock(&zcrypt_rng_mutex);
> if (zcrypt_rng_device_count == 0) {
> - zcrypt_rng_buffer = (u32 *)get_zeroed_page(GFP_KERNEL);
> + zcrypt_rng_buffer = kzalloc(PAGE_SIZE, GFP_KERNEL);
> if (!zcrypt_rng_buffer) {
> rc = -ENOMEM;
> goto out;
> @@ -1799,7 +1799,7 @@ int zcrypt_rng_device_add(void)
> return 0;
>
> out_free:
> - free_page((unsigned long)zcrypt_rng_buffer);
> + kfree(zcrypt_rng_buffer);
> out:
> mutex_unlock(&zcrypt_rng_mutex);
> return rc;
> @@ -1811,7 +1811,7 @@ void zcrypt_rng_device_remove(void)
> zcrypt_rng_device_count--;
> if (zcrypt_rng_device_count == 0) {
> hwrng_unregister(&zcrypt_rng_dev);
> - free_page((unsigned long)zcrypt_rng_buffer);
> + kfree(zcrypt_rng_buffer);
> }
> mutex_unlock(&zcrypt_rng_mutex);
> }
Reviewed-by: Harald Freudenberger <freude@linux.ibm.com>
^ permalink raw reply [flat|nested] 23+ messages in thread* Re: [PATCH 6/6] s390/zcrypt: replace get_zeroed_page() with kzalloc()
2026-05-28 7:09 ` [PATCH 6/6] s390/zcrypt: replace get_zeroed_page() with kzalloc() Mike Rapoport (Microsoft)
2026-05-29 8:29 ` Harald Freudenberger
@ 2026-05-29 10:28 ` Heiko Carstens
1 sibling, 0 replies; 23+ messages in thread
From: Heiko Carstens @ 2026-05-29 10:28 UTC (permalink / raw)
To: Mike Rapoport (Microsoft)
Cc: Alexander Gordeev, Vasily Gorbik, Alexandra Winter,
Aswin Karuvally, Christian Borntraeger, Harald Freudenberger,
Holger Dengler, Jan Hoeppner, Stefan Haberland, Sven Schnelle,
linux-s390
On Thu, May 28, 2026 at 10:09:54AM +0300, Mike Rapoport (Microsoft) wrote:
> zcrypt_rng_device_add() allocates a buffer for the software random
> number generator data cache.
>
> 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.
>
> Replace use of get_zeroed_page() with kzalloc() and free_page() with
> kfree().
>
> Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> drivers/s390/crypto/zcrypt_api.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
Reviewed-by: Heiko Carstens <hca@linux.ibm.com>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 0/6] s390/drivers: replace __get_free_pages() call with kmalloc()
2026-05-28 7:09 [PATCH 0/6] s390/drivers: replace __get_free_pages() call with kmalloc() Mike Rapoport (Microsoft)
` (5 preceding siblings ...)
2026-05-28 7:09 ` [PATCH 6/6] s390/zcrypt: replace get_zeroed_page() with kzalloc() Mike Rapoport (Microsoft)
@ 2026-05-28 14:48 ` Alexander Gordeev
2026-05-28 15:16 ` Mike Rapoport
6 siblings, 1 reply; 23+ messages in thread
From: Alexander Gordeev @ 2026-05-28 14:48 UTC (permalink / raw)
To: Mike Rapoport (Microsoft)
Cc: Heiko Carstens, Vasily Gorbik, Alexandra Winter, Aswin Karuvally,
Christian Borntraeger, Harald Freudenberger, Holger Dengler,
Jan Hoeppner, Stefan Haberland, Sven Schnelle, linux-s390
On Thu, May 28, 2026 at 10:09:48AM +0300, Mike Rapoport (Microsoft) wrote:
Hi Mike,
> This is a (tiny) part of larger work of replacing page allocator calls
> with kmalloc.
>
> Nowadays the right way to say "I need a buffer" is kmalloc() rather than
> ancient and ugly __get_free_pages().
>
> Also in git:
> https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git gfp-to-kmalloc/s390-drivers
>
> ---
> Mike Rapoport (Microsoft) (6):
> s390/con3270: replace __get_free_page() with kmalloc()
> s390/dasd: replace get_zeroed_page() with kzalloc()
> s390/hvc_iucv: replace get_zeroed_page() with kzalloc()
> s390/qeth: replace get_zeroed_page() with kzalloc()
> s390/trng: replace __get_free_page() with kmalloc()
> s390/zcrypt: replace get_zeroed_page() with kzalloc()
>
> drivers/char/hw_random/s390-trng.c | 5 +++--
> drivers/s390/block/dasd_eckd.c | 12 ++++++------
> drivers/s390/block/dasd_eer.c | 4 ++--
> drivers/s390/char/con3270.c | 8 ++++----
> drivers/s390/crypto/zcrypt_api.c | 6 +++---
> drivers/s390/net/qeth_core_main.c | 4 ++--
> drivers/tty/hvc/hvc_iucv.c | 6 +++---
> 7 files changed, 23 insertions(+), 22 deletions(-)
Did you use a particular tool/script to identify these locations?
The immediat question would by why these sources only and not the
others that also use the old functions?
Thanks!
^ permalink raw reply [flat|nested] 23+ messages in thread* Re: [PATCH 0/6] s390/drivers: replace __get_free_pages() call with kmalloc()
2026-05-28 14:48 ` [PATCH 0/6] s390/drivers: replace __get_free_pages() call with kmalloc() Alexander Gordeev
@ 2026-05-28 15:16 ` Mike Rapoport
2026-05-29 6:21 ` Alexander Gordeev
0 siblings, 1 reply; 23+ messages in thread
From: Mike Rapoport @ 2026-05-28 15:16 UTC (permalink / raw)
To: Alexander Gordeev
Cc: Heiko Carstens, Vasily Gorbik, Alexandra Winter, Aswin Karuvally,
Christian Borntraeger, Harald Freudenberger, Holger Dengler,
Jan Hoeppner, Stefan Haberland, Sven Schnelle, linux-s390
On Thu, May 28, 2026 at 04:48:41PM +0200, Alexander Gordeev wrote:
> On Thu, May 28, 2026 at 10:09:48AM +0300, Mike Rapoport (Microsoft) wrote:
>
> Hi Mike,
>
> > This is a (tiny) part of larger work of replacing page allocator calls
> > with kmalloc.
> >
> > Nowadays the right way to say "I need a buffer" is kmalloc() rather than
> > ancient and ugly __get_free_pages().
> >
> > Also in git:
> > https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git gfp-to-kmalloc/s390-drivers
> >
> > ---
> > Mike Rapoport (Microsoft) (6):
> > s390/con3270: replace __get_free_page() with kmalloc()
> > s390/dasd: replace get_zeroed_page() with kzalloc()
> > s390/hvc_iucv: replace get_zeroed_page() with kzalloc()
> > s390/qeth: replace get_zeroed_page() with kzalloc()
> > s390/trng: replace __get_free_page() with kmalloc()
> > s390/zcrypt: replace get_zeroed_page() with kzalloc()
> >
> > drivers/char/hw_random/s390-trng.c | 5 +++--
> > drivers/s390/block/dasd_eckd.c | 12 ++++++------
> > drivers/s390/block/dasd_eer.c | 4 ++--
> > drivers/s390/char/con3270.c | 8 ++++----
> > drivers/s390/crypto/zcrypt_api.c | 6 +++---
> > drivers/s390/net/qeth_core_main.c | 4 ++--
> > drivers/tty/hvc/hvc_iucv.c | 6 +++---
> > 7 files changed, 23 insertions(+), 22 deletions(-)
>
> Did you use a particular tool/script to identify these locations?
> The immediat question would by why these sources only and not the
> others that also use the old functions?
I used an LLM to identify "the most safe callers to convert" to being with.
Since every call site requires a manual review of the surrounding code and
the actual usage, for the first round I limited the changes to allocations
that are temporary or staging buffers.
With a less restrictive prompt I've got 57 patches to s390 (both arch/ and
drivers/), bu that's too much for me to chew in a single setting :)
If you are curious, overall changes (before the human review) are here:
https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git/log/?h=gfp-to-kmalloc/v0.2
> Thanks!
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 0/6] s390/drivers: replace __get_free_pages() call with kmalloc()
2026-05-28 15:16 ` Mike Rapoport
@ 2026-05-29 6:21 ` Alexander Gordeev
2026-05-29 7:13 ` Mike Rapoport
0 siblings, 1 reply; 23+ messages in thread
From: Alexander Gordeev @ 2026-05-29 6:21 UTC (permalink / raw)
To: Mike Rapoport
Cc: Heiko Carstens, Vasily Gorbik, Alexandra Winter, Aswin Karuvally,
Christian Borntraeger, Harald Freudenberger, Holger Dengler,
Jan Hoeppner, Stefan Haberland, Sven Schnelle, linux-s390
On Thu, May 28, 2026 at 06:16:28PM +0300, Mike Rapoport wrote:
> > Did you use a particular tool/script to identify these locations?
> > The immediat question would by why these sources only and not the
> > others that also use the old functions?
>
> I used an LLM to identify "the most safe callers to convert" to being with.
>
> Since every call site requires a manual review of the surrounding code and
> the actual usage, for the first round I limited the changes to allocations
> that are temporary or staging buffers.
>
> With a less restrictive prompt I've got 57 patches to s390 (both arch/ and
> drivers/), bu that's too much for me to chew in a single setting :)
Thanks for the explanation!
> If you are curious, overall changes (before the human review) are here:
> https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git/log/?h=gfp-to-kmalloc/v0.2
So you are planning to address all of those?
> --
> Sincerely yours,
> Mike.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 0/6] s390/drivers: replace __get_free_pages() call with kmalloc()
2026-05-29 6:21 ` Alexander Gordeev
@ 2026-05-29 7:13 ` Mike Rapoport
0 siblings, 0 replies; 23+ messages in thread
From: Mike Rapoport @ 2026-05-29 7:13 UTC (permalink / raw)
To: Alexander Gordeev
Cc: Heiko Carstens, Vasily Gorbik, Alexandra Winter, Aswin Karuvally,
Christian Borntraeger, Harald Freudenberger, Holger Dengler,
Jan Hoeppner, Stefan Haberland, Sven Schnelle, linux-s390
On Fri, May 29, 2026 at 08:21:59AM +0200, Alexander Gordeev wrote:
> On Thu, May 28, 2026 at 06:16:28PM +0300, Mike Rapoport wrote:
> > > Did you use a particular tool/script to identify these locations?
> > > The immediat question would by why these sources only and not the
> > > others that also use the old functions?
> >
> > I used an LLM to identify "the most safe callers to convert" to being with.
> >
> > Since every call site requires a manual review of the surrounding code and
> > the actual usage, for the first round I limited the changes to allocations
> > that are temporary or staging buffers.
> >
> > With a less restrictive prompt I've got 57 patches to s390 (both arch/ and
> > drivers/), bu that's too much for me to chew in a single setting :)
>
> Thanks for the explanation!
>
> > If you are curious, overall changes (before the human review) are here:
> > https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git/log/?h=gfp-to-kmalloc/v0.2
>
> So you are planning to address all of those?
Yeah, that's the plan.
Slowly but steadily :)
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 23+ messages in thread