]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ethtool: rss: support dumping RSS contexts
authorJakub Kicinski <kuba@kernel.org>
Sat, 10 Aug 2024 05:37:25 +0000 (22:37 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 12 Aug 2024 13:16:24 +0000 (14:16 +0100)
Now that we track RSS contexts in the core we can easily dump
them. This is a major introspection improvement, as previously
the only way to find all contexts would be to try all ids
(of which there may be 2^32 - 1).

Don't use the XArray iterators (like xa_for_each_start()) as they
do not move the index past the end of the array once done, which
caused multiple bugs in Netlink dumps in the past.

Reviewed-by: Edward Cree <ecree.xilinx@gmail.com>
Reviewed-by: Joe Damato <jdamato@fastly.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Documentation/netlink/specs/ethtool.yaml
net/ethtool/netlink.c
net/ethtool/netlink.h
net/ethtool/rss.c

index ea21fe135b97eb26f2d90967a31128799e92f2e7..cf69eedae51d27d2776650e32097439133bdc4d0 100644 (file)
@@ -1749,12 +1749,12 @@ operations:
 
       attribute-set: rss
 
-      do: &rss-get-op
+      do:
         request:
           attributes:
             - header
             - context
-        reply:
+        reply: &rss-reply
           attributes:
             - header
             - context
@@ -1762,6 +1762,11 @@ operations:
             - indir
             - hkey
             - input_xfrm
+      dump:
+        request:
+          attributes:
+            - header
+        reply: *rss-reply
     -
       name: plca-get-cfg
       doc: Get PLCA params.
index cb1eea00e349896a5f5ab3596f1b0e89882a7390..041548e5f5e640a0974d286dbd3f8fb7f6a703b4 100644 (file)
@@ -1128,6 +1128,8 @@ static const struct genl_ops ethtool_genl_ops[] = {
        {
                .cmd    = ETHTOOL_MSG_RSS_GET,
                .doit   = ethnl_default_doit,
+               .start  = ethnl_rss_dump_start,
+               .dumpit = ethnl_rss_dumpit,
                .policy = ethnl_rss_get_policy,
                .maxattr = ARRAY_SIZE(ethnl_rss_get_policy) - 1,
        },
index 46ec273a87c5c63ec706233f8e3183327108d20c..919371383b235fdc27b2aea1651579d46f69cf3a 100644 (file)
@@ -464,6 +464,8 @@ int ethnl_tunnel_info_doit(struct sk_buff *skb, struct genl_info *info);
 int ethnl_tunnel_info_start(struct netlink_callback *cb);
 int ethnl_tunnel_info_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
 int ethnl_act_module_fw_flash(struct sk_buff *skb, struct genl_info *info);
+int ethnl_rss_dump_start(struct netlink_callback *cb);
+int ethnl_rss_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
 
 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];
index 023782ca1230d3c5195d8e426992dc87f11f9ca6..2865720ff583dfa9ff202faa8383cf5eaa58b44c 100644 (file)
@@ -208,6 +208,141 @@ static void rss_cleanup_data(struct ethnl_reply_data *reply_base)
        kfree(data->indir_table);
 }
 
+struct rss_nl_dump_ctx {
+       unsigned long           ifindex;
+       unsigned long           ctx_idx;
+
+       /* User wants to only dump contexts from given ifindex */
+       unsigned int            match_ifindex;
+};
+
+static struct rss_nl_dump_ctx *rss_dump_ctx(struct netlink_callback *cb)
+{
+       NL_ASSERT_DUMP_CTX_FITS(struct rss_nl_dump_ctx);
+
+       return (struct rss_nl_dump_ctx *)cb->ctx;
+}
+
+int ethnl_rss_dump_start(struct netlink_callback *cb)
+{
+       const struct genl_info *info = genl_info_dump(cb);
+       struct rss_nl_dump_ctx *ctx = rss_dump_ctx(cb);
+       struct ethnl_req_info req_info = {};
+       struct nlattr **tb = info->attrs;
+       int ret;
+
+       /* Filtering by context not supported */
+       if (tb[ETHTOOL_A_RSS_CONTEXT]) {
+               NL_SET_BAD_ATTR(info->extack, tb[ETHTOOL_A_RSS_CONTEXT]);
+               return -EINVAL;
+       }
+
+       ret = ethnl_parse_header_dev_get(&req_info,
+                                        tb[ETHTOOL_A_RSS_HEADER],
+                                        sock_net(cb->skb->sk), cb->extack,
+                                        false);
+       if (req_info.dev) {
+               ctx->match_ifindex = req_info.dev->ifindex;
+               ctx->ifindex = ctx->match_ifindex;
+               ethnl_parse_header_dev_put(&req_info);
+               req_info.dev = NULL;
+       }
+
+       return ret;
+}
+
+static int
+rss_dump_one_ctx(struct sk_buff *skb, struct netlink_callback *cb,
+                struct net_device *dev, u32 rss_context)
+{
+       const struct genl_info *info = genl_info_dump(cb);
+       struct rss_reply_data data = {};
+       struct rss_req_info req = {};
+       void *ehdr;
+       int ret;
+
+       req.rss_context = rss_context;
+
+       ehdr = ethnl_dump_put(skb, cb, ETHTOOL_MSG_RSS_GET_REPLY);
+       if (!ehdr)
+               return -EMSGSIZE;
+
+       ret = ethnl_fill_reply_header(skb, dev, ETHTOOL_A_RSS_HEADER);
+       if (ret < 0)
+               goto err_cancel;
+
+       /* Context 0 is not currently storred or cached in the XArray */
+       if (!rss_context)
+               ret = rss_prepare_get(&req, dev, &data, info);
+       else
+               ret = rss_prepare_ctx(&req, dev, &data, info);
+       if (ret)
+               goto err_cancel;
+
+       ret = rss_fill_reply(skb, &req.base, &data.base);
+       if (ret)
+               goto err_cleanup;
+       genlmsg_end(skb, ehdr);
+
+       rss_cleanup_data(&data.base);
+       return 0;
+
+err_cleanup:
+       rss_cleanup_data(&data.base);
+err_cancel:
+       genlmsg_cancel(skb, ehdr);
+       return ret;
+}
+
+static int
+rss_dump_one_dev(struct sk_buff *skb, struct netlink_callback *cb,
+                struct net_device *dev)
+{
+       struct rss_nl_dump_ctx *ctx = rss_dump_ctx(cb);
+       int ret;
+
+       if (!dev->ethtool_ops->get_rxfh)
+               return 0;
+
+       if (!ctx->ctx_idx) {
+               ret = rss_dump_one_ctx(skb, cb, dev, 0);
+               if (ret)
+                       return ret;
+               ctx->ctx_idx++;
+       }
+
+       for (; xa_find(&dev->ethtool->rss_ctx, &ctx->ctx_idx,
+                      ULONG_MAX, XA_PRESENT); ctx->ctx_idx++) {
+               ret = rss_dump_one_ctx(skb, cb, dev, ctx->ctx_idx);
+               if (ret)
+                       return ret;
+       }
+       ctx->ctx_idx = 0;
+
+       return 0;
+}
+
+int ethnl_rss_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
+{
+       struct rss_nl_dump_ctx *ctx = rss_dump_ctx(cb);
+       struct net *net = sock_net(skb->sk);
+       struct net_device *dev;
+       int ret = 0;
+
+       rtnl_lock();
+       for_each_netdev_dump(net, dev, ctx->ifindex) {
+               if (ctx->match_ifindex && ctx->match_ifindex != ctx->ifindex)
+                       break;
+
+               ret = rss_dump_one_dev(skb, cb, dev);
+               if (ret)
+                       break;
+       }
+       rtnl_unlock();
+
+       return ret;
+}
+
 const struct ethnl_request_ops ethnl_rss_request_ops = {
        .request_cmd            = ETHTOOL_MSG_RSS_GET,
        .reply_cmd              = ETHTOOL_MSG_RSS_GET_REPLY,