ethtool: rss: support creating and removing contexts via Netlink
Subsystems (6)
Jakub Kicinski
maintainercover ethtool: rss: support creating and removing contexts via Netlink
This series completes support of RSS configuration via Netlink. All functionality supported by the IOCTL is now supported by Netlink. Future series (time allowing) will add:
- hashing on the flow label, which started this whole thing;
- pinning the RSS context to a Netlink socket for auto-cleanup.
The first patch is a leftover held back from previous series to avoid conflicting with Gal's fix.
Next 4 patches refactor existing code to make reusing it for context creation possible. 2 patches after that add create and delete commands. Last but not least the test is extended.
Jakub Kicinski (8):
ethtool: assert that drivers with sym hash are consistent for RSS
contexts
ethtool: rejig the RSS notification machinery for more types
ethtool: rss: factor out allocating memory for response
ethtool: rss: factor out populating response from context
ethtool: move ethtool_rxfh_ctx_alloc() to common code
ethtool: rss: support creating contexts via Netlink
ethtool: rss: support removing contexts via Netlink
selftests: drv-net: rss_api: context create and delete tests
Documentation/netlink/specs/ethtool.yaml | 41 +- Documentation/networking/ethtool-netlink.rst | 41 ++ .../uapi/linux/ethtool_netlink_generated.h | 5 + net/ethtool/common.h | 8 +- net/ethtool/netlink.h | 5 + net/ethtool/common.c | 39 ++ net/ethtool/ioctl.c | 48 +-- net/ethtool/netlink.c | 22 + net/ethtool/rss.c | 393 ++++++++++++++++-- .../selftests/drivers/net/hw/rss_api.py | 73 ++++ 10 files changed, 603 insertions(+), 72 deletions(-)
Signature · 1 line
2.50.1
Jakub Kicinski
maintainerPATCH 1/8 ethtool: assert that drivers with sym hash are consistent for RSS contexts
Supporting per-RSS context configuration of hashing fields but not the hashing algorithm would complicate the code a lot. We'd need to cross check the config against all RSS contexts. None of the drivers need this today, so explicitly prevent new drivers with such skewed capabilities from registering. If such driver appears it will need to first adjust the checks in the core.
--- net/ethtool/common.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ethtool/common.c +4 -0
@@ -829,6 +829,10 @@ int ethtool_check_ops(const struct ethtool_ops *ops)return -EINVAL ;if (WARN_ON (ops->supported_input_xfrm && !ops->get_rxfh_fields))return -EINVAL ; +if (WARN_ON (ops->supported_input_xfrm && + ops->rxfh_per_ctx_fields != ops->rxfh_per_ctx_key)) +return -EINVAL ; +/* NOTE: sufficiently insane drivers may swap ethtool_ops at runtime, * the fact that ops are checked at registration time does not * mean the ops attached to a netdev later on are sane.
Signature · 1 line
2.50.1
Jakub Kicinski
maintainerPATCH 2/8 ethtool: rejig the RSS notification machinery for more types
In reply to Jakub KicinskiIn anticipation for CREATE and DELETE notifications - explicitly pass the notification type to ethtool_rss_notify(), when calling from the IOCTL code.
--- net/ethtool/common.h | 5 +++-- net/ethtool/ioctl.c | 12 +++++++----- net/ethtool/rss.c | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-)
net/ethtool/common.h +3 -2
@@ -76,9 +76,10 @@ int ethtool_get_module_eeprom_call(struct net_device *dev,bool __ethtool_dev_mm_supported (struct net_device *dev);#if IS_ENABLED (CONFIG_ETHTOOL_NETLINK ) -void ethtool_rss_notify (struct net_device *dev,u32 rss_context); +void ethtool_rss_notify (struct net_device *dev,u32 type,u32 rss_context);#else -static inline void ethtool_rss_notify (struct net_device *dev,u32 rss_context) +static inline void +ethtool_rss_notify (struct net_device *dev,u32 type,u32 rss_context) { }#endif
net/ethtool/ioctl.c +7 -5
@@ -1105,7 +1105,7 @@ ethtool_set_rxfh_fields(struct net_device *dev, u32 cmd, void __user *useraddr)if (rc)return rc; -ethtool_rss_notify (dev, fields.rss_context); +ethtool_rss_notify (dev,ETHTOOL_MSG_RSS_NTF , fields.rss_context);return 0 ; }
@@ -1520,8 +1520,8 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,struct ethtool_rxnfc rx_rings;struct ethtool_rxfh rxfh;bool create = false; -bool mod = false;u8 *rss_config; +int ntf =0 ;int ret;if (!ops->get_rxnfc || !ops->set_rxfh)
@@ -1671,6 +1671,7 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, rxfh_dev.input_xfrm = rxfh.input_xfrm;if (!rxfh.rss_context) { + ntf =ETHTOOL_MSG_RSS_NTF ; ret = ops->set_rxfh (dev, &rxfh_dev, extack); }else if (create) { ret = ops->create_rxfh_context (dev, ctx, &rxfh_dev, extack);
@@ -1682,9 +1683,11 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, ret = ops->remove_rxfh_context (dev, ctx, rxfh.rss_context, extack); }else { + ntf =ETHTOOL_MSG_RSS_NTF ; ret = ops->modify_rxfh_context (dev, ctx, &rxfh_dev, extack); }if (ret) { + ntf =0 ;if (create) {/* failed to create, free our new tracking entry */ xa_erase (&dev->ethtool->rss_ctx, rxfh.rss_context);
@@ -1692,7 +1695,6 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, } goto out_unlock; } - mod = !create && !rxfh_dev.rss_delete;if (copy_to_user (useraddr + offsetof(struct ethtool_rxfh , rss_context), &rxfh_dev.rss_context,sizeof (rxfh_dev.rss_context)))
@@ -1732,8 +1734,8 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,mutex_unlock (&dev->ethtool->rss_lock); out_free:kfree (rss_config); -if (mod) -ethtool_rss_notify (dev, rxfh.rss_context); +if (ntf) +ethtool_rss_notify (dev, ntf, rxfh.rss_context);return ret; }
net/ethtool/rss.c +2 -2
@@ -461,13 +461,13 @@ int ethnl_rss_dumpit(struct sk_buff *skb, struct netlink_callback *cb)/* RSS_NTF */ -void ethtool_rss_notify (struct net_device *dev,u32 rss_context) +void ethtool_rss_notify (struct net_device *dev,u32 type,u32 rss_context) {struct rss_req_info req_info = { .rss_context = rss_context, }; -ethnl_notify (dev,ETHTOOL_MSG_RSS_NTF , &req_info.base); +ethnl_notify (dev, type, &req_info.base); }/* RSS_SET */
Signature · 1 line
2.50.1
Re: [PATCH net-next 2/8] ethtool: rejig the RSS notification machinery for more types
Quoted 5 lines · Jakub Kicinski
In anticipation for CREATE and DELETE notifications - explicitly pass the notification type to
ethtool_rss_notify(), when calling from the IOCTL code.Signed-off-by Jakub Kicinski <[email protected]>
Jakub Kicinski
maintainerPATCH 3/8 ethtool: rss: factor out allocating memory for response
In reply to Jakub KicinskiTo ease the code reuse for RSS_CREATE we'll want to prepare struct rss_reply_data for the new context. Unfortunately we can't depend on the exiting scaffolding because the context doesn't exist (ctx=NULL) when we start preparing. Factor out the portion of the context 0 handling responsible for allocation of request memory, so that we can call it directly.
--- net/ethtool/rss.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-)
net/ethtool/rss.c +30 -17
@@ -113,21 +113,11 @@ rss_prepare_flow_hash(const struct rss_req_info *req, struct net_device *dev, }static int -rss_prepare_get (const struct rss_req_info *request,struct net_device *dev, -struct rss_reply_data *data,const struct genl_info *info) +rss_get_data_alloc (struct net_device *dev,struct rss_reply_data *data) { -struct ethtool_rxfh_param rxfh = {}; -const struct ethtool_ops *ops; +const struct ethtool_ops *ops = dev->ethtool_ops;u32 total_size, indir_bytes;u8 *rss_config; -int ret; - - ops = dev->ethtool_ops; - - ret =ethnl_ops_begin (dev); -if (ret <0 ) -return ret; -mutex_lock (&dev->ethtool->rss_lock); data->indir_size =0 ; data->hkey_size =0 ;
@@ -139,16 +129,39 @@ rss_prepare_get(const struct rss_req_info *request, struct net_device *dev, indir_bytes = data->indir_size *sizeof (u32); total_size = indir_bytes + data->hkey_size; rss_config =kzalloc (total_size,GFP_KERNEL ); -if (!rss_config) { - ret = -ENOMEM ; - goto out_unlock; - } +if (!rss_config) +return -ENOMEM ;if (data->indir_size) data->indir_table = (u32 *)rss_config;if (data->hkey_size) data->hkey = rss_config + indir_bytes; +return 0 ; +} + +static void rss_get_data_free (const struct rss_reply_data *data) +{ +kfree (data->indir_table); +} + +static int +rss_prepare_get (const struct rss_req_info *request,struct net_device *dev, +struct rss_reply_data *data,const struct genl_info *info) +{ +const struct ethtool_ops *ops = dev->ethtool_ops; +struct ethtool_rxfh_param rxfh = {}; +int ret; + + ret =ethnl_ops_begin (dev); +if (ret <0 ) +return ret; +mutex_lock (&dev->ethtool->rss_lock); + + ret =rss_get_data_alloc (dev, data); +if (ret) + goto out_unlock; + rxfh.indir_size = data->indir_size; rxfh.indir = data->indir_table; rxfh.key_size = data->hkey_size;
@@ -318,7 +331,7 @@ static void rss_cleanup_data(struct ethnl_reply_data *reply_base) {const struct rss_reply_data *data =RSS_REPDATA (reply_base); -kfree (data->indir_table); +rss_get_data_free (data); }struct rss_nl_dump_ctx {
Signature · 1 line
2.50.1
Jakub Kicinski
maintainerPATCH 4/8 ethtool: rss: factor out populating response from context
In reply to Jakub KicinskiSimilarly to previous change, factor out populating the response. We will use this after the context was allocated to send a notification so this time factor out from the additional context handling, rather than context 0 handling (for request context didn't exist, for response it does).
--- net/ethtool/rss.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-)
net/ethtool/rss.c +22 -10
@@ -179,6 +179,25 @@ rss_prepare_get(const struct rss_req_info *request, struct net_device *dev,return ret; } +static void +__rss_prepare_ctx (struct net_device *dev,struct rss_reply_data *data, +struct ethtool_rxfh_context *ctx) +{ +if (WARN_ON_ONCE (data->indir_size != ctx->indir_size || + data->hkey_size != ctx->key_size)) +return ; + + data->no_key_fields = !dev->ethtool_ops->rxfh_per_ctx_key; + + data->hfunc = ctx->hfunc; + data->input_xfrm = ctx->input_xfrm; +memcpy (data->indir_table,ethtool_rxfh_context_indir (ctx), + data->indir_size *sizeof (u32)); +if (data->hkey_size) +memcpy (data->hkey,ethtool_rxfh_context_key (ctx), + data->hkey_size); +} +static int rss_prepare_ctx (const struct rss_req_info *request,struct net_device *dev,struct rss_reply_data *data,const struct genl_info *info)
@@ -188,8 +207,6 @@ rss_prepare_ctx(const struct rss_req_info *request, struct net_device *dev,u8 *rss_config;int ret; - data->no_key_fields = !dev->ethtool_ops->rxfh_per_ctx_key; -mutex_lock (&dev->ethtool->rss_lock); ctx =xa_load (&dev->ethtool->rss_ctx, request->rss_context);if (!ctx) {
@@ -199,8 +216,6 @@ rss_prepare_ctx(const struct rss_req_info *request, struct net_device *dev, data->indir_size = ctx->indir_size; data->hkey_size = ctx->key_size; - data->hfunc = ctx->hfunc; - data->input_xfrm = ctx->input_xfrm; indir_bytes = data->indir_size *sizeof (u32); total_size = indir_bytes + data->hkey_size;
@@ -211,13 +226,10 @@ rss_prepare_ctx(const struct rss_req_info *request, struct net_device *dev, } data->indir_table = (u32 *)rss_config; -memcpy (data->indir_table,ethtool_rxfh_context_indir (ctx), indir_bytes); - -if (data->hkey_size) { +if (data->hkey_size) data->hkey = rss_config + indir_bytes; -memcpy (data->hkey,ethtool_rxfh_context_key (ctx), - data->hkey_size); - } + +__rss_prepare_ctx (dev, data, ctx); ret =0 ; out_unlock:
Signature · 1 line
2.50.1
Re: [PATCH net-next 4/8] ethtool: rss: factor out populating response from context
Quoted 7 lines · Jakub Kicinski
Similarly to previous change, factor out populating the response. We will use this after the context was allocated to send a notification so this time factor out from the additional context handling, rather than context 0 handling (for request context didn't exist, for response it does).
Signed-off-by Jakub Kicinski <[email protected]>
Quoted 9 lines
--- net/ethtool/rss.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-)net/ethtool/rss.c +0
-0
net/ethtool/rss.c rss_prepare_get(const struct rss_req_info *request, struct net_device *dev, · line 187
Quoted 9 lines
net/ethtool/rss.c +6
-0@@ -179,6 +179,25 @@ rss_prepare_get(const struct rss_req_info *request, struct net_device *dev,return ret; } +static void +__rss_prepare_ctx (struct net_device *dev,struct rss_reply_data *data, +struct ethtool_rxfh_context *ctx) +{ +if (WARN_ON_ONCE (data->indir_size != ctx->indir_size || + data->hkey_size != ctx->key_size))
I Wouldn't consider this part of "factoring out".
Jakub Kicinski
maintainerPATCH 5/8 ethtool: move ethtool_rxfh_ctx_alloc() to common code
In reply to Jakub KicinskiMove ethtool_rxfh_ctx_alloc() to common code, Netlink will need it.
--- net/ethtool/common.h | 3 +++ net/ethtool/common.c | 34 ++++++++++++++++++++++++++++++++++ net/ethtool/ioctl.c | 34 ---------------------------------- 3 files changed, 37 insertions(+), 34 deletions(-)
net/ethtool/common.h +3 -0
@@ -43,6 +43,9 @@ bool convert_legacy_settings_to_link_ksettings(int ethtool_check_max_channel (struct net_device *dev,struct ethtool_channels channels,struct genl_info *info); +struct ethtool_rxfh_context * +ethtool_rxfh_ctx_alloc (const struct ethtool_ops *ops, +u32 indir_size,u32 key_size);int ethtool_check_rss_ctx_busy (struct net_device *dev,u32 rss_context);int ethtool_rxfh_config_is_sym (u64 rxfh);
net/ethtool/common.c +34 -0
@@ -806,6 +806,40 @@ int ethtool_check_rss_ctx_busy(struct net_device *dev, u32 rss_context)return rc; } +struct ethtool_rxfh_context * +ethtool_rxfh_ctx_alloc (const struct ethtool_ops *ops, +u32 indir_size,u32 key_size) +{ +size_t indir_bytes, flex_len, key_off, size; +struct ethtool_rxfh_context *ctx; +u32 priv_bytes, indir_max; +u16 key_max; + + key_max =max (key_size, ops->rxfh_key_space); + indir_max =max (indir_size, ops->rxfh_indir_space); + + priv_bytes =ALIGN (ops->rxfh_priv_size,sizeof (u32)); + indir_bytes =array_size (indir_max,sizeof (u32)); + + key_off =size_add (priv_bytes, indir_bytes); + flex_len =size_add (key_off, key_max); + size = struct_size_t(struct ethtool_rxfh_context, data, flex_len); + + ctx =kzalloc (size,GFP_KERNEL_ACCOUNT ); +if (!ctx) +return NULL ; + + ctx->indir_size = indir_size; + ctx->key_size = key_size; + ctx->key_off = key_off; + ctx->priv_size = ops->rxfh_priv_size; + + ctx->hfunc =ETH_RSS_HASH_NO_CHANGE ; + ctx->input_xfrm =RXH_XFRM_NO_CHANGE ; + +return ctx; +} +/* Check if fields configured for flow hash are symmetric - if src is included * so is dst and vice versa. */
net/ethtool/ioctl.c +0 -34
@@ -1473,40 +1473,6 @@ static noinline_for_stack int ethtool_get_rxfh(struct net_device *dev,return ret; } -static struct ethtool_rxfh_context * -ethtool_rxfh_ctx_alloc (const struct ethtool_ops *ops, -u32 indir_size,u32 key_size) -{ -size_t indir_bytes, flex_len, key_off, size; -struct ethtool_rxfh_context *ctx; -u32 priv_bytes, indir_max; -u16 key_max; - - key_max =max (key_size, ops->rxfh_key_space); - indir_max =max (indir_size, ops->rxfh_indir_space); - - priv_bytes =ALIGN (ops->rxfh_priv_size,sizeof (u32)); - indir_bytes =array_size (indir_max,sizeof (u32)); - - key_off =size_add (priv_bytes, indir_bytes); - flex_len =size_add (key_off, key_max); - size = struct_size_t(struct ethtool_rxfh_context, data, flex_len); - - ctx =kzalloc (size,GFP_KERNEL_ACCOUNT ); -if (!ctx) -return NULL ; - - ctx->indir_size = indir_size; - ctx->key_size = key_size; - ctx->key_off = key_off; - ctx->priv_size = ops->rxfh_priv_size; - - ctx->hfunc =ETH_RSS_HASH_NO_CHANGE ; - ctx->input_xfrm =RXH_XFRM_NO_CHANGE ; - -return ctx; -} - static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,void __user *useraddr) {
Signature · 1 line
2.50.1
Re: [PATCH net-next 5/8] ethtool: move ethtool_rxfh_ctx_alloc() to common code
Quoted 3 lines · Jakub Kicinski
Move
ethtool_rxfh_ctx_alloc()to common code, Netlink will need it.Signed-off-by Jakub Kicinski <[email protected]>
Jakub Kicinski
maintainerPATCH 6/8 ethtool: rss: support creating contexts via Netlink
In reply to Jakub KicinskiSupport creating contexts via Netlink. Setting flow hashing fields on the new context is not supported at this stage, it can be added later.
An empty indirection table is not supported. This is a carry over from the IOCTL interface where empty indirection table meant delete. We can repurpose empty indirection table in Netlink but for now to avoid confusion reject it using the policy.
--- Documentation/netlink/specs/ethtool.yaml | 23 +- Documentation/networking/ethtool-netlink.rst | 27 +++ .../uapi/linux/ethtool_netlink_generated.h | 3 + net/ethtool/netlink.h | 3 + net/ethtool/ioctl.c | 1 + net/ethtool/netlink.c | 15 ++ net/ethtool/rss.c | 203 ++++++++++++++++++ 7 files changed, 273 insertions(+), 2 deletions(-)
Documentation/netlink/specs/ethtool.yaml +21 -2
@@ -2684,9 +2684,28 @@ c-version-name: ethtool-genl-version name: rss-ntf doc: | Notification for change in RSS configuration. - For additional contexts only modifications are modified, not creation - or removal of the contexts. + For additional contexts only modifications use this notification, + creation and deletion have dedicated messages. notify: rss-get + - + name: rss-create-act + doc: Create an RSS context. + attribute-set: rss + do: + request: &rss-create-attrs + attributes: + - header + - context + - hfunc + - indir + - hkey + - input-xfrm + reply: *rss-create-attrs + - + name: rss-create-ntf + doc: | + Notification for creation of an additional RSS context. + notify: rss-create-act mcast-groups: list:
Documentation/networking/ethtool-netlink.rst +27 -0
@@ -240,6 +240,7 @@ All constants identifying message types use ``ETHTOOL_CMD_`` prefix and suffix ``ETHTOOL_MSG_TSCONFIG_GET`` get hw timestamping configuration ``ETHTOOL_MSG_TSCONFIG_SET`` set hw timestamping configuration ``ETHTOOL_MSG_RSS_SET`` set RSS settings + ``ETHTOOL_MSG_RSS_CREATE_ACT`` create an additional RSS context ===================================== ================================= Kernel to userspace:
@@ -294,6 +295,8 @@ All constants identifying message types use ``ETHTOOL_CMD_`` prefix and suffix ``ETHTOOL_MSG_TSCONFIG_SET_REPLY`` new hw timestamping configuration ``ETHTOOL_MSG_PSE_NTF`` PSE events notification ``ETHTOOL_MSG_RSS_NTF`` RSS settings notification + ``ETHTOOL_MSG_RSS_CREATE_ACT_REPLY`` create an additional RSS context + ``ETHTOOL_MSG_RSS_CREATE_NTF`` additional RSS context created ======================================== ================================= ``GET`` requests are sent by userspace applications to retrieve device
@@ -2014,6 +2017,30 @@ device needs at least 8 entries - the real table in use will end up being of 2, so tables which size is not a power of 2 will likely be rejected. Using table of size 0 will reset the indirection table to the default. +RSS_CREATE_ACT +============== + +Request contents: + +===================================== ====== ============================== + ``ETHTOOL_A_RSS_HEADER`` nested request header + ``ETHTOOL_A_RSS_CONTEXT`` u32 context number + ``ETHTOOL_A_RSS_HFUNC`` u32 RSS hash func + ``ETHTOOL_A_RSS_INDIR`` binary Indir table bytes + ``ETHTOOL_A_RSS_HKEY`` binary Hash key bytes + ``ETHTOOL_A_RSS_INPUT_XFRM`` u32 RSS input data transformation +===================================== ====== ============================== + +Kernel response contents: + +===================================== ====== ============================== + ``ETHTOOL_A_RSS_HEADER`` nested request header + ``ETHTOOL_A_RSS_CONTEXT`` u32 context number +===================================== ====== ============================== + +Create an additional RSS context, if ``ETHTOOL_A_RSS_CONTEXT`` is not +specified kernel will allocate one automatically. + PLCA_GET_CFG ============
include/uapi/linux/ethtool_netlink_generated.h +3 -0
@@ -841,6 +841,7 @@ enum {ETHTOOL_MSG_TSCONFIG_GET ,ETHTOOL_MSG_TSCONFIG_SET ,ETHTOOL_MSG_RSS_SET , +ETHTOOL_MSG_RSS_CREATE_ACT , __ETHTOOL_MSG_USER_CNT,ETHTOOL_MSG_USER_MAX = (__ETHTOOL_MSG_USER_CNT -1 )
@@ -898,6 +899,8 @@ enum {ETHTOOL_MSG_TSCONFIG_SET_REPLY ,ETHTOOL_MSG_PSE_NTF ,ETHTOOL_MSG_RSS_NTF , +ETHTOOL_MSG_RSS_CREATE_ACT_REPLY , +ETHTOOL_MSG_RSS_CREATE_NTF , __ETHTOOL_MSG_KERNEL_CNT,ETHTOOL_MSG_KERNEL_MAX = (__ETHTOOL_MSG_KERNEL_CNT -1 )
net/ethtool/netlink.h +3 -0
@@ -10,6 +10,7 @@struct ethnl_req_info ; +u32 ethnl_bcast_seq_next (void ); int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info, const struct nlattr *nest, struct net *net, struct netlink_ext_ack *extack,
@@ -485,6 +486,7 @@ extern const struct nla_policy ethnl_pse_get_policy[ETHTOOL_A_PSE_HEADER + 1];extern const struct nla_policy ethnl_pse_set_policy[ETHTOOL_A_PSE_MAX +1 ];extern const struct nla_policy ethnl_rss_get_policy[ETHTOOL_A_RSS_START_CONTEXT +1 ];extern const struct nla_policy ethnl_rss_set_policy[ETHTOOL_A_RSS_FLOW_HASH +1 ]; +extern const struct nla_policy ethnl_rss_create_policy[ETHTOOL_A_RSS_INPUT_XFRM +1 ];extern const struct nla_policy ethnl_plca_get_cfg_policy[ETHTOOL_A_PLCA_HEADER +1 ];extern const struct nla_policy ethnl_plca_set_cfg_policy[ETHTOOL_A_PLCA_MAX +1 ];extern const struct nla_policy ethnl_plca_get_status_policy[ETHTOOL_A_PLCA_HEADER +1 ];
@@ -507,6 +509,7 @@ int ethnl_rss_dumpit(struct sk_buff *skb, struct netlink_callback *cb);int ethnl_tsinfo_start (struct netlink_callback *cb);int ethnl_tsinfo_dumpit (struct sk_buff *skb,struct netlink_callback *cb);int ethnl_tsinfo_done (struct netlink_callback *cb); +int ethnl_rss_create_doit (struct sk_buff *skb,struct genl_info *info);extern const char stats_std_names[__ETHTOOL_STATS_CNT][ETH_GSTRING_LEN ];extern const char stats_eth_phy_names[__ETHTOOL_A_STATS_ETH_PHY_CNT][ETH_GSTRING_LEN ];
net/ethtool/ioctl.c +1 -0
@@ -1640,6 +1640,7 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, ntf =ETHTOOL_MSG_RSS_NTF ; ret = ops->set_rxfh (dev, &rxfh_dev, extack); }else if (create) { + ntf =ETHTOOL_MSG_RSS_CREATE_NTF ; ret = ops->create_rxfh_context (dev, ctx, &rxfh_dev, extack);/* Make sure driver populates defaults */ WARN_ON_ONCE(!ret && !rxfh_dev.key && ops->rxfh_per_ctx_key &&
net/ethtool/netlink.c +15 -0
@@ -81,6 +81,12 @@ static void ethnl_sock_priv_destroy(void *priv) } } +u32 ethnl_bcast_seq_next (void ) +{ +ASSERT_RTNL (); +return ++ethnl_bcast_seq; +} +int ethnl_ops_begin (struct net_device *dev) {int ret;
@@ -954,6 +960,7 @@ ethnl_default_notify_ops[ETHTOOL_MSG_KERNEL_MAX + 1] = { [ETHTOOL_MSG_PLCA_NTF] = ðnl_plca_cfg_request_ops, [ETHTOOL_MSG_MM_NTF] = ðnl_mm_request_ops, [ETHTOOL_MSG_RSS_NTF] = ðnl_rss_request_ops, + [ETHTOOL_MSG_RSS_CREATE_NTF] = ðnl_rss_request_ops, };/* default notification handler */
@@ -1061,6 +1068,7 @@ static const ethnl_notify_handler_t ethnl_notify_handlers[] = { [ETHTOOL_MSG_PLCA_NTF] = ethnl_default_notify, [ETHTOOL_MSG_MM_NTF] = ethnl_default_notify, [ETHTOOL_MSG_RSS_NTF] = ethnl_default_notify, + [ETHTOOL_MSG_RSS_CREATE_NTF] = ethnl_default_notify, }; void ethnl_notify(struct net_device *dev, unsigned int cmd,
@@ -1512,6 +1520,13 @@ static const struct genl_ops ethtool_genl_ops[] = { .policy = ethnl_rss_set_policy, .maxattr = ARRAY_SIZE(ethnl_rss_set_policy) - 1, }, + { + .cmd = ETHTOOL_MSG_RSS_CREATE_ACT, + .flags = GENL_UNS_ADMIN_PERM, + .doit = ethnl_rss_create_doit, + .policy = ethnl_rss_create_policy, + .maxattr = ARRAY_SIZE(ethnl_rss_create_policy) - 1, + }, };static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/rss.c +203 -0
206 lines not on this page · raw message
Signature · 1 line
2.50.1
Re: [PATCH net-next 6/8] ethtool: rss: support creating contexts via Netlink
Documentation/networking/ethtool-netlink.rst device needs at least 8 entries - the real table in use will end up being · line 2042
Quoted 9 lines · Jakub Kicinski
Documentation/networking/ethtool-netlink.rst +9
-0+Kernel response contents: + +===================================== ====== ============================== + ``ETHTOOL_A_RSS_HEADER`` nested request header + ``ETHTOOL_A_RSS_CONTEXT`` u32 context number +===================================== ====== ============================== + +Create an additional RSS context, if ``ETHTOOL_A_RSS_CONTEXT`` is not +specified kernel will allocate one automatically.
We don't support choosing the context id from userspace in ioctl flow, I think it should be stated somewhere (at the least, in the commit message?).
Jakub Kicinski
maintainerRe: [PATCH net-next 6/8] ethtool: rss: support creating contexts via Netlink
Quoted 13 lines · On Sun, 20 Jul 2025 14:42:36 +0300 Gal Pressman wrote:
Documentation/networking/ethtool-netlink.rst device needs at least 8 entries - the real table in use will end up being · line 2042
Quoted 9 lines · Jakub Kicinski
Documentation/networking/ethtool-netlink.rst +9
-0+Kernel response contents: + +===================================== ====== ============================== + ``ETHTOOL_A_RSS_HEADER`` nested request header + ``ETHTOOL_A_RSS_CONTEXT`` u32 context number +===================================== ====== ============================== + +Create an additional RSS context, if ``ETHTOOL_A_RSS_CONTEXT`` is not +specified kernel will allocate one automatically.We don't support choosing the context id from userspace in ioctl flow, I think it should be stated somewhere (at the least, in the commit message?).
Sure, how about:
Support letting user choose the ID for the new context. This was not possible in IOCTL since the context ID field for the create action had to be set to the ETH_RXFH_CONTEXT_ALLOC magic value.
Re: [PATCH net-next 6/8] ethtool: rss: support creating contexts via Netlink
Quoted 15 lines · Jakub Kicinski
Quoted 13 lines · On Sun, 20 Jul 2025 14:42:36 +0300 Gal Pressman wrote:
Documentation/networking/ethtool-netlink.rst device needs at least 8 entries - the real table in use will end up being · line 2042
Quoted 9 lines · Jakub Kicinski
Documentation/networking/ethtool-netlink.rst +9
-0+Kernel response contents: + +===================================== ====== ============================== + ``ETHTOOL_A_RSS_HEADER`` nested request header + ``ETHTOOL_A_RSS_CONTEXT`` u32 context number +===================================== ====== ============================== + +Create an additional RSS context, if ``ETHTOOL_A_RSS_CONTEXT`` is not +specified kernel will allocate one automatically.We don't support choosing the context id from userspace in ioctl flow, I think it should be stated somewhere (at the least, in the commit message?).
Quoted 5 lines
Sure, how about:
Support letting user choose the ID for the new context. This was not possible in IOCTL since the context ID field for the create action had to be set to the
ETH_RXFH_CONTEXT_ALLOCmagic value.
Perfect, thanks!
Jakub Kicinski
maintainerPATCH 7/8 ethtool: rss: support removing contexts via Netlink
In reply to Jakub KicinskiImplement removing additional RSS contexts via Netlink. Technically it'd be possible to shoehorn the delete operation into ethnl_request_ops-compatible handler. The code ends up longer than open coded version, and I think we'll need a custom way of sending notifications at some stage (if we allow tying the context lifetime to the netlink socket, in the future).
--- Documentation/netlink/specs/ethtool.yaml | 18 +++ Documentation/networking/ethtool-netlink.rst | 14 +++ .../uapi/linux/ethtool_netlink_generated.h | 2 + net/ethtool/netlink.h | 2 + net/ethtool/common.c | 1 + net/ethtool/ioctl.c | 1 + net/ethtool/netlink.c | 7 ++ net/ethtool/rss.c | 109 +++++++++++++++++- 8 files changed, 153 insertions(+), 1 deletion(-)
Documentation/netlink/specs/ethtool.yaml +18 -0
@@ -2706,6 +2706,24 @@ c-version-name: ethtool-genl-version doc: | Notification for creation of an additional RSS context. notify: rss-create-act + - + name: rss-delete-act + doc: Delete an RSS context. + attribute-set: rss + do: + request: + attributes: + - header + - context + - + name: rss-delete-ntf + doc: | + Notification for deletion of an additional RSS context. + attribute-set: rss + event: + attributes: + - header + - context mcast-groups: list:
Documentation/networking/ethtool-netlink.rst +14 -0
@@ -241,6 +241,7 @@ All constants identifying message types use ``ETHTOOL_CMD_`` prefix and suffix ``ETHTOOL_MSG_TSCONFIG_SET`` set hw timestamping configuration ``ETHTOOL_MSG_RSS_SET`` set RSS settings ``ETHTOOL_MSG_RSS_CREATE_ACT`` create an additional RSS context + ``ETHTOOL_MSG_RSS_DELETE_ACT`` delete an additional RSS context ===================================== ================================= Kernel to userspace:
@@ -297,6 +298,7 @@ All constants identifying message types use ``ETHTOOL_CMD_`` prefix and suffix ``ETHTOOL_MSG_RSS_NTF`` RSS settings notification ``ETHTOOL_MSG_RSS_CREATE_ACT_REPLY`` create an additional RSS context ``ETHTOOL_MSG_RSS_CREATE_NTF`` additional RSS context created + ``ETHTOOL_MSG_RSS_DELETE_NTF`` additional RSS context deleted ======================================== ================================= ``GET`` requests are sent by userspace applications to retrieve device
@@ -2041,6 +2043,18 @@ RSS_CREATE_ACT Create an additional RSS context, if ``ETHTOOL_A_RSS_CONTEXT`` is not specified kernel will allocate one automatically. +RSS_DELETE_ACT +============== + +Request contents: + +===================================== ====== ============================== + ``ETHTOOL_A_RSS_HEADER`` nested request header + ``ETHTOOL_A_RSS_CONTEXT`` u32 context number +===================================== ====== ============================== + +Delete an additional RSS context. + PLCA_GET_CFG ============
include/uapi/linux/ethtool_netlink_generated.h +2 -0
@@ -842,6 +842,7 @@ enum {ETHTOOL_MSG_TSCONFIG_SET ,ETHTOOL_MSG_RSS_SET ,ETHTOOL_MSG_RSS_CREATE_ACT , +ETHTOOL_MSG_RSS_DELETE_ACT , __ETHTOOL_MSG_USER_CNT,ETHTOOL_MSG_USER_MAX = (__ETHTOOL_MSG_USER_CNT -1 )
@@ -901,6 +902,7 @@ enum {ETHTOOL_MSG_RSS_NTF ,ETHTOOL_MSG_RSS_CREATE_ACT_REPLY ,ETHTOOL_MSG_RSS_CREATE_NTF , +ETHTOOL_MSG_RSS_DELETE_NTF , __ETHTOOL_MSG_KERNEL_CNT,ETHTOOL_MSG_KERNEL_MAX = (__ETHTOOL_MSG_KERNEL_CNT -1 )
net/ethtool/netlink.h +2 -0
@@ -487,6 +487,7 @@ extern const struct nla_policy ethnl_pse_set_policy[ETHTOOL_A_PSE_MAX + 1];extern const struct nla_policy ethnl_rss_get_policy[ETHTOOL_A_RSS_START_CONTEXT +1 ];extern const struct nla_policy ethnl_rss_set_policy[ETHTOOL_A_RSS_FLOW_HASH +1 ];extern const struct nla_policy ethnl_rss_create_policy[ETHTOOL_A_RSS_INPUT_XFRM +1 ]; +extern const struct nla_policy ethnl_rss_delete_policy[ETHTOOL_A_RSS_CONTEXT +1 ];extern const struct nla_policy ethnl_plca_get_cfg_policy[ETHTOOL_A_PLCA_HEADER +1 ];extern const struct nla_policy ethnl_plca_set_cfg_policy[ETHTOOL_A_PLCA_MAX +1 ];extern const struct nla_policy ethnl_plca_get_status_policy[ETHTOOL_A_PLCA_HEADER +1 ];
@@ -510,6 +511,7 @@ int ethnl_tsinfo_start(struct netlink_callback *cb);int ethnl_tsinfo_dumpit (struct sk_buff *skb,struct netlink_callback *cb);int ethnl_tsinfo_done (struct netlink_callback *cb);int ethnl_rss_create_doit (struct sk_buff *skb,struct genl_info *info); +int ethnl_rss_delete_doit (struct sk_buff *skb,struct genl_info *info);extern const char stats_std_names[__ETHTOOL_STATS_CNT][ETH_GSTRING_LEN ];extern const char stats_eth_phy_names[__ETHTOOL_A_STATS_ETH_PHY_CNT][ETH_GSTRING_LEN ];
net/ethtool/common.c +1 -0
@@ -1136,5 +1136,6 @@ void ethtool_rxfh_context_lost(struct net_device *dev, u32 context_id)netdev_err (dev,"device error, RSS context %d lost\n" , context_id); ctx =xa_erase (&dev->ethtool->rss_ctx, context_id);kfree (ctx); +ethtool_rss_notify (dev,ETHTOOL_MSG_RSS_DELETE_NTF , context_id); }EXPORT_SYMBOL (ethtool_rxfh_context_lost);
net/ethtool/ioctl.c +1 -0
@@ -1647,6 +1647,7 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, !memchr_inv (ethtool_rxfh_context_key (ctx),0 , ctx->key_size)); }else if (rxfh_dev.rss_delete) { + ntf =ETHTOOL_MSG_RSS_DELETE_NTF ; ret = ops->remove_rxfh_context (dev, ctx, rxfh.rss_context, extack); }else {
net/ethtool/netlink.c +7 -0
@@ -1527,6 +1527,13 @@ static const struct genl_ops ethtool_genl_ops[] = { .policy = ethnl_rss_create_policy, .maxattr = ARRAY_SIZE(ethnl_rss_create_policy) - 1, }, + { + .cmd = ETHTOOL_MSG_RSS_DELETE_ACT, + .flags = GENL_UNS_ADMIN_PERM, + .doit = ethnl_rss_delete_doit, + .policy = ethnl_rss_delete_policy, + .maxattr = ARRAY_SIZE(ethnl_rss_delete_policy) - 1, + }, };static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/rss.c +108 -1
124 lines not on this page · raw message
Signature · 1 line
2.50.1
Jakub Kicinski
maintainerPATCH 8/8 selftests: drv-net: rss_api: context create and delete tests
In reply to Jakub KicinskiAdd test cases for creating and deleting contexts.
TAP version 13
1..12
ok 1 rss_api.test_rxfh_nl_set_fail
ok 2 rss_api.test_rxfh_nl_set_indir
ok 3 rss_api.test_rxfh_nl_set_indir_ctx
ok 4 rss_api.test_rxfh_indir_ntf
ok 5 rss_api.test_rxfh_indir_ctx_ntf
ok 6 rss_api.test_rxfh_nl_set_key
ok 7 rss_api.test_rxfh_fields
ok 8 rss_api.test_rxfh_fields_set
ok 9 rss_api.test_rxfh_fields_set_xfrm # SKIP no input-xfrm supported ok 10 rss_api.test_rxfh_fields_ntf
ok 11 rss_api.test_rss_ctx_add
ok 12 rss_api.test_rss_ctx_ntf
# Totals: pass:11 fail:0 xfail:0 xpass:0 skip:1 error:0
--- .../selftests/drivers/net/hw/rss_api.py | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+)
tools/testing/selftests/drivers/net/hw/rss_api.py +73 -0
@@ -5,6 +5,7 @@ API level tests for RSS (mostly Netlink vs IOCTL). """ +import errno import glob import random from lib.py import ksft_run, ksft_exit, ksft_eq, ksft_is, ksft_ne, ksft_raises
@@ -390,6 +391,78 @@ from lib.py import NetDrvEnv ksft_eq(next(ethnl.poll_ntf(duration=0.01), None), None) +def test_rss_ctx_add(cfg): + """ Test creating an additional RSS context via Netlink """ + + _require_2qs(cfg) + + # Test basic creation + ctx = cfg.ethnl.rss_create_act({"header": {"dev-index": cfg.ifindex}}) + d = defer(ethtool, f"-X {cfg.ifname} context {ctx.get('context')} delete") + ksft_ne(ctx.get("context", 0), 0) + ksft_ne(set(ctx.get("indir", [0])), {0}, + comment="Driver should init the indirection table") + + # Try requesting the ID we just got allocated + with ksft_raises(NlError) as cm: + ctx = cfg.ethnl.rss_create_act({ + "header": {"dev-index": cfg.ifindex}, + "context": ctx.get("context"), + }) + ethtool(f"-X {cfg.ifname} context {ctx.get('context')} delete") + d.exec() + ksft_eq(cm.exception.nl_msg.error, -errno.EBUSY) + + # Test creating with a specified RSS table, and context ID + ctx_id = ctx.get("context") + ctx = cfg.ethnl.rss_create_act({ + "header": {"dev-index": cfg.ifindex}, + "context": ctx_id, + "indir": [1], + }) + ethtool(f"-X {cfg.ifname} context {ctx.get('context')} delete") + ksft_eq(ctx.get("context"), ctx_id) + ksft_eq(set(ctx.get("indir", [0])), {1}) + + +def test_rss_ctx_ntf(cfg): + """ Test notifications for creating additional RSS contexts """ + + ethnl = EthtoolFamily() + ethnl.ntf_subscribe("monitor") + + # Create / delete via Netlink + ctx = cfg.ethnl.rss_create_act({"header": {"dev-index": cfg.ifindex}}) + cfg.ethnl.rss_delete_act({ + "header": {"dev-index": cfg.ifindex}, + "context": ctx["context"], + }) + + ntf = next(ethnl.poll_ntf(duration=0.2), None) + if ntf is None: + raise KsftFailEx("[NL] No notification after context creation") + ksft_eq(ntf["name"], "rss-create-ntf") + ksft_eq(ctx, ntf["msg"]) + + ntf = next(ethnl.poll_ntf(duration=0.2), None) + if ntf is None: + raise KsftFailEx("[NL] No notification after context deletion") + ksft_eq(ntf["name"], "rss-delete-ntf") + + # Create / deleve via IOCTL + ctx_id = _ethtool_create(cfg, "--disable-netlink -X", "context new") + ethtool(f"--disable-netlink -X {cfg.ifname} context {ctx_id} delete") + ntf = next(ethnl.poll_ntf(duration=0.2), None) + if ntf is None: + raise KsftFailEx("[IOCTL] No notification after context creation") + ksft_eq(ntf["name"], "rss-create-ntf") + + ntf = next(ethnl.poll_ntf(duration=0.2), None) + if ntf is None: + raise KsftFailEx("[IOCTL] No notification after context deletion") + ksft_eq(ntf["name"], "rss-delete-ntf") + + def main() -> None: """ Ksft boiler plate main """
Signature · 1 line
2.50.1
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Thu, 17 Jul 2025 16:43:35 -0700 you wrote:
This series completes support of RSS configuration via Netlink. All functionality supported by the IOCTL is now supported by Netlink. Future series (time allowing) will add:
- hashing on the flow label, which started this whole thing;
- pinning the RSS context to a Netlink socket for auto-cleanup.The first patch is a leftover held back from previous series to avoid conflicting with Gal's fix.
[...]
Here is the summary with links:
- [net-next,1/8] ethtool: assert that drivers with sym hash are consistent for RSS contexts
https://git.kernel.org/netdev/net-next/c/80e55735d5a5 - [net-next,2/8] ethtool: rejig the RSS notification machinery for more types https://git.kernel.org/netdev/net-next/c/5f5c59b78e5a - [net-next,3/8] ethtool: rss: factor out allocating memory for response https://git.kernel.org/netdev/net-next/c/a45f98efa483 - [net-next,4/8] ethtool: rss: factor out populating response from context https://git.kernel.org/netdev/net-next/c/5c090d9eae88 - [net-next,5/8] ethtool: move ethtool_rxfh_ctx_alloc() to common code https://git.kernel.org/netdev/net-next/c/55ef461ce18f - [net-next,6/8] ethtool: rss: support creating contexts via Netlink https://git.kernel.org/netdev/net-next/c/a166ab7816c5 - [net-next,7/8] ethtool: rss: support removing contexts via Netlink https://git.kernel.org/netdev/net-next/c/fbe09277fa63 - [net-next,8/8] selftests: drv-net: rss_api: context create and delete tests https://git.kernel.org/netdev/net-next/c/4c86c9fdf6a5
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html