🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26404

Re: [PATCH net 3/3] devlink: make room for many nested instances in a dev message

#26404
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 13:31
143 lines
13197 bytes
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
Technical Details
Message-ID: <179630471718.3146.7791163240760595954@kernel.org>
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376635-linux-kernel-netdev=dewy.ru
References: <20261202124956.18277-4-przemyslaw.kitszel@intel.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376635-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <179630471718.3146.7791163240760595954@kernel.org>
References: <20261202124956.18277-4-przemyslaw.kitszel@intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2503300"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:1f4VLieum04JwDY+oAZjFoCFrXQ= sha256:XB0evgHcz84REBhhVr7YYSl6QNFhJfL9UECG9q9s+U4=
	sha1:vCvZ7DQc9BuSYqoqCnL3RYbvpT4= sha256:QOa4pH+gFdw1GeDTr5KHtOahrDqQto97DFhu6K3r5tw=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id CBFC7117962; Thu,  3 Dec 2026 16:32:22 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.64
X-Spam-Status: No, score=-3.64 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id ZYbaN7D_lylk;
	Thu,  3 Dec 2026 16:32:12 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376635-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 6501411795D; Thu,  3 Dec 2026 16:32:04 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 9641B2B65E; Thu,  3 Dec 2026 13:31:59 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796304719;
	b=bhHPzithEI8zd7MFwmKt0438pvvFtbGm0rcUM2ciLTAuFGtOzSiO9V9IGNdmUbSPIref
	 nU8t+PANwxl/SRxWeQfqH5ec9NcHUxLMD4y5KgTjy1Yac69CONhwKvo4fLSpiBrQoO8rD
	 GQE0gtsW5zVA+H8mhgWwjggD78wDVWGKhn7AQVj/cxpM8DVXTyLvEqp8zbd0HNu3ALhgj
	 2X8n/ZilvEzexhQHLS+Nmfl0J1X/x0e3dbPN4zBQpXAa6JeTN24FxaqNXFGKBg7n/giPZ
	 bIStPtlcMdUVy+dTQcvL10rThsn94jemV0dJMfALC4y8h2TFZGN6s2Y2HdPG58yvPBw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796304719;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=+ma0Q05okcC3OgktQEbhrre5hJOqd5L1WhUFydBw84A=;
	b=nngJsQ0XlUXJZkOOGxpp+DfJlYUg/euqPox8xKfMcnLqC1DYp5+kax7aTXl/A0FBAW7W
	 ElkdCiT55nbQXeyQpXjz4ydxx+26EmMGcETtTsnMUp3xmEKJNK1Ua7+k1bFcffSKbFj0a
	 5+5Jvi+5z8ubH6yQtBQm1VZpl6oYAmn8GL1H0FuvBzY8vquTJ/K4Zao/cJwk4XoOGDBL+
	 zk7ukhsAyyu5s4QkS00p9KKvRDxGPZ1QtAxyco01eenpaCmrD1rM10qFR9bKY99JADCPs
	 jaVvg+wDz4hPE7/PDtwrQSZjdrOpIlDa2y26N1fFuNUZPIjoXH4884UdVEqsn+ns81w==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FMKTGt0B;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E8E0606A32D;
	Thu,  3 Dec 2026 13:31:59 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FMKTGt0B
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796304718;
	b=ikDRmC9idZLDAlsury+u0siG+zoO8b0YIf7BPsyLCxDK5kx4zPLQiD5IVnyN+JFgys1k
	 SlqBZt/l+xXZZer3rHWKzzo/Gz9RofazO2/OBt1otWrGxYHSUAUU99c7xjJ8Q4LCfajBD
	 C54zzV4EPtMb6LoIIneiyafzzJ3XmUzjbcfS/Sm/iaHtMPjyiVzlHCwPqFkhc50VNsY8l
	 M4OXycqw3Tty19NbQFq/BW0T1X+7Lfi4Vr4f7QjTJXOk26yEv2RzWZG2r+9iSmEQQmbXq
	 fntFUBeix5tbvhSZuE2EcIOmlGjsirN2aVR52gSXdAM5BzGtUyPF8VxhdqZvirRVNVg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796304718;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=+ma0Q05okcC3OgktQEbhrre5hJOqd5L1WhUFydBw84A=;
	b=aimhtIOgJia2JZz8bcEcnra6VMkaEzIqNndHqcVqpw0rew48E/zxZKbKE3XLdekWSpAo
	 JeH6+kove891hhnCv76Mkkdo43G4sCjK4SNUf+ak+2/7Krf68fwuJhU8OqbsHJqUy8fCB
	 FB2wBhmx4jgBQqPrO611iEYYrhJakVgLzrFyUfSF2uY4DwzpKbALI0ujIJJlvf7uTXeVW
	 vDJZlO9lcPo7eStG8VJIqWEi481psjVd93I/D1io2aop8O5cDOL6PZ48FBPEdkHk881iu
	 seww44ji/aqaI48rxdRWSW5JeH+O6E3xbPSzgmYdxnLT+5fkpErp74tnTDPzKcL738Q==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FMKTGt0B;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 913E3606A335
	for <netdev@vger.kernel.org>; Thu,  3 Dec 2026 13:31:58 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 938901F00893;
	Thu,  3 Dec 2026 13:31:57 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796304718;
	bh=+ma0Q05okcC3OgktQEbhrre5hJOqd5L1WhUFydBw84A=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=FMKTGt0BdZxeEZVTF577hHdVA/gnjpuCKRxu6lOMFbVarMYpN4c2d1X5IEmiOmd16
	 7zGm1CnS+msyRRHaF2xIczJ+6xwERmzkBsEWrAQSZ2RYpBKJzUAKQlk0rvq2Iyo9+S
	 GPy3An2lsibW9cE4WWmWHTU6j/C7tBeOSYQQdhRBFQbD84ZyuMKCYz0LeuQjcyEIWc
	 cdd4kL95kWXeqPhLcFtdeGxvhZFlZ3w+smo4rYUJJTtXhiS3iTjpigzbiwLA+6UGgk
	 4A23wdXjDRTj01RKnxEjcBpz2JJ46VxTtVxHIWLmbar1rXcsqF2KasSaaX2xZlQFTU
	 aLADoPQXDtKiw==
X-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
X-In-Reply-To: <20261202124956.18277-4-przemyslaw.kitszel@intel.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list