Skip to contentSkip to conversation

devlink: use spec to generate split ops

PATCH Superseded Jiri Pirko 2 participants 16 messages Aug 2, 2023 – Aug 3, 2023

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jiri Pirko

author maintainer
#0 lore raw

v2 cover devlink: use spec to generate split ops

From: Jiri Pirko <[email protected]>

This is an outcome of the discussion in the following thread:
https://lore.kernel.org/netdev/[email protected]/
It serves as a dependency on the linked selector patchset.

There is an existing spec for devlink used for userspace part generation. There are two commands supported there.

This patchset extends the spec so kernel split ops code could be generated from it.

---
v1->v2:
- see individual patches for changelog

Jiri Pirko (11):
netlink: specs: add dump-strict flag for dont-validate property ynl-gen-c.py: filter rendering of validate field values for split ops ynl-gen-c.py: allow directional model for kernel mode ynl-gen-c.py: render netlink policies static for split ops
devlink: rename devlink_nl_ops to devlink_nl_small_ops
netlink: specs: devlink: add info-get dump op
devlink: add split ops generated according to spec
devlink: include the generated netlink header
devlink: rename couple of doit netlink callbacks to match generated
names
devlink: introduce couple of dumpit callbacks for split ops
devlink: use generated split ops and remove duplicated commands from
small ops

 Documentation/netlink/genetlink-c.yaml      |  2 +-
 Documentation/netlink/genetlink-legacy.yaml |  2 +-
 Documentation/netlink/genetlink.yaml        |  2 +-
 Documentation/netlink/specs/devlink.yaml    | 14 ++++-
 net/devlink/Makefile                        |  2 +-
 net/devlink/dev.c                           | 27 +++++-----
 net/devlink/devl_internal.h                 | 20 +++----
 net/devlink/leftover.c                      | 16 +-----
 net/devlink/netlink.c                       | 35 ++++++------
 net/devlink/netlink_gen.c                   | 59 +++++++++++++++++++++
 net/devlink/netlink_gen.h                   | 29 ++++++++++
 tools/net/ynl/generated/devlink-user.c      | 53 ++++++++++++++++++
 tools/net/ynl/generated/devlink-user.h      | 10 ++++
 tools/net/ynl/ynl-gen-c.py                  | 20 +++++--
 14 files changed, 231 insertions(+), 60 deletions(-)
 create mode 100644 net/devlink/netlink_gen.c
 create mode 100644 net/devlink/netlink_gen.h
Signature · 1 line
2.41.0
author maintainer
#1 lore raw

PATCH v2 1/11 netlink: specs: add dump-strict flag for dont-validate property

From: Jiri Pirko <[email protected]>

Allow user to specify GENL_DONT_VALIDATE_DUMP_STRICT flag for validation and add this flag to netlink spec schema.

---
v1->v2:
- new patch

---
 Documentation/netlink/genetlink-c.yaml      | 2 +-
 Documentation/netlink/genetlink-legacy.yaml | 2 +-
 Documentation/netlink/genetlink.yaml        | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
Documentation/netlink/genetlink-c.yaml +1 -1
index 57d1c1c4918f..4c1f8c22627b 100644
@@ -274,7 +274,7 @@ properties:
               description: Kernel attribute validation flags.
               type: array
               items:
-                enum: [ strict, dump ]
+                enum: [ strict, dump, dump-strict ]
             do: &subop-type
               description: Main command handler.
               type: object
Documentation/netlink/genetlink-legacy.yaml +1 -1
index 43b769c98fb2..196076dfa309 100644
@@ -321,7 +321,7 @@ properties:
               description: Kernel attribute validation flags.
               type: array
               items:
-                enum: [ strict, dump ]
+                enum: [ strict, dump, dump-strict ]
             # Start genetlink-legacy
             fixed-header: *fixed-header
             # End genetlink-legacy
Documentation/netlink/genetlink.yaml +1 -1
index 1cbb448d2f1c..3d338c48bf21 100644
@@ -243,7 +243,7 @@ properties:
               description: Kernel attribute validation flags.
               type: array
               items:
-                enum: [ strict, dump ]
+                enum: [ strict, dump, dump-strict ]
             do: &subop-type
               description: Main command handler.
               type: object
Signature · 1 line
2.41.0
author maintainer
#2 lore raw

PATCH v2 2/11 ynl-gen-c.py: filter rendering of validate field values for split ops

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

For split ops, do and dump has different meaningful values in validate field.

Fix the rendering to allow the values per op type as follows:
do: strict
dump: dump, strict-dump

