regulator: event: Add netlink command for event mask
PATCH v2 1/1 regulator: event: Add netlink command for event mask
Add netlink command to enable perticular event(s) broadcasting instead of all regulator events.
...
Changes in v2:
- Update attribute to REG_GENL_ATTR_SET_EVENT_MASK
--- drivers/regulator/event.c | 28 ++++++++++++++++++++++++++++ include/uapi/regulator/regulator.h | 1 + 2 files changed, 29 insertions(+)
drivers/regulator/event.c +28 -0
@@ -14,17 +14,41 @@static atomic_t reg_event_seqnum =ATOMIC_INIT (0 ); +static u64 event_mask; +static const struct genl_multicast_group reg_event_mcgrps[] = { { .name =REG_GENL_MCAST_GROUP_NAME , }, }; +static int reg_genl_cmd_doit (struct sk_buff *skb,struct genl_info *info) +{ +if (info->attrs[REG_GENL_ATTR_SET_EVENT_MASK ]) { + event_mask =nla_get_u64 (info->attrs[REG_GENL_ATTR_SET_EVENT_MASK ]); +pr_info ("event_mask -> %llx" , event_mask); +return 0 ; + } +pr_warn ("Unknown attribute." ); +return -EOPNOTSUPP ; +} + +static const struct genl_small_ops reg_genl_ops[] = { + { + .cmd =REG_GENL_CMD_EVENT , + .validate =GENL_DONT_VALIDATE_STRICT |GENL_DONT_VALIDATE_DUMP , + .doit = reg_genl_cmd_doit, + } +}; +static struct genl_family reg_event_genl_family__ro_after_init = { .module =THIS_MODULE , .name =REG_GENL_FAMILY_NAME , .version =REG_GENL_VERSION , .maxattr =REG_GENL_ATTR_MAX , + .small_ops = reg_genl_ops, + .n_small_ops =ARRAY_SIZE (reg_genl_ops), .mcgrps = reg_event_mcgrps, .n_mcgrps =ARRAY_SIZE (reg_event_mcgrps), + .resv_start_op = __REG_GENL_CMD_MAX, };int reg_generate_netlink_event (const char *reg_name,u64 event)
@@ -35,6 +59,9 @@ int reg_generate_netlink_event(const char *reg_name, u64 event)void *msg_header;int size; +if (!(event_mask & event)) +return 0 ; +/* allocate memory */ size =nla_total_size (sizeof (struct reg_genl_event )) +nla_total_size (0 );
@@ -73,6 +100,7 @@ int reg_generate_netlink_event(const char *reg_name, u64 event)static int __init reg_event_genetlink_init (void ) { + event_mask =0 ;return genl_register_family (®_event_genl_family); }
include/uapi/regulator/regulator.h +1 -0
@@ -69,6 +69,7 @@ struct reg_genl_event {enum {REG_GENL_ATTR_UNSPEC ,REG_GENL_ATTR_EVENT ,/* reg event info needed by user space */ +REG_GENL_ATTR_SET_EVENT_MASK ,/* reg event mask */ __REG_GENL_ATTR_MAX, };
base-commit: 94cc3087aac4103c33c6da84c092301afd783200
Signature · 1 line
2.41.0
Hi Naresh,
Thanks for working on this! :)
Quoted 2 lines · Naresh Solanki
Add netlink command to enable perticular event(s) broadcasting instead of all regulator events.
I think this mechanism for limiting events being forwarded to the listener is worthy. My original idea was to utilize the netlink multicast groups for this so that the regulator core would register multiple multicast groups for this family. User would then listen only the groups he is interested, and multiplexing the messages would be done by netlink/socket code.
Problem(?) of the approach you propose here is that the event filtering is global for all users. If multicast groups were used, this filtering would be done per listener socket basis. I'm not sure if that would be needed though, but somehow I feel it would be more usable for different user-land appliactions (cost being the increased complexity though).
Eg, I am thinking users could enable receiving multicasts for events they like using:
setsockopt(..., SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, ..., ...)
Do you think allowing setting the 'filtering' this way per socket would work or be beneficial?
Quoted 18 lines
Signed-off-by Naresh Solanki <[email protected]>...
Changes in v2:
- Update attribute toREG_GENL_ATTR_SET_EVENT_MASK--- drivers/regulator/event.c | 28 ++++++++++++++++++++++++++++ include/uapi/regulator/regulator.h | 1 + 2 files changed, 29 insertions(+)drivers/regulator/event.c +0
-0@@ -14,17 +14,41 @@static atomic_t reg_event_seqnum =ATOMIC_INIT (0 );
drivers/regulator/event.c line 26
Quoted 10 lines
drivers/regulator/event.c +6
-0+static u64 event_mask; +static const struct genl_multicast_group reg_event_mcgrps[] = { { .name =REG_GENL_MCAST_GROUP_NAME , }, }; +static int reg_genl_cmd_doit (struct sk_buff *skb,struct genl_info *info) +{ +if (info->attrs[REG_GENL_ATTR_SET_EVENT_MASK ]) { + event_mask =nla_get_u64 (info->attrs[REG_GENL_ATTR_SET_EVENT_MASK ]);
If we go with just a global event_mask (not per listener) event filtering, then we might need protection/barrier for this write of a 64bit value(?)
drivers/regulator/event.c line 27
Quoted 1 line
drivers/regulator/event.c +1
-0+pr_info ("event_mask -> %llx" , event_mask);
I would drop this print, or by very least, make it dbg.
drivers/regulator/event.c line 30
Quoted 3 lines
drivers/regulator/event.c +3
-0+return 0 ; + } +pr_warn ("Unknown attribute." );
I would make this dbg as well.
Quoted 25 lines
drivers/regulator/event.c +14
-0+return -EOPNOTSUPP ; +} + +static const struct genl_small_ops reg_genl_ops[] = { + { + .cmd =REG_GENL_CMD_EVENT , + .validate =GENL_DONT_VALIDATE_STRICT |GENL_DONT_VALIDATE_DUMP , + .doit = reg_genl_cmd_doit, + } +}; +static struct genl_family reg_event_genl_family__ro_after_init = { .module =THIS_MODULE , .name =REG_GENL_FAMILY_NAME , .version =REG_GENL_VERSION , .maxattr =REG_GENL_ATTR_MAX , + .small_ops = reg_genl_ops, + .n_small_ops =ARRAY_SIZE (reg_genl_ops), .mcgrps = reg_event_mcgrps, .n_mcgrps =ARRAY_SIZE (reg_event_mcgrps), + .resv_start_op = __REG_GENL_CMD_MAX, };int reg_generate_netlink_event (const char *reg_name,u64 event)
drivers/regulator/event.c int reg_generate_netlink_event(const char *reg_name, u64 event) · line 61
Quoted 3 lines
drivers/regulator/event.c +0
-0@@ -35,6 +59,9 @@ int reg_generate_netlink_event(const char *reg_name, u64 event)void *msg_header;int size;
Barrier/locking here too?
Quoted 26 lines
drivers/regulator/event.c +3
-0+if (!(event_mask & event)) + return 0; > +/* allocate memory */ size =nla_total_size (sizeof (struct reg_genl_event )) +nla_total_size (0 );@@ -73,6 +100,7 @@ int reg_generate_netlink_event(const char *reg_name, u64 event)static int __init reg_event_genetlink_init (void ) { + event_mask =0 ;return genl_register_family (®_event_genl_family); }include/uapi/regulator/regulator.h +1
-0@@ -69,6 +69,7 @@ struct reg_genl_event {enum {REG_GENL_ATTR_UNSPEC ,REG_GENL_ATTR_EVENT ,/* reg event info needed by user space */ +REG_GENL_ATTR_SET_EVENT_MASK ,/* reg event mask */ __REG_GENL_ATTR_MAX, };
Quoted 1 line
base-commit:
94cc3087aac4103c33c6da84c092301afd783200
Yours,
-- Matti
Signature · 5 lines
Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~
Mark Brown
maintainerQuoted 2 lines · Matti Vaittinen
Do you think allowing setting the 'filtering' this way per socket would work or be beneficial?
I haven't thought about it enough to say anything about the working bit but it does seem like it could be useful (eg, a UI might be interested in more events than something just looking for critical errors).
Mark Brown
maintainerQuoted 11 lines · Matti Vaittinen
Quoted 1 line · Naresh Solanki
Add netlink command to enable perticular event(s) broadcasting instead
I think this mechanism for limiting events being forwarded to the listener is worthy. My original idea was to utilize the netlink multicast groups for this so that the regulator core would register multiple multicast groups for this family. User would then listen only the groups he is interested, and multiplexing the messages would be done by netlink/socket code.
Quoted 5 lines
Problem(?) of the approach you propose here is that the event filtering is global for all users. If multicast groups were used, this filtering would be done per listener socket basis. I'm not sure if that would be needed though, but somehow I feel it would be more usable for different user-land appliactions (cost being the increased complexity though).
Thinking about this some more I do think that global filtering like the current patch would at least need some sort of permission check, otherwise just any random process can disrupt everyone's monitoring. Per socket filtering does seem like the way to go.
Hi
Quoted 19 lines · Mark Brown
Quoted 11 lines · Matti Vaittinen
Quoted 1 line · Naresh Solanki
Add netlink command to enable perticular event(s) broadcasting instead
I think this mechanism for limiting events being forwarded to the listener is worthy. My original idea was to utilize the netlink multicast groups for this so that the regulator core would register multiple multicast groups for this family. User would then listen only the groups he is interested, and multiplexing the messages would be done by netlink/socket code.
Quoted 5 lines
Problem(?) of the approach you propose here is that the event filtering is global for all users. If multicast groups were used, this filtering would be done per listener socket basis. I'm not sure if that would be needed though, but somehow I feel it would be more usable for different user-land appliactions (cost being the increased complexity though).
Quoted 4 lines
Thinking about this some more I do think that global filtering like the current patch would at least need some sort of permission check, otherwise just any random process can disrupt everyone's monitoring. Per socket filtering does seem like the way to go.
Agree. Will work on it & after validation will post the CL. This change can be abandoned for now.
Regards,
Naresh