From nobody Fri Feb 13 17:34:08 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2B6CE7D0A8 for ; Thu, 21 Sep 2023 19:51:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230070AbjIUTwC (ORCPT ); Thu, 21 Sep 2023 15:52:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229831AbjIUTvr (ORCPT ); Thu, 21 Sep 2023 15:51:47 -0400 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6C061481D; Thu, 21 Sep 2023 12:42:27 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 32ABE1BF203; Thu, 21 Sep 2023 19:42:22 +0000 (UTC) From: Ilya Maximets To: netdev@vger.kernel.org Cc: Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , linux-kernel@vger.kernel.org, dev@openvswitch.org, Pravin B Shelar , Eelco Chaudron , Ilya Maximets Subject: [PATCH net-next v2] openvswitch: reduce stack usage in do_execute_actions Date: Thu, 21 Sep 2023 21:42:35 +0200 Message-ID: <20230921194314.1976605-1-i.maximets@ovn.org> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: i.maximets@ovn.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" do_execute_actions() function can be called recursively multiple times while executing actions that require pipeline forking or recirculations. It may also be re-entered multiple times if the packet leaves openvswitch module and re-enters it through a different port. Currently, there is a 256-byte array allocated on stack in this function that is supposed to hold NSH header. Compilers tend to pre-allocate that space right at the beginning of the function: a88: 48 81 ec b0 01 00 00 sub $0x1b0,%rsp NSH is not a very common protocol, but the space is allocated on every recursive call or re-entry multiplying the wasted stack space. Move the stack allocation to push_nsh() function that is only used if NSH actions are actually present. push_nsh() is also a simple function without a possibility for re-entry, so the stack is returned right away. With this change the preallocated space is reduced by 256 B per call: b18: 48 81 ec b0 00 00 00 sub $0xb0,%rsp Signed-off-by: Ilya Maximets Reviewed-by: Aaron Conole Reviewed-by: Eric Dumazet --- Version 2: - Added 'noinline_for_stack' to avoid potential inlining. [Eric] net/openvswitch/actions.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c index 5f8094acd056..6fcd7e2ca81f 100644 --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -311,11 +311,18 @@ static int push_eth(struct sk_buff *skb, struct sw_fl= ow_key *key, return 0; } =20 -static int push_nsh(struct sk_buff *skb, struct sw_flow_key *key, - const struct nshhdr *nh) +static noinline_for_stack int push_nsh(struct sk_buff *skb, + struct sw_flow_key *key, + const struct nlattr *a) { + u8 buffer[NSH_HDR_MAX_LEN]; + struct nshhdr *nh =3D (struct nshhdr *)buffer; int err; =20 + err =3D nsh_hdr_from_nlattr(a, nh, NSH_HDR_MAX_LEN); + if (err) + return err; + err =3D nsh_push(skb, nh); if (err) return err; @@ -1439,17 +1446,9 @@ static int do_execute_actions(struct datapath *dp, s= truct sk_buff *skb, err =3D pop_eth(skb, key); break; =20 - case OVS_ACTION_ATTR_PUSH_NSH: { - u8 buffer[NSH_HDR_MAX_LEN]; - struct nshhdr *nh =3D (struct nshhdr *)buffer; - - err =3D nsh_hdr_from_nlattr(nla_data(a), nh, - NSH_HDR_MAX_LEN); - if (unlikely(err)) - break; - err =3D push_nsh(skb, key, nh); + case OVS_ACTION_ATTR_PUSH_NSH: + err =3D push_nsh(skb, key, nla_data(a)); break; - } =20 case OVS_ACTION_ATTR_POP_NSH: err =3D pop_nsh(skb, key); --=20 2.41.0