diff mbox series

[net-next,01/14] devlink: define enum for attr types of dynamic attributes

Message ID 20250228021227.871993-2-saeed@kernel.org (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series devlink, mlx5: Add new parameters for link management and SRIOV/eSwitch configurations | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl fail Generated files up to date; build failed; build has 10 warnings/errors; GEN HAS DIFF 2 files changed, 12664 deletions(-);
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success Errors and warnings before: 26 (+1) this patch: 26 (+1)
netdev/cc_maintainers warning 2 maintainers not CCed: horms@kernel.org donald.hunter@gmail.com
netdev/build_clang success Errors and warnings before: 2 this patch: 2
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 523 this patch: 523
netdev/checkpatch warning WARNING: Possible repeated word: 'type'
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc fail Errors and warnings before: 4 this patch: 13
netdev/source_inline success Was 0 now: 0

Commit Message

Saeed Mahameed Feb. 28, 2025, 2:12 a.m. UTC
From: Jiri Pirko <jiri@nvidia.com>

Devlink param and health reporter fmsg use attributes with dynamic type
which is determined according to a different type. Currently used values
are NLA_*. The problem is, they are not part of UAPI. They may change
which would cause a break.

To make this future safe, introduce a enum that shadows NLA_* values in
it and is part of UAPI.

Also, this allows to possibly carry types that are unrelated to NLA_*
values.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
---
 Documentation/netlink/specs/devlink.yaml | 23 ++++++++++++++++++
 include/uapi/linux/devlink.h             | 17 ++++++++++++++
 net/devlink/health.c                     | 17 ++++++++++++--
 net/devlink/param.c                      | 30 ++++++++++++------------
 4 files changed, 70 insertions(+), 17 deletions(-)

Comments

Simon Horman March 6, 2025, 12:05 p.m. UTC | #1
On Thu, Feb 27, 2025 at 06:12:14PM -0800, Saeed Mahameed wrote:
> From: Jiri Pirko <jiri@nvidia.com>
> 
> Devlink param and health reporter fmsg use attributes with dynamic type
> which is determined according to a different type. Currently used values
> are NLA_*. The problem is, they are not part of UAPI. They may change
> which would cause a break.
> 
> To make this future safe, introduce a enum that shadows NLA_* values in
> it and is part of UAPI.
> 
> Also, this allows to possibly carry types that are unrelated to NLA_*
> values.
> 
> Signed-off-by: Jiri Pirko <jiri@nvidia.com>
> Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
> ---
>  Documentation/netlink/specs/devlink.yaml | 23 ++++++++++++++++++
>  include/uapi/linux/devlink.h             | 17 ++++++++++++++
>  net/devlink/health.c                     | 17 ++++++++++++--
>  net/devlink/param.c                      | 30 ++++++++++++------------
>  4 files changed, 70 insertions(+), 17 deletions(-)
> 
> diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml
> index 09fbb4c03fc8..e99fc51856c5 100644
> --- a/Documentation/netlink/specs/devlink.yaml
> +++ b/Documentation/netlink/specs/devlink.yaml
> @@ -202,6 +202,29 @@ definitions:
>          name: exception
>        -
>          name: control
> +  -
> +    type: enum
> +    name: dyn_attr_type
> +    entries:
> +      -
> +        name: u8
> +        value: 1
> +      -
> +        name: u16
> +      -
> +        name: u32
> +      -
> +        name: u64
> +      -
> +        name: string
> +      -
> +        name: flag
> +      -
> +        name: nul_string
> +        value: 10
> +      -
> +        name: binary
> +  -
>  
>  attribute-sets:
>    -

Hi Saeed,

Thanks for these patches.

Unfortunately the above seems to cause ynl-regen to blow up.
I don't know why, but I see:

  $ ./tools/net/ynl/ynl-regen.sh
  Traceback (most recent call last):
    File "/home/nipa/net-next/wt-1/tools/net/ynl/pyynl/ynl_gen_c.py", line 3074, in <module>
      main()
      ~~~~^^
    File "/home/nipa/net-next/wt-1/tools/net/ynl/pyynl/ynl_gen_c.py", line 2783, in main
      parsed = Family(args.spec, exclude_ops)
    File "/home/nipa/net-next/wt-1/tools/net/ynl/pyynl/ynl_gen_c.py", line 954, in __init__
      super().__init__(file_name, exclude_ops=exclude_ops)
      ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/nipa/net-next/wt-1/tools/net/ynl/pyynl/lib/nlspec.py", line 462, in __init__
      jsonschema.validate(self.yaml, schema)
      ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3.13/site-packages/jsonschema/validators.py", line 1307, in validate
      raise error
  jsonschema.exceptions.ValidationError: None is not of type 'object'

  ...

Perhaps I need a newer version of jsonschema?


> diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
> index 9401aa343673..8cdd60eb3c43 100644
> --- a/include/uapi/linux/devlink.h
> +++ b/include/uapi/linux/devlink.h
> @@ -385,6 +385,23 @@ enum devlink_linecard_state {
>  	DEVLINK_LINECARD_STATE_MAX = __DEVLINK_LINECARD_STATE_MAX - 1
>  };
>  
> +/**
> + * enum devlink_dyn_attr_type - Dynamic attribute type type.

Perhaps this relates to auto-generation.
But I think the Kernel doc should also document the enum values:
DEVLINK_DYN_ATTR_TYPE_U8, ...

> + */
> +enum devlink_dyn_attr_type {
> +	/* Following values relate to the internal NLA_* values */
> +	DEVLINK_DYN_ATTR_TYPE_U8 = 1,
> +	DEVLINK_DYN_ATTR_TYPE_U16,
> +	DEVLINK_DYN_ATTR_TYPE_U32,
> +	DEVLINK_DYN_ATTR_TYPE_U64,
> +	DEVLINK_DYN_ATTR_TYPE_STRING,
> +	DEVLINK_DYN_ATTR_TYPE_FLAG,
> +	DEVLINK_DYN_ATTR_TYPE_NUL_STRING = 10,
> +	DEVLINK_DYN_ATTR_TYPE_BINARY,
> +	__DEVLINK_DYN_ATTR_TYPE_CUSTOM_BASE = 0x80,
> +	/* Any possible custom types, unrelated to NLA_* values go below */
> +};
> +
>  enum devlink_attr {
>  	/* don't change the order or add anything between, this is ABI! */
>  	DEVLINK_ATTR_UNSPEC,

...
diff mbox series

Patch

diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml
index 09fbb4c03fc8..e99fc51856c5 100644
--- a/Documentation/netlink/specs/devlink.yaml
+++ b/Documentation/netlink/specs/devlink.yaml
@@ -202,6 +202,29 @@  definitions:
         name: exception
       -
         name: control
+  -
+    type: enum
+    name: dyn_attr_type
+    entries:
+      -
+        name: u8
+        value: 1
+      -
+        name: u16
+      -
+        name: u32
+      -
+        name: u64
+      -
+        name: string
+      -
+        name: flag
+      -
+        name: nul_string
+        value: 10
+      -
+        name: binary
+  -
 
 attribute-sets:
   -
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 9401aa343673..8cdd60eb3c43 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -385,6 +385,23 @@  enum devlink_linecard_state {
 	DEVLINK_LINECARD_STATE_MAX = __DEVLINK_LINECARD_STATE_MAX - 1
 };
 
+/**
+ * enum devlink_dyn_attr_type - Dynamic attribute type type.
+ */
+enum devlink_dyn_attr_type {
+	/* Following values relate to the internal NLA_* values */
+	DEVLINK_DYN_ATTR_TYPE_U8 = 1,
+	DEVLINK_DYN_ATTR_TYPE_U16,
+	DEVLINK_DYN_ATTR_TYPE_U32,
+	DEVLINK_DYN_ATTR_TYPE_U64,
+	DEVLINK_DYN_ATTR_TYPE_STRING,
+	DEVLINK_DYN_ATTR_TYPE_FLAG,
+	DEVLINK_DYN_ATTR_TYPE_NUL_STRING = 10,
+	DEVLINK_DYN_ATTR_TYPE_BINARY,
+	__DEVLINK_DYN_ATTR_TYPE_CUSTOM_BASE = 0x80,
+	/* Any possible custom types, unrelated to NLA_* values go below */
+};
+
 enum devlink_attr {
 	/* don't change the order or add anything between, this is ABI! */
 	DEVLINK_ATTR_UNSPEC,
diff --git a/net/devlink/health.c b/net/devlink/health.c
index 57db6799722a..accb80cd3348 100644
--- a/net/devlink/health.c
+++ b/net/devlink/health.c
@@ -930,18 +930,31 @@  EXPORT_SYMBOL_GPL(devlink_fmsg_binary_pair_put);
 static int
 devlink_fmsg_item_fill_type(struct devlink_fmsg_item *msg, struct sk_buff *skb)
 {
+	enum devlink_dyn_attr_type dyn_attr_type;
+
 	switch (msg->nla_type) {
 	case NLA_FLAG:
+		dyn_attr_type = DEVLINK_DYN_ATTR_TYPE_FLAG;
+		break;
 	case NLA_U8:
+		dyn_attr_type = DEVLINK_DYN_ATTR_TYPE_U8;
+		break;
 	case NLA_U32:
+		dyn_attr_type = DEVLINK_DYN_ATTR_TYPE_U32;
+		break;
 	case NLA_U64:
+		dyn_attr_type = DEVLINK_DYN_ATTR_TYPE_U64;
+		break;
 	case NLA_NUL_STRING:
+		dyn_attr_type = DEVLINK_DYN_ATTR_TYPE_NUL_STRING;
+		break;
 	case NLA_BINARY:
-		return nla_put_u8(skb, DEVLINK_ATTR_FMSG_OBJ_VALUE_TYPE,
-				  msg->nla_type);
+		dyn_attr_type = DEVLINK_DYN_ATTR_TYPE_BINARY;
+		break;
 	default:
 		return -EINVAL;
 	}
+	return nla_put_u8(skb, DEVLINK_ATTR_FMSG_OBJ_VALUE_TYPE, dyn_attr_type);
 }
 
 static int
diff --git a/net/devlink/param.c b/net/devlink/param.c
index dcf0d1ccebba..e19d978dffa6 100644
--- a/net/devlink/param.c
+++ b/net/devlink/param.c
@@ -167,19 +167,19 @@  static int devlink_param_set(struct devlink *devlink,
 }
 
 static int
-devlink_param_type_to_nla_type(enum devlink_param_type param_type)
+devlink_param_type_to_dyn_attr_type(enum devlink_param_type param_type)
 {
 	switch (param_type) {
 	case DEVLINK_PARAM_TYPE_U8:
-		return NLA_U8;
+		return DEVLINK_DYN_ATTR_TYPE_U8;
 	case DEVLINK_PARAM_TYPE_U16:
-		return NLA_U16;
+		return DEVLINK_DYN_ATTR_TYPE_U16;
 	case DEVLINK_PARAM_TYPE_U32:
-		return NLA_U32;
+		return DEVLINK_DYN_ATTR_TYPE_U32;
 	case DEVLINK_PARAM_TYPE_STRING:
-		return NLA_STRING;
+		return DEVLINK_DYN_ATTR_TYPE_STRING;
 	case DEVLINK_PARAM_TYPE_BOOL:
-		return NLA_FLAG;
+		return DEVLINK_DYN_ATTR_TYPE_FLAG;
 	default:
 		return -EINVAL;
 	}
@@ -247,7 +247,7 @@  static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
 	struct devlink_param_gset_ctx ctx;
 	struct nlattr *param_values_list;
 	struct nlattr *param_attr;
-	int nla_type;
+	int dyn_attr_type;
 	void *hdr;
 	int err;
 	int i;
@@ -294,10 +294,10 @@  static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
 	if (param->generic && nla_put_flag(msg, DEVLINK_ATTR_PARAM_GENERIC))
 		goto param_nest_cancel;
 
-	nla_type = devlink_param_type_to_nla_type(param->type);
-	if (nla_type < 0)
+	dyn_attr_type = devlink_param_type_to_dyn_attr_type(param->type);
+	if (dyn_attr_type < 0)
 		goto param_nest_cancel;
-	if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_TYPE, nla_type))
+	if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_TYPE, dyn_attr_type))
 		goto param_nest_cancel;
 
 	param_values_list = nla_nest_start_noflag(msg,
@@ -420,19 +420,19 @@  devlink_param_type_get_from_info(struct genl_info *info,
 		return -EINVAL;
 
 	switch (nla_get_u8(info->attrs[DEVLINK_ATTR_PARAM_TYPE])) {
-	case NLA_U8:
+	case DEVLINK_DYN_ATTR_TYPE_U8:
 		*param_type = DEVLINK_PARAM_TYPE_U8;
 		break;
-	case NLA_U16:
+	case DEVLINK_DYN_ATTR_TYPE_U16:
 		*param_type = DEVLINK_PARAM_TYPE_U16;
 		break;
-	case NLA_U32:
+	case DEVLINK_DYN_ATTR_TYPE_U32:
 		*param_type = DEVLINK_PARAM_TYPE_U32;
 		break;
-	case NLA_STRING:
+	case DEVLINK_DYN_ATTR_TYPE_STRING:
 		*param_type = DEVLINK_PARAM_TYPE_STRING;
 		break;
-	case NLA_FLAG:
+	case DEVLINK_DYN_ATTR_TYPE_FLAG:
 		*param_type = DEVLINK_PARAM_TYPE_BOOL;
 		break;
 	default: