Linux filesystem development
 help / color / mirror / Atom feed
* [PATCH] init: do_mounts: use kmalloc() for allocations of temporary buffers
@ 2026-05-20  8:16 Mike Rapoport (Microsoft)
  2026-05-20 10:57 ` David Disseldorp
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-05-20  8:16 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, Jan Kara
  Cc: Mike Rapoport, linux-fsdevel, linux-kernel, linux-mm

Several places in init/do_mounts.c allocate temporary buffers for
filesystem names or options using __get_free_page() or alloc_page().

Usage of alloc_page() APIs is not required there and only creates
unnecessary noise with castings or conversion from struct page to void *.

kmalloc() is a better API for these uses and it also provides better
scalability and more debugging possibilities.

Replace use of __get_free_page() and alloc_page() with kmalloc().

While on it, add a check for -ENOMEM condition in mount_root_generic().

Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
This is a (tiny) part of larger work of replacing page allocator calls
with kmalloc:

Also in git:
https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git gfp-to-kmalloc/init
---
 init/do_mounts.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/init/do_mounts.c b/init/do_mounts.c
index 55ed3ac0b70f..95e0b3a0f711 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -143,16 +143,14 @@ static int __init do_mount_root(const char *name, const char *fs,
 				 const int flags, const void *data)
 {
 	struct super_block *s;
-	struct page *p = NULL;
 	char *data_page = NULL;
 	int ret;
 
 	if (data) {
 		/* init_mount() requires a full page as fifth argument */
-		p = alloc_page(GFP_KERNEL);
-		if (!p)
+		data_page = kmalloc(PAGE_SIZE, GFP_KERNEL);
+		if (!data_page)
 			return -ENOMEM;
-		data_page = page_address(p);
 		strscpy_pad(data_page, data, PAGE_SIZE);
 	}
 
@@ -170,19 +168,20 @@ static int __init do_mount_root(const char *name, const char *fs,
 	       MAJOR(ROOT_DEV), MINOR(ROOT_DEV));
 
 out:
-	if (p)
-		put_page(p);
+	kfree(data_page);
 	return ret;
 }
 
 void __init mount_root_generic(char *name, char *pretty_name, int flags)
 {
-	struct page *page = alloc_page(GFP_KERNEL);
-	char *fs_names = page_address(page);
+	char *fs_names = kmalloc(PAGE_SIZE, GFP_KERNEL);
 	char *p;
 	char b[BDEVNAME_SIZE];
 	int num_fs, i;
 
+	if (!fs_names)
+		panic("VFS: Unable to mount root fs: not enough memory");
+
 	scnprintf(b, BDEVNAME_SIZE, "unknown-block(%u,%u)",
 		  MAJOR(ROOT_DEV), MINOR(ROOT_DEV));
 	if (root_fs_names)
@@ -242,7 +241,7 @@ void __init mount_root_generic(char *name, char *pretty_name, int flags)
 	printk("\n");
 	panic("VFS: Unable to mount root fs on \"%s\" or %s", pretty_name, b);
 out:
-	put_page(page);
+	kfree(fs_names);
 }
  
 #ifdef CONFIG_ROOT_NFS
@@ -343,7 +342,7 @@ static int __init mount_nodev_root(char *root_device_name)
 	int err = -EINVAL;
 	int num_fs, i;
 
-	fs_names = (void *)__get_free_page(GFP_KERNEL);
+	fs_names = kmalloc(PAGE_SIZE, GFP_KERNEL);
 	if (!fs_names)
 		return -EINVAL;
 	num_fs = split_fs_names(fs_names, PAGE_SIZE);
@@ -360,7 +359,7 @@ static int __init mount_nodev_root(char *root_device_name)
 			break;
 	}
 
-	free_page((unsigned long)fs_names);
+	kfree(fs_names);
 	return err;
 }
 

---
base-commit: 5d6919055dec134de3c40167a490f33c74c12581
change-id: 20260520-init-152a94946e25

Best regards,
--  
Sincerely yours,
Mike.


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] init: do_mounts: use kmalloc() for allocations of temporary buffers
  2026-05-20  8:16 [PATCH] init: do_mounts: use kmalloc() for allocations of temporary buffers Mike Rapoport (Microsoft)
@ 2026-05-20 10:57 ` David Disseldorp
  2026-05-20 12:41 ` kernel test robot
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: David Disseldorp @ 2026-05-20 10:57 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft)
  Cc: Alexander Viro, Christian Brauner, Jan Kara, linux-fsdevel,
	linux-kernel, linux-mm

On Wed, 20 May 2026 11:16:51 +0300, Mike Rapoport (Microsoft) wrote:

> Several places in init/do_mounts.c allocate temporary buffers for
> filesystem names or options using __get_free_page() or alloc_page().
> 
> Usage of alloc_page() APIs is not required there and only creates
> unnecessary noise with castings or conversion from struct page to void *.
> 
> kmalloc() is a better API for these uses and it also provides better
> scalability and more debugging possibilities.
> 
> Replace use of __get_free_page() and alloc_page() with kmalloc().
> 
> While on it, add a check for -ENOMEM condition in mount_root_generic().
> 
> Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

Looks fine...
Reviewed-by: David Disseldorp <ddiss@suse.de>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] init: do_mounts: use kmalloc() for allocations of temporary buffers
  2026-05-20  8:16 [PATCH] init: do_mounts: use kmalloc() for allocations of temporary buffers Mike Rapoport (Microsoft)
  2026-05-20 10:57 ` David Disseldorp