---
v1->v2:
- consider strict-dump flag newly added by the previous patch
- re-phrased the commit message, altered the patch subject a bit

---
 tools/net/ynl/ynl-gen-c.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
tools/net/ynl/ynl-gen-c.py +9 -1
index 650be9b8b693..a3f70ca929fb 100755
@@ -1988,9 +1988,17 @@ def print_kernel_op_table(family, cw):
                 cw.block_start()
                 members = [('cmd', op.enum_name)]
                 if 'dont-validate' in op:
+                    dont_validate = []
+                    for x in op['dont-validate']:
+                        if op_mode == 'do' and x in ['dump', 'dump-strict']:
+                            continue
+                        if op_mode == "dump" and x == 'strict':
+                            continue
+                        dont_validate.append(x)
+
                     members.append(('validate',
                                     ' | '.join([c_upper('genl-dont-validate-' + x)
-                                                for x in op['dont-validate']])), )
+                                                for x in dont_validate])), )
                 name = c_lower(f"{family.name}-nl-{op_name}-{op_mode}it")
                 if 'pre' in op[op_mode]:
                     members.append((cb_names[op_mode]['pre'], c_lower(op[op_mode]['pre'])))
Signature · 1 line
2.41.0
author maintainer
#3 lore raw

PATCH v2 3/11 ynl-gen-c.py: allow directional model for kernel mode

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Directional model limitation is only applicable for uapi mode. For kernel mode, the code is generated correctly using right cmd values for do/dump requests. Lift the limitation.

---
v1->v2:
- re-phrased the patch description

---
 tools/net/ynl/ynl-gen-c.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/net/ynl/ynl-gen-c.py +1 -1
index a3f70ca929fb..34ee7b8e3f71 100755
@@ -2317,7 +2317,7 @@ def main():
         return
 
     supported_models = ['unified']
-    if args.mode == 'user':
+    if args.mode in  ['user', 'kernel']:
         supported_models += ['directional']
     if parsed.msg_id_model not in supported_models:
         print(f'Message enum-model {parsed.msg_id_model} not supported for {args.mode} generation')
Signature · 1 line
2.41.0
maintainer
#4 lore raw

Re: [patch net-next v2 03/11] ynl-gen-c.py: allow directional model for kernel mode

tools/net/ynl/ynl-gen-c.py def main(): · line 2320

Quoted 3 lines · On Wed, 2 Aug 2023 17:20:15 +0200 Jiri Pirko wrote:

supported_models = ['unified']

tools/net/ynl/ynl-gen-c.py +1 -1
-    if args.mode == 'user':
+    if args.mode in  ['user', 'kernel']:

nit: double space after "in"

Quoted 1 line
         supported_models += ['directional']
author maintainer
#5 lore raw

PATCH v2 4/11 ynl-gen-c.py: render netlink policies static for split ops

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

When policies are rendered for split ops, they are consumed in the same file. No need to expose them for user outside, make them static.

---
v1->v2:
- new patch

---
 tools/net/ynl/ynl-gen-c.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/net/ynl/ynl-gen-c.py +6 -2
index 34ee7b8e3f71..d0753cb39901 100755
@@ -1843,13 +1843,13 @@ def print_ntf_type_free(ri):
 
 
 def print_req_policy_fwd(cw, struct, ri=None, terminate=True):
-    if terminate and ri and kernel_can_gen_family_struct(struct.family):
+    if terminate and ri and policy_should_be_static(struct.family):
         return
 
     if terminate:
         prefix = 'extern '
     else:
-        if kernel_can_gen_family_struct(struct.family) and ri:
+        if ri and policy_should_be_static(struct.family):
             prefix = 'static '
         else:
             prefix = ''
@@ -1877,6 +1877,10 @@ def kernel_can_gen_family_struct(family):
     return family.proto == 'genetlink'
 
 
+def policy_should_be_static(family):
+    return family.kernel_policy == 'split' or kernel_can_gen_family_struct(family)
+
+
 def print_kernel_op_table_fwd(family, cw, terminate):
     exported = not kernel_can_gen_family_struct(family)
 
Signature · 1 line
2.41.0
author maintainer
#6 lore raw

PATCH v2 5/11 devlink: rename devlink_nl_ops to devlink_nl_small_ops

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

In order to avoid name collision with the generated split ops array which is going to be introduced as a follow-up patch, rename the existing ops array to devlink_nl_small_ops.

---
 net/devlink/devl_internal.h | 2 +-
 net/devlink/leftover.c      | 2 +-
 net/devlink/netlink.c       | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
net/devlink/devl_internal.h +1 -1
index 62921b2eb0d3..c67f074641d4 100644
@@ -119,7 +119,7 @@ struct devlink_cmd {
 			struct netlink_callback *cb);
 };
 
-extern const struct genl_small_ops devlink_nl_ops[56];
+extern const struct genl_small_ops devlink_nl_small_ops[56];
 
 struct devlink *
 devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs);
net/devlink/leftover.c +1 -1
index 5128b9c7eea8..8f42f1f45705 100644
@@ -6278,7 +6278,7 @@ static int devlink_nl_cmd_trap_policer_set_doit(struct sk_buff *skb,
 	return devlink_trap_policer_set(devlink, policer_item, info);
 }
 
-const struct genl_small_ops devlink_nl_ops[56] = {
+const struct genl_small_ops devlink_nl_small_ops[56] = {
 	{
 		.cmd = DEVLINK_CMD_GET,
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/devlink/netlink.c +2 -2
index 7a332eb70f70..82a3238d5344 100644
@@ -243,8 +243,8 @@ struct genl_family devlink_nl_family __ro_after_init = {
 	.pre_doit	= devlink_nl_pre_doit,
 	.post_doit	= devlink_nl_post_doit,
 	.module		= THIS_MODULE,
-	.small_ops	= devlink_nl_ops,
-	.n_small_ops	= ARRAY_SIZE(devlink_nl_ops),
+	.small_ops	= devlink_nl_small_ops,
+	.n_small_ops	= ARRAY_SIZE(devlink_nl_small_ops),
 	.resv_start_op	= DEVLINK_CMD_SELFTESTS_RUN + 1,
 	.mcgrps		= devlink_nl_mcgrps,
 	.n_mcgrps	= ARRAY_SIZE(devlink_nl_mcgrps),
Signature · 1 line
2.41.0
author maintainer
#7 lore raw

PATCH v2 6/11 netlink: specs: devlink: add info-get dump op

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Add missing dump op for info-get command and re-generate related devlink-user.[ch] code.

---
v1->v2:
- new patch, spec split from the next one, adding forgotten changes in devlink-user.[ch] code

---
 Documentation/netlink/specs/devlink.yaml |  4 +-
 tools/net/ynl/generated/devlink-user.c   | 53 ++++++++++++++++++++++++
 tools/net/ynl/generated/devlink-user.h   | 10 +++++
 3 files changed, 66 insertions(+), 1 deletion(-)
Documentation/netlink/specs/devlink.yaml +3 -1
index 5d46ca966979..12699b7ce292 100644
@@ -194,7 +194,7 @@ operations:
         request:
           value: 51
           attributes: *dev-id-attrs
-        reply:
+        reply: &info-get-reply
           value: 51
           attributes:
             - bus-name
@@ -204,3 +204,5 @@ operations:
             - info-version-fixed
             - info-version-running
             - info-version-stored
+      dump:
+        reply: *info-get-reply
tools/net/ynl/generated/devlink-user.c +53 -0

59 lines not on this page · raw message

tools/net/ynl/generated/devlink-user.h +10 -0
index a008b99b6e24..af65e2f2f529 100644
@@ -207,4 +207,14 @@ void devlink_info_get_rsp_free(struct devlink_info_get_rsp *rsp);
 struct devlink_info_get_rsp *
 devlink_info_get(struct ynl_sock *ys, struct devlink_info_get_req *req);
 
+/* DEVLINK_CMD_INFO_GET - dump */
+struct devlink_info_get_list {
+	struct devlink_info_get_list *next;
+	struct devlink_info_get_rsp obj __attribute__ ((aligned (8)));
+};
+
+void devlink_info_get_list_free(struct devlink_info_get_list *rsp);
+
+struct devlink_info_get_list *devlink_info_get_dump(struct ynl_sock *ys);
+
 #endif /* _LINUX_DEVLINK_GEN_H */
Signature · 1 line
2.41.0
author maintainer
#8 lore raw

PATCH v2 7/11 devlink: add split ops generated according to spec

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Improve the existing devlink spec in order to serve as a source for generation of valid devlink split ops for the existing commands. Add the generated sources.

Node that the policies are narrowed down only to the attributes that are actually parsed. The dont-validate-strict parsing policy makes sure that other possibly passed garbage attributes from userspace are ignored during validation.

---
v1->v2:
- fixed "for" typo
- added note to patch description about narrowing down the policy
- moved info-get dump op addition to a separate patch
- regenerated files according to static policies change

---
 Documentation/netlink/specs/devlink.yaml | 10 ++++
 net/devlink/Makefile                     |  2 +-
 net/devlink/netlink_gen.c                | 59 ++++++++++++++++++++++++
 net/devlink/netlink_gen.h                | 29 ++++++++++++
 4 files changed, 99 insertions(+), 1 deletion(-)
 create mode 100644 net/devlink/netlink_gen.c
 create mode 100644 net/devlink/netlink_gen.h
Documentation/netlink/specs/devlink.yaml +10 -0
index 12699b7ce292..f6df0b3fd502 100644
@@ -165,8 +165,13 @@ operations:
       name: get
       doc: Get devlink instances.
       attribute-set: devlink
+      dont-validate:
+        - strict
+        - dump
 
       do:
+        pre: devlink-nl-pre-doit
+        post: devlink-nl-post-doit
         request:
           value: 1
           attributes: &dev-id-attrs
@@ -189,8 +194,13 @@ operations:
       name: info-get
       doc: Get device information, like driver name, hardware and firmware versions etc.
       attribute-set: devlink
+      dont-validate:
+        - strict
+        - dump
 
       do:
+        pre: devlink-nl-pre-doit
+        post: devlink-nl-post-doit
         request:
           value: 51
           attributes: *dev-id-attrs
net/devlink/Makefile +1 -1
index ef91a76646a3..a087af581847 100644
@@ -1,3 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0
 
-obj-y := leftover.o core.o netlink.o dev.o health.o
+obj-y := leftover.o core.o netlink.o netlink_gen.o dev.o health.o
net/devlink/netlink_gen.c new file +59 -0

59 lines not on this page · raw message

net/devlink/netlink_gen.h new file +29 -0
new file mode 100644
index 000000000000..11980e04a718
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
+/* Do not edit directly, auto-generated from: */
+/*	Documentation/netlink/specs/devlink.yaml */
+/* YNL-GEN kernel header */
+
+#ifndef _LINUX_DEVLINK_GEN_H
+#define _LINUX_DEVLINK_GEN_H
+
+#include <net/netlink.h>
+#include <net/genetlink.h>
+
+#include <uapi/linux/devlink.h>
+
+/* Ops table for devlink */
+extern const struct genl_split_ops devlink_nl_ops[4];
+
+int devlink_nl_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb,
+			struct genl_info *info);
+void
+devlink_nl_post_doit(const struct genl_split_ops *ops, struct sk_buff *skb,
+		     struct genl_info *info);
+
+int devlink_nl_get_doit(struct sk_buff *skb, struct genl_info *info);
+int devlink_nl_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
+int devlink_nl_info_get_doit(struct sk_buff *skb, struct genl_info *info);
+int devlink_nl_info_get_dumpit(struct sk_buff *skb,
+			       struct netlink_callback *cb);
+
+#endif /* _LINUX_DEVLINK_GEN_H */
Signature · 1 line
2.41.0
author maintainer
#9 lore raw

PATCH v2 8/11 devlink: include the generated netlink header

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Put the newly added generated header to the include list. Un-static the pre-doit and post-doit functions as they are used in the generated files.

---
 net/devlink/devl_internal.h | 2 ++
 net/devlink/netlink.c       | 8 ++++----
 2 files changed, 6 insertions(+), 4 deletions(-)
net/devlink/devl_internal.h +2 -0
index c67f074641d4..f5ad66d5773c 100644
@@ -12,6 +12,8 @@
 #include <net/devlink.h>
 #include <net/net_namespace.h>
 
+#include "netlink_gen.h"
+
 #define DEVLINK_REGISTERED XA_MARK_1
 
 #define DEVLINK_RELOAD_STATS_ARRAY_SIZE \
net/devlink/netlink.c +4 -4
index 82a3238d5344..39e07a5a69af 100644
@@ -109,8 +109,8 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs)
 	return ERR_PTR(-ENODEV);
 }
 
-static int devlink_nl_pre_doit(const struct genl_split_ops *ops,
-			       struct sk_buff *skb, struct genl_info *info)
+int devlink_nl_pre_doit(const struct genl_split_ops *ops,
+			struct sk_buff *skb, struct genl_info *info)
 {
 	struct devlink_linecard *linecard;
 	struct devlink_port *devlink_port;
@@ -167,8 +167,8 @@ static int devlink_nl_pre_doit(const struct genl_split_ops *ops,
 	return err;
 }
 
-static void devlink_nl_post_doit(const struct genl_split_ops *ops,
-				 struct sk_buff *skb, struct genl_info *info)
+void devlink_nl_post_doit(const struct genl_split_ops *ops,
+			  struct sk_buff *skb, struct genl_info *info)
 {
 	struct devlink *devlink;
 
Signature · 1 line
2.41.0
author maintainer
#10 lore raw

PATCH v2 9/11 devlink: rename couple of doit netlink callbacks to match generated names

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

The generated names of the doit netlink callback are missing "cmd" in their names. Fix the names and remove the original prototypes.

---
 net/devlink/dev.c           | 4 ++--
 net/devlink/devl_internal.h | 2 --
 net/devlink/leftover.c      | 4 ++--
 3 files changed, 4 insertions(+), 6 deletions(-)
net/devlink/dev.c +2 -2
index bf1d6f1bcfc7..2e120b3da220 100644
@@ -196,7 +196,7 @@ void devlink_notify(struct devlink *devlink, enum devlink_command cmd)
 				msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL);
 }
 
-int devlink_nl_cmd_get_doit(struct sk_buff *skb, struct genl_info *info)
+int devlink_nl_get_doit(struct sk_buff *skb, struct genl_info *info)
 {
 	struct devlink *devlink = info->user_ptr[0];
 	struct sk_buff *msg;
@@ -804,7 +804,7 @@ devlink_nl_info_fill(struct sk_buff *msg, struct devlink *devlink,
 	return err;
 }
 
-int devlink_nl_cmd_info_get_doit(struct sk_buff *skb, struct genl_info *info)
+int devlink_nl_info_get_doit(struct sk_buff *skb, struct genl_info *info)
 {
 	struct devlink *devlink = info->user_ptr[0];
 	struct sk_buff *msg;
net/devlink/devl_internal.h +0 -2
index f5ad66d5773c..419bc92da503 100644
@@ -216,11 +216,9 @@ struct devlink_rate *
 devlink_rate_node_get_from_info(struct devlink *devlink,
 				struct genl_info *info);
 /* Devlink nl cmds */
-int devlink_nl_cmd_get_doit(struct sk_buff *skb, struct genl_info *info);
 int devlink_nl_cmd_reload(struct sk_buff *skb, struct genl_info *info);
 int devlink_nl_cmd_eswitch_get_doit(struct sk_buff *skb, struct genl_info *info);
 int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb, struct genl_info *info);
-int devlink_nl_cmd_info_get_doit(struct sk_buff *skb, struct genl_info *info);
 int devlink_nl_cmd_flash_update(struct sk_buff *skb, struct genl_info *info);
 int devlink_nl_cmd_selftests_get_doit(struct sk_buff *skb, struct genl_info *info);
 int devlink_nl_cmd_selftests_run(struct sk_buff *skb, struct genl_info *info);
net/devlink/leftover.c +2 -2
index 8f42f1f45705..094cd0e8224e 100644
@@ -6282,7 +6282,7 @@ const struct genl_small_ops devlink_nl_small_ops[56] = {
 	{
 		.cmd = DEVLINK_CMD_GET,
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
-		.doit = devlink_nl_cmd_get_doit,
+		.doit = devlink_nl_get_doit,
 		.dumpit = devlink_nl_instance_iter_dumpit,
 		/* can be retrieved by unprivileged users */
 	},
@@ -6536,7 +6536,7 @@ const struct genl_small_ops devlink_nl_small_ops[56] = {
 	{
 		.cmd = DEVLINK_CMD_INFO_GET,
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
-		.doit = devlink_nl_cmd_info_get_doit,
+		.doit = devlink_nl_info_get_doit,
 		.dumpit = devlink_nl_instance_iter_dumpit,
 		/* can be retrieved by unprivileged users */
 	},
Signature · 1 line
2.41.0
author maintainer
#11 lore raw

PATCH v2 10/11 devlink: introduce couple of dumpit callbacks for split ops

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Introduce couple of dumpit callbacks for generated split ops. Have them as a thin wrapper around iteration function and allow to pass dump_one() function pointer directly without need to store in devlink_cmd structs.

---
v1->v2:
- fixed typo in patch subject

---
 net/devlink/dev.c           | 23 +++++++++++++----------
 net/devlink/devl_internal.h | 14 ++++++++------
 net/devlink/leftover.c      |  4 ++--
 net/devlink/netlink.c       | 21 ++++++++++++---------
 4 files changed, 35 insertions(+), 27 deletions(-)
net/devlink/dev.c +13 -10
index 2e120b3da220..1782157351ed 100644
@@ -217,17 +217,19 @@ int devlink_nl_get_doit(struct sk_buff *skb, struct genl_info *info)
 }
 
 static int
-devlink_nl_cmd_get_dump_one(struct sk_buff *msg, struct devlink *devlink,
-			    struct netlink_callback *cb)
+devlink_nl_get_dump_one(struct sk_buff *msg, struct devlink *devlink,
+			struct netlink_callback *cb)
 {
 	return devlink_nl_fill(msg, devlink, DEVLINK_CMD_NEW,
 			       NETLINK_CB(cb->skb).portid,
 			       cb->nlh->nlmsg_seq, NLM_F_MULTI);
 }
 
-const struct devlink_cmd devl_cmd_get = {
-	.dump_one		= devlink_nl_cmd_get_dump_one,
-};
+int devlink_nl_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)
+{
+	return devlink_nl_dumpit(msg, cb, devlink_nl_get_dump_one);
+}
+
 
 static void devlink_reload_failed_set(struct devlink *devlink,
 				      bool reload_failed)
@@ -826,8 +828,8 @@ int devlink_nl_info_get_doit(struct sk_buff *skb, struct genl_info *info)
 }
 
 static int
-devlink_nl_cmd_info_get_dump_one(struct sk_buff *msg, struct devlink *devlink,
-				 struct netlink_callback *cb)
+devlink_nl_info_get_dump_one(struct sk_buff *msg, struct devlink *devlink,
+			     struct netlink_callback *cb)
 {
 	int err;
 
@@ -840,9 +842,10 @@ devlink_nl_cmd_info_get_dump_one(struct sk_buff *msg, struct devlink *devlink,
 	return err;
 }
 
-const struct devlink_cmd devl_cmd_info_get = {
-	.dump_one		= devlink_nl_cmd_info_get_dump_one,
-};
+int devlink_nl_info_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)
+{
+	return devlink_nl_dumpit(msg, cb, devlink_nl_info_get_dump_one);
+}
 
 static int devlink_nl_flash_update_fill(struct sk_buff *msg,
 					struct devlink *devlink,
net/devlink/devl_internal.h +8 -6
index 419bc92da503..51de0e1fc769 100644
@@ -116,9 +116,12 @@ struct devlink_nl_dump_state {
 	};
 };
 
+typedef int devlink_nl_dump_one_func_t(struct sk_buff *msg,
+				       struct devlink *devlink,
+				       struct netlink_callback *cb);
+
 struct devlink_cmd {
-	int (*dump_one)(struct sk_buff *msg, struct devlink *devlink,
-			struct netlink_callback *cb);
+	devlink_nl_dump_one_func_t *dump_one;
 };
 
 extern const struct genl_small_ops devlink_nl_small_ops[56];
@@ -129,8 +132,9 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs);
 void devlink_notify_unregister(struct devlink *devlink);
 void devlink_notify_register(struct devlink *devlink);
 
-int devlink_nl_instance_iter_dumpit(struct sk_buff *msg,
-				    struct netlink_callback *cb);
+int devlink_nl_dumpit(struct sk_buff *msg, struct netlink_callback *cb,
+		      devlink_nl_dump_one_func_t *dump_one);
+int devlink_nl_instance_iter_dumpit(struct sk_buff *msg, struct netlink_callback *cb);
 
 static inline struct devlink_nl_dump_state *
 devlink_dump_state(struct netlink_callback *cb)
@@ -151,7 +155,6 @@ devlink_nl_put_handle(struct sk_buff *msg, struct devlink *devlink)
 }
 
 /* Commands */
-extern const struct devlink_cmd devl_cmd_get;
 extern const struct devlink_cmd devl_cmd_port_get;
 extern const struct devlink_cmd devl_cmd_sb_get;
 extern const struct devlink_cmd devl_cmd_sb_pool_get;
@@ -159,7 +162,6 @@ extern const struct devlink_cmd devl_cmd_sb_port_pool_get;
 extern const struct devlink_cmd devl_cmd_sb_tc_pool_bind_get;
 extern const struct devlink_cmd devl_cmd_param_get;
 extern const struct devlink_cmd devl_cmd_region_get;
-extern const struct devlink_cmd devl_cmd_info_get;
 extern const struct devlink_cmd devl_cmd_health_reporter_get;
 extern const struct devlink_cmd devl_cmd_trap_get;
 extern const struct devlink_cmd devl_cmd_trap_group_get;
