From patchwork Mon Nov 9 17:16:17 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5634 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:3317:b0:119:e1c9:93e6 with SMTP id bx23csp1181031lab; Mon, 9 Nov 2026 09:16:53 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHaBqc2Haslr2QZBUaTBup6bdCC/UFU5yW8/7S+pcD16yWUqCamJRiEOhxQl+VyhvnZHig4VXLI4sE=@openvpn.net X-Received: by 2002:a05:6830:4119:b0:845:8d86:9f8d with SMTP id 46e09a7af769-85f5073bc31mr3381648a34.8.1794244613293; Mon, 09 Nov 2026 09:16:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794244613; cv=none; d=google.com; s=arc-20260327; b=nO4Oxx16/la3Zx+e3EuL3UaqHLyQ8aWDdWyuXVp9bKgBawjucCjE/1d4YkpgP9wNWC V9/YsHdqXNLCxgitxPGHaFfL8F+n0pPgaP9PkAps4XD6pegoZSFNFjvEH74mOSp8HxhI kF5lAzMVJcWb8OIla+1r/e6r/6rVZq7967jq8nvNjyZqdEou1gzqhOITkPS4T2fhdkWJ oqGkKlEGbZaJTCOe0QcSIYe2Rqis8mu+tt/F5U9JFnQAVHsO/pQJTTZaEudH5QfFMZgO t3/dTYCiMLiFFsLVd3QubGfy5ysUOfi4jU/YCVn4AgK4zzMrtRLKiBnV07Q3HirJwbDN KzKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=20Jq7WR67GX75PFp5Ps8xRPvbdpqIgwFKUMvc0YyXIM=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=k1FdnQkd9Ukl3MQ2ebkdYThaLfobwWO49RQr7cfPAZf924q7CKImrIjTcc80E87/hb GwVZk2PnIOCjxfrO3YrOlSj+Jh9cYyamKSmf8PKYVvGhzQLYN8n2qXHv2pApP29Pl0p9 SK8mL20SKb9hxeh3ztBmqnog6OF2ZhE81/SET5hGpi0yRu7QseOcdMH0CybLsg2MZEvA XOy6NxP9C+PiYuhqnkoQQyOvPUkMZrFXrHJ5scGPhG/BcKvwXiVSCM//eAqAYuCzUSOn O7Rkmz0ohls0t7qCystNaAecpV5v1RNZM4p9sBhALjBTbkjct5sBrlZXqlM7/kRzKd+e l+Rw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=FatB7K6Z; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=DY3QdR5T; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=dtKqRkGX; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=HUXoAbfy; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 46e09a7af769-85f4fb3dcf3si5766779a34.63.2026.11.09.09.16.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 09:16:53 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=FatB7K6Z; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=DY3QdR5T; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=dtKqRkGX; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=HUXoAbfy; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=20Jq7WR67GX75PFp5Ps8xRPvbdpqIgwFKUMvc0YyXIM=; b=FatB7K6Z3e9fqE RF1l+CXO5yQArul0qugroBtFVyhUUEZmzIrSMCUEAwdf8fwdnHXVkJHfYXBV1k3kfy0y6J9nJecUC tfGu8lohgKDL3TKhf3PgQOVxHzQ5yl6qSAsMN8VFRu379dpSkbS51BG19h6VZgJTTuXXO4vjkMSTY e3M=; Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xQSzD-00000000720-1BtJ; Mon, 09 Nov 2026 17:16:51 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xQSzB-0000000071Y-1YKe for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=wiVtNqyOEa9hXkp56Be1GfF1HR/MiOKphtwMgZFKU0s=; b=DY3QdR5TIO+X9jgkfjrgX23H/3 sAZ/N4DAfuwWno/Wts0DUqNL0S2GTdMwWn15Lf3PuFM1p+1f14+7I9tXuKhAriz4tcCcWRI4/anAd Ix/As/n0PclFBVAk4jaejTlARvC/UOvCNayTBi1gTKx18T9kG/RJCG3Z6k+zujCOhNtk=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=wiVtNqyOEa9hXkp56Be1GfF1HR/MiOKphtwMgZFKU0s=; b=dtKqRkGXQupmLFTkxDl0kjxXE+ rK62bQkWfqHx5kRfenwQ4amPZXYXtWrOvmoHRA3ct0eHWCwpu9JyA2qczGtZ8eV8UAMPhy7uwNitt dtRYdFzIG3AlB3nkxF0Q2iLWZUJXqT55HLGfUFkfnwgnR04P5TE4/UB6+rzM19soZ1Rs=; Received: from mout-b-210.mailbox.org ([195.10.208.40]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQSz8-000000003aY-0mJt for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:49 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-210.mailbox.org (Postfix) with ESMTPS id 4jNbzm6TXCzFpkx for ; Mon, 09 Nov 2026 18:16:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794244596; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wiVtNqyOEa9hXkp56Be1GfF1HR/MiOKphtwMgZFKU0s=; b=HUXoAbfyaaAH7OoOPxBNwGihJXnhdEUXZquLHBQGFsA39QCikU1BJIJYQLSr6+HK0cwKwT LX6gGKfNAZ+ne5we+2n1w9BgeStF/0moOffqZwmdVedScDeXlEYQMbwtVdte4RuQ2CKHnH 87uBy6NHHboAy0CHLhIwV16qv4LBSSbULz2XSeaeRrGov1n/R9A7/HW1p2VWDfSlk7TGyR tbEN0K9HfqqI7FH2Am/XNA9fhnw9fTOx1vynkScTXsyoZDo0FclUEfuGrCLtY5JXy0oeZp DnnPN4vNUaOjDH1BVQK6g634H2b6isdaJqywEtnFT7kP+Xw5Mn5ijnpwuQHjGg== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 18:16:17 +0100 Message-ID: <1025ad1b437a4eb410967703dfd784a4ba8c30f5.1794244231.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNbzm6TXCzFpkx X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: ovpn already advertises software GSO support and segments GSO skbs in its transmit path. However, without checksum offload in the device features, the networking core has to segment GSO packets before [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1xQSz8-000000003aY-0mJt Subject: [Openvpn-devel] [PATCH ovpn net-next v5 1/9] ovpn: advertise checksum offload for GSO packets X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881401839859428985 X-GMAIL-MSGID: 1881401839859428985 ovpn already advertises software GSO support and segments GSO skbs in its transmit path. However, without checksum offload in the device features, the networking core has to segment GSO packets before they reach ovpn because TCP GSO packets normally carry CHECKSUM_PARTIAL state. Advertise NETIF_F_HW_CSUM so the stack can pass such packets to ovpn. Complete partial checksums after any GSO segmentation and before submitting packets for encryption, since the inner packet checksum can no longer be fixed after the packet has been encrypted. Also pass the ovpn feature set to skb_gso_segment with GSO capabilities masked out: this forces software segmentation, but still lets the segmenter preserve supported non-GSO properties such as non-linear skb data instead of needlessly linearizing. Account peer packet statistics for every segment which survives segmentation rather than once for the original GSO skb. Signed-off-by: Ralf Lici --- No changes since v4 https://lore.kernel.org/openvpn-devel/1025ad1b437a4eb410967703dfd784a4ba8c30f5.1794234673.git.ralf@mandelbit.com/ No changes since v3 https://lore.kernel.org/openvpn-devel/1025ad1b437a4eb410967703dfd784a4ba8c30f5.1794223133.git.ralf@mandelbit.com/ Changes since v2 https://lore.kernel.org/openvpn-devel/20261102164353.459969-2-ralf@mandelbit.com/ - Account peer packet statistics for every segment which survives GSO segmentation rather than once for the original GSO skb. (Sashiko) No changes since v1 https://lore.kernel.org/openvpn-devel/1bbfde37488ade61928554db3a119525adf7b608.1790843153.git.ralf@mandelbit.com/ drivers/net/ovpn/io.c | 23 ++++++++++++++++++++--- drivers/net/ovpn/main.c | 2 +- drivers/net/ovpn/stats.h | 10 +++++++++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/net/ovpn/io.c b/drivers/net/ovpn/io.c index f14eb4e6c46a..3b0c9b30e879 100644 --- a/drivers/net/ovpn/io.c +++ b/drivers/net/ovpn/io.c @@ -356,6 +356,7 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) struct ovpn_priv *ovpn = netdev_priv(dev); struct sk_buff *segments, *curr, *next; struct sk_buff_head skb_list; + netdev_features_t features; unsigned int tx_bytes = 0; struct ovpn_peer *peer; __be16 proto; @@ -390,8 +391,13 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) skb_dst_drop(skb); if (skb_is_gso(skb)) { - segments = skb_gso_segment(skb, 0); - if (IS_ERR(segments)) { + /* force software segmentation, but keep ovpn's non-GSO feature + * bits so the generated segments can preserve non-linear skb + * data where possible + */ + features = netif_skb_features(skb); + segments = skb_gso_segment(skb, features & ~NETIF_F_GSO_MASK); + if (IS_ERR_OR_NULL(segments)) { ret = PTR_ERR(segments); net_err_ratelimited("%s: cannot segment payload packet: %d\n", netdev_name(dev), ret); @@ -416,6 +422,16 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) continue; } + /* NETIF_F_HW_CSUM requires completing partial checksums */ + if (unlikely(curr->ip_summed == CHECKSUM_PARTIAL && + skb_checksum_help(curr) < 0)) { + net_err_ratelimited("%s: skb_checksum_help failed for payload packet\n", + netdev_name(dev)); + ovpn_dev_dstats_tx_dropped(ovpn->dev); + kfree_skb(curr); + continue; + } + /* only count what we actually send */ tx_bytes += curr->len; __skb_queue_tail(&skb_list, curr); @@ -430,7 +446,8 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) } skb_list.prev->next = NULL; - ovpn_peer_stats_increment_tx(&peer->vpn_stats, tx_bytes); + ovpn_peer_stats_add_tx(&peer->vpn_stats, tx_bytes, + skb_queue_len(&skb_list)); ovpn_send(ovpn, skb_list.next, peer); return NETDEV_TX_OK; diff --git a/drivers/net/ovpn/main.c b/drivers/net/ovpn/main.c index 0708249e9607..28e1eb06e127 100644 --- a/drivers/net/ovpn/main.c +++ b/drivers/net/ovpn/main.c @@ -157,7 +157,7 @@ static const struct ethtool_ops ovpn_ethtool_ops = { static void ovpn_setup(struct net_device *dev) { - netdev_features_t feat = NETIF_F_SG | NETIF_F_GSO | + netdev_features_t feat = NETIF_F_HW_CSUM | NETIF_F_SG | NETIF_F_GSO | NETIF_F_GSO_SOFTWARE | NETIF_F_HIGHDMA; dev->needs_free_netdev = true; diff --git a/drivers/net/ovpn/stats.h b/drivers/net/ovpn/stats.h index 3a45b97c0056..9331f5e9179b 100644 --- a/drivers/net/ovpn/stats.h +++ b/drivers/net/ovpn/stats.h @@ -40,10 +40,18 @@ static inline void ovpn_peer_stats_increment_rx(struct ovpn_peer_stats *stats, ovpn_peer_stats_increment(&stats->rx, n); } +static inline void ovpn_peer_stats_add_tx(struct ovpn_peer_stats *stats, + const unsigned int bytes, + unsigned int packets) +{ + atomic64_add(bytes, &stats->tx.bytes); + atomic64_add(packets, &stats->tx.packets); +} + static inline void ovpn_peer_stats_increment_tx(struct ovpn_peer_stats *stats, const unsigned int n) { - ovpn_peer_stats_increment(&stats->tx, n); + ovpn_peer_stats_add_tx(stats, n, 1); } static inline void ovpn_dev_dstats_tx_dropped(struct net_device *dev) From patchwork Mon Nov 9 17:16:18 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5633 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:3317:b0:119:e1c9:93e6 with SMTP id bx23csp1181032lab; Mon, 9 Nov 2026 09:16:53 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFoeL1BRE5OUDD+BWTbQKdpMpIEFoAzDXNEJqPBwxm5Ook8+DklnKLbFMHZW8Laeo81xxDjOk6tUuU=@openvpn.net X-Received: by 2002:a05:6808:1908:b0:4f9:595:b80c with SMTP id 5614622812f47-5683cd1a098mr241337b6e.41.1794244613424; Mon, 09 Nov 2026 09:16:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794244613; cv=none; d=google.com; s=arc-20260327; b=d9norCaMoXseL0I/l9T8b0gwRntYM8PrVrVK6yG/smkCKFeE6KeiAXocAyAbaOpw5W oQVpdomwNj346FcuG9ZdvdIFt8n4fd8B41S8b8jbBnQz7rJUtEtn/PhhzhYHhRAPWkTq lHPLQL/I72BGfxCD6toghfX4fuTt2YP4CGs9zSvI0sPKdrpASSXvMqhskSFPxR/imoIk NzUpY6WK/uSH2zo+ZdyISpgEHzu5pQ3ep6XrzhcXDsTyXPu8xfOyVM6hVMKSxdQo98QZ eyFwWKR2dRBFRCb5ss60gRHG4RMc3aGBBVOJut+6VP3ghdVufVjSIZ9HHwV39logDXq4 1p1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=67Hq2+nrHUw9mYQBRiq7NcKO4qMRw836EViL6xLZsgY=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=QghwkP+dnsGMvV0B//8cb8lowIJE8EcCJGqpn/7qdLStnA6KraA2CsbGdykjmLysN7 2t/BltYxQ2+FbZ62UxUjDQuPl3gr57Wo40uf8CYQmAG96srcJQsVrQ7PyrfapzrRuOcf xsx484ViTTc88w8rpn0UkGfu05F6y+qjUHKFQA2ZmmVpN6ypAANBpOGL7BWQxwShAoxy mQ3TtpGNkErPfOUmKgk49ct84kSjgxmoDRyvAbffn5LZGFu2KXq/uwH/0PecAL0iGSOE +YH4WDPyKlGNAypLtufPHiBlB99iFnRb03NX8hjw64rrfmHvIlcGB2O+1it4W2EFn8/u dRcg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=PTIkzVLE; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=RLFjXnEg; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="MvB/v8av"; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=Laq3iNeh; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 5614622812f47-56813aea885si5211078b6e.43.2026.11.09.09.16.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 09:16:53 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=PTIkzVLE; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=RLFjXnEg; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="MvB/v8av"; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=Laq3iNeh; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=67Hq2+nrHUw9mYQBRiq7NcKO4qMRw836EViL6xLZsgY=; b=PTIkzVLEqDQeFp sk/yRvx7nUiF5KsIamVwr8b+Pk+N/cfArLNzieNEdUXXMmVaOHDtpVp9PF4c3yCoJk2OyWDgz/BM9 ExPwExSnN7AfxYyq+nICjyxJqhr9hR3kN2HPwQLE8rFQzaRLPQUs8n7qUVa45yG6KTeld2iEHE/ok OcQ=; Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xQSzD-000000005Sp-3qJr; Mon, 09 Nov 2026 17:16:51 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xQSzA-000000005Sb-2MWF for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=8VpvfRV9IalDBp6BcmhGmtP7iyH2XayIHrt7UJGMm7Y=; b=RLFjXnEgICOQuEzD4ySoGQZOyQ 3DwNqD0UrCqZ0k8rVzAQtPmeQNa4qTEHP01DPxvkNx3WXEsFDkJXofrwp0/Ue+0ZiF4Q/UcmBz1v/ /9q5oSxWwVnqlnLdmVGfWhANftHm05U32Oy6xsXZn650E65SMuxX6cxxvO51pfZY7sUQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=8VpvfRV9IalDBp6BcmhGmtP7iyH2XayIHrt7UJGMm7Y=; b=MvB/v8aviyhlkweOI890rPSkY3 DQOL9RTY7xmVgteZUs0U4J/dDkqLZM3B2LoxLQe7H6YjqtbKntKpu33Qv6OzgJZYuZ0Jv8YrH6GBh ajEMvXEUnIBO5ab5ti3dirrhPlrBNX2l47WLS362ff4VNwPZyVLgNeKPNq4h1msRE8eI=; Received: from mout-b-106.mailbox.org ([195.10.208.46]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQSz7-000000003aX-3R8t for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:48 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-106.mailbox.org (Postfix) with ESMTPS id 4jNbzn2lxWzNldX for ; Mon, 09 Nov 2026 18:16:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794244597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8VpvfRV9IalDBp6BcmhGmtP7iyH2XayIHrt7UJGMm7Y=; b=Laq3iNehb0bK3bLE4oPnrAUVS6Y7LGF+jzGO/4s4hqDwMlVo+9VeX4c8osJxUvS8RPYYwU /w+m5sfM38ddlEDqmQnHS9uaQro+s/OFO5waACL4pgiq1FxDQgDG/hgFN36uhlg/yOQu5x Dydhobs+dHef39J4oTFVGMpkJpB0pr8DtYRJp8hWJ/qx3WGgdOf1qqlx5o0K/yom1ctiNS wOMqj5ZFphuLFPt5rcajf5wwiO08rDo0ehEZ0OW8hWT286R1m6bTmcSb0VgzrYgRDChZxc 45piqdqqFr0Q3/AgeNOeCd7RXrpOxJfKV3eGMnTs7x+jvU4ifavOTVoeJjS0Aw== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 18:16:18 +0100 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNbzn2lxWzNldX X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Forwarded TCP traffic can be coalesced into SKB_GSO_FRAGLIST when the receiving host has no local TCP socket for the flow. Although ovpn segments every GSO input itself, it does not advertise NETIF_F_ [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1xQSz7-000000003aX-3R8t Subject: [Openvpn-devel] [PATCH ovpn net-next v5 2/9] ovpn: accept frag-list GSO input X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881401839906694793 X-GMAIL-MSGID: 1881401839906694793 Forwarded TCP traffic can be coalesced into SKB_GSO_FRAGLIST when the receiving host has no local TCP socket for the flow. Although ovpn segments every GSO input itself, it does not advertise NETIF_F_FRAGLIST, so generic transmit validation segments these aggregates before calling ovpn_net_xmit. That segmentation is functionally correct, but causes ovpn_net_xmit to be invoked separately for every resulting packet. Advertise frag-list storage so ovpn receives the aggregate intact and performs protocol validation and destination-to-peer lookup once before segmenting it. Frag-list GSO segmentation recovers the complete child skbs, which can then be encrypted in place and transmitted independently. The feature also admits non-GSO frag lists, which describe one packet split across several skbs. Let skb_cow_data preserve small lists directly. If a list exceeds the AEAD scatterlist limit, linearize it and continue rather than rejecting an otherwise valid packet. Signed-off-by: Ralf Lici --- No changes since v4 https://lore.kernel.org/openvpn-devel/d9c14824ec8786328076546ede61c98e21cf88ed.1794234673.git.ralf@mandelbit.com/ No changes since v3 https://lore.kernel.org/openvpn-devel/d9c14824ec8786328076546ede61c98e21cf88ed.1794223133.git.ralf@mandelbit.com/ Changes since v2 https://lore.kernel.org/openvpn-devel/20261102164353.459969-3-ralf@mandelbit.com/ - Update the commit message now that fixed-size frag-list GSO input can use the UDP GSO output path. No changes since v1 https://lore.kernel.org/openvpn-devel/5baa1d94e29e7b109ffd412b4f1d5d113a319389.1790843153.git.ralf@mandelbit.com/ drivers/net/ovpn/crypto_aead.c | 8 ++++++-- drivers/net/ovpn/main.c | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index 74eaf6fac2f5..2af493fd5735 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -168,8 +168,12 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, if (unlikely(nfrags < 0)) return nfrags; - if (unlikely(nfrags + 2 > (MAX_SKB_FRAGS + 2))) - return -ENOSPC; + if (unlikely(nfrags > MAX_SKB_FRAGS)) { + ret = skb_linearize(skb); + if (unlikely(ret)) + return ret; + nfrags = 1; + } /* allocate temporary memory for iv, sg and req */ tmp = kmalloc(ovpn_aead_crypto_tmp_size(ks->encrypt, nfrags), diff --git a/drivers/net/ovpn/main.c b/drivers/net/ovpn/main.c index 28e1eb06e127..ac4e0d85e215 100644 --- a/drivers/net/ovpn/main.c +++ b/drivers/net/ovpn/main.c @@ -158,7 +158,8 @@ static const struct ethtool_ops ovpn_ethtool_ops = { static void ovpn_setup(struct net_device *dev) { netdev_features_t feat = NETIF_F_HW_CSUM | NETIF_F_SG | NETIF_F_GSO | - NETIF_F_GSO_SOFTWARE | NETIF_F_HIGHDMA; + NETIF_F_GSO_SOFTWARE | NETIF_F_FRAGLIST | + NETIF_F_HIGHDMA; dev->needs_free_netdev = true; From patchwork Mon Nov 9 17:16:19 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5637 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp982954lat; Mon, 9 Nov 2026 09:18:13 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFCCTsH71BAZPp+kkBEQ+oBLfdrOYVkdcQhro/B5MnQjJOiZpxUoH9PiN402Z1IST4bVAuEtl6xdh0=@openvpn.net X-Received: by 2002:a05:6870:e304:b0:48f:e137:dc7f with SMTP id 586e51a60fabf-4adecb4dcc1mr2599892fac.57.1794244613170; Mon, 09 Nov 2026 09:16:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794244613; cv=none; d=google.com; s=arc-20260327; b=eoG3p6JD+zUZuLJjBWT6S6/ZVI+PJ1ir8i1YkoqSdFrekT96iIf79WTMmZzyZAi5Ye 2tJ7olhyu6WvAua2I0vPTI7ODoeYMy7xqONOFNf0/I/sP+pbYXSfadyLINlDqKb+N9xI vBEDzobcR/vu13Vu8vlljS4KNx8me5+cEhkZdGCX4lGfUzJX92/y48lNbqzVzjgmhIFx nB3dZ9wx/1/JY7SbYnJ4S0M2NxCu/FII/pGmCJvoY421rXMXAHQKBI1BkwM2s/2soi7u AT4Y8a3q2u1hggVbfqmrTQlUoWsPKzW7oX9B3++heMsnWcfZExYtt8x0CIXjM0WFrvVy HduA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=AlSjeqZ1Imc9mc7JKhC7PdOdn3+rXLbCHUnvYrdP4vo=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=ZjgTsYZHAyk9zqB6I/S9z/s6cEnM78qDU6h6b7LUUajzH8ThCwyNqL8k/GyM91mqYa HSOK/oMjow7PuLdKLblu3xiMfKGsfroredIJ70rJK1sYhqMJeBm0vKCzW8yas5vlIWYK cgKIX+KpFyyKh+QGOeMBscODObaHw+Q+M8XgCyt6JgwjMDNRUUjn4oZGSE+7gsZ73nEc +SME0bxQqXm1Lqvq4jVhTYsCH9U8jubsHxP3OmVVM4Y9f1DbSuNfDsn6NyjxvclYaRDF KrVMGG5Xci8QOAmwgvLKYpLGhPyOBL2/wU9/I54KjJDL7KpM5XR/79x1FjR2aBOi8hWS LIKw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=JIMr6ITK; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=c6+lmnak; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=CseNgxfp; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=Y+PYnkiu; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 586e51a60fabf-4ade64c7afbsi5957022fac.10.2026.11.09.09.16.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 09:16:53 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=JIMr6ITK; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=c6+lmnak; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=CseNgxfp; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=Y+PYnkiu; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=AlSjeqZ1Imc9mc7JKhC7PdOdn3+rXLbCHUnvYrdP4vo=; b=JIMr6ITKI6GlNg FDj+urdUwQCsuJRDLVuGyuR6No7nfBabedOv3EN0s4iuplUGdCdbv8QEXcuCbAuGa0gDHtr4ZpFjt Gxyu7QnZq1DSURXPXA1+/Azh5YTsmDlf+ECV3VyNotI76RchNfwC/g92I4zYKuuggCzcs3nObqUTb ioQ=; Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xQSzB-000000002ZQ-00OC; Mon, 09 Nov 2026 17:16:49 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xQSz9-000000002ZJ-3mQT for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=JpGIDN3lXSTNLLtzvcz4xeRUH+MNCJpOFLV4Mg3yvSo=; b=c6+lmnakjszRAEp9/+ZJZnPh+f gc8NVNM4wIH3HIa47UyUNRQoCn7vf6AXhYSka63r5lTFLfOwCWkj76zbgvjtAUQSsEwbeCPR/3AB7 PLsfPmlHf4fYXheXWFxq4ur37ybpgspY8DaxiE+2/190GR/aVkOu1B6EzQ/ez60PlhjU=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=JpGIDN3lXSTNLLtzvcz4xeRUH+MNCJpOFLV4Mg3yvSo=; b=CseNgxfpBQSLoETwI5eSMh206R gsatcvnlDh/anyPhkDassiJz3zJ3o7hTryFPapL2UYPf5QBzwirJGxTPfKkyuH1ED6ZmqzAbD/oiF V/I3m4NLe1rF50YqTO7Xt0jeHbQJY6KQ3Y10z/TsflI2JFGK5QA1Lso5bAPtkIhBdG2o=; Received: from mout-b-110.mailbox.org ([195.10.208.55]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQSz7-000000004gY-2xfB for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:47 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-110.mailbox.org (Postfix) with ESMTPS id 4jNbzn54mRzNl79 for ; Mon, 09 Nov 2026 18:16:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794244597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JpGIDN3lXSTNLLtzvcz4xeRUH+MNCJpOFLV4Mg3yvSo=; b=Y+PYnkiumoSrGN+qdZ/BwSZT3NKBeWmHr/7FQtRjhJjUXPPuimRw80lq8lrwLuwDFlyV/W oRdSXhmoadVoWnLra3wVdJsfzGkSFRt9cVNRT7jAbDK0RLtIHBXbfOAJKQy7p/8ypRH8Vj 5IXvU5hgyB3EGw25gy+uQ4snCDLWLccWFSYx/JZEo+c2pX9mNmDgwBmu+mcRoYyg+iRZYl 2rrqEpvEPPGKwbbpTLG+054XGf6AinjP+wpGBgbTK2JOargfYKREdlIjEzn1SeVPfe1RVa j5larEgw3u2uFH1YVIlF0gyl6e7+6HuHVCW7C8rcsrILlYkRIYGdfB3pDZzrKg== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 18:16:19 +0100 Message-ID: <2f20065198c3c020b9612b52d5452e8028fbca77.1794244231.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNbzn54mRzNl79 X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-2.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Move DATA_V2 framing sizes to the protocol header and factor request allocation and header construction into helpers. This prepares the transmit path for an out-of-place encryption destination without [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-Headers-End: 1xQSz7-000000004gY-2xfB Subject: [Openvpn-devel] [PATCH ovpn net-next v5 3/9] ovpn: refactor AEAD encryption helpers X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881401839806002047 X-GMAIL-MSGID: 1881401839806002047 Move DATA_V2 framing sizes to the protocol header and factor request allocation and header construction into helpers. This prepares the transmit path for an out-of-place encryption destination without changing packet handling. Signed-off-by: Ralf Lici --- No changes since v4 https://lore.kernel.org/openvpn-devel/2f20065198c3c020b9612b52d5452e8028fbca77.1794234673.git.ralf@mandelbit.com/ No changes since v3 https://lore.kernel.org/openvpn-devel/2f20065198c3c020b9612b52d5452e8028fbca77.1794223133.git.ralf@mandelbit.com/ No changes since v2 https://lore.kernel.org/openvpn-devel/20261102164353.459969-4-ralf@mandelbit.com/ No changes since v1 https://lore.kernel.org/openvpn-devel/f075b9782b14d64756c84e132c138482f08287b9.1790843153.git.ralf@mandelbit.com/ drivers/net/ovpn/crypto_aead.c | 97 ++++++++++++++++++++-------------- drivers/net/ovpn/io.h | 3 +- drivers/net/ovpn/proto.h | 4 ++ 3 files changed, 63 insertions(+), 41 deletions(-) diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index 2af493fd5735..30299581422d 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -24,9 +24,6 @@ #include "proto.h" #include "skb.h" -#define OVPN_AUTH_TAG_SIZE 16 -#define OVPN_AAD_SIZE (OVPN_OPCODE_SIZE + OVPN_NONCE_WIRE_SIZE) - #define ALG_NAME_AES "gcm(aes)" #define ALG_NAME_CHACHAPOLY "rfc7539(chacha20,poly1305)" @@ -42,7 +39,7 @@ static int ovpn_aead_encap_overhead(const struct ovpn_crypto_key_slot *ks) * an AEAD request structure with extra space for SG * and IV. * @tfm: the AEAD cipher handle - * @nfrags: the number of fragments in the skb + * @nents: the number of scatterlist entries * * This function calculates the size of a contiguous memory block that includes * the initialization vector (IV), the AEAD request, and an array of scatterlist @@ -54,7 +51,7 @@ static int ovpn_aead_encap_overhead(const struct ovpn_crypto_key_slot *ks) * Return: the size of the temporary memory that needs to be allocated */ static unsigned int ovpn_aead_crypto_tmp_size(struct crypto_aead *tfm, - const unsigned int nfrags) + const unsigned int nents) { unsigned int len = OVPN_NONCE_SIZE; @@ -70,8 +67,8 @@ static unsigned int ovpn_aead_crypto_tmp_size(struct crypto_aead *tfm, /* round up to the next multiple of the scatterlist alignment */ len = ALIGN(len, __alignof__(struct scatterlist)); - /* add enough space for nfrags + 2 scatterlist entries */ - len += array_size(sizeof(struct scatterlist), nfrags + 2); + /* add enough space for the scatterlist entries */ + len += array_size(sizeof(struct scatterlist), nents); return len; } @@ -135,6 +132,53 @@ static struct scatterlist *ovpn_aead_crypto_req_sg(struct crypto_aead *aead, __alignof__(struct scatterlist)); } +static struct aead_request *ovpn_aead_request_alloc(struct crypto_aead *aead, + struct sk_buff *skb, + unsigned int nents, u8 **iv) +{ + struct aead_request *req; + void *tmp; + + /* allocate IV, request and scatterlist entries in one block */ + tmp = kmalloc(ovpn_aead_crypto_tmp_size(aead, nents), GFP_ATOMIC); + if (unlikely(!tmp)) + return ERR_PTR(-ENOMEM); + + ovpn_skb_cb(skb)->crypto_tmp = tmp; + *iv = ovpn_aead_crypto_tmp_iv(aead, tmp); + req = ovpn_aead_crypto_tmp_req(aead, *iv); + + return req; +} + +static int ovpn_aead_encrypt_header(struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, + u8 *iv, u8 *data) +{ + u32 pktid, op; + int ret; + + /* obtain packet ID, which is used both as a first + * 4 bytes of nonce and last 4 bytes of associated data. + */ + ret = ovpn_pktid_xmit_next(&ks->pid_xmit, &pktid); + if (unlikely(ret < 0)) + return ret; + + /* concat 4 bytes packet id and 8 bytes nonce tail into 12 bytes + * nonce + */ + ovpn_pktid_aead_write(pktid, ks->nonce_tail_xmit, iv); + + /* add the packet opcode and wire nonce as associated data */ + op = ovpn_opcode_compose(OVPN_DATA_V2, ks->key_id, peer->tx_id); + BUILD_BUG_ON(sizeof(op) != OVPN_OPCODE_SIZE); + *(__force __be32 *)data = htonl(op); + memcpy(data + OVPN_OPCODE_SIZE, iv, OVPN_NONCE_WIRE_SIZE); + + return 0; +} + int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb) { @@ -143,8 +187,6 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *trailer; struct scatterlist *sg; int nfrags, ret; - u32 pktid, op; - void *tmp; u8 *iv; ovpn_skb_cb(skb)->peer = peer; @@ -175,16 +217,9 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, nfrags = 1; } - /* allocate temporary memory for iv, sg and req */ - tmp = kmalloc(ovpn_aead_crypto_tmp_size(ks->encrypt, nfrags), - GFP_ATOMIC); - if (unlikely(!tmp)) - return -ENOMEM; - - ovpn_skb_cb(skb)->crypto_tmp = tmp; - - iv = ovpn_aead_crypto_tmp_iv(ks->encrypt, tmp); - req = ovpn_aead_crypto_tmp_req(ks->encrypt, iv); + req = ovpn_aead_request_alloc(ks->encrypt, skb, nfrags + 2, &iv); + if (IS_ERR(req)) + return PTR_ERR(req); sg = ovpn_aead_crypto_req_sg(ks->encrypt, req); /* sg table: @@ -206,28 +241,12 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, __skb_push(skb, tag_size); sg_set_buf(sg + ret + 1, skb->data, tag_size); - /* obtain packet ID, which is used both as a first - * 4 bytes of nonce and last 4 bytes of associated data. - */ - ret = ovpn_pktid_xmit_next(&ks->pid_xmit, &pktid); + /* make space for the additional data and push it to the front */ + __skb_push(skb, OVPN_AAD_SIZE); + ret = ovpn_aead_encrypt_header(peer, ks, iv, skb->data); if (unlikely(ret < 0)) return ret; - /* concat 4 bytes packet id and 8 bytes nonce tail into 12 bytes - * nonce - */ - ovpn_pktid_aead_write(pktid, ks->nonce_tail_xmit, iv); - - /* make space for packet id and push it to the front */ - __skb_push(skb, OVPN_NONCE_WIRE_SIZE); - memcpy(skb->data, iv, OVPN_NONCE_WIRE_SIZE); - - /* add packet op as head of additional data */ - op = ovpn_opcode_compose(OVPN_DATA_V2, ks->key_id, peer->tx_id); - __skb_push(skb, OVPN_OPCODE_SIZE); - BUILD_BUG_ON(sizeof(op) != OVPN_OPCODE_SIZE); - *((__force __be32 *)skb->data) = htonl(op); - /* AEAD Additional data */ sg_set_buf(sg, skb->data, OVPN_AAD_SIZE); @@ -281,7 +300,7 @@ int ovpn_aead_decrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, return -ENOSPC; /* allocate temporary memory for iv, sg and req */ - tmp = kmalloc(ovpn_aead_crypto_tmp_size(ks->decrypt, nfrags), + tmp = kmalloc(ovpn_aead_crypto_tmp_size(ks->decrypt, nfrags + 2), GFP_ATOMIC); if (unlikely(!tmp)) return -ENOMEM; diff --git a/drivers/net/ovpn/io.h b/drivers/net/ovpn/io.h index db9e10f9077c..1a94f0fda1d1 100644 --- a/drivers/net/ovpn/io.h +++ b/drivers/net/ovpn/io.h @@ -11,8 +11,7 @@ #define _NET_OVPN_OVPN_H_ /* DATA_V2 header size with AEAD encryption */ -#define OVPN_HEAD_ROOM (OVPN_OPCODE_SIZE + OVPN_NONCE_WIRE_SIZE + \ - 16 /* AEAD TAG length */ + \ +#define OVPN_HEAD_ROOM (OVPN_DATA_V2_OVERHEAD + \ max(sizeof(struct udphdr), sizeof(struct tcphdr)) +\ max(sizeof(struct ipv6hdr), sizeof(struct iphdr))) diff --git a/drivers/net/ovpn/proto.h b/drivers/net/ovpn/proto.h index b7d285b4d9c1..f3b305cbefe5 100644 --- a/drivers/net/ovpn/proto.h +++ b/drivers/net/ovpn/proto.h @@ -39,6 +39,10 @@ #define OVPN_NONCE_WIRE_SIZE (OVPN_NONCE_SIZE - OVPN_NONCE_TAIL_SIZE) #define OVPN_OPCODE_SIZE 4 /* DATA_V2 opcode size */ +#define OVPN_AUTH_TAG_SIZE 16 +#define OVPN_AAD_SIZE (OVPN_OPCODE_SIZE + \ + OVPN_NONCE_WIRE_SIZE) +#define OVPN_DATA_V2_OVERHEAD (OVPN_AAD_SIZE + OVPN_AUTH_TAG_SIZE) #define OVPN_OPCODE_KEYID_MASK 0x07000000 #define OVPN_OPCODE_PKTTYPE_MASK 0xF8000000 #define OVPN_OPCODE_PEERID_MASK 0x00FFFFFF From patchwork Mon Nov 9 17:16:20 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5635 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:3317:b0:119:e1c9:93e6 with SMTP id bx23csp1181033lab; Mon, 9 Nov 2026 09:16:53 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHf8wxjON395xQHAO8RCV3lYQIBirn91vgKw3/3I8Kxxju6Pe9iahWKoOijJ1CawMImuYp1CE/2A6Q=@openvpn.net X-Received: by 2002:a05:6830:2b23:b0:847:db9d:abfe with SMTP id 46e09a7af769-860dbfde16emr71758a34.23.1794244613395; Mon, 09 Nov 2026 09:16:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794244613; cv=none; d=google.com; s=arc-20260327; b=lvrxHa4lat0L1d5YyLh0LNUVyEJvaqEK/ZEBVdHz5hach52z5BP3XEc5qco4dJSZPC N1yyVTLptMGH9bz4ibP9t1uf/bclurxj6+aH4baJvOEFjmCMkzsJ3YBE4WnirZhymggq uR1l4tpPSYKhZsupz0lLp3GaS2uXTEhHa+BpATy3Obv3OuytZRJvowHBV9nbQRe77nbS lC7Ni3GqNV1gb7MUdleDWic9GMC8SkO269BpzWTiaY1kf+woLBFh01YEwMWvNB+xaIlj x5u0l9nq67ldmk+Ch5RgFEeVjLV6WsMAKmA8HprfMYdHPT345RNI1SukvsTZbaAik4Z5 fmJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=wShcAArO456Ewmmz6uXqc9o0FiHNL0d81qFICKY/ygE=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=WbVOr4vmg+mky1eXJeEnIh+7SEXbK7JIba+QYlQbQoWBQPHjEmqPl0MWCNwkA1YgFg jcKBf74FqswjVT6MYxa4yRnbG73pWRek15TTjOCMvCN86kN3MMrwnb9nuiqgzIGoz56r o6pK8KQ7m9IB2r5l1ZoCsAwJGXAqTsxWsgMvtfzhuhqX5iXRKb1zmbjLCGzEsWX4hCNP Xalmb/ianwkTOmGe1fzyr+7u69vDtkViYZo45byfHXiLHSFGLRxMPLnG0CKchGVHLrFB lrR7gvT/KLJ9inxfp3wyBEBrqWPceJ6tR8hU+MtmEodjY3nm2W+oCMYyiX9oTTK8SeF/ ixjA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=ZtkeHq7j; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Uf9ugsqV; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Enpi0diZ; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=E6Zrp03F; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 46e09a7af769-860db86e638si335817a34.3.2026.11.09.09.16.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 09:16:53 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=ZtkeHq7j; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Uf9ugsqV; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Enpi0diZ; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=E6Zrp03F; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=wShcAArO456Ewmmz6uXqc9o0FiHNL0d81qFICKY/ygE=; b=ZtkeHq7jPokrg/ O6Ak9ktTHFM82Dev9B2skh4xbsBvW8FWl6fnN1B+tq5fH78PrPFxTQ8vC5mn8dvz5vHzvxSfmBRfj gbHCTUFAeXe22IT7rCkuDt+BSHGRO1VE7rPr616U063aylaWXXPMGt3Ko4iGcz0ILeDAJF8jEto/s vvw=; Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xQSzD-0000000072D-1qMf; Mon, 09 Nov 2026 17:16:51 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xQSzC-0000000071m-1lzy for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=4/L3lBlo8ps1ZrYb9ptJvVUdbT4CceCmF3qzRP4wyUs=; b=Uf9ugsqVXd5OPTufco0E9QJNgi wjIRldXeNuHHHE5XuCUoAPDbzYiq64NTg6W3EazDuibV6f9s62PKcd391TXh881+RI6m9DPtlreRZ bx7doJP3jluxPhn0UhpL5S37ANbfMBftnELOcCQo9RHGVWXwirY3Zv0zyc2PEN2mbuHM=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=4/L3lBlo8ps1ZrYb9ptJvVUdbT4CceCmF3qzRP4wyUs=; b=Enpi0diZ1YXml2TT6GovSBPJ4g FymdPOEKyIQSyY1MRY8iHCDp4qCeiig/hTWOPlS3k/7SFsGZnp2ie6ibVUCHxHy8y6K1dusqv7GP+ DF7uatrFzi07k+a2Mbh5QIrXLl+JlNHfeaAMGqolgqnWJeCRHJcTaXhrbucyzHcOjnDk=; Received: from mout-b-112.mailbox.org ([195.10.208.42]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQSz8-000000004ge-1R5m for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:50 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-112.mailbox.org (Postfix) with ESMTPS id 4jNbzn6zFmz5wP4 for ; Mon, 09 Nov 2026 18:16:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794244598; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4/L3lBlo8ps1ZrYb9ptJvVUdbT4CceCmF3qzRP4wyUs=; b=E6Zrp03F6Xq4SXxpnO4syRVGQrKRj+v2R8BZ1Idgr0VRv6wh7YM7end0AQfyNyk2g13y0u rbKYBIUp+j8D0atoGAhJLg5Ck1JdkrW/rWkT+3yciCdaYy/F7RQ1Yc4YpqvCmSBPGTymG0 Tb9Virzok4HC8Dx+D0zUSvR159p8889fgNezXlYOQLLlOSzatYrU4GhYulJKFH2Nh1b2XX X50yJWgltqxpA0V1H4++Ak/quY49mg4bqqFWBrZfJ6aAmzo0TyG4j8Uxy66SiYIGc0S1Lg dxOKken987JguYUNtrOWFDqSchfGZNYYmtTOaRyTq9QWlVutE2NMG9yyT7jy/Q== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 18:16:20 +0100 Message-ID: <1533a769382fd369d6f3e839d870f42efd1b4809.1794244231.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNbzn6zFmz5wP4 X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The UDP GSO output path introduced next requires a synchronous encrypt transform. Record the transform type in the immutable key slot when it is created, avoiding repeated inspection of the crypto alg [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1xQSz8-000000004ge-1R5m Subject: [Openvpn-devel] [PATCH ovpn net-next v5 4/9] ovpn: record asynchronous transmit crypto X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881401839902923651 X-GMAIL-MSGID: 1881401839902923651 The UDP GSO output path introduced next requires a synchronous encrypt transform. Record the transform type in the immutable key slot when it is created, avoiding repeated inspection of the crypto algorithm flags in the data path. Signed-off-by: Ralf Lici --- No changes since v4 https://lore.kernel.org/openvpn-devel/1533a769382fd369d6f3e839d870f42efd1b4809.1794234673.git.ralf@mandelbit.com/ No changes since v3 https://lore.kernel.org/openvpn-devel/1533a769382fd369d6f3e839d870f42efd1b4809.1794223133.git.ralf@mandelbit.com/ New in v3. drivers/net/ovpn/crypto.h | 2 ++ drivers/net/ovpn/crypto_aead.c | 1 + 2 files changed, 3 insertions(+) diff --git a/drivers/net/ovpn/crypto.h b/drivers/net/ovpn/crypto.h index e3feb16d5498..8ce324e9b58f 100644 --- a/drivers/net/ovpn/crypto.h +++ b/drivers/net/ovpn/crypto.h @@ -39,6 +39,8 @@ struct ovpn_peer_key_reset { struct ovpn_crypto_key_slot { u8 key_id; + /* whether the encrypt transform is asynchronous */ + bool async; struct crypto_aead *encrypt; struct crypto_aead *decrypt; diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index 30299581422d..5e5320338165 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -462,6 +462,7 @@ ovpn_aead_crypto_key_slot_new(const struct ovpn_key_config *kc) ks->encrypt = NULL; goto destroy_ks; } + ks->async = crypto_tfm_is_async(crypto_aead_tfm(ks->encrypt)); ks->decrypt = ovpn_aead_init("decrypt", alg_name, kc->decrypt.cipher_key, From patchwork Mon Nov 9 17:16:21 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5632 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp981166lat; Mon, 9 Nov 2026 09:16:53 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHBuoof2UoYnkR0fNH4wKaOTguv1pHZHnJUgxDlF3DLmqz5GYJvcvuzji2Yt+iwH5ybf2NzvjFFRHo=@openvpn.net X-Received: by 2002:a05:6808:124d:b0:4d7:17d5:6c9b with SMTP id 5614622812f47-5683c73be25mr260412b6e.9.1794244613101; Mon, 09 Nov 2026 09:16:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794244613; cv=none; d=google.com; s=arc-20260327; b=Ck6pLPaptjtyfG1uLjgbeoa4/ZfQbpKzH8Rcpaz6CHF2jajje3XKHLPXWChT67JxIk nnXs5UEKT1jSXCxBj2Kn/jP8Pi595IvEJWhAWaO9u5Zszd80xe5R/HReUKZYrV4djtcW elMPKIdPr9woxpzCNnyDXZ2QHAzDP0maNLuovLx0bwTSSvMQnkjy04meMkjGCr16Bg80 awX4eYgnU6IkoLkdTgaykOBLtpE4sOuC/QE9834/uEHYvUaOGNigep35vS5CK+4yPPZM +pLR90WvXHSoYb1P1ZWWjVsUfTeRyf/giONxwIOXJbWSdqI+pKqYZlv9mFcDwHsn4dR1 M9iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=UcYANbV+gT4UYVEtqkacmwIfQaxQQ3xDB3kRPM6K7Lc=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=WGLBplpbrNtEbFGYTMipqjJjYAmZgUSC8Hp+3RYVhJYo7WK0Kpov2032dXnWXz/C3F vo2NZaz5W8MGkRDivvkgnyZLS28wOWVPPJFsmgSN5VlPVlVkzgQLWTR4ybczXLdHkHJP gwntJq0i8IInqv75+AhhOi2Gmi8nSxBHXIdzVsUqCaGQX1WRbnklyAnFXKNR8tjStDPm bbG8RyK/LJJBpDoU+AaZ4o7u8bvdPXQObAOevfWKUXe0FZmTV1dPcTg7fzRgSBNwp4cH /wMQZFJITmZtCDEwXXQ/gx6R8g/hsoIeufSkipzLKHkZOkLw+kXqJ3vwAoiS5lXfKvD8 EG+A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=Prkw8AOK; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=VrNyaWVt; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=BsWPq9FJ; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=sbREPBDt; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 5614622812f47-56813b5616bsi5176828b6e.66.2026.11.09.09.16.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 09:16:53 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=Prkw8AOK; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=VrNyaWVt; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=BsWPq9FJ; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=sbREPBDt; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=UcYANbV+gT4UYVEtqkacmwIfQaxQQ3xDB3kRPM6K7Lc=; b=Prkw8AOKNR3PZz 6qW8DIzbSwyEL1mgLtSC4amSsMPAAilyjcxV9CPBUE6zo0DQ/NsnJgZpCH946Wq7BQO2zx07AqTd1 Vostuk0sFRXy1GbHse7pRxc+sw1ijWHESg7+zFl1BAeKFUpQBGEPcLNmaYUJCIqKHz1H0uHMku/7z 3Vg=; Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xQSzC-0000000071f-0gVh; Mon, 09 Nov 2026 17:16:50 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xQSz9-0000000071Q-2KIb for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=+zLtSnmWsvLRpgfDMIGDTINlrWeCJaBlFoakE+L4Xp8=; b=VrNyaWVt/IjYU965IzV3SEIMna L0x8aTNeyNhMf3LxWqWugf0YBENcI0w/LVkwXuAIgWzZqmboFdt/HtxL4R5LHnZTVwCgrPMy9GSbE Q0pFXMZNPWn8ZWhYvcBEVuElM+8AcNI31eupAuI9g1fxDrt/Peeq4Rthrt+U5qYz0qFQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=+zLtSnmWsvLRpgfDMIGDTINlrWeCJaBlFoakE+L4Xp8=; b=BsWPq9FJs7c9D2pt8awTkDWfmo oxNvEZvIlsjdpap+hzMvtE6J/04GhgzG+sWkl/B+cRigWk1Hy7oKP3tkhtDFneSc+H4LxSFYwLqjL kIENAX8qgcdXH4Dfktdh0sx59Xt2IW40uQjlGJGG+L5gXT770QA1PusfCx08hcv82ZXM=; Received: from mout-b-201.mailbox.org ([195.10.208.61]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQSz8-000000004gd-0KXi for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:47 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-201.mailbox.org (Postfix) with ESMTPS id 4jNbzp1VtBzLlb5 for ; Mon, 09 Nov 2026 18:16:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794244598; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+zLtSnmWsvLRpgfDMIGDTINlrWeCJaBlFoakE+L4Xp8=; b=sbREPBDtt2nw8Z0XUpkWCdx0PI1EWxquenmj6vNYRdBQ0J0d/5Vra/RPrT3Z8y2OnmMutm jHVxf0RroihSChLr7jndm2b5ZdqVTgbsKpHBOWP324MiXb9AObaIg3FNzCt0E9QyqAva6e ABw2Vy2MYBOw8wQV5iERWhr7umx0uMzuKJg7hZTXSRW6VP9VKOL+k9hMG2aPJSDnz+OMGi mMBCTAbbiAXHoCxVxzYc3YSdLOJ6KbIHJXZaEbpuE4+WlAkOtfQlVqDIdOiiGxNp7KwFox lpljDeent9iNda2LuxJ/0ojj8dWV1bwfe3Hh9k49nQA2RoxvwX0xu9pFbGSLCw== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 18:16:21 +0100 Message-ID: <84055d076e4df97aa0658920a14359d8543c7a84.1794244231.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNbzp1VtBzLlb5 X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: UDP GSO segmentation currently propagates socket write ownership only when the aggregate uses sock_wfree. An encapsulator such as ovpn can instead retain ownership from the payload socket, including t [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1xQSz8-000000004gd-0KXi Subject: [Openvpn-devel] [PATCH ovpn net-next v5 5/9] udp: preserve write ownership across GSO segmentation X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881401839419248081 X-GMAIL-MSGID: 1881401839419248081 UDP GSO segmentation currently propagates socket write ownership only when the aggregate uses sock_wfree. An encapsulator such as ovpn can instead retain ownership from the payload socket, including tcp_wfree, while repackaging its data as UDP GSO. In that case the destructor remains on the aggregate and runs when software segmentation consumes it, before the resulting UDP packets complete transmission. This releases the write-memory charge early and can wake TCP Small Queues prematurely. Use is_skb_wmem to recognize the standard write-accounting destructors and propagate the original destructor to every segment. These destructors all release ownership using skb->sk and skb->truesize, so the existing truesize adjustment remains applicable. Skbs owned through sock_wfree are handled as before. Signed-off-by: Ralf Lici --- No changes since v4 https://lore.kernel.org/openvpn-devel/84055d076e4df97aa0658920a14359d8543c7a84.1794234673.git.ralf@mandelbit.com/ New in v4. net/ipv4/udp_offload.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index cf07c3c6611a..d41529030fbb 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -481,6 +481,7 @@ static struct sk_buff *__udp_gso_segment_list(struct sk_buff *skb, struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, netdev_features_t features, bool is_ipv6) { + void (*destructor)(struct sk_buff *skb) = gso_skb->destructor; struct sock *sk = gso_skb->sk; unsigned int sum_truesize = 0; struct sk_buff *segs, *seg; @@ -542,7 +543,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, skb_pull(gso_skb, sizeof(*uh)); /* clear destructor to avoid skb_segment assigning it to tail */ - copy_dtor = gso_skb->destructor == sock_wfree; + copy_dtor = is_skb_wmem(gso_skb); if (copy_dtor) { gso_skb->destructor = NULL; gso_skb->sk = NULL; @@ -551,7 +552,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, segs = skb_segment(gso_skb, features); if (IS_ERR_OR_NULL(segs)) { if (copy_dtor) { - gso_skb->destructor = sock_wfree; + gso_skb->destructor = destructor; gso_skb->sk = sk; } return segs; @@ -571,7 +572,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, for (;;) { if (copy_dtor) { - seg->destructor = sock_wfree; + seg->destructor = destructor; seg->sk = sk; sum_truesize += seg->truesize; } From patchwork Mon Nov 9 17:16:22 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5640 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp983628lat; Mon, 9 Nov 2026 09:18:43 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErEfu7sgprZUYgnoZI5IWgtMDdh7sW7wXl7+hwJCQKPpcMpPS0w3BKiCUJ5o88mE3hXZUxFdtzujF78=@openvpn.net X-Received: by 2002:a05:6808:1814:b0:4d3:9029:5ab3 with SMTP id 5614622812f47-5683ca4b384mr318611b6e.35.1794244614561; Mon, 09 Nov 2026 09:16:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794244614; cv=none; d=google.com; s=arc-20260327; b=JQQVgzC1gVLq7+XVdSLnqh/zGq6m+oi98SwXQvTiO4PVQn/7E189VdbYqXqcmz03gb /r9Dv1kLJM5W8jN0nKEYkUkAupUh5BvzahFTf9tI5WAsnzEEIMwchg6TTR+XDyARkvGO jRf/daE6mQSzYgl1Xps5L68HrgY3VohYQSQyWKu+zvRObj8rG2k3GDJ+zF5zdyIbFNVU JETlyXQh8K2GkaHbQmXbeSbeDmqzxybhztwFasOMoWXGD8CmGfUmj3s2wzfxzWkJImVF yD5wkf2rKujsKDg0/rjmyOIdy5bGayriNEXL0pbKZGCgFSH3E+Mb+NCUgxMZtqE11KnC r2eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=Fhu1dhe89gfyrNWI6FI8izegVPseTxw+c8BA+X7iHBI=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=pCEjhNo47OffxnJh8p4K6xPqx/idKGkAf5iEUNU7iroy45AVox7yhnySM954jLklMf uGAU3JBOWCJbt1zYUQx/ZO+a+beyK4f0d6Jzzim5tqLc+dOnmyUBw/kRFp39LT3VSmNT 8re9LKz8kk2pbGy0klVCNpfqUBtTS0nXrUayhk+dHCFX/gKaU/ghsfQfkQydlEOPyLVL Ipkip1+Rtqac0DHhVMnamdbUa4IP5IzeoxxS+I49qKCD9ZTOI2q84Y2MNAsPU34QrpqL YUDdh6o95omcV1S6SVPYJkBrB/0v+mK/RQcp5+2WMvzlCnu0mOVDXyA9y+U2a62KFHSs pMjQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=D4+mYDLh; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=JFvIbz0I; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=NwCqT7PL; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=zy0pawxv; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 5614622812f47-56813b4601csi5217501b6e.60.2026.11.09.09.16.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 09:16:54 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=D4+mYDLh; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=JFvIbz0I; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=NwCqT7PL; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=zy0pawxv; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=Fhu1dhe89gfyrNWI6FI8izegVPseTxw+c8BA+X7iHBI=; b=D4+mYDLhiq9FNi 4Teoju7dzTJ9CH1e+F1RMGZfj4xEmipCvSNLSKQw+cZR+OgLOyZEEnp0R664JfuWPMT7y60p2PuM4 7wp1MnMhlvuEBuq0t3hSmKz4Lu82bL7q7gprxYsJeZzDaxXyaLsFLzIhk5M644kxd2xEyVsNNt0Lf TSg=; Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xQSzF-000000002aQ-1KZP; Mon, 09 Nov 2026 17:16:53 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xQSzD-000000002Zg-0Tw6 for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=oV0uZS32JUDQmnomlm2i/ZOJjZyTe6JjsvGaQSDF6Ng=; b=JFvIbz0IR6TuVt07DOP9uFT7d3 Fy6JVm/6TZs5PWt1fbJOWEWSUONUdSNA7gKyeNl3GLuqd+u8Ly8bXW4eZTG4+ofsb7ptVSDNv2waJ lR1iZ1QMNonVEBlqwuUnywRkQtdxi+RqCu46XipbwlAnOd1aw1Fb+3EK1UCDZUNva+Q8=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=oV0uZS32JUDQmnomlm2i/ZOJjZyTe6JjsvGaQSDF6Ng=; b=NwCqT7PL1reV965JCEkMj90NWN XdY1Rv8HcgisY3keDXLOrQLLq344Zu7SqFh5bRZMhb/W0BbCvVRkd91Icux56v4cYh3ni9uGWiG8Z zt9ExCTvCfBjFgmBObC3smBdy6ICO6Z8U1xEtCwmEsqxzIuyFWq7k5XTkfH3mKiWkGZ0=; Received: from mout-b-202.mailbox.org ([195.10.208.62]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQSz8-000000004gg-3vX6 for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:51 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-202.mailbox.org (Postfix) with ESMTPS id 4jNbzp3f1bzKmpL for ; Mon, 09 Nov 2026 18:16:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794244598; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oV0uZS32JUDQmnomlm2i/ZOJjZyTe6JjsvGaQSDF6Ng=; b=zy0pawxv+XfRCpittiSVdgTAG9KK2DUG8/rjxNGy3MbILlQrJMuy4DnQ5KGHW8Ckowe9Qg H80IvsZa/mIqCWni6rL2E8XDjncqq4wa0aXXQp8ZEBwmREstwNGcUi5ERarKD1hhyMqHgM euUCYQKRLoPQmkYVZIzOTDDCgnBI6A8eXk+gG7fr4d9u89WYJNEBUT7FWBFk48cg1tuik0 Kyk7wTnB6g3/3fmZurPX2TYJ2Ojz3baZJDlEJm8nsJNHFlh+7mOlIViR3mp1oz729Vti1u 8Ar5SlNb/Kz9ZGWCOh1nnxG8C4bLScHCeWDEiayoNYULftf7c1uklOOktZ4SgA== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 18:16:22 +0100 Message-ID: <65a46fe2bff88f09da9450157eab19fed782a264.1794244231.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNbzp3f1bzKmpL X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: When GSO input reaches ovpn, segment it while completing its checksums, then encrypt eligible fixed-size segments out of place into one or more page-backed UDP GSO skbs. This retains page-backed paylo [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1xQSz8-000000004gg-3vX6 Subject: [Openvpn-devel] [PATCH ovpn net-next v5 6/9] ovpn: convert GSO input into UDP GSO output X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881401840923364708 X-GMAIL-MSGID: 1881401840923364708 When GSO input reaches ovpn, segment it while completing its checksums, then encrypt eligible fixed-size segments out of place into one or more page-backed UDP GSO skbs. This retains page-backed payload fragments without copying them into linear skbs and amortizes lower-stack per-packet work. Fixed-size frag-list GSO input uses the same path; GSO_BY_FRAGS remains on the in-place path. Use this path only with synchronous crypto transforms. UDP GSO records must be contiguous at a fixed gso_size stride, so they cannot be padded to cache-line boundaries without transmitting the padding. Adjacent records therefore share cache lines, which independently completing asynchronous DMA mappings cannot safely do on non-coherent systems, as described in Documentation/core-api/dma-api.rst. Asynchronous transforms retain the existing per-record in-place path. Split output at GSO_LEGACY_MAX_SIZE. Transmit an aggregate only after every record succeeds. If one record fails, drop the aggregate. Leave the remaining input queued for the in-place path. Keep ordinary packets and unsupported segment geometries on the in-place path. Preserve scheduling metadata and socket write ownership when replacing the input skbs so that lower-stack pacing, write-memory accounting and completion behaviour remain consistent. Reset the replacement skb's inner network header before encapsulation so tunnel byte accounting excludes reserved headroom. As with other tunnel GSO users, the device tx_packets counter counts one output GSO skb, while ovpn's peer counters continue to count each encrypted record. On two directly connected 100-Gbit/s mlx5 ports, six interleaved measurements using one zero-copy TCP flow over UDP ovpn with AES-128-GCM, a 1408-byte tunnel MTU and a 1500-byte physical MTU produced these means with hardware segmentation: Without UDP GSO With UDP GSO Throughput 13.431 Gbit/s 17.149 Gbit/s (+27.7%) Cycles per byte 6.628 4.899 (-26.1%) Instructions per byte 13.871 10.653 (-23.2%) Four order-balanced pre/post pairs with tx-udp-segmentation disabled on the lower device produced these means with software segmentation: Without UDP GSO With UDP GSO Throughput 13.647 Gbit/s 16.278 Gbit/s (+19.3%) Cycles per byte 6.609 6.199 (-6.2%) Instructions per byte 13.858 14.582 (+5.2%) Signed-off-by: Ralf Lici --- Changes since v4 https://lore.kernel.org/openvpn-devel/cfbfab4e0b9d744e55019d6072d505e34e9b1d12.1794234673.git.ralf@mandelbit.com/ - Transfer write accounting from successfully encrypted source segments to the replacement aggregate without running the source destructors, preventing an early TCP Small Queues wakeup. (Sashiko) - Preserve TX timestamp requests, neighbour-confirmation state and security marks on the replacement aggregate. Changes since v3 https://lore.kernel.org/openvpn-devel/55ca5e8f9f2fb9939ee28deeb42aa6bd5476a136.1794223133.git.ralf@mandelbit.com/ - Reserve LL_MAX_HEADER when sizing output aggregates so the final skb stays below lower-device GSO limits after its link header is pushed. (Sashiko) - Only batch segments which share the same socket owner and destructor. (Sashiko) Changes since v2 https://lore.kernel.org/openvpn-devel/20261102164353.459969-5-ralf@mandelbit.com/ - Restrict UDP GSO output to synchronous AEAD transforms and remove the asynchronous batch-completion machinery. - Let fixed-size frag-list GSO input use the UDP GSO output path; only GSO_BY_FRAGS input remains on the in-place path. - Transfer socket write ownership with the input skb's original destructor so TCP Small Queues wakeups remain correct. (Sashiko) - Preserve timestamp and ooo_okay metadata on the replacement aggregate. - Reset the replacement skb's inner network header so tunnel byte accounting excludes reserved headroom, and document that device tx_packets counts output GSO skbs. (Sashiko) - Refresh the measurements, including a lower-device software-segmentation control. Changes since v1 https://lore.kernel.org/openvpn-devel/47eee3045f402b2baf7db759bc9cfd35dee8f73d.1790843153.git.ralf@mandelbit.com/ - Release successfully encrypted source skbs with consume_skb after their data has been transferred to the output aggregate. (Antonio) drivers/net/ovpn/crypto_aead.c | 101 +++++++-- drivers/net/ovpn/crypto_aead.h | 4 + drivers/net/ovpn/io.c | 371 ++++++++++++++++++++++++++++----- drivers/net/ovpn/stats.h | 6 +- drivers/net/ovpn/tcp.c | 4 +- drivers/net/ovpn/udp.c | 26 ++- 6 files changed, 433 insertions(+), 79 deletions(-) diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index 5e5320338165..26305984197e 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -134,13 +134,17 @@ static struct scatterlist *ovpn_aead_crypto_req_sg(struct crypto_aead *aead, static struct aead_request *ovpn_aead_request_alloc(struct crypto_aead *aead, struct sk_buff *skb, - unsigned int nents, u8 **iv) + unsigned int nents, + unsigned int extra, u8 **iv) { struct aead_request *req; void *tmp; - /* allocate IV, request and scatterlist entries in one block */ - tmp = kmalloc(ovpn_aead_crypto_tmp_size(aead, nents), GFP_ATOMIC); + /* allocate IV, request, scatterlist entries and caller scratch space + * in one block + */ + tmp = kmalloc(ovpn_aead_crypto_tmp_size(aead, nents) + extra, + GFP_ATOMIC); if (unlikely(!tmp)) return ERR_PTR(-ENOMEM); @@ -151,19 +155,11 @@ static struct aead_request *ovpn_aead_request_alloc(struct crypto_aead *aead, return req; } -static int ovpn_aead_encrypt_header(struct ovpn_peer *peer, - struct ovpn_crypto_key_slot *ks, - u8 *iv, u8 *data) +static void ovpn_aead_encrypt_header(struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, + u32 pktid, u8 *iv, u8 *data) { - u32 pktid, op; - int ret; - - /* obtain packet ID, which is used both as a first - * 4 bytes of nonce and last 4 bytes of associated data. - */ - ret = ovpn_pktid_xmit_next(&ks->pid_xmit, &pktid); - if (unlikely(ret < 0)) - return ret; + u32 op; /* concat 4 bytes packet id and 8 bytes nonce tail into 12 bytes * nonce @@ -175,8 +171,74 @@ static int ovpn_aead_encrypt_header(struct ovpn_peer *peer, BUILD_BUG_ON(sizeof(op) != OVPN_OPCODE_SIZE); *(__force __be32 *)data = htonl(op); memcpy(data + OVPN_OPCODE_SIZE, iv, OVPN_NONCE_WIRE_SIZE); +} + +int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, struct sk_buff *skb, + struct sk_buff *gso_skb, unsigned int offset) +{ + const unsigned int dst_nents = skb_shinfo(gso_skb)->nr_frags + 4; + const unsigned int src_nents = skb_shinfo(skb)->nr_frags + 2; + struct scatterlist *src, *dst; + struct aead_request *req; + unsigned int payload_off; + int dst_idx, mapped, ret; + u8 *aad, *iv; + u32 pktid; + + req = ovpn_aead_request_alloc(ks->encrypt, skb, src_nents + dst_nents, + OVPN_AAD_SIZE, &iv); + if (IS_ERR(req)) + return PTR_ERR(req); + src = ovpn_aead_crypto_req_sg(ks->encrypt, req); + dst = src + src_nents; + aad = (u8 *)(dst + dst_nents); - return 0; + ret = ovpn_pktid_xmit_next(&ks->pid_xmit, &pktid); + if (unlikely(ret < 0)) + return ret; + ovpn_aead_encrypt_header(peer, ks, pktid, iv, aad); + + ret = skb_store_bits(gso_skb, offset, aad, OVPN_AAD_SIZE); + if (unlikely(ret < 0)) + return ret; + + /* encrypt out of place from the original segmented skb directly into + * its final range in the UDP GSO skb + */ + sg_init_table(src, src_nents); + sg_set_buf(src, aad, OVPN_AAD_SIZE); + mapped = skb_to_sgvec_nomark(skb, src + 1, 0, skb->len); + if (unlikely(mapped < 0)) + return mapped; + sg_mark_end(&src[mapped]); + + sg_init_table(dst, dst_nents); + dst_idx = skb_to_sgvec_nomark(gso_skb, dst, offset, OVPN_AAD_SIZE); + if (unlikely(dst_idx < 0)) + return dst_idx; + + payload_off = offset + OVPN_AAD_SIZE + OVPN_AUTH_TAG_SIZE; + mapped = skb_to_sgvec_nomark(gso_skb, dst + dst_idx, payload_off, + skb->len); + if (unlikely(mapped < 0)) + return mapped; + dst_idx += mapped; + + mapped = skb_to_sgvec_nomark(gso_skb, dst + dst_idx, + offset + OVPN_AAD_SIZE, + OVPN_AUTH_TAG_SIZE); + if (unlikely(mapped < 0)) + return mapped; + dst_idx += mapped; + sg_mark_end(&dst[dst_idx - 1]); + + aead_request_set_tfm(req, ks->encrypt); + aead_request_set_callback(req, 0, NULL, NULL); + aead_request_set_crypt(req, src, dst, skb->len, iv); + aead_request_set_ad(req, OVPN_AAD_SIZE); + + return crypto_aead_encrypt(req); } int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, @@ -187,6 +249,7 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *trailer; struct scatterlist *sg; int nfrags, ret; + u32 pktid; u8 *iv; ovpn_skb_cb(skb)->peer = peer; @@ -217,7 +280,7 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, nfrags = 1; } - req = ovpn_aead_request_alloc(ks->encrypt, skb, nfrags + 2, &iv); + req = ovpn_aead_request_alloc(ks->encrypt, skb, nfrags + 2, 0, &iv); if (IS_ERR(req)) return PTR_ERR(req); sg = ovpn_aead_crypto_req_sg(ks->encrypt, req); @@ -243,9 +306,11 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, /* make space for the additional data and push it to the front */ __skb_push(skb, OVPN_AAD_SIZE); - ret = ovpn_aead_encrypt_header(peer, ks, iv, skb->data); + /* obtain the packet ID used by both the nonce and associated data */ + ret = ovpn_pktid_xmit_next(&ks->pid_xmit, &pktid); if (unlikely(ret < 0)) return ret; + ovpn_aead_encrypt_header(peer, ks, pktid, iv, skb->data); /* AEAD Additional data */ sg_set_buf(sg, skb->data, OVPN_AAD_SIZE); diff --git a/drivers/net/ovpn/crypto_aead.h b/drivers/net/ovpn/crypto_aead.h index fae3b585a43b..8b444744944e 100644 --- a/drivers/net/ovpn/crypto_aead.h +++ b/drivers/net/ovpn/crypto_aead.h @@ -17,6 +17,10 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb); +int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, + struct sk_buff *skb, struct sk_buff *gso_skb, + unsigned int offset); int ovpn_aead_decrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb); diff --git a/drivers/net/ovpn/io.c b/drivers/net/ovpn/io.c index 3b0c9b30e879..697a336faa9e 100644 --- a/drivers/net/ovpn/io.c +++ b/drivers/net/ovpn/io.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include "ovpnpriv.h" #include "peer.h" @@ -32,6 +34,14 @@ const unsigned char ovpn_keepalive_message[OVPN_KEEPALIVE_SIZE] = { 0x07, 0xed, 0x2d, 0x0a, 0x98, 0x1f, 0xc7, 0x48 }; +/* gso_within_dev_limits() requires skb->len, which by then includes the + * link-layer and outer network headers, to stay below gso_max_size + */ +#define OVPN_UDP_GSO_MAX_PAYLOAD (GSO_LEGACY_MAX_SIZE - \ + LL_MAX_HEADER - \ + sizeof(struct ipv6hdr) - \ + sizeof(struct udphdr) - 1) + /** * ovpn_is_keepalive - check if skb contains a keepalive message * @skb: packet to check @@ -234,43 +244,23 @@ void ovpn_recv(struct ovpn_peer *peer, struct sk_buff *skb) ovpn_decrypt_post(skb, ovpn_aead_decrypt(peer, ks, skb)); } -void ovpn_encrypt_post(void *data, int ret) +static void ovpn_encrypt_key_exhausted(struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks) +{ + netdev_warn(peer->ovpn->dev, "killing key %u for peer %u\n", + ks->key_id, peer->id); + if (ovpn_crypto_kill_key(&peer->crypto, ks->key_id)) + /* let userspace know so that a new key must be negotiated */ + ovpn_nl_key_swap_notify(peer, ks->key_id); +} + +static void ovpn_encrypt_send(struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, + struct sk_buff *skb, unsigned int packets) { - struct ovpn_crypto_key_slot *ks; - struct sk_buff *skb = data; struct ovpn_socket *sock; - struct ovpn_peer *peer; unsigned int orig_len; - /* encryption is happening asynchronously. This function will be - * called later by the crypto callback with a proper return value - */ - if (unlikely(ret == -EINPROGRESS)) - return; - - ks = ovpn_skb_cb(skb)->ks; - peer = ovpn_skb_cb(skb)->peer; - - /* crypto is done, cleanup skb CB and its members */ - kfree(ovpn_skb_cb(skb)->crypto_tmp); - - if (unlikely(ret == -ERANGE)) { - /* we ran out of IVs and we must kill the key as it can't be - * use anymore - */ - netdev_warn(peer->ovpn->dev, - "killing key %u for peer %u\n", ks->key_id, - peer->id); - if (ovpn_crypto_kill_key(&peer->crypto, ks->key_id)) - /* let userspace know so that a new key must be negotiated */ - ovpn_nl_key_swap_notify(peer, ks->key_id); - - goto err; - } - - if (unlikely(ret < 0)) - goto err; - skb_mark_not_on_list(skb); orig_len = skb->len; @@ -291,45 +281,211 @@ void ovpn_encrypt_post(void *data, int ret) goto err_unlock; } - ovpn_peer_stats_increment_tx(&peer->link_stats, orig_len); + ovpn_peer_stats_add_tx(&peer->link_stats, orig_len, packets); /* keep track of last sent packet for keepalive */ WRITE_ONCE(peer->last_sent, ktime_get_boottime_seconds()); /* skb passed down the stack - don't free it */ skb = NULL; err_unlock: rcu_read_unlock(); -err: if (unlikely(skb)) - ovpn_dev_dstats_tx_dropped(peer->ovpn->dev); + ovpn_dev_dstats_tx_dropped(peer->ovpn->dev, packets); kfree_skb(skb); - if (likely(ks)) - ovpn_crypto_key_slot_put(ks); + ovpn_crypto_key_slot_put(ks); ovpn_peer_put(peer); } -static bool ovpn_encrypt_one(struct ovpn_peer *peer, struct sk_buff *skb) +void ovpn_encrypt_post(void *data, int ret) +{ + struct sk_buff *skb = data; + struct ovpn_crypto_key_slot *ks; + struct ovpn_peer *peer; + + /* encryption is happening asynchronously. This function will be + * called later by the crypto callback with a proper return value + */ + if (unlikely(ret == -EINPROGRESS)) + return; + + peer = ovpn_skb_cb(skb)->peer; + ks = ovpn_skb_cb(skb)->ks; + + /* crypto is done, cleanup skb CB and its members */ + kfree(ovpn_skb_cb(skb)->crypto_tmp); + + if (unlikely(ret == -ERANGE)) { + ovpn_encrypt_key_exhausted(peer, ks); + goto err; + } + + if (unlikely(ret < 0)) + goto err; + + ovpn_encrypt_send(peer, ks, skb, 1); + return; +err: + ovpn_dev_dstats_tx_dropped(peer->ovpn->dev, 1); + kfree_skb(skb); + ovpn_crypto_key_slot_put(ks); + ovpn_peer_put(peer); +} + +/* Hold the peer and its primary key for one encryption operation. + * The returned key and the peer each carry one reference which the caller must + * release or pass to the completion path. + */ +static struct ovpn_crypto_key_slot * +ovpn_encrypt_refs_get(struct ovpn_peer *peer) { struct ovpn_crypto_key_slot *ks; /* get primary key to be used for encrypting data */ ks = ovpn_crypto_key_slot_primary(&peer->crypto); if (unlikely(!ks)) - return false; + return NULL; - /* take a reference to the peer because the crypto code may run async. - * ovpn_encrypt_post() will release it upon completion + /* the caller already owns a peer reference, so failure indicates a + * broken reference lifetime elsewhere */ if (unlikely(!ovpn_peer_hold(peer))) { DEBUG_NET_WARN_ON_ONCE(1); ovpn_crypto_key_slot_put(ks); - return false; + return NULL; } + return ks; +} + +static bool ovpn_encrypt_one(struct ovpn_peer *peer, struct sk_buff *skb) +{ + struct ovpn_crypto_key_slot *ks; + + ks = ovpn_encrypt_refs_get(peer); + if (unlikely(!ks)) + return false; + memset(ovpn_skb_cb(skb), 0, sizeof(struct ovpn_cb)); ovpn_encrypt_post(skb, ovpn_aead_encrypt(peer, ks, skb)); return true; } +static bool ovpn_encrypt_gso_queue(struct sk_buff_head *skbs, + struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, + struct sk_buff *batch, + unsigned int segments) +{ + unsigned int offset = 0, moved = 0, i, len; + struct sk_buff *skb; + int ret; + + for (i = 0; i < segments; i++) { + skb = __skb_dequeue(skbs); + len = skb->len + OVPN_DATA_V2_OVERHEAD; + + memset(ovpn_skb_cb(skb), 0, sizeof(struct ovpn_cb)); + ret = ovpn_aead_encrypt_gso(peer, ks, skb, batch, offset); + kfree(ovpn_skb_cb(skb)->crypto_tmp); + if (unlikely(ret < 0)) { + DEBUG_NET_WARN_ON_ONCE(ret == -EINPROGRESS || + ret == -EBUSY); + if (ret == -ERANGE) + ovpn_encrypt_key_exhausted(peer, ks); + ovpn_dev_dstats_tx_dropped(peer->ovpn->dev, i + 1); + kfree_skb(skb); + break; + } + + /* pass on the TX timestamp request, which GSO segmentation + * attached to the segment holding the timestamped byte + */ + if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_ANY_TSTAMP)) { + skb_shinfo(batch)->tx_flags |= + skb_shinfo(skb)->tx_flags & SKBTX_ANY_TSTAMP; + skb_shinfo(batch)->tskey = skb_shinfo(skb)->tskey; + } + + /* the encrypted data now lives in the aggregate, which already + * carries the write charge, so free the segment without its + * destructor, which for TCP would wake TSQ before the batch has + * left the host + */ + if (batch->sk) { + moved += skb->truesize; + skb->destructor = NULL; + skb->sk = NULL; + } + consume_skb(skb); + offset += len; + } + + /* the aggregate's own charge keeps sk_wmem_alloc above zero */ + if (moved) + WARN_ON_ONCE(refcount_sub_and_test(moved, + &batch->sk->sk_wmem_alloc)); + if (unlikely(i < segments)) + goto err; + + ovpn_encrypt_send(peer, ks, batch, segments); + return true; +err: + ovpn_crypto_key_slot_put(ks); + ovpn_peer_put(peer); + return false; +} + +static struct sk_buff *ovpn_udp_gso_alloc(const struct sk_buff *first_segment, + unsigned int batch_len, + unsigned int segments) +{ + struct sk_buff *gso_skb; + int ret; + + gso_skb = alloc_skb_with_frags(OVPN_HEAD_ROOM, batch_len, + SKB_FRAG_PAGE_ORDER, &ret, GFP_ATOMIC); + if (unlikely(!gso_skb)) + return NULL; + + skb_reserve(gso_skb, OVPN_HEAD_ROOM); + skb_reset_inner_network_header(gso_skb); + gso_skb->len = batch_len; + gso_skb->data_len = batch_len; + + /* take over the input's write ownership with its own destructor, as + * GSO segmentation does, so that freeing the aggregate releases the + * charge and, for TCP, runs tcp_wfree to wake TSQ once the batch has + * left the host + */ + if (first_segment->sk && is_skb_wmem(first_segment)) { + gso_skb->sk = first_segment->sk; + gso_skb->destructor = first_segment->destructor; + refcount_add(gso_skb->truesize, + &gso_skb->sk->sk_wmem_alloc); + } + + /* keep the metadata retained by the in-place path, which reuses the + * input skb + */ + gso_skb->priority = first_segment->priority; + skb_set_delivery_time(gso_skb, first_segment->tstamp, + first_segment->tstamp_type); + gso_skb->ooo_okay = first_segment->ooo_okay; + skb_set_dst_pending_confirm(gso_skb, + skb_get_dst_pending_confirm(first_segment)); + skb_copy_hash(gso_skb, first_segment); + skb_copy_secmark(gso_skb, first_segment); +#ifdef CONFIG_XPS + gso_skb->sender_cpu = first_segment->sender_cpu; +#endif + + skb_shinfo(gso_skb)->gso_type = SKB_GSO_UDP_L4; + skb_shinfo(gso_skb)->gso_size = first_segment->len + + OVPN_DATA_V2_OVERHEAD; + skb_shinfo(gso_skb)->gso_segs = segments; + + return gso_skb; +} + /* send skb to connected peer, if any */ static void ovpn_send(struct ovpn_priv *ovpn, struct sk_buff *skb, struct ovpn_peer *peer) @@ -341,7 +497,7 @@ static void ovpn_send(struct ovpn_priv *ovpn, struct sk_buff *skb, */ skb_list_walk_safe(skb, curr, next) { if (unlikely(!ovpn_encrypt_one(peer, curr))) { - ovpn_dev_dstats_tx_dropped(ovpn->dev); + ovpn_dev_dstats_tx_dropped(ovpn->dev, 1); kfree_skb(curr); } } @@ -349,19 +505,109 @@ static void ovpn_send(struct ovpn_priv *ovpn, struct sk_buff *skb, ovpn_peer_put(peer); } +/* encrypt fixed-size input segments into one or more UDP GSO aggregates */ +static void ovpn_send_gso(struct sk_buff_head *skbs, struct ovpn_peer *peer) +{ + unsigned int max_segs, seg_len, batch_len, segs; + struct ovpn_crypto_key_slot *ks; + struct sk_buff *batch; + + seg_len = skb_peek(skbs)->len + OVPN_DATA_V2_OVERHEAD; + max_segs = min_t(unsigned int, UDP_MAX_SEGMENTS, + OVPN_UDP_GSO_MAX_PAYLOAD / seg_len); + + /* if even two encrypted skbs cannot fit, leave the whole queue for the + * ordinary transmit path + */ + if (max_segs < 2) + return; + + /* An input GSO skb might produce more than max_segs segments, so we + * consume as many as we can for each iteration. A final single skb, or + * any remainder left after batching stops, stays queued and falls back + * to the ordinary transmit path. + */ + while (skb_queue_len(skbs) > 1) { + segs = min_t(unsigned int, skb_queue_len(skbs), max_segs); + /* acquire shared state before allocating/consuming anything */ + ks = ovpn_encrypt_refs_get(peer); + if (unlikely(!ks)) + return; + /* recheck in case the key was swapped */ + if (unlikely(ks->async)) { + ovpn_crypto_key_slot_put(ks); + ovpn_peer_put(peer); + return; + } + + /* all but the final input skb have the same length, so start + * with the full-size calculation and adjust only the final + * group below + */ + batch_len = segs * (skb_peek(skbs)->len + + OVPN_DATA_V2_OVERHEAD); + if (segs == skb_queue_len(skbs)) + batch_len -= skb_peek(skbs)->len - + skb_peek_tail(skbs)->len; + + batch = ovpn_udp_gso_alloc(skb_peek(skbs), batch_len, segs); + if (unlikely(!batch)) { + ovpn_crypto_key_slot_put(ks); + ovpn_peer_put(peer); + return; + } + + if (unlikely(!ovpn_encrypt_gso_queue(skbs, peer, ks, + batch, segs))) { + kfree_skb(batch); + return; + } + } +} + +static bool ovpn_peer_supports_udp_gso(struct ovpn_peer *peer) +{ + struct ovpn_crypto_key_slot *ks; + struct ovpn_socket *sock; + bool udp_gso; + u8 idx; + + rcu_read_lock(); + idx = READ_ONCE(peer->crypto.primary_idx); + ks = rcu_dereference(peer->crypto.slots[idx]); + sock = rcu_dereference(peer->sock); + /* UDP GSO requires checksums. These socket settings can change after + * we decide to batch, but an already-built batch remains checksummed. + * Linux's ordinary UDP GSO path makes the same choice. + */ + udp_gso = ks && !ks->async && sock && + sock->sk->sk_protocol == IPPROTO_UDP && + !sock->sk->sk_no_check_tx && !udp_get_no_check6_tx(sock->sk); + rcu_read_unlock(); + + return udp_gso; +} + /* Send user data to the network */ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) { struct ovpn_priv *ovpn = netdev_priv(dev); struct sk_buff *segments, *curr, *next; + const bool gso_in = skb_is_gso(skb); struct sk_buff_head skb_list; netdev_features_t features; unsigned int tx_bytes = 0; struct ovpn_peer *peer; + bool gso_out; __be16 proto; int ret; + /* GSO_BY_FRAGS input remains on the in-place path because its variable + * segment sizes cannot be represented by one UDP GSO output size + */ + gso_out = gso_in && skb_shinfo(skb)->gso_size != GSO_BY_FRAGS; + /* reset netfilter state */ nf_reset_ct(skb); @@ -390,13 +636,14 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) /* dst was needed for peer selection - it can now be dropped */ skb_dst_drop(skb); - if (skb_is_gso(skb)) { - /* force software segmentation, but keep ovpn's non-GSO feature - * bits so the generated segments can preserve non-linear skb - * data where possible + if (gso_in) { + /* force software segmentation and calculate each checksum + * while allowing safe page-backed payload fragments to remain + * non-linear */ features = netif_skb_features(skb); - segments = skb_gso_segment(skb, features & ~NETIF_F_GSO_MASK); + features &= ~(NETIF_F_GSO_MASK | NETIF_F_CSUM_MASK); + segments = skb_gso_segment(skb, features); if (IS_ERR_OR_NULL(segments)) { ret = PTR_ERR(segments); net_err_ratelimited("%s: cannot segment payload packet: %d\n", @@ -418,7 +665,8 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) if (unlikely(!curr)) { net_err_ratelimited("%s: skb_share_check failed for payload packet\n", netdev_name(dev)); - ovpn_dev_dstats_tx_dropped(ovpn->dev); + ovpn_dev_dstats_tx_dropped(ovpn->dev, 1); + gso_out = false; continue; } @@ -427,11 +675,23 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) skb_checksum_help(curr) < 0)) { net_err_ratelimited("%s: skb_checksum_help failed for payload packet\n", netdev_name(dev)); - ovpn_dev_dstats_tx_dropped(ovpn->dev); + ovpn_dev_dstats_tx_dropped(ovpn->dev, 1); kfree_skb(curr); + gso_out = false; continue; } + /* one aggregate can carry only one write owner, so batch only + * segments that share it + */ + if (gso_out && !skb_queue_empty(&skb_list)) { + struct sk_buff *prev = skb_peek_tail(&skb_list); + + if (unlikely(prev->sk != curr->sk || + prev->destructor != curr->destructor)) + gso_out = false; + } + /* only count what we actually send */ tx_bytes += curr->len; __skb_queue_tail(&skb_list, curr); @@ -444,10 +704,15 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) ovpn_peer_put(peer); return NETDEV_TX_OK; } - skb_list.prev->next = NULL; ovpn_peer_stats_add_tx(&peer->vpn_stats, tx_bytes, skb_queue_len(&skb_list)); + + if (gso_out && skb_queue_len(&skb_list) > 1 && + ovpn_peer_supports_udp_gso(peer)) + ovpn_send_gso(&skb_list, peer); + + skb_list.prev->next = NULL; ovpn_send(ovpn, skb_list.next, peer); return NETDEV_TX_OK; @@ -455,7 +720,7 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) drop: ovpn_peer_put(peer); drop_no_peer: - ovpn_dev_dstats_tx_dropped(ovpn->dev); + ovpn_dev_dstats_tx_dropped(ovpn->dev, 1); skb_tx_error(skb); kfree_skb_list(skb); return NETDEV_TX_OK; diff --git a/drivers/net/ovpn/stats.h b/drivers/net/ovpn/stats.h index 9331f5e9179b..b3fe006c01f6 100644 --- a/drivers/net/ovpn/stats.h +++ b/drivers/net/ovpn/stats.h @@ -54,10 +54,12 @@ static inline void ovpn_peer_stats_increment_tx(struct ovpn_peer_stats *stats, ovpn_peer_stats_add_tx(stats, n, 1); } -static inline void ovpn_dev_dstats_tx_dropped(struct net_device *dev) +static inline void ovpn_dev_dstats_tx_dropped(struct net_device *dev, + unsigned int packets) { local_bh_disable(); - dev_dstats_tx_dropped(dev); + while (packets--) + dev_dstats_tx_dropped(dev); local_bh_enable(); } diff --git a/drivers/net/ovpn/tcp.c b/drivers/net/ovpn/tcp.c index 8fe8a8e750a4..5cba35e4a8ee 100644 --- a/drivers/net/ovpn/tcp.c +++ b/drivers/net/ovpn/tcp.c @@ -332,7 +332,7 @@ static void ovpn_tcp_send_sock_skb(struct ovpn_peer *peer, struct sock *sk, ovpn_tcp_send_sock(peer, sk); if (peer->tcp.out_msg.skb) { - ovpn_dev_dstats_tx_dropped(peer->ovpn->dev); + ovpn_dev_dstats_tx_dropped(peer->ovpn->dev, 1); kfree_skb(skb); return; } @@ -354,7 +354,7 @@ void ovpn_tcp_send_skb(struct ovpn_peer *peer, struct sock *sk, if (sock_owned_by_user(sk)) { if (skb_queue_len(&peer->tcp.out_queue) >= READ_ONCE(net_hotdata.max_backlog)) { - ovpn_dev_dstats_tx_dropped(peer->ovpn->dev); + ovpn_dev_dstats_tx_dropped(peer->ovpn->dev, 1); kfree_skb(skb); goto unlock; } diff --git a/drivers/net/ovpn/udp.c b/drivers/net/ovpn/udp.c index 055cdb1bee13..0eb6d32f4ceb 100644 --- a/drivers/net/ovpn/udp.c +++ b/drivers/net/ovpn/udp.c @@ -288,9 +288,13 @@ static int ovpn_udp4_output(struct ovpn_peer *peer, struct ovpn_bind *bind, spin_unlock_bh(&peer->lock); transmit: + /* an already-built UDP GSO needs a checksum seed even if the socket's + * no-check option changed while encryption was in flight + */ udp_tunnel_xmit_skb(rt, sk, skb, fl.saddr, fl.daddr, 0, ip4_dst_hoplimit(&rt->dst), 0, fl.fl4_sport, - fl.fl4_dport, false, sk->sk_no_check_tx, 0); + fl.fl4_dport, false, + !skb_is_gso(skb) && sk->sk_no_check_tx, 0); ret = 0; err: local_bh_enable(); @@ -388,9 +392,13 @@ static int ovpn_udp6_output(struct ovpn_peer *peer, struct ovpn_bind *bind, * udp_tunnel_xmit_skb() */ skb->ignore_df = 1; + /* keep checksum offload enabled for an in-flight UDP GSO batch even if + * the socket's no-check option has changed since batch creation + */ udp_tunnel6_xmit_skb(dst, sk, skb, skb->dev, &fl.saddr, &fl.daddr, 0, ip6_dst_hoplimit(dst), 0, fl.fl6_sport, - fl.fl6_dport, udp_get_no_check6_tx(sk), 0); + fl.fl6_dport, + !skb_is_gso(skb) && udp_get_no_check6_tx(sk), 0); ret = 0; err: local_bh_enable(); @@ -467,8 +475,18 @@ void ovpn_udp_send_skb(struct ovpn_peer *peer, struct sock *sk, skb->dev = peer->ovpn->dev; skb->mark = key.mark; - /* no checksum performed at this layer */ - skb->ip_summed = CHECKSUM_NONE; + if (skb_is_gso(skb)) { + /* udp_tunnel_xmit_skb installs the outer UDP header after this + * function returns: point CHECKSUM_PARTIAL at that future + * header so both hw and sw UDP GSO can complete the checksum. + */ + skb->ip_summed = CHECKSUM_PARTIAL; + skb->csum_start = skb_headroom(skb) - sizeof(struct udphdr); + skb->csum_offset = offsetof(struct udphdr, check); + } else { + /* no checksum performed at this layer */ + skb->ip_summed = CHECKSUM_NONE; + } ovpn_dst_cache_check_key(peer, &peer->dst_cache, &key); From patchwork Mon Nov 9 17:16:23 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5636 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp981198lat; Mon, 9 Nov 2026 09:16:55 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHxhTWCXEeNDm5N0L+uTjo5ykpXt10ERd/bXYWzMod3iG7SKnkPUQeWTh6vAh2oUCT6b6DJxyL/CIw=@openvpn.net X-Received: by 2002:a05:6870:1b05:b0:48f:e0f6:bd4a with SMTP id 586e51a60fabf-4ae20333e7amr65057fac.31.1794244615239; Mon, 09 Nov 2026 09:16:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794244615; cv=none; d=google.com; s=arc-20260327; b=W+JC7aC3pOeDVyq3AxYJUbZWirWo03Tm9B+OiyxOgV/h2xZzfkWc2Ef+HUmCc6xH8N JFypvECqZJfCTnsvj1eXyfEEvAsSoNqG1PvxW7N/82cfPYrYCNle/eXm33gQG9wk78GI 8aJFDazhhv6qC1llG6stYJXUKYiGglcWAwXGIbYNCg46OFmzGZlxQrYUfnZxPH2PWMbD bNsRwKXQ4St9WXG8aLXlYAgUpGqTwc663ILEGwQsuXpl85BvajM1759qrCip34GWOFNN pmY2k8av5mzBZv3xEFbXUF9NmFEv2RugumOLYhtsXgUZK2wWJiiiGr9sh1+msKHgUKf7 DFAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=wgziNjaFndDvoRcC2LyaZ6gYJhtAhYYjJdWBx3Bfd9k=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=mN6OpQRN1x/yAy2qz85UHENZWL5aH521ezhqrpH1dLPJL5ji1zvKuS5ABCkfaqVEM6 K/jHXjZkUMuR8BDAJHawGR66F22UavTQPzwoTHajd0ufGV42BhLeFoTO8GV0tZJLDgr9 ZhBetVUK5BG4gBlE/bGve6TZcRALsfSiAI2vbkuwMfm/O6Jkpg3c7TBCu/W1qeWlpeCi Lb1XCXtEEDaeXnmxyRpUknBS4q9Z0IaNM9LgbWtQK0ORiA3alnEzlz94sO91JByNIkse sgNKxY7/S885ktJ7R2qnvfoMI6VNS1iCeMeVcwNXH2j0zvJqHPBTfMF+RSXjr/sXqpA9 ObVA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b="d/bd0FXg"; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="BQ8/7m2J"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=ClvKhziA; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=cO7pcvvd; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 586e51a60fabf-4ade692f6c8si5796828fac.53.2026.11.09.09.16.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 09:16:55 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b="d/bd0FXg"; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="BQ8/7m2J"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=ClvKhziA; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=cO7pcvvd; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=wgziNjaFndDvoRcC2LyaZ6gYJhtAhYYjJdWBx3Bfd9k=; b=d/bd0FXgcnQoUw OJAX1/FmwJoCTDsDF15wGXZ3DJA4NL+8mLIcrpctX2usIRUgk7HmNm0Dx2qEc7RQLjKPI8OXM7fqX ZthmWslxB8dsk/YosdGV7yaiTCPegxB+d3HtMXgbpZctpc1jBaPFx4oO5POKjCmljtPiiKUM3Loek tVY=; Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xQSzG-000000001aE-0kTE; Mon, 09 Nov 2026 17:16:54 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xQSzB-000000001Zl-1xL1 for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=v3R4oPBqa6HR0kWR3UeTqJBp9nvDfgbct38jjMXcp8U=; b=BQ8/7m2JBvBTUyHQIqJPqnD4dt 9jS8qQg8GBuSGSxnvcfiQRuJTyXm0gC6XQcVbFt19bxwpl9XetjBuHZsSn2Y0TM0DZERYggJlHQMa 52A2iEikozJqK5G0JMQR9HFcnNX+7s0CNk+Iqtrkuvk6rW8MIsqEYexKXQ3akNRVmMjY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=v3R4oPBqa6HR0kWR3UeTqJBp9nvDfgbct38jjMXcp8U=; b=ClvKhziAajR/1DrpKP+Akdfom/ YoJm0tPQoWsw7NeDk/i6n2908dUawHzdE7AzW4FvJ+JHocbfl+f81UkoBDVOzRojz9WhtgRxn0NDx xGy1uRwjU3HGfh7MFTO62J94oIW69mWoSJoRBLrXIfUoi51RIIZlUAaxlcVds1nRBDxo=; Received: from mout-b-206.mailbox.org ([195.10.208.51]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQSz8-000000003aa-46bG for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:49 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-206.mailbox.org (Postfix) with ESMTPS id 4jNbzp5tyRzXn for ; Mon, 09 Nov 2026 18:16:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794244598; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v3R4oPBqa6HR0kWR3UeTqJBp9nvDfgbct38jjMXcp8U=; b=cO7pcvvdkOBx4PT9x4RtnrM+GHq7NSAx80etdLgFGpnsvwvr8REQ04zpT0fZnAPItSJQDc ZAVGcbGo8c+Ytr2oHVJ5QopVT+BvfwJBGu7lr4eHZkPZTQu/we/7AoWjbSoSoNxT9gXH5e ADbGm64vzGurC/SeX3PxdDxaXlp0ZFvl0rW1dtDPRAvcTw80HZP8HkcXtSc+QdUpPkDFyn BuIfzoaXWEfNCxkSMTHQPQ8f1UizgExknZbFHYuWtAerDMZ9bfIysp3aAbmn/Sb39W8bCX e5ns/i3ubHiETQQwcR/P7oJGz3ir5SceIadBZRCVvu1n8SCmHJCVXohd7F02ig== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 18:16:23 +0100 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNbzp5tyRzXn X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-2.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The UDP GSO path currently allocates one packet ID for every input segment. This performs one atomic update per segment even though the whole batch is prepared by a single caller. Reserve the complete consecutive range before dequeuing any input skb, then assign its IDs to segments in queue order. This reduces packet-ID allocation to one atomic operation per batch and leaves th [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-Headers-End: 1xQSz8-000000003aa-46bG Subject: [Openvpn-devel] [PATCH ovpn net-next v5 7/9] ovpn: reserve packet-ID ranges for UDP GSO batches X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881401842094660069 X-GMAIL-MSGID: 1881401842094660069 The UDP GSO path currently allocates one packet ID for every input segment. This performs one atomic update per segment even though the whole batch is prepared by a single caller. Reserve the complete consecutive range before dequeuing any input skb, then assign its IDs to segments in queue order. This reduces packet-ID allocation to one atomic operation per batch and leaves the input queue intact when no complete range remains, allowing the ordinary transmit path to retry with a newly installed key. If the requested range would cross the end of the packet-ID space, publish exhaustion immediately. Packet IDs abandoned after a later encryption failure remain unused, so an AEAD IV is never reused. Signed-off-by: Ralf Lici --- No changes since v4 https://lore.kernel.org/openvpn-devel/3f40c3db4152e57b0c8b67edb1afe739cba60947.1794234673.git.ralf@mandelbit.com/ No changes since v3 https://lore.kernel.org/openvpn-devel/b7eeace194390a817c6b1105a5f2e294329fc4b9.1794223133.git.ralf@mandelbit.com/ Changes since v2 https://lore.kernel.org/openvpn-devel/20261102164353.459969-6-ralf@mandelbit.com/ - Adapt to the synchronous UDP GSO path; no intended functional change. No changes since v1 https://lore.kernel.org/openvpn-devel/a7138d54319d501b6ba7f1d50dce65cb8d2c3e46.1790843153.git.ralf@mandelbit.com/ drivers/net/ovpn/crypto_aead.c | 7 ++--- drivers/net/ovpn/crypto_aead.h | 2 +- drivers/net/ovpn/io.c | 17 +++++++++--- drivers/net/ovpn/pktid.h | 48 ++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 9 deletions(-) diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index 26305984197e..a75a0bf65c89 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -175,7 +175,8 @@ static void ovpn_aead_encrypt_header(struct ovpn_peer *peer, int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb, - struct sk_buff *gso_skb, unsigned int offset) + struct sk_buff *gso_skb, unsigned int offset, + u32 pktid) { const unsigned int dst_nents = skb_shinfo(gso_skb)->nr_frags + 4; const unsigned int src_nents = skb_shinfo(skb)->nr_frags + 2; @@ -184,7 +185,6 @@ int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, unsigned int payload_off; int dst_idx, mapped, ret; u8 *aad, *iv; - u32 pktid; req = ovpn_aead_request_alloc(ks->encrypt, skb, src_nents + dst_nents, OVPN_AAD_SIZE, &iv); @@ -194,9 +194,6 @@ int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, dst = src + src_nents; aad = (u8 *)(dst + dst_nents); - ret = ovpn_pktid_xmit_next(&ks->pid_xmit, &pktid); - if (unlikely(ret < 0)) - return ret; ovpn_aead_encrypt_header(peer, ks, pktid, iv, aad); ret = skb_store_bits(gso_skb, offset, aad, OVPN_AAD_SIZE); diff --git a/drivers/net/ovpn/crypto_aead.h b/drivers/net/ovpn/crypto_aead.h index 8b444744944e..92e8ed76fba6 100644 --- a/drivers/net/ovpn/crypto_aead.h +++ b/drivers/net/ovpn/crypto_aead.h @@ -20,7 +20,7 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb, struct sk_buff *gso_skb, - unsigned int offset); + unsigned int offset, u32 pktid); int ovpn_aead_decrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb); diff --git a/drivers/net/ovpn/io.c b/drivers/net/ovpn/io.c index 697a336faa9e..cf9f196f7379 100644 --- a/drivers/net/ovpn/io.c +++ b/drivers/net/ovpn/io.c @@ -377,20 +377,31 @@ static bool ovpn_encrypt_gso_queue(struct sk_buff_head *skbs, { unsigned int offset = 0, moved = 0, i, len; struct sk_buff *skb; + u32 first_pktid; int ret; + /* reserve the complete range before dequeuing any input skb so that a + * failure leaves the ordinary transmit path available as a fallback + */ + if (unlikely(ovpn_pktid_xmit_range(&ks->pid_xmit, segments, + &first_pktid))) { + ovpn_encrypt_key_exhausted(peer, ks); + ovpn_crypto_key_slot_put(ks); + ovpn_peer_put(peer); + return false; + } + for (i = 0; i < segments; i++) { skb = __skb_dequeue(skbs); len = skb->len + OVPN_DATA_V2_OVERHEAD; memset(ovpn_skb_cb(skb), 0, sizeof(struct ovpn_cb)); - ret = ovpn_aead_encrypt_gso(peer, ks, skb, batch, offset); + ret = ovpn_aead_encrypt_gso(peer, ks, skb, batch, offset, + first_pktid + i); kfree(ovpn_skb_cb(skb)->crypto_tmp); if (unlikely(ret < 0)) { DEBUG_NET_WARN_ON_ONCE(ret == -EINPROGRESS || ret == -EBUSY); - if (ret == -ERANGE) - ovpn_encrypt_key_exhausted(peer, ks); ovpn_dev_dstats_tx_dropped(peer->ovpn->dev, i + 1); kfree_skb(skb); break; diff --git a/drivers/net/ovpn/pktid.h b/drivers/net/ovpn/pktid.h index 21845f353bc8..c922e11da6a0 100644 --- a/drivers/net/ovpn/pktid.h +++ b/drivers/net/ovpn/pktid.h @@ -68,6 +68,54 @@ static inline int ovpn_pktid_xmit_next(struct ovpn_pktid_xmit *pid, u32 *pktid) return 0; } +/** + * ovpn_pktid_xmit_range - reserve consecutive packet IDs + * @pid: transmit packet-ID state + * @count: non-zero number of IDs to reserve + * @pktid: first reserved packet ID + * + * The reservation is all-or-nothing. If the requested range would cross the + * end of the 32-bit packet-ID space, exhaust the state without returning the + * unused tail. Packet IDs can be skipped but never reused as an AEAD IV. + * + * Return: 0 on success or -ERANGE when no complete range remains + */ +static inline int ovpn_pktid_xmit_range(struct ovpn_pktid_xmit *pid, + unsigned int count, u32 *pktid) +{ + int old = atomic_read(&pid->seq_num); + u32 first, next; + bool fits; + + for (;;) { + first = (u32)old; + next = first + count; + + /* space is already exhausted */ + if (unlikely(!first)) + return -ERANGE; + + fits = count - 1 <= U32_MAX - first; + /* if it doesn't fit we still have to publish exhaustion (0) + * so concurrent allocators stop using this key + */ + if (unlikely(!fits)) + next = 0; + + /* if another CPU changed the state, we retry using the new + * seq_num value + */ + if (!atomic_try_cmpxchg(&pid->seq_num, &old, (int)next)) + continue; + + if (unlikely(!fits)) + return -ERANGE; + + *pktid = first; + return 0; + } +} + /* Write 12-byte AEAD IV to dest */ static inline void ovpn_pktid_aead_write(const u32 pktid, const u8 nt[], From patchwork Mon Nov 9 17:16:24 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5639 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp983513lat; Mon, 9 Nov 2026 09:18:36 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHm2T2Uu1Y34CrHnK1W/4Ze71kWyxEZCC01ua/oV6FrJ72TjJ2zGlZpgfX4a1qKXiTbuOZYuQd2rZo=@openvpn.net X-Received: by 2002:a05:6808:2386:b0:4b3:7efc:e970 with SMTP id 5614622812f47-5683c9dfdf3mr219575b6e.5.1794244613607; Mon, 09 Nov 2026 09:16:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794244613; cv=none; d=google.com; s=arc-20260327; b=fvj+wTjeNcelW+0ejy64aWXYSYWlGnnw6vp3f0dhSRTBY6o2T+CPwt4QBteu1S0M9l h+hmRatZkdgBwxI80uv4fOg76iuaGRbHaQdxdB7ZdXb6ZgHe2s37TqN5saLn1Dc9oKYM H4fXjETmUniUTJULMuMedIaGz6NJauSWuOePBfThRjDr8II8f7iKaTi9Pap0TZ3einmf 9r/emydlu4GWr0+ysapZAiFlWWEBkXISrNyOXwQXSsP8qcydmJ+wBfvSzrX0nmGMLR4h NxeOpYIS9f/SuXz8KinpsYZ4xt3zpqI/m5YoXwfTGJUClmMH2mM2Blv9ZeaGq10F3hxP sP1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=C8ZTkCdKxhMg3QkWhSNVDrvU4NmJc30oL5Yz1eX+qLU=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=IVVWKZKRdnjlziJvCPg0aJLuGHIzBvpDfNuYRV9gSYBN0HUKiUxCO0EY3vNJ1UiwIx yo6V7634TL4vrF3lDOUzeLRKsaDghZhWiDPbhYhwvNbABgcC2SFLlmNLFXavLZc7WQz9 wn2i5tXrWavFw2e+QftMWunuWVUcDYWticDPk9IQOnSYQwbNqwkyqee4e6IfwqWzhVbw FTyb/SoNfmOq9bS5MT0mH1ZrWIxAZncnXATHx+02zKo4Pz8Su1r0d+tZZTBLzxd2c4b1 wf/VLwS+7BcBDKKpTA1oBnJXdsFa19dmwrCfDMyP3zcqCDLQfv9Os6LISk2zIu6W16r4 d+3Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=UE2tVeop; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=PT1G7RzW; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=aSRz7s3l; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=qUDlqA1Z; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 5614622812f47-56813b97ef7si5212129b6e.78.2026.11.09.09.16.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 09:16:53 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=UE2tVeop; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=PT1G7RzW; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=aSRz7s3l; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=qUDlqA1Z; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=C8ZTkCdKxhMg3QkWhSNVDrvU4NmJc30oL5Yz1eX+qLU=; b=UE2tVeop3mMBTO w1s26PeJQTZF7wxyW/CYNcERnZp+SQa0tchOI2W2sTTFoLGBx/dF95IOF0uJcPANAGha5NQOACBZz iGIFFUeS3w/yuwQcstPaFPnG1bHshmcKrFVa4WCpuCQ8KjjBkrPAGeIwCf2Am5TDUySk3K0v5yyTa hSI=; Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xQSzE-000000005T2-0BbC; Mon, 09 Nov 2026 17:16:52 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xQSzB-000000005Si-2zdX for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ddgVDKqdiAxFMEY2+uct1UMmmeth1+b6Yi9Xo1BcFUc=; b=PT1G7RzWqo7UUwJuk2L+/2Z2/2 FB0jJqppzthe8UyrqsnL5I/k1QAknm60ycgISYWgCWRxzppDY0gBZ4xup7jZAaj0XWBsajdlNJp3g 2iCtnLRcpN4a4ARRSe2/CW6QZS2AtXX5+kw+KqFO7SR4veCtH85wUIvLua/SmOUEWZBA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ddgVDKqdiAxFMEY2+uct1UMmmeth1+b6Yi9Xo1BcFUc=; b=aSRz7s3l5UhEC1rYSYzByhLgm1 /1IHiY8SqSd4GUl++ADRfL4Nbm94Nrb3UcB9Iln6DdonQjkFS6LgPiPp+/xRTupOjYh0esDl23ovS wTd3abq3pdDKSaXE7CbNXCnjkgbp6UkA55N3Gr64+zS6JywwpTecnDi1QMZOseGqo+LI=; Received: from mout-b-210.mailbox.org ([195.10.208.40]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQSz8-000000003aZ-3HAa for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:49 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-210.mailbox.org (Postfix) with ESMTPS id 4jNbzq0wV5zFqX2 for ; Mon, 09 Nov 2026 18:16:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794244599; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ddgVDKqdiAxFMEY2+uct1UMmmeth1+b6Yi9Xo1BcFUc=; b=qUDlqA1ZZwwnB7twU+T5XDdwS1BmywCq/Qv5OYRO/xncpDNCML4B/OFsrPP6CzGtKCNCYM idVRXtDroOyvhvqh8lCjkHMbBDJyUgpxUWaLpuyVoepZ0Eec4xNFCX1AICeCzQWZg1+svv JcVopBRvzRVTuQSJdo+3HAeujtTZp/Nuer+ZfZ/I3dhqj35KETC1NFKOQZmZifaGVSctK1 p+i+FM0qhHmf5ZFb7oyznZtHWUl6OZw7og78/luIr/D100I/t8tvmQbtrvRhYd615JNMKf HYwRDy52ZXSkaiBCRTOSOZ58Wydv1hnHOm28n+dUoTW7yNlGT/aHBf/q9mwLNg== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 18:16:24 +0100 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNbzq0wV5zFqX2 X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Each encrypted GSO record currently builds its authenticated header in request-local scratch storage, copies it into the final UDP GSO aggregate and then maps that range again as destination AAD. Map the final output range first and, when it is represented by one base-page-contained scatterlist entry, construct the header directly there. Use the same entry as source and destination AAD since t [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1xQSz8-000000003aZ-3HAa Subject: [Openvpn-devel] [PATCH ovpn net-next v5 8/9] ovpn: place GSO record AAD directly in output X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881401839742773213 X-GMAIL-MSGID: 1881401839742773213 Each encrypted GSO record currently builds its authenticated header in request-local scratch storage, copies it into the final UDP GSO aggregate and then maps that range again as destination AAD. Map the final output range first and, when it is represented by one base-page-contained scatterlist entry, construct the header directly there. Use the same entry as source and destination AAD since the AEAD interface does not write destination AAD and permits the two entries to alias. Use an unaligned-safe opcode store because a record's offset in the aggregate need not be naturally aligned. Retain the scratch-and-copy path as a fallback when the output range cannot be mapped suitably. In a balanced three-round matrix, direct placement increased throughput by 2.1% and reduced cycles and instructions per byte by 1.3% and 1.0%. Signed-off-by: Ralf Lici --- No changes since v4 https://lore.kernel.org/openvpn-devel/26e88846a6e2ebcd4a64c50d61edff9ccf6161ac.1794234673.git.ralf@mandelbit.com/ No changes since v3 https://lore.kernel.org/openvpn-devel/62065a69f01a64708cc34e6eeff159bb4bbc5f48.1794223133.git.ralf@mandelbit.com/ Changes since v2 https://lore.kernel.org/openvpn-devel/20261102164353.459969-10-ralf@mandelbit.com/ - Use an unaligned-safe store when constructing AAD directly in the output aggregate. (Sashiko) - Refresh the measurements. New in v2. drivers/net/ovpn/crypto_aead.c | 64 ++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index a75a0bf65c89..763fd4f2cc25 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -8,7 +8,9 @@ */ #include +#include #include +#include #include #include #include @@ -169,10 +171,33 @@ static void ovpn_aead_encrypt_header(struct ovpn_peer *peer, /* add the packet opcode and wire nonce as associated data */ op = ovpn_opcode_compose(OVPN_DATA_V2, ks->key_id, peer->tx_id); BUILD_BUG_ON(sizeof(op) != OVPN_OPCODE_SIZE); - *(__force __be32 *)data = htonl(op); + put_unaligned_be32(op, data); memcpy(data + OVPN_OPCODE_SIZE, iv, OVPN_NONCE_WIRE_SIZE); } +static bool ovpn_aead_encrypt_header_direct(struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, + u32 pktid, u8 *iv, + struct scatterlist *sg) +{ + unsigned int offset, page_offset; + struct page *page; + void *addr; + + offset = sg->offset; + page_offset = offset_in_page(offset); + if (page_offset + OVPN_AAD_SIZE > PAGE_SIZE) + return false; + + /* an SG offset can address a later base page in a compound page */ + page = sg_page(sg) + (offset >> PAGE_SHIFT); + addr = kmap_local_page(page); + ovpn_aead_encrypt_header(peer, ks, pktid, iv, addr + page_offset); + kunmap_local(addr); + + return true; +} + int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb, struct sk_buff *gso_skb, unsigned int offset, @@ -184,6 +209,7 @@ int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, struct aead_request *req; unsigned int payload_off; int dst_idx, mapped, ret; + bool direct_aad; u8 *aad, *iv; req = ovpn_aead_request_alloc(ks->encrypt, skb, src_nents + dst_nents, @@ -194,26 +220,42 @@ int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, dst = src + src_nents; aad = (u8 *)(dst + dst_nents); - ovpn_aead_encrypt_header(peer, ks, pktid, iv, aad); - - ret = skb_store_bits(gso_skb, offset, aad, OVPN_AAD_SIZE); - if (unlikely(ret < 0)) - return ret; - /* encrypt out of place from the original segmented skb directly into * its final range in the UDP GSO skb */ sg_init_table(src, src_nents); - sg_set_buf(src, aad, OVPN_AAD_SIZE); + /* use the final output bytes as source AAD too when they can be safely + * written through one base-page mapping + */ + mapped = skb_to_sgvec_nomark(gso_skb, src, offset, OVPN_AAD_SIZE); + if (unlikely(mapped < 0)) + return mapped; + direct_aad = mapped == 1 && + ovpn_aead_encrypt_header_direct(peer, ks, pktid, iv, src); + if (unlikely(!direct_aad)) { + ovpn_aead_encrypt_header(peer, ks, pktid, iv, aad); + ret = skb_store_bits(gso_skb, offset, aad, OVPN_AAD_SIZE); + if (unlikely(ret < 0)) + return ret; + sg_set_buf(src, aad, OVPN_AAD_SIZE); + } + mapped = skb_to_sgvec_nomark(skb, src + 1, 0, skb->len); if (unlikely(mapped < 0)) return mapped; sg_mark_end(&src[mapped]); sg_init_table(dst, dst_nents); - dst_idx = skb_to_sgvec_nomark(gso_skb, dst, offset, OVPN_AAD_SIZE); - if (unlikely(dst_idx < 0)) - return dst_idx; + if (likely(direct_aad)) { + /* destination AAD is not written and may alias source AAD */ + sg_set_page(dst, sg_page(src), src->length, src->offset); + dst_idx = 1; + } else { + dst_idx = skb_to_sgvec_nomark(gso_skb, dst, offset, + OVPN_AAD_SIZE); + if (unlikely(dst_idx < 0)) + return dst_idx; + } payload_off = offset + OVPN_AAD_SIZE + OVPN_AUTH_TAG_SIZE; mapped = skb_to_sgvec_nomark(gso_skb, dst + dst_idx, payload_off, From patchwork Mon Nov 9 17:16:25 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5638 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp983170lat; Mon, 9 Nov 2026 09:18:22 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErG8/XHN+0twg/b1zvruEnaRS/h8Z1wzxn+BzTLIAwIfpxhTAhML9427BeJS+HoNfzetViBTS3kSGko=@openvpn.net X-Received: by 2002:a05:6820:5711:10b0:6f9:4f1b:3987 with SMTP id 006d021491bc7-7170f2d3b16mr1683621eaf.59.1794244613576; Mon, 09 Nov 2026 09:16:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794244613; cv=none; d=google.com; s=arc-20260327; b=N5WACf/oLeM8hm0VCVAqJEHEkB3gej0g9KhP6BBEOrW9O0HrgZmldyxW5vHhwUz1BY yxP78VreJp8ug5hy0Z136Pm1ZIw9FLvwZPnJSIDNvQed2GcGqQ+0cK4gZU/hljPTPMiU jjcPwZbuXw1qtswhApVouxtAxj794J0uAYA1aG2hZXvUk1MpIIAieC7xu7n/wUj2qeoc 7C+Tp/4p/ivSuRhA2Wx7bpthC8IUCtNyVaz9wCG1oA7HltPyAhA/g0jY0x5WNRs60UMi jExAIJGDdpjJQt7X6sel4Va4rhscgELlxMyy3lD2iTNS1VFtsM/apxYo/Kebm1yoakwh SGSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=ylOX9LWgUOEGMLycktLZ0wb2JE4bWr5atF78CYh1m10=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=ZlS6gOQip/dhGxp0A9hzc9VwPeQ2eEEl9MgJ9NaxtrboTZOYBjLfPQW9qjqHqgx39J 41LPznxqSJcH22HHw8/uQwbb6wrrFGDVVDuC16dXlyCN1UPCg+c1RLQHXOYDsdtgW2rg suvaZhlVuagIIL1zMP5HK/TD1eNms7jogcJWYnKBf1F+qWpKJSFIX178Xqd2PYXWG2dN WOALweqmifB/BxG4HjxrcUGSDLD66CNq6Ue+mVvgDFOgEdxcR0TMKj1PfG3FsEZ4Xy2U KTI8ojU0V3PjJrsLRVkUsJ23ut90P4pvnHotFoBIz67/qDOe58NP4FUaXtOyI8HOwv/O yvwQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=eu5YtXsX; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=eJpxGB+S; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=A3fHCOHh; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=URHOiN0N; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 586e51a60fabf-4ae1f83ed73si277293fac.67.2026.11.09.09.16.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 09:16:53 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=eu5YtXsX; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=eJpxGB+S; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=A3fHCOHh; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=URHOiN0N; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=ylOX9LWgUOEGMLycktLZ0wb2JE4bWr5atF78CYh1m10=; b=eu5YtXsXQNmBR8 +5UxbZqYf7J3msH+N6joetMnXZjD02VJ0UIdzLQZyOtGgRC5QYTG1A9qkCsAvNoxE/V2L3u00H0vq CB9AUlWQ1hA2FcuUJsjc2ataDSaFLfc+YfMiC9UHR08zQYOyojUHumeriQJm/WnYQm1ctN5TBUjBP qAE=; Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xQSzE-000000002Zw-0l3w; Mon, 09 Nov 2026 17:16:52 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xQSzB-000000002ZX-1f9g for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=6M/ukuCgO3AQfPi2kbTIR2TIw3bm3ZExq27KNWl+wqI=; b=eJpxGB+S5+6ByHSZtoxO7Whyup 0y2DIrZvZN9TIeK6Vp/poiJ2tde6bKaGfU0Ij3HfnkchIaWij3JepVhas+btzBW6z9CXKSd4fVWb3 Xs4AWfmqpJF7Yl8FqQXQhynAisRt8NYyKdmx+p1SGvTYj2VA/cJl4ufbxKfIsUfEtDBk=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=6M/ukuCgO3AQfPi2kbTIR2TIw3bm3ZExq27KNWl+wqI=; b=A3fHCOHhyzfkKJQrpa1x5dpGHu UPbFY1WhY/z6PTXOo0T9Um2Plt4sHllpE91phOHuGJq0s7JChT6iosQCkQp+bQGIBFRA6yQ+EX/AB XdwV5u1O2xQQZCWsiL1Uw+dvDjaCutCR2i4qDF2ePIuEF+uHg2TS7qsAc1NEyNLxh7Kw=; Received: from mout-b-105.mailbox.org ([195.10.208.50]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQSz9-000000004gh-2x2y for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:49 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-105.mailbox.org (Postfix) with ESMTPS id 4jNbzq2gyGz9tRL for ; Mon, 09 Nov 2026 18:16:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794244599; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6M/ukuCgO3AQfPi2kbTIR2TIw3bm3ZExq27KNWl+wqI=; b=URHOiN0N6G74VZ/cpZBz4RIGKI4ATCbLACLTOM6PDqj1DV3DL7mpre8ZYUb/YPUfw/8feu oLMXuW9sCKT0Lb7wmBTCKXzx3kTUTQy10mzn372qa7H83Br15bhHyA3DpSDzUdV+hUPlMK fK618MYaQkAZBOl+dUjvGQHUkWHT2o1Xm/obap9d8pZC8fFTMiVaOLekboPyGNvqbQg/8W UeuvW4+gpYWQk5QunE2g3uab8CHAojDljVek3bEdDNSsToE6k0l/S8TJCMAevPjolEsOE1 ZvwiUPePfQYTfdCVN+iQy3dEBhvijxFVtu/AyZDIeQB30CMWJvoiN2Vc5wukGQ== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 18:16:25 +0100 Message-ID: <2b306807196651e75e0bcbad0e672fb1d22a10de.1794244231.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNbzq2gyGz9tRL X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-2.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: UDP GSO aggregation is restricted to synchronous transforms, so each AEAD request is complete before the next record is prepared. The request, IV, scatterlists and fallback AAD scratch space therefore [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-Headers-End: 1xQSz9-000000004gh-2x2y Subject: [Openvpn-devel] [PATCH ovpn net-next v5 9/9] ovpn: reuse one AEAD request per UDP GSO batch X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881401839857094496 X-GMAIL-MSGID: 1881401839857094496 UDP GSO aggregation is restricted to synchronous transforms, so each AEAD request is complete before the next record is prepared. The request, IV, scatterlists and fallback AAD scratch space therefore need not be allocated separately for every record. Keep the small context descriptor on the stack and allocate one backing area containing a source table, destination table and crypto request for the complete batch. Rebuild the table contents and update the IV for each record. Initialize the transform, callback and associated-data length once because they remain constant. This replaces one allocation and free per record with one per batch while retaining the same output layout and error handling. On two directly connected 100-Gbit/s mlx5 ports using one zero-copy TCP flow, AES-128-GCM and a 1408-byte tunnel MTU, mean cycles per byte decreased from 4.849 to 4.680 (-3.5%) and instructions per byte from 10.563 to 10.354 (-2.0%). Signed-off-by: Ralf Lici --- No changes since v4 https://lore.kernel.org/openvpn-devel/f913dae13b9c0bc390a1d3e32c8ca60b2e6ec3ea.1794234673.git.ralf@mandelbit.com/ No changes since v3 https://lore.kernel.org/openvpn-devel/abf6a5a2236f03dc8d4d1f14a94ac19507af7007.1794223133.git.ralf@mandelbit.com/ New in v3. drivers/net/ovpn/crypto_aead.c | 102 +++++++++++++++++++-------------- drivers/net/ovpn/crypto_aead.h | 25 ++++++-- drivers/net/ovpn/io.c | 14 +++-- 3 files changed, 89 insertions(+), 52 deletions(-) diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index 763fd4f2cc25..e27b8c47c0fb 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -136,17 +136,13 @@ static struct scatterlist *ovpn_aead_crypto_req_sg(struct crypto_aead *aead, static struct aead_request *ovpn_aead_request_alloc(struct crypto_aead *aead, struct sk_buff *skb, - unsigned int nents, - unsigned int extra, u8 **iv) + unsigned int nents, u8 **iv) { struct aead_request *req; void *tmp; - /* allocate IV, request, scatterlist entries and caller scratch space - * in one block - */ - tmp = kmalloc(ovpn_aead_crypto_tmp_size(aead, nents) + extra, - GFP_ATOMIC); + /* allocate IV, request and scatterlist entries in one block */ + tmp = kmalloc(ovpn_aead_crypto_tmp_size(aead, nents), GFP_ATOMIC); if (unlikely(!tmp)) return ERR_PTR(-ENOMEM); @@ -198,86 +194,108 @@ static bool ovpn_aead_encrypt_header_direct(struct ovpn_peer *peer, return true; } -int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, +int ovpn_aead_gso_ctx_init(struct ovpn_aead_gso_ctx *ctx, + struct ovpn_crypto_key_slot *ks, + struct sk_buff *gso_skb) +{ + const unsigned int dst_nents = skb_shinfo(gso_skb)->nr_frags + 4; + const unsigned int src_nents = MAX_SKB_FRAGS + 2; + unsigned int tmp_size; + + tmp_size = ovpn_aead_crypto_tmp_size(ks->encrypt, + src_nents + dst_nents); + tmp_size += OVPN_AAD_SIZE; + ctx->tmp = kmalloc(tmp_size, GFP_ATOMIC); + if (unlikely(!ctx->tmp)) + return -ENOMEM; + + ctx->dst_nents = dst_nents; + ctx->iv = ovpn_aead_crypto_tmp_iv(ks->encrypt, ctx->tmp); + ctx->req = ovpn_aead_crypto_tmp_req(ks->encrypt, ctx->iv); + ctx->src = ovpn_aead_crypto_req_sg(ks->encrypt, ctx->req); + ctx->dst = ctx->src + src_nents; + ctx->aad = (u8 *)(ctx->dst + dst_nents); + aead_request_set_tfm(ctx->req, ks->encrypt); + aead_request_set_callback(ctx->req, 0, NULL, NULL); + aead_request_set_ad(ctx->req, OVPN_AAD_SIZE); + + return 0; +} + +void ovpn_aead_gso_ctx_free(struct ovpn_aead_gso_ctx *ctx) +{ + kfree(ctx->tmp); +} + +int ovpn_aead_encrypt_gso(struct ovpn_aead_gso_ctx *ctx, struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb, struct sk_buff *gso_skb, unsigned int offset, u32 pktid) { - const unsigned int dst_nents = skb_shinfo(gso_skb)->nr_frags + 4; - const unsigned int src_nents = skb_shinfo(skb)->nr_frags + 2; - struct scatterlist *src, *dst; - struct aead_request *req; unsigned int payload_off; int dst_idx, mapped, ret; bool direct_aad; - u8 *aad, *iv; - - req = ovpn_aead_request_alloc(ks->encrypt, skb, src_nents + dst_nents, - OVPN_AAD_SIZE, &iv); - if (IS_ERR(req)) - return PTR_ERR(req); - src = ovpn_aead_crypto_req_sg(ks->encrypt, req); - dst = src + src_nents; - aad = (u8 *)(dst + dst_nents); /* encrypt out of place from the original segmented skb directly into * its final range in the UDP GSO skb */ - sg_init_table(src, src_nents); + sg_init_table(ctx->src, skb_shinfo(skb)->nr_frags + 2); /* use the final output bytes as source AAD too when they can be safely * written through one base-page mapping */ - mapped = skb_to_sgvec_nomark(gso_skb, src, offset, OVPN_AAD_SIZE); + mapped = skb_to_sgvec_nomark(gso_skb, ctx->src, offset, + OVPN_AAD_SIZE); if (unlikely(mapped < 0)) return mapped; direct_aad = mapped == 1 && - ovpn_aead_encrypt_header_direct(peer, ks, pktid, iv, src); + ovpn_aead_encrypt_header_direct(peer, ks, pktid, ctx->iv, + ctx->src); if (unlikely(!direct_aad)) { - ovpn_aead_encrypt_header(peer, ks, pktid, iv, aad); - ret = skb_store_bits(gso_skb, offset, aad, OVPN_AAD_SIZE); + ovpn_aead_encrypt_header(peer, ks, pktid, ctx->iv, ctx->aad); + ret = skb_store_bits(gso_skb, offset, ctx->aad, + OVPN_AAD_SIZE); if (unlikely(ret < 0)) return ret; - sg_set_buf(src, aad, OVPN_AAD_SIZE); + sg_set_buf(ctx->src, ctx->aad, OVPN_AAD_SIZE); } - mapped = skb_to_sgvec_nomark(skb, src + 1, 0, skb->len); + mapped = skb_to_sgvec_nomark(skb, ctx->src + 1, 0, skb->len); if (unlikely(mapped < 0)) return mapped; - sg_mark_end(&src[mapped]); + sg_mark_end(&ctx->src[mapped]); - sg_init_table(dst, dst_nents); + sg_init_table(ctx->dst, ctx->dst_nents); if (likely(direct_aad)) { /* destination AAD is not written and may alias source AAD */ - sg_set_page(dst, sg_page(src), src->length, src->offset); + sg_set_page(ctx->dst, sg_page(ctx->src), ctx->src->length, + ctx->src->offset); dst_idx = 1; } else { - dst_idx = skb_to_sgvec_nomark(gso_skb, dst, offset, + dst_idx = skb_to_sgvec_nomark(gso_skb, ctx->dst, offset, OVPN_AAD_SIZE); if (unlikely(dst_idx < 0)) return dst_idx; } payload_off = offset + OVPN_AAD_SIZE + OVPN_AUTH_TAG_SIZE; - mapped = skb_to_sgvec_nomark(gso_skb, dst + dst_idx, payload_off, - skb->len); + mapped = skb_to_sgvec_nomark(gso_skb, ctx->dst + dst_idx, + payload_off, skb->len); if (unlikely(mapped < 0)) return mapped; dst_idx += mapped; - mapped = skb_to_sgvec_nomark(gso_skb, dst + dst_idx, + mapped = skb_to_sgvec_nomark(gso_skb, ctx->dst + dst_idx, offset + OVPN_AAD_SIZE, OVPN_AUTH_TAG_SIZE); if (unlikely(mapped < 0)) return mapped; dst_idx += mapped; - sg_mark_end(&dst[dst_idx - 1]); + sg_mark_end(&ctx->dst[dst_idx - 1]); - aead_request_set_tfm(req, ks->encrypt); - aead_request_set_callback(req, 0, NULL, NULL); - aead_request_set_crypt(req, src, dst, skb->len, iv); - aead_request_set_ad(req, OVPN_AAD_SIZE); + aead_request_set_crypt(ctx->req, ctx->src, ctx->dst, skb->len, + ctx->iv); - return crypto_aead_encrypt(req); + return crypto_aead_encrypt(ctx->req); } int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, @@ -319,7 +337,7 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, nfrags = 1; } - req = ovpn_aead_request_alloc(ks->encrypt, skb, nfrags + 2, 0, &iv); + req = ovpn_aead_request_alloc(ks->encrypt, skb, nfrags + 2, &iv); if (IS_ERR(req)) return PTR_ERR(req); sg = ovpn_aead_crypto_req_sg(ks->encrypt, req); diff --git a/drivers/net/ovpn/crypto_aead.h b/drivers/net/ovpn/crypto_aead.h index 92e8ed76fba6..c0c777410661 100644 --- a/drivers/net/ovpn/crypto_aead.h +++ b/drivers/net/ovpn/crypto_aead.h @@ -15,12 +15,29 @@ #include #include +struct aead_request; +struct scatterlist; + +struct ovpn_aead_gso_ctx { + struct aead_request *req; + struct scatterlist *src; + struct scatterlist *dst; + void *tmp; + u8 *iv; + u8 *aad; + unsigned int dst_nents; +}; + int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb); -int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, - struct ovpn_crypto_key_slot *ks, - struct sk_buff *skb, struct sk_buff *gso_skb, - unsigned int offset, u32 pktid); +int ovpn_aead_gso_ctx_init(struct ovpn_aead_gso_ctx *ctx, + struct ovpn_crypto_key_slot *ks, + struct sk_buff *gso_skb); +void ovpn_aead_gso_ctx_free(struct ovpn_aead_gso_ctx *ctx); +int ovpn_aead_encrypt_gso(struct ovpn_aead_gso_ctx *ctx, struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, struct sk_buff *skb, + struct sk_buff *gso_skb, unsigned int offset, + u32 pktid); int ovpn_aead_decrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb); diff --git a/drivers/net/ovpn/io.c b/drivers/net/ovpn/io.c index cf9f196f7379..cfdaad214bc1 100644 --- a/drivers/net/ovpn/io.c +++ b/drivers/net/ovpn/io.c @@ -376,29 +376,29 @@ static bool ovpn_encrypt_gso_queue(struct sk_buff_head *skbs, unsigned int segments) { unsigned int offset = 0, moved = 0, i, len; + struct ovpn_aead_gso_ctx ctx = { }; struct sk_buff *skb; u32 first_pktid; int ret; + if (unlikely(ovpn_aead_gso_ctx_init(&ctx, ks, batch))) + goto err; + /* reserve the complete range before dequeuing any input skb so that a * failure leaves the ordinary transmit path available as a fallback */ if (unlikely(ovpn_pktid_xmit_range(&ks->pid_xmit, segments, &first_pktid))) { ovpn_encrypt_key_exhausted(peer, ks); - ovpn_crypto_key_slot_put(ks); - ovpn_peer_put(peer); - return false; + goto err; } for (i = 0; i < segments; i++) { skb = __skb_dequeue(skbs); len = skb->len + OVPN_DATA_V2_OVERHEAD; - memset(ovpn_skb_cb(skb), 0, sizeof(struct ovpn_cb)); - ret = ovpn_aead_encrypt_gso(peer, ks, skb, batch, offset, + ret = ovpn_aead_encrypt_gso(&ctx, peer, ks, skb, batch, offset, first_pktid + i); - kfree(ovpn_skb_cb(skb)->crypto_tmp); if (unlikely(ret < 0)) { DEBUG_NET_WARN_ON_ONCE(ret == -EINPROGRESS || ret == -EBUSY); @@ -437,9 +437,11 @@ static bool ovpn_encrypt_gso_queue(struct sk_buff_head *skbs, if (unlikely(i < segments)) goto err; + ovpn_aead_gso_ctx_free(&ctx); ovpn_encrypt_send(peer, ks, batch, segments); return true; err: + ovpn_aead_gso_ctx_free(&ctx); ovpn_crypto_key_slot_put(ks); ovpn_peer_put(peer); return false;