* [PATCH 1/4] char: xilinx_hwicap: replace page allocator calls with k[mz]alloc()
2026-08-30 7:47 [PATCH 0/4] char/misc: replace page allocator calls with k[mz]alloc() Mike Rapoport (Microsoft)
@ 2026-08-30 7:47 ` Mike Rapoport (Microsoft)
2026-08-30 7:47 ` [PATCH 2/4] char: xillybus: replace __get_free_pages() with kmalloc() Mike Rapoport (Microsoft)
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-08-30 7:47 UTC (permalink / raw)
To: Arnd Bergmann, Brad Warrum, Eli Billauer, Greg Kroah-Hartman,
Michal Simek, Ritu Agarwal
Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Mike Rapoport,
Vlastimil Babka, linux-arm-kernel, linux-kernel, linux-mm,
linuxppc-dev
hwicap_read() and hwicap_write() allocate temporary buffers used to pass
the FPGA configuration data to and from userspace.
These buffers can be allocated with kmalloc() as there's nothing special
about them 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() and get_zeroed_page() with kmalloc() and
kzalloc() and free_page() with kfree().
Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Assisted-by: copilot:claude-opus
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/char/xilinx_hwicap/xilinx_hwicap.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
index 9bb5fa642fd8..bbeb9b6060dc 100644
--- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c
+++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
@@ -382,7 +382,7 @@ hwicap_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
4 - bytes_to_read);
} else {
/* Get new data from the ICAP, and return what was requested. */
- kbuf = (u32 *) get_zeroed_page(GFP_KERNEL);
+ kbuf = kzalloc(PAGE_SIZE, GFP_KERNEL);
if (!kbuf) {
status = -ENOMEM;
goto error;
@@ -412,13 +412,13 @@ hwicap_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
/* If we didn't read correctly, then bail out. */
if (status) {
- free_page((unsigned long)kbuf);
+ kfree(kbuf);
goto error;
}
/* If we fail to return the data to the user, then bail out. */
if (copy_to_user(buf, kbuf, bytes_to_read)) {
- free_page((unsigned long)kbuf);
+ kfree(kbuf);
status = -EFAULT;
goto error;
}
@@ -426,7 +426,7 @@ hwicap_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
kbuf,
bytes_remaining);
drvdata->read_buffer_in_use = bytes_remaining;
- free_page((unsigned long)kbuf);
+ kfree(kbuf);
}
status = bytes_to_read;
error:
@@ -457,7 +457,7 @@ hwicap_write(struct file *file, const char __user *buf,
goto error;
}
- kbuf = (u32 *) __get_free_page(GFP_KERNEL);
+ kbuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!kbuf) {
status = -ENOMEM;
goto error;
@@ -479,13 +479,13 @@ hwicap_write(struct file *file, const char __user *buf,
(((char *)kbuf) + drvdata->write_buffer_in_use),
buf + written,
len - (drvdata->write_buffer_in_use))) {
- free_page((unsigned long)kbuf);
+ kfree(kbuf);
status = -EFAULT;
goto error;
}
} else {
if (copy_from_user(kbuf, buf + written, len)) {
- free_page((unsigned long)kbuf);
+ kfree(kbuf);
status = -EFAULT;
goto error;
}
@@ -495,7 +495,7 @@ hwicap_write(struct file *file, const char __user *buf,
kbuf, len >> 2);
if (status) {
- free_page((unsigned long)kbuf);
+ kfree(kbuf);
status = -EFAULT;
goto error;
}
@@ -516,7 +516,7 @@ hwicap_write(struct file *file, const char __user *buf,
}
}
- free_page((unsigned long)kbuf);
+ kfree(kbuf);
status = written;
error:
mutex_unlock(&drvdata->sem);
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 2/4] char: xillybus: replace __get_free_pages() with kmalloc()
2026-08-30 7:47 [PATCH 0/4] char/misc: replace page allocator calls with k[mz]alloc() Mike Rapoport (Microsoft)
2026-08-30 7:47 ` [PATCH 1/4] char: xilinx_hwicap: " Mike Rapoport (Microsoft)
@ 2026-08-30 7:47 ` Mike Rapoport (Microsoft)
2026-08-30 7:48 ` [PATCH 3/4] misc: ibmvmc: replace get_zeroed_page() with kzalloc() Mike Rapoport (Microsoft)
2026-08-30 7:48 ` [PATCH 4/4] platform: goldfish: pipe: replace __get_free_page() with kmalloc() Mike Rapoport (Microsoft)
3 siblings, 0 replies; 5+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-08-30 7:47 UTC (permalink / raw)
To: Arnd Bergmann, Brad Warrum, Eli Billauer, Greg Kroah-Hartman,
Michal Simek, Ritu Agarwal
Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Mike Rapoport,
Vlastimil Babka, linux-arm-kernel, linux-kernel, linux-mm,
linuxppc-dev
fifo_init() allocates the buffers backing the software FIFO and
endpoint_alloc() allocates the transfer buffers of a USB endpoint.
These buffers can be allocated with kmalloc() as there's nothing special
about them 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.
Since kmalloc() does not need the allocation order, ask it for the buffer
sizes the driver already tracks and drop the now unused order fields. For
a FIFO smaller than a page this also stops rounding the allocation up to
PAGE_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@redhat.com
Assisted-by: copilot:claude-opus
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/char/xillybus/xillyusb.c | 25 +++++++------------------
1 file changed, 7 insertions(+), 18 deletions(-)
diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xillyusb.c
index 34e7ad3bcab3..193e2a5b599e 100644
--- a/drivers/char/xillybus/xillyusb.c
+++ b/drivers/char/xillybus/xillyusb.c
@@ -71,7 +71,6 @@ struct xillyfifo {
unsigned int bufsize; /* In bytes, always a power of 2 */
unsigned int bufnum;
unsigned int size; /* Lazy: Equals bufsize * bufnum */
- unsigned int buf_order;
int fill; /* Number of bytes in the FIFO */
spinlock_t lock;
@@ -95,7 +94,6 @@ struct xillyusb_endpoint {
struct list_head filled_buffers;
spinlock_t buffers_lock; /* protect these two lists */
- unsigned int order;
unsigned int buffer_size;
unsigned int fill_mask;
@@ -370,7 +368,6 @@ static int fifo_init(struct xillyfifo *fifo,
unsigned int log2_size)
{
unsigned int log2_bufnum;
- unsigned int buf_order;
int i;
unsigned int log2_fifo_buf_size;
@@ -380,18 +377,14 @@ static int fifo_init(struct xillyfifo *fifo,
if (log2_size > log2_fifo_buf_size) {
log2_bufnum = log2_size - log2_fifo_buf_size;
- buf_order = fifo_buf_order;
fifo->bufsize = 1 << log2_fifo_buf_size;
} else {
log2_bufnum = 0;
- buf_order = (log2_size > PAGE_SHIFT) ?
- log2_size - PAGE_SHIFT : 0;
fifo->bufsize = 1 << log2_size;
}
fifo->bufnum = 1 << log2_bufnum;
fifo->size = fifo->bufnum * fifo->bufsize;
- fifo->buf_order = buf_order;
fifo->mem = kmalloc_array(fifo->bufnum, sizeof(void *), GFP_KERNEL);
@@ -399,8 +392,7 @@ static int fifo_init(struct xillyfifo *fifo,
return -ENOMEM;
for (i = 0; i < fifo->bufnum; i++) {
- fifo->mem[i] = (void *)
- __get_free_pages(GFP_KERNEL, buf_order);
+ fifo->mem[i] = kmalloc(fifo->bufsize, GFP_KERNEL);
if (!fifo->mem[i])
goto memfail;
@@ -417,7 +409,7 @@ static int fifo_init(struct xillyfifo *fifo,
memfail:
for (i--; i >= 0; i--)
- free_pages((unsigned long)fifo->mem[i], buf_order);
+ kfree(fifo->mem[i]);
kfree(fifo->mem);
fifo->mem = NULL;
@@ -438,7 +430,7 @@ static void fifo_mem_release(struct xillyfifo *fifo)
return;
for (i = 0; i < fifo->bufnum; i++)
- free_pages((unsigned long)fifo->mem[i], fifo->buf_order);
+ kfree(fifo->mem[i]);
kfree(fifo->mem);
}
@@ -477,7 +469,7 @@ static void endpoint_dealloc(struct xillyusb_endpoint *ep)
struct xillybuffer *xb =
list_entry(this, struct xillybuffer, entry);
- free_pages((unsigned long)xb->buf, ep->order);
+ kfree(xb->buf);
kfree(xb);
}
@@ -509,8 +501,7 @@ static struct xillyusb_endpoint
init_usb_anchor(&ep->anchor);
INIT_WORK(&ep->workitem, work);
- ep->order = order;
- ep->buffer_size = 1 << (PAGE_SHIFT + order);
+ ep->buffer_size = 1 << (PAGE_SHIFT + order);
ep->outstanding_urbs = 0;
ep->drained = true;
ep->wake_on_drain = false;
@@ -520,7 +511,6 @@ static struct xillyusb_endpoint
for (i = 0; i < bufnum; i++) {
struct xillybuffer *xb;
- unsigned long addr;
xb = kzalloc_obj(*xb);
@@ -529,15 +519,14 @@ static struct xillyusb_endpoint
return NULL;
}
- addr = __get_free_pages(GFP_KERNEL, order);
+ xb->buf = kmalloc(ep->buffer_size, GFP_KERNEL);
- if (!addr) {
+ if (!xb->buf) {
kfree(xb);
endpoint_dealloc(ep);
return NULL;
}
- xb->buf = (void *)addr;
xb->ep = ep;
list_add_tail(&xb->entry, &ep->buffers);
}
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 3/4] misc: ibmvmc: replace get_zeroed_page() with kzalloc()
2026-08-30 7:47 [PATCH 0/4] char/misc: replace page allocator calls with k[mz]alloc() Mike Rapoport (Microsoft)
2026-08-30 7:47 ` [PATCH 1/4] char: xilinx_hwicap: " Mike Rapoport (Microsoft)
2026-08-30 7:47 ` [PATCH 2/4] char: xillybus: replace __get_free_pages() with kmalloc() Mike Rapoport (Microsoft)
@ 2026-08-30 7:48 ` Mike Rapoport (Microsoft)
2026-08-30 7:48 ` [PATCH 4/4] platform: goldfish: pipe: replace __get_free_page() with kmalloc() Mike Rapoport (Microsoft)
3 siblings, 0 replies; 5+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-08-30 7:48 UTC (permalink / raw)
To: Arnd Bergmann, Brad Warrum, Eli Billauer, Greg Kroah-Hartman,
Michal Simek, Ritu Agarwal
Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Mike Rapoport,
Vlastimil Babka, linux-arm-kernel, linux-kernel, linux-mm,
linuxppc-dev
ibmvmc_init_crq_queue() allocates the CRQ message queue that is shared
with the hypervisor. The queue is mapped for DMA and registered with the
hypervisor by its DMA address.
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
Assisted-by: copilot:claude-opus
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/misc/ibmvmc.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/misc/ibmvmc.c b/drivers/misc/ibmvmc.c
index da82b1edb7c9..7d503ebd9f3c 100644
--- a/drivers/misc/ibmvmc.c
+++ b/drivers/misc/ibmvmc.c
@@ -154,7 +154,7 @@ static void ibmvmc_release_crq_queue(struct crq_server_adapter *adapter)
dma_unmap_single(adapter->dev,
queue->msg_token,
queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL);
- free_page((unsigned long)queue->msgs);
+ kfree(queue->msgs);
}
/**
@@ -2130,7 +2130,7 @@ static int ibmvmc_init_crq_queue(struct crq_server_adapter *adapter)
int rc = 0;
int retrc = 0;
- queue->msgs = (struct ibmvmc_crq_msg *)get_zeroed_page(GFP_KERNEL);
+ queue->msgs = kzalloc(PAGE_SIZE, GFP_KERNEL);
if (!queue->msgs)
goto malloc_failed;
@@ -2192,7 +2192,7 @@ static int ibmvmc_init_crq_queue(struct crq_server_adapter *adapter)
queue->msg_token,
queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL);
map_failed:
- free_page((unsigned long)queue->msgs);
+ kfree(queue->msgs);
malloc_failed:
return -ENOMEM;
}
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 4/4] platform: goldfish: pipe: replace __get_free_page() with kmalloc()
2026-08-30 7:47 [PATCH 0/4] char/misc: replace page allocator calls with k[mz]alloc() Mike Rapoport (Microsoft)
` (2 preceding siblings ...)
2026-08-30 7:48 ` [PATCH 3/4] misc: ibmvmc: replace get_zeroed_page() with kzalloc() Mike Rapoport (Microsoft)
@ 2026-08-30 7:48 ` Mike Rapoport (Microsoft)
3 siblings, 0 replies; 5+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-08-30 7:48 UTC (permalink / raw)
To: Arnd Bergmann, Brad Warrum, Eli Billauer, Greg Kroah-Hartman,
Michal Simek, Ritu Agarwal
Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Mike Rapoport,
Vlastimil Babka, linux-arm-kernel, linux-kernel, linux-mm,
linuxppc-dev
goldfish_pipe_open() allocates the per-pipe command buffer and
goldfish_pipe_device_init() allocates the buffers the device shares with
the host. Both are passed to the host as physical addresses and must be
physically contiguous, which kmalloc() guarantees.
These buffers can be allocated with kmalloc() as there's nothing special
about them 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.
While on it, size both allocations after the structures they hold instead
of always taking a full page.
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
Assisted-by: copilot:claude-opus
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/platform/goldfish/goldfish_pipe.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/drivers/platform/goldfish/goldfish_pipe.c b/drivers/platform/goldfish/goldfish_pipe.c
index fa241ca8feb0..3f34db896ece 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -708,12 +708,11 @@ static int goldfish_pipe_open(struct inode *inode, struct file *file)
init_waitqueue_head(&pipe->wake_queue);
/*
- * Command buffer needs to be allocated on its own page to make sure
- * it is physically contiguous in host's address space.
+ * The command buffer is passed to the host as a physical address, so
+ * it must be physically contiguous, which kmalloc() guarantees.
*/
BUILD_BUG_ON(sizeof(struct goldfish_pipe_command) > PAGE_SIZE);
- pipe->command_buffer =
- (struct goldfish_pipe_command *)__get_free_page(GFP_KERNEL);
+ pipe->command_buffer = kmalloc_obj(*pipe->command_buffer);
if (!pipe->command_buffer) {
status = -ENOMEM;
goto err_pipe;
@@ -749,7 +748,7 @@ static int goldfish_pipe_open(struct inode *inode, struct file *file)
dev->pipes[id] = NULL;
err_id_locked:
spin_unlock_irqrestore(&dev->lock, flags);
- free_page((unsigned long)pipe->command_buffer);
+ kfree(pipe->command_buffer);
err_pipe:
kfree(pipe);
return status;
@@ -770,7 +769,7 @@ static int goldfish_pipe_release(struct inode *inode, struct file *filp)
spin_unlock_irqrestore(&dev->lock, flags);
filp->private_data = NULL;
- free_page((unsigned long)pipe->command_buffer);
+ kfree(pipe->command_buffer);
kfree(pipe);
return 0;
}
@@ -833,13 +832,12 @@ static int goldfish_pipe_device_init(struct platform_device *pdev,
/*
* We're going to pass two buffers, open_command_params and
- * signalled_pipe_buffers, to the host. This means each of those buffers
- * needs to be contained in a single physical page. The easiest choice
- * is to just allocate a page and place the buffers in it.
+ * signalled_pipe_buffers, to the host as physical addresses. This means
+ * each of those buffers needs to be physically contiguous, which
+ * kmalloc() guarantees.
*/
BUILD_BUG_ON(sizeof(struct goldfish_pipe_dev_buffers) > PAGE_SIZE);
- dev->buffers = (struct goldfish_pipe_dev_buffers *)
- __get_free_page(GFP_KERNEL);
+ dev->buffers = kmalloc_obj(*dev->buffers);
if (!dev->buffers) {
kfree(dev->pipes);
misc_deregister(&dev->miscdev);
@@ -867,7 +865,7 @@ static void goldfish_pipe_device_deinit(struct platform_device *pdev,
{
misc_deregister(&dev->miscdev);
kfree(dev->pipes);
- free_page((unsigned long)dev->buffers);
+ kfree(dev->buffers);
}
static int goldfish_pipe_probe(struct platform_device *pdev)
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread