[PATCH 06/13] s390/cmf: Use kmalloc() for the CMB area

From: Mike Rapoport (Microsoft)

Date: Mon Sep 07 2026 - 06:36:59 EST


alloc_cmb() allocates the channel measurement block area shared by
devices using the basic channel measurement format.

This memory 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 measurement block origin must be page aligned and kmalloc()
guarantees that a power of two sized allocation is aligned to its size.

Replace use of __get_free_pages() with kmalloc() and free_pages() with
kfree().

Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@xxxxxxxxxx
Assisted-by: copilot:claude-opus
Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
---
drivers/s390/cio/cmf.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/s390/cio/cmf.c b/drivers/s390/cio/cmf.c
index 92ab3d546fe47..6c46b0d0b3da4 100644
--- a/drivers/s390/cio/cmf.c
+++ b/drivers/s390/cio/cmf.c
@@ -501,12 +501,12 @@ static int alloc_cmb(struct ccw_device *cdev)
WARN_ON(!list_empty(&cmb_area.list));

spin_unlock(&cmb_area.lock);
- mem = (void *)__get_free_pages(GFP_KERNEL, get_order(size));
+ mem = kmalloc(PAGE_SIZE << get_order(size), GFP_KERNEL);
spin_lock(&cmb_area.lock);

if (cmb_area.mem) {
/* ok, another thread was faster */
- free_pages((unsigned long)mem, get_order(size));
+ kfree(mem);
} else if (!mem) {
/* no luck */
ret = -ENOMEM;
@@ -547,10 +547,8 @@ static void free_cmb(struct ccw_device *cdev)
list_del_init(&priv->cmb_list);

if (list_empty(&cmb_area.list)) {
- ssize_t size;
- size = sizeof(struct cmb) * cmb_area.num_channels;
cmf_activate(NULL, CMF_OFF);
- free_pages((unsigned long)cmb_area.mem, get_order(size));
+ kfree(cmb_area.mem);
cmb_area.mem = NULL;
}
spin_unlock_irq(cdev->ccwlock);

--
2.53.0