Subject: Re: [PATCH net-next v2 09/12] ethtool: rss: support dumping RSS contexts

From: Edward Cree <[email-masked]>
Date: Tue, 6 Aug 2024 15:24:50 +0100

On 03/08/2024 05:26, Jakub Kicinski wrote:
> 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).
> 
> Signed-off-by: Jakub Kicinski <[email-masked]>
...
> +	if (!ctx->ctx_idx) {
> +		ret = rss_dump_one_ctx(skb, cb, dev, 0);
> +		if (ret)
> +			return ret;
> +		ctx->ctx_idx++;
> +	}

Maybe comment this block with something like "context 0 is
 not stored in the XArray" to make clear why this is split
 out from a loop that looks like it should be able to handle
 it.

> +
> +	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;

Feels like there has to be a way to do this with
 xa_for_each_start()?  Something like (untested):

	struct ethtool_rxfh_context *rss_ctx;

	xa_for_each_start(&dev->ethtool->rss_ctx, ctx->ctx_idx,
			  rss_ctx, ctx->ctx_idx) {
		ret = rss_dump_one_ctx(skb, cb, dev, ctx->ctx_idx);
		if (ret)
			return ret;
	}
	ctx->ctx_idx = 0;