Skip to content

Commit 82ae67c

Browse files
committed
ethtool: rss: support setting hfunc via Netlink
Support setting RSS hash function / algo via ethtool Netlink. Like IOCTL we don't validate that the function is within the range known to the kernel. The drivers do a pretty good job validating the inputs, and the IDs are technically "dynamically queried" rather than part of uAPI. Only change should be that in Netlink we don't support user explicitly passing ETH_RSS_HASH_NO_CHANGE (0), if no change is requested the attribute should be absent. The ETH_RSS_HASH_NO_CHANGE is retained in driver-facing API for consistency (not that I see a strong reason for it). Reviewed-by: Gal Pressman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 6e7eb93 commit 82ae67c

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Documentation/netlink/specs/ethtool.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,6 +2654,7 @@ operations:
26542654
attributes:
26552655
- header
26562656
- context
2657+
- hfunc
26572658
- indir
26582659
-
26592660
name: rss-ntf

Documentation/networking/ethtool-netlink.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,6 +1999,7 @@ Request contents:
19991999
===================================== ====== ==============================
20002000
``ETHTOOL_A_RSS_HEADER`` nested request header
20012001
``ETHTOOL_A_RSS_CONTEXT`` u32 context number
2002+
``ETHTOOL_A_RSS_HFUNC`` u32 RSS hash func
20022003
``ETHTOOL_A_RSS_INDIR`` binary Indir table bytes
20032004
===================================== ====== ==============================
20042005

net/ethtool/rss.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ void ethtool_rss_notify(struct net_device *dev, u32 rss_context)
475475
const struct nla_policy ethnl_rss_set_policy[ETHTOOL_A_RSS_START_CONTEXT + 1] = {
476476
[ETHTOOL_A_RSS_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy),
477477
[ETHTOOL_A_RSS_CONTEXT] = { .type = NLA_U32, },
478+
[ETHTOOL_A_RSS_HFUNC] = NLA_POLICY_MIN(NLA_U32, 1),
478479
[ETHTOOL_A_RSS_INDIR] = { .type = NLA_BINARY, },
479480
};
480481

@@ -489,6 +490,9 @@ ethnl_rss_set_validate(struct ethnl_req_info *req_info, struct genl_info *info)
489490
if (request->rss_context && !ops->create_rxfh_context)
490491
bad_attr = bad_attr ?: tb[ETHTOOL_A_RSS_CONTEXT];
491492

493+
if (request->rss_context && !ops->rxfh_per_ctx_key)
494+
bad_attr = bad_attr ?: tb[ETHTOOL_A_RSS_HFUNC];
495+
492496
if (bad_attr) {
493497
NL_SET_BAD_ATTR(info->extack, bad_attr);
494498
return -EOPNOTSUPP;
@@ -588,6 +592,8 @@ rss_set_ctx_update(struct ethtool_rxfh_context *ctx, struct nlattr **tb,
588592
ethtool_rxfh_context_indir(ctx)[i] = rxfh->indir[i];
589593
ctx->indir_configured = !!nla_len(tb[ETHTOOL_A_RSS_INDIR]);
590594
}
595+
if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE)
596+
ctx->hfunc = rxfh->hfunc;
591597
}
592598

593599
static int
@@ -618,7 +624,11 @@ ethnl_rss_set(struct ethnl_req_info *req_info, struct genl_info *info)
618624
goto exit_clean_data;
619625
indir_mod = !!tb[ETHTOOL_A_RSS_INDIR];
620626

621-
rxfh.hfunc = ETH_RSS_HASH_NO_CHANGE;
627+
rxfh.hfunc = data.hfunc;
628+
ethnl_update_u8(&rxfh.hfunc, tb[ETHTOOL_A_RSS_HFUNC], &mod);
629+
if (rxfh.hfunc == data.hfunc)
630+
rxfh.hfunc = ETH_RSS_HASH_NO_CHANGE;
631+
622632
rxfh.input_xfrm = RXH_XFRM_NO_CHANGE;
623633

624634
mutex_lock(&dev->ethtool->rss_lock);

0 commit comments

Comments
 (0)