From patchwork Wed Sep 27 00:13:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13399766 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2926110F6 for ; Wed, 27 Sep 2023 00:13:25 +0000 (UTC) Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6BAD4ED8 for ; Tue, 26 Sep 2023 17:13:22 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-690f7d73a3aso8931442b3a.0 for ; Tue, 26 Sep 2023 17:13:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695773602; x=1696378402; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lSgYiRCYt1363lggyuUkHxtIxmN4dJJNRSQ3gemLbtA=; b=QnQFG7vdSu4aeZdl7zctvXcolJDaxe2FAIZPgE42tsX5uELjO9WsHnsZSuX4sHa6vJ ylRSB+OrbfPTccKs+RL9vuGNrToR5sPSaEqdxxHstAEZ1py6ctIV6wgvtcAQl4U4LrG1 YK3IdZR3YNP47REXV+IKBEBt7LmVNUGeJqURJIh71wz1ocbCweumNdfdHSgZbwaEQKc8 9UqvrNk0cpyOR22hH69vnwoyZuVLY0rSfzHA908mbVF+bqXYsGfFo94s3TWOq0KP1vvP VQZm5WtBMae1mrLgS3BmfVIhOJzrJFwGUswy1n9Mb2AGxYmIOlqqVRxCmP6KwsANIhaN DWlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695773602; x=1696378402; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lSgYiRCYt1363lggyuUkHxtIxmN4dJJNRSQ3gemLbtA=; b=axA4PKNDPRA5XMKhBpdZqdbSEOc/OBI3fRdVp12JMo+6JGCdg6ZBc+t+dJww2oAX6Y Z3YC3236XTD7883BtjonQegOwmc3rQT/tW2c6BLMSFpLRp+qZ0eI9oZh9MA/EdV7vb97 wVFv+RwExC/aa7mh2af6ZKYXoLBv+h9HjtUklYylzh/CqiENPkJ9BVrrB3fJ3hIjWJkb QBO9NFeeRsyadTbECeQS/wbhVjfsFFU6UA9ob+4mUfXskcSqU81ZGi5cNHf/gNsk1W2v F5E3oGTuTPDgF0t/AiiNtwdsmheAyutu9YA32wC1ZVq0AYkLbcJauzQsZtQMq5lSi8SY RkGg== X-Gm-Message-State: AOJu0YxMObnBaTOSPeQrB9/rU8+JswJ/FWw6GvdP+hqcjYULfdOR1ck0 lXRgVO7rU+GTG4udLfeyAVdtF9Svecc= X-Google-Smtp-Source: AGHT+IFQbQagGC2q3NPQzim2PrBBKTyGczkssRa1QpxvaSX8KbD7D9aMIrdtVfI+7RpKyyurPY1ZkQ== X-Received: by 2002:a05:6a21:3d84:b0:157:eb32:e739 with SMTP id bj4-20020a056a213d8400b00157eb32e739mr387666pzc.32.1695773601907; Tue, 26 Sep 2023 17:13:21 -0700 (PDT) Received: from wheely.local0.net ([203.63.110.121]) by smtp.gmail.com with ESMTPSA id j1-20020a170902c3c100b001bc18e579aesm5623333plj.101.2023.09.26.17.13.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 17:13:21 -0700 (PDT) From: Nicholas Piggin To: netdev@vger.kernel.org Cc: Nicholas Piggin , dev@openvswitch.org, Pravin B Shelar Subject: [RFC PATCH 1/7] net: openvswitch: Move NSH buffer out of do_execute_actions Date: Wed, 27 Sep 2023 10:13:02 +1000 Message-Id: <20230927001308.749910-2-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230927001308.749910-1-npiggin@gmail.com> References: <20230927001308.749910-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This takes do_execute_actions stack use from 544 bytes to 288 bytes. execute_push_nsh uses 336 bytes, but it is a leaf call not involved in recursion. Signed-off-by: Nicholas Piggin --- net/openvswitch/actions.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c index fd66014d8a76..8933caa92794 100644 --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -1286,6 +1286,21 @@ static int execute_dec_ttl(struct sk_buff *skb, struct sw_flow_key *key) return 0; } +static noinline_for_stack int execute_push_nsh(struct sk_buff *skb, + struct sw_flow_key *key, + const struct nlattr *attr) +{ + u8 buffer[NSH_HDR_MAX_LEN]; + struct nshhdr *nh = (struct nshhdr *)buffer; + int err; + + err = nsh_hdr_from_nlattr(attr, nh, NSH_HDR_MAX_LEN); + if (likely(!err)) + err = push_nsh(skb, key, nh); + + return err; +} + /* Execute a list of actions against 'skb'. */ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, struct sw_flow_key *key, @@ -1439,17 +1454,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 = execute_push_nsh(skb, key, nla_data(a)); break; - } case OVS_ACTION_ATTR_POP_NSH: err = pop_nsh(skb, key); From patchwork Wed Sep 27 00:13:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13399767 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBF6910F9 for ; Wed, 27 Sep 2023 00:13:26 +0000 (UTC) Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 432A15581 for ; Tue, 26 Sep 2023 17:13:25 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1c451541f23so77829185ad.2 for ; Tue, 26 Sep 2023 17:13:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695773604; x=1696378404; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Le/c0YgktUnEDcOh4FSJ0sBiH21QKPiXLtB2lr2AvBc=; b=TDibrhCJcIJ2UMz2jtMZhFFNAXJcmIB61kViUcrVknlVr7pUTfOCxJq+IG5TKf5pgh MpMospYlMmphF+6Ok55Us38Cr74je2qFKJ9w8k134uxud74qkLQxhit1WGAo5zUiMPfZ I0FFhtt0twtT3od4xa7ePsHGutIiD8aneVsV4cWSMoQhA27fova2kloPIuvBJAPikKJc kCjVLmtIV74JAneDo0CjvzUwMc2C9IIfLkHNdG2BaSa1YETZPPBO+zceeGJrz/LHpQVY 9hYw7TqVxDsO3+hCTt5mrY8zT6WKNa58CrPVbaHzH6t8cxmvfUcTFckcXIMimeNCQzf1 m2uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695773604; x=1696378404; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Le/c0YgktUnEDcOh4FSJ0sBiH21QKPiXLtB2lr2AvBc=; b=J2bDyj9yTU1GvYPYyr1UbiCf25qVHkrZ89uzVeGs3pYaYBgK24j3RIQr+eCu1qFLiA bHCh+geC33ACPa5U0jFalTAc+T9CNZU3UXyZUZoPGRlifmruLY1zBwH0o3WnB+yLQY4v 8JfQnGzQj7shDzXedt7SVpCOGyEZZLXenE3WVxJwQYrE+kmXkM+4Zw+UB8M+qJR6v0dU MafFId8+aqCm7BhXrlOwa++Iq2ZrCXg4hhFzswrd7tyydEn0MsyvAwa4iS/dbqzi8Tl9 GVUtUkiHmnNWkpmMvSWlge0QdSvGbdCegfUBFUY/IrfGmgLHdckK2OtCPG/AfOTEHpO6 /pqQ== X-Gm-Message-State: AOJu0Ywi9+NKYWojUZfFjMpNQu5SMInptwidPkqzYj9WLAtGfXwPuEkY 1TSKAXWTYH791JyDidUBn0FP5poFFLU= X-Google-Smtp-Source: AGHT+IHZte+tfqg1S1fQiq/biwIqcnyw0fdEHy1faVZZfp8bNJKkeSfwaAZLd1sC1yNax9O4IOXe/g== X-Received: by 2002:a17:902:eecc:b0:1c4:172b:2f7c with SMTP id h12-20020a170902eecc00b001c4172b2f7cmr353100plb.0.1695773604540; Tue, 26 Sep 2023 17:13:24 -0700 (PDT) Received: from wheely.local0.net ([203.63.110.121]) by smtp.gmail.com with ESMTPSA id j1-20020a170902c3c100b001bc18e579aesm5623333plj.101.2023.09.26.17.13.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 17:13:24 -0700 (PDT) From: Nicholas Piggin To: netdev@vger.kernel.org Cc: Nicholas Piggin , dev@openvswitch.org, Pravin B Shelar Subject: [RFC PATCH 2/7] net: openvswitch: Reduce execute_push_nsh stack overhead Date: Wed, 27 Sep 2023 10:13:03 +1000 Message-Id: <20230927001308.749910-3-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230927001308.749910-1-npiggin@gmail.com> References: <20230927001308.749910-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Use dynamic allocation to reduce execute_push_nsh stack consumption from 336 bytes to 64 bytes, at the cost of introducing a GFP_ATOMIC allocation. Signed-off-by: Nicholas Piggin --- net/openvswitch/actions.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c index 8933caa92794..af177701a606 100644 --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -1290,13 +1290,17 @@ static noinline_for_stack int execute_push_nsh(struct sk_buff *skb, struct sw_flow_key *key, const struct nlattr *attr) { - u8 buffer[NSH_HDR_MAX_LEN]; - struct nshhdr *nh = (struct nshhdr *)buffer; + struct nshhdr *nh; int err; + nh = kmalloc(NSH_HDR_MAX_LEN, GFP_ATOMIC); + if (unlikely(!nh)) + return -ENOMEM; /* XXX: should this skip action like clone? */ + err = nsh_hdr_from_nlattr(attr, nh, NSH_HDR_MAX_LEN); if (likely(!err)) err = push_nsh(skb, key, nh); + kfree(nh); return err; } From patchwork Wed Sep 27 00:13:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13399768 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 717D1136C for ; Wed, 27 Sep 2023 00:13:29 +0000 (UTC) Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 047B05589 for ; Tue, 26 Sep 2023 17:13:28 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1c5bbb205e3so89694695ad.0 for ; Tue, 26 Sep 2023 17:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695773607; x=1696378407; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KW3aFuL8O8dR3kRbqmT+ARsollJPUDKAYpQ+DwVRtxs=; b=AlgOt5BPxwfwJhC5aIkUaAVlF0zB5bp3c+e6S3hVdKxDa1CYQQsbyLi9CSC/yvOAU+ LRUTD+s0rjiZeAe3P0D2yvX/5SGKZzo8pDCG6PcckqQ8ZGHaus1IRgrdx/zb7o3lvZFX wwILplbSeitX0SM5+tcj3RGtPq/HQAVV06NIN9KeedTyFIVhUqgyLqroVWyruNIDCPSD sEQXwPDnA+bMl4Wifvf4Gs2VBYFr/aQH9TQbPdrWgvE1JVv9KoDSUN87qDqOh9iKCbqi i1itkxpUWs51xi4tf+MOf+p9iLLez/kHu9pwsnqJS3KdfAnd/fvfX1t8ETdnMN8sacNo 73qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695773607; x=1696378407; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KW3aFuL8O8dR3kRbqmT+ARsollJPUDKAYpQ+DwVRtxs=; b=Xh9qXpQQZylmwBfcIh68ZQJGdCKYYthAYlnvDqEu7qQRiud5DT8cxKBfLrTrZ53SdT yJDYRrTulYA5GezRjex3KTVS/itd+af9BoruYzoMl4aZALPb5YlW0q5WdNVc0SyBf2LQ aBR5Uhggmjlp3nnVLB05CTZxATnBgD0qHJV9qacplReiVShOvkmGuWVsiUSoXDaRw7oV S8oCDeZ7Tm8vKIIkShGV+jM26odFo+ymexOQIdGSHxKz+jSSk5gdLwpqnW2tWmrB/lIr CM5Tcxau21AwYQZt8TqQ+AOcLevwjdAqTjG3PJFTYsWgt1CbzxmF0N/9fTBxSasU4XIH 311Q== X-Gm-Message-State: AOJu0Yx2GTQ89CpeZAqtqXc15bKelH+n6q+CaC4BpAU92/YPmpPkikb3 trGMfLwMWwj2YS38RWBUdALy0IDFOAc= X-Google-Smtp-Source: AGHT+IEc29fSkECPHqhAoHPkyRUqk1O24wtvTXfIHqWiidvz3VYa7JYnOcmMr96iXFM6aoEHZdlnvA== X-Received: by 2002:a17:903:25d2:b0:1c3:2532:ac71 with SMTP id jc18-20020a17090325d200b001c32532ac71mr348256plb.31.1695773607227; Tue, 26 Sep 2023 17:13:27 -0700 (PDT) Received: from wheely.local0.net ([203.63.110.121]) by smtp.gmail.com with ESMTPSA id j1-20020a170902c3c100b001bc18e579aesm5623333plj.101.2023.09.26.17.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 17:13:26 -0700 (PDT) From: Nicholas Piggin To: netdev@vger.kernel.org Cc: Nicholas Piggin , dev@openvswitch.org, Pravin B Shelar Subject: [RFC PATCH 3/7] net: openvswitch: uninline action execution Date: Wed, 27 Sep 2023 10:13:04 +1000 Message-Id: <20230927001308.749910-4-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230927001308.749910-1-npiggin@gmail.com> References: <20230927001308.749910-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC A function tends to use as much stack as the maximum of any control flow path. Compilers can "shrink wrap" to special-case stack allocation, but that only works well for exclusive paths. The switch statement in the loop in do_execute_actions uses as much stack as the maximum of its cases, and so inlining large actions increases overall stack uage. This is particularly bad because the actions that cause recursion are not the largest stack users. Uninline action execution functions, which reduces the stack usage of do_execute_actions from 288 bytes to 112 bytes. Signed-off-by: Nicholas Piggin --- net/openvswitch/actions.c | 69 +++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c index af177701a606..b4d4150c5e69 100644 --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -913,8 +913,9 @@ static void ovs_fragment(struct net *net, struct vport *vport, ovs_kfree_skb_reason(skb, reason); } -static void do_output(struct datapath *dp, struct sk_buff *skb, int out_port, - struct sw_flow_key *key) +static noinline_for_stack void do_output(struct datapath *dp, + struct sk_buff *skb, int out_port, + struct sw_flow_key *key) { struct vport *vport = ovs_vport_rcu(dp, out_port); @@ -944,10 +945,11 @@ static void do_output(struct datapath *dp, struct sk_buff *skb, int out_port, } } -static int output_userspace(struct datapath *dp, struct sk_buff *skb, - struct sw_flow_key *key, const struct nlattr *attr, - const struct nlattr *actions, int actions_len, - uint32_t cutlen) +static noinline_for_stack +int output_userspace(struct datapath *dp, struct sk_buff *skb, + struct sw_flow_key *key, const struct nlattr *attr, + const struct nlattr *actions, int actions_len, + uint32_t cutlen) { struct dp_upcall_info upcall; const struct nlattr *a; @@ -1022,9 +1024,9 @@ static int dec_ttl_exception_handler(struct datapath *dp, struct sk_buff *skb, * Otherwise, sample() should keep 'skb' intact regardless what * actions are executed within sample(). */ -static int sample(struct datapath *dp, struct sk_buff *skb, - struct sw_flow_key *key, const struct nlattr *attr, - bool last) +static noinline_for_stack int sample(struct datapath *dp, struct sk_buff *skb, + struct sw_flow_key *key, + const struct nlattr *attr, bool last) { struct nlattr *actions; struct nlattr *sample_arg; @@ -1053,9 +1055,10 @@ static int sample(struct datapath *dp, struct sk_buff *skb, * Otherwise, clone() should keep 'skb' intact regardless what * actions are executed within clone(). */ -static int clone(struct datapath *dp, struct sk_buff *skb, - struct sw_flow_key *key, const struct nlattr *attr, - bool last) +static noinline_for_stack int clone(struct datapath *dp, + struct sk_buff *skb, + struct sw_flow_key *key, + const struct nlattr *attr, bool last) { struct nlattr *actions; struct nlattr *clone_arg; @@ -1071,8 +1074,9 @@ static int clone(struct datapath *dp, struct sk_buff *skb, !dont_clone_flow_key); } -static void execute_hash(struct sk_buff *skb, struct sw_flow_key *key, - const struct nlattr *attr) +static noinline_for_stack void execute_hash(struct sk_buff *skb, + struct sw_flow_key *key, + const struct nlattr *attr) { struct ovs_action_hash *hash_act = nla_data(attr); u32 hash = 0; @@ -1094,9 +1098,9 @@ static void execute_hash(struct sk_buff *skb, struct sw_flow_key *key, key->ovs_flow_hash = hash; } -static int execute_set_action(struct sk_buff *skb, - struct sw_flow_key *flow_key, - const struct nlattr *a) +static noinline_for_stack int execute_set_action(struct sk_buff *skb, + struct sw_flow_key *flow_key, + const struct nlattr *a) { /* Only tunnel set execution is supported without a mask. */ if (nla_type(a) == OVS_KEY_ATTR_TUNNEL_INFO) { @@ -1114,9 +1118,9 @@ static int execute_set_action(struct sk_buff *skb, /* Mask is at the midpoint of the data. */ #define get_mask(a, type) ((const type)nla_data(a) + 1) -static int execute_masked_set_action(struct sk_buff *skb, - struct sw_flow_key *flow_key, - const struct nlattr *a) +static noinline_for_stack +int execute_masked_set_action(struct sk_buff *skb, struct sw_flow_key *flow_key, + const struct nlattr *a) { int err = 0; @@ -1189,9 +1193,9 @@ static int execute_masked_set_action(struct sk_buff *skb, return err; } -static int execute_recirc(struct datapath *dp, struct sk_buff *skb, - struct sw_flow_key *key, - const struct nlattr *a, bool last) +static noinline_for_stack +int execute_recirc(struct datapath *dp, struct sk_buff *skb, + struct sw_flow_key *key, const struct nlattr *a, bool last) { u32 recirc_id; @@ -1208,9 +1212,10 @@ static int execute_recirc(struct datapath *dp, struct sk_buff *skb, return clone_execute(dp, skb, key, recirc_id, NULL, 0, last, true); } -static int execute_check_pkt_len(struct datapath *dp, struct sk_buff *skb, - struct sw_flow_key *key, - const struct nlattr *attr, bool last) +static noinline_for_stack +int execute_check_pkt_len(struct datapath *dp, struct sk_buff *skb, + struct sw_flow_key *key, const struct nlattr *attr, + bool last) { struct ovs_skb_cb *ovs_cb = OVS_CB(skb); const struct nlattr *actions, *cpl_arg; @@ -1247,7 +1252,8 @@ static int execute_check_pkt_len(struct datapath *dp, struct sk_buff *skb, nla_len(actions), last, clone_flow_key); } -static int execute_dec_ttl(struct sk_buff *skb, struct sw_flow_key *key) +static noinline_for_stack int execute_dec_ttl(struct sk_buff *skb, + struct sw_flow_key *key) { int err; @@ -1526,10 +1532,11 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, * The execution may be deferred in case the actions can not be executed * immediately. */ -static int clone_execute(struct datapath *dp, struct sk_buff *skb, - struct sw_flow_key *key, u32 recirc_id, - const struct nlattr *actions, int len, - bool last, bool clone_flow_key) +static noinline_for_stack +int clone_execute(struct datapath *dp, struct sk_buff *skb, + struct sw_flow_key *key, u32 recirc_id, + const struct nlattr *actions, int len, bool last, + bool clone_flow_key) { struct deferred_action *da; struct sw_flow_key *clone; From patchwork Wed Sep 27 00:13:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13399769 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0526B10EB for ; Wed, 27 Sep 2023 00:13:31 +0000 (UTC) Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4EB7558D for ; Tue, 26 Sep 2023 17:13:30 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1c3cbfa40d6so89228405ad.1 for ; Tue, 26 Sep 2023 17:13:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695773610; x=1696378410; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TofRGtMhRPGgNgEwxNU34TFDCu+gzuDMLfb+dtqCXjQ=; b=Svh66JX2lC3Y79KsBJWXVL+2V6elZ8gb6zN3i8q6ncAeSY3d22JSdrUcC5rVPDPeIl jSR7x7S3WneDyM/dG0lAIr7ZChjWn8IUKpjAKxAr9wTbPhkB3zbpEUT277K46dZJKJPn z3XKXlv4A1wwFCy4a22XRDjgQWjvxn8u8aQ3Vx6cBSIevn+tQ2NTdzFC1p7ek/7Yi7Wq adY1/1nJ+VQv/iOrLoSkzBnQlsVXeZPnhwqN7lpcVeaJ70HekVpUoSILwLPJY+BdZpzM 8nXedAjXUbErXYnQBHahV/NQ0AtiMx76eDSioFEEbBNS/YUrJa7i4WP+DIjJ4uS5DYCU tsww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695773610; x=1696378410; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TofRGtMhRPGgNgEwxNU34TFDCu+gzuDMLfb+dtqCXjQ=; b=pEPK8XJq8vmS83ec6hpL67sSK7+awSo+9d3v+CpNjey/3vHwEIFakZp8Er+zb1gkki TWJvVtrPKxt1gFQLotfnGrPK6++ukdw908sYdJfBiXqSKeB9lgCF7wJveY05BEV4cBJu 4qL3FQhMUBvjafIDCbAF+/9u4EdjgdevkmvIHRxvMt/bNL5ZhykQXheCuxl0kYYN1LhI ytIZU2Y7Pa5EPV+uJ0+litMB8xnAdf1BtOZuufmJm+4UawUWdGYHokRrBP4mVKc7TVcC t/vHoJkyqPuXV8h9IIiptfKdxOrpcHli7Qx8goW38arbY5mZMelng50J1l/AIr3eSkaD wKTQ== X-Gm-Message-State: AOJu0Yzf6pq/3kgyATy/ZMaaNDtHP+nwhZvHLIWfp3Cke4NAEoHMB6UM rcks+6MLK+nX/elemYCD1b0q3uKjCLE= X-Google-Smtp-Source: AGHT+IFe+bxcLw9zxVvgyqKXSHnAy+bFRf2KFsXmH/SxtFIR/KsLXcxpyIpTdqZfJrcK7IUcTzhdvw== X-Received: by 2002:a17:903:1cf:b0:1c4:375c:110a with SMTP id e15-20020a17090301cf00b001c4375c110amr475177plh.19.1695773610188; Tue, 26 Sep 2023 17:13:30 -0700 (PDT) Received: from wheely.local0.net ([203.63.110.121]) by smtp.gmail.com with ESMTPSA id j1-20020a170902c3c100b001bc18e579aesm5623333plj.101.2023.09.26.17.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 17:13:29 -0700 (PDT) From: Nicholas Piggin To: netdev@vger.kernel.org Cc: Nicholas Piggin , dev@openvswitch.org, Pravin B Shelar Subject: [RFC PATCH 4/7] net: openvswitch: ovs_vport_receive reduce stack usage Date: Wed, 27 Sep 2023 10:13:05 +1000 Message-Id: <20230927001308.749910-5-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230927001308.749910-1-npiggin@gmail.com> References: <20230927001308.749910-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Dynamically allocating the sw_flow_key reduces stack usage of ovs_vport_receive from 544 bytes to 64 bytes at the cost of another GFP_ATOMIC allocation in the receive path. XXX: is this a problem with memory reserves if ovs is in a memory reclaim path, or since we have a skb allocated, is it okay to use some GFP_ATOMIC reserves? Signed-off-by: Nicholas Piggin --- net/openvswitch/vport.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c index 972ae01a70f7..ddba3e00832b 100644 --- a/net/openvswitch/vport.c +++ b/net/openvswitch/vport.c @@ -494,9 +494,13 @@ u32 ovs_vport_find_upcall_portid(const struct vport *vport, int ovs_vport_receive(struct vport *vport, struct sk_buff *skb, const struct ip_tunnel_info *tun_info) { - struct sw_flow_key key; + struct sw_flow_key *key; int error; + key = kmalloc(sizeof(*key), GFP_ATOMIC); + if (!key) + return -ENOMEM; + OVS_CB(skb)->input_vport = vport; OVS_CB(skb)->mru = 0; OVS_CB(skb)->cutlen = 0; @@ -510,12 +514,16 @@ int ovs_vport_receive(struct vport *vport, struct sk_buff *skb, } /* Extract flow from 'skb' into 'key'. */ - error = ovs_flow_key_extract(tun_info, skb, &key); + error = ovs_flow_key_extract(tun_info, skb, key); if (unlikely(error)) { kfree_skb(skb); + kfree(key); return error; } - ovs_dp_process_packet(skb, &key); + ovs_dp_process_packet(skb, key); + + kfree(key); + return 0; } From patchwork Wed Sep 27 00:13:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13399771 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 837311118 for ; Wed, 27 Sep 2023 00:13:34 +0000 (UTC) Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3FEF558D for ; Tue, 26 Sep 2023 17:13:33 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1c5db4925f9so72365445ad.1 for ; Tue, 26 Sep 2023 17:13:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695773613; x=1696378413; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wTg9psR2+piEPoaSc9Zx3utTOXhQXIIsVJjumDfUeU4=; b=PV07f/f+LxbmnVsPHQZrLkh9cYaIu7o7MhxTS/6L5bDsReQ8WN+aAag+ircaWf7Jap FxQ4+7NMXIMpCI5O0rCdCL8tQw7FDRuxgpx5wHOCRl4yfj8SL5RfndmzHdwX6XDy3uoy E0FiyrHdgUje2401oVuJW3Hf0bEkxjv3auSgkyDWIlUrNMGs0fIHDAhbzRE71x7ekbgA nK5Y07qcG8905I+pzh51fDWIl8kzJ2TZ+h1gNDmFWyfyor3D8MtaztUkugjM4L3zFhKk 2Nh6J9KD8oF9D1LNSaOXuMlLU3ZDW4n105Gv+p5kmKNE5zU/I5veOKyHOfPaBOylsE7K Gd9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695773613; x=1696378413; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wTg9psR2+piEPoaSc9Zx3utTOXhQXIIsVJjumDfUeU4=; b=YBrJ6b8GdLAn86ezu/h+96UgEGlNnGMiCWkpU0NtYVm/8x3NI1N9tiDm+HZKE5nJNH bMemx04VZvdbhF3JWsuD+i9Wvt4E9ZNoOiyJv1ilZO3fXW76gy4eaifLpC6EHaEKW4bw rh1qjwZTLXJNM1nwQAMn+kl7BDVOvjDNdpnySl0d5HZuQttybz1w0Fz7Hf4Q+E0xJce6 HuRNkq5fXuRJ6QmfoCsCf53Tlg/ljDQ3aNJXmjlIuk0AIcdvgRsKrik2MYghbwUYvbxT 1O3X2pmF3TcANI9ru5ZKxtq/Y5KGJ6iupYGd+1wX3aghqrrrqdEYUt1tSXydgN7ozo9S 8hDw== X-Gm-Message-State: AOJu0Yzy9AggaHleoev5Fkyndx+hMkyAL3lySKaIsYeF0cEShaw0iwLo YrFqKbUbyogFQ/NRke28F5MjoHxmu3E= X-Google-Smtp-Source: AGHT+IEJ5jzuWWHM5ESo+TJV0BG+cRQP7JW/ctMT2E6K4vI/izFd29y7VGylKavigU0du58wXErHQg== X-Received: by 2002:a17:903:2349:b0:1b5:674d:2aa5 with SMTP id c9-20020a170903234900b001b5674d2aa5mr754754plh.13.1695773612850; Tue, 26 Sep 2023 17:13:32 -0700 (PDT) Received: from wheely.local0.net ([203.63.110.121]) by smtp.gmail.com with ESMTPSA id j1-20020a170902c3c100b001bc18e579aesm5623333plj.101.2023.09.26.17.13.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 17:13:32 -0700 (PDT) From: Nicholas Piggin To: netdev@vger.kernel.org Cc: Nicholas Piggin , dev@openvswitch.org, Pravin B Shelar Subject: [RFC PATCH 5/7] net: openvswitch: uninline ovs_fragment to control stack usage Date: Wed, 27 Sep 2023 10:13:06 +1000 Message-Id: <20230927001308.749910-6-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230927001308.749910-1-npiggin@gmail.com> References: <20230927001308.749910-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC ovs_fragment uses a lot of stack, 400 bytes. It is a leaf function but its caller do_output is involved in openvswitch recursion. GCC 13.2 for powerpc64le is not inlining it, but it only has a single call site, so it is liable to being inlined. Mark it noinline_for_stack, to ensure it doesn't bloat stack use in the recursive path. Signed-off-by: Nicholas Piggin --- net/openvswitch/actions.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c index b4d4150c5e69..12ad998b70e2 100644 --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -849,9 +849,9 @@ static void prepare_frag(struct vport *vport, struct sk_buff *skb, skb_pull(skb, hlen); } -static void ovs_fragment(struct net *net, struct vport *vport, - struct sk_buff *skb, u16 mru, - struct sw_flow_key *key) +static noinline_for_stack +void ovs_fragment(struct net *net, struct vport *vport, struct sk_buff *skb, + u16 mru, struct sw_flow_key *key) { enum ovs_drop_reason reason; u16 orig_network_offset = 0; From patchwork Wed Sep 27 00:13:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13399770 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A87610E1 for ; Wed, 27 Sep 2023 00:13:37 +0000 (UTC) Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D4FD59C3 for ; Tue, 26 Sep 2023 17:13:36 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1c61bde0b4bso46040165ad.3 for ; Tue, 26 Sep 2023 17:13:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695773615; x=1696378415; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kXhL3o0sTOUKMqNKkJ+0Y25UfdzGjQwWOfR7lPB6ykE=; b=X+tOjVq2yqSYiqRQNHTSSc+w+5eMGIOgS3sU+tQXtR2rUPAxjkFiqxiRKxD5ruhEvT zWD+HQAnYRR1JJv15gChQ7cFyO4ZnCvTMoIR7wTOaHh7zL3nMCoPiX2qCDZECIG55vnV naa25cu4TWqiemGnSXkp6wOootJfHXwSphbsOJIWz193tbwe0EAtPAn7Wsh6VAgx/fIh CdmcFNg0kBMYQ6XJKJQOPHh6mVWVq+UKpmIF0tB1zFd/Yfqn744dISd1xvKFuAFaN7NP aGTesQ66BwE4jUxdVCuwqqwgR6DBjdj+tEBVkyZ8A3eqBG/tElUF2agDVrnXtl3yXPHV auQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695773615; x=1696378415; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kXhL3o0sTOUKMqNKkJ+0Y25UfdzGjQwWOfR7lPB6ykE=; b=SWH+DoH0yqLHvoc2Yk52v9NHIURFCyKRo2zqCSzVjtUPqctbpdOZSYR3vYqAUwYBwm Hpej3B/dI6IBgtCtBlF4rK6mtalPz/8ynOjXPpfQz16nHij/KstfTuevypSQuSTG2cIw gAm5FyYpxBjobepXxLn/12jLe3grGhpJE1nEY/Rmo55Imsf/61/1tN5r7uHZu5+gzmKf HTrDU+LclF1C2qpvUiObYbrTPjuBqDPkpd/QckhP25G/41q+Q5vqD8AWIxSewaR04XuB cKKawmFMUXWiIW+wmqiCjGUvwuVAJlvJ4wNLIG+1N2OQ8jKq0i2n+JX9xvpuulf/Z9l/ 0B0A== X-Gm-Message-State: AOJu0YzsNfmpHKOSkGReIfq6qlnDOal0S4F/kwVPsw7qcEq5YGGtMG31 Ind1iNr4Ly9g5M7tKBgaiZ/dSzXFyPU= X-Google-Smtp-Source: AGHT+IGrbto64urSayF3SYkkaSV9eGasHRuQTs5RFbPzkux1/G/0+LDvyHErja0wYLLHdOkObCgSzw== X-Received: by 2002:a17:902:ecc6:b0:1b8:b285:ec96 with SMTP id a6-20020a170902ecc600b001b8b285ec96mr380536plh.23.1695773615462; Tue, 26 Sep 2023 17:13:35 -0700 (PDT) Received: from wheely.local0.net ([203.63.110.121]) by smtp.gmail.com with ESMTPSA id j1-20020a170902c3c100b001bc18e579aesm5623333plj.101.2023.09.26.17.13.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 17:13:35 -0700 (PDT) From: Nicholas Piggin To: netdev@vger.kernel.org Cc: Nicholas Piggin , dev@openvswitch.org, Pravin B Shelar Subject: [RFC PATCH 6/7] net: openvswitch: Reduce ovs_fragment stack usage Date: Wed, 27 Sep 2023 10:13:07 +1000 Message-Id: <20230927001308.749910-7-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230927001308.749910-1-npiggin@gmail.com> References: <20230927001308.749910-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Allocate the dst route dynamically rather than on stack, reducing ovs_fragment stack usage from 400 to 160 bytes, at a cost of a GFP_ATOMIC allocation. Signed-off-by: Nicholas Piggin --- net/openvswitch/actions.c | 33 ++++++++++++++++++++++++--------- net/openvswitch/drop.h | 1 + 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c index 12ad998b70e2..a6e10f59838f 100644 --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -868,38 +868,53 @@ void ovs_fragment(struct net *net, struct vport *vport, struct sk_buff *skb, } if (key->eth.type == htons(ETH_P_IP)) { - struct rtable ovs_rt = { 0 }; + struct rtable *ovs_rt; unsigned long orig_dst; + ovs_rt = kzalloc(sizeof(*ovs_rt), GFP_ATOMIC); + if (!ovs_rt) { + OVS_NLERR(1, "No memory to fragment"); + reason = OVS_DROP_NOMEM; + goto err; + } + prepare_frag(vport, skb, orig_network_offset, ovs_key_mac_proto(key)); - dst_init(&ovs_rt.dst, &ovs_dst_ops, NULL, 1, + dst_init(&ovs_rt->dst, &ovs_dst_ops, NULL, 1, DST_OBSOLETE_NONE, DST_NOCOUNT); - ovs_rt.dst.dev = vport->dev; + ovs_rt->dst.dev = vport->dev; orig_dst = skb->_skb_refdst; - skb_dst_set_noref(skb, &ovs_rt.dst); + skb_dst_set_noref(skb, &ovs_rt->dst); IPCB(skb)->frag_max_size = mru; ip_do_fragment(net, skb->sk, skb, ovs_vport_output); refdst_drop(orig_dst); + kfree(ovs_rt); } else if (key->eth.type == htons(ETH_P_IPV6)) { unsigned long orig_dst; - struct rt6_info ovs_rt; + struct rt6_info *ovs_rt; + + ovs_rt = kzalloc(sizeof(*ovs_rt), GFP_ATOMIC); + if (!ovs_rt) { + OVS_NLERR(1, "No memory to fragment"); + reason = OVS_DROP_NOMEM; + goto err; + } prepare_frag(vport, skb, orig_network_offset, ovs_key_mac_proto(key)); - memset(&ovs_rt, 0, sizeof(ovs_rt)); - dst_init(&ovs_rt.dst, &ovs_dst_ops, NULL, 1, + dst_init(&ovs_rt->dst, &ovs_dst_ops, NULL, 1, DST_OBSOLETE_NONE, DST_NOCOUNT); - ovs_rt.dst.dev = vport->dev; + ovs_rt->dst.dev = vport->dev; orig_dst = skb->_skb_refdst; - skb_dst_set_noref(skb, &ovs_rt.dst); + skb_dst_set_noref(skb, &ovs_rt->dst); IP6CB(skb)->frag_max_size = mru; ipv6_stub->ipv6_fragment(net, skb->sk, skb, ovs_vport_output); refdst_drop(orig_dst); + kfree(ovs_rt); } else { WARN_ONCE(1, "Failed fragment ->%s: eth=%04x, MRU=%d, MTU=%d.", ovs_vport_name(vport), ntohs(key->eth.type), mru, diff --git a/net/openvswitch/drop.h b/net/openvswitch/drop.h index cedf9b7b5796..0bf156867a69 100644 --- a/net/openvswitch/drop.h +++ b/net/openvswitch/drop.h @@ -20,6 +20,7 @@ R(OVS_DROP_FRAG_INVALID_PROTO) \ R(OVS_DROP_CONNTRACK) \ R(OVS_DROP_IP_TTL) \ + R(OVS_DROP_NOMEM) \ /* deliberate comment for trailing \ */ enum ovs_drop_reason { From patchwork Wed Sep 27 00:13:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13399772 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0030C110A for ; Wed, 27 Sep 2023 00:13:39 +0000 (UTC) Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D20865FC1 for ; Tue, 26 Sep 2023 17:13:38 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1c451541f23so77831445ad.2 for ; Tue, 26 Sep 2023 17:13:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695773618; x=1696378418; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XZ6L0X0czBnGtOrBDWDBQdqRNYqy/TkiSVt0wMO8NXw=; b=ET4oGermqhIo4C1ls9lvWovEmSdxyF6sYjS5xVvZXUFG1UsfHPw4N9bj2krWWVPrT5 ZcHtYqcQibw/uhVOUY5wB7ClmtloQDZvpJx+gl5wl7wB/DWx49DsruOsKWLE742Z4dih qv8C8X2gPFdjP9JHDQxubA0Wd3PCimtp8qhEWeO6bMKDmOr9W355XObw/EkIvA4u40V8 OROy6USTim+rvqb5F1LomztdegkgHtn0mJjRZjK60TyevZu16u5vOlA3EBmGyIhN7iyB kav0tF4fdYg2tT9crf8K20ZnL2nV+yK22PKexGTiabmCgVI01RrX979yslIAxLCJNGnt iWyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695773618; x=1696378418; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XZ6L0X0czBnGtOrBDWDBQdqRNYqy/TkiSVt0wMO8NXw=; b=B5jBNjuHfrerB8PhDC6QUhBujLyWnBrAr3TdfwNihbbF3GsMT1qadHEZnzOyvuaFeL sy5QWAfSTH0e9Ej/pMp8p9nuA7kDTKN1ekyE0gc8sv7IDCidm9QF8OvnAk9qWIStWtz9 8vo595R3oK9/TqXAWskCR7tsZ0N6LDNKIAQq0kSLt2wD8MrV4Nl6c87BT5GayQ1/dqz+ 58vp2SxGumVKeYjmncbqNQirq1wHH7HrCnHMMScXyvDn6s3+1kcrE/QjjvfCvbEaceR9 zGrACOE79Dfj5eReU6gM3+LPuc2QCDp1AFLwrLvRzefnPZ07q6WX986Mo54wEn4tPfXd hPKg== X-Gm-Message-State: AOJu0YxwZ32xP255hne47jWCvopanCA9jKLU5rGthNLX1Pkbe9HlgIoR enh9JWilc0Cn/aQjBxpLSaYBUuyFob0= X-Google-Smtp-Source: AGHT+IECpPlomNoCjzfWu/layqAjaj6hGyUlXsjsnZdFGo5uJDGiH7wDs7DKGEghAaSoK9cssUy8rg== X-Received: by 2002:a17:902:9f87:b0:1c1:eb8b:79a6 with SMTP id g7-20020a1709029f8700b001c1eb8b79a6mr276379plq.24.1695773618165; Tue, 26 Sep 2023 17:13:38 -0700 (PDT) Received: from wheely.local0.net ([203.63.110.121]) by smtp.gmail.com with ESMTPSA id j1-20020a170902c3c100b001bc18e579aesm5623333plj.101.2023.09.26.17.13.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 17:13:37 -0700 (PDT) From: Nicholas Piggin To: netdev@vger.kernel.org Cc: Nicholas Piggin , dev@openvswitch.org, Pravin B Shelar Subject: [RFC PATCH 7/7] net: openvswitch: Reduce stack usage in ovs_dp_process_packet Date: Wed, 27 Sep 2023 10:13:08 +1000 Message-Id: <20230927001308.749910-8-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230927001308.749910-1-npiggin@gmail.com> References: <20230927001308.749910-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The upcall in ovs_dp_process_packet uses a lot of stack and is not involved in the recursive call. Move it into an out of line function, reducing stack overhead from 144 to 96 bytes. Signed-off-by: Nicholas Piggin --- net/openvswitch/datapath.c | 55 +++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index 11c69415c605..bdbbdd556c4a 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c @@ -242,6 +242,37 @@ void ovs_dp_detach_port(struct vport *p) ovs_vport_del(p); } +static noinline_for_stack +void do_packet_upcall(struct sk_buff *skb, struct sw_flow_key *key, + const struct vport *p, struct datapath *dp) +{ + struct dp_upcall_info upcall; + int error; + + memset(&upcall, 0, sizeof(upcall)); + upcall.cmd = OVS_PACKET_CMD_MISS; + + if (dp->user_features & OVS_DP_F_DISPATCH_UPCALL_PER_CPU) + upcall.portid = + ovs_dp_get_upcall_portid(dp, smp_processor_id()); + else + upcall.portid = ovs_vport_find_upcall_portid(p, skb); + + upcall.mru = OVS_CB(skb)->mru; + error = ovs_dp_upcall(dp, skb, key, &upcall, 0); + switch (error) { + case 0: + case -EAGAIN: + case -ERESTARTSYS: + case -EINTR: + consume_skb(skb); + break; + default: + kfree_skb(skb); + break; + } +} + /* Must be called with rcu_read_lock. */ void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key) { @@ -261,30 +292,6 @@ void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key) flow = ovs_flow_tbl_lookup_stats(&dp->table, key, skb_get_hash(skb), &n_mask_hit, &n_cache_hit); if (unlikely(!flow)) { - struct dp_upcall_info upcall; - - memset(&upcall, 0, sizeof(upcall)); - upcall.cmd = OVS_PACKET_CMD_MISS; - - if (dp->user_features & OVS_DP_F_DISPATCH_UPCALL_PER_CPU) - upcall.portid = - ovs_dp_get_upcall_portid(dp, smp_processor_id()); - else - upcall.portid = ovs_vport_find_upcall_portid(p, skb); - - upcall.mru = OVS_CB(skb)->mru; - error = ovs_dp_upcall(dp, skb, key, &upcall, 0); - switch (error) { - case 0: - case -EAGAIN: - case -ERESTARTSYS: - case -EINTR: - consume_skb(skb); - break; - default: - kfree_skb(skb); - break; - } stats_counter = &stats->n_missed; goto out; }