params: Add support for static keys
Subsystems (2)
PATCH v2 1/1 params: Add support for static keys
Static keys can now be a module parameter, e.g.
module_param_named(foo, foo.key, static_key_t, 0644)
bcachefs is now using this.
--- include/linux/jump_label.h | 2 ++ include/linux/moduleparam.h | 7 +++++++ kernel/params.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+)
include/linux/jump_label.h +2 -0
@@ -107,6 +107,8 @@ struct static_key { #endif /* CONFIG_JUMP_LABEL */ }; +typedef struct static_key static_key_t ; +#endif /* __ASSEMBLY__ */ #ifdef CONFIG_JUMP_LABEL
include/linux/moduleparam.h +7 -0
@@ -122,6 +122,7 @@ struct kparam_array* charp: a character pointer * bool: a bool, values 0/1, y/n, Y/N. * invbool: the above, only sense-reversed (N = true). +* static_key_t: same as bool, but updates a 'struct static_key' */ #define module_param (name, type, perm) \ module_param_named(name, name, type, perm)
@@ -488,6 +489,12 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);#define param_get_bint param_get_int#define param_check_bint param_check_int +/* A static key, which can only be set like a bool */ +extern const struct kernel_param_ops param_ops_static_key_t; +extern int param_set_static_key_t (const char *val,const struct kernel_param *kp); +extern int param_get_static_key_t (char *buffer,const struct kernel_param *kp); +#define param_check_static_key_t (name, p) __param_check(name, p, struct static_key) +/** * module_param_array - a parameter which is an array of some type * @name: the name of the array variable
kernel/params.c +35 -0
@@ -14,6 +14,7 @@#include <linux/overflow.h> #include <linux/security.h> #include <linux/slab.h> +#include <linux/static_key.h> #include <linux/string.h> #ifdef CONFIG_SYSFS
@@ -412,6 +413,40 @@ const struct kernel_param_ops param_ops_bint = { };EXPORT_SYMBOL (param_ops_bint); +int param_set_static_key_t (const char *val,const struct kernel_param *kp) +{ +/* Match bool exactly, by re-using it. */ +struct kernel_param boolkp = *kp; +bool v; +int ret; + + boolkp.arg = &v; + + ret =param_set_bool (val, &boolkp); +if (ret) +return ret; +if (v) +static_key_enable (kp->arg); +else +static_key_disable (kp->arg); +return 0 ; +} +EXPORT_SYMBOL (param_set_static_key_t); + +int param_get_static_key_t (char *buffer,const struct kernel_param *kp) +{ +struct static_key *key = kp->arg; +return sprintf (buffer,"%c\n" ,static_key_enabled (key) ?'Y' :'N' ); +} +EXPORT_SYMBOL (param_get_static_key_t); + +const struct kernel_param_ops param_ops_static_key_t = { + .flags =KERNEL_PARAM_OPS_FL_NOARG , + .set = param_set_static_key_t, + .get = param_get_static_key_t, +}; +EXPORT_SYMBOL (param_ops_static_key_t); +/* We break the rule and mangle the string. */ static int param_array(struct module *mod, const char *name,
Signature · 1 line
2.49.0
Josh Poimboeuf
maintainerQuoted 41 lines · Kent Overstreet
Static keys can now be a module parameter, e.g.
module_param_named(foo, foo.key, static_key_t, 0644)bcachefs is now using this.
Cc Luis Chamberlain <[email protected]>Cc Petr Pavlu <[email protected]>Cc Sami Tolvanen <[email protected]>Cc Daniel Gomez <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Josh Poimboeuf <[email protected]>Cc Jason Baron <[email protected]>Cc Steven Rostedt <[email protected]>Cc Ard Biesheuvel <[email protected]>Signed-off-by Kent Overstreet <[email protected]>--- include/linux/jump_label.h | 2 ++ include/linux/moduleparam.h | 7 +++++++ kernel/params.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+)include/linux/jump_label.h +2
-0@@ -107,6 +107,8 @@ struct static_key { #endif /* CONFIG_JUMP_LABEL */ }; +typedef struct static_key static_key_t ; +#endif /* __ASSEMBLY__ */ #ifdef CONFIG_JUMP_LABEL include/linux/moduleparam.h +0
-0
include/linux/moduleparam.h struct kparam_array · line 125
Quoted 4 lines
include/linux/moduleparam.h +1
-0@@ -122,6 +122,7 @@ struct kparam_array* charp: a character pointer * bool: a bool, values 0/1, y/n, Y/N. * invbool: the above, only sense-reversed (N = true). +* static_key_t: same as bool, but updates a 'struct static_key'
The static_key_*() interfaces are deprecated because they're really easy to use incorrectly. I don't think we want to propagate that misuse to modules.
It would be better to have type(s) based on static_key_false and/or static_key_true, depending on whatever the default is.
Signature · 1 line
Josh
Quoted 51 lines · Josh Poimboeuf
Quoted 41 lines · Kent Overstreet
Static keys can now be a module parameter, e.g.
module_param_named(foo, foo.key, static_key_t, 0644)bcachefs is now using this.
Cc Luis Chamberlain <[email protected]>Cc Petr Pavlu <[email protected]>Cc Sami Tolvanen <[email protected]>Cc Daniel Gomez <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Josh Poimboeuf <[email protected]>Cc Jason Baron <[email protected]>Cc Steven Rostedt <[email protected]>Cc Ard Biesheuvel <[email protected]>Signed-off-by Kent Overstreet <[email protected]>--- include/linux/jump_label.h | 2 ++ include/linux/moduleparam.h | 7 +++++++ kernel/params.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+)include/linux/jump_label.h +2
-0@@ -107,6 +107,8 @@ struct static_key { #endif /* CONFIG_JUMP_LABEL */ }; +typedef struct static_key static_key_t ; +#endif /* __ASSEMBLY__ */ #ifdef CONFIG_JUMP_LABEL include/linux/moduleparam.h +0
-0include/linux/moduleparam.h struct kparam_array · line 125
Quoted 4 lines
include/linux/moduleparam.h +1
-0@@ -122,6 +122,7 @@ struct kparam_array* charp: a character pointer * bool: a bool, values 0/1, y/n, Y/N. * invbool: the above, only sense-reversed (N = true). +* static_key_t: same as bool, but updates a 'struct static_key' The static_key_*() interfaces are deprecated because they're really easy to use incorrectly. I don't think we want to propagate that misuse to modules.
Quoted 2 lines
It would be better to have type(s) based on
static_key_falseand/orstatic_key_true, depending on whatever the default is.
Except those are just wrappers around struct static_key, so why does that matter here?
Josh Poimboeuf
maintainerQuoted 12 lines · Kent Overstreet
Quoted 11 lines · Josh Poimboeuf
include/linux/moduleparam.h struct kparam_array · line 125
Quoted 6 lines
+++
b/include/linux/moduleparam.hinclude/linux/moduleparam.h +1
-0@@ -122,6 +122,7 @@ struct kparam_array* charp: a character pointer * bool: a bool, values 0/1, y/n, Y/N. * invbool: the above, only sense-reversed (N = true). +* static_key_t: same as bool, but updates a 'struct static_key' The static_key_*() interfaces are deprecated because they're really easy to use incorrectly. I don't think we want to propagate that misuse to modules.
Quoted 5 lines
Quoted 2 lines
It would be better to have type(s) based on
static_key_falseand/orstatic_key_true, depending on whatever the default is.Except those are just wrappers around struct
static_key, so why does that matter here?
Those struct wrappers are needed to work with static_branch_likely() and static_branch_unlikely().
We really need to get rid of old static_key_true() and static_key_false(), they don't have many users left at this point.
Signature · 1 line
Josh
Quoted 13 lines · Josh Poimboeuf
Quoted 12 lines · Kent Overstreet
Quoted 11 lines · Josh Poimboeuf
include/linux/moduleparam.h struct kparam_array · line 125
Quoted 6 lines
+++
b/include/linux/moduleparam.hinclude/linux/moduleparam.h +1
-0@@ -122,6 +122,7 @@ struct kparam_array* charp: a character pointer * bool: a bool, values 0/1, y/n, Y/N. * invbool: the above, only sense-reversed (N = true). +* static_key_t: same as bool, but updates a 'struct static_key' The static_key_*() interfaces are deprecated because they're really easy to use incorrectly. I don't think we want to propagate that misuse to modules.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
It would be better to have type(s) based on
static_key_falseand/orstatic_key_true, depending on whatever the default is.Except those are just wrappers around struct
static_key, so why does that matter here?Those struct wrappers are needed to work with
static_branch_likely()andstatic_branch_unlikely().
Sure, but this has no bearing on that - unless I've missed them, there aren't separate methods for just setting and checking the value, which is all we're doing here.
Josh Poimboeuf
maintainerQuoted 20 lines · Kent Overstreet
Quoted 19 lines · Josh Poimboeuf
Quoted 17 lines · Kent Overstreet
Quoted 11 lines · Josh Poimboeuf
include/linux/moduleparam.h struct kparam_array · line 125
Quoted 6 lines
+++
b/include/linux/moduleparam.hinclude/linux/moduleparam.h +1
-0@@ -122,6 +122,7 @@ struct kparam_array* charp: a character pointer * bool: a bool, values 0/1, y/n, Y/N. * invbool: the above, only sense-reversed (N = true). +* static_key_t: same as bool, but updates a 'struct static_key' The static_key_*() interfaces are deprecated because they're really easy to use incorrectly. I don't think we want to propagate that misuse to modules.
Quoted 2 lines
It would be better to have type(s) based on
static_key_falseand/orstatic_key_true, depending on whatever the default is.Except those are just wrappers around struct
static_key, so why does that matter here?
Quoted 6 lines
Quoted 2 lines
Those struct wrappers are needed to work with
static_branch_likely()andstatic_branch_unlikely().Sure, but this has no bearing on that - unless I've missed them, there aren't separate methods for just setting and checking the value, which is all we're doing here.
To make use of this feature, wouldn't the module need to use static_key_false() or so to actually insert the static branch to check the value? Otherwise what's the point of using static keys here?
Signature · 1 line
Josh
Quoted 24 lines · Josh Poimboeuf
Quoted 23 lines · Kent Overstreet
Quoted 21 lines · Josh Poimboeuf
Quoted 12 lines · Kent Overstreet
Quoted 11 lines · Josh Poimboeuf
include/linux/moduleparam.h struct kparam_array · line 125
Quoted 6 lines
+++
b/include/linux/moduleparam.hinclude/linux/moduleparam.h +1
-0@@ -122,6 +122,7 @@ struct kparam_array* charp: a character pointer * bool: a bool, values 0/1, y/n, Y/N. * invbool: the above, only sense-reversed (N = true). +* static_key_t: same as bool, but updates a 'struct static_key' The static_key_*() interfaces are deprecated because they're really easy to use incorrectly. I don't think we want to propagate that misuse to modules.
Quoted 5 lines
Quoted 2 lines
It would be better to have type(s) based on
static_key_falseand/orstatic_key_true, depending on whatever the default is.Except those are just wrappers around struct
static_key, so why does that matter here?Those struct wrappers are needed to work with
static_branch_likely()andstatic_branch_unlikely().
Quoted 7 lines
Quoted 3 lines
Sure, but this has no bearing on that - unless I've missed them, there aren't separate methods for just setting and checking the value, which is all we're doing here.
To make use of this feature, wouldn't the module need to use
static_key_false()or so to actually insert the static branch to check the value? Otherwise what's the point of using static keys here?
I'm not sure I follow?
You just pass the inner static_key to the modparam, you still use static_key_true or static_key_false as normal.
Josh Poimboeuf
maintainerQuoted 29 lines · Kent Overstreet
Quoted 28 lines · Josh Poimboeuf
Quoted 26 lines · Kent Overstreet
Quoted 13 lines · Josh Poimboeuf
Quoted 12 lines · Kent Overstreet
Quoted 11 lines · Josh Poimboeuf
Review struct kparam_array · line 125
Quoted 6 lines
+++
b/include/linux/moduleparam.h(quoted diff) +1
-0@@ -122,6 +122,7 @@ struct kparam_array * charp: a character pointer * bool: a bool, values 0/1, y/n, Y/N. * invbool: the above, only sense-reversed (N = true). + * static_key_t: same as bool, but updates a 'struct static_key'The static_key_*() interfaces are deprecated because they're really easy to use incorrectly. I don't think we want to propagate that misuse to modules.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
It would be better to have type(s) based on
static_key_falseand/orstatic_key_true, depending on whatever the default is.Except those are just wrappers around struct
static_key, so why does that matter here?Those struct wrappers are needed to work with
static_branch_likely()andstatic_branch_unlikely().Sure, but this has no bearing on that - unless I've missed them, there aren't separate methods for just setting and checking the value, which is all we're doing here.
Quoted 8 lines
Quoted 3 lines
To make use of this feature, wouldn't the module need to use
static_key_false()or so to actually insert the static branch to check the value? Otherwise what's the point of using static keys here?I'm not sure I follow?
You just pass the inner
static_keyto the modparam, you still usestatic_key_trueorstatic_key_falseas normal.
Ok, so the caller does something like so?
DEFINE_STATIC_KEY_FALSE(foo); module_param_named(foo, foo.key, static_key_t, 0);
I guess that works, but 'foo.key' is awkward in that it's nonobvious and breaks the abstraction. Driver people might end up allocating static_key directly and using the deprecated interfaces again.
My preference would be to stick to the supported interfaces, e.g.:
DEFINE_STATIC_KEY_FALSE(foo); module_param_named(foo, foo, static_key_false_t, 0);
Signature · 1 line
Josh
Quoted 44 lines · Josh Poimboeuf
Quoted 29 lines · Kent Overstreet
Quoted 28 lines · Josh Poimboeuf
Quoted 26 lines · Kent Overstreet
Quoted 13 lines · Josh Poimboeuf
Quoted 12 lines · Kent Overstreet
Quoted 11 lines · Josh Poimboeuf
Review struct kparam_array · line 125
Quoted 6 lines
+++
b/include/linux/moduleparam.h(quoted diff) +1
-0@@ -122,6 +122,7 @@ struct kparam_array * charp: a character pointer * bool: a bool, values 0/1, y/n, Y/N. * invbool: the above, only sense-reversed (N = true). + * static_key_t: same as bool, but updates a 'struct static_key'The static_key_*() interfaces are deprecated because they're really easy to use incorrectly. I don't think we want to propagate that misuse to modules.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
It would be better to have type(s) based on
static_key_falseand/orstatic_key_true, depending on whatever the default is.Except those are just wrappers around struct
static_key, so why does that matter here?Those struct wrappers are needed to work with
static_branch_likely()andstatic_branch_unlikely().Sure, but this has no bearing on that - unless I've missed them, there aren't separate methods for just setting and checking the value, which is all we're doing here.
Quoted 8 lines
Quoted 3 lines
To make use of this feature, wouldn't the module need to use
static_key_false()or so to actually insert the static branch to check the value? Otherwise what's the point of using static keys here?I'm not sure I follow?
You just pass the inner
static_keyto the modparam, you still usestatic_key_trueorstatic_key_falseas normal.Ok, so the caller does something like so?
DEFINE_STATIC_KEY_FALSE(foo); module_param_named(foo, foo.key, static_key_t, 0);
Quoted 8 lines
I guess that works, but 'foo.key' is awkward in that it's nonobvious and breaks the abstraction. Driver people might end up allocating
static_keydirectly and using the deprecated interfaces again.My preference would be to stick to the supported interfaces, e.g.:
DEFINE_STATIC_KEY_FALSE(foo); module_param_named(foo, foo, static_key_false_t, 0);
Yeah, that looks reasonable