[PATCH net-next] devlink: Implement devlink param multi attribute nested data values

Ratheesh Kannoth posted 1 patch 2 weeks, 1 day ago
There is a newer version of this series
Documentation/netlink/specs/devlink.yaml |  4 ++++
include/net/devlink.h                    |  8 ++++++++
include/uapi/linux/devlink.h             |  1 +
net/devlink/netlink_gen.c                |  2 ++
net/devlink/param.c                      | 18 +++++++++++++++++-
5 files changed, 32 insertions(+), 1 deletion(-)
[PATCH net-next] devlink: Implement devlink param multi attribute nested data values
Posted by Ratheesh Kannoth 2 weeks, 1 day ago
From: Saeed Mahameed <saeedm@nvidia.com>

Devlink param value attribute is not defined since devlink is handling
the value validating and parsing internally, this allows us to implement
multi attribute values without breaking any policies.

Devlink param multi-attribute values are considered to be dynamically
sized arrays of u32 values, by introducing a new devlink param type
DEVLINK_PARAM_TYPE_U32_ARRAY, driver and user space can set a variable
count of u32 values into the DEVLINK_ATTR_PARAM_VALUE_DATA attribute.

Implement get/set parsing and add to the internal value structure passed
to drivers.

This is useful for devices that need to configure a list of values for
a specific configuration.

example:
$ devlink dev param show pci/... name multi-value-param
name multi-value-param type driver-specific
values:
cmode permanent value: 0,1,2,3,4,5,6,7

$ devlink dev param set pci/... name multi-value-param \
		value 4,5,6,7,0,1,2,3 cmode permanent

Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
Signed-off-by: Ratheesh Kannoth <rkannoth@marvell.com>
---
 Documentation/netlink/specs/devlink.yaml |  4 ++++
 include/net/devlink.h                    |  8 ++++++++
 include/uapi/linux/devlink.h             |  1 +
 net/devlink/netlink_gen.c                |  2 ++
 net/devlink/param.c                      | 18 +++++++++++++++++-
 5 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml
index 837112da6738..e8a8287c4f19 100644
--- a/Documentation/netlink/specs/devlink.yaml
+++ b/Documentation/netlink/specs/devlink.yaml
@@ -226,6 +226,10 @@ definitions:
         value: 10
       -
         name: binary
+      -
+        name: u32-array
+        value: 129
+
   -
     name: rate-tc-index-max
     type: const
diff --git a/include/net/devlink.h b/include/net/devlink.h
index cb839e0435a1..0a496715da99 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -432,6 +432,13 @@ enum devlink_param_type {
 	DEVLINK_PARAM_TYPE_U64 = DEVLINK_VAR_ATTR_TYPE_U64,
 	DEVLINK_PARAM_TYPE_STRING = DEVLINK_VAR_ATTR_TYPE_STRING,
 	DEVLINK_PARAM_TYPE_BOOL = DEVLINK_VAR_ATTR_TYPE_FLAG,
+	DEVLINK_PARAM_TYPE_U32_ARRAY = DEVLINK_VAR_ATTR_TYPE_U32_ARRAY,
+};
+
+#define __DEVLINK_PARAM_MAX_ARRAY_SIZE 32
+struct devlink_param_u32_array {
+	u32 size;
+	u32 val[__DEVLINK_PARAM_MAX_ARRAY_SIZE];
 };
 
 union devlink_param_value {
@@ -441,6 +448,7 @@ union devlink_param_value {
 	u64 vu64;
 	char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
 	bool vbool;
+	struct devlink_param_u32_array u32arr;
 };
 
 struct devlink_param_gset_ctx {
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index e7d6b6d13470..768d0d88710f 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -404,6 +404,7 @@ enum devlink_var_attr_type {
 	DEVLINK_VAR_ATTR_TYPE_BINARY,
 	__DEVLINK_VAR_ATTR_TYPE_CUSTOM_BASE = 0x80,
 	/* Any possible custom types, unrelated to NLA_* values go below */
+	DEVLINK_VAR_ATTR_TYPE_U32_ARRAY,
 };
 
 enum devlink_attr {
diff --git a/net/devlink/netlink_gen.c b/net/devlink/netlink_gen.c
index f4c61c2b4f22..e5a80eb467b8 100644
--- a/net/devlink/netlink_gen.c
+++ b/net/devlink/netlink_gen.c
@@ -32,6 +32,8 @@ devlink_attr_param_type_validate(const struct nlattr *attr,
 	case DEVLINK_VAR_ATTR_TYPE_NUL_STRING:
 		fallthrough;
 	case DEVLINK_VAR_ATTR_TYPE_BINARY:
+		fallthrough;
+	case DEVLINK_VAR_ATTR_TYPE_U32_ARRAY:
 		return 0;
 	}
 	NL_SET_ERR_MSG_ATTR(extack, attr, "invalid enum value");
diff --git a/net/devlink/param.c b/net/devlink/param.c
index e0ea93eded43..2d0ef13b562f 100644
--- a/net/devlink/param.c
+++ b/net/devlink/param.c
@@ -252,6 +252,11 @@ devlink_nl_param_value_put(struct sk_buff *msg, enum devlink_param_type type,
 				return -EMSGSIZE;
 		}
 		break;
+	case DEVLINK_PARAM_TYPE_U32_ARRAY:
+		for (int i = 0; i < val.u32arr.size; i++)
+			if (nla_put_u32(msg, nla_type, val.u32arr.val[i]))
+				return -EMSGSIZE;
+		break;
 	}
 	return 0;
 }
@@ -507,7 +512,7 @@ devlink_param_value_get_from_info(const struct devlink_param *param,
 				  union devlink_param_value *value)
 {
 	struct nlattr *param_data;
-	int len;
+	int len, cnt, rem;
 
 	param_data = info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA];
 
@@ -547,6 +552,17 @@ devlink_param_value_get_from_info(const struct devlink_param *param,
 			return -EINVAL;
 		value->vbool = nla_get_flag(param_data);
 		break;
+
+	case DEVLINK_PARAM_TYPE_U32_ARRAY:
+		cnt = 0;
+		nla_for_each_attr_type(param_data,
+				       DEVLINK_ATTR_PARAM_VALUE_DATA,
+				       genlmsg_data(info->genlhdr),
+				       genlmsg_len(info->genlhdr), rem)
+			value->u32arr.val[cnt++] = nla_get_u32(param_data);
+
+		value->u32arr.size = cnt;
+		break;
 	}
 	return 0;
 }
