[PATCH 3/3] slab: use new API for remaining command line parameters

Petr Tesarik posted 3 patches 3 months, 2 weeks ago
[PATCH 3/3] slab: use new API for remaining command line parameters
Posted by Petr Tesarik 3 months, 2 weeks ago
Use core_param() and __core_param_cb() instead of __setup() or
__setup_param() to improve syntax checking and error messages.

Replace get_option() with kstrtouint(), because:
* the latter accepts a pointer to const char,
* these parameters should not accept ranges,
* error value can be passed directly to parser.

There is one more change apart from the parsing of numeric parameters:
slub_strict_numa parameter name must match exactly. Before this patch the
kernel would silently accept any option that starts with the name as an
undocumented alias.

Signed-off-by: Petr Tesarik <ptesarik@suse.com>
---
 mm/slub.c | 57 +++++++++++++++++++++++++++++++++----------------------
 1 file changed, 34 insertions(+), 23 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index b124087b95f32..482460ff3abca 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -8119,46 +8119,53 @@ void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab)
  *		Kmalloc subsystem
  *******************************************************************/
 
-static int __init setup_slub_min_order(char *str)
+static int __init setup_slub_min_order(const char *str, const struct kernel_param *kp)
 {
-	get_option(&str, (int *)&slub_min_order);
+	int ret;
+
+	ret = kstrtouint(str, 0, &slub_min_order);
+	if (ret)
+		return ret;
 
 	if (slub_min_order > slub_max_order)
 		slub_max_order = slub_min_order;
 
-	return 1;
+	return 0;
 }
 
-__setup("slab_min_order=", setup_slub_min_order);
-__setup_param("slub_min_order=", slub_min_order, setup_slub_min_order, 0);
-
+static const struct kernel_param_ops param_ops_slab_min_order __initconst = {
+	.set = setup_slub_min_order,
+};
+__core_param_cb(slab_min_order, &param_ops_slab_min_order, &slub_min_order, 0);
+__core_param_cb(slub_min_order, &param_ops_slab_min_order, &slub_min_order, 0);
 
-static int __init setup_slub_max_order(char *str)
+static int __init setup_slub_max_order(const char *str, const struct kernel_param *kp)
 {
-	get_option(&str, (int *)&slub_max_order);
+	int ret;
+
+	ret = kstrtouint(str, 0, &slub_max_order);
+	if (ret)
+		return ret;
+
 	slub_max_order = min_t(unsigned int, slub_max_order, MAX_PAGE_ORDER);
 
 	if (slub_min_order > slub_max_order)
 		slub_min_order = slub_max_order;
 
-	return 1;
+	return 0;
 }
 
-__setup("slab_max_order=", setup_slub_max_order);
-__setup_param("slub_max_order=", slub_max_order, setup_slub_max_order, 0);
-
-static int __init setup_slub_min_objects(char *str)
-{
-	get_option(&str, (int *)&slub_min_objects);
-
-	return 1;
-}
+static const struct kernel_param_ops param_ops_slab_max_order __initconst = {
+	.set = setup_slub_max_order,
+};
+__core_param_cb(slab_max_order, &param_ops_slab_max_order, &slub_max_order, 0);
+__core_param_cb(slub_max_order, &param_ops_slab_max_order, &slub_max_order, 0);
 
-__setup("slab_min_objects=", setup_slub_min_objects);
-__setup_param("slub_min_objects=", slub_min_objects, setup_slub_min_objects, 0);
+core_param(slab_min_objects, slub_min_objects, uint, 0);
+core_param(slub_min_objects, slub_min_objects, uint, 0);
 
 #ifdef CONFIG_NUMA
-static int __init setup_slab_strict_numa(char *str)
+static int __init setup_slab_strict_numa(const char *str, const struct kernel_param *kp)
 {
 	if (nr_node_ids > 1) {
 		static_branch_enable(&strict_numa);
@@ -8167,10 +8174,14 @@ static int __init setup_slab_strict_numa(char *str)
 		pr_warn("slab_strict_numa parameter set on non NUMA system.\n");
 	}
 
-	return 1;
+	return 0;
 }
 
-__setup("slab_strict_numa", setup_slab_strict_numa);
+static const struct kernel_param_ops param_ops_slab_strict_numa __initconst = {
+	.flags = KERNEL_PARAM_OPS_FL_NOARG,
+	.set = setup_slab_strict_numa,
+};
+__core_param_cb(slab_strict_numa, &param_ops_slab_strict_numa, NULL, 0);
 #endif
 
 
-- 
2.51.0
Re: [PATCH 3/3] slab: use new API for remaining command line parameters
Posted by Harry Yoo 3 months, 1 week ago
On Fri, Oct 24, 2025 at 07:06:54PM +0200, Petr Tesarik wrote:
> Use core_param() and __core_param_cb() instead of __setup() or
> __setup_param() to improve syntax checking and error messages.
> 
> Replace get_option() with kstrtouint(), because:
> * the latter accepts a pointer to const char,
> * these parameters should not accept ranges,
> * error value can be passed directly to parser.
> 
> There is one more change apart from the parsing of numeric parameters:
> slub_strict_numa parameter name must match exactly. Before this patch the

nit: ^ slab_strict_numa

> kernel would silently accept any option that starts with the name as an
> undocumented alias.
> 
> Signed-off-by: Petr Tesarik <ptesarik@suse.com>
> ---

Looks good to me,
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>

-- 
Cheers,
Harry / Hyeonggon
Re: [PATCH 3/3] slab: use new API for remaining command line parameters
Posted by Petr Tesarik 3 months, 1 week ago
On Wed, 29 Oct 2025 19:52:46 +0900
Harry Yoo <harry.yoo@oracle.com> wrote:

> On Fri, Oct 24, 2025 at 07:06:54PM +0200, Petr Tesarik wrote:
> > Use core_param() and __core_param_cb() instead of __setup() or
> > __setup_param() to improve syntax checking and error messages.
> > 
> > Replace get_option() with kstrtouint(), because:
> > * the latter accepts a pointer to const char,
> > * these parameters should not accept ranges,
> > * error value can be passed directly to parser.
> > 
> > There is one more change apart from the parsing of numeric parameters:
> > slub_strict_numa parameter name must match exactly. Before this patch the  
> 
> nit: ^ slab_strict_numa

Indeed.

Petr T
Re: [PATCH 3/3] slab: use new API for remaining command line parameters
Posted by Vlastimil Babka 3 months, 1 week ago
On 10/30/25 14:32, Petr Tesarik wrote:
> On Wed, 29 Oct 2025 19:52:46 +0900
> Harry Yoo <harry.yoo@oracle.com> wrote:
> 
>> On Fri, Oct 24, 2025 at 07:06:54PM +0200, Petr Tesarik wrote:
>> > Use core_param() and __core_param_cb() instead of __setup() or
>> > __setup_param() to improve syntax checking and error messages.
>> > 
>> > Replace get_option() with kstrtouint(), because:
>> > * the latter accepts a pointer to const char,
>> > * these parameters should not accept ranges,
>> > * error value can be passed directly to parser.
>> > 
>> > There is one more change apart from the parsing of numeric parameters:
>> > slub_strict_numa parameter name must match exactly. Before this patch the  
>> 
>> nit: ^ slab_strict_numa

Ah right, thanks, fixed up.

> Indeed.
> 
> Petr T