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: 1840024 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=k9qwGh9Q; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RwTxl4l3Mz1yp0 for ; Wed, 27 Sep 2023 18:17:47 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 9598A61081; Wed, 27 Sep 2023 08:17:45 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 9598A61081 Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=k9qwGh9Q X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nzrIYZOJ6710; Wed, 27 Sep 2023 08:17:44 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 6E55F60B0C; Wed, 27 Sep 2023 08:17:43 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 6E55F60B0C Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0A91BC0DD7; Wed, 27 Sep 2023 08:17:41 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 394B7C0032 for ; Wed, 27 Sep 2023 00:13:23 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 2242F40116 for ; Wed, 27 Sep 2023 00:13:23 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 2242F40116 Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=k9qwGh9Q X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jjWhH-RumaR2 for ; Wed, 27 Sep 2023 00:13:22 +0000 (UTC) Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by smtp2.osuosl.org (Postfix) with ESMTPS id 87682408E5 for ; Wed, 27 Sep 2023 00:13:22 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 87682408E5 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-690d8fb3b7eso8917681b3a.1 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=openvswitch.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=k9qwGh9QbzSfEtrsEFu58ITAJGu0N7TfwuESs+FcysU5b2aGtsKrYJt83NfauSWN0Z D5ScLhaNv3iT3NtBDGgvP3KXskPjvb79CM2wDdzMulBApTol/pjHC6s2U8rNESG8d+Tl 0RYrTID/uRB0ZVs/N+CslJ+eUT60S04H+sQiWH1u146Gekq3yLrWys0nmkESB82LflZQ G7zJ31V4QeMXX6F8Va4pjKGc0Lu1E9edf21eN4bm147xiMnp2UJQlsJhKTua+DZrzj7S o9zGDPa0ttQ/YDrjN8KurC2qHkitD71VSR8dLd7zz9TJ1sBNm451q6HE+T1CuATvJARN hS1w== 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=dBu9Iy3f6yG2Tzhd4kHwmL3uLHK6OSL8j2nayZcOwkuuN2eMXwxvIaTs8uqJe/T8z+ iEbDWZSqLLOYiHujdrgMMaDdQ0Pi+mAq/woYkYY8TJ3Gg7bmzg/vm4A/boI6EGezszup k/negW2CXqevjRD6+4dt3b6kIfJQ6bvkMDS/YAFb/fA4p8Oys8APdCRylMNQskLY1dbW CDqP5/EHAVtRaMYg8J+FU8O+TY6+dYmnnp1I2VQJywIt5gIB2FENdGreN/rs2xACz3Eo cgyHzp+vkirGHN60jb6THTgW+9bKlV6Ei7Ns5KzRb+urQc1L1y19lvvaxe7XjJ/0sgWj guJw== X-Gm-Message-State: AOJu0YzGGDJNz3h4jIeLPpqZDxGUwgeK+jSNeF0mPM6p5bm8ek9vBUhk 1gttz68tvX4v7em5C9Jb8AE= 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 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> MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 27 Sep 2023 08:17:38 +0000 Cc: dev@openvswitch.org, Nicholas Piggin Subject: [ovs-dev] [RFC PATCH 1/7] net: openvswitch: Move NSH buffer out of do_execute_actions X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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: 1840025 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hNTpfPlS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RwTxp4Tgfz1yp0 for ; Wed, 27 Sep 2023 18:17:50 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 346ED61062; Wed, 27 Sep 2023 08:17:47 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 346ED61062 Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hNTpfPlS X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZDVW8tljQisq; Wed, 27 Sep 2023 08:17:46 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id CC12E60EA4; Wed, 27 Sep 2023 08:17:44 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org CC12E60EA4 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C98B1C0DDB; Wed, 27 Sep 2023 08:17:41 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id DA459C0032 for ; Wed, 27 Sep 2023 00:13:25 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id A809982741 for ; Wed, 27 Sep 2023 00:13:25 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org A809982741 Authentication-Results: smtp1.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hNTpfPlS X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UpSAqgb28afk for ; Wed, 27 Sep 2023 00:13:25 +0000 (UTC) Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by smtp1.osuosl.org (Postfix) with ESMTPS id 1C01B82730 for ; Wed, 27 Sep 2023 00:13:24 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 1C01B82730 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1c3bd829b86so78134285ad.0 for ; Tue, 26 Sep 2023 17:13:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695773604; x=1696378404; darn=openvswitch.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=hNTpfPlSYgkzJ1JMjGum8zMkFqk2yzAeFUkPWViqYfi+k4Du3tO2AQ0v0DA8p1Vj+p pfg1wnZWxMqsiiiF8fQYXetocONsbpbYNhXQW7uXUcWVKNLJQi5lA5AiLeCoqD23jvug dri7sjA1ASF4dSl6kdmI+Qm981VmhmAqALxmTgje2JHxMuuYJSJWSmMriZ/o6NZ9Jq/T qZ4KeL52/Db+mOuTFdMJ3bYCEkSZsz/NwkPfyjXLzv+cnVfhwuApeXgYtTtX9xvG+Ifv L++Fmwa5HBMzTacJNQCMLRCgm8p7pH7xixJKZCztPW7wkLYUTONWsOlSHuaxOc2Ayudj YwkA== 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=U398gGK++Z/HHE0Q1dduLeiXYT/O0NMn5CX0+ZX1kihVKRsky+eGkVIBm2cNqYZQBQ PTj2PDBpJ87rpKm51X9tr4/C/g23IQTwZQUbti53Yz2i6ogOzRKDh5bNXa7/ID8rESPa g9uV6ujpv+UgOPUXeaF3cxHaM7SoadVPcealSDkREKyfjg38cw+pdLoTrCSmJF6ggKB1 wM5CA7beC1uBKPy0jPw6NIvuZ2/aDxVnlIcPz1s13ttPuoKgC/Pay2dPGKqmpeXVNJx8 4RPNIuoj86jvJ84MqM5CgYEm0BL2XETzHXdCAW0YApPu44AOKCyx0mgK6gQ/f7QZY5rX OaeQ== X-Gm-Message-State: AOJu0YwwE8V6t1k/yjuT0ZVJIKnt0RmW57ZyQCu4BWjfmsNHVlojcfNY 8HpbGHtl8fBO0sO+J/5HyPM= 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 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> MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 27 Sep 2023 08:17:38 +0000 Cc: dev@openvswitch.org, Nicholas Piggin Subject: [ovs-dev] [RFC PATCH 2/7] net: openvswitch: Reduce execute_push_nsh stack overhead X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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: 1840026 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=BZHQGsBd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RwTxs20dSz1yp0 for ; Wed, 27 Sep 2023 18:17:52 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 53B0282A3B; Wed, 27 Sep 2023 08:17:49 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 53B0282A3B Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=BZHQGsBd X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id l5DAsKSyZkY5; Wed, 27 Sep 2023 08:17:48 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 63B69829DC; Wed, 27 Sep 2023 08:17:46 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 63B69829DC Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C0063C0DDF; Wed, 27 Sep 2023 08:17:42 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id E20DCC0032 for ; Wed, 27 Sep 2023 00:13:28 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id B1C2C8272C for ; Wed, 27 Sep 2023 00:13:28 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org B1C2C8272C X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3hTDzi_lrKSe for ; Wed, 27 Sep 2023 00:13:28 +0000 (UTC) Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by smtp1.osuosl.org (Postfix) with ESMTPS id E467782718 for ; Wed, 27 Sep 2023 00:13:27 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org E467782718 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1c1ff5b741cso89467115ad.2 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=openvswitch.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=BZHQGsBd5GFqaDcytDNFuXUoSQUGu8VjDgUNHsUaYy+wVsNI5TjmjFjwtg5AUMqmow pqOTOho89+gdWZIVQ+QERBKXdRUU1kYssFS7soYBLEiVCcZlsHKND1E5FBnLxOyQxzVz 7VHd2MX/krrGGFo2leAXh4PTJQ9XxZsSPfpq61lZ7xcQ117hSZTfmIK1EqSTYmbLvHTq vdJ1hnUUGIaVVTSQ+8SEafXClKObFyEHvEBfsvhbmswqzHiD52n9HTLR9RfqP3PCR8pd vgcCJTSJtqzqnkQMAw2LzaVjVadU4yRWoYXh16y2kMyUh49mslLrPbescRB0zCJBnoVA tO/Q== 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=R17VoEFVA44R0ppvbs7BQQs2nyHfXwGi0GMmJ+KtusdyqyBAbBhHFkf5SM7LpUaQgY c7ajXHlu2OE79p4jiYIyCVrm/ZUjBEn3PPhYuCaSEP/2sUmlfI744rZihJvqX1kPHfHf hQ2x5LiAAqbG/j2Ik4MdHKn1Be1KDVs3a9MYrSdvnzY4+4jDi9Ol6Y5ngZOutWekxpEv 5vbPwwU4KzE0yHOYQMSLgUny82EoSXzXMGtPB+1NNMJxGYCiiE0ZlX/8DSy/APpIGik2 EYdKdNvDiPxH0Rl0WzoQUFWbXeMG/X+n0HpJk4tCbJKHtchC3iKK9RiIr/FQS6AqrFUE 2+gg== X-Gm-Message-State: AOJu0YyAORSh60gyDIkAqinJDCwa2JWeFhrmw9pgrVwprPVqnVBd4rjv MrZRnaKST59m5aFVGSS6SOk= 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 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> MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 27 Sep 2023 08:17:38 +0000 Cc: dev@openvswitch.org, Nicholas Piggin Subject: [ovs-dev] [RFC PATCH 3/7] net: openvswitch: uninline action execution X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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: 1840027 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Sly9styC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RwTxv51cpz1yp0 for ; Wed, 27 Sep 2023 18:17:55 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 10D9E82BF4; Wed, 27 Sep 2023 08:17:52 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 10D9E82BF4 Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Sly9styC X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AKPdtb5Ce_xr; Wed, 27 Sep 2023 08:17:49 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id CAEB2829B6; Wed, 27 Sep 2023 08:17:47 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org CAEB2829B6 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id CA2AEC0DE2; Wed, 27 Sep 2023 08:17:43 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8E025C0071 for ; Wed, 27 Sep 2023 00:13:31 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 677F5408E5 for ; Wed, 27 Sep 2023 00:13:31 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 677F5408E5 Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Sly9styC X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1sL1oelRn_Kh for ; Wed, 27 Sep 2023 00:13:30 +0000 (UTC) Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by smtp2.osuosl.org (Postfix) with ESMTPS id B1BF440116 for ; Wed, 27 Sep 2023 00:13:30 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org B1BF440116 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1c5cd27b1acso89172075ad.2 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=openvswitch.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=Sly9styCrDkAIHPzbuIRUmVDAAI4ZwA/0xomCngw5Ym03OuO2W6qFACjxQrdHjHQW5 rtgTF7lmZBu1Zi8/yFdCDUb9MbJ2vtNPvbbghj59e/0VJAe2FvYM/Pl/BA4X1RAInBG7 hMsrgmp8Hjj3/6oas0B9juSAqFsFczEKULgg6wNxRP7VifK8k2n6Z8hMlToZzirSKPEi xjPqQhf32ReRecFDVnhwseVDT2fB6ea3eSA75IuS6OXXzYUlNhdh20i11PbK/io1uFoj VwACQo/4xzOl7wlG8LPxkehAj71/NcHc3WaTgYryAiR7RZSCE6R9WwEHhrhjbxmKV0vc qCvg== 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=lYL69deZNVSBzex044Yz+zh+jbQPfM2cBrxgH1YW+NHkV+8rtz3bl2iWFvqmtP9fKf jwfEYIKq1/KH//wPsnW0LLGy5a4PvEFATr926nbJ6Nd8kb8OaYTB2KuzQ3Ua0VqUHM1e XE7oWUxTqea2GTC+iqwm+QcFOI1/aVF8S6ucLbqwSn2U4DQo+7t3JB2hdOzSgq8pihV6 xARHdCybm5WUlhtjt6Ly/2DFfaYhbKbrHNTe7/0WdPMeLp5NSa3hlHBBUK2QZ8xiiv4b XSn0C6TkTs+cZib4+T4pV9CEwt/FY3yS23JQeVdvYWMiGyL/d8wR90fsHUw5Davmgsyu NbsA== X-Gm-Message-State: AOJu0YwEhAqxEaQsOnmv1B6oHJUG//nOGcBfV5Zlef+7p09fYZjq3xgQ F/uoYav3sDdbpfgUbvUK8ig= 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 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> MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 27 Sep 2023 08:17:38 +0000 Cc: dev@openvswitch.org, Nicholas Piggin Subject: [ovs-dev] [RFC PATCH 4/7] net: openvswitch: ovs_vport_receive reduce stack usage X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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: 1840028 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JKrtgMFI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RwTxx3FRpz1yp0 for ; Wed, 27 Sep 2023 18:17:57 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 952D64211C; Wed, 27 Sep 2023 08:17:53 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 952D64211C Authentication-Results: smtp4.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JKrtgMFI X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9IKIgOJUS94D; Wed, 27 Sep 2023 08:17:51 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 7477941FF4; Wed, 27 Sep 2023 08:17:49 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 7477941FF4 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 9A996C0DD7; Wed, 27 Sep 2023 08:17:44 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 4CEAFC0032 for ; Wed, 27 Sep 2023 00:13:34 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 28D83613B9 for ; Wed, 27 Sep 2023 00:13:34 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 28D83613B9 Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JKrtgMFI X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gICEjqjSwjOK for ; Wed, 27 Sep 2023 00:13:33 +0000 (UTC) Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by smtp3.osuosl.org (Postfix) with ESMTPS id 89146613B4 for ; Wed, 27 Sep 2023 00:13:33 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 89146613B4 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1c60f1a2652so43705165ad.0 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=openvswitch.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=JKrtgMFIl/EgLqk5dMtPqP3+uWQFrROknGRv/uDQx4aUgL0aGNzgR2u+4vd8+6vA2T pD5aJJzziA58iocOUkoEzOay/UqDoj8+t0o2M8gekyk/raU9DaMCWLKv4esDBnJu4Yln SdT8yCRrvpW40Nk8Eq8ASX97ryYLkJyNjeHwsdUC9N2jnb1YgMLO0BmHHTfvLVM3cIql 1u175UDP534g6GP55PkgHzUEfGA5Ki207h6UdAIhPjXV2U/CFrLsepmAw64jL6mRLZXq 45G1XpkSvzlnPKLSPPgv2DTD0E4uRyGgjutppF5A5i903ISty1Wiz9GzC6ykxM+nJvI/ ULYQ== 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=NRUYlhcUPq+pB4QuNIsON/ap3/in2Qhy8Rv2sksc4vS2JvJfrwXAiama50irRLgPD7 mqko9BvOjKdScWJHxMKwBAyqtbaC7xqTjHdN/wDbMP7SB1lPFr+yiMhRKEGPd6PIhGhr cgK5EsIfadkfY/TiOVPmJaOVEIgVzRBTYjhwn72cAqxb6evEZhGbNhSV2tHN0hHu3Wmt lUs0nr6eUyCjJhsxZM6OjbcD2DE9ghyzU6ROuI6pHllq5H99lHc12XcMwbnWejc64wcp bPGhKE1VGDueaB47+PJhqnMrWZFxiXOgOXJH1e92KZbGJp7AUQ1l9Nc4u58fNZuBF4zZ 3wbg== X-Gm-Message-State: AOJu0YwOhK+gbdEMZBq9+FNiAPcKf5THOL4BfYRmbBRkRHDsYlYiOdwc xL6htSnipoReEm+S9BZtxwY= 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 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> MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 27 Sep 2023 08:17:38 +0000 Cc: dev@openvswitch.org, Nicholas Piggin Subject: [ovs-dev] [RFC PATCH 5/7] net: openvswitch: uninline ovs_fragment to control stack usage X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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: 1840029 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=mSm5w/JA; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RwTy02fFBz1yp0 for ; Wed, 27 Sep 2023 18:18:00 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 5F8D442094; Wed, 27 Sep 2023 08:17:56 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 5F8D442094 Authentication-Results: smtp4.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=mSm5w/JA X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oEcuUk2B-vQ8; Wed, 27 Sep 2023 08:17:54 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id CB9BA42091; Wed, 27 Sep 2023 08:17:51 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org CB9BA42091 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 58F4BC0DE7; Wed, 27 Sep 2023 08:17:45 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 4B29FC0032 for ; Wed, 27 Sep 2023 00:13:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 0272D408E8 for ; Wed, 27 Sep 2023 00:13:37 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 0272D408E8 Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=mSm5w/JA X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aYJFMwc0LeQD for ; Wed, 27 Sep 2023 00:13:36 +0000 (UTC) Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by smtp2.osuosl.org (Postfix) with ESMTPS id 263EB40116 for ; Wed, 27 Sep 2023 00:13:36 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 263EB40116 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1c5bbb205e3so89695955ad.0 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=openvswitch.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=mSm5w/JAPCxq7h7cDdGemKtoWCUH27N6Q/3TyGo/JH8KEcloqYmWjTgqaimpdqyG3B X7/YXeZLSPmPsLCCI9xwasMM1x9NEh4dqdnq2LPgsxBeKG/yCFK23QzjgmLVPzGau0M+ 7H1DTjSQgCDzlj8X+Fx8nO7TZ3om+UECoNpTn4UoFwGLr2R05/HfCsCxG3jw+k1RhGU1 WfFxAZH67y0Fa/pK3C11Qcf+ksL1qwlX5arVUQuW5L4VsMwkhhBvIn6ga27MP/eqkjbL +sIndCu2XI4Hu9L7xsT5HzQq4C3Rqqyj0gfKH5JvypNnNyVUMpf2qMJFAIG/xDLYHBp3 jrBw== 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=Atvg3IUy6L9buoixk3G+qCz5d38rszXACqLw2WHiz5pYq33xPvVnIwPV91f1uSOXS8 qyWIjSQlTHChYMiSzcMyWYFHOIf4BGB/SmvjdrdPKcqqD6Slo6DZJfxjkAqbPnstdNjP 1pr8/44NybfvpF2Y/af01YyeM+l/cGOfJCk+eQ+6sGeFjP5yBda5XDZ12wMn4Vz6tvJX QQjQf9E+PiEudfJbl8xbbYxrTEXCOQ96OQSGHqa5k0JBYhD+7QwFot7m+Nw0CV5EWCHX jkLe+loRq0g9j92olrS0d0pHFySqcBHXMTDSCoSV12APQAvrnAo6v5qv55/T4VuE+NOC nNrA== X-Gm-Message-State: AOJu0YxgxAepjtPaKOQbmKl+jmT2N3pVVQSLtUKNY3xTYFpGJNR3OjRl lgTFSv2O7KEhrojIKHK1m3WwwydFGgk= 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 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> MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 27 Sep 2023 08:17:38 +0000 Cc: dev@openvswitch.org, Nicholas Piggin Subject: [ovs-dev] [RFC PATCH 6/7] net: openvswitch: Reduce ovs_fragment stack usage X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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: 1840030 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=expPSdve; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RwTy25bWCz1yp0 for ; Wed, 27 Sep 2023 18:18:02 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 515BA41DF6; Wed, 27 Sep 2023 08:17:58 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 515BA41DF6 Authentication-Results: smtp4.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=expPSdve X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Zv4bQMNU8eb1; Wed, 27 Sep 2023 08:17:56 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id A9A42420A8; Wed, 27 Sep 2023 08:17:53 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org A9A42420A8 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D9824C0DEA; Wed, 27 Sep 2023 08:17:45 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 79668C0032 for ; Wed, 27 Sep 2023 00:13:39 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 553F6613BB for ; Wed, 27 Sep 2023 00:13:39 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 553F6613BB Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=expPSdve X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GYlRNfxWdz0O for ; Wed, 27 Sep 2023 00:13:38 +0000 (UTC) Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by smtp3.osuosl.org (Postfix) with ESMTPS id B3B8E613BD for ; Wed, 27 Sep 2023 00:13:38 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org B3B8E613BD Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1c5c91bece9so77930615ad.3 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=openvswitch.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=expPSdveo8Z/xdIbHLvVPfb2HcyzMkQxm+luObOzV372AIuamhagFJ+NJWY+ynkK8J Vm6jIisZMi4wP5X9ngwEvpjiqWQMrDoCumLhbY+MvTd6965bsxsoJ9uWT1MvPERxzYHW xCjy3i8nEjsVclJ9Tkkno441Aw5FRykxhHZcJG/Y9l5MF1cusVwofHc6kfsG9jpR6DeI Ihq3yr50CcXcXec7tWQtt5dzLag7HUGaAF11ELMx5RL855WHakrXKZRYm4rVATRlBR0U ObPb2IY9CTifrViNgbbgTfe68d3kMm5gaYzcoY0QvacyiIrf77Im9xMh6VXGv0WeEb/p Rwvw== 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=hb5a056NA/HnJzS3UkS8yEbRqKX94khojr7fXKWaLI7Yeo3/ZwdBm0OOSD7vh6PiSY g7O7Tjm3SDO5j6sBqm84DlJd8HZhOvDRQIoeuDRAfS1zPS+OaCbMNawGxafGD4pnw1g9 VSKQOdFasK1P0y0Udiod4fV+Wx1I0PKakLFSpDmjNuVDIDh6/D2p27V+UP0OFigi4dke mYA5iZgqxMogBKXtUMqYQ+DSRj5DtL2VsG7DhQfDCifNJYNkwlvuHvlRD2cqpt1EbCEU a+zZMNMWFUlvHwRz6cngTO5wKUmN4eM9nLfrrR6h8uLA5n8sgjCyBl7rIO1mAyz4nWYJ NPFA== X-Gm-Message-State: AOJu0Yxywq/W68/xFFBc2zYO9NRz7aAhfoLRCmB0JAcX0Z/eRmfiTwyU l5MtabahmzHX2y2/B6AlBD5aHTdIQbw= 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 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> MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 27 Sep 2023 08:17:38 +0000 Cc: dev@openvswitch.org, Nicholas Piggin Subject: [ovs-dev] [RFC PATCH 7/7] net: openvswitch: Reduce stack usage in ovs_dp_process_packet X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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; }