Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2253107rdb; Thu, 21 Sep 2023 13:00:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFzAvudACpM5SxRLHuRYBrOgOdIkFihOjeB0U3SDgyQaY3g/KWVZE+OASG5DbA4rZjb9vQ X-Received: by 2002:a17:903:18d:b0:1bd:d510:78fb with SMTP id z13-20020a170903018d00b001bdd51078fbmr743253plg.3.1695326416836; Thu, 21 Sep 2023 13:00:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695326416; cv=none; d=google.com; s=arc-20160816; b=v2FhcFNmFJWw8lG0uCJslDICreBnAaIt/QHfjuRmAC+8DoYuFBlF9+EIrRN26p7ZjY zZ5IZKEp56G/xQcyuDfLHaoRUXpg/Tqoe2nS7qshA/LSk1e0Pr15zPUnmCKRWbc6nI8l Y9t3V/lNX5pjFlLlUvIELdBD9oyInp7T5hHmiU1EKSKPZa4qhuCvtFH7PxtP5gtE+hZQ dSVvAQe5l3S82NGrvstu746NjdNP5uUOx7Hg8c+UC7w+86xfNjv9XCj3LrSka+7zd76o FwoXg+ZV8NPhIJKliD6swl/dFCf3ypdf7eHPnrYJWjm3IM0NZeow0A7Zw5SK+YL+p3+a 6MtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=d1ItAS1xei6XzHVHCZiCJ+ODdwFrQ2Bph7pfV2N3GBs=; fh=JD3ZmI7NpBTabG+bbY62O7K58DVY7VbZFrFwA3LcnWw=; b=qlHYo0RT6vQSwuNr2x8CA75KUOLBOCawuKidGotB+eOpcgQ7zdX6SnFYhNVPSdw6cm 2/M2lpiTYZp04X31olaElJ5Efzv/FtFWtutgnlFaJJguHu8LtphiujJZvCUDirVR6g62 n/uMTHn8EVxLAkzfhqE0mEHultBwz4z3eDrpBSrOGGLxH5o6R3jrO1+X1ky7/6AvLmpf PReNDFhQGLCG+A/FFnexQyNVAC+tpmQMnbuoJXry2btTx0bddsh5nrDhbNDely09pV6p 0I9/GbxENDU4GGIL30v4VYh4Ml3tjS1x19EtreXA3cX+cfjVmGy8HbkrHcsr25gjOT4R sy+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id ik29-20020a170902ab1d00b001ab29e00303si2056322plb.426.2023.09.21.13.00.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 13:00:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 41D2481B17BB; Thu, 21 Sep 2023 12:52:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230163AbjIUTwA (ORCPT + 99 others); Thu, 21 Sep 2023 15:52:00 -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: 8bit X-GND-Sasl: i.maximets@ovn.org X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 21 Sep 2023 12:52:16 -0700 (PDT) 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 --- 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_flow_key *key, return 0; } -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 = (struct nshhdr *)buffer; int err; + err = nsh_hdr_from_nlattr(a, nh, NSH_HDR_MAX_LEN); + if (err) + return err; + err = nsh_push(skb, nh); if (err) return err; @@ -1439,17 +1446,9 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, err = pop_eth(skb, key); break; - case OVS_ACTION_ATTR_PUSH_NSH: { - u8 buffer[NSH_HDR_MAX_LEN]; - struct nshhdr *nh = (struct nshhdr *)buffer; - - err = nsh_hdr_from_nlattr(nla_data(a), nh, - NSH_HDR_MAX_LEN); - if (unlikely(err)) - break; - err = push_nsh(skb, key, nh); + case OVS_ACTION_ATTR_PUSH_NSH: + err = push_nsh(skb, key, nla_data(a)); break; - } case OVS_ACTION_ATTR_POP_NSH: err = pop_nsh(skb, key); -- 2.41.0