net/devlink/leftover.c +2 -2
index 094cd0e8224e..895b732bed8e 100644
@@ -6283,7 +6283,7 @@ const struct genl_small_ops devlink_nl_small_ops[56] = {
 		.cmd = DEVLINK_CMD_GET,
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
 		.doit = devlink_nl_get_doit,
-		.dumpit = devlink_nl_instance_iter_dumpit,
+		.dumpit = devlink_nl_get_dumpit,
 		/* can be retrieved by unprivileged users */
 	},
 	{
@@ -6537,7 +6537,7 @@ const struct genl_small_ops devlink_nl_small_ops[56] = {
 		.cmd = DEVLINK_CMD_INFO_GET,
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
 		.doit = devlink_nl_info_get_doit,
-		.dumpit = devlink_nl_instance_iter_dumpit,
+		.dumpit = devlink_nl_info_get_dumpit,
 		/* can be retrieved by unprivileged users */
 	},
 	{
net/devlink/netlink.c +12 -9
index 39e07a5a69af..98d5c6b0acd8 100644
@@ -178,7 +178,6 @@ void devlink_nl_post_doit(const struct genl_split_ops *ops,
 }
 
 static const struct devlink_cmd *devl_cmds[] = {
-	[DEVLINK_CMD_GET]		= &devl_cmd_get,
 	[DEVLINK_CMD_PORT_GET]		= &devl_cmd_port_get,
 	[DEVLINK_CMD_SB_GET]		= &devl_cmd_sb_get,
 	[DEVLINK_CMD_SB_POOL_GET]	= &devl_cmd_sb_pool_get,
@@ -186,7 +185,6 @@ static const struct devlink_cmd *devl_cmds[] = {
 	[DEVLINK_CMD_SB_TC_POOL_BIND_GET] = &devl_cmd_sb_tc_pool_bind_get,
 	[DEVLINK_CMD_PARAM_GET]		= &devl_cmd_param_get,
 	[DEVLINK_CMD_REGION_GET]	= &devl_cmd_region_get,
-	[DEVLINK_CMD_INFO_GET]		= &devl_cmd_info_get,
 	[DEVLINK_CMD_HEALTH_REPORTER_GET] = &devl_cmd_health_reporter_get,
 	[DEVLINK_CMD_TRAP_GET]		= &devl_cmd_trap_get,
 	[DEVLINK_CMD_TRAP_GROUP_GET]	= &devl_cmd_trap_group_get,
@@ -196,23 +194,19 @@ static const struct devlink_cmd *devl_cmds[] = {
 	[DEVLINK_CMD_SELFTESTS_GET]	= &devl_cmd_selftests_get,
 };
 
-int devlink_nl_instance_iter_dumpit(struct sk_buff *msg,
-				    struct netlink_callback *cb)
+int devlink_nl_dumpit(struct sk_buff *msg, struct netlink_callback *cb,
+		      devlink_nl_dump_one_func_t *dump_one)
 {
-	const struct genl_dumpit_info *info = genl_dumpit_info(cb);
 	struct devlink_nl_dump_state *state = devlink_dump_state(cb);
-	const struct devlink_cmd *cmd;
 	struct devlink *devlink;
 	int err = 0;
 
-	cmd = devl_cmds[info->op.cmd];
-
 	while ((devlink = devlinks_xa_find_get(sock_net(msg->sk),
 					       &state->instance))) {
 		devl_lock(devlink);
 
 		if (devl_is_registered(devlink))
-			err = cmd->dump_one(msg, devlink, cb);
+			err = dump_one(msg, devlink, cb);
 		else
 			err = 0;
 
@@ -233,6 +227,15 @@ int devlink_nl_instance_iter_dumpit(struct sk_buff *msg,
 	return msg->len;
 }
 
+int devlink_nl_instance_iter_dumpit(struct sk_buff *msg,
+				    struct netlink_callback *cb)
+{
+	const struct genl_dumpit_info *info = genl_dumpit_info(cb);
+	const struct devlink_cmd *cmd = devl_cmds[info->op.cmd];
+
+	return devlink_nl_dumpit(msg, cb, cmd->dump_one);
+}
+
 struct genl_family devlink_nl_family __ro_after_init = {
 	.name		= DEVLINK_GENL_NAME,
 	.version	= DEVLINK_GENL_VERSION,
Signature · 1 line
2.41.0
maintainer
#12 lore raw

Re: [patch net-next v2 10/11] devlink: introduce couple of dumpit callbacks for split ops

net/devlink/dev.c int devlink_nl_get_doit(struct sk_buff *skb, struct genl_info *info) · line 234

Quoted 7 lines · On Wed, 2 Aug 2023 17:20:22 +0200 Jiri Pirko wrote:
net/devlink/dev.c +5 -0
+int devlink_nl_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)
+{
+	return devlink_nl_dumpit(msg, cb, devlink_nl_get_dump_one);
+}
+
 
 static void devlink_reload_failed_set(struct devlink *devlink,

nit double new line

author maintainer
#13 lore raw

PATCH v2 11/11 devlink: use generated split ops and remove duplicated commands from small ops

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Do the switch and use generated split ops for get and info_get commands. Remove those from small ops array.

---
 net/devlink/devl_internal.h |  2 +-
 net/devlink/leftover.c      | 16 +---------------
 net/devlink/netlink.c       |  2 ++
 3 files changed, 4 insertions(+), 16 deletions(-)
net/devlink/devl_internal.h +1 -1
index 51de0e1fc769..7fdd956ff992 100644
@@ -124,7 +124,7 @@ struct devlink_cmd {
 	devlink_nl_dump_one_func_t *dump_one;
 };
 
-extern const struct genl_small_ops devlink_nl_small_ops[56];
+extern const struct genl_small_ops devlink_nl_small_ops[54];
 
 struct devlink *
 devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs);
net/devlink/leftover.c +1 -15
index 895b732bed8e..3bf42f5335ed 100644
@@ -6278,14 +6278,7 @@ static int devlink_nl_cmd_trap_policer_set_doit(struct sk_buff *skb,
 	return devlink_trap_policer_set(devlink, policer_item, info);
 }
 
-const struct genl_small_ops devlink_nl_small_ops[56] = {
-	{
-		.cmd = DEVLINK_CMD_GET,
-		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
-		.doit = devlink_nl_get_doit,
-		.dumpit = devlink_nl_get_dumpit,
-		/* can be retrieved by unprivileged users */
-	},
+const struct genl_small_ops devlink_nl_small_ops[54] = {
 	{
 		.cmd = DEVLINK_CMD_PORT_GET,
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
@@ -6533,13 +6526,6 @@ const struct genl_small_ops devlink_nl_small_ops[56] = {
 		.dumpit = devlink_nl_cmd_region_read_dumpit,
 		.flags = GENL_ADMIN_PERM,
 	},
-	{
-		.cmd = DEVLINK_CMD_INFO_GET,
-		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
-		.doit = devlink_nl_info_get_doit,
-		.dumpit = devlink_nl_info_get_dumpit,
-		/* can be retrieved by unprivileged users */
-	},
 	{
 		.cmd = DEVLINK_CMD_HEALTH_REPORTER_GET,
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/devlink/netlink.c +2 -0
index 98d5c6b0acd8..bada2819827b 100644
@@ -248,6 +248,8 @@ struct genl_family devlink_nl_family __ro_after_init = {
 	.module		= THIS_MODULE,
 	.small_ops	= devlink_nl_small_ops,
 	.n_small_ops	= ARRAY_SIZE(devlink_nl_small_ops),
+	.split_ops	= devlink_nl_ops,
+	.n_split_ops	= ARRAY_SIZE(devlink_nl_ops),
 	.resv_start_op	= DEVLINK_CMD_SELFTESTS_RUN + 1,
 	.mcgrps		= devlink_nl_mcgrps,
 	.n_mcgrps	= ARRAY_SIZE(devlink_nl_mcgrps),
Signature · 1 line
2.41.0
maintainer
#14 lore raw
In reply to Jiri Pirko
Quoted 9 lines · On Wed, 2 Aug 2023 17:20:12 +0200 Jiri Pirko wrote:

This is an outcome of the discussion in the following thread:
https://lore.kernel.org/netdev/[email protected]/
It serves as a dependency on the linked selector patchset.

There is an existing spec for devlink used for userspace part generation. There are two commands supported there.

This patchset extends the spec so kernel split ops code could be generated from it.

Looks good! But you need to reshuffle stuff in patches 7-10 because there's a temporary build breakage. Some squashing, reordering and maybe splitting patch 10 should do?

Feel free to post v3 without waiting the full 24h.

Signature · 1 line
pw-bot: cr
author maintainer
#15 lore raw
Quoted 8 lines · Thu, Aug 03, 2023 at 04:07:34AM CEST, [email protected] wrote:
Quoted 7 lines · On Wed, 2 Aug 2023 17:20:12 +0200 Jiri Pirko wrote:

This is an outcome of the discussion in the following thread:
https://lore.kernel.org/netdev/[email protected]/
It serves as a dependency on the linked selector patchset.

There is an existing spec for devlink used for userspace part generation. There are two commands supported there.

Quoted 6 lines
Quoted 2 lines

This patchset extends the spec so kernel split ops code could be generated from it.

Looks good! But you need to reshuffle stuff in patches 7-10 because there's a temporary build breakage. Some squashing, reordering and maybe splitting patch 10 should do?

I was very careful not to cause any breakage. Will double check, fix the 2 nits and send v3.

Thanks!

Quoted 4 lines

Feel free to post v3 without waiting the full 24h.

Signature · 1 line
pw-bot: cr