All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Eric Dumazet <edumazet@google.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, eric.dumazet@gmail.com
Subject: Re: [PATCH v2 net-next] net: reduce rtnetlink_rcv_msg() stack usage
Date: Thu, 11 Jul 2024 13:46:45 +0100	[thread overview]
Message-ID: <20240711124645.GC8788@kernel.org> (raw)
In-Reply-To: <20240710151653.3786604-1-edumazet@google.com>

On Wed, Jul 10, 2024 at 03:16:53PM +0000, Eric Dumazet wrote:
> IFLA_MAX is increasing slowly but surely.
> 
> Some compilers use more than 512 bytes of stack in rtnetlink_rcv_msg()
> because it calls rtnl_calcit() for RTM_GETLINK message.
> 
> Use noinline_for_stack attribute to not inline rtnl_calcit(),
> and directly use nla_for_each_attr_type() (Jakub suggestion)
> because we only care about IFLA_EXT_MASK at this stage.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Reviewed-by: Simon Horman <horms@kernel.org>

> ---
>  net/core/rtnetlink.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
> index eabfc8290f5e29f2ef3e5c1481715ae9056ea689..87e67194f24046a8420bbb51c19fb0a686b9b06b 100644
> --- a/net/core/rtnetlink.c
> +++ b/net/core/rtnetlink.c
> @@ -3969,22 +3969,28 @@ static int rtnl_dellinkprop(struct sk_buff *skb, struct nlmsghdr *nlh,
>  	return rtnl_linkprop(RTM_DELLINKPROP, skb, nlh, extack);
>  }
>  
> -static u32 rtnl_calcit(struct sk_buff *skb, struct nlmsghdr *nlh)
> +static noinline_for_stack u32 rtnl_calcit(struct sk_buff *skb,
> +					  struct nlmsghdr *nlh)
>  {
>  	struct net *net = sock_net(skb->sk);
>  	size_t min_ifinfo_dump_size = 0;
> -	struct nlattr *tb[IFLA_MAX+1];
>  	u32 ext_filter_mask = 0;
>  	struct net_device *dev;
> -	int hdrlen;
> +	struct nlattr *nla;
> +	int hdrlen, rem;
>  
>  	/* Same kernel<->userspace interface hack as in rtnl_dump_ifinfo. */
>  	hdrlen = nlmsg_len(nlh) < sizeof(struct ifinfomsg) ?
>  		 sizeof(struct rtgenmsg) : sizeof(struct ifinfomsg);
>  
> -	if (nlmsg_parse_deprecated(nlh, hdrlen, tb, IFLA_MAX, ifla_policy, NULL) >= 0) {
> -		if (tb[IFLA_EXT_MASK])
> -			ext_filter_mask = nla_get_u32(tb[IFLA_EXT_MASK]);
> +	if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen))
> +		return NLMSG_GOODSIZE;
> +
> +	nla_for_each_attr_type(nla, IFLA_EXT_MASK,
> +			       nlmsg_attrdata(nlh, hdrlen),
> +			       nlmsg_attrlen(nlh, hdrlen), rem) {
> +		if (nla_len(nla) == sizeof(u32))
> +			ext_filter_mask = nla_get_u32(nla);

I guess that in practice we can break here.
But perhaps there is some case where there is more than one
IFLA_EXT_MASK attribute and it changes behaviour.

>  	}
>  
>  	if (!ext_filter_mask)
> -- 
> 2.45.2.993.g49e7a77208-goog
> 
> 

  reply	other threads:[~2024-07-11 12:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-10 15:16 [PATCH v2 net-next] net: reduce rtnetlink_rcv_msg() stack usage Eric Dumazet
2024-07-11 12:46 ` Simon Horman [this message]
2024-07-12  0:31 ` patchwork-bot+netdevbpf

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=20240711124645.GC8788@kernel.org \
    --to=horms@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.