summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin K. Petersen (Oracle) <mkp@kernel.org>2026-09-01 22:44:12 -0400
committerMartin K. Petersen (Oracle) <mkp@kernel.org>2026-09-01 22:44:12 -0400
commit401b5781ab9182b28a1c6c4e262cc5e1e7716fbb (patch)
treefc33ba24207f6137514a5145b5d2244a86050763
parentcee9395acd8043be0644b25c34bfa86623f2b935 (diff)
parente64b8f3224add21f02c5d64e11371830e631cdba (diff)
downloadlinux-next-401b5781ab9182b28a1c6c4e262cc5e1e7716fbb.tar.gz
linux-next-401b5781ab9182b28a1c6c4e262cc5e1e7716fbb.zip
Merge patch series "scsi: replace __get_free_pages() with kmalloc()"
Mike Rapoport (Microsoft) <rppt@kernel.org> says: This is a (small) part of larger work of replacing page allocator calls with kmalloc. 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/ Link: https://patch.msgid.link/20260704-b4-scsi-v2-0-7d2d21a810de@kernel.org Signed-off-by: Martin K. Petersen (Oracle) <mkp@kernel.org>
-rw-r--r--drivers/scsi/ipr.c4
-rw-r--r--drivers/scsi/scsi_devinfo.c5
-rw-r--r--drivers/scsi/scsi_proc.c9
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_hipd.h4
-rw-r--r--drivers/target/target_core_file.c4
5 files changed, 14 insertions, 12 deletions
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index d207e5e81afe..19153dd24736 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -2893,7 +2893,7 @@ static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
(ioa_dump->hdr.len + bytes_copied) < max_dump_size) {
if (ioa_dump->page_offset >= PAGE_SIZE ||
ioa_dump->page_offset == 0) {
- page = (__be32 *)__get_free_page(GFP_ATOMIC);
+ page = kmalloc(PAGE_SIZE, GFP_NOIO);
if (!page) {
ipr_trace;
@@ -3226,7 +3226,7 @@ static void ipr_release_dump(struct kref *kref)
spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
for (i = 0; i < dump->ioa_dump.next_page_index; i++)
- free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
+ kfree(dump->ioa_dump.ioa_data[i]);
vfree(dump->ioa_dump.ioa_data);
kfree(dump);
diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c
index 15ffbe93ac72..2bccadf4f22f 100644
--- a/drivers/scsi/scsi_devinfo.c
+++ b/drivers/scsi/scsi_devinfo.c
@@ -691,7 +691,8 @@ static ssize_t proc_scsi_devinfo_write(struct file *file,
if (!buf || length>PAGE_SIZE)
return -EINVAL;
- if (!(buffer = (char *) __get_free_page(GFP_KERNEL)))
+ buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
+ if (!buffer)
return -ENOMEM;
if (copy_from_user(buffer, buf, length)) {
err =-EFAULT;
@@ -708,7 +709,7 @@ static ssize_t proc_scsi_devinfo_write(struct file *file,
scsi_dev_info_list_add_str(buffer);
out:
- free_page((unsigned long)buffer);
+ kfree(buffer);
return err;
}
diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c
index 1799dcae775c..fdc355d783da 100644
--- a/drivers/scsi/scsi_proc.c
+++ b/drivers/scsi/scsi_proc.c
@@ -28,6 +28,7 @@
#include <linux/mutex.h>
#include <linux/gfp.h>
#include <linux/uaccess.h>
+#include <linux/slab.h>
#include <scsi/scsi.h>
#include <scsi/scsi_device.h>
@@ -74,7 +75,7 @@ static ssize_t proc_scsi_host_write(struct file *file, const char __user *buf,
if (!shost->hostt->write_info)
return -EINVAL;
- page = (char *)__get_free_page(GFP_KERNEL);
+ page = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (page) {
ret = -EFAULT;
if (copy_from_user(page, buf, count))
@@ -82,7 +83,7 @@ static ssize_t proc_scsi_host_write(struct file *file, const char __user *buf,
ret = shost->hostt->write_info(shost, page, count);
}
out:
- free_page((unsigned long)page);
+ kfree(page);
return ret;
}
@@ -412,7 +413,7 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
if (!buf || length > PAGE_SIZE)
return -EINVAL;
- buffer = (char *)__get_free_page(GFP_KERNEL);
+ buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!buffer)
return -ENOMEM;
@@ -467,7 +468,7 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
err = length;
out:
- free_page((unsigned long)buffer);
+ kfree(buffer);
return err;
}
diff --git a/drivers/scsi/sym53c8xx_2/sym_hipd.h b/drivers/scsi/sym53c8xx_2/sym_hipd.h
index 9231a2899064..aa365e8ba66f 100644
--- a/drivers/scsi/sym53c8xx_2/sym_hipd.h
+++ b/drivers/scsi/sym53c8xx_2/sym_hipd.h
@@ -1110,9 +1110,9 @@ bad:
*/
#define sym_get_mem_cluster() \
- (void *) __get_free_pages(GFP_ATOMIC, SYM_MEM_PAGE_ORDER)
+ kmalloc(PAGE_SIZE << SYM_MEM_PAGE_ORDER, GFP_ATOMIC)
#define sym_free_mem_cluster(p) \
- free_pages((unsigned long)p, SYM_MEM_PAGE_ORDER)
+ kfree(p)
/*
* Link between free memory chunks of a given size.
diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c
index 62ced9f5102f..ab9824a4852f 100644
--- a/drivers/target/target_core_file.c
+++ b/drivers/target/target_core_file.c
@@ -516,7 +516,7 @@ fd_do_prot_unmap(struct se_cmd *cmd, sector_t lba, sector_t nolb)
void *buf;
int rc;
- buf = (void *)__get_free_page(GFP_KERNEL);
+ buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!buf) {
pr_err("Unable to allocate FILEIO prot buf\n");
return -ENOMEM;
@@ -524,7 +524,7 @@ fd_do_prot_unmap(struct se_cmd *cmd, sector_t lba, sector_t nolb)
rc = fd_do_prot_fill(cmd->se_dev, lba, nolb, buf, PAGE_SIZE);
- free_page((unsigned long)buf);
+ kfree(buf);
return rc;
}