devlink: code split and structured instance walk
Subsystems (4)
Jakub Kicinski
maintainercover devlink: code split and structured instance walk
Hi!
I started working on the refcounting / registration changes and (as is usual in our profession) I quickly veered off into refactoring / paying technical debt. I hope this is not too controversial.
===
Split devlink.c into a handful of files, trying to keep the "core" code away from all the command-specific implementations. The core code has been quite scattered before. Going forward we can consider using a source file per-subobject, I think that it's quite beneficial to newcomers (based on relative ease with which folks contribute to ethtool vs devlink). But this series doesn't split everything out, yet - partially due to backporting concerns, but mostly due to lack of time.
Introduce a context structure for dumps, and use it to store the devlink instance ID of the last dumped devlink instance. This means we don't have to restart the walk from 0 each time.
Finally - introduce a "structured walk". A centralized dump handler in devlink/netlink.c which walks the devlink instances, deals with refcounting/locking, simplifying the per-object implementations quite a bit.
Jakub Kicinski (15):
devlink: move code to a dedicated directory
devlink: split out core code
devlink: split out netlink code
devlink: protect devlink dump by the instance lock
netlink: add macro for checking dump ctx size
devlink: use an explicit structure for dump context
devlink: remove start variables from dumps
devlink: drop the filter argument from devlinks_xa_find_get
devlink: health: combine loops in dump
devlink: restart dump based on devlink instance ids (simple)
devlink: restart dump based on devlink instance ids (nested)
devlink: restart dump based on devlink instance ids (function)
devlink: uniformly take the devlink instance lock in the dump loop
devlink: add by-instance dump infra
devlink: convert remaining dumps to the by-instance scheme
include/linux/netlink.h | 4 +
net/Makefile | 1 +
net/core/Makefile | 1 -
net/devlink/Makefile | 3 +
net/{core/devlink.c => devlink/basic.c} | 1457 ++++++-----------------
net/devlink/core.c | 345 ++++++
net/devlink/devl_internal.h | 205 ++++
net/devlink/netlink.c | 241 ++++
net/netfilter/nf_conntrack_netlink.c | 2 +-
9 files changed, 1157 insertions(+), 1102 deletions(-)
create mode 100644 net/devlink/Makefile
rename net/{core/devlink.c => devlink/basic.c} (90%)
create mode 100644 net/devlink/core.c
create mode 100644 net/devlink/devl_internal.h
create mode 100644 net/devlink/netlink.cSignature · 1 line
2.38.1
Jakub Kicinski
maintainerRFC 1/15 devlink: move code to a dedicated directory
The devlink code is hard to navigate with 13kLoC in one file. I really like the way Michal split the ethtool into per-command files and core. It'd probably be too much to split it all up, but we can at least separate the core parts out of the per-cmd implementations and put it in a directory so that new commands can be separate files.
Move the code, subsequent commit will do a partial split.
---
net/Makefile | 1 +
net/core/Makefile | 1 -
net/devlink/Makefile | 3 +++
net/{core/devlink.c => devlink/basic.c} | 0
4 files changed, 4 insertions(+), 1 deletion(-)
create mode 100644 net/devlink/Makefile
rename net/{core/devlink.c => devlink/basic.c} (100%)net/Makefile +1 -0
@@ -23,6 +23,7 @@ obj-$(CONFIG_BPFILTER) += bpfilter/ obj-$(CONFIG_PACKET) += packet/ obj-$(CONFIG_NET_KEY) += key/ obj-$(CONFIG_BRIDGE) += bridge/ +obj-$(CONFIG_NET_DEVLINK) += devlink/ obj-$(CONFIG_NET_DSA) += dsa/ obj-$(CONFIG_ATALK) += appletalk/ obj-$(CONFIG_X25) += x25/
net/core/Makefile +0 -1
@@ -33,7 +33,6 @@ obj-$(CONFIG_LWTUNNEL) += lwtunnel.o obj-$(CONFIG_LWTUNNEL_BPF) += lwt_bpf.o obj-$(CONFIG_DST_CACHE) += dst_cache.o obj-$(CONFIG_HWBM) += hwbm.o -obj-$(CONFIG_NET_DEVLINK) += devlink.o obj-$(CONFIG_GRO_CELLS) += gro_cells.o obj-$(CONFIG_FAILOVER) += failover.o obj-$(CONFIG_NET_SOCK_MSG) += skmsg.o
net/devlink/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y := basic.o
net/devlink/basic.c renamed from net/core/devlink.c +0 -0
Signature · 1 line
2.38.1
Jakub Kicinski
maintainerRFC 5/15 netlink: add macro for checking dump ctx size
In reply to Jakub KicinskiWe encourage casting struct netlink_callback::ctx to a local struct (in a comment above the field). Provide a convenience macro for checking if the local struct fits into the ctx.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- include/linux/netlink.h | 4 ++++ net/netfilter/nf_conntrack_netlink.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-)
include/linux/netlink.h +4 -0
@@ -263,6 +263,10 @@ struct netlink_callback { }; }; +#define NL_ASSET_DUMP_CTX_FITS (type_name) \ + BUILD_BUG_ON(sizeof(type_name) > \ + sizeof_field(struct netlink_callback, ctx)) +struct netlink_notify {struct net *net;u32 portid;
net/netfilter/nf_conntrack_netlink.c +1 -1
@@ -3866,7 +3866,7 @@ static int __init ctnetlink_init(void) {int ret; - BUILD_BUG_ON(sizeof(struct ctnetlink_list_dump_ctx) > sizeof_field(struct netlink_callback, ctx)); +NL_ASSET_DUMP_CTX_FITS (struct ctnetlink_list_dump_ctx ); ret =nfnetlink_subsys_register (&ctnl_subsys);if (ret <0 ) {
Signature · 1 line
2.38.1
Jakub Kicinski
maintainerRFC 2/15 devlink: split out core code
In reply to Jakub KicinskiMove core code into a separate file. It's spread around the main file which makes refactoring and figuring out how devlink works harder.
Move the xarray, all the most core devlink instance code out like locking, ref counting, alloc, register, etc. Leave port stuff in basic.c, if we want to move port code it'd probably be to its own file.
Rename devlink_netdevice_event() to make it clear that it only touches ports (that's the only change which isn't a pure code move).
--- net/devlink/Makefile | 2 +- net/devlink/basic.c | 444 +----------------------------------- net/devlink/core.c | 347 ++++++++++++++++++++++++++++ net/devlink/devl_internal.h | 117 ++++++++++ 4 files changed, 476 insertions(+), 434 deletions(-) create mode 100644 net/devlink/core.c create mode 100644 net/devlink/devl_internal.h
net/devlink/Makefile +1 -1
@@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 -obj-y := basic.o +obj-y := basic.o core.o
net/devlink/basic.c +11 -433
525 lines not on this page · raw message
net/devlink/core.c new file +347 -0
347 lines not on this page · raw message
net/devlink/devl_internal.h new file +117 -0
117 lines not on this page · raw message
Signature · 1 line
2.38.1
Jakub Kicinski
maintainerRFC 7/15 devlink: remove start variables from dumps
In reply to Jakub KicinskiThe start variables made the code clearer when we had to access cb->args[0] directly, as the name args doesn't explain much. Now that we use a structure to hold state this seems no longer needed.
--- net/devlink/basic.c | 55 ++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 36 deletions(-)
net/devlink/basic.c +19 -36
@@ -1225,7 +1225,6 @@ static int devlink_nl_cmd_rate_get_dumpit(struct sk_buff *msg,struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink_rate *devlink_rate;struct devlink *devlink; -int start = dump->idx;unsigned long index;int idx =0 ;int err =0 ;
@@ -1236,7 +1235,7 @@ static int devlink_nl_cmd_rate_get_dumpit(struct sk_buff *msg,enum devlink_command cmd =DEVLINK_CMD_RATE_NEW ;u32 id =NETLINK_CB (cb->skb).portid; -if (idx < start) { +if (idx < dump->idx) { idx++;continue ; }
@@ -1320,13 +1319,12 @@ static int devlink_nl_cmd_get_dumpit(struct sk_buff *msg, {struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink; -int start = dump->idx;unsigned long index;int idx =0 ;int err;devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { -if (idx < start) { +if (idx < dump->idx) { idx++;devlink_put (devlink);continue ;
@@ -1377,14 +1375,13 @@ static int devlink_nl_cmd_port_get_dumpit(struct sk_buff *msg,struct devlink *devlink;struct devlink_port *devlink_port;unsigned long index, port_index; -int start = dump->idx;int idx =0 ;int err;devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) {devl_lock (devlink);xa_for_each (&devlink->ports, port_index, devlink_port) { -if (idx < start) { +if (idx < dump->idx) { idx++;continue ; }
@@ -2156,7 +2153,6 @@ static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg,struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink_linecard *linecard;struct devlink *devlink; -int start = dump->idx;unsigned long index;int idx =0 ;int err;
@@ -2164,7 +2160,7 @@ static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg,devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) {mutex_lock (&devlink->linecards_lock);list_for_each_entry (linecard, &devlink->linecard_list, list) { -if (idx < start) { +if (idx < dump->idx) { idx++;continue ; }
@@ -2419,7 +2415,6 @@ static int devlink_nl_cmd_sb_get_dumpit(struct sk_buff *msg,struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink;struct devlink_sb *devlink_sb; -int start = dump->idx;unsigned long index;int idx =0 ;int err;
@@ -2427,7 +2422,7 @@ static int devlink_nl_cmd_sb_get_dumpit(struct sk_buff *msg,devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) {devl_lock (devlink);list_for_each_entry (devlink_sb, &devlink->sb_list, list) { -if (idx < start) { +if (idx < dump->idx) { idx++;continue ; }
@@ -2562,7 +2557,6 @@ static int devlink_nl_cmd_sb_pool_get_dumpit(struct sk_buff *msg,struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink;struct devlink_sb *devlink_sb; -int start = dump->idx;unsigned long index;int idx =0 ;int err =0 ;
@@ -2573,8 +2567,8 @@ static int devlink_nl_cmd_sb_pool_get_dumpit(struct sk_buff *msg,devl_lock (devlink);list_for_each_entry (devlink_sb, &devlink->sb_list, list) { - err =__sb_pool_get_dumpit (msg, start, &idx, devlink, - devlink_sb, + err =__sb_pool_get_dumpit (msg, dump->idx, &idx, + devlink, devlink_sb,NETLINK_CB (cb->skb).portid, cb->nlh->nlmsg_seq);if (err == -EOPNOTSUPP ) {
@@ -2778,7 +2772,6 @@ static int devlink_nl_cmd_sb_port_pool_get_dumpit(struct sk_buff *msg,struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink;struct devlink_sb *devlink_sb; -int start = dump->idx;unsigned long index;int idx =0 ;int err =0 ;
@@ -2789,7 +2782,7 @@ static int devlink_nl_cmd_sb_port_pool_get_dumpit(struct sk_buff *msg,devl_lock (devlink);list_for_each_entry (devlink_sb, &devlink->sb_list, list) { - err =__sb_port_pool_get_dumpit (msg, start, &idx, + err =__sb_port_pool_get_dumpit (msg, dump->idx, &idx, devlink, devlink_sb,NETLINK_CB (cb->skb).portid, cb->nlh->nlmsg_seq);
@@ -3022,7 +3015,6 @@ devlink_nl_cmd_sb_tc_pool_bind_get_dumpit(struct sk_buff *msg,struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink;struct devlink_sb *devlink_sb; -int start = dump->idx;unsigned long index;int idx =0 ;int err =0 ;
@@ -3033,9 +3025,8 @@ devlink_nl_cmd_sb_tc_pool_bind_get_dumpit(struct sk_buff *msg,devl_lock (devlink);list_for_each_entry (devlink_sb, &devlink->sb_list, list) { - err =__sb_tc_pool_bind_get_dumpit (msg, start, &idx, - devlink, - devlink_sb, + err =__sb_tc_pool_bind_get_dumpit (msg, dump->idx, &idx, + devlink, devlink_sb,NETLINK_CB (cb->skb).portid, cb->nlh->nlmsg_seq);if (err == -EOPNOTSUPP ) {
@@ -4881,13 +4872,12 @@ static int devlink_nl_cmd_selftests_get_dumpit(struct sk_buff *msg, {struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink; -int start = dump->idx;unsigned long index;int idx =0 ;int err =0 ;devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { -if (idx < start || !devlink->ops->selftest_check) +if (idx < dump->idx || !devlink->ops->selftest_check) goto inc;devl_lock (devlink);
@@ -5363,7 +5353,6 @@ static int devlink_nl_cmd_param_get_dumpit(struct sk_buff *msg,struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink_param_item *param_item;struct devlink *devlink; -int start = dump->idx;unsigned long index;int idx =0 ;int err =0 ;
@@ -5371,7 +5360,7 @@ static int devlink_nl_cmd_param_get_dumpit(struct sk_buff *msg,devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) {devl_lock (devlink);list_for_each_entry (param_item, &devlink->param_list, list) { -if (idx < start) { +if (idx < dump->idx) { idx++;continue ; }
@@ -6107,14 +6096,13 @@ static int devlink_nl_cmd_region_get_dumpit(struct sk_buff *msg, {struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink; -int start = dump->idx;unsigned long index;int idx =0 ;int err =0 ;devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { err =devlink_nl_cmd_region_get_devlink_dumpit (msg, cb, devlink, - &idx, start); + &idx, dump->idx);devlink_put (devlink);if (err) goto out;
@@ -6759,13 +6747,12 @@ static int devlink_nl_cmd_info_get_dumpit(struct sk_buff *msg, {struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink; -int start = dump->idx;unsigned long index;int idx =0 ;int err =0 ;devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { -if (idx < start) +if (idx < dump->idx) goto inc;devl_lock (devlink);
@@ -7930,7 +7917,6 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,unsigned long index, port_index;struct devlink_port *port;struct devlink *devlink; -int start = dump->idx;int idx =0 ;int err;
@@ -7938,7 +7924,7 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,mutex_lock (&devlink->reporters_lock);list_for_each_entry (reporter, &devlink->reporter_list, list) { -if (idx < start) { +if (idx < dump->idx) { idx++;continue ; }
@@ -7962,7 +7948,7 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,xa_for_each (&devlink->ports, port_index, port) {mutex_lock (&port->reporters_lock);list_for_each_entry (reporter, &port->reporter_list, list) { -if (idx < start) { +if (idx < dump->idx) { idx++;continue ; }
@@ -8513,7 +8499,6 @@ static int devlink_nl_cmd_trap_get_dumpit(struct sk_buff *msg,struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink_trap_item *trap_item;struct devlink *devlink; -int start = dump->idx;unsigned long index;int idx =0 ;int err;
@@ -8521,7 +8506,7 @@ static int devlink_nl_cmd_trap_get_dumpit(struct sk_buff *msg,devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) {devl_lock (devlink);list_for_each_entry (trap_item, &devlink->trap_list, list) { -if (idx < start) { +if (idx < dump->idx) { idx++;continue ; }
@@ -8731,7 +8716,6 @@ static int devlink_nl_cmd_trap_group_get_dumpit(struct sk_buff *msg,struct devlink_trap_group_item *group_item;u32 portid =NETLINK_CB (cb->skb).portid;struct devlink *devlink; -int start = dump->idx;unsigned long index;int idx =0 ;int err;
@@ -8740,7 +8724,7 @@ static int devlink_nl_cmd_trap_group_get_dumpit(struct sk_buff *msg,devl_lock (devlink);list_for_each_entry (group_item, &devlink->trap_group_list, list) { -if (idx < start) { +if (idx < dump->idx) { idx++;continue ; }
@@ -9036,7 +9020,6 @@ static int devlink_nl_cmd_trap_policer_get_dumpit(struct sk_buff *msg,struct devlink_trap_policer_item *policer_item;u32 portid =NETLINK_CB (cb->skb).portid;struct devlink *devlink; -int start = dump->idx;unsigned long index;int idx =0 ;int err;
@@ -9045,7 +9028,7 @@ static int devlink_nl_cmd_trap_policer_get_dumpit(struct sk_buff *msg,devl_lock (devlink);list_for_each_entry (policer_item, &devlink->trap_policer_list, list) { -if (idx < start) { +if (idx < dump->idx) { idx++;continue ; }
Signature · 1 line
2.38.1
Jakub Kicinski
maintainerRFC 4/15 devlink: protect devlink dump by the instance lock
In reply to Jakub KicinskiTake the instance lock around devlink_nl_fill() when the dumping. We are only dumping basic info so in the worst case we were only risking data races until now.
--- net/devlink/basic.c | 3 +++ 1 file changed, 3 insertions(+)
net/devlink/basic.c +3 -0
@@ -1330,10 +1330,13 @@ static int devlink_nl_cmd_get_dumpit(struct sk_buff *msg,continue ; } +devl_lock (devlink); err =devlink_nl_fill (msg, devlink,DEVLINK_CMD_NEW ,NETLINK_CB (cb->skb).portid, cb->nlh->nlmsg_seq,NLM_F_MULTI ); +devl_unlock (devlink);devlink_put (devlink); +if (err) goto out; idx++;
Signature · 1 line
2.38.1
Jakub Kicinski
maintainerRFC 6/15 devlink: use an explicit structure for dump context
In reply to Jakub KicinskiCreate a dump context structure instead of using cb->args as an unsigned long array. This is a pure conversion which is intended to be as much of a noop as possible. Subsequent changes will use this to simplify the code.
The two non-trivial parts are:
- devlink_nl_cmd_health_reporter_dump_get_dumpit() checks args[0] to see if devlink_fmsg_dumpit() has already been called (whether this is the first msg), but doesn't use the exact value, so we can drop the local variable there already
- devlink_nl_cmd_region_read_dumpit() uses args[0] for address but we'll use args[1] now, shouldn't matter
--- net/devlink/basic.c | 98 ++++++++++++++++++++++--------------- net/devlink/devl_internal.h | 23 +++++++++ 2 files changed, 81 insertions(+), 40 deletions(-)
net/devlink/basic.c +58 -40
@@ -1222,9 +1222,10 @@ static void devlink_rate_notify(struct devlink_rate *devlink_rate,static int devlink_nl_cmd_rate_get_dumpit (struct sk_buff *msg,struct netlink_callback *cb) { +struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink_rate *devlink_rate;struct devlink *devlink; -int start = cb->args[0 ]; +int start = dump->idx;unsigned long index;int idx =0 ;int err =0 ;
@@ -1256,7 +1257,7 @@ static int devlink_nl_cmd_rate_get_dumpit(struct sk_buff *msg,if (err != -EMSGSIZE )return err; - cb->args[0 ] = idx; + dump->idx = idx;return msg->len; }
@@ -1317,8 +1318,9 @@ static int devlink_nl_cmd_get_doit(struct sk_buff *skb, struct genl_info *info)static int devlink_nl_cmd_get_dumpit (struct sk_buff *msg,struct netlink_callback *cb) { +struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink; -int start = cb->args[0 ]; +int start = dump->idx;unsigned long index;int idx =0 ;int err;
@@ -1342,7 +1344,7 @@ static int devlink_nl_cmd_get_dumpit(struct sk_buff *msg, idx++; } out: - cb->args[0 ] = idx; + dump->idx = idx;return msg->len; }
@@ -1371,10 +1373,11 @@ static int devlink_nl_cmd_port_get_doit(struct sk_buff *skb,static int devlink_nl_cmd_port_get_dumpit (struct sk_buff *msg,struct netlink_callback *cb) { +struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink;struct devlink_port *devlink_port;unsigned long index, port_index; -int start = cb->args[0 ]; +int start = dump->idx;int idx =0 ;int err;
@@ -1401,7 +1404,7 @@ static int devlink_nl_cmd_port_get_dumpit(struct sk_buff *msg,devlink_put (devlink); } out: - cb->args[0 ] = idx; + dump->idx = idx;return msg->len; }
@@ -2150,9 +2153,10 @@ static int devlink_nl_cmd_linecard_get_doit(struct sk_buff *skb,static int devlink_nl_cmd_linecard_get_dumpit (struct sk_buff *msg,struct netlink_callback *cb) { +struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink_linecard *linecard;struct devlink *devlink; -int start = cb->args[0 ]; +int start = dump->idx;unsigned long index;int idx =0 ;int err;
@@ -2183,7 +2187,7 @@ static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg,devlink_put (devlink); } out: - cb->args[0 ] = idx; + dump->idx = idx;return msg->len; }
@@ -2412,9 +2416,10 @@ static int devlink_nl_cmd_sb_get_doit(struct sk_buff *skb,static int devlink_nl_cmd_sb_get_dumpit (struct sk_buff *msg,struct netlink_callback *cb) { +struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink;struct devlink_sb *devlink_sb; -int start = cb->args[0 ]; +int start = dump->idx;unsigned long index;int idx =0 ;int err;
@@ -2442,7 +2447,7 @@ static int devlink_nl_cmd_sb_get_dumpit(struct sk_buff *msg,devlink_put (devlink); } out: - cb->args[0 ] = idx; + dump->idx = idx;return msg->len; }
@@ -2554,9 +2559,10 @@ static int __sb_pool_get_dumpit(struct sk_buff *msg, int start, int *p_idx,static int devlink_nl_cmd_sb_pool_get_dumpit (struct sk_buff *msg,struct netlink_callback *cb) { +struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink;struct devlink_sb *devlink_sb; -int start = cb->args[0 ]; +int start = dump->idx;unsigned long index;int idx =0 ;int err =0 ;
@@ -2587,7 +2593,7 @@ static int devlink_nl_cmd_sb_pool_get_dumpit(struct sk_buff *msg,if (err != -EMSGSIZE )return err; - cb->args[0 ] = idx; + dump->idx = idx;return msg->len; }
@@ -2769,9 +2775,10 @@ static int __sb_port_pool_get_dumpit(struct sk_buff *msg, int start, int *p_idx,static int devlink_nl_cmd_sb_port_pool_get_dumpit (struct sk_buff *msg,struct netlink_callback *cb) { +struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink;struct devlink_sb *devlink_sb; -int start = cb->args[0 ]; +int start = dump->idx;unsigned long index;int idx =0 ;int err =0 ;
@@ -2802,7 +2809,7 @@ static int devlink_nl_cmd_sb_port_pool_get_dumpit(struct sk_buff *msg,if (err != -EMSGSIZE )return err; - cb->args[0 ] = idx; + dump->idx = idx;return msg->len; }
@@ -3012,9 +3019,10 @@ static int devlink_nl_cmd_sb_tc_pool_bind_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb) { + struct devlink_nl_dump_state *dump = devl_dump_state(cb);struct devlink *devlink;struct devlink_sb *devlink_sb; -int start = cb->args[0 ]; +int start = dump->idx;unsigned long index;int idx =0 ;int err =0 ;
@@ -3046,7 +3054,7 @@ devlink_nl_cmd_sb_tc_pool_bind_get_dumpit(struct sk_buff *msg,if (err != -EMSGSIZE )return err; - cb->args[0 ] = idx; + dump->idx = idx;return msg->len; }
@@ -4871,8 +4879,9 @@ static int devlink_nl_cmd_selftests_get_doit(struct sk_buff *skb,static int devlink_nl_cmd_selftests_get_dumpit (struct sk_buff *msg,struct netlink_callback *cb) { +struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink; -int start = cb->args[0 ]; +int start = dump->idx;unsigned long index;int idx =0 ;int err =0 ;
@@ -4899,7 +4908,7 @@ static int devlink_nl_cmd_selftests_get_dumpit(struct sk_buff *msg,if (err != -EMSGSIZE )return err; - cb->args[0 ] = idx; + dump->idx = idx;return msg->len; }
@@ -5351,9 +5360,10 @@ static void devlink_param_notify(struct devlink *devlink,static int devlink_nl_cmd_param_get_dumpit (struct sk_buff *msg,struct netlink_callback *cb) { +struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink_param_item *param_item;struct devlink *devlink; -int start = cb->args[0 ]; +int start = dump->idx;unsigned long index;int idx =0 ;int err =0 ;
@@ -5386,7 +5396,7 @@ static int devlink_nl_cmd_param_get_dumpit(struct sk_buff *msg,if (err != -EMSGSIZE )return err; - cb->args[0 ] = idx; + dump->idx = idx;return msg->len; }
@@ -6095,8 +6105,9 @@ static int devlink_nl_cmd_region_get_devlink_dumpit(struct sk_buff *msg,static int devlink_nl_cmd_region_get_dumpit (struct sk_buff *msg,struct netlink_callback *cb) { +struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink; -int start = cb->args[0 ]; +int start = dump->idx;unsigned long index;int idx =0 ;int err =0 ;
@@ -6109,7 +6120,7 @@ static int devlink_nl_cmd_region_get_dumpit(struct sk_buff *msg, goto out; } out: - cb->args[0 ] = idx; + dump->idx = idx;return msg->len; }
@@ -6394,6 +6405,7 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb, struct netlink_callback *cb) {const struct genl_dumpit_info *info =genl_dumpit_info (cb); +struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct nlattr *chunks_attr, *region_attr, *snapshot_attr;u64 ret_offset, start_offset, end_offset =U64_MAX ;struct nlattr **attrs = info->attrs;
@@ -6407,7 +6419,7 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,void *hdr;int err; - start_offset = *((u64 *)&cb->args[0 ]); + start_offset = dump->start_offset; devlink =devlink_get_from_attrs (sock_net (cb->skb->sk), attrs);if (IS_ERR (devlink))
@@ -6546,7 +6558,7 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb, goto nla_put_failure; } - *((u64 *)&cb->args[0 ]) = ret_offset; + dump->start_offset = ret_offset;nla_nest_end (skb, chunks_attr);genlmsg_end (skb, hdr);
@@ -6745,8 +6757,9 @@ static int devlink_nl_cmd_info_get_doit(struct sk_buff *skb,static int devlink_nl_cmd_info_get_dumpit (struct sk_buff *msg,struct netlink_callback *cb) { +struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink; -int start = cb->args[0 ]; +int start = dump->idx;unsigned long index;int idx =0 ;int err =0 ;
@@ -6775,7 +6788,7 @@ static int devlink_nl_cmd_info_get_dumpit(struct sk_buff *msg,if (err != -EMSGSIZE )return err; - cb->args[0 ] = idx; + dump->idx = idx;return msg->len; }
@@ -7344,7 +7357,8 @@ static int devlink_fmsg_dumpit(struct devlink_fmsg *fmsg, struct sk_buff *skb, struct netlink_callback *cb, enum devlink_command cmd) { - int index = cb->args[0]; +struct devlink_nl_dump_state *dump =devl_dump_state (cb); +int index = dump->idx;int tmp_index = index;void *hdr;int err;
@@ -7360,7 +7374,7 @@ static int devlink_fmsg_dumpit(struct devlink_fmsg *fmsg, struct sk_buff *skb,if ((err && err != -EMSGSIZE ) || tmp_index == index) goto nla_put_failure; - cb->args[0 ] = index; + dump->idx = index;genlmsg_end (skb, hdr);return skb->len;
@@ -7911,11 +7925,12 @@ static int devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb) { + struct devlink_nl_dump_state *dump = devl_dump_state(cb);struct devlink_health_reporter *reporter;unsigned long index, port_index;struct devlink_port *port;struct devlink *devlink; -int start = cb->args[0 ]; +int start = dump->idx;int idx =0 ;int err;
@@ -7970,7 +7985,7 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,devlink_put (devlink); } out: - cb->args[0 ] = idx; + dump->idx = idx;return msg->len; }
@@ -8082,8 +8097,8 @@ static int devlink_nl_cmd_health_reporter_dump_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) { + struct devlink_nl_dump_state *dump = devl_dump_state(cb);struct devlink_health_reporter *reporter; -u64 start = cb->args[0 ];int err; reporter =devlink_health_reporter_get_from_cb (cb);
@@ -8095,13 +8110,13 @@ devlink_nl_cmd_health_reporter_dump_get_dumpit(struct sk_buff *skb, goto out; }mutex_lock (&reporter->dump_lock); -if (!start) { +if (!dump->idx) { err =devlink_health_do_dump (reporter,NULL , cb->extack);if (err) goto unlock; - cb->args[1 ] = reporter->dump_ts; + dump->dump_ts = reporter->dump_ts; } -if (!reporter->dump_fmsg || cb->args[1 ] != reporter->dump_ts) { +if (!reporter->dump_fmsg || dump->dump_ts != reporter->dump_ts) {NL_SET_ERR_MSG_MOD (cb->extack,"Dump trampled, please retry" ); err = -EAGAIN ; goto unlock;
@@ -8495,9 +8510,10 @@ static int devlink_nl_cmd_trap_get_doit(struct sk_buff *skb,static int devlink_nl_cmd_trap_get_dumpit (struct sk_buff *msg,struct netlink_callback *cb) { +struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink_trap_item *trap_item;struct devlink *devlink; -int start = cb->args[0 ]; +int start = dump->idx;unsigned long index;int idx =0 ;int err;
@@ -8525,7 +8541,7 @@ static int devlink_nl_cmd_trap_get_dumpit(struct sk_buff *msg,devlink_put (devlink); } out: - cb->args[0 ] = idx; + dump->idx = idx;return msg->len; }
@@ -8710,11 +8726,12 @@ static int devlink_nl_cmd_trap_group_get_doit(struct sk_buff *skb,static int devlink_nl_cmd_trap_group_get_dumpit (struct sk_buff *msg,struct netlink_callback *cb) { +struct devlink_nl_dump_state *dump =devl_dump_state (cb);enum devlink_command cmd =DEVLINK_CMD_TRAP_GROUP_NEW ;struct devlink_trap_group_item *group_item;u32 portid =NETLINK_CB (cb->skb).portid;struct devlink *devlink; -int start = cb->args[0 ]; +int start = dump->idx;unsigned long index;int idx =0 ;int err;
@@ -8743,7 +8760,7 @@ static int devlink_nl_cmd_trap_group_get_dumpit(struct sk_buff *msg,devlink_put (devlink); } out: - cb->args[0 ] = idx; + dump->idx = idx;return msg->len; }
@@ -9014,11 +9031,12 @@ static int devlink_nl_cmd_trap_policer_get_doit(struct sk_buff *skb,static int devlink_nl_cmd_trap_policer_get_dumpit (struct sk_buff *msg,struct netlink_callback *cb) { +struct devlink_nl_dump_state *dump =devl_dump_state (cb);enum devlink_command cmd =DEVLINK_CMD_TRAP_POLICER_NEW ;struct devlink_trap_policer_item *policer_item;u32 portid =NETLINK_CB (cb->skb).portid;struct devlink *devlink; -int start = cb->args[0 ]; +int start = dump->idx;unsigned long index;int idx =0 ;int err;
@@ -9047,7 +9065,7 @@ static int devlink_nl_cmd_trap_policer_get_dumpit(struct sk_buff *msg,devlink_put (devlink); } out: - cb->args[0 ] = idx; + dump->idx = idx;return msg->len; }
net/devlink/devl_internal.h +23 -0
@@ -107,6 +107,21 @@ enum devlink_multicast_groups { DEVLINK_MCGRP_CONFIG, }; +/* state held across netlink dumps */ +struct devlink_nl_dump_state { +int idx; +union { +/* DEVLINK_CMD_REGION_READ */ +struct { +u64 start_offset; + }; +/* DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET */ +struct { +u64 dump_ts; + }; + }; +}; +extern const struct genl_small_ops devlink_nl_ops[56 ];struct devlink *devlink_get_from_attrs (struct net *net,struct nlattr **attrs);
@@ -114,6 +129,14 @@ struct devlink *devlink_get_from_attrs(struct net *net, struct nlattr **attrs);void devlink_notify_unregister (struct devlink *devlink);void devlink_notify_register (struct devlink *devlink); +static inline struct devlink_nl_dump_state * +devl_dump_state (struct netlink_callback *cb) +{ +NL_ASSET_DUMP_CTX_FITS (struct devlink_nl_dump_state ); + +return (struct devlink_nl_dump_state *)cb->ctx; +} +/* Ports */ int devlink_port_netdevice_event (struct notifier_block *nb,unsigned long event,void *ptr);
Signature · 1 line
2.38.1
Jakub Kicinski
maintainerRFC 3/15 devlink: split out netlink code
In reply to Jakub KicinskiMove out the netlink glue into a separate file.
Leave the ops in the old file because we'd have to export a ton of functions. Going forward we should switch to split ops which will let us to put the new ops in the netlink.c file.
Pure code move, no functional changes.
--- net/devlink/Makefile | 2 +- net/devlink/basic.c | 212 ++---------------------------------- net/devlink/devl_internal.h | 31 ++++++ net/devlink/netlink.c | 195 +++++++++++++++++++++++++++++++++ 4 files changed, 235 insertions(+), 205 deletions(-) create mode 100644 net/devlink/netlink.c
net/devlink/Makefile +1 -1
@@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 -obj-y := basic.o core.o +obj-y := basic.o core.o netlink.o
net/devlink/basic.c +8 -204
264 lines not on this page · raw message
net/devlink/devl_internal.h +31 -0
@@ -97,6 +97,20 @@ devlinks_xa_find_get_next(struct net *net, unsigned long *indexp, xa_mark_t filter);/* Netlink */ +#define DEVLINK_NL_FLAG_NEED_PORT BIT(0) +#define DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT BIT(1) +#define DEVLINK_NL_FLAG_NEED_RATE BIT(2) +#define DEVLINK_NL_FLAG_NEED_RATE_NODE BIT(3) +#define DEVLINK_NL_FLAG_NEED_LINECARD BIT(4) + +enum devlink_multicast_groups { +DEVLINK_MCGRP_CONFIG , +}; + +extern const struct genl_small_ops devlink_nl_ops[56 ]; + +struct devlink *devlink_get_from_attrs (struct net *net,struct nlattr **attrs); +void devlink_notify_unregister (struct devlink *devlink);void devlink_notify_register (struct devlink *devlink);
@@ -104,6 +118,9 @@ void devlink_notify_register(struct devlink *devlink);int devlink_port_netdevice_event (struct notifier_block *nb,unsigned long event,void *ptr); +struct devlink_port * +devlink_port_get_from_info (struct devlink *devlink,struct genl_info *info); +/* Reload */ bool devlink_reload_actions_valid (const struct devlink_ops *ops); int devlink_reload(struct devlink *devlink, struct net *dest_net,
@@ -115,3 +132,17 @@ static inline bool devlink_reload_supported(const struct devlink_ops *ops) {return ops->reload_down && ops->reload_up; } + +/* Line cards */ +struct devlink_linecard ; + +struct devlink_linecard * +devlink_linecard_get_from_info (struct devlink *devlink,struct genl_info *info); +void devlink_linecard_put (struct devlink_linecard *linecard); + +/* Rates */ +struct devlink_rate * +devlink_rate_get_from_info (struct devlink *devlink,struct genl_info *info); +struct devlink_rate * +devlink_rate_node_get_from_info (struct devlink *devlink, +struct genl_info *info);
net/devlink/netlink.c new file +195 -0
195 lines not on this page · raw message
Signature · 1 line
2.38.1
Jakub Kicinski
maintainerRFC 8/15 devlink: drop the filter argument from devlinks_xa_find_get
In reply to Jakub KicinskiLooks like devlinks_xa_find_get() was intended to get the mark from the @filter argument. It doesn't actually use @filter, passing DEVLINK_REGISTERED to xa_find_fn() directly. Walking marks other than registered is unlikely so drop @filter argument completely.
--- net/devlink/core.c | 12 +++++------- net/devlink/devl_internal.h | 15 +++++---------- 2 files changed, 10 insertions(+), 17 deletions(-)
net/devlink/core.c +5 -7
@@ -92,7 +92,7 @@ void devlink_put(struct devlink *devlink) }static struct devlink * -devlinks_xa_find_get (struct net *net,unsigned long *indexp,xa_mark_t filter, +devlinks_xa_find_get (struct net *net,unsigned long *indexp,void * (*xa_find_fn)(struct xarray *,unsigned long *,unsigned long ,xa_mark_t )) {
@@ -125,17 +125,15 @@ devlinks_xa_find_get(struct net *net, unsigned long *indexp, xa_mark_t filter, }struct devlink * -devlinks_xa_find_get_first (struct net *net,unsigned long *indexp, -xa_mark_t filter) +devlinks_xa_find_get_first (struct net *net,unsigned long *indexp) { -return devlinks_xa_find_get (net, indexp, filter, xa_find); +return devlinks_xa_find_get (net, indexp, xa_find); }struct devlink * -devlinks_xa_find_get_next (struct net *net,unsigned long *indexp, -xa_mark_t filter) +devlinks_xa_find_get_next (struct net *net,unsigned long *indexp) { -return devlinks_xa_find_get (net, indexp, filter, xa_find_after); +return devlinks_xa_find_get (net, indexp, xa_find_after); }/**
net/devlink/devl_internal.h +5 -10
@@ -81,20 +81,15 @@ extern struct genl_family devlink_nl_family;* devlink_put() needs to be called for each iterated devlink pointer * in loop body in order to release the reference. */ -#define devlinks_xa_for_each_get (net, index, devlink, filter) \ - for (index = 0, \ - devlink = devlinks_xa_find_get_first(net, &index, filter); \ - devlink; devlink = devlinks_xa_find_get_next(net, &index, filter)) -#define devlinks_xa_for_each_registered_get (net, index, devlink) \ - devlinks_xa_for_each_get(net, index, devlink, DEVLINK_REGISTERED) + for (index = 0, \ + devlink = devlinks_xa_find_get_first(net, &index); \ + devlink; devlink = devlinks_xa_find_get_next(net, &index))struct devlink * -devlinks_xa_find_get_first (struct net *net,unsigned long *indexp, -xa_mark_t filter); +devlinks_xa_find_get_first (struct net *net,unsigned long *indexp);struct devlink * -devlinks_xa_find_get_next (struct net *net,unsigned long *indexp, -xa_mark_t filter); +devlinks_xa_find_get_next (struct net *net,unsigned long *indexp);/* Netlink */ #define DEVLINK_NL_FLAG_NEED_PORT BIT(0)
Signature · 1 line
2.38.1
Jakub Kicinski
maintainerRFC 9/15 devlink: health: combine loops in dump
In reply to Jakub KicinskiWalk devlink instances only once. Dump the instance reporters and port reporters before moving to the next instance. User space should not depend on ordering of messages.
This will make improving stability of the walk easier.
--- net/devlink/basic.c | 3 --- 1 file changed, 3 deletions(-)
net/devlink/basic.c +0 -3
@@ -7940,10 +7940,7 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, idx++; }mutex_unlock (&devlink->reporters_lock); -devlink_put (devlink); - } -devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) {devl_lock (devlink);xa_for_each (&devlink->ports, port_index, port) {mutex_lock (&port->reporters_lock);
Signature · 1 line
2.38.1
Jakub Kicinski
maintainerRFC 10/15 devlink: restart dump based on devlink instance ids (simple)
In reply to Jakub Kicinskixarray gives each devlink instance an id and allows us to restart walk based on that id quite neatly. This is nice both from the perspective of code brevity and from the stability of the dump (devlink instances disappearing from before the resumption point will not cause inconsistent dumps).
This patch takes care of simple cases where dump->idx counts devlink instances only.
--- net/devlink/basic.c | 36 ++++++++---------------------------- net/devlink/core.c | 2 +- net/devlink/devl_internal.h | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 29 deletions(-)
net/devlink/basic.c +8 -28
@@ -1319,17 +1319,9 @@ static int devlink_nl_cmd_get_dumpit(struct sk_buff *msg, {struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink; -unsigned long index; -int idx =0 ;int err; -devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { -if (idx < dump->idx) { - idx++; -devlink_put (devlink); -continue ; - } - +devlink_dump_for_each_instance_get (msg, dump, devlink) {devl_lock (devlink); err = devlink_nl_fill(msg, devlink, DEVLINK_CMD_NEW, NETLINK_CB(cb->skb).portid,
@@ -1339,10 +1331,8 @@ static int devlink_nl_cmd_get_dumpit(struct sk_buff *msg,if (err) goto out; - idx++; } out: - dump->idx = idx;return msg->len; }
@@ -4872,13 +4862,13 @@ static int devlink_nl_cmd_selftests_get_dumpit(struct sk_buff *msg, {struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink; -unsigned long index; -int idx =0 ;int err =0 ; -devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { -if (idx < dump->idx || !devlink->ops->selftest_check) - goto inc; +devlink_dump_for_each_instance_get (msg, dump, devlink) { +if (!devlink->ops->selftest_check) { +devlink_put (devlink); +continue ; + }devl_lock (devlink); err = devlink_nl_selftests_fill(msg, devlink,
@@ -4890,15 +4880,13 @@ static int devlink_nl_cmd_selftests_get_dumpit(struct sk_buff *msg,devlink_put (devlink);break ; } -inc: - idx++; +devlink_put (devlink); }if (err != -EMSGSIZE )return err; - dump->idx = idx;return msg->len; }
@@ -6747,14 +6735,9 @@ static int devlink_nl_cmd_info_get_dumpit(struct sk_buff *msg, {struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink; -unsigned long index; -int idx =0 ;int err =0 ; -devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { -if (idx < dump->idx) - goto inc; - +devlink_dump_for_each_instance_get (msg, dump, devlink) {devl_lock (devlink); err = devlink_nl_info_fill(msg, devlink, DEVLINK_CMD_INFO_GET, NETLINK_CB(cb->skb).portid,
@@ -6767,15 +6750,12 @@ static int devlink_nl_cmd_info_get_dumpit(struct sk_buff *msg,devlink_put (devlink);break ; } -inc: - idx++;devlink_put (devlink); }if (err != -EMSGSIZE )return err; - dump->idx = idx;return msg->len; }
net/devlink/core.c +1 -1
@@ -91,7 +91,7 @@ void devlink_put(struct devlink *devlink)call_rcu (&devlink->rcu, __devlink_put_rcu); } -static struct devlink * +struct devlink *devlinks_xa_find_get (struct net *net,unsigned long *indexp,void * (*xa_find_fn)(struct xarray *,unsigned long *,unsigned long ,xa_mark_t ))
net/devlink/devl_internal.h +14 -0
@@ -87,6 +87,10 @@ extern struct genl_family devlink_nl_family; devlink; devlink = devlinks_xa_find_get_next(net, &index))struct devlink * +devlinks_xa_find_get (struct net *net,unsigned long *indexp, +void * (*xa_find_fn)(struct xarray *,unsigned long *, +unsigned long ,xa_mark_t )); +struct devlink *devlinks_xa_find_get_first (struct net *net,unsigned long *indexp);struct devlink *devlinks_xa_find_get_next (struct net *net,unsigned long *indexp);
@@ -104,6 +108,7 @@ enum devlink_multicast_groups {/* state held across netlink dumps */ struct devlink_nl_dump_state { +unsigned long instance;int idx;union {/* DEVLINK_CMD_REGION_READ */
@@ -117,6 +122,15 @@ struct devlink_nl_dump_state { }; }; +/* Iterate over devlink pointers which were possible to get reference to. +* devlink_put() needs to be called for each iterated devlink pointer +* in loop body in order to release the reference. +*/ +#define devlink_dump_for_each_instance_get (msg, dump, devlink) \ + for (; (devlink = devlinks_xa_find_get(sock_net(msg->sk), \ + &dump->instance, xa_find)); \ + dump->instance++) +extern const struct genl_small_ops devlink_nl_ops[56 ];struct devlink *devlink_get_from_attrs (struct net *net,struct nlattr **attrs);
Signature · 1 line
2.38.1
Jakub Kicinski
maintainerRFC 13/15 devlink: uniformly take the devlink instance lock in the dump loop
In reply to Jakub KicinskiMove the lock taking out of devlink_nl_cmd_region_get_devlink_dumpit(). This way all dumps will take the instance lock in the main iteration loop directly, making refactoring and reading the code easier.
--- net/devlink/basic.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
net/devlink/basic.c +6 -7
@@ -6050,9 +6050,8 @@ static int devlink_nl_cmd_region_get_devlink_dumpit(struct sk_buff *msg,struct devlink_region *region;struct devlink_port *port;unsigned long port_index; -int err =0 ; +int err; -devl_lock (devlink);list_for_each_entry (region, &devlink->region_list, list) {if (*idx < start) { (*idx)++;
@@ -6064,7 +6063,7 @@ static int devlink_nl_cmd_region_get_devlink_dumpit(struct sk_buff *msg, cb->nlh->nlmsg_seq, NLM_F_MULTI, region);if (err) - goto out; +return err; (*idx)++; }
@@ -6072,12 +6071,10 @@ static int devlink_nl_cmd_region_get_devlink_dumpit(struct sk_buff *msg, err =devlink_nl_cmd_region_get_port_dumpit (msg, cb, port, idx, start);if (err) - goto out; +return err; } -out: -devl_unlock (devlink); -return err; +return 0 ; } static int devlink_nl_cmd_region_get_dumpit(struct sk_buff *msg,
@@ -6090,8 +6087,10 @@ static int devlink_nl_cmd_region_get_dumpit(struct sk_buff *msg,devlink_dump_for_each_instance_get (msg, dump, devlink) {int idx =0 ; +devl_lock (devlink); err =devlink_nl_cmd_region_get_devlink_dumpit (msg, cb, devlink, &idx, dump->idx); +devl_unlock (devlink);devlink_put (devlink);if (err) { dump->idx = idx;
Signature · 1 line
2.38.1
Jakub Kicinski
maintainerRFC 12/15 devlink: restart dump based on devlink instance ids (function)
In reply to Jakub KicinskiUse xarray id for cases of sub-objects which are iterated in a function.
--- net/devlink/basic.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-)
net/devlink/basic.c +21 -20
@@ -2547,12 +2547,12 @@ static int devlink_nl_cmd_sb_pool_get_dumpit(struct sk_buff *msg, {struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink; -struct devlink_sb *devlink_sb; -unsigned long index; -int idx =0 ;int err =0 ; -devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { +devlink_dump_for_each_instance_get (msg, dump, devlink) { +struct devlink_sb *devlink_sb; +int idx =0 ; +if (!devlink->ops->sb_pool_get) goto retry;
@@ -2567,6 +2567,7 @@ static int devlink_nl_cmd_sb_pool_get_dumpit(struct sk_buff *msg, }else if (err) {devl_unlock (devlink);devlink_put (devlink); + dump->idx = idx; goto out; } }
@@ -2578,7 +2579,6 @@ static int devlink_nl_cmd_sb_pool_get_dumpit(struct sk_buff *msg,if (err != -EMSGSIZE )return err; - dump->idx = idx;return msg->len; }
@@ -2762,12 +2762,12 @@ static int devlink_nl_cmd_sb_port_pool_get_dumpit(struct sk_buff *msg, {struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink; -struct devlink_sb *devlink_sb; -unsigned long index; -int idx =0 ;int err =0 ; -devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { +devlink_dump_for_each_instance_get (msg, dump, devlink) { +struct devlink_sb *devlink_sb; +int idx =0 ; +if (!devlink->ops->sb_port_pool_get) goto retry;
@@ -2782,6 +2782,7 @@ static int devlink_nl_cmd_sb_port_pool_get_dumpit(struct sk_buff *msg, }else if (err) {devl_unlock (devlink);devlink_put (devlink); + dump->idx = idx; goto out; } }
@@ -2793,7 +2794,6 @@ static int devlink_nl_cmd_sb_port_pool_get_dumpit(struct sk_buff *msg,if (err != -EMSGSIZE )return err; - dump->idx = idx;return msg->len; }
@@ -3005,12 +3005,12 @@ devlink_nl_cmd_sb_tc_pool_bind_get_dumpit(struct sk_buff *msg, {struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink; -struct devlink_sb *devlink_sb; -unsigned long index; -int idx =0 ;int err =0 ; -devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { +devlink_dump_for_each_instance_get (msg, dump, devlink) { +struct devlink_sb *devlink_sb; +int idx =0 ; +if (!devlink->ops->sb_tc_pool_bind_get) goto retry;
@@ -3025,6 +3025,7 @@ devlink_nl_cmd_sb_tc_pool_bind_get_dumpit(struct sk_buff *msg, }else if (err) {devl_unlock (devlink);devlink_put (devlink); + dump->idx = idx; goto out; } }
@@ -3036,7 +3037,6 @@ devlink_nl_cmd_sb_tc_pool_bind_get_dumpit(struct sk_buff *msg,if (err != -EMSGSIZE )return err; - dump->idx = idx;return msg->len; }
@@ -6085,19 +6085,20 @@ static int devlink_nl_cmd_region_get_dumpit(struct sk_buff *msg, {struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink; -unsigned long index; -int idx =0 ;int err =0 ; -devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { +devlink_dump_for_each_instance_get (msg, dump, devlink) { +int idx =0 ; + err =devlink_nl_cmd_region_get_devlink_dumpit (msg, cb, devlink, &idx, dump->idx);devlink_put (devlink); -if (err) +if (err) { + dump->idx = idx; goto out; + } } out: - dump->idx = idx;return msg->len; }
Signature · 1 line
2.38.1
Jakub Kicinski
maintainerRFC 14/15 devlink: add by-instance dump infra
In reply to Jakub KicinskiMost dumpit implementations walk the devlink instances. This requires careful lock taking and reference dropping. Factor the loop out and provide just a callback to handle a single instance dump.
Convert one user as an example, other users converted in the next change.
Slightly inspired by ethtool netlink code.
--- net/devlink/basic.c | 55 ++++++++++++++++--------------------- net/devlink/devl_internal.h | 10 +++++++ net/devlink/netlink.c | 33 ++++++++++++++++++++++ 3 files changed, 67 insertions(+), 31 deletions(-)
net/devlink/basic.c +24 -31
@@ -1219,47 +1219,40 @@ static void devlink_rate_notify(struct devlink_rate *devlink_rate, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL); } -static int devlink_nl_cmd_rate_get_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) +static int +devlink_nl_cmd_rate_get_dumpinst (struct sk_buff *msg,struct devlink *devlink, +struct netlink_callback *cb) {struct devlink_nl_dump_state *dump =devl_dump_state (cb); -struct devlink *devlink; +struct devlink_rate *devlink_rate; +int idx =0 ;int err =0 ; -devlink_dump_for_each_instance_get (msg, dump, devlink) { -struct devlink_rate *devlink_rate; -int idx =0 ; - -devl_lock (devlink); -list_for_each_entry (devlink_rate, &devlink->rate_list, list) { -enum devlink_command cmd =DEVLINK_CMD_RATE_NEW ; -u32 id =NETLINK_CB (cb->skb).portid; +list_for_each_entry (devlink_rate, &devlink->rate_list, list) { +enum devlink_command cmd =DEVLINK_CMD_RATE_NEW ; +u32 id =NETLINK_CB (cb->skb).portid; -if (idx < dump->idx) { - idx++; -continue ; - } - err =devlink_nl_rate_fill (msg, devlink_rate, cmd, id, - cb->nlh->nlmsg_seq, -NLM_F_MULTI ,NULL ); -if (err) { -devl_unlock (devlink); -devlink_put (devlink); - dump->idx = idx; - goto out; - } +if (idx < dump->idx) { idx++; +continue ; } -devl_unlock (devlink); -devlink_put (devlink); + err =devlink_nl_rate_fill (msg, devlink_rate, cmd, id, + cb->nlh->nlmsg_seq, +NLM_F_MULTI ,NULL ); +if (err) { + dump->idx = idx; +break ; + } + idx++; } -out: -if (err != -EMSGSIZE ) -return err; -return msg->len; +return err; } +const struct devlink_gen_cmd devl_gen_rate_get = { + .dump_one = devlink_nl_cmd_rate_get_dumpinst, +}; +static int devlink_nl_cmd_rate_get_doit (struct sk_buff *skb,struct genl_info *info) {
@@ -9130,7 +9123,7 @@ const struct genl_small_ops devlink_nl_ops[56] = { { .cmd = DEVLINK_CMD_RATE_GET, .doit = devlink_nl_cmd_rate_get_doit, - .dumpit = devlink_nl_cmd_rate_get_dumpit, + .dumpit = devlink_instance_iter_dump, .internal_flags = DEVLINK_NL_FLAG_NEED_RATE, /* can be retrieved by unprivileged users */ },
net/devlink/devl_internal.h +10 -0
@@ -122,6 +122,11 @@ struct devlink_nl_dump_state { }; }; +struct devlink_gen_cmd { +int (*dump_one)(struct sk_buff *msg,struct devlink *devlink, +struct netlink_callback *cb); +}; +/* Iterate over devlink pointers which were possible to get reference to. * devlink_put() needs to be called for each iterated devlink pointer * in loop body in order to release the reference.
@@ -138,6 +143,9 @@ struct devlink *devlink_get_from_attrs(struct net *net, struct nlattr **attrs);void devlink_notify_unregister (struct devlink *devlink);void devlink_notify_register (struct devlink *devlink); +int devlink_instance_iter_dump (struct sk_buff *msg, +struct netlink_callback *cb); +static inline struct devlink_nl_dump_state *devl_dump_state (struct netlink_callback *cb) {
@@ -173,6 +181,8 @@ devlink_linecard_get_from_info(struct devlink *devlink, struct genl_info *info);void devlink_linecard_put (struct devlink_linecard *linecard);/* Rates */ +extern const struct devlink_gen_cmd devl_gen_rate_get; +struct devlink_rate *devlink_rate_get_from_info (struct devlink *devlink,struct genl_info *info); struct devlink_rate *
net/devlink/netlink.c +33 -0
@@ -5,6 +5,7 @@*/ #include <net/genetlink.h> +#include <net/sock.h> #include "devl_internal.h"
@@ -177,6 +178,38 @@ static void devlink_nl_post_doit(const struct genl_split_ops *ops,devlink_put (devlink); } +static const struct devlink_gen_cmd *devl_gen_cmds[] = { + [DEVLINK_CMD_RATE_GET ] = &devl_gen_rate_get, +}; + +int devlink_instance_iter_dump (struct sk_buff *msg,struct netlink_callback *cb) +{ +const struct genl_dumpit_info *info =genl_dumpit_info (cb); +struct devlink_nl_dump_state *dump =devl_dump_state (cb); +const struct devlink_gen_cmd *cmd; +struct devlink *devlink; +int err =0 ; + + cmd = devl_gen_cmds[info->op.cmd]; + +devlink_dump_for_each_instance_get (msg, dump, devlink) { +devl_lock (devlink); + err = cmd->dump_one (msg, devlink, cb); +devl_unlock (devlink); +devlink_put (devlink); + +if (err) +break ; + +/* restart sub-object walk for the next instance */ + dump->idx =0 ; + } + +if (err != -EMSGSIZE ) +return err; +return msg->len; +} +struct genl_family devlink_nl_family__ro_after_init = { .name =DEVLINK_GENL_NAME , .version =DEVLINK_GENL_VERSION ,
Signature · 1 line
2.38.1
Jakub Kicinski
maintainerRFC 11/15 devlink: restart dump based on devlink instance ids (nested)
In reply to Jakub KicinskiUse xarray id for cases of simple sub-object iteration. We'll now use the dump->instance for the devlink instances and dump->idx for subobject index.
Moving the definition of idx into the inner loop makes sense, so while at it also move other sub-object local variables into the loop.
--- net/devlink/basic.c | 93 +++++++++++++++++++------------------ net/devlink/devl_internal.h | 2 +- 2 files changed, 49 insertions(+), 46 deletions(-)
net/devlink/basic.c +48 -45
@@ -1223,13 +1223,13 @@ static int devlink_nl_cmd_rate_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb) {struct devlink_nl_dump_state *dump =devl_dump_state (cb); -struct devlink_rate *devlink_rate;struct devlink *devlink; -unsigned long index; -int idx =0 ;int err =0 ; -devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { +devlink_dump_for_each_instance_get (msg, dump, devlink) { +struct devlink_rate *devlink_rate; +int idx =0 ; +devl_lock (devlink);list_for_each_entry (devlink_rate, &devlink->rate_list, list) {enum devlink_command cmd =DEVLINK_CMD_RATE_NEW ;
@@ -1245,6 +1245,7 @@ static int devlink_nl_cmd_rate_get_dumpit(struct sk_buff *msg,if (err) {devl_unlock (devlink);devlink_put (devlink); + dump->idx = idx; goto out; } idx++;
@@ -1256,7 +1257,6 @@ static int devlink_nl_cmd_rate_get_dumpit(struct sk_buff *msg,if (err != -EMSGSIZE )return err; - dump->idx = idx;return msg->len; }
@@ -1363,12 +1363,13 @@ static int devlink_nl_cmd_port_get_dumpit(struct sk_buff *msg, {struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink; -struct devlink_port *devlink_port; -unsigned long index, port_index; -int idx =0 ;int err; -devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { +devlink_dump_for_each_instance_get (msg, dump, devlink) { +struct devlink_port *devlink_port; +unsigned long port_index; +int idx =0 ; +devl_lock (devlink);xa_for_each (&devlink->ports, port_index, devlink_port) {if (idx < dump->idx) {
@@ -1383,6 +1384,7 @@ static int devlink_nl_cmd_port_get_dumpit(struct sk_buff *msg,if (err) {devl_unlock (devlink);devlink_put (devlink); + dump->idx = idx; goto out; } idx++;
@@ -1391,7 +1393,6 @@ static int devlink_nl_cmd_port_get_dumpit(struct sk_buff *msg,devlink_put (devlink); } out: - dump->idx = idx;return msg->len; }
@@ -2143,11 +2144,11 @@ static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg,struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink_linecard *linecard;struct devlink *devlink; -unsigned long index; -int idx =0 ;int err; -devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { +devlink_dump_for_each_instance_get (msg, dump, devlink) { +int idx =0 ; +mutex_lock (&devlink->linecards_lock);list_for_each_entry (linecard, &devlink->linecard_list, list) {if (idx < dump->idx) {
@@ -2165,6 +2166,7 @@ static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg,if (err) {mutex_unlock (&devlink->linecards_lock);devlink_put (devlink); + dump->idx = idx; goto out; } idx++;
@@ -2173,7 +2175,6 @@ static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg,devlink_put (devlink); } out: - dump->idx = idx;return msg->len; }
@@ -2404,12 +2405,12 @@ static int devlink_nl_cmd_sb_get_dumpit(struct sk_buff *msg, {struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink *devlink; -struct devlink_sb *devlink_sb; -unsigned long index; -int idx =0 ;int err; -devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { +devlink_dump_for_each_instance_get (msg, dump, devlink) { +struct devlink_sb *devlink_sb; +int idx =0 ; +devl_lock (devlink);list_for_each_entry (devlink_sb, &devlink->sb_list, list) {if (idx < dump->idx) {
@@ -2424,6 +2425,7 @@ static int devlink_nl_cmd_sb_get_dumpit(struct sk_buff *msg,if (err) {devl_unlock (devlink);devlink_put (devlink); + dump->idx = idx; goto out; } idx++;
@@ -2432,7 +2434,6 @@ static int devlink_nl_cmd_sb_get_dumpit(struct sk_buff *msg,devlink_put (devlink); } out: - dump->idx = idx;return msg->len; }
@@ -5339,13 +5340,13 @@ static int devlink_nl_cmd_param_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb) {struct devlink_nl_dump_state *dump =devl_dump_state (cb); -struct devlink_param_item *param_item;struct devlink *devlink; -unsigned long index; -int idx =0 ;int err =0 ; -devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { +devlink_dump_for_each_instance_get (msg, dump, devlink) { +struct devlink_param_item *param_item; +int idx =0 ; +devl_lock (devlink);list_for_each_entry (param_item, &devlink->param_list, list) {if (idx < dump->idx) {
@@ -5362,6 +5363,7 @@ static int devlink_nl_cmd_param_get_dumpit(struct sk_buff *msg, }else if (err) {devl_unlock (devlink);devlink_put (devlink); + dump->idx = idx; goto out; } idx++;
@@ -5373,7 +5375,6 @@ static int devlink_nl_cmd_param_get_dumpit(struct sk_buff *msg,if (err != -EMSGSIZE )return err; - dump->idx = idx;return msg->len; }
@@ -7893,14 +7894,15 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb) {struct devlink_nl_dump_state *dump =devl_dump_state (cb); -struct devlink_health_reporter *reporter; -unsigned long index, port_index; -struct devlink_port *port;struct devlink *devlink; -int idx =0 ;int err; -devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { +devlink_dump_for_each_instance_get (msg, dump, devlink) { +struct devlink_health_reporter *reporter; +struct devlink_port *port; +unsigned long port_index; +int idx =0 ; +mutex_lock (&devlink->reporters_lock);list_for_each_entry (reporter, &devlink->reporter_list, list) {
@@ -7915,6 +7917,7 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,if (err) {mutex_unlock (&devlink->reporters_lock);devlink_put (devlink); + dump->idx = idx; goto out; } idx++;
@@ -7938,6 +7941,7 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,mutex_unlock (&port->reporters_lock);devl_unlock (devlink);devlink_put (devlink); + dump->idx = idx; goto out; } idx++;
@@ -7948,7 +7952,6 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,devlink_put (devlink); } out: - dump->idx = idx;return msg->len; }
@@ -8474,13 +8477,13 @@ static int devlink_nl_cmd_trap_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb) {struct devlink_nl_dump_state *dump =devl_dump_state (cb); -struct devlink_trap_item *trap_item;struct devlink *devlink; -unsigned long index; -int idx =0 ;int err; -devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { +devlink_dump_for_each_instance_get (msg, dump, devlink) { +struct devlink_trap_item *trap_item; +int idx =0 ; +devl_lock (devlink);list_for_each_entry (trap_item, &devlink->trap_list, list) {if (idx < dump->idx) {
@@ -8495,6 +8498,7 @@ static int devlink_nl_cmd_trap_get_dumpit(struct sk_buff *msg,if (err) {devl_unlock (devlink);devlink_put (devlink); + dump->idx = idx; goto out; } idx++;
@@ -8503,7 +8507,6 @@ static int devlink_nl_cmd_trap_get_dumpit(struct sk_buff *msg,devlink_put (devlink); } out: - dump->idx = idx;return msg->len; }
@@ -8690,14 +8693,14 @@ static int devlink_nl_cmd_trap_group_get_dumpit(struct sk_buff *msg, {struct devlink_nl_dump_state *dump =devl_dump_state (cb);enum devlink_command cmd =DEVLINK_CMD_TRAP_GROUP_NEW ; -struct devlink_trap_group_item *group_item;u32 portid =NETLINK_CB (cb->skb).portid;struct devlink *devlink; -unsigned long index; -int idx =0 ;int err; -devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { +devlink_dump_for_each_instance_get (msg, dump, devlink) { +struct devlink_trap_group_item *group_item; +int idx =0 ; +devl_lock (devlink);list_for_each_entry (group_item, &devlink->trap_group_list, list) {
@@ -8713,6 +8716,7 @@ static int devlink_nl_cmd_trap_group_get_dumpit(struct sk_buff *msg,if (err) {devl_unlock (devlink);devlink_put (devlink); + dump->idx = idx; goto out; } idx++;
@@ -8721,7 +8725,6 @@ static int devlink_nl_cmd_trap_group_get_dumpit(struct sk_buff *msg,devlink_put (devlink); } out: - dump->idx = idx;return msg->len; }
@@ -8994,14 +8997,14 @@ static int devlink_nl_cmd_trap_policer_get_dumpit(struct sk_buff *msg, {struct devlink_nl_dump_state *dump =devl_dump_state (cb);enum devlink_command cmd =DEVLINK_CMD_TRAP_POLICER_NEW ; -struct devlink_trap_policer_item *policer_item;u32 portid =NETLINK_CB (cb->skb).portid;struct devlink *devlink; -unsigned long index; -int idx =0 ;int err; -devlinks_xa_for_each_registered_get (sock_net (msg->sk), index, devlink) { +devlink_dump_for_each_instance_get (msg, dump, devlink) { +struct devlink_trap_policer_item *policer_item; +int idx =0 ; +devl_lock (devlink);list_for_each_entry (policer_item, &devlink->trap_policer_list, list) {
@@ -9017,6 +9020,7 @@ static int devlink_nl_cmd_trap_policer_get_dumpit(struct sk_buff *msg,if (err) {devl_unlock (devlink);devlink_put (devlink); + dump->idx = idx; goto out; } idx++;
@@ -9025,7 +9029,6 @@ static int devlink_nl_cmd_trap_policer_get_dumpit(struct sk_buff *msg,devlink_put (devlink); } out: - dump->idx = idx;return msg->len; }
net/devlink/devl_internal.h +1 -1
@@ -129,7 +129,7 @@ struct devlink_nl_dump_state {#define devlink_dump_for_each_instance_get (msg, dump, devlink) \ for (; (devlink = devlinks_xa_find_get(sock_net(msg->sk), \ &dump->instance, xa_find)); \ - dump->instance++) + dump->instance++, dump->idx = 0)extern const struct genl_small_ops devlink_nl_ops[56 ];
Signature · 1 line
2.38.1
Jakub Kicinski
maintainerRFC 15/15 devlink: convert remaining dumps to the by-instance scheme
In reply to Jakub KicinskiSoon we'll have to check if a devlink instance is alive after locking it. Convert to the by-instance dumping scheme to make refactoring easier.
Most of the subobject code no longer has to worry about any devlink locking / lifetime rules (the only ones that still do are the two subject types which stubbornly use their own locking). Both dump and do callbacks are given a devlink instance which is already locked and good-to-access (do from the .pre_doit handler, dump from the new dump indirection).
Note that we'll now check presence of an op (e.g. for sb_pool_get) under the devlink instance lock, that will soon be necessary anyway, because we don't hold refs on the driver modules so the memory in which ops live may be gone for a dead instance, after upcoming locking changes.
--- net/devlink/basic.c | 686 +++++++++++++++--------------------- net/devlink/devl_internal.h | 15 + net/devlink/netlink.c | 13 + 3 files changed, 320 insertions(+), 394 deletions(-)
net/devlink/basic.c +292 -394
@@ -1307,28 +1307,19 @@ static int devlink_nl_cmd_get_doit(struct sk_buff *skb, struct genl_info *info)return genlmsg_reply (msg, info); } -static int devlink_nl_cmd_get_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) +static int +devlink_nl_cmd_get_dumpinst (struct sk_buff *msg,struct devlink *devlink, +struct netlink_callback *cb) { -struct devlink_nl_dump_state *dump =devl_dump_state (cb); -struct devlink *devlink; -int err; - -devlink_dump_for_each_instance_get (msg, dump, devlink) { -devl_lock (devlink); - err =devlink_nl_fill (msg, devlink,DEVLINK_CMD_NEW , -NETLINK_CB (cb->skb).portid, - cb->nlh->nlmsg_seq,NLM_F_MULTI ); -devl_unlock (devlink); -devlink_put (devlink); - -if (err) - goto out; - } -out: -return msg->len; +return devlink_nl_fill (msg, devlink,DEVLINK_CMD_NEW , +NETLINK_CB (cb->skb).portid, + cb->nlh->nlmsg_seq,NLM_F_MULTI ); } +const struct devlink_gen_cmd devl_gen_inst = { + .dump_one = devlink_nl_cmd_get_dumpinst, +}; +static int devlink_nl_cmd_port_get_doit (struct sk_buff *skb,struct genl_info *info) {
@@ -1351,44 +1342,40 @@ static int devlink_nl_cmd_port_get_doit(struct sk_buff *skb,return genlmsg_reply (msg, info); } -static int devlink_nl_cmd_port_get_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) +static int +devlink_nl_cmd_port_get_dumpinst (struct sk_buff *msg,struct devlink *devlink, +struct netlink_callback *cb) {struct devlink_nl_dump_state *dump =devl_dump_state (cb); -struct devlink *devlink; -int err; - -devlink_dump_for_each_instance_get (msg, dump, devlink) { -struct devlink_port *devlink_port; -unsigned long port_index; -int idx =0 ; +struct devlink_port *devlink_port; +unsigned long port_index; +int idx =0 ; +int err =0 ; -devl_lock (devlink); -xa_for_each (&devlink->ports, port_index, devlink_port) { -if (idx < dump->idx) { - idx++; -continue ; - } - err =devlink_nl_port_fill (msg, devlink_port, -DEVLINK_CMD_NEW , -NETLINK_CB (cb->skb).portid, - cb->nlh->nlmsg_seq, -NLM_F_MULTI , cb->extack); -if (err) { -devl_unlock (devlink); -devlink_put (devlink); - dump->idx = idx; - goto out; - } +xa_for_each (&devlink->ports, port_index, devlink_port) { +if (idx < dump->idx) { idx++; +continue ; } -devl_unlock (devlink); -devlink_put (devlink); + err =devlink_nl_port_fill (msg, devlink_port, +DEVLINK_CMD_NEW , +NETLINK_CB (cb->skb).portid, + cb->nlh->nlmsg_seq, +NLM_F_MULTI , cb->extack); +if (err) { + dump->idx = idx; +break ; + } + idx++; } -out: -return msg->len; + +return err; } +const struct devlink_gen_cmd devl_gen_port = { + .dump_one = devlink_nl_cmd_port_get_dumpinst, +}; +static int devlink_port_type_set (struct devlink_port *devlink_port,enum devlink_port_type port_type)
@@ -2393,43 +2380,39 @@ static int devlink_nl_cmd_sb_get_doit(struct sk_buff *skb,return genlmsg_reply (msg, info); } -static int devlink_nl_cmd_sb_get_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) +static int +devlink_nl_cmd_sb_get_dumpinst (struct sk_buff *msg,struct devlink *devlink, +struct netlink_callback *cb) {struct devlink_nl_dump_state *dump =devl_dump_state (cb); -struct devlink *devlink; -int err; - -devlink_dump_for_each_instance_get (msg, dump, devlink) { -struct devlink_sb *devlink_sb; -int idx =0 ; +struct devlink_sb *devlink_sb; +int idx =0 ; +int err =0 ; -devl_lock (devlink); -list_for_each_entry (devlink_sb, &devlink->sb_list, list) { -if (idx < dump->idx) { - idx++; -continue ; - } - err =devlink_nl_sb_fill (msg, devlink, devlink_sb, -DEVLINK_CMD_SB_NEW , -NETLINK_CB (cb->skb).portid, - cb->nlh->nlmsg_seq, -NLM_F_MULTI ); -if (err) { -devl_unlock (devlink); -devlink_put (devlink); - dump->idx = idx; - goto out; - } +list_for_each_entry (devlink_sb, &devlink->sb_list, list) { +if (idx < dump->idx) { idx++; +continue ; } -devl_unlock (devlink); -devlink_put (devlink); + err =devlink_nl_sb_fill (msg, devlink, devlink_sb, +DEVLINK_CMD_SB_NEW , +NETLINK_CB (cb->skb).portid, + cb->nlh->nlmsg_seq, +NLM_F_MULTI ); +if (err) { + dump->idx = idx; +break ; + } + idx++; } -out: -return msg->len; + +return err; } +const struct devlink_gen_cmd devl_gen_sb = { + .dump_one = devlink_nl_cmd_sb_get_dumpinst, +}; + static int devlink_nl_sb_pool_fill(struct sk_buff *msg, struct devlink *devlink, struct devlink_sb *devlink_sb, u16 pool_index, enum devlink_command cmd,
@@ -2535,46 +2518,39 @@ static int __sb_pool_get_dumpit(struct sk_buff *msg, int start, int *p_idx,return 0 ; } -static int devlink_nl_cmd_sb_pool_get_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) +static int +devlink_nl_cmd_sb_pool_get_dumpinst (struct sk_buff *msg, +struct devlink *devlink, +struct netlink_callback *cb) {struct devlink_nl_dump_state *dump =devl_dump_state (cb); -struct devlink *devlink; +struct devlink_sb *devlink_sb;int err =0 ; +int idx =0 ; -devlink_dump_for_each_instance_get (msg, dump, devlink) { -struct devlink_sb *devlink_sb; -int idx =0 ; - -if (!devlink->ops->sb_pool_get) - goto retry; +if (!devlink->ops->sb_pool_get) +return 0 ; -devl_lock (devlink); -list_for_each_entry (devlink_sb, &devlink->sb_list, list) { - err =__sb_pool_get_dumpit (msg, dump->idx, &idx, - devlink, devlink_sb, -NETLINK_CB (cb->skb).portid, - cb->nlh->nlmsg_seq); -if (err == -EOPNOTSUPP ) { - err =0 ; - }else if (err) { -devl_unlock (devlink); -devlink_put (devlink); - dump->idx = idx; - goto out; - } +list_for_each_entry (devlink_sb, &devlink->sb_list, list) { + err =__sb_pool_get_dumpit (msg, dump->idx, &idx, + devlink, devlink_sb, +NETLINK_CB (cb->skb).portid, + cb->nlh->nlmsg_seq); +if (err == -EOPNOTSUPP ) { + err =0 ; + }else if (err) { + dump->idx = idx; +break ; } -devl_unlock (devlink); -retry: -devlink_put (devlink); } -out: -if (err != -EMSGSIZE ) -return err; -return msg->len; +return err; } +const struct devlink_gen_cmd devl_gen_sb_pool = { + .dump_one = devlink_nl_cmd_sb_pool_get_dumpinst, +}; + static int devlink_sb_pool_set(struct devlink *devlink, unsigned int sb_index, u16 pool_index, u32 size, enum devlink_sb_threshold_type threshold_type,
@@ -2750,46 +2726,39 @@ static int __sb_port_pool_get_dumpit(struct sk_buff *msg, int start, int *p_idx,return 0 ; } -static int devlink_nl_cmd_sb_port_pool_get_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) +static int +devlink_nl_cmd_sb_port_pool_get_dumpinst (struct sk_buff *msg, +struct devlink *devlink, +struct netlink_callback *cb) {struct devlink_nl_dump_state *dump =devl_dump_state (cb); -struct devlink *devlink; +struct devlink_sb *devlink_sb; +int idx =0 ;int err =0 ; -devlink_dump_for_each_instance_get (msg, dump, devlink) { -struct devlink_sb *devlink_sb; -int idx =0 ; - -if (!devlink->ops->sb_port_pool_get) - goto retry; +if (!devlink->ops->sb_port_pool_get) +return 0 ; -devl_lock (devlink); -list_for_each_entry (devlink_sb, &devlink->sb_list, list) { - err =__sb_port_pool_get_dumpit (msg, dump->idx, &idx, - devlink, devlink_sb, -NETLINK_CB (cb->skb).portid, - cb->nlh->nlmsg_seq); -if (err == -EOPNOTSUPP ) { - err =0 ; - }else if (err) { -devl_unlock (devlink); -devlink_put (devlink); - dump->idx = idx; - goto out; - } +list_for_each_entry (devlink_sb, &devlink->sb_list, list) { + err =__sb_port_pool_get_dumpit (msg, dump->idx, &idx, + devlink, devlink_sb, +NETLINK_CB (cb->skb).portid, + cb->nlh->nlmsg_seq); +if (err == -EOPNOTSUPP ) { + err =0 ; + }else if (err) { + dump->idx = idx; +break ; } -devl_unlock (devlink); -retry: -devlink_put (devlink); } -out: -if (err != -EMSGSIZE ) -return err; -return msg->len; +return err; } +const struct devlink_gen_cmd devl_gen_sb_port_pool = { + .dump_one = devlink_nl_cmd_sb_port_pool_get_dumpinst, +}; + static int devlink_sb_port_pool_set(struct devlink_port *devlink_port, unsigned int sb_index, u16 pool_index, u32 threshold,
@@ -2993,46 +2962,38 @@ static int __sb_tc_pool_bind_get_dumpit(struct sk_buff *msg, }static int -devlink_nl_cmd_sb_tc_pool_bind_get_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) +devlink_nl_cmd_sb_tc_pool_bind_get_dumpinst (struct sk_buff *msg, +struct devlink *devlink, +struct netlink_callback *cb) {struct devlink_nl_dump_state *dump =devl_dump_state (cb); -struct devlink *devlink; +struct devlink_sb *devlink_sb; +int idx =0 ;int err =0 ; -devlink_dump_for_each_instance_get (msg, dump, devlink) { -struct devlink_sb *devlink_sb; -int idx =0 ; - -if (!devlink->ops->sb_tc_pool_bind_get) - goto retry; +if (!devlink->ops->sb_tc_pool_bind_get) +return 0 ; -devl_lock (devlink); -list_for_each_entry (devlink_sb, &devlink->sb_list, list) { - err =__sb_tc_pool_bind_get_dumpit (msg, dump->idx, &idx, - devlink, devlink_sb, -NETLINK_CB (cb->skb).portid, - cb->nlh->nlmsg_seq); -if (err == -EOPNOTSUPP ) { - err =0 ; - }else if (err) { -devl_unlock (devlink); -devlink_put (devlink); - dump->idx = idx; - goto out; - } +list_for_each_entry (devlink_sb, &devlink->sb_list, list) { + err =__sb_tc_pool_bind_get_dumpit (msg, dump->idx, &idx, + devlink, devlink_sb, +NETLINK_CB (cb->skb).portid, + cb->nlh->nlmsg_seq); +if (err == -EOPNOTSUPP ) { + err =0 ; + }else if (err) { + dump->idx = idx; +break ; } -devl_unlock (devlink); -retry: -devlink_put (devlink); } -out: -if (err != -EMSGSIZE ) -return err; -return msg->len; +return err; } +const struct devlink_gen_cmd devl_gen_sb_tc_pool_bind = { + .dump_one = devlink_nl_cmd_sb_tc_pool_bind_get_dumpinst, +}; + static int devlink_sb_tc_pool_bind_set(struct devlink_port *devlink_port, unsigned int sb_index, u16 tc_index, enum devlink_sb_pool_type pool_type,
@@ -4851,39 +4812,24 @@ static int devlink_nl_cmd_selftests_get_doit(struct sk_buff *skb,return genlmsg_reply (msg, info); } -static int devlink_nl_cmd_selftests_get_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) +static int +devlink_nl_cmd_selftests_get_dumpinst (struct sk_buff *msg, +struct devlink *devlink, +struct netlink_callback *cb) { -struct devlink_nl_dump_state *dump =devl_dump_state (cb); -struct devlink *devlink; -int err =0 ; - -devlink_dump_for_each_instance_get (msg, dump, devlink) { -if (!devlink->ops->selftest_check) { -devlink_put (devlink); -continue ; - } - -devl_lock (devlink); - err =devlink_nl_selftests_fill (msg, devlink, -NETLINK_CB (cb->skb).portid, - cb->nlh->nlmsg_seq,NLM_F_MULTI , - cb->extack); -devl_unlock (devlink); -if (err) { -devlink_put (devlink); -break ; - } - -devlink_put (devlink); - } - -if (err != -EMSGSIZE ) -return err; +if (!devlink->ops->selftest_check) +return 0 ; -return msg->len; +return devlink_nl_selftests_fill (msg, devlink, +NETLINK_CB (cb->skb).portid, + cb->nlh->nlmsg_seq,NLM_F_MULTI , + cb->extack); } +const struct devlink_gen_cmd devl_gen_selftests = { + .dump_one = devlink_nl_cmd_selftests_get_dumpinst, +}; +static int devlink_selftest_result_put (struct sk_buff *skb,unsigned int id,enum devlink_selftest_status test_status) {
@@ -5329,48 +5275,41 @@ static void devlink_param_notify(struct devlink *devlink, msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL); } -static int devlink_nl_cmd_param_get_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) +static int +devlink_nl_cmd_param_get_dumpinst (struct sk_buff *msg,struct devlink *devlink, +struct netlink_callback *cb) {struct devlink_nl_dump_state *dump =devl_dump_state (cb); -struct devlink *devlink; +struct devlink_param_item *param_item; +int idx =0 ;int err =0 ; -devlink_dump_for_each_instance_get (msg, dump, devlink) { -struct devlink_param_item *param_item; -int idx =0 ; - -devl_lock (devlink); -list_for_each_entry (param_item, &devlink->param_list, list) { -if (idx < dump->idx) { - idx++; -continue ; - } - err =devlink_nl_param_fill (msg, devlink,0 , param_item, -DEVLINK_CMD_PARAM_GET , -NETLINK_CB (cb->skb).portid, - cb->nlh->nlmsg_seq, -NLM_F_MULTI ); -if (err == -EOPNOTSUPP ) { - err =0 ; - }else if (err) { -devl_unlock (devlink); -devlink_put (devlink); - dump->idx = idx; - goto out; - } +list_for_each_entry (param_item, &devlink->param_list, list) { +if (idx < dump->idx) { idx++; +continue ; } -devl_unlock (devlink); -devlink_put (devlink); + err =devlink_nl_param_fill (msg, devlink,0 , param_item, +DEVLINK_CMD_PARAM_GET , +NETLINK_CB (cb->skb).portid, + cb->nlh->nlmsg_seq, +NLM_F_MULTI ); +if (err == -EOPNOTSUPP ) { + err =0 ; + }else if (err) { + dump->idx = idx; +break ; + } + idx++; } -out: -if (err != -EMSGSIZE ) -return err; -return msg->len; +return err; } +const struct devlink_gen_cmd devl_gen_param = { + .dump_one = devlink_nl_cmd_param_get_dumpinst, +}; +static int devlink_param_type_get_from_info (struct genl_info *info,enum devlink_param_type *param_type)
@@ -6034,20 +5973,20 @@ static int devlink_nl_cmd_region_get_port_dumpit(struct sk_buff *msg,return err; } -static int devlink_nl_cmd_region_get_devlink_dumpit (struct sk_buff *msg, -struct netlink_callback *cb, -struct devlink *devlink, -int *idx, -int start) +static int +devlink_nl_cmd_region_get_dumpinst (struct sk_buff *msg,struct devlink *devlink, +struct netlink_callback *cb) { +struct devlink_nl_dump_state *dump =devl_dump_state (cb);struct devlink_region *region;struct devlink_port *port;unsigned long port_index; +int idx =0 ;int err;list_for_each_entry (region, &devlink->region_list, list) { -if (*idx < start) { - (*idx)++; +if (idx < dump->idx) { + idx++;continue ; } err = devlink_nl_region_fill(msg, devlink,
@@ -6055,44 +5994,28 @@ static int devlink_nl_cmd_region_get_devlink_dumpit(struct sk_buff *msg,NETLINK_CB (cb->skb).portid, cb->nlh->nlmsg_seq, NLM_F_MULTI, region); -if (err) +if (err) { + dump->idx = idx;return err; - (*idx)++; + } + idx++; }xa_for_each (&devlink->ports, port_index, port) { - err =devlink_nl_cmd_region_get_port_dumpit (msg, cb, port, idx, - start); -if (err) + err =devlink_nl_cmd_region_get_port_dumpit (msg, cb, port, &idx, + dump->idx); +if (err) { + dump->idx = idx;return err; + } }return 0 ; } -static int devlink_nl_cmd_region_get_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) -{ -struct devlink_nl_dump_state *dump =devl_dump_state (cb); -struct devlink *devlink; -int err =0 ; - -devlink_dump_for_each_instance_get (msg, dump, devlink) { -int idx =0 ; - -devl_lock (devlink); - err =devlink_nl_cmd_region_get_devlink_dumpit (msg, cb, devlink, - &idx, dump->idx); -devl_unlock (devlink); -devlink_put (devlink); -if (err) { - dump->idx = idx; - goto out; - } - } -out: -return msg->len; -} +const struct devlink_gen_cmd devl_gen_region = { + .dump_one = devlink_nl_cmd_region_get_dumpinst, +};static int devlink_nl_cmd_region_del (struct sk_buff *skb,struct genl_info *info)
@@ -6724,35 +6647,25 @@ static int devlink_nl_cmd_info_get_doit(struct sk_buff *skb,return genlmsg_reply (msg, info); } -static int devlink_nl_cmd_info_get_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) +static int +devlink_nl_cmd_info_get_dumpinst (struct sk_buff *msg,struct devlink *devlink, +struct netlink_callback *cb) { -struct devlink_nl_dump_state *dump =devl_dump_state (cb); -struct devlink *devlink; -int err =0 ; - -devlink_dump_for_each_instance_get (msg, dump, devlink) { -devl_lock (devlink); - err =devlink_nl_info_fill (msg, devlink,DEVLINK_CMD_INFO_GET , -NETLINK_CB (cb->skb).portid, - cb->nlh->nlmsg_seq,NLM_F_MULTI , - cb->extack); -devl_unlock (devlink); -if (err == -EOPNOTSUPP ) - err =0 ; -else if (err) { -devlink_put (devlink); -break ; - } -devlink_put (devlink); - } - -if (err != -EMSGSIZE ) -return err; +int err; -return msg->len; + err =devlink_nl_info_fill (msg, devlink,DEVLINK_CMD_INFO_GET , +NETLINK_CB (cb->skb).portid, + cb->nlh->nlmsg_seq,NLM_F_MULTI , + cb->extack); +if (err == -EOPNOTSUPP ) + err =0 ; +return err; } +const struct devlink_gen_cmd devl_gen_info = { + .dump_one = devlink_nl_cmd_info_get_dumpinst, +}; +struct devlink_fmsg_item {struct list_head list;int attrtype;
@@ -8466,43 +8379,39 @@ static int devlink_nl_cmd_trap_get_doit(struct sk_buff *skb,return err; } -static int devlink_nl_cmd_trap_get_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) +static int +devlink_nl_cmd_trap_get_dumpinst (struct sk_buff *msg,struct devlink *devlink, +struct netlink_callback *cb) {struct devlink_nl_dump_state *dump =devl_dump_state (cb); -struct devlink *devlink; -int err; - -devlink_dump_for_each_instance_get (msg, dump, devlink) { -struct devlink_trap_item *trap_item; -int idx =0 ; +struct devlink_trap_item *trap_item; +int idx =0 ; +int err =0 ; -devl_lock (devlink); -list_for_each_entry (trap_item, &devlink->trap_list, list) { -if (idx < dump->idx) { - idx++; -continue ; - } - err =devlink_nl_trap_fill (msg, devlink, trap_item, -DEVLINK_CMD_TRAP_NEW , -NETLINK_CB (cb->skb).portid, - cb->nlh->nlmsg_seq, -NLM_F_MULTI ); -if (err) { -devl_unlock (devlink); -devlink_put (devlink); - dump->idx = idx; - goto out; - } +list_for_each_entry (trap_item, &devlink->trap_list, list) { +if (idx < dump->idx) { idx++; +continue ; } -devl_unlock (devlink); -devlink_put (devlink); + err =devlink_nl_trap_fill (msg, devlink, trap_item, +DEVLINK_CMD_TRAP_NEW , +NETLINK_CB (cb->skb).portid, + cb->nlh->nlmsg_seq, +NLM_F_MULTI ); +if (err) { + dump->idx = idx; +break ; + } + idx++; } -out: -return msg->len; + +return err; } +const struct devlink_gen_cmd devl_gen_trap = { + .dump_one = devlink_nl_cmd_trap_get_dumpinst, +}; + static int __devlink_trap_action_set(struct devlink *devlink, struct devlink_trap_item *trap_item, enum devlink_trap_action trap_action,
@@ -8681,46 +8590,41 @@ static int devlink_nl_cmd_trap_group_get_doit(struct sk_buff *skb,return err; } -static int devlink_nl_cmd_trap_group_get_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) +static int +devlink_nl_cmd_trap_group_get_dumpinst (struct sk_buff *msg, +struct devlink *devlink, +struct netlink_callback *cb) {struct devlink_nl_dump_state *dump =devl_dump_state (cb); -enum devlink_command cmd =DEVLINK_CMD_TRAP_GROUP_NEW ; -u32 portid =NETLINK_CB (cb->skb).portid; -struct devlink *devlink; -int err; +struct devlink_trap_group_item *group_item; +int idx =0 ; +int err =0 ; -devlink_dump_for_each_instance_get (msg, dump, devlink) { -struct devlink_trap_group_item *group_item; -int idx =0 ; -devl_lock (devlink); -list_for_each_entry (group_item, &devlink->trap_group_list, - list) { -if (idx < dump->idx) { - idx++; -continue ; - } - err =devlink_nl_trap_group_fill (msg, devlink, - group_item, cmd, - portid, - cb->nlh->nlmsg_seq, -NLM_F_MULTI ); -if (err) { -devl_unlock (devlink); -devlink_put (devlink); - dump->idx = idx; - goto out; - } +list_for_each_entry (group_item, &devlink->trap_group_list, list) { +if (idx < dump->idx) { idx++; +continue ; } -devl_unlock (devlink); -devlink_put (devlink); + err =devlink_nl_trap_group_fill (msg, devlink, group_item, +DEVLINK_CMD_TRAP_GROUP_NEW , +NETLINK_CB (cb->skb).portid, + cb->nlh->nlmsg_seq, +NLM_F_MULTI ); +if (err) { + dump->idx = idx; +break ; + } + idx++; } -out: -return msg->len; + +return err; } +const struct devlink_gen_cmd devl_gen_trap_group = { + .dump_one = devlink_nl_cmd_trap_group_get_dumpinst, +}; + static int __devlink_trap_group_action_set(struct devlink *devlink, struct devlink_trap_group_item *group_item,
@@ -8985,46 +8889,40 @@ static int devlink_nl_cmd_trap_policer_get_doit(struct sk_buff *skb,return err; } -static int devlink_nl_cmd_trap_policer_get_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) +static int +devlink_nl_cmd_trap_policer_get_dumpinst (struct sk_buff *msg, +struct devlink *devlink, +struct netlink_callback *cb) {struct devlink_nl_dump_state *dump =devl_dump_state (cb); -enum devlink_command cmd =DEVLINK_CMD_TRAP_POLICER_NEW ; -u32 portid =NETLINK_CB (cb->skb).portid; -struct devlink *devlink; -int err; - -devlink_dump_for_each_instance_get (msg, dump, devlink) { -struct devlink_trap_policer_item *policer_item; -int idx =0 ; +struct devlink_trap_policer_item *policer_item; +int idx =0 ; +int err =0 ; -devl_lock (devlink); -list_for_each_entry (policer_item, &devlink->trap_policer_list, - list) { -if (idx < dump->idx) { - idx++; -continue ; - } - err =devlink_nl_trap_policer_fill (msg, devlink, - policer_item, cmd, - portid, - cb->nlh->nlmsg_seq, -NLM_F_MULTI ); -if (err) { -devl_unlock (devlink); -devlink_put (devlink); - dump->idx = idx; - goto out; - } +list_for_each_entry (policer_item, &devlink->trap_policer_list, list) { +if (idx < dump->idx) { idx++; +continue ; } -devl_unlock (devlink); -devlink_put (devlink); + err =devlink_nl_trap_policer_fill (msg, devlink, policer_item, +DEVLINK_CMD_TRAP_POLICER_NEW , +NETLINK_CB (cb->skb).portid, + cb->nlh->nlmsg_seq, +NLM_F_MULTI ); +if (err) { + dump->idx = idx; +break ; + } + idx++; } -out: -return msg->len; + +return err; } +const struct devlink_gen_cmd devl_gen_trap_policer = { + .dump_one = devlink_nl_cmd_trap_policer_get_dumpinst, +}; + static int devlink_trap_policer_set(struct devlink *devlink, struct devlink_trap_policer_item *policer_item,
@@ -9102,14 +9000,14 @@ const struct genl_small_ops devlink_nl_ops[56] = { .cmd = DEVLINK_CMD_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = devlink_nl_cmd_get_doit, - .dumpit = devlink_nl_cmd_get_dumpit, + .dumpit = devlink_instance_iter_dump, /* can be retrieved by unprivileged users */ }, { .cmd = DEVLINK_CMD_PORT_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = devlink_nl_cmd_port_get_doit, - .dumpit = devlink_nl_cmd_port_get_dumpit, + .dumpit = devlink_instance_iter_dump, .internal_flags = DEVLINK_NL_FLAG_NEED_PORT, /* can be retrieved by unprivileged users */ },
@@ -9185,14 +9083,14 @@ const struct genl_small_ops devlink_nl_ops[56] = { .cmd = DEVLINK_CMD_SB_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = devlink_nl_cmd_sb_get_doit, - .dumpit = devlink_nl_cmd_sb_get_dumpit, + .dumpit = devlink_instance_iter_dump, /* can be retrieved by unprivileged users */ }, { .cmd = DEVLINK_CMD_SB_POOL_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = devlink_nl_cmd_sb_pool_get_doit, - .dumpit = devlink_nl_cmd_sb_pool_get_dumpit, + .dumpit = devlink_instance_iter_dump, /* can be retrieved by unprivileged users */ }, {
@@ -9205,7 +9103,7 @@ const struct genl_small_ops devlink_nl_ops[56] = { .cmd = DEVLINK_CMD_SB_PORT_POOL_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = devlink_nl_cmd_sb_port_pool_get_doit, - .dumpit = devlink_nl_cmd_sb_port_pool_get_dumpit, + .dumpit = devlink_instance_iter_dump, .internal_flags = DEVLINK_NL_FLAG_NEED_PORT, /* can be retrieved by unprivileged users */ },
@@ -9220,7 +9118,7 @@ const struct genl_small_ops devlink_nl_ops[56] = { .cmd = DEVLINK_CMD_SB_TC_POOL_BIND_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = devlink_nl_cmd_sb_tc_pool_bind_get_doit, - .dumpit = devlink_nl_cmd_sb_tc_pool_bind_get_dumpit, + .dumpit = devlink_instance_iter_dump, .internal_flags = DEVLINK_NL_FLAG_NEED_PORT, /* can be retrieved by unprivileged users */ },
@@ -9301,7 +9199,7 @@ const struct genl_small_ops devlink_nl_ops[56] = { .cmd = DEVLINK_CMD_PARAM_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = devlink_nl_cmd_param_get_doit, - .dumpit = devlink_nl_cmd_param_get_dumpit, + .dumpit = devlink_instance_iter_dump, /* can be retrieved by unprivileged users */ }, {
@@ -9329,7 +9227,7 @@ const struct genl_small_ops devlink_nl_ops[56] = { .cmd = DEVLINK_CMD_REGION_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = devlink_nl_cmd_region_get_doit, - .dumpit = devlink_nl_cmd_region_get_dumpit, + .dumpit = devlink_instance_iter_dump, .flags = GENL_ADMIN_PERM, }, {
@@ -9355,7 +9253,7 @@ const struct genl_small_ops devlink_nl_ops[56] = { .cmd = DEVLINK_CMD_INFO_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = devlink_nl_cmd_info_get_doit, - .dumpit = devlink_nl_cmd_info_get_dumpit, + .dumpit = devlink_instance_iter_dump, /* can be retrieved by unprivileged users */ }, {
@@ -9417,7 +9315,7 @@ const struct genl_small_ops devlink_nl_ops[56] = { { .cmd = DEVLINK_CMD_TRAP_GET, .doit = devlink_nl_cmd_trap_get_doit, - .dumpit = devlink_nl_cmd_trap_get_dumpit, + .dumpit = devlink_instance_iter_dump, /* can be retrieved by unprivileged users */ }, {
@@ -9428,7 +9326,7 @@ const struct genl_small_ops devlink_nl_ops[56] = { { .cmd = DEVLINK_CMD_TRAP_GROUP_GET, .doit = devlink_nl_cmd_trap_group_get_doit, - .dumpit = devlink_nl_cmd_trap_group_get_dumpit, + .dumpit = devlink_instance_iter_dump, /* can be retrieved by unprivileged users */ }, {
@@ -9439,7 +9337,7 @@ const struct genl_small_ops devlink_nl_ops[56] = { { .cmd = DEVLINK_CMD_TRAP_POLICER_GET, .doit = devlink_nl_cmd_trap_policer_get_doit, - .dumpit = devlink_nl_cmd_trap_policer_get_dumpit, + .dumpit = devlink_instance_iter_dump, /* can be retrieved by unprivileged users */ }, {
@@ -9450,7 +9348,7 @@ const struct genl_small_ops devlink_nl_ops[56] = { { .cmd = DEVLINK_CMD_SELFTESTS_GET, .doit = devlink_nl_cmd_selftests_get_doit, - .dumpit = devlink_nl_cmd_selftests_get_dumpit + .dumpit = devlink_instance_iter_dump, /* can be retrieved by unprivileged users */ }, {
net/devlink/devl_internal.h +15 -0
@@ -154,6 +154,21 @@ devl_dump_state(struct netlink_callback *cb)return (struct devlink_nl_dump_state *)cb->ctx; } +/* gen cmds */ +extern const struct devlink_gen_cmd devl_gen_inst; +extern const struct devlink_gen_cmd devl_gen_port; +extern const struct devlink_gen_cmd devl_gen_sb; +extern const struct devlink_gen_cmd devl_gen_sb_pool; +extern const struct devlink_gen_cmd devl_gen_sb_port_pool; +extern const struct devlink_gen_cmd devl_gen_sb_tc_pool_bind; +extern const struct devlink_gen_cmd devl_gen_selftests; +extern const struct devlink_gen_cmd devl_gen_param; +extern const struct devlink_gen_cmd devl_gen_region; +extern const struct devlink_gen_cmd devl_gen_info; +extern const struct devlink_gen_cmd devl_gen_trap; +extern const struct devlink_gen_cmd devl_gen_trap_group; +extern const struct devlink_gen_cmd devl_gen_trap_policer; +/* Ports */ int devlink_port_netdevice_event (struct notifier_block *nb,unsigned long event,void *ptr);
net/devlink/netlink.c +13 -0
@@ -179,7 +179,20 @@ static void devlink_nl_post_doit(const struct genl_split_ops *ops, }static const struct devlink_gen_cmd *devl_gen_cmds[] = { + [DEVLINK_CMD_GET ] = &devl_gen_inst, + [DEVLINK_CMD_PORT_GET ] = &devl_gen_port, + [DEVLINK_CMD_SB_GET ] = &devl_gen_sb, + [DEVLINK_CMD_SB_POOL_GET ] = &devl_gen_sb_pool, + [DEVLINK_CMD_SB_PORT_POOL_GET ] = &devl_gen_sb_port_pool, + [DEVLINK_CMD_SB_TC_POOL_BIND_GET ] = &devl_gen_sb_tc_pool_bind, + [DEVLINK_CMD_PARAM_GET ] = &devl_gen_param, + [DEVLINK_CMD_REGION_GET ] = &devl_gen_region, + [DEVLINK_CMD_INFO_GET ] = &devl_gen_info, [DEVLINK_CMD_RATE_GET ] = &devl_gen_rate_get, + [DEVLINK_CMD_TRAP_GET ] = &devl_gen_trap, + [DEVLINK_CMD_TRAP_GROUP_GET ] = &devl_gen_trap_group, + [DEVLINK_CMD_TRAP_POLICER_GET ] = &devl_gen_trap_policer, + [DEVLINK_CMD_SELFTESTS_GET ] = &devl_gen_selftests, };int devlink_instance_iter_dump (struct sk_buff *msg,struct netlink_callback *cb)
Signature · 1 line
2.38.1
Jiri Pirko
maintainerRe: [RFC net-next 04/15] devlink: protect devlink dump by the instance lock
In reply to Jakub KicinskiQuoted 5 lines · Thu, Dec 15, 2022 at 03:01:44AM CET, [email protected] wrote:
Take the instance lock around
devlink_nl_fill()when the dumping. We are only dumping basic info so in the worst case we were only risking data races until now.Signed-off-by Jakub Kicinski <[email protected]>
Should this be a separate patch targeted to -net with proper "fixes" instead?
Jiri Pirko
maintainerRe: [RFC net-next 14/15] devlink: add by-instance dump infra
In reply to Jakub KicinskiQuoted 149 lines · Thu, Dec 15, 2022 at 03:01:54AM CET, [email protected] wrote:
Most dumpit implementations walk the devlink instances. This requires careful lock taking and reference dropping. Factor the loop out and provide just a callback to handle a single instance dump.
Convert one user as an example, other users converted in the next change.
Slightly inspired by ethtool netlink code.
Signed-off-by Jakub Kicinski <[email protected]>---
net/devlink/basic.c | 55 ++++++++++++++++--------------------- net/devlink/devl_internal.h | 10 +++++++ net/devlink/netlink.c | 33 ++++++++++++++++++++++ 3 files changed, 67 insertions(+), 31 deletions(-)net/devlink/basic.c +24
-31@@ -1219,47 +1219,40 @@ static void devlink_rate_notify(struct devlink_rate *devlink_rate, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL); } -static int devlink_nl_cmd_rate_get_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) +static int +devlink_nl_cmd_rate_get_dumpinst (struct sk_buff *msg,struct devlink *devlink, +struct netlink_callback *cb) {struct devlink_nl_dump_state *dump =devl_dump_state (cb); -struct devlink *devlink; +struct devlink_rate *devlink_rate; +int idx =0 ;int err =0 ; -devlink_dump_for_each_instance_get (msg, dump, devlink) { -struct devlink_rate *devlink_rate; -int idx =0 ; - -devl_lock (devlink); -list_for_each_entry (devlink_rate, &devlink->rate_list, list) { -enum devlink_command cmd =DEVLINK_CMD_RATE_NEW ; -u32 id =NETLINK_CB (cb->skb).portid; +list_for_each_entry (devlink_rate, &devlink->rate_list, list) { +enum devlink_command cmd =DEVLINK_CMD_RATE_NEW ; +u32 id =NETLINK_CB (cb->skb).portid; -if (idx < dump->idx) { - idx++; -continue ; - } - err =devlink_nl_rate_fill (msg, devlink_rate, cmd, id, - cb->nlh->nlmsg_seq, -NLM_F_MULTI ,NULL ); -if (err) { -devl_unlock (devlink); -devlink_put (devlink); - dump->idx = idx; - goto out; - } +if (idx < dump->idx) { idx++; +continue ; } -devl_unlock (devlink); -devlink_put (devlink); + err =devlink_nl_rate_fill (msg, devlink_rate, cmd, id, + cb->nlh->nlmsg_seq, +NLM_F_MULTI ,NULL ); +if (err) { + dump->idx = idx; +break ; + } + idx++; } -out: -if (err != -EMSGSIZE ) -return err; -return msg->len; +return err; } +const struct devlink_gen_cmd devl_gen_rate_get = { + .dump_one = devlink_nl_cmd_rate_get_dumpinst, +}; +static int devlink_nl_cmd_rate_get_doit (struct sk_buff *skb,struct genl_info *info) {@@ -9130,7 +9123,7 @@ const struct genl_small_ops devlink_nl_ops[56] = { { .cmd = DEVLINK_CMD_RATE_GET, .doit = devlink_nl_cmd_rate_get_doit, - .dumpit = devlink_nl_cmd_rate_get_dumpit, + .dumpit = devlink_instance_iter_dump, .internal_flags = DEVLINK_NL_FLAG_NEED_RATE, /* can be retrieved by unprivileged users */ },net/devlink/devl_internal.h +8
-0@@ -122,6 +122,11 @@ struct devlink_nl_dump_state { }; }; +struct devlink_gen_cmd { +int (*dump_one)(struct sk_buff *msg,struct devlink *devlink, +struct netlink_callback *cb); +}; +/* Iterate over devlink pointers which were possible to get reference to. * devlink_put() needs to be called for each iterated devlink pointer * in loop body in order to release the reference. @@ -138,6 +143,9 @@ struct devlink *devlink_get_from_attrs(struct net *net, struct nlattr **attrs);void devlink_notify_unregister (struct devlink *devlink);void devlink_notify_register (struct devlink *devlink); +int devlink_instance_iter_dump (struct sk_buff *msg, +struct netlink_callback *cb); +static inline struct
devlink_nl_dump_state*devl_dump_state(struct netlink_callback *cb)
{net/devlink/devl_internal.h +2
-0@@ -173,6 +181,8 @@ devlink_linecard_get_from_info(struct devlink *devlink, struct genl_info *info);void devlink_linecard_put (struct devlink_linecard *linecard);/* Rates */ +extern const struct devlink_gen_cmd devl_gen_rate_get; +struct
devlink_rate*devlink_rate_get_from_info(struct devlink *devlink, struct genl_info *info); structdevlink_rate*net/devlink/netlink.c +1
-0@@ -5,6 +5,7 @@*/ #include <net/genetlink.h> +#include <net/sock.h> #include "devl_internal.h"
net/devlink/netlink.c static void devlink_nl_post_doit(const struct genl_split_ops *ops, · line 183
Quoted 6 lines
net/devlink/netlink.c +3
-0@@ -177,6 +178,38 @@ static void devlink_nl_post_doit(const struct genl_split_ops *ops,devlink_put (devlink); } +static const struct devlink_gen_cmd *devl_gen_cmds[] = { + [DEVLINK_CMD_RATE_GET ] = &devl_gen_rate_get, +};
Instead of having this extra list of ops struct, woudn't it make sence to rather implement this dumpit_one infra directly as a part of generic netlink code? Something like:
{
.cmd = DEVLINK_CMD_RATE_GET,
.doit = devlink_nl_cmd_rate_get_doit, .dumpit_one = devlink_nl_cmd_rate_get_dumpit_one, .dumpit_one_walk = devlink_nl_dumpit_one_walk, .internal_flags = DEVLINK_NL_FLAG_NEED_RATE, /* can be retrieved by unprivileged users */
},
Where devlink_nl_dumpit_one_walk would be basically your devlink_instance_iter_dump(), it would get an extra arg dumpit_one function pointer from generic netlink code to call per item:
int devlink_nl_dumpit_one_walk(struct sk_buff *msg, struct netlink_callback *cb,
int (*dumpit_one)(struct sk_buff *msg,
struct netlink_callback *cb, void *priv));
{
const struct genl_dumpit_info *info = genl_dumpit_info(cb);
struct devlink_nl_dump_state *dump = devl_dump_state(cb);
struct devlink *devlink;
int err = 0;
devlink_dump_for_each_instance_get(msg, dump, devlink) {
devl_lock(devlink);
err = dumpit_one(msg, cb, devlink);
devl_unlock(devlink);
devlink_put(devlink);
if (err)
break;
/* restart sub-object walk for the next instance */
dump->idx = 0;
}
if (err != -EMSGSIZE)
return err;
return msg->len;
}Or we can avoid .dumpit_one_walk() and just have classic .dumpit() which would get the dumpit_one() pointer cb->dumpit_one (obtainable by a helper doing a proper check-warn_on on null).
Quoted 35 lines
net/devlink/netlink.c +29
-0+ +int devlink_instance_iter_dump (struct sk_buff *msg,struct netlink_callback *cb) +{ +const struct genl_dumpit_info *info =genl_dumpit_info (cb); +struct devlink_nl_dump_state *dump =devl_dump_state (cb); +const struct devlink_gen_cmd *cmd; +struct devlink *devlink; +int err =0 ; + + cmd = devl_gen_cmds[info->op.cmd]; + +devlink_dump_for_each_instance_get (msg, dump, devlink) { +devl_lock (devlink); + err = cmd->dump_one (msg, devlink, cb); +devl_unlock (devlink); +devlink_put (devlink); + +if (err) +break ; + +/* restart sub-object walk for the next instance */ + dump->idx =0 ; + } + +if (err != -EMSGSIZE ) +return err; +return msg->len; +} +struct genl_family devlink_nl_family__ro_after_init = { .name =DEVLINK_GENL_NAME , .version =DEVLINK_GENL_VERSION ,Signature · 1 line
2.38.1
Jiri Pirko
maintainerRe: [RFC net-next 01/15] devlink: move code to a dedicated directory
In reply to Jakub KicinskiQuoted 3 lines · Thu, Dec 15, 2022 at 03:01:41AM CET, [email protected] wrote:
The devlink code is hard to navigate with 13kLoC in one file. I really like the way Michal split the ethtool into per-command files and core. It'd probably be too much to split it all up,
Why not? While you are at it, I think that we should split it right away.
Quoted 4 lines
but we can at least separate the core parts out of the per-cmd implementations and put it in a directory so that new commands can be separate files.
Quoted 8 lines
Move the code, subsequent commit will do a partial split.
Signed-off-by Jakub Kicinski <[email protected]>---
net/Makefile | 1 + net/core/Makefile | 1 - net/devlink/Makefile | 3 +++ net/{core/devlink.c => devlink/basic.c} | 0
What's "basic" about it? It sounds a bit misleading.
Quoted 9 lines
4 files changed, 4 insertions(+), 1 deletion(-)create mode 100644
net/devlink/Makefilerenamenet/{core/devlink.c=>devlink/basic.c} (100%)net/Makefile +0
-0@@ -23,6 +23,7 @@ obj-$(CONFIG_BPFILTER) += bpfilter/
Quoted 4 lines
obj-$(CONFIG_PACKET) += packet/
obj-$(CONFIG_NET_KEY) += key/
obj-$(CONFIG_BRIDGE) += bridge/
+obj-$(CONFIG_NET_DEVLINK) += devlink/
Hmm, as devlink is not really designed to be only networking thing, perhaps this is good opportunity to move out of net/ and change the config name to "CONFIG_DEVLINK" ?
Quoted 35 lines
obj-$(CONFIG_NET_DSA) += dsa/
obj-$(CONFIG_ATALK) += appletalk/
obj-$(CONFIG_X25) += x25/net/core/Makefile +0
-0@@ -33,7 +33,6 @@ obj-$(CONFIG_LWTUNNEL) += lwtunnel.oobj-$(CONFIG_LWTUNNEL_BPF) += lwt_bpf.o
obj-$(CONFIG_DST_CACHE) += dst_cache.o
obj-$(CONFIG_HWBM) += hwbm.o
-obj-$(CONFIG_NET_DEVLINK) += devlink.o
obj-$(CONFIG_GRO_CELLS) += gro_cells.o
obj-$(CONFIG_FAILOVER) += failover.o
obj-$(CONFIG_NET_SOCK_MSG) += skmsg.onet/devlink/Makefile new file +3
-0@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y := basic.onet/devlink/basic.c renamed from net/core/devlink.c +0
-0Signature · 2 lines
-- 2.38.1
Jiri Pirko
maintainerRe: [RFC net-next 06/15] devlink: use an explicit structure for dump context
In reply to Jakub KicinskiQuoted 13 lines · Thu, Dec 15, 2022 at 03:01:46AM CET, [email protected] wrote:
Create a dump context structure instead of using
cb->argsas an unsigned long array. This is a pure conversion which is intended to be as much of a noop as possible. Subsequent changes will use this to simplify the code.The two non-trivial parts are:
-devlink_nl_cmd_health_reporter_dump_get_dumpit()checks args[0] to see ifdevlink_fmsg_dumpit()has already been called (whether this is the first msg), but doesn't use the exact value, so we can drop the local variable there already
-devlink_nl_cmd_region_read_dumpit()uses args[0] for address but we'll use args[1] now, shouldn't matter
Quoted 1 line
Signed-off-by Jakub Kicinski <[email protected]>
Neat.
Re: [RFC net-next 01/15] devlink: move code to a dedicated directory
In reply to Jiri PirkoQuoted 8 lines · Jiri Pirko
Quoted 3 lines · Thu, Dec 15, 2022 at 03:01:41AM CET, [email protected] wrote:
The devlink code is hard to navigate with 13kLoC in one file. I really like the way Michal split the ethtool into per-command files and core. It'd probably be too much to split it all up,
Why not? While you are at it, I think that we should split it right away.
From the cover letter it sounds like "not enough time". I like splitting things up but would be fine with just one file per sub object type like one for ports, one for regions, etc.
Thanks,
Jake
Re: [RFC net-next 03/15] devlink: split out netlink code
In reply to Jakub KicinskiQuoted 5 lines · Jakub Kicinski
Move out the netlink glue into a separate file.
Leave the ops in the old file because we'd have to export a ton of functions. Going forward we should switch to split ops which will let us to put the new ops in thenetlink.cfile.
Moving to split ops will also be a requirement for per-op policy right?
Thanks,
Jake
Re: [RFC net-next 06/15] devlink: use an explicit structure for dump context
In reply to Jakub KicinskiQuoted 5 lines · Jakub Kicinski
Create a dump context structure instead of using
cb->argsas an unsigned long array. This is a pure conversion which is intended to be as much of a noop as possible. Subsequent changes will use this to simplify the code.
Quoted 8 lines
The two non-trivial parts are:
-devlink_nl_cmd_health_reporter_dump_get_dumpit()checks args[0] to see ifdevlink_fmsg_dumpit()has already been called (whether this is the first msg), but doesn't use the exact value, so we can drop the local variable there already
-devlink_nl_cmd_region_read_dumpit()uses args[0] for address but we'll use args[1] now, shouldn't matter
And to be clear, the context is not ABI since its not exported outside the kernel. Thus, these changes don't break compatibility with user space.
Re: [RFC net-next 08/15] devlink: drop the filter argument from devlinks_xa_find_get
In reply to Jakub KicinskiQuoted 5 lines · Jakub Kicinski
Looks like
devlinks_xa_find_get()was intended to get the mark from the @filter argument. It doesn't actually use @filter, passingDEVLINK_REGISTEREDtoxa_find_fn()directly. Walking marks other than registered is unlikely so drop @filter argument completely.
Yea, if somehow it ever becomes necessary we can add something back. There are a limited number of marks available anyways.
If it does become necessary we can always refactor this back at that point.
Thanks,
Jake
Re: [RFC net-next 10/15] devlink: restart dump based on devlink instance ids (simple)
In reply to Jakub KicinskiQuoted 8 lines · Jakub Kicinski
xarray gives each devlink instance an id and allows us to restart walk based on that id quite neatly. This is nice both from the perspective of code brevity and from the stability of the dump (devlink instances disappearing from before the resumption point will not cause inconsistent dumps).
This patch takes care of simple cases where
dump->idxcounts devlink instances only.
So with this change for now dump->instance and dump->idx will be identical, but we'll slowly change the meaning of dump->idx with each of the following changes as we expand the user of this macro.
Nice. Keeps it simpler to review. Thanks!
Re: [RFC net-next 14/15] devlink: add by-instance dump infra
In reply to Jakub KicinskiQuoted 10 lines · Jakub Kicinski
Most dumpit implementations walk the devlink instances. This requires careful lock taking and reference dropping. Factor the loop out and provide just a callback to handle a single instance dump.
Convert one user as an example, other users converted in the next change.
Slightly inspired by ethtool netlink code.
This is much nicer! A lot easier to read the dump for one instance than to try and parse out the iterating over each devlink.
Jakub Kicinski
maintainerRe: [RFC net-next 01/15] devlink: move code to a dedicated directory
In reply to Jiri PirkoQuoted 6 lines · On Thu, 15 Dec 2022 10:51:43 +0100 Jiri Pirko wrote:
Quoted 4 lines
net/Makefile | 1 + net/core/Makefile | 1 - net/devlink/Makefile | 3 +++ net/{core/devlink.c => devlink/basic.c} | 0What's "basic" about it? It sounds a bit misleading.
Agreed, but try to suggest a better name ;) the_rest_of_it.c ? :)
Quoted 4 lines
Quoted 4 lines
4 files changed, 4 insertions(+), 1 deletion(-)create mode 100644
net/devlink/Makefilerenamenet/{core/devlink.c=>devlink/basic.c} (100%)
Quoted 13 lines
Quoted 9 lines
net/Makefile +0
-0@@ -23,6 +23,7 @@ obj-$(CONFIG_BPFILTER) += bpfilter/obj-$(CONFIG_PACKET) += packet/
obj-$(CONFIG_NET_KEY) += key/
obj-$(CONFIG_BRIDGE) += bridge/
+obj-$(CONFIG_NET_DEVLINK) += devlink/Hmm, as devlink is not really designed to be only networking thing, perhaps this is good opportunity to move out of
net/and change the config name to "CONFIG_DEVLINK" ?
Nothing against it, but don't think it belongs in this patch. So I call scope creep.
Jakub Kicinski
maintainerRe: [RFC net-next 01/15] devlink: move code to a dedicated directory
In reply to Jacob KellerQuoted 6 lines · On Thu, 15 Dec 2022 10:44:14 -0800 Jacob Keller wrote:
Quoted 5 lines · Jiri Pirko
Quoted 3 lines · Thu, Dec 15, 2022 at 03:01:41AM CET, [email protected] wrote:
The devlink code is hard to navigate with 13kLoC in one file. I really like the way Michal split the ethtool into per-command files and core. It'd probably be too much to split it all up,
Quoted 6 lines
Quoted 2 lines
Why not? While you are at it, I think that we should split it right away.
From the cover letter it sounds like "not enough time". I like
splitting things up but would be fine with just one file per sub object type like one for ports, one for regions, etc.
Indeed, I had to draw the line somewhere. Always plenty of opportunities to reshuffle and improve code which has grown organically over the years. But the sun goes down obsitnately...
Jakub Kicinski
maintainerRe: [RFC net-next 03/15] devlink: split out netlink code
In reply to Jacob KellerQuoted 7 lines · On Thu, 15 Dec 2022 10:45:48 -0800 Jacob Keller wrote:
Quoted 5 lines · Jakub Kicinski
Move out the netlink glue into a separate file.
Leave the ops in the old file because we'd have to export a ton of functions. Going forward we should switch to split ops which will let us to put the new ops in thenetlink.cfile.Moving to split ops will also be a requirement for per-op policy right?
We can mix within one family, tho, IIRC.
So new ops can have their own families and the old ones can stick to the family policy (unless someone takes the risk of converting them).
Jakub Kicinski
maintainerRe: [RFC net-next 04/15] devlink: protect devlink dump by the instance lock
In reply to Jiri PirkoQuoted 7 lines · On Thu, 15 Dec 2022 09:42:27 +0100 Jiri Pirko wrote:
Quoted 3 lines · Thu, Dec 15, 2022 at 03:01:44AM CET, [email protected] wrote:
Take the instance lock around
devlink_nl_fill()when the dumping. We are only dumping basic info so in the worst case we were only risking data races until now.Should this be a separate patch targeted to -net with proper "fixes" instead?
Will do, if nothing else it will make the series smaller :) But TBH I could not spot any issue other than perhaps non-atomic dump of the reload stats, but that's meh..
Jakub Kicinski
maintainerRe: [RFC net-next 06/15] devlink: use an explicit structure for dump context
In reply to Jacob KellerQuoted 2 lines · On Thu, 15 Dec 2022 10:50:11 -0800 Jacob Keller wrote:
And to be clear, the context is not ABI since its not exported outside the kernel. Thus, these changes don't break compatibility with user space.
Yes, indeed.
Re: [RFC net-next 14/15] devlink: add by-instance dump infra
In reply to Jiri PirkoQuoted 52 lines · Jiri Pirko
net/devlink/netlink.c static void devlink_nl_post_doit(const struct genl_split_ops *ops, · line 183
Quoted 4 lines
net/devlink/netlink.c +3
-0+static const struct devlink_gen_cmd *devl_gen_cmds[] = { + [DEVLINK_CMD_RATE_GET ] = &devl_gen_rate_get, +};Instead of having this extra list of ops struct, woudn't it make sence to rather implement this
dumpit_oneinfra directly as a part of generic netlink code? Something like:net/devlink/basic.c +0
-0{ .cmd = DEVLINK_CMD_RATE_GET, .doit = devlink_nl_cmd_rate_get_doit,.dumpit_one =
devlink_nl_cmd_rate_get_dumpit_one, .dumpit_one_walk =devlink_nl_dumpit_one_walk,net/devlink/basic.c +0
-0.internal_flags = DEVLINK_NL_FLAG_NEED_RATE, /* can be retrieved by unprivileged users */ },Where
devlink_nl_dumpit_one_walkwould be basically yourdevlink_instance_iter_dump(), it would get an extra argdumpit_onefunction pointer from generic netlink code to call per item:int devlink_nl_dumpit_one_walk(struct
sk_buff*msg, structnetlink_callback*cb,
int (*dumpit_one)(structsk_buff*msg,
structnetlink_callback*cb, void *priv));{ const struct genl_dumpit_info *info = genl_dumpit_info(cb); struct devlink_nl_dump_state *dump = devl_dump_state(cb); struct devlink *devlink; int err = 0; devlink_dump_for_each_instance_get(msg, dump, devlink) { devl_lock(devlink); err = dumpit_one(msg, cb, devlink); devl_unlock(devlink); devlink_put(devlink); if (err) break; /* restart sub-object walk for the next instance */ dump->idx = 0; } if (err != -EMSGSIZE) return err; return msg->len; }
Quoted 5 lines
Or we can avoid .dumpit_one_walk() and just have classic .dumpit() which would get the
dumpit_one()pointercb->dumpit_one(obtainable by a helper doing a proper check-warn_on on null).
I agree, if we can make this part of the generic netlink code without too much trouble that would be good.
Re: [RFC net-next 01/15] devlink: move code to a dedicated directory
In reply to Jakub KicinskiQuoted 10 lines · Jakub Kicinski
Quoted 6 lines · On Thu, 15 Dec 2022 10:51:43 +0100 Jiri Pirko wrote:
Quoted 4 lines
net/Makefile | 1 + net/core/Makefile | 1 - net/devlink/Makefile | 3 +++ net/{core/devlink.c => devlink/basic.c} | 0What's "basic" about it? It sounds a bit misleading.
Agreed, but try to suggest a better name ;)
the_rest_of_it.c? :)
I tried to think of something, but you already use core elsewhere in the series. If our long term goal really is to split everything out then maybe "leftover.c"? Or just "devlink/devlink.c"
Quoted 18 lines
Quoted 4 lines
Quoted 4 lines
4 files changed, 4 insertions(+), 1 deletion(-)create mode 100644
net/devlink/Makefilerenamenet/{core/devlink.c=>devlink/basic.c} (100%)Quoted 13 lines
Quoted 9 lines
net/Makefile +0
-0@@ -23,6 +23,7 @@ obj-$(CONFIG_BPFILTER) += bpfilter/obj-$(CONFIG_PACKET) += packet/
obj-$(CONFIG_NET_KEY) += key/
obj-$(CONFIG_BRIDGE) += bridge/
+obj-$(CONFIG_NET_DEVLINK) += devlink/Hmm, as devlink is not really designed to be only networking thing, perhaps this is good opportunity to move out of
net/and change the config name to "CONFIG_DEVLINK" ?
Quoted 2 lines
Nothing against it, but don't think it belongs in this patch. So I call scope creep.
Right. I think this patch set focusing on just the iteration for dumping is good.
Re: [RFC net-next 03/15] devlink: split out netlink code
In reply to Jakub KicinskiQuoted 7 lines · Jakub Kicinski
Quoted 6 lines · On Thu, 15 Dec 2022 10:45:48 -0800 Jacob Keller wrote:
Quoted 5 lines · Jakub Kicinski
Move out the netlink glue into a separate file.
Leave the ops in the old file because we'd have to export a ton of functions. Going forward we should switch to split ops which will let us to put the new ops in thenetlink.cfile.
Quoted 5 lines
Quoted 1 line
Moving to split ops will also be a requirement for per-op policy right?
We can mix within one family, tho, IIRC.
So new ops can have their own families and the old ones can stick to the family policy (unless someone takes the risk of converting them).
I would like to convert them at some point, even if we leave the old commands as non-strict. Either way I think it would be preferable to begin enforcing that new ops must be strict and must be per-op policy.
I personally think that moving from non-strict to strict should be ok especially if we plan it over a few releases. A sane user space application would generally prefer to be told "this is unacceptable" rather than have the wrong operation done, or have its attributes silently ignored... but I can understand the argument against breaking user space that used to work.
Quoted 18 lines · Jakub Kicinski
Hi!
I started working on the refcounting / registration changes and (as is usual in our profession) I quickly veered off into refactoring / paying technical debt. I hope this is not too controversial.
===
Split
devlink.cinto a handful of files, trying to keep the "core" code away from all the command-specific implementations. The core code has been quite scattered before. Going forward we can consider using a source file per-subobject, I think that it's quite beneficial to newcomers (based on relative ease with which folks contribute to ethtool vs devlink). But this series doesn't split everything out, yet - partially due to backporting concerns, but mostly due to lack of time.
Quoted 9 lines
Introduce a context structure for dumps, and use it to store the devlink instance ID of the last dumped devlink instance. This means we don't have to restart the walk from 0 each time.
Finally - introduce a "structured walk". A centralized dump handler in
devlink/netlink.cwhich walks the devlink instances, deals with refcounting/locking, simplifying the per-object implementations quite a bit.
I'm fine with the series as-is.
Moving the dumpit_one thing into generic netlink files seems ok, but I trust you may have already thought about and decided it was too devlink specific.
Thanks,
Jake
Jakub Kicinski
maintainerRe: [RFC net-next 14/15] devlink: add by-instance dump infra
In reply to Jiri PirkoQuoted 3 lines · On Thu, 15 Dec 2022 10:11:03 +0100 Jiri Pirko wrote:
Instead of having this extra list of ops struct, woudn't it make sence to rather implement this
dumpit_oneinfra directly as a part of generic netlink code?
I was wondering about that, but none of the ideas were sufficiently neat to implement :( There's a lot of improvements that can be done in the core, starting with making more of the info structures shared between do and dump in genl :(
net/devlink/basic.c const struct genl_small_ops devlink_nl_ops[56] = { · line 9129
Quoted 10 lines
Something like:
net/devlink/basic.c +0
-0{ .cmd = DEVLINK_CMD_RATE_GET, .doit = devlink_nl_cmd_rate_get_doit,.dumpit_one =
devlink_nl_cmd_rate_get_dumpit_one, .dumpit_one_walk =devlink_nl_dumpit_one_walk,net/devlink/basic.c +0
-0.internal_flags = DEVLINK_NL_FLAG_NEED_RATE, /* can be retrieved by unprivileged users */ },
Growing the struct ops (especially the one called _small_) may be a hard sale for a single user. For split ops, it's a different story, because we can possibly have a flag that changes the interpretation of the union. Maybe.
I'd love to have a way of breaking down the ops so that we can factor out the filling of the message (the code that is shared between doit and dump). Just for the walk I don't think it's worth it.
I went in the same direction as ethtool because if over time we arrive at a similar structure we can use that as a corner stone.
All in all, I think this patch is a reasonable step forward. But definitely agree that the genl infra is still painfully basic.
Jakub Kicinski
maintainerRe: [RFC net-next 01/15] devlink: move code to a dedicated directory
In reply to Jacob KellerQuoted 7 lines · On Thu, 15 Dec 2022 11:29:02 -0800 Jacob Keller wrote:
Quoted 3 lines
Quoted 1 line
What's "basic" about it? It sounds a bit misleading.
Agreed, but try to suggest a better name ;)
the_rest_of_it.c? :)I tried to think of something, but you already use core elsewhere in the series. If our long term goal really is to split everything out then maybe "
leftover.c"? Or just "devlink/devlink.c"
leftover.c is fine by me. Jiri?
Jiri Pirko
maintainerRe: [RFC net-next 01/15] devlink: move code to a dedicated directory
Quoted 10 lines · Thu, Dec 15, 2022 at 08:48:29PM CET, [email protected] wrote:
Quoted 7 lines · On Thu, 15 Dec 2022 11:29:02 -0800 Jacob Keller wrote:
Quoted 3 lines
Quoted 1 line
What's "basic" about it? It sounds a bit misleading.
Agreed, but try to suggest a better name ;)
the_rest_of_it.c? :)I tried to think of something, but you already use core elsewhere in the series. If our long term goal really is to split everything out then maybe "
leftover.c"? Or just "devlink/devlink.c"
leftover.cis fine by me. Jiri?
If the goal is to remove the file entirely eventually, I'm okay with that.
Jiri Pirko
maintainerRe: [RFC net-next 01/15] devlink: move code to a dedicated directory
In reply to Jakub KicinskiQuoted 28 lines · Thu, Dec 15, 2022 at 08:09:25PM CET, [email protected] wrote:
Quoted 6 lines · On Thu, 15 Dec 2022 10:51:43 +0100 Jiri Pirko wrote:
Quoted 4 lines
net/Makefile | 1 + net/core/Makefile | 1 - net/devlink/Makefile | 3 +++ net/{core/devlink.c => devlink/basic.c} | 0What's "basic" about it? It sounds a bit misleading.
Agreed, but try to suggest a better name ;)
the_rest_of_it.c? :)Quoted 4 lines
Quoted 4 lines
4 files changed, 4 insertions(+), 1 deletion(-)create mode 100644
net/devlink/Makefilerenamenet/{core/devlink.c=>devlink/basic.c} (100%)Quoted 13 lines
Quoted 9 lines
net/Makefile +0
-0@@ -23,6 +23,7 @@ obj-$(CONFIG_BPFILTER) += bpfilter/obj-$(CONFIG_PACKET) += packet/
obj-$(CONFIG_NET_KEY) += key/
obj-$(CONFIG_BRIDGE) += bridge/
+obj-$(CONFIG_NET_DEVLINK) += devlink/Hmm, as devlink is not really designed to be only networking thing, perhaps this is good opportunity to move out of
net/and change the config name to "CONFIG_DEVLINK" ?
Quoted 2 lines
Nothing against it, but don't think it belongs in this patch. So I call scope creep.
Yeah, but I mean, since you move it from /net/core to /net/, why not just move it to / ?
Jiri Pirko
maintainerRe: [RFC net-next 14/15] devlink: add by-instance dump infra
In reply to Jakub KicinskiQuoted 21 lines · Thu, Dec 15, 2022 at 08:47:06PM CET, [email protected] wrote:
Quoted 3 lines · On Thu, 15 Dec 2022 10:11:03 +0100 Jiri Pirko wrote:
Instead of having this extra list of ops struct, woudn't it make sence to rather implement this
dumpit_oneinfra directly as a part of generic netlink code?I was wondering about that, but none of the ideas were sufficiently neat to implement :( There's a lot of improvements that can be done in the core, starting with making more of the info structures shared between do and dump in genl :(
net/devlink/basic.c const struct genl_small_ops devlink_nl_ops[56] = { · line 9129
Quoted 10 lines
Something like:
net/devlink/basic.c +0
-0{ .cmd = DEVLINK_CMD_RATE_GET, .doit = devlink_nl_cmd_rate_get_doit,.dumpit_one =
devlink_nl_cmd_rate_get_dumpit_one, .dumpit_one_walk =devlink_nl_dumpit_one_walk,net/devlink/basic.c +0
-0.internal_flags = DEVLINK_NL_FLAG_NEED_RATE, /* can be retrieved by unprivileged users */ },
Quoted 8 lines
Growing the struct ops (especially the one called _small_) may be a hard sale for a single user. For split ops, it's a different story, because we can possibly have a flag that changes the interpretation of the union. Maybe.
I'd love to have a way of breaking down the ops so that we can factor out the filling of the message (the code that is shared between doit and dump). Just for the walk I don't think it's worth it.
Okay, that is something I thought about as well. Let me take a stab at it.
Quoted 5 lines
I went in the same direction as ethtool because if over time we arrive at a similar structure we can use that as a corner stone.
All in all, I think this patch is a reasonable step forward.
Yeah, could be always changed...
Quoted 1 line
But definitely agree that the genl infra is still painfully basic.
Jakub Kicinski
maintainerRe: [RFC net-next 01/15] devlink: move code to a dedicated directory
In reply to Jiri PirkoQuoted 9 lines · On Fri, 16 Dec 2022 10:10:41 +0100 Jiri Pirko wrote:
Quoted 6 lines
Quoted 3 lines
Hmm, as devlink is not really designed to be only networking thing, perhaps this is good opportunity to move out of
net/and change the config name to "CONFIG_DEVLINK" ?Nothing against it, but don't think it belongs in this patch. So I call scope creep.
Yeah, but I mean, since you move it from /net/core to /net/, why not just move it to / ?
It still needs to depend on NET for sockets, right?
Re: [RFC net-next 01/15] devlink: move code to a dedicated directory
Quoted 5 lines · Jakub Kicinski
Quoted 4 lines · On Fri, 16 Dec 2022 10:10:41 +0100 Jiri Pirko wrote:
Quoted 4 lines
Quoted 3 lines
Hmm, as devlink is not really designed to be only networking thing, perhaps this is good opportunity to move out of
net/and change the config name to "CONFIG_DEVLINK" ?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Nothing against it, but don't think it belongs in this patch. So I call scope creep.
Yeah, but I mean, since you move it from /net/core to /net/, why not just move it to / ?
It still needs to depend on NET for sockets, right?
Its going to depend on whatever Generic Netlink depends on yea.