Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2289754rdb; Thu, 21 Sep 2023 14:14:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHSC4ZjMp1I0iQU6zDxCxcnix3UvPvmNVcFuuaa4WDHhHs5fQTiMGX88ONwyunkOY7QE8bX X-Received: by 2002:a17:90b:1084:b0:271:7cd6:165d with SMTP id gj4-20020a17090b108400b002717cd6165dmr6729964pjb.26.1695330865415; Thu, 21 Sep 2023 14:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695330865; cv=none; d=google.com; s=arc-20160816; b=deadwZiLI2Pupkfo5UmDdliseJ0WpwzYEXBzmzIjh07x5GY/JgWIbqaHvFyfZHWkhX rmS73Afga4vlKbaHz424dBLRt7V3VaAMXT12y+z+NwKcbzvnuaAAKcveAzmsgKIAHn49 RdcbZlg8GVs8x1x7Rel4fWkwy70Xw7eSJ0aRZ1/q6CtlVktZ5Y9EirjQHGS2p8bzcXJJ RsKLW0JDI4BTUbcqaNypenqQCSXBprPx2AAfrhFYguZhgzONv81hYBq3PG1NagCYOq3V eHIl+Euq8WoASAHPjyCe8jw1THGkHIIcDhTpDn/p742Qyxt5jX/lBWL0y/scLBRh3YuX AIgw== 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 Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id i8-20020a17090ad34800b00267ed8359e2si2389877pjx.55.2023.09.21.14.14.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 14:14:25 -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 1BDC280B19C5; Thu, 21 Sep 2023 12:56:04 -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 S231258AbjIUTz6 (ORCPT + 99 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 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 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:04 -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 --- 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); -- 2.41.0