From patchwork Thu Sep 21 19:42:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 142873 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5107636vqi; Thu, 21 Sep 2023 13:08:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZxVnzk1oXgGQFX5R3VegKmEokBNUB1icuvvy9ok7xD1y5opd09wHbQoOPjFym3U48LCPl X-Received: by 2002:a05:6a20:a10d:b0:13e:debc:3657 with SMTP id q13-20020a056a20a10d00b0013edebc3657mr589467pzk.30.1695326897831; Thu, 21 Sep 2023 13:08:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695326897; cv=none; d=google.com; s=arc-20160816; b=xZgw+r/GjJauyJsmeDk4n+jd9NUdvHnpA23+dsFlcdqaTSGQKzxTAJEuGcsoEGPrfS MTuOuWE1ZY6ZB+49yLPQsVtLoCv7WVKVyORE3B/GkoFSuiT1JXzW8jxqX9I9hwFxxASe 8s8+gh8ht8ew8wCsn72gXTxlCcTZmRYA3b6SxYTwUVSzpoUKLKv6A6MZk8anX8NMQbNJ 3A36KWtLhGZleSjkMGhQ8b3tJaa1TYJ2cOU9JAnir6sjFH54Gl7ltPIOP88GE/12DKn+ BtfM1vxke3DzFKygcdTRN+WX2q4CjXCAAd6ExrQVkIVPvIHfZjmn3uM6/ZNYg39t/dWi JYXQ== 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:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id h9-20020a056a00230900b0068fba70d25dsi2356659pfh.33.2023.09.21.13.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 13:08:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 7F49882A8883; Thu, 21 Sep 2023 12:52:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230290AbjIUTwB (ORCPT + 28 others); Thu, 21 Sep 2023 15:52:01 -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 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 12:52:06 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777677793174231947 X-GMAIL-MSGID: 1777679097290822759 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: Eric Dumazet Reviewed-by: Aaron Conole --- 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);