@ 2026-05-20 12:41 ` kernel test robot
  2026-05-21  0:49 ` SeongJae Park
  2026-05-22 10:13 ` Christian Brauner
  3 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2026-05-20 12:41 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft), Alexander Viro, Christian Brauner,
	Jan Kara
  Cc: oe-kbuild-all, Mike Rapoport, linux-fsdevel, linux-kernel,
	linux-mm

Hi Mike,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 5d6919055dec134de3c40167a490f33c74c12581]

url:    https://github.com/intel-lab-lkp/linux/commits/Mike-Rapoport-Microsoft/init-do_mounts-use-kmalloc-for-allocations-of-temporary-buffers/20260520-164927
base:   5d6919055dec134de3c40167a490f33c74c12581
patch link:    https://lore.kernel.org/r/20260520-init-v1-1-aaf2ebac5ad9%40kernel.org
patch subject: [PATCH] init: do_mounts: use kmalloc() for allocations of temporary buffers
config: xtensa-allnoconfig (https://download.01.org/0day-ci/archive/20260520/202605202055.kwkCHqR9-lkp@intel.com/config)
compiler: xtensa-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260520/202605202055.kwkCHqR9-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202605202055.kwkCHqR9-lkp@intel.com/

All warnings (new ones prefixed by >>, old ones prefixed by <<):

>> WARNING: modpost: vmlinux: section mismatch in reference: try_to_run_init_process+0x24 (section: .text.unlikely) -> initcall_level_names (section: .init.data)

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] init: do_mounts: use kmalloc() for allocations of temporary buffers
  2026-05-20  8:16 [PATCH] init: do_mounts: use kmalloc() for allocations of temporary buffers Mike Rapoport (Microsoft)
  2026-05-20 10:57 ` David Disseldorp
  2026-05-20 12:41 ` kernel test robot
@ 2026-05-21  0:49 ` SeongJae Park
  2026-05-22 10:13 ` Christian Brauner
  3 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2026-05-21  0:49 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft)
  Cc: SeongJae Park, Alexander Viro, Christian Brauner, Jan Kara,
	linux-fsdevel, linux-kernel, linux-mm

On Wed, 20 May 2026 11:16:51 +0300 "Mike Rapoport (Microsoft)" <rppt@kernel.org> wrote:

> Several places in init/do_mounts.c allocate temporary buffers for
> filesystem names or options using __get_free_page() or alloc_page().
> 
> Usage of alloc_page() APIs is not required there and only creates
> unnecessary noise with castings or conversion from struct page to void *.
> 
> kmalloc() is a better API for these uses and it also provides better
> scalability and more debugging possibilities.
> 
> Replace use of __get_free_page() and alloc_page() with kmalloc().

Makes sense.  I once wondered if kmalloc_objs() fits here, but kmalloc() also
looks good to me.

> 
> While on it, add a check for -ENOMEM condition in mount_root_generic().
> 
> Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

Reviewed-by: SeongJae Park <sj@kernel.org>


Thanks,
SJ

[...]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] init: do_mounts: use kmalloc() for allocations of temporary buffers
  2026-05-20  8:16 [PATCH] init: do_mounts: use kmalloc() for allocations of temporary buffers Mike Rapoport (Microsoft)
                   ` (2 preceding siblings ...)
  2026-05-21  0:49 ` SeongJae Park
@ 2026-05-22 10:13 ` Christian Brauner
  3 siblings, 0 replies; 5+ messages in thread
From: Christian Brauner @ 2026-05-22 10:13 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft)
  Cc: Christian Brauner, Alexander Viro, Jan Kara, linux-fsdevel,
	linux-kernel, linux-mm

On Wed, 20 May 2026 11:16:51 +0300, Mike Rapoport (Microsoft) wrote:
> Several places in init/do_mounts.c allocate temporary buffers for
> filesystem names or options using __get_free_page() or alloc_page().
> 
> Usage of alloc_page() APIs is not required there and only creates
> unnecessary noise with castings or conversion from struct page to void *.
> 
> kmalloc() is a better API for these uses and it also provides better
> scalability and more debugging possibilities.
> 
> [...]

Applied to the vfs-7.2.misc branch of the vfs/vfs.git tree.
Patches in the vfs-7.2.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.2.misc

[1/1] init: do_mounts: use kmalloc() for allocations of temporary buffers
      https://git.kernel.org/vfs/vfs/c/3fb2d124b647

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-05-22 10:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-20  8:16 [PATCH] init: do_mounts: use kmalloc() for allocations of temporary buffers Mike Rapoport (Microsoft)
2026-05-20 10:57 ` David Disseldorp
2026-05-20 12:41 ` kernel test robot
2026-05-21  0:49 ` SeongJae Park
2026-05-22 10:13 ` Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox