Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: przemyslaw.kitszel@intel.com
Cc: netdev@vger.kernel.org, pabeni@redhat.com, willemb@google.com,
	donald.hunter@gmail.com, jiri@resnulli.us,
	intel-wired-lan@lists.osuosl.org, anthony.l.nguyen@intel.com,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	horms@kernel.org, andrew+netdev@lunn.ch, poros@redhat.com
Subject: Re: [PATCH net 3/3] devlink: make room for many nested instances in a dev message
Date: Thu, 03 Dec 2026 13:31:57 +0000	[thread overview]
Message-ID: <179630471718.3146.7791163240760595954@kernel.org> (raw)
In-Reply-To: <20261202124956.18277-4-przemyslaw.kitszel@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] In `devlink_nl_get_pre_dumpit()` (net/devlink/dev.c),
  `cb->min_dump_alloc` is set to the largest size estimate of any…

--

devlink: make room for many nested instances in a dev message

This commit sizes the DEVLINK_CMD_GET doit reply and the NEW/DEL
notification so they include the handles of all nested devlink instances.
For the dump, it adds a start callback that sets min_dump_alloc to the
largest estimated message size among the instances. It also makes devlink
dumps fail with -EMSGSIZE when an instance does not fit in an empty skb.

Closes: https://lore.kernel.org/netdev/20261126094321.40071-1-poros@redhat.com

> diff --git a/net/devlink/dev.c b/net/devlink/dev.c
> index b7e5aebf13be5..07fad82d9e1c1 100644
> --- a/net/devlink/dev.c
> +++ b/net/devlink/dev.c
> @@ -156,6 +156,21 @@ static int devlink_nl_nested_fill(struct sk_buff *msg, struct devlink *devlink)
>  	return 0;
>  }
>  
> +static size_t devlink_nl_dev_msg_size(struct devlink *devlink, size_t size)
> +{
> +	unsigned long rel_index;
> +	void *unused;
> +
> +	xa_for_each(&devlink->nested_rels, rel_index, unused)
> +		size += devlink_rel_devlink_handle_size(rel_index);
> +	return size;
> +}
> +
> +static size_t devlink_nl_dev_dump_size(struct devlink *devlink)
> +{
> +	return devlink_nl_dev_msg_size(devlink, 512);
> +}
> +

[ ... ]

> @@ -240,13 +257,34 @@ int devlink_nl_get_doit(struct sk_buff *skb, struct genl_info *info)
>  	return genlmsg_reply(msg, info);
>  }
>  
> +int devlink_nl_get_pre_dumpit(struct netlink_callback *cb)
> +{
> +	struct net *net = sock_net(cb->skb->sk);
> +	struct devlink *devlink;
> +	unsigned long index;
> +
> +	/* no instance lock, the size is only a hint for the first dump skb */
> +	devlinks_xa_for_each_registered_get(net, index, devlink) {
> +		cb->min_dump_alloc = max(cb->min_dump_alloc,
> +					 devlink_nl_dev_dump_size(devlink));
> +		devlink_put(devlink);
> +	}
> +	return 0;
> +}

[Severity: Medium]
Can this make "devlink dev show" fail for readers with a page-sized
buffer, in setups where it worked before this patch?

min_dump_alloc ends up as the largest estimate over all instances in the
netns. netlink_dump() then uses it for every skb of the dump, not only the
first one:

net/netlink/af_netlink.c:netlink_dump() {
    ...
	alloc_min_size = max_t(int, cb->min_dump_alloc, NLMSG_GOODSIZE);

	max_recvmsg_len = READ_ONCE(nlk->max_recvmsg_len);
	if (alloc_min_size < max_recvmsg_len) {
		alloc_size = max_recvmsg_len;
    ...
	if (!skb) {
		alloc_size = alloc_min_size;
    ...
	skb_reserve(skb, skb_tailroom(skb) - alloc_size);
    ...
}

So once one instance's estimate goes over 4096, every dump skb is sized
above a page. Each skb is packed with as many messages as fit, including
skbs that only carry small instances with no nested devlinks.

The estimate is also noticeably higher than what actually gets put. The
512 byte base in devlink_nl_dev_dump_size() is about 240 bytes more than
the rest of the message (~270 bytes).

devlink_nl_nested_handle_size() always counts a u64 DEVLINK_ATTR_INDEX and
DEVLINK_ATTR_NETNS_ID. The put side looks like this:

net/devlink/devl_internal.h:devlink_nl_put_handle() {
    ...
	if (nla_put_uint(msg, DEVLINK_ATTR_INDEX, devlink->index))
		return -EMSGSIZE;
    ...
}

devlink->index is a u32, so it gets a 4 byte payload.
devlink_nl_put_nested_handle() only adds the netns id when the netns
differs. That is about 12 bytes of slack per same-netns handle.

As a rough example, take an ice PF with about 70 SF devlinks ("auxiliary"
and "ice.sf.N", about 44 bytes per handle). Its real message is about
272 + 44 * 70 = 3350 bytes, which even fit the old NLMSG_DEFAULT_SIZE
buffer. Its estimate is about 512 + 56 * 70 = 4430 bytes.

The SF instances are in the same netns, at about 250 bytes per message. So
about 17 of them get packed into one 4430 byte skb, and iproute2 gets
ENOSPC on the first recv. Before the patch, alloc_size was max_recvmsg_len
(4096) and every message fit.

Would it make sense to raise min_dump_alloc only for the skb that needs
it? Or could the estimate be tightened so it does not cross a page when
the real message does not?

For the larger counts this patch targets (more than ~80 SFs, and later
256 VFs), the devlink_nl_get_doit() reply is now delivered, but it is
larger than a page. So iproute2 gets ENOSPC instead of EMSGSIZE.

The dump also now fails outright. Before, it listed the instances that
come before the large one.

Given the Closes: tag, should the commit message say that iproute2 still
can't show these setups?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202124956.18277-1-przemyslaw.kitszel%40intel.com

  reply	other threads:[~2026-12-03 13:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:48 [PATCH net 0/3] ice, devlink: fixes needed for XLVF Przemek Kitszel
2026-12-02 12:48 ` [PATCH net 1/3] ice: move only the valid VF queues on LAG reclaim and reset rebuild Przemek Kitszel
2026-12-02 12:48 ` [PATCH net 2/3] ice: lock VF config while changing its MSI-X vector count Przemek Kitszel
2026-12-03 13:31   ` netdev-bot+sashiko
2026-12-02 12:48 ` [PATCH net 3/3] devlink: make room for many nested instances in a dev message Przemek Kitszel
2026-12-03 13:31   ` netdev-bot+sashiko [this message]
2026-12-02 12:54 ` [PATCH net 0/3] ice, devlink: fixes needed for XLVF netdev-bot+sinfo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179630471718.3146.7791163240760595954@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=poros@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox