2023-09-14 08:58:27

by Kees Cook

[permalink] [raw]
Subject: [PATCH v2] module: Clarify documentation of module_param_call()

Commit 9bbb9e5a3310 ("param: use ops in struct kernel_param, rather than
get and set fns directly") added the comment that module_param_call()
was deprecated, during a large scale refactoring to bring sanity to type
casting back then. In 2017 following more cleanups, it became useful
again as it wraps a common pattern of creating an ops struct for a
given get/set pair:

b2f270e87473 ("module: Prepare to convert all module_param_call() prototypes")
ece1996a21ee ("module: Do not paper over type mismatches in module_param_call()")

static const struct kernel_param_ops __param_ops_##name = \
{ .flags = 0, .set = _set, .get = _get }; \
__module_param_call(MODULE_PARAM_PREFIX, \
name, &__param_ops_##name, arg, perm, -1, 0)

__module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, 0)

Many users of module_param_cb() appear to be almost universally
open-coding the same thing that module_param_call() does now. Don't
discourage[1] people from using module_param_call(): clarify the comment
to show that module_param_cb() is useful if you repeatedly use the same
pair of get/set functions.

[1] https://lore.kernel.org/lkml/202308301546.5C789E5EC@keescook/

Cc: Luis Chamberlain <[email protected]>
Cc: Johan Hovold <[email protected]>
Cc: Jessica Yu <[email protected]>
Cc: Sagi Grimberg <[email protected]>
Cc: Nick Desaulniers <[email protected]>
Cc: Miguel Ojeda <[email protected]>
Cc: Joe Perches <[email protected]>
Cc: [email protected]
Reviewed-by: Miguel Ojeda <[email protected]>
Signed-off-by: Kees Cook <[email protected]>
---
Luis, I note that include/linux/moduleparam.h isn't in the MAINTAINERS
file pattern. Perhaps you want to use include/linux/module*.h?
---
include/linux/moduleparam.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index 962cd41a2cb5..d4452f93d060 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -293,7 +293,11 @@ struct kparam_array
= { __param_str_##name, THIS_MODULE, ops, \
VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg } }

-/* Obsolete - use module_param_cb() */
+/*
+ * Useful for describing a set/get pair used only once (i.e. for this
+ * parameter). For repeated set/get pairs (i.e. the same struct
+ * kernel_param_ops), use module_param_cb() instead.
+ */
#define module_param_call(name, _set, _get, arg, perm) \
static const struct kernel_param_ops __param_ops_##name = \
{ .flags = 0, .set = _set, .get = _get }; \
--
2.34.1


2023-09-20 23:24:12

by Luis Chamberlain

[permalink] [raw]
Subject: Re: [PATCH v2] module: Clarify documentation of module_param_call()

On Wed, Sep 13, 2023 at 04:54:14PM -0700, Kees Cook wrote:
> Commit 9bbb9e5a3310 ("param: use ops in struct kernel_param, rather than
> get and set fns directly") added the comment that module_param_call()
> was deprecated, during a large scale refactoring to bring sanity to type
> casting back then. In 2017 following more cleanups, it became useful
> again as it wraps a common pattern of creating an ops struct for a
> given get/set pair:
>
> b2f270e87473 ("module: Prepare to convert all module_param_call() prototypes")
> ece1996a21ee ("module: Do not paper over type mismatches in module_param_call()")
>
> static const struct kernel_param_ops __param_ops_##name = \
> { .flags = 0, .set = _set, .get = _get }; \
> __module_param_call(MODULE_PARAM_PREFIX, \
> name, &__param_ops_##name, arg, perm, -1, 0)
>
> __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, 0)
>
> Many users of module_param_cb() appear to be almost universally
> open-coding the same thing that module_param_call() does now. Don't
> discourage[1] people from using module_param_call(): clarify the comment
> to show that module_param_cb() is useful if you repeatedly use the same
> pair of get/set functions.
>
> [1] https://lore.kernel.org/lkml/202308301546.5C789E5EC@keescook/
>
> Cc: Luis Chamberlain <[email protected]>
> Cc: Johan Hovold <[email protected]>
> Cc: Jessica Yu <[email protected]>
> Cc: Sagi Grimberg <[email protected]>
> Cc: Nick Desaulniers <[email protected]>
> Cc: Miguel Ojeda <[email protected]>
> Cc: Joe Perches <[email protected]>
> Cc: [email protected]
> Reviewed-by: Miguel Ojeda <[email protected]>
> Signed-off-by: Kees Cook <[email protected]>

Applied and pushed to modules-next, thanks

> ---
> Luis, I note that include/linux/moduleparam.h isn't in the MAINTAINERS
> file pattern. Perhaps you want to use include/linux/module*.h?

Sent patch! Thanks!

Luis