From nobody Mon Dec 15 19:10:24 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 181B227B4EB for ; Mon, 3 Nov 2025 15:40:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762184437; cv=none; b=RRYbS8NvZMm55TkK+TWHMmT1SDeCvwOwu8LrFsYhrb+mt0G8eeICTAlTkG5vFlcrSLu0w/ZfOE6DLGSE17tbd475Gdi3rRlA8sFd2wDzQExzGVfgipej/RPfYzYcMxPuckVm6aKOj3KhTDjfSpSqivKrvbdavE7d81+3CZhiNk4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762184437; c=relaxed/simple; bh=X0wiVDoDQ/lFIVflb6+x+uwRmf/djAYzNvf0460O2tc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=uUsibMN/qZ/9UkWi38K6CSs+CBIUAB6rTc3Oi0izz2TGg1B+wstmFtfU4XCQ7SurYjChXj1p+VA9xREHy/FNya7GEiDB9wQySvFvG1db3hJS/ehEHfTuMz9ObV6Cth9fgF76Gu5Ici2TtWeSn8Cwj37iAX7uUqAt738ESdzT50I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Rt9hSliq; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Rt9hSliq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762184433; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=o9wfXsJS9xOV8WFM6Ew+60eZBPyQWXtK745crlrG0W8=; b=Rt9hSliqW22SKQwto2NOMtkPBSJs39KpwWRJ4wii+2b7wz+xFZc29EnQJgIKizobLETNud W7+Yfsl8/GFPRY8fTvVgat4fqzRjoBj8dhQ/ddex2sF6jBs2mye7W14KB+vTE6h6o29ojr yxf0dqNTf020RJexHr67MBPBIpvRqGY= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-102--LThxPVfNm6oI7BQImudPw-1; Mon, 03 Nov 2025 10:40:30 -0500 X-MC-Unique: -LThxPVfNm6oI7BQImudPw-1 X-Mimecast-MFC-AGG-ID: -LThxPVfNm6oI7BQImudPw_1762184428 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 003DB180AE37; Mon, 3 Nov 2025 15:40:16 +0000 (UTC) Received: from antares.redhat.com (unknown [10.44.33.211]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 67A7119540DD; Mon, 3 Nov 2025 15:40:09 +0000 (UTC) From: Adrian Moreno To: netdev@vger.kernel.org Cc: kuba@kernel.org, nicolas.dichtel@6wind.com, toke@redhat.com, Adrian Moreno , "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Kuniyuki Iwashima , Stanislav Fomichev , Xiao Liang , Cong Wang , linux-kernel@vger.kernel.org Subject: [PATCH net-next v3] rtnetlink: honor RTEXT_FILTER_SKIP_STATS in IFLA_STATS Date: Mon, 3 Nov 2025 16:40:04 +0100 Message-ID: <20251103154006.1189707-1-amorenoz@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" Gathering interface statistics can be a relatively expensive operation on certain systems as it requires iterating over all the cpus. RTEXT_FILTER_SKIP_STATS was first introduced [1] to skip AF_INET6 statistics from interface dumps and it was then extended [2] to also exclude IFLA_VF_INFO. The semantics of the flag does not seem to be limited to AF_INET or VF statistics and having a way to query the interface status (e.g: carrier, address) without retrieving its statistics seems reasonable. So this patch extends the use RTEXT_FILTER_SKIP_STATS to also affect IFLA_STATS. [1] https://lore.kernel.org/all/20150911204848.GC9687@oracle.com/ [2] https://lore.kernel.org/all/20230611105108.122586-1-gal@nvidia.com/ Signed-off-by: Adrian Moreno Reviewed-by: Eric Dumazet Reviewed-by: Nicolas Dichtel Reviewed-by: Toke H=C3=B8iland-J=C3=B8rgensen --- net/core/rtnetlink.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 8040ff7c356e..b2a8920df1cc 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1270,13 +1270,13 @@ static size_t rtnl_dpll_pin_size(const struct net_d= evice *dev) static noinline size_t if_nlmsg_size(const struct net_device *dev, u32 ext_filter_mask) { - return NLMSG_ALIGN(sizeof(struct ifinfomsg)) + size_t size; + + size =3D NLMSG_ALIGN(sizeof(struct ifinfomsg)) + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */ + nla_total_size(IFALIASZ) /* IFLA_IFALIAS */ + nla_total_size(IFNAMSIZ) /* IFLA_QDISC */ + nla_total_size_64bit(sizeof(struct rtnl_link_ifmap)) - + nla_total_size(sizeof(struct rtnl_link_stats)) - + nla_total_size_64bit(sizeof(struct rtnl_link_stats64)) + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */ + nla_total_size(MAX_ADDR_LEN) /* IFLA_BROADCAST */ + nla_total_size(4) /* IFLA_TXQLEN */ @@ -1329,6 +1329,12 @@ static noinline size_t if_nlmsg_size(const struct ne= t_device *dev, + nla_total_size(2) /* IFLA_HEADROOM */ + nla_total_size(2) /* IFLA_TAILROOM */ + 0; + + if (!(ext_filter_mask & RTEXT_FILTER_SKIP_STATS)) + size +=3D nla_total_size(sizeof(struct rtnl_link_stats)) + + nla_total_size_64bit(sizeof(struct rtnl_link_stats64)); + + return size; } =20 static int rtnl_vf_ports_fill(struct sk_buff *skb, struct net_device *dev) @@ -2123,7 +2129,8 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, if (rtnl_phys_switch_id_fill(skb, dev)) goto nla_put_failure; =20 - if (rtnl_fill_stats(skb, dev)) + if (!(ext_filter_mask & RTEXT_FILTER_SKIP_STATS) && + rtnl_fill_stats(skb, dev)) goto nla_put_failure; =20 if (rtnl_fill_vf(skb, dev, ext_filter_mask)) --=20 2.51.1