-- 
2.43.0
Re: [PATCH net-next] devlink: Implement devlink param multi attribute nested data values
Posted by kernel test robot 2 weeks, 1 day ago
Hi Ratheesh,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Ratheesh-Kannoth/devlink-Implement-devlink-param-multi-attribute-nested-data-values/20260123-145646
base:   net-next/main
patch link:    https://lore.kernel.org/r/20260123065257.2993735-1-rkannoth%40marvell.com
patch subject: [PATCH net-next] devlink: Implement devlink param multi attribute nested data values
config: arc-allmodconfig (https://download.01.org/0day-ci/archive/20260123/202601232124.fqzsosEi-lkp@intel.com/config)
compiler: arc-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260123/202601232124.fqzsosEi-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202601232124.fqzsosEi-lkp@intel.com/

All warnings (new ones prefixed by >>):

   net/devlink/param.c: In function 'devlink_nl_param_fill.constprop':
>> net/devlink/param.c:410:1: warning: the frame size of 1300 bytes is larger than 1280 bytes [-Wframe-larger-than=]
     410 | }
         | ^


vim +410 net/devlink/param.c

830c41e1e987d9 Jiri Pirko   2023-08-28  304  
830c41e1e987d9 Jiri Pirko   2023-08-28  305  static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
830c41e1e987d9 Jiri Pirko   2023-08-28  306  				 unsigned int port_index,
830c41e1e987d9 Jiri Pirko   2023-08-28  307  				 struct devlink_param_item *param_item,
830c41e1e987d9 Jiri Pirko   2023-08-28  308  				 enum devlink_command cmd,
011d133bb988f8 Daniel Zahka 2025-11-18  309  				 u32 portid, u32 seq, int flags,
011d133bb988f8 Daniel Zahka 2025-11-18  310  				 struct netlink_ext_ack *extack)
830c41e1e987d9 Jiri Pirko   2023-08-28  311  {
2a367002ed321e Daniel Zahka 2025-11-18  312  	union devlink_param_value default_value[DEVLINK_PARAM_CMODE_MAX + 1];
830c41e1e987d9 Jiri Pirko   2023-08-28  313  	union devlink_param_value param_value[DEVLINK_PARAM_CMODE_MAX + 1];
2a367002ed321e Daniel Zahka 2025-11-18  314  	bool default_value_set[DEVLINK_PARAM_CMODE_MAX + 1] = {};
830c41e1e987d9 Jiri Pirko   2023-08-28  315  	bool param_value_set[DEVLINK_PARAM_CMODE_MAX + 1] = {};
830c41e1e987d9 Jiri Pirko   2023-08-28  316  	const struct devlink_param *param = param_item->param;
830c41e1e987d9 Jiri Pirko   2023-08-28  317  	struct devlink_param_gset_ctx ctx;
830c41e1e987d9 Jiri Pirko   2023-08-28  318  	struct nlattr *param_values_list;
830c41e1e987d9 Jiri Pirko   2023-08-28  319  	struct nlattr *param_attr;
830c41e1e987d9 Jiri Pirko   2023-08-28  320  	void *hdr;
830c41e1e987d9 Jiri Pirko   2023-08-28  321  	int err;
830c41e1e987d9 Jiri Pirko   2023-08-28  322  	int i;
830c41e1e987d9 Jiri Pirko   2023-08-28  323  
830c41e1e987d9 Jiri Pirko   2023-08-28  324  	/* Get value from driver part to driverinit configuration mode */
830c41e1e987d9 Jiri Pirko   2023-08-28  325  	for (i = 0; i <= DEVLINK_PARAM_CMODE_MAX; i++) {
830c41e1e987d9 Jiri Pirko   2023-08-28  326  		if (!devlink_param_cmode_is_supported(param, i))
830c41e1e987d9 Jiri Pirko   2023-08-28  327  			continue;
830c41e1e987d9 Jiri Pirko   2023-08-28  328  		if (i == DEVLINK_PARAM_CMODE_DRIVERINIT) {
830c41e1e987d9 Jiri Pirko   2023-08-28  329  			if (param_item->driverinit_value_new_valid)
830c41e1e987d9 Jiri Pirko   2023-08-28  330  				param_value[i] = param_item->driverinit_value_new;
830c41e1e987d9 Jiri Pirko   2023-08-28  331  			else if (param_item->driverinit_value_valid)
830c41e1e987d9 Jiri Pirko   2023-08-28  332  				param_value[i] = param_item->driverinit_value;
830c41e1e987d9 Jiri Pirko   2023-08-28  333  			else
830c41e1e987d9 Jiri Pirko   2023-08-28  334  				return -EOPNOTSUPP;
2a367002ed321e Daniel Zahka 2025-11-18  335  
2a367002ed321e Daniel Zahka 2025-11-18  336  			if (param_item->driverinit_value_valid) {
2a367002ed321e Daniel Zahka 2025-11-18  337  				default_value[i] = param_item->driverinit_default;
2a367002ed321e Daniel Zahka 2025-11-18  338  				default_value_set[i] = true;
2a367002ed321e Daniel Zahka 2025-11-18  339  			}
830c41e1e987d9 Jiri Pirko   2023-08-28  340  		} else {
830c41e1e987d9 Jiri Pirko   2023-08-28  341  			ctx.cmode = i;
011d133bb988f8 Daniel Zahka 2025-11-18  342  			err = devlink_param_get(devlink, param, &ctx, extack);
830c41e1e987d9 Jiri Pirko   2023-08-28  343  			if (err)
830c41e1e987d9 Jiri Pirko   2023-08-28  344  				return err;
830c41e1e987d9 Jiri Pirko   2023-08-28  345  			param_value[i] = ctx.val;
2a367002ed321e Daniel Zahka 2025-11-18  346  
2a367002ed321e Daniel Zahka 2025-11-18  347  			err = devlink_param_get_default(devlink, param, &ctx,
2a367002ed321e Daniel Zahka 2025-11-18  348  							extack);
2a367002ed321e Daniel Zahka 2025-11-18  349  			if (!err) {
2a367002ed321e Daniel Zahka 2025-11-18  350  				default_value[i] = ctx.val;
2a367002ed321e Daniel Zahka 2025-11-18  351  				default_value_set[i] = true;
2a367002ed321e Daniel Zahka 2025-11-18  352  			} else if (err != -EOPNOTSUPP) {
2a367002ed321e Daniel Zahka 2025-11-18  353  				return err;
2a367002ed321e Daniel Zahka 2025-11-18  354  			}
830c41e1e987d9 Jiri Pirko   2023-08-28  355  		}
830c41e1e987d9 Jiri Pirko   2023-08-28  356  		param_value_set[i] = true;
830c41e1e987d9 Jiri Pirko   2023-08-28  357  	}
830c41e1e987d9 Jiri Pirko   2023-08-28  358  
830c41e1e987d9 Jiri Pirko   2023-08-28  359  	hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd);
830c41e1e987d9 Jiri Pirko   2023-08-28  360  	if (!hdr)
830c41e1e987d9 Jiri Pirko   2023-08-28  361  		return -EMSGSIZE;
830c41e1e987d9 Jiri Pirko   2023-08-28  362  
830c41e1e987d9 Jiri Pirko   2023-08-28  363  	if (devlink_nl_put_handle(msg, devlink))
830c41e1e987d9 Jiri Pirko   2023-08-28  364  		goto genlmsg_cancel;
830c41e1e987d9 Jiri Pirko   2023-08-28  365  
830c41e1e987d9 Jiri Pirko   2023-08-28  366  	if (cmd == DEVLINK_CMD_PORT_PARAM_GET ||
830c41e1e987d9 Jiri Pirko   2023-08-28  367  	    cmd == DEVLINK_CMD_PORT_PARAM_NEW ||
830c41e1e987d9 Jiri Pirko   2023-08-28  368  	    cmd == DEVLINK_CMD_PORT_PARAM_DEL)
830c41e1e987d9 Jiri Pirko   2023-08-28  369  		if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX, port_index))
830c41e1e987d9 Jiri Pirko   2023-08-28  370  			goto genlmsg_cancel;
830c41e1e987d9 Jiri Pirko   2023-08-28  371  
830c41e1e987d9 Jiri Pirko   2023-08-28  372  	param_attr = nla_nest_start_noflag(msg, DEVLINK_ATTR_PARAM);
830c41e1e987d9 Jiri Pirko   2023-08-28  373  	if (!param_attr)
830c41e1e987d9 Jiri Pirko   2023-08-28  374  		goto genlmsg_cancel;
830c41e1e987d9 Jiri Pirko   2023-08-28  375  	if (nla_put_string(msg, DEVLINK_ATTR_PARAM_NAME, param->name))
830c41e1e987d9 Jiri Pirko   2023-08-28  376  		goto param_nest_cancel;
830c41e1e987d9 Jiri Pirko   2023-08-28  377  	if (param->generic && nla_put_flag(msg, DEVLINK_ATTR_PARAM_GENERIC))
830c41e1e987d9 Jiri Pirko   2023-08-28  378  		goto param_nest_cancel;
f9e78932eac650 Jiri Pirko   2025-05-05  379  	if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_TYPE, param->type))
830c41e1e987d9 Jiri Pirko   2023-08-28  380  		goto param_nest_cancel;
830c41e1e987d9 Jiri Pirko   2023-08-28  381  
830c41e1e987d9 Jiri Pirko   2023-08-28  382  	param_values_list = nla_nest_start_noflag(msg,
830c41e1e987d9 Jiri Pirko   2023-08-28  383  						  DEVLINK_ATTR_PARAM_VALUES_LIST);
830c41e1e987d9 Jiri Pirko   2023-08-28  384  	if (!param_values_list)
830c41e1e987d9 Jiri Pirko   2023-08-28  385  		goto param_nest_cancel;
830c41e1e987d9 Jiri Pirko   2023-08-28  386  
830c41e1e987d9 Jiri Pirko   2023-08-28  387  	for (i = 0; i <= DEVLINK_PARAM_CMODE_MAX; i++) {
830c41e1e987d9 Jiri Pirko   2023-08-28  388  		if (!param_value_set[i])
830c41e1e987d9 Jiri Pirko   2023-08-28  389  			continue;
830c41e1e987d9 Jiri Pirko   2023-08-28  390  		err = devlink_nl_param_value_fill_one(msg, param->type,
2a367002ed321e Daniel Zahka 2025-11-18  391  						      i, param_value[i],
2a367002ed321e Daniel Zahka 2025-11-18  392  						      default_value[i],
2a367002ed321e Daniel Zahka 2025-11-18  393  						      default_value_set[i]);
830c41e1e987d9 Jiri Pirko   2023-08-28  394  		if (err)
830c41e1e987d9 Jiri Pirko   2023-08-28  395  			goto values_list_nest_cancel;
830c41e1e987d9 Jiri Pirko   2023-08-28  396  	}
830c41e1e987d9 Jiri Pirko   2023-08-28  397  
830c41e1e987d9 Jiri Pirko   2023-08-28  398  	nla_nest_end(msg, param_values_list);
830c41e1e987d9 Jiri Pirko   2023-08-28  399  	nla_nest_end(msg, param_attr);
830c41e1e987d9 Jiri Pirko   2023-08-28  400  	genlmsg_end(msg, hdr);
830c41e1e987d9 Jiri Pirko   2023-08-28  401  	return 0;
830c41e1e987d9 Jiri Pirko   2023-08-28  402  
830c41e1e987d9 Jiri Pirko   2023-08-28  403  values_list_nest_cancel:
830c41e1e987d9 Jiri Pirko   2023-08-28  404  	nla_nest_end(msg, param_values_list);
830c41e1e987d9 Jiri Pirko   2023-08-28  405  param_nest_cancel:
830c41e1e987d9 Jiri Pirko   2023-08-28  406  	nla_nest_cancel(msg, param_attr);
830c41e1e987d9 Jiri Pirko   2023-08-28  407  genlmsg_cancel:
830c41e1e987d9 Jiri Pirko   2023-08-28  408  	genlmsg_cancel(msg, hdr);
830c41e1e987d9 Jiri Pirko   2023-08-28  409  	return -EMSGSIZE;
830c41e1e987d9 Jiri Pirko   2023-08-28 @410  }
830c41e1e987d9 Jiri Pirko   2023-08-28  411  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH net-next] devlink: Implement devlink param multi attribute nested data values
Posted by kernel test robot 2 weeks, 1 day ago
Hi Ratheesh,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Ratheesh-Kannoth/devlink-Implement-devlink-param-multi-attribute-nested-data-values/20260123-145646
base:   net-next/main
patch link:    https://lore.kernel.org/r/20260123065257.2993735-1-rkannoth%40marvell.com
patch subject: [PATCH net-next] devlink: Implement devlink param multi attribute nested data values
config: hexagon-allmodconfig (https://download.01.org/0day-ci/archive/20260123/202601232029.nwwE5gfM-lkp@intel.com/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260123/202601232029.nwwE5gfM-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202601232029.nwwE5gfM-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> net/devlink/param.c:305:12: warning: stack frame size (1464) exceeds limit (1280) in 'devlink_nl_param_fill' [-Wframe-larger-than]
     305 | static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
         |            ^
   1 warning generated.


vim +/devlink_nl_param_fill +305 net/devlink/param.c

830c41e1e987d9 Jiri Pirko   2023-08-28  304  
830c41e1e987d9 Jiri Pirko   2023-08-28 @305  static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
830c41e1e987d9 Jiri Pirko   2023-08-28  306  				 unsigned int port_index,
830c41e1e987d9 Jiri Pirko   2023-08-28  307  				 struct devlink_param_item *param_item,
830c41e1e987d9 Jiri Pirko   2023-08-28  308  				 enum devlink_command cmd,
011d133bb988f8 Daniel Zahka 2025-11-18  309  				 u32 portid, u32 seq, int flags,
011d133bb988f8 Daniel Zahka 2025-11-18  310  				 struct netlink_ext_ack *extack)
830c41e1e987d9 Jiri Pirko   2023-08-28  311  {
2a367002ed321e Daniel Zahka 2025-11-18  312  	union devlink_param_value default_value[DEVLINK_PARAM_CMODE_MAX + 1];
830c41e1e987d9 Jiri Pirko   2023-08-28  313  	union devlink_param_value param_value[DEVLINK_PARAM_CMODE_MAX + 1];
2a367002ed321e Daniel Zahka 2025-11-18  314  	bool default_value_set[DEVLINK_PARAM_CMODE_MAX + 1] = {};
830c41e1e987d9 Jiri Pirko   2023-08-28  315  	bool param_value_set[DEVLINK_PARAM_CMODE_MAX + 1] = {};
830c41e1e987d9 Jiri Pirko   2023-08-28  316  	const struct devlink_param *param = param_item->param;
830c41e1e987d9 Jiri Pirko   2023-08-28  317  	struct devlink_param_gset_ctx ctx;
830c41e1e987d9 Jiri Pirko   2023-08-28  318  	struct nlattr *param_values_list;
830c41e1e987d9 Jiri Pirko   2023-08-28  319  	struct nlattr *param_attr;
830c41e1e987d9 Jiri Pirko   2023-08-28  320  	void *hdr;
830c41e1e987d9 Jiri Pirko   2023-08-28  321  	int err;
830c41e1e987d9 Jiri Pirko   2023-08-28  322  	int i;
830c41e1e987d9 Jiri Pirko   2023-08-28  323  
830c41e1e987d9 Jiri Pirko   2023-08-28  324  	/* Get value from driver part to driverinit configuration mode */
830c41e1e987d9 Jiri Pirko   2023-08-28  325  	for (i = 0; i <= DEVLINK_PARAM_CMODE_MAX; i++) {
830c41e1e987d9 Jiri Pirko   2023-08-28  326  		if (!devlink_param_cmode_is_supported(param, i))
830c41e1e987d9 Jiri Pirko   2023-08-28  327  			continue;
830c41e1e987d9 Jiri Pirko   2023-08-28  328  		if (i == DEVLINK_PARAM_CMODE_DRIVERINIT) {
830c41e1e987d9 Jiri Pirko   2023-08-28  329  			if (param_item->driverinit_value_new_valid)
830c41e1e987d9 Jiri Pirko   2023-08-28  330  				param_value[i] = param_item->driverinit_value_new;
830c41e1e987d9 Jiri Pirko   2023-08-28  331  			else if (param_item->driverinit_value_valid)
830c41e1e987d9 Jiri Pirko   2023-08-28  332  				param_value[i] = param_item->driverinit_value;
830c41e1e987d9 Jiri Pirko   2023-08-28  333  			else
830c41e1e987d9 Jiri Pirko   2023-08-28  334  				return -EOPNOTSUPP;
2a367002ed321e Daniel Zahka 2025-11-18  335  
2a367002ed321e Daniel Zahka 2025-11-18  336  			if (param_item->driverinit_value_valid) {
2a367002ed321e Daniel Zahka 2025-11-18  337  				default_value[i] = param_item->driverinit_default;
2a367002ed321e Daniel Zahka 2025-11-18  338  				default_value_set[i] = true;
2a367002ed321e Daniel Zahka 2025-11-18  339  			}
830c41e1e987d9 Jiri Pirko   2023-08-28  340  		} else {
830c41e1e987d9 Jiri Pirko   2023-08-28  341  			ctx.cmode = i;
011d133bb988f8 Daniel Zahka 2025-11-18  342  			err = devlink_param_get(devlink, param, &ctx, extack);
830c41e1e987d9 Jiri Pirko   2023-08-28  343  			if (err)
830c41e1e987d9 Jiri Pirko   2023-08-28  344  				return err;
830c41e1e987d9 Jiri Pirko   2023-08-28  345  			param_value[i] = ctx.val;
2a367002ed321e Daniel Zahka 2025-11-18  346  
2a367002ed321e Daniel Zahka 2025-11-18  347  			err = devlink_param_get_default(devlink, param, &ctx,
2a367002ed321e Daniel Zahka 2025-11-18  348  							extack);
2a367002ed321e Daniel Zahka 2025-11-18  349  			if (!err) {
2a367002ed321e Daniel Zahka 2025-11-18  350  				default_value[i] = ctx.val;
2a367002ed321e Daniel Zahka 2025-11-18  351  				default_value_set[i] = true;
2a367002ed321e Daniel Zahka 2025-11-18  352  			} else if (err != -EOPNOTSUPP) {
2a367002ed321e Daniel Zahka 2025-11-18  353  				return err;
2a367002ed321e Daniel Zahka 2025-11-18  354  			}
830c41e1e987d9 Jiri Pirko   2023-08-28  355  		}
830c41e1e987d9 Jiri Pirko   2023-08-28  356  		param_value_set[i] = true;
830c41e1e987d9 Jiri Pirko   2023-08-28  357  	}
830c41e1e987d9 Jiri Pirko   2023-08-28  358  
830c41e1e987d9 Jiri Pirko   2023-08-28  359  	hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd);
830c41e1e987d9 Jiri Pirko   2023-08-28  360  	if (!hdr)
830c41e1e987d9 Jiri Pirko   2023-08-28  361  		return -EMSGSIZE;
830c41e1e987d9 Jiri Pirko   2023-08-28  362  
830c41e1e987d9 Jiri Pirko   2023-08-28  363  	if (devlink_nl_put_handle(msg, devlink))
830c41e1e987d9 Jiri Pirko   2023-08-28  364  		goto genlmsg_cancel;
830c41e1e987d9 Jiri Pirko   2023-08-28  365  
830c41e1e987d9 Jiri Pirko   2023-08-28  366  	if (cmd == DEVLINK_CMD_PORT_PARAM_GET ||
830c41e1e987d9 Jiri Pirko   2023-08-28  367  	    cmd == DEVLINK_CMD_PORT_PARAM_NEW ||
830c41e1e987d9 Jiri Pirko   2023-08-28  368  	    cmd == DEVLINK_CMD_PORT_PARAM_DEL)
830c41e1e987d9 Jiri Pirko   2023-08-28  369  		if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX, port_index))
830c41e1e987d9 Jiri Pirko   2023-08-28  370  			goto genlmsg_cancel;
830c41e1e987d9 Jiri Pirko   2023-08-28  371  
830c41e1e987d9 Jiri Pirko   2023-08-28  372  	param_attr = nla_nest_start_noflag(msg, DEVLINK_ATTR_PARAM);
830c41e1e987d9 Jiri Pirko   2023-08-28  373  	if (!param_attr)
830c41e1e987d9 Jiri Pirko   2023-08-28  374  		goto genlmsg_cancel;
830c41e1e987d9 Jiri Pirko   2023-08-28  375  	if (nla_put_string(msg, DEVLINK_ATTR_PARAM_NAME, param->name))
830c41e1e987d9 Jiri Pirko   2023-08-28  376  		goto param_nest_cancel;
830c41e1e987d9 Jiri Pirko   2023-08-28  377  	if (param->generic && nla_put_flag(msg, DEVLINK_ATTR_PARAM_GENERIC))
830c41e1e987d9 Jiri Pirko   2023-08-28  378  		goto param_nest_cancel;
f9e78932eac650 Jiri Pirko   2025-05-05  379  	if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_TYPE, param->type))
830c41e1e987d9 Jiri Pirko   2023-08-28  380  		goto param_nest_cancel;
830c41e1e987d9 Jiri Pirko   2023-08-28  381  
830c41e1e987d9 Jiri Pirko   2023-08-28  382  	param_values_list = nla_nest_start_noflag(msg,
830c41e1e987d9 Jiri Pirko   2023-08-28  383  						  DEVLINK_ATTR_PARAM_VALUES_LIST);
830c41e1e987d9 Jiri Pirko   2023-08-28  384  	if (!param_values_list)
830c41e1e987d9 Jiri Pirko   2023-08-28  385  		goto param_nest_cancel;
830c41e1e987d9 Jiri Pirko   2023-08-28  386  
830c41e1e987d9 Jiri Pirko   2023-08-28  387  	for (i = 0; i <= DEVLINK_PARAM_CMODE_MAX; i++) {
830c41e1e987d9 Jiri Pirko   2023-08-28  388  		if (!param_value_set[i])
830c41e1e987d9 Jiri Pirko   2023-08-28  389  			continue;
830c41e1e987d9 Jiri Pirko   2023-08-28  390  		err = devlink_nl_param_value_fill_one(msg, param->type,
2a367002ed321e Daniel Zahka 2025-11-18  391  						      i, param_value[i],
2a367002ed321e Daniel Zahka 2025-11-18  392  						      default_value[i],
2a367002ed321e Daniel Zahka 2025-11-18  393  						      default_value_set[i]);
830c41e1e987d9 Jiri Pirko   2023-08-28  394  		if (err)
830c41e1e987d9 Jiri Pirko   2023-08-28  395  			goto values_list_nest_cancel;
830c41e1e987d9 Jiri Pirko   2023-08-28  396  	}
830c41e1e987d9 Jiri Pirko   2023-08-28  397  
830c41e1e987d9 Jiri Pirko   2023-08-28  398  	nla_nest_end(msg, param_values_list);
830c41e1e987d9 Jiri Pirko   2023-08-28  399  	nla_nest_end(msg, param_attr);
830c41e1e987d9 Jiri Pirko   2023-08-28  400  	genlmsg_end(msg, hdr);
830c41e1e987d9 Jiri Pirko   2023-08-28  401  	return 0;
830c41e1e987d9 Jiri Pirko   2023-08-28  402  
830c41e1e987d9 Jiri Pirko   2023-08-28  403  values_list_nest_cancel:
830c41e1e987d9 Jiri Pirko   2023-08-28  404  	nla_nest_end(msg, param_values_list);
830c41e1e987d9 Jiri Pirko   2023-08-28  405  param_nest_cancel:
830c41e1e987d9 Jiri Pirko   2023-08-28  406  	nla_nest_cancel(msg, param_attr);
830c41e1e987d9 Jiri Pirko   2023-08-28  407  genlmsg_cancel:
830c41e1e987d9 Jiri Pirko   2023-08-28  408  	genlmsg_cancel(msg, hdr);
830c41e1e987d9 Jiri Pirko   2023-08-28  409  	return -EMSGSIZE;
830c41e1e987d9 Jiri Pirko   2023-08-28  410  }
830c41e1e987d9 Jiri Pirko   2023-08-28  411  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH net-next] devlink: Implement devlink param multi attribute nested data values
Posted by Ratheesh Kannoth 2 weeks, 1 day ago
On 2026-01-23 at 18:18:15, kernel test robot (lkp@intel.com) wrote:
> Hi Ratheesh,
>
> kernel test robot noticed the following build warnings:
> All warnings (new ones prefixed by >>):
>
> >> net/devlink/param.c:305:12: warning: stack frame size (1464) exceeds limit (1280) in 'devlink_nl_param_fill' [-Wframe-larger-than]
>      305 | static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
>          |            ^
>    1 warning generated.

