From patchwork Thu Sep 21 19:04:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 142914 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5142979vqi; Thu, 21 Sep 2023 14:14:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/upA6/gS8TWgE94VHKYEWSo8MbouCw3JCCzeauznVBfGWaTvzjX/HXwA8Lz3aPlWkhq84 X-Received: by 2002:a17:902:e5c1:b0:1c3:1316:ea52 with SMTP id u1-20020a170902e5c100b001c31316ea52mr6671728plf.61.1695330869192; Thu, 21 Sep 2023 14:14:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695330869; cv=none; d=google.com; s=arc-20160816; b=klNQNR09ohWFvmCF2/pIbQXLCORWYrllDZZd7pzyaHBqQhGu26o2mAG5yNsZ1AgQPH mfFUiew0hi6+P1DfuZjSXE8rPeC1tJpY6RDm+lpW7NYphsJmBZj1zgUB8NGwpFA7Vi7+ 5+nd2Ij/TSMcl5M6bNMwoaxNbr9p5qQMGQHGCjCkow2Drc6PLgO/lQTN7kaBikkAx3wF nFv7QAWGaAvkEGkKhXV0TPxakN3cnE5KSpCSsngslj8tIRnJJccaqnHjZCVMdRYNOBWL rruR0XZXwbG9P7nIexQwYhh96KkDDd7Dilpj9DG/gBgrQrkHSCTwz2lIBQBmFYQXrc+b i7eg== 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=Y5o2YSFwa/403ZlZbJW1DEgyMCYaF8ZWLyER6ajwTlI=; fh=JD3ZmI7NpBTabG+bbY62O7K58DVY7VbZFrFwA3LcnWw=; b=PuL2qtS6Ala18WbYaHJlFonvSi6u55lRH+vOKHgmkFCuuOHCzJHCD9NRIiDwu3Onsy CqxEnCrlLqzIV5qWUVL1UZ2jZrklCLQx5Kv5k+4tPbIr95TF5ApxAmsmPsaY+v5oA/v2 PtVHbcHCzxAXrUg95/LOfF9QJ6h2Nvk0BuDh2ujrR7V/B9KUVmcfEYUUtCdW3pKlx57z JVvoyHi89QvgHyyvcKPOQRIIiWASFaK0J6nWUAuUNXeEsDFBscathGVvqr1PfaY0q7Rd bs/iL6XPk2ZqoZ9Pig0BwydcZl5hPQDK8JYp638l11+XXEAW4ghFOF071O+UM24kr/GO awuw== 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:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id u16-20020a170902e81000b001b9e82a6beesi2385673plg.548.2023.09.21.14.14.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 14:14:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id EB18780C2EB1; Thu, 21 Sep 2023 12:56:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230169AbjIUTz6 (ORCPT + 28 others); Thu, 21 Sep 2023 15:55:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230044AbjIUTzr (ORCPT ); Thu, 21 Sep 2023 15:55:47 -0400 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE0F0C0647; Thu, 21 Sep 2023 12:03:45 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 8654420004; Thu, 21 Sep 2023 19:03:38 +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] openvswitch: reduce stack usage in do_execute_actions Date: Thu, 21 Sep 2023 21:04:27 +0200 Message-ID: <20230921190429.1970766-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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 21 Sep 2023 12:56:15 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777677793174231947 X-GMAIL-MSGID: 1777683261110217166 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 --- net/openvswitch/actions.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c index 5f8094acd056..80cc5c512d7b 100644 --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -312,10 +312,16 @@ static int push_eth(struct sk_buff *skb, struct sw_flow_key *key, } static int push_nsh(struct sk_buff *skb, struct sw_flow_key *key, - const struct nshhdr *nh) + 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 +1445,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);