Jakub,
shall i modify to heap allocation and push v2 ?

-Ratheesh

>
>
> vim +/devlink_nl_param_fill +305 net/devlink/param.c
>
> 830c41e1e987d9 Jiri Pirko   2023-08-28  304
> 830c41e1e987d9 Jiri Pirko   2023-08-28 @305  static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
> 830c41e1e987d9 Jiri Pirko   2023-08-28  306  				 unsigned int port_index,
> 830c41e1e987d9 Jiri Pirko   2023-08-28  307  				 struct devlink_param_item *param_item,
> 830c41e1e987d9 Jiri Pirko   2023-08-28  308  				 enum devlink_command cmd,
> 011d133bb988f8 Daniel Zahka 2025-11-18  309  				 u32 portid, u32 seq, int flags,
> 011d133bb988f8 Daniel Zahka 2025-11-18  310  				 struct netlink_ext_ack *extack)
> 830c41e1e987d9 Jiri Pirko   2023-08-28  311  {
> 2a367002ed321e Daniel Zahka 2025-11-18  312  	union devlink_param_value default_value[DEVLINK_PARAM_CMODE_MAX + 1];
> 830c41e1e987d9 Jiri Pirko   2023-08-28  313  	union devlink_param_value param_value[DEVLINK_PARAM_CMODE_MAX + 1];
> 2a367002ed321e Daniel Zahka 2025-11-18  314  	bool default_value_set[DEVLINK_PARAM_CMODE_MAX + 1] = {};
> 830c41e1e987d9 Jiri Pirko   2023-08-28  315  	bool param_value_set[DEVLINK_PARAM_CMODE_MAX + 1] = {};
> 830c41e1e987d9 Jiri Pirko   2023-08-28  316  	const struct devlink_param *param = param_item->param;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  317  	struct devlink_param_gset_ctx ctx;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  318  	struct nlattr *param_values_list;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  319  	struct nlattr *param_attr;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  320  	void *hdr;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  321  	int err;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  322  	int i;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  323
> 830c41e1e987d9 Jiri Pirko   2023-08-28  324  	/* Get value from driver part to driverinit configuration mode */
> 830c41e1e987d9 Jiri Pirko   2023-08-28  325  	for (i = 0; i <= DEVLINK_PARAM_CMODE_MAX; i++) {
> 830c41e1e987d9 Jiri Pirko   2023-08-28  326  		if (!devlink_param_cmode_is_supported(param, i))
> 830c41e1e987d9 Jiri Pirko   2023-08-28  327  			continue;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  328  		if (i == DEVLINK_PARAM_CMODE_DRIVERINIT) {
> 830c41e1e987d9 Jiri Pirko   2023-08-28  329  			if (param_item->driverinit_value_new_valid)
> 830c41e1e987d9 Jiri Pirko   2023-08-28  330  				param_value[i] = param_item->driverinit_value_new;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  331  			else if (param_item->driverinit_value_valid)
> 830c41e1e987d9 Jiri Pirko   2023-08-28  332  				param_value[i] = param_item->driverinit_value;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  333  			else
> 830c41e1e987d9 Jiri Pirko   2023-08-28  334  				return -EOPNOTSUPP;
> 2a367002ed321e Daniel Zahka 2025-11-18  335
> 2a367002ed321e Daniel Zahka 2025-11-18  336  			if (param_item->driverinit_value_valid) {
> 2a367002ed321e Daniel Zahka 2025-11-18  337  				default_value[i] = param_item->driverinit_default;
> 2a367002ed321e Daniel Zahka 2025-11-18  338  				default_value_set[i] = true;
> 2a367002ed321e Daniel Zahka 2025-11-18  339  			}
> 830c41e1e987d9 Jiri Pirko   2023-08-28  340  		} else {
> 830c41e1e987d9 Jiri Pirko   2023-08-28  341  			ctx.cmode = i;
> 011d133bb988f8 Daniel Zahka 2025-11-18  342  			err = devlink_param_get(devlink, param, &ctx, extack);
> 830c41e1e987d9 Jiri Pirko   2023-08-28  343  			if (err)
> 830c41e1e987d9 Jiri Pirko   2023-08-28  344  				return err;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  345  			param_value[i] = ctx.val;
> 2a367002ed321e Daniel Zahka 2025-11-18  346
> 2a367002ed321e Daniel Zahka 2025-11-18  347  			err = devlink_param_get_default(devlink, param, &ctx,
> 2a367002ed321e Daniel Zahka 2025-11-18  348  							extack);
> 2a367002ed321e Daniel Zahka 2025-11-18  349  			if (!err) {
> 2a367002ed321e Daniel Zahka 2025-11-18  350  				default_value[i] = ctx.val;
> 2a367002ed321e Daniel Zahka 2025-11-18  351  				default_value_set[i] = true;
> 2a367002ed321e Daniel Zahka 2025-11-18  352  			} else if (err != -EOPNOTSUPP) {
> 2a367002ed321e Daniel Zahka 2025-11-18  353  				return err;
> 2a367002ed321e Daniel Zahka 2025-11-18  354  			}
> 830c41e1e987d9 Jiri Pirko   2023-08-28  355  		}
> 830c41e1e987d9 Jiri Pirko   2023-08-28  356  		param_value_set[i] = true;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  357  	}
> 830c41e1e987d9 Jiri Pirko   2023-08-28  358
> 830c41e1e987d9 Jiri Pirko   2023-08-28  359  	hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd);
> 830c41e1e987d9 Jiri Pirko   2023-08-28  360  	if (!hdr)
> 830c41e1e987d9 Jiri Pirko   2023-08-28  361  		return -EMSGSIZE;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  362
> 830c41e1e987d9 Jiri Pirko   2023-08-28  363  	if (devlink_nl_put_handle(msg, devlink))
> 830c41e1e987d9 Jiri Pirko   2023-08-28  364  		goto genlmsg_cancel;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  365
> 830c41e1e987d9 Jiri Pirko   2023-08-28  366  	if (cmd == DEVLINK_CMD_PORT_PARAM_GET ||
> 830c41e1e987d9 Jiri Pirko   2023-08-28  367  	    cmd == DEVLINK_CMD_PORT_PARAM_NEW ||
> 830c41e1e987d9 Jiri Pirko   2023-08-28  368  	    cmd == DEVLINK_CMD_PORT_PARAM_DEL)
> 830c41e1e987d9 Jiri Pirko   2023-08-28  369  		if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX, port_index))
> 830c41e1e987d9 Jiri Pirko   2023-08-28  370  			goto genlmsg_cancel;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  371
> 830c41e1e987d9 Jiri Pirko   2023-08-28  372  	param_attr = nla_nest_start_noflag(msg, DEVLINK_ATTR_PARAM);
> 830c41e1e987d9 Jiri Pirko   2023-08-28  373  	if (!param_attr)
> 830c41e1e987d9 Jiri Pirko   2023-08-28  374  		goto genlmsg_cancel;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  375  	if (nla_put_string(msg, DEVLINK_ATTR_PARAM_NAME, param->name))
> 830c41e1e987d9 Jiri Pirko   2023-08-28  376  		goto param_nest_cancel;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  377  	if (param->generic && nla_put_flag(msg, DEVLINK_ATTR_PARAM_GENERIC))
> 830c41e1e987d9 Jiri Pirko   2023-08-28  378  		goto param_nest_cancel;
> f9e78932eac650 Jiri Pirko   2025-05-05  379  	if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_TYPE, param->type))
> 830c41e1e987d9 Jiri Pirko   2023-08-28  380  		goto param_nest_cancel;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  381
> 830c41e1e987d9 Jiri Pirko   2023-08-28  382  	param_values_list = nla_nest_start_noflag(msg,
> 830c41e1e987d9 Jiri Pirko   2023-08-28  383  						  DEVLINK_ATTR_PARAM_VALUES_LIST);
> 830c41e1e987d9 Jiri Pirko   2023-08-28  384  	if (!param_values_list)
> 830c41e1e987d9 Jiri Pirko   2023-08-28  385  		goto param_nest_cancel;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  386
> 830c41e1e987d9 Jiri Pirko   2023-08-28  387  	for (i = 0; i <= DEVLINK_PARAM_CMODE_MAX; i++) {
> 830c41e1e987d9 Jiri Pirko   2023-08-28  388  		if (!param_value_set[i])
> 830c41e1e987d9 Jiri Pirko   2023-08-28  389  			continue;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  390  		err = devlink_nl_param_value_fill_one(msg, param->type,
> 2a367002ed321e Daniel Zahka 2025-11-18  391  						      i, param_value[i],
> 2a367002ed321e Daniel Zahka 2025-11-18  392  						      default_value[i],
> 2a367002ed321e Daniel Zahka 2025-11-18  393  						      default_value_set[i]);
> 830c41e1e987d9 Jiri Pirko   2023-08-28  394  		if (err)
> 830c41e1e987d9 Jiri Pirko   2023-08-28  395  			goto values_list_nest_cancel;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  396  	}
> 830c41e1e987d9 Jiri Pirko   2023-08-28  397
> 830c41e1e987d9 Jiri Pirko   2023-08-28  398  	nla_nest_end(msg, param_values_list);
> 830c41e1e987d9 Jiri Pirko   2023-08-28  399  	nla_nest_end(msg, param_attr);
> 830c41e1e987d9 Jiri Pirko   2023-08-28  400  	genlmsg_end(msg, hdr);
> 830c41e1e987d9 Jiri Pirko   2023-08-28  401  	return 0;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  402
> 830c41e1e987d9 Jiri Pirko   2023-08-28  403  values_list_nest_cancel:
> 830c41e1e987d9 Jiri Pirko   2023-08-28  404  	nla_nest_end(msg, param_values_list);
> 830c41e1e987d9 Jiri Pirko   2023-08-28  405  param_nest_cancel:
> 830c41e1e987d9 Jiri Pirko   2023-08-28  406  	nla_nest_cancel(msg, param_attr);
> 830c41e1e987d9 Jiri Pirko   2023-08-28  407  genlmsg_cancel:
> 830c41e1e987d9 Jiri Pirko   2023-08-28  408  	genlmsg_cancel(msg, hdr);
> 830c41e1e987d9 Jiri Pirko   2023-08-28  409  	return -EMSGSIZE;
> 830c41e1e987d9 Jiri Pirko   2023-08-28  410  }
> 830c41e1e987d9 Jiri Pirko   2023-08-28  411
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki