From patchwork Mon Nov 9 11:25:16 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5615 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp529079lat; Mon, 9 Nov 2026 03:25:50 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHBujIqRlB97TyfQtXESXWAwwOKBqruLpXEWVhZqUgFeRYF5cQjh/rLd8OyPp7EebcTiTYiat+TGz4=@openvpn.net X-Received: by 2002:a05:693c:6219:b0:36a:3ac:b15 with SMTP id 5a478bee46e88-3725e53e215mr6723044eec.36.1794223550069; Mon, 09 Nov 2026 03:25:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794223550; cv=none; d=google.com; s=arc-20260327; b=G85kDWXJmExYVUSFklR6pi1D2hnTbNF1kZ9RxdFWxxvXag7nAPDen4+1NfD+BeDILB SSiBF/kX516sOyUlT2/2/qOcOWzkfQOeTatUa32nH9IdzqnoqNn5NOEJ3pHsTk66XkJz NhMMqYxqRpYqv2LjzlrU5vPYRFc+NNcsREO4yQ4PBhH9DGy/442wH4+jBb1F1e4hn1yS G9Nt5ktVjm7LuwAhatXRSuC5OWa8zcwDEHtWSAROdFYwT0cQzGiDuWeMNVvWI1QpugnT KxD4XChoXyCHclhFS8SuDC0ply56LOQuDhKgvDHtTshWAPRftlFb9rxbKsUIvDoSzBoI I9bQ== 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=CVojCLxCFcOe8UIgweHCwrBwmMvL30eD9qbhqx87HWc=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=JOhLxa+eLOdVXd5U+Eh8Uo5T+qq/b253cavJJNWqJxdd2+vCtZE5hxzKyT5xeVsfJF XOcd2W/skOD2j6iPwS2ZV0B/MUZazWf0HDiUEU9SFMXjcIssKK6iHtbnKG5Bj5gw9H1U PZxflr2wR6fst5nN/nzRCdLRBTw4rx8OG8NoS6VwFhLEWzMzDcfV76eYfi/8WCd+kwCK 1XvcrSHeu45Z4/32UGtzRCSWG8Dpl0gKBrnAhhGUxnQBkESfDWOSx4IZhKhAvICLcGwl ylTJ9i8+KLfJC+YcrS7v33FiafmXjNQrG4m4H1Iph8MgehAQjnmjhPS64gT1lkYeTCaK hDzA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=ATFuAnD8; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=lYKHSSPd; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="ZV/8NW+p"; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=oIckzM9b; 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 5a478bee46e88-372632de76bsi19444704eec.1.2026.11.09.03.25.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 03:25:50 -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=ATFuAnD8; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=lYKHSSPd; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="ZV/8NW+p"; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=oIckzM9b; 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=CVojCLxCFcOe8UIgweHCwrBwmMvL30eD9qbhqx87HWc=; b=ATFuAnD8TXstlz D3y6aoHmpTNbpI1v5Q9INHgZR9DtxIYmCpcc9DNJcS7sEqUkqshggSKcXe3bwSTOReSu6MOGEwsRP Bb33SlGY5cedw6gye+HS4ywpidjop7lqWqZexqyUfKlVt3VdA8RYxbl1YtaV+6Vg8ppQpfxuMUai6 O9E=; 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 1xQNVS-000000002m8-3yUa; Mon, 09 Nov 2026 11:25:46 +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 1xQNVQ-000000002ly-1f9G for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 11:25:45 +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=57rDa9q7ow46D2cQusYuQITUY/eyzBVjAi47J/gtMTw=; b=lYKHSSPd0qCyJMEeoO+6GwcqKE FotPfnE18obpSAPk5smZCKQqWerEv0/CFT4siyjW0naAVzxE2ffBb0gcBrOvDbBQe1ovXgiq5aPQZ Sy519BaFabhEeJYbsd86IG0S/4QUjo9Zty6FbUIrRa+plPelxgCNOE0xNxqU0poAehL0=; 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=57rDa9q7ow46D2cQusYuQITUY/eyzBVjAi47J/gtMTw=; b=ZV/8NW+pC/oCk62L/fx3w4JfdX +zSBrdOmmEwFeiEafLBndd5am3TJtZuBz6C1Z+H8Ss7w+zKJvyT5BltPRVcnL0q1OZiHT7Z5D7IR+ cAjA0cOm9dnZAn4JHwSaatbRUYpNGEeVNcMNskQJtClIdS+nwOYdfGX77QupPEXNHHSE=; Received: from mout-b-203.mailbox.org ([195.10.208.52]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQNVP-000000003Em-0065 for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 11:25:44 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA512) (No client certificate requested) by mout-b-203.mailbox.org (Postfix) with ESMTPS id 4jNSBk4PKKzLltD for ; Mon, 09 Nov 2026 12:25:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794223534; 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=57rDa9q7ow46D2cQusYuQITUY/eyzBVjAi47J/gtMTw=; b=oIckzM9b80hgiEirsIINve2sUznz4u7dVyCE/EjYcRKe7/sLiQ6WFRfWrEJvd1YxD7VGNW EbJKvpCtYoHFyp1tBw9apbZoLyrGoKXlA+cna53E2tfIdaXZCDrD+7gNwjS2JczLk6Jdg3 WIkDch58IlJQEFtlwSl9mFgXRgEJblosiISEltWaEo3yWNnvYzQB5GQFE96bBG0IbSO1Qy YQGA/DwzSSEGiW/3b/vveKEadNjU/w9Mn0wr7dvl6QjdC9UO13H3Ey2NoLrZCUPX1fbe/e zzDHXjF+bmDZ5c+X1QXmCM6q1msUSs2OWes9mviB53aYip0fSGT8aD40tqWbfQ== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 12:25:16 +0100 Message-ID: <1025ad1b437a4eb410967703dfd784a4ba8c30f5.1794223133.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNSBk4PKKzLltD 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: 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 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: 1xQNVP-000000003Em-0065 Subject: [Openvpn-devel] [PATCH ovpn net-next v3 1/8] 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: 1881379753406037229 X-GMAIL-MSGID: 1881379753406037229 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 --- 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 11:25: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: 5613 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp529077lat; Mon, 9 Nov 2026 03:25:50 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHQLJ+b5ZtBLNhA7dzHv+6YNvzbptxJVvsHCzRXtZPU8YisPA8EmLmQxrBS+XzGKTWOSZ9M3CxD554=@openvpn.net X-Received: by 2002:a05:693c:88c6:20b0:372:598d:c0bb with SMTP id 5a478bee46e88-372598dc563mr6412907eec.13.1794223550090; Mon, 09 Nov 2026 03:25:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794223550; cv=none; d=google.com; s=arc-20260327; b=PNoKMG7nU7li1xhSX+dbr/pujWBOt0Juz3gyBN/q7LBdZyYEQNiPRaxMGPn9ZPBpxx X4Nw7z3WnkeLA//C4ExhqDbnxnYpWPpG7dNG1xZFjcT0MANsqSa38pCZ36JJBEH0gNmx nmJaEZ6mhzeQm/oCtvrogCKgsZCgyPa7BGX5ikTWHZ14fbnoowZqazsBODAzGgATir6l 5VbxnfcxUUyZDgMX6ulDY8yIk0XC+d2j4ivQKUzxt8rUkaxUXui4xI6eu7QXDEkgyeCt s5TE7NxPpKDjj66yd+rL2nS2mLskQT/gF+7HflsfM+hWGZXY9tDHeEyRROpYLYnJ0VuZ 0Bgg== 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=n+gKJ5fEYcLs5ja3cy7bTrVXn7jyBJ2/dNQv7WaYNqI=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=VbNDKaAt7AN5CjkXr32yr2omjimrIB/O71KcZ/tMS9F9mbEVBMwcuo2wooAHX/28Uf LA7cMNVRzgOkR12G8n+//0ZqXoQDWicAVvmXjpkL0D/4fd6HMTvfz1Ux8Su8oIsptdR6 FdmGlvZlbkSJCzIqI9kSIkm/Z6gPk8spvycoRIGDaTy26YpStD2S/JMHCQct+r4cVhWc CzP03heNCnXIyTBY68HpMb8faXPhCdX74fjF3zZOabpUw3ofmrnhedRD1I011e18aL+L ta4qElq3wtUm+ZcjTxKkd2dxBrS7D6LhScSoJ7G37fGWEeNyF0GNoFLhyWtEYyvYPv+k Qqig==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=gyUxzoIe; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="GIf/i5oM"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="NDReo0L/"; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=k9G7QPOT; 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 5a478bee46e88-37265ff863csi14619812eec.48.2026.11.09.03.25.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 03:25:50 -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=gyUxzoIe; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="GIf/i5oM"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="NDReo0L/"; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=k9G7QPOT; 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=n+gKJ5fEYcLs5ja3cy7bTrVXn7jyBJ2/dNQv7WaYNqI=; b=gyUxzoIenFB3dE +dRMR5sF0ZGVkaahrmXeHa6zx8fHztxX4T/h/0hTSx70y4ZPHY1npT474N9VolwdsTssF6pQolWzw BpqRXLMdQTwkRwOpAVwsZUHhq8mkbVaxxKI8V/Hp5xit6sH7E3spwmu5qeMH67BCGZG42lD+gwDMa 7mo=; 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 1xQNVU-000000007rA-435a; Mon, 09 Nov 2026 11:25:48 +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 1xQNVQ-000000007qO-1ImC for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 11:25:45 +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=oQ5Zt1YdtdqVn4hKEgtMKWZcjMxLtcf92isP/m3zVdM=; b=GIf/i5oMXhXZtbo6Yx9yznGcp5 B9bCyLHFsloIHg1SNQ7Eq97EE3FGUCE6O5XyHq76nMH8Ix81FRgGSZ/X4MCN4iuGOfIwk90vrSfxB 4w8JzF4GmDQtftl7BSNdC3jrbnc3rIPc/srbHOCOP8KMYJVvjrOvxfuG/HDayeKyMGmo=; 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=oQ5Zt1YdtdqVn4hKEgtMKWZcjMxLtcf92isP/m3zVdM=; b=NDReo0L/9w9BdR6t0Tx0r7j9QK uTmBfwVyCfYgam0uB6fklGakkqkmEuQGuIaZiDQsYRJYPHEvy6djNabN3PNYsl1dz1BFm8qI+5NJ/ 6DmcmYIj/8PGwInZBoZKuWlo5sN3PoKIrX67mAgkDWeNZifm11wF1Cl6zvY4+OJl+nsI=; 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 1xQNVP-000000003En-0r71 for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 11:25:44 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (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 4jNSBk6TVNzFq8X for ; Mon, 09 Nov 2026 12:25:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794223534; 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=oQ5Zt1YdtdqVn4hKEgtMKWZcjMxLtcf92isP/m3zVdM=; b=k9G7QPOTDNPi8SCu7B0W/xxUWGoDplnWAITJmO5UPnHUF5+Uno5MK99Pwo/FIkjmgrb1dB DCK+QfoDnltywtweHhiRfpreUrswFW2Vth0FtxhAcc5rU+39YTYt9372YK4oBeaa9WWz6/ Gl2MjL6y9NMX8JUdVRA8f2IFX2bnjW339mVXKWRnpyKRhnuS/MgLHTOMB3tqwFZDFJWJE/ 4es24tvaBCA/WJRFhCyXX/CWUzcXlET3YVLLvyoCv8FYpP0hhH3HXFUs+5d2A7Pbx0MF/t e2Dn5LND+EZKwd5tbXWJGgiyVDOWzOlMPK8KG+8QpzzjzdcAd7wasQQzesxgiQ== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 12:25:17 +0100 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNSBk6TVNzFq8X 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: 1xQNVP-000000003En-0r71 Subject: [Openvpn-devel] [PATCH ovpn net-next v3 2/8] 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: 1881379753230860787 X-GMAIL-MSGID: 1881379753230860787 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 --- 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 11:25: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: 5614 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp529070lat; Mon, 9 Nov 2026 03:25:50 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHG2BEMDCMq/f3rli4OgPzUDFfzms1hbXi9bVc+7ZXyewbCOaMDtfNZdzZ1qNDt3ZEuRLd6A6j3SWU=@openvpn.net X-Received: by 2002:a05:7023:a5a:b0:195:c6c2:c6b with SMTP id a92af1059eb24-1b39fec217bmr5932223c88.35.1794223549924; Mon, 09 Nov 2026 03:25:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794223549; cv=none; d=google.com; s=arc-20260327; b=TxLXNKEzf+mZiZjIzyzZ44HySwKHbtbt3TXef6n9l7FRBQiBBgDwVRfrGmiBIrLLib p3iz4YF1TtTaW7mk82sO6vaI7+qTc5gfj1L3D5nLnxn+KPZoUFFdpHcNf8aQcGqVGk74 MzykpOH44AoIoj+9GhpbkyNLkPiCU4h6GJKvYqZqOdLceTBcBTAVqG+A0hMEI6b5HB7H c6uN0vT4bBgmnJanZ02WZO7DKDdeRA4a/uYzhKNhqD3qmKs89QoiiHqbLGeCYKCq80n7 F+ZmiGX0dl7O369bFZbQtqCtSPF/L2dhdT3pxTzsB/c68rKec4muzKbEaslCYbLeP5e2 ga+Q== 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=ye2oGGkQcZ06gfpQDwkYJd1BBW9u8k3rucKRjX/p/xY=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=W2a34cMALKH+svATGuvDceAssyVwcF9nV/rGtdgg3LWw09PkvfT48RBlTJ/4vtc3L5 yCZUscGGerMjBqkMrMEaAQSVvnXdkyIH9INBZ//klvmm4ZkpnS+fYO2Bonr5Cjc/th86 j2too/hcsSDG8CUth8liih+Rm5SmOH0CSbquotfPCMIXcd4QYxKDzqheDUYxz8olhdSm N0L6Oblv2Aax1CNrKeoxzRkx/h3puTJdQYGcDwuMJriYsS7DZn5pnOdYS9hMF0PCKhhW eZeW/G3wo22folPUgyjSMJ+4jdXXHFFHh2SlRC+fRb2BfTEeEw6y+pscHsL3vV4d+ypP NbaA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=KmnwfEiD; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=WRvk9iy7; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=DPa3IfVg; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=rHIZcgZ9; 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 a92af1059eb24-1b375618c0dsi12668047c88.20.2026.11.09.03.25.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 03:25:49 -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=KmnwfEiD; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=WRvk9iy7; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=DPa3IfVg; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=rHIZcgZ9; 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=ye2oGGkQcZ06gfpQDwkYJd1BBW9u8k3rucKRjX/p/xY=; b=KmnwfEiDxfRKIT DLZ9gMuZtR96ERcbEvA6y++fSFAeq6tR2QpEOL/e22ZrwiK7LzX49GX+f5cZo3a3xDw/T9tOC5BuR G/m14m+wE9V4sHXlYBbwA9/MF7m5ER5uIqTRI5JsmMiGot96MzAicSJVy/PhZkSITEwxDh1FxRuvk 0oo=; 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 1xQNVS-0000000029D-0TyW; Mon, 09 Nov 2026 11:25:46 +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 1xQNVQ-00000000295-2iKw for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 11:25:45 +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=dqj1MLPJ0rbx2qfmBYFHL0WNbSheJeJ5v4uqqr5NFAc=; b=WRvk9iy7xVXbmUeJjq3xAjps+t QhRiOXHDv3NKwS2NuNOGdMTZRgNkGoJSgc4GP4mtgdnWt3WEONkJkJSYTi+RfMCpgW9csoAacYo7f eH+uKpFpCVjMTQX66obLRV5BT3cc7nPifu05Oig1/AIKo01Ld9usiby4zi4sOl+L3dww=; 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=dqj1MLPJ0rbx2qfmBYFHL0WNbSheJeJ5v4uqqr5NFAc=; b=DPa3IfVg6E90nKuwCPNFkKdgKW YgFyhUeGhJkpVQl/VyIi01FMH4NgQ9Hwy30pCjSHZbncIrcJFLwzx4RsgoFRAWrqzJh3WLzlyveNk oJuc8rjQg6KvES/oI+7UMdUkovy1UvYw/LQK2C8g1t76HpA82NVOMrso2nN1Y/g3v7vM=; Received: from mout-b-106.mailbox.org ([195.10.208.46]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQNVP-000000004rm-0gAg for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 11:25:44 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (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 4jNSBl2H37zNkf5 for ; Mon, 09 Nov 2026 12:25:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794223535; 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=dqj1MLPJ0rbx2qfmBYFHL0WNbSheJeJ5v4uqqr5NFAc=; b=rHIZcgZ9DcFDh+C1JbRe0E8hQaovpy45aAO9StFF20DQKwYRfxo7L1M3g3agpsGXYo8CHp kap+AkrHkGZyUZADm3h9t37bI7L2p2fgZKaGBi+oCR+4V8kGtWHP+/1POucp5jhr/gzerl YNoU7QkEMzDFymyviEniYgpextB5hJE4EgIA1s1qiLOQkiAz0oa6pj/DFpRn+6YMioTmA7 0Yc1FrMSvI011c/Hk8LGSHkN2FBQuAE7vI6tlwKJICoILZ6syLxq5IYzdafJQxnYZAc/YU pDSbSWtV0v0dtYB4iG9ISxBmaWG9zXYcoGGEq3VZ+hBG6SMzaZoFVNUgZaIWug== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 12:25:18 +0100 Message-ID: <2f20065198c3c020b9612b52d5452e8028fbca77.1794223133.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNSBl2H37zNkf5 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: 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_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: 1xQNVP-000000004rm-0gAg Subject: [Openvpn-devel] [PATCH ovpn net-next v3 3/8] 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: 1881379752673883414 X-GMAIL-MSGID: 1881379752673883414 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 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 11:25: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: 5616 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp529078lat; Mon, 9 Nov 2026 03:25:50 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErEdOMqQMWLQwgMGWQ00eEVNbwvd+AGcm31Uny0JHUUv1i56CZ6Gcq6oixpIoClfdXJ22NGLsW9WkYI=@openvpn.net X-Received: by 2002:a05:7300:f48a:b0:36a:1b62:da with SMTP id 5a478bee46e88-3725632241cmr7235510eec.12.1794223550116; Mon, 09 Nov 2026 03:25:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794223550; cv=none; d=google.com; s=arc-20260327; b=jWn2hRAFOiagynMHUwEqzvW2Dr7/1F4ZeONquvEdgm/Tdf3h0bHEKOzWVsPf+yecoX pFmSlhCj+/D22VB1+ZzY2SXdqEewV8qt7+UqpQSl28rd55P9ikulg9o4idjMMTt/cGhA p32iA38sTs07wRQ4Rq5AMgx41hCaEHtgLPTUuYn56/1eKFjqhQEIEw++zk0jmj+H2IoH XzsjUzPqyRZnpYeztfENEkK+q6GPU3bMjfza69Pnz1zxRA0AKyNdmyAn9Hish6BVWVls FDvE+XNbnjheAla+SndtgSP1JWQ80ljr897NYXDdTblGWVj+nxq3GDnottO0NL3OL0yb zNRA== 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=a4ws/NRpKKny0gXw7cJ8nvLi/nuXf4BcHX6Pr6cnYo8=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=ECiajkflQyknjUPMbsftpDR/a4KkBm1m2/IOn1V4siZ8b0/MpUwTYGxO9FHf/GFpfE PvKcBVm/MYXUi9GK3ld+GVmIj8z9Lb3I5CYa2fPU7Yxpzxu/ZOIpZDSXvL1Sd4T9i8ap SnaV6wvWX33Bfihm71wEs9jYbx0D+DSPb5yav20sksAltWO4Ewkh9mIBxkrTz3qCEA30 deBRC3fOY2qh8qLDVRxwZ13SfJFVmaRqh8erZ/Jv8Qm1ifBtwQqXB2Q4JvbGZWxPwgSm ndqH/rRBYdn+GlFLIOPHakyUs+xJTCFo4QyNkZQj/Vy6OLGslrqNB5+yiCMxNxC5SSiY kADg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=cbSW6+MR; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=B3Ir29Zx; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Jw0CBJEh; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=LzrMBtub; 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 5a478bee46e88-372657126b1si13725840eec.22.2026.11.09.03.25.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 03:25:50 -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=cbSW6+MR; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=B3Ir29Zx; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Jw0CBJEh; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=LzrMBtub; 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=a4ws/NRpKKny0gXw7cJ8nvLi/nuXf4BcHX6Pr6cnYo8=; b=cbSW6+MR6B/xyt xV01EVCgx7RzPIfY1RyYE/BCSZdO2GKRDODS1AVgL4vjcNm8fJIKx5GpzOSbAqkJSELpPLKgYmIoL dk/16mjTAgroYRs/nxgGBVGSVHEvmxurex1wlZYX7oeFr/hC8Bd+Svx94dsru2G7Ngnn9MFMdpbL5 B8U=; 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 1xQNVU-000000000Eu-1Wnk; Mon, 09 Nov 2026 11:25:48 +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 1xQNVT-000000000Ee-0Nmt for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 11:25:47 +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=6kKkuLkZCGynnGRhj8a+I9cQev0AfdNSRee++Uaqs9Q=; b=B3Ir29Zx4mapvzYn/iI1tfKwmm bAHlIYxJ5ydwWi7ZlAaZzfKvUpL8eTX0veoppdEo9kZvHMx0nvRzVal8rK5s/k8XQXBawROyAhGH4 Ne9kB7mSzjYNpueG2MVCX0zeydyIuVSou4VXQTENNPxKwTxAbcsxnhWRXLCDaLzfieg4=; 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=6kKkuLkZCGynnGRhj8a+I9cQev0AfdNSRee++Uaqs9Q=; b=Jw0CBJEhNhNbSySFBVh6obg3PI AEpW305QZd+aiGRGJLBVypE21ronYvqyv3mj3LhaII6HD8KMEsFm+LjXmXL/vyiaHTV4IXnKs7Xhd gh9yMnwo3d5k988+tvz1sODLILnqctZDFTCshh+XCvh+Lw5KmIZTIPdlSYE5xMGZBBLM=; 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 1xQNVP-000000004rn-2XDu for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 11:25:47 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (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 4jNSBl5xywzNlcG for ; Mon, 09 Nov 2026 12:25:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794223535; 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=6kKkuLkZCGynnGRhj8a+I9cQev0AfdNSRee++Uaqs9Q=; b=LzrMBtubIfdKMq+dWmUxTQvb2EZGqeZLKozACntE8blDtMRxC1+AeB/Z1us7kOkZqKcL7X 4uWTzzHh5Mdus6HjOH11WDDGEE9J8X3zU8K+N+ZU1e17brMrHGpc8atBHBhbjBrvHRRUxd dHM3ikuwi+SHhezpCCQrv266apjP4wUnMhAEGrKr7P9END8qfa7gWCElFTkJV83IY8N34R 8sboNo2dVmSfb0UlkcTBzcANjp0byKGnR7WfYy3PrieN5ePTE3WHzhQ17jy9X4n5mgpLMt mcoQVGWcVpTq+oohZUpuMcm5FNJk6zO4VL3vBPH0EJvCUr76IoveJ6PyhAkapg== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 12:25:19 +0100 Message-ID: <1533a769382fd369d6f3e839d870f42efd1b4809.1794223133.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNSBl5xywzNlcG 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 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 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: 1xQNVP-000000004rn-2XDu Subject: [Openvpn-devel] [PATCH ovpn net-next v3 4/8] 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: 1881379753492099350 X-GMAIL-MSGID: 1881379753492099350 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 --- 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 11:25: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: 5619 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp529086lat; Mon, 9 Nov 2026 03:25:50 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErGkauo+FSCWKkG/z4v2+MQ1WEICXai0QVrecgOFAjuuvJ09UNLYWB6O36NnDn+EhBWEpJqWPDYSKDo=@openvpn.net X-Received: by 2002:a05:701a:c907:b0:190:8f72:445e with SMTP id a92af1059eb24-1b39fecbe1fmr6066650c88.11.1794223550363; Mon, 09 Nov 2026 03:25:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794223550; cv=none; d=google.com; s=arc-20260327; b=SoR4vNwCkmFNvyTlOUP+SdWrB3k8+MzkX0x5G0xJXPxc3u4P+37x7P9fq3O7xX3Nos Ay9zllFQFeAHR97GVFEVpaGtcwFu/mokdYEk0FSudLGMm5Fm41LVAxAec4H6G3taIyU2 N0U/r0E4SUrNmXn7ibZxFWu8xH0FXFteVrgdKzmGoXv8/EHHXxJbctCGxJkY5lbf90dF 5URWEVSOfXD3Grxe7MxuB3RojAwsoDwCbZk1CqB+HiOChuaNNthqQJJfK8sacML61svL UlclDe6XzxrYnAh5MYUeSim8Vt9AciGcb2ODAdTabzVLb+aCc+UBwVENvZAM5FzphcH4 Bn/A== 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=4Sf53yOWbVrfgBfkMeTvK83skyFncp46w4H1mMdLu+Y=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=V1OQiScXDo770xVG1aHmmsjp6Dex07IpXjO+W8eHyt+qOko7VHOaV3RXziUWcuxKdX iYs/WzYwd4P6h1ynRoEZEDAMSZ4K94iBN6R6Bzl9XM1BAjodcXoJ7OJAXee61O9K2Ez3 wHZl4uQyGshAsrZ5GuxMr/abjxUwjAzMM8Ark6pOGzHd/DkegzwmK5JVU3m6LdJ5mJHS AuDqouwP4Zsw2Q5ABQHU4LdlqRY3isGh1iRxdCOipnY+prb8y3ADqepBRUGWLPc6VcSq 1aSv0TLvDFc6+hr+xnlO9JwORaCI9G+n6AnOjiezsT7bOV8EOOMQjD9Pcyy9ERYpah6p L6DQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=W342sSru; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=DsTdQfJj; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=jMsonx3O; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b="V/06jbBj"; 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 a92af1059eb24-1b3771eb9c9si19224616c88.62.2026.11.09.03.25.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 03:25:50 -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=W342sSru; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=DsTdQfJj; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=jMsonx3O; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b="V/06jbBj"; 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=4Sf53yOWbVrfgBfkMeTvK83skyFncp46w4H1mMdLu+Y=; b=W342sSruk9IiXb CxdoDgKWGwABMyqnO/aqAUnpcEk7WZyRm3qsMFee32Y1rhSdo5LsXmh5yycMNU+D1BsOl6DUEsvjF n28uxKL+y8FVymTLo2WcmEAzKA5HtpyNFdBZp7RmvN4XzwzKRgSCUslUDVzgBRXfEBuEFOaygsnxG 6W8=; 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 1xQNVV-000000007rc-1Jz1; Mon, 09 Nov 2026 11:25:49 +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 1xQNVT-000000007qq-0hhm for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 11:25:47 +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=FcuxmGV8Qk2A8G+gVtr65dcS+BPYv24LZva7opnZvws=; b=DsTdQfJjpDBnaX78lVpgyv/QRI gy+1+MB8iRNnKg6/ApJv7jgHwmjt0H2nNL1QndCklMPXuEom/NsSZKayWccyLsH8vEvO4+8UTAIvL XqJSyR5HJ5DsYVGct8fCuFP5FUVtNW+vR+b2GdLce9cyZ2B/Stwd4LV76GeXaJ5LlY3k=; 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=FcuxmGV8Qk2A8G+gVtr65dcS+BPYv24LZva7opnZvws=; b=jMsonx3OveAhqIt9y7Zb119tGz +j3coXrvpuNCYFOfpVMfRiGMBh94oRoqNqQPFmhgvXuC0YnxbhseSgqFREqNDyNJxvauXF3pXHvcd iJFTmMwvjH85kyWWT6jCKR8xt+qyXveCXJpYvAbd/AkIaJdreUoPaLrnVcTLRYU8xOQU=; Received: from mout-b-112.mailbox.org ([195.10.208.42]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQNVQ-000000003Ep-2Vlp for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 11:25:47 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (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 4jNSBm1rT3z5vPF for ; Mon, 09 Nov 2026 12:25:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794223536; 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=FcuxmGV8Qk2A8G+gVtr65dcS+BPYv24LZva7opnZvws=; b=V/06jbBjJ8BWtU5sBkfYkM7UJHiVJ42KZn+uerHyQ0F5uDPAo7mIvh3y54JlubHP470GSf FCFQ6hWpvo398Y/W3jTGLN+YvIdO+v4CTZg6moyVegbUzP5MLeUY7G0cb8ujrcW+5giz3Y 4Y3DlMOenQEYyoA7aC3+O5+IS6gX4phBeYs9vUvCiSM9hYOsWJgrzYx/ZMATjBmsOP0OLZ 1BdQ275EW6jdvNhqdxx0oo42j1E5iE+iQXV2xiOxaWqbD86oW3FpJdqFP26Lv5k0ddeiPQ Q5rDn5dbdjEGdHwOqpk23ZHqr2GNgNRPfFAh+TwDDOocvJ9V0mZtr7fGTYMyMA== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 12:25:20 +0100 Message-ID: <55ca5e8f9f2fb9939ee28deeb42aa6bd5476a136.1794223133.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNSBm1rT3z5vPF 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: 1xQNVQ-000000003Ep-2Vlp Subject: [Openvpn-devel] [PATCH ovpn net-next v3 5/8] 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: 1881379753333717524 X-GMAIL-MSGID: 1881379753333717524 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 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 | 331 +++++++++++++++++++++++++++------ drivers/net/ovpn/stats.h | 6 +- drivers/net/ovpn/tcp.c | 4 +- drivers/net/ovpn/udp.c | 26 ++- 6 files changed, 393 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..d544ccb24283 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,13 @@ const unsigned char ovpn_keepalive_message[OVPN_KEEPALIVE_SIZE] = { 0x07, 0xed, 0x2d, 0x0a, 0x98, 0x1f, 0xc7, 0x48 }; +/* Leave room for the largest outer network header. The strict inequality in + * is_skb_forwardable also requires staying one byte below gso_max_size. + */ +#define OVPN_UDP_GSO_MAX_PAYLOAD (GSO_LEGACY_MAX_SIZE - \ + sizeof(struct ipv6hdr) - \ + sizeof(struct udphdr) - 1) + /** * ovpn_is_keepalive - check if skb contains a keepalive message * @skb: packet to check @@ -234,43 +243,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 +280,183 @@ 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, 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); + goto err; + } + + /* the encrypted data now lives in the aggregate */ + consume_skb(skb); + offset += len; + } + + 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_copy_hash(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 +468,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 +476,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 +607,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 +636,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,8 +646,9 @@ 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; } @@ -444,10 +664,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 +680,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 11:25: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: 5617 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp529080lat; Mon, 9 Nov 2026 03:25:50 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHEnYW1/gnrej1juUMQjAJ4olPE9VJTJiMUnn/SLkld4EOe42qv10uoBnVFLW+qJunelEDsuZ1bTIU=@openvpn.net X-Received: by 2002:a05:7300:3e93:b0:36a:f99:ae79 with SMTP id 5a478bee46e88-372554755bbmr6894267eec.7.1794223550200; Mon, 09 Nov 2026 03:25:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794223550; cv=none; d=google.com; s=arc-20260327; b=UW9lQy9vu0AMhiQ7uug/++Jdt7NmrdFW2+iBFiX2rrLn6IlipYOPci5haVjeMbauO5 NGSvr0X1/DwjCKLDA4lBTTsHfhzy9zQrHjQvLHNGOuY/dKGTk9lmsFKveBxBVJoctOAW pQJE8kgGrSWmhHA2JHzVD8HldK1puqxaIwukD2HJZUu7piJdRiF3CSsRq9ShysTJuy5k OrI9wY5mxzJrAaJ8+w+hc1G1J3T93AtpBswszKe5xvIgQ1hnAUGFBKjf6B013+z304RY 6Pte31tqmOj3qRlOYeAhP8ww+B2L0pjl69YyjCyXvcHPiQArvNfiSi9D5ngAywuX09kp uH4g== 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=yOtaGmED0Yl7BZpL48+PUhAGw/LQ3RtI2WdK7kVKbq0=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=aPY/2VVCx1mogihz12PTDtHcOXHHz30m4VxLp7yTrsugGFS21SojlBeil4qF/dUp9h Fb9reWyQ0XE76ZWeqk7OpNuHnMNE/Gj21S7k432QSqRRk73RJ5+L0h6R2zZRn5Y7LHpM lAkWfasMMwiX8t3khRavajXpVbCFrYng+Er5UJHyfPcr0BYdbM3ao2ZJXNpYqY+3nbOZ 90uDIyIBI2K0bTXJ1AVSrWNQZBZFFE+/BFcx4l9ce3iSTSAHG1LQlX+W32pqJ25X2PBT J3gTtimXlqWyrGOIE/IHnwznyIwGZ/kqmCmHcVuFW938ijZEBk6RqASC6kXeY7cvEknq m1/g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=IU5qOWPj; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=JBCQTds4; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=d0RnF0xP; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=0xxBbDjU; 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 5a478bee46e88-372662e2351si13510096eec.56.2026.11.09.03.25.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 03:25:50 -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=IU5qOWPj; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=JBCQTds4; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=d0RnF0xP; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=0xxBbDjU; 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=yOtaGmED0Yl7BZpL48+PUhAGw/LQ3RtI2WdK7kVKbq0=; b=IU5qOWPjP0LRLL nSxd9u9xZaRId0kEzpzHsOa/xZIXzjh9R46ZuQsDsnUyPh9ZbXcmtJT68MbU7c3vO4pYGrY10wGpD p53NmUj8PZfk6174POT1xz8lq4oP4eIBOQh6IvPgCpnLvJ+Y2bz6WT4WXOwjOGKIJTFYoT+hdrV6x O6o=; 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 1xQNVU-000000000El-0kGH; Mon, 09 Nov 2026 11:25:48 +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 1xQNVS-000000000EX-1hiD for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 11:25:46 +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=l2kNC0lqxElr7nEL4hdSPF/mD9fpyCR3UgrPxIoTCto=; b=JBCQTds4w7UbKxI5tQDI/eA1uK Bnw/JZyX8XJMoOVvXurQclcICqz1bRwHXw4PDtI2VTnvmNSW0dghgAdFXrfjfy4vg2IN4xnzv4kvJ +oe54KCNhxUlbFNj6PHz0oW3jL/fTelmmLukPAKCs+w5hhtJXRg/oqPFmdSoaeuRJJOo=; 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=l2kNC0lqxElr7nEL4hdSPF/mD9fpyCR3UgrPxIoTCto=; b=d0RnF0xPDRKobqDWFIan0mFTbL aq9S0U9DY/ZhBmJrhnILvk1Ln2MtgeSEnq4QGBB8uu2QJNZ3LH6Kqr/TKXvlhVHhm79rFFX6rclZS tlrHqZPJriDLYPaHhvATdNTrLDcZLjKoiZmDdkSoi53oIR730umYRdrhZg55tPaXHe48=; Received: from mout-b-202.mailbox.org ([195.10.208.62]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQNVQ-000000003Eo-1pzV for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 11:25:46 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (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 4jNSBm3ylPzKnB9 for ; Mon, 09 Nov 2026 12:25:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794223536; 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=l2kNC0lqxElr7nEL4hdSPF/mD9fpyCR3UgrPxIoTCto=; b=0xxBbDjUs7i/QfA20bSfEjv/0KCEFS7dYhZu/BxQTHRibpZvxu/Uk+h1LwoGmEKKbbflRP m12Uk7VocuEw5BBOV9mf48TLjd2stKUrErN313CijrrHmt1CXEI+Wh5sCdoofKL11Q3sjz O5Uuwtu525FCNB7ct/4ojJH64Kxt8VTtwfjHSMPKvwZoq6InbLEklQpdjakxFzkqtvHk5e fqHktHfc8tBhRdNLp+876A1udQ426stOFvMZlm0cTXpkjlhpeK9dMY6dMO4QKHI2ySebPB DNuBUqs+NtgUfdu4aeMmphMg9EO45qsUnYH6pqBaUyCyQIHn4hP0QJD0mqUmsg== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 12:25:21 +0100 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNSBm3ylPzKnB9 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: 1xQNVQ-000000003Eo-1pzV Subject: [Openvpn-devel] [PATCH ovpn net-next v3 6/8] 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: 1881379753610173670 X-GMAIL-MSGID: 1881379753610173670 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 --- 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 d544ccb24283..4caf1837b59e 100644 --- a/drivers/net/ovpn/io.c +++ b/drivers/net/ovpn/io.c @@ -376,20 +376,31 @@ static bool ovpn_encrypt_gso_queue(struct sk_buff_head *skbs, { unsigned int offset = 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); goto err; 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 11:25: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: 5618 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp529082lat; Mon, 9 Nov 2026 03:25:50 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErH4QOhET4kli6qE2h2fF8BNl8N4iq7547ntpetvlleqEHh94SlWfaZvtgIBgZ5dmQzFTO5KPhd22+k=@openvpn.net X-Received: by 2002:a05:701b:42d4:10b0:1a0:5c85:d1b3 with SMTP id a92af1059eb24-1b39feceee1mr6120263c88.43.1794223550350; Mon, 09 Nov 2026 03:25:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794223550; cv=none; d=google.com; s=arc-20260327; b=AqN7OJ3VYbmLL5f+/cttQYwC7C168VeCvtgmce/me2+JYllpY2jzvHbbVIG+eEDhju cpUaRtSf95DBIyMaoNljifSTUGg3vmYj5VpP9howtGqVOUThWeCcFiQSbQF9NxgZreeV jU+8Xg4mE/+fvGBMGHCEswiRyIV1TJHoSZo4bQpnFsJGVSgne9um7aOqFTtOqtfEo6Tf cbVRl69Bz2ssAkWwmUkkDkrqvlhXMSpdxWKaheFbC3DODnW/QMV1mARuK4502YzWL2v8 dFni4ePsCrypkFse2T6Oa17ClQ4pWeaARETzMzzwcxTWdpPzmkwXIz3OVQcxNNhr2PJ5 iakg== 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=r50xbjj1pGZEw4isjq+cX3/K/Kl+Lb353FRLmn58qh0=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=XKWH1aCl2fgHb0QDWySArhZ7By4Hwo2YLpHJipLsJvZrTB7rpRCoi1U7sA8RVS9CU5 EBooO7S+OiqctRrafsk7bnJGht9ofrQSr1jGxtUAMFo1961KrsEEV7huuzLA4WCfuOkb Ve1yBjBwJt8+Fiy0FP+2HikKayXXhFfwBxUfhNuxVYpZlsMZaDwlHvPIyziNwFAMxYj4 oSoNW1BnN+E7NKlVuut/NzdP34Qg4nwuf64PGfXIb4qU3ezjP6We+yuWU2nSnh1BXZAv ckSRKP9iz8x1ZDUYxSLqEJj+uJ2HsOSPSyBYNwj9IAKEkUbKbliiQs7W5BIG0pXVMFwF WttQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=KXgm3SuH; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=ln56DqrK; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=gWqjn90m; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=itsdz3EG; 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 a92af1059eb24-1b3773ea53dsi13479923c88.80.2026.11.09.03.25.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 03:25:50 -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=KXgm3SuH; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=ln56DqrK; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=gWqjn90m; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=itsdz3EG; 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=r50xbjj1pGZEw4isjq+cX3/K/Kl+Lb353FRLmn58qh0=; b=KXgm3SuHovCAJP tdKUOk+w3wryZEk9/XSX2AiPULE/Rq5iLhzVuMk/i49gHw8PcNY40y6KhTB2qxdRjC23bCzQlJz6g YB5qB2/f/O7w7hvxnJUiUpAjujVOtVH/m32M5i700VXzGFXID63Vt5eRiXnWskpw+qKOKjEjZ8lr5 jns=; 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 1xQNVV-000000007rO-0iBF; Mon, 09 Nov 2026 11:25:49 +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 1xQNVS-000000007qf-1iCg for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 11:25:46 +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=f4SnrhR9D2361nQa4fNcldoJKwFCEok70Fp5pR9X97g=; b=ln56DqrKt2+eABefLmOrINxjSS JBdpn8+N9OIxTgn6CXD+DRYEuOJnT5EY2v2rs1WB9OGmT0TdWDG5xeRzcuPjIG7+KPu766n4D2zSl bgUw7RGmogj+cTkBdb3rFWAP2OPsMTScigY1DXJ26Ams3EZFFUS8NhBSd9E/bvww+TzE=; 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=f4SnrhR9D2361nQa4fNcldoJKwFCEok70Fp5pR9X97g=; b=gWqjn90m9vRBJ9FQwrC/EJ+NY3 yk+0sC9m+L/rAl9ZqRVlSV7w1EPOfdDyyocWrF157OAny4Syi/fQYpdZauLADLKzTWx6xerRtOVng B23eDDiewHZy0qmU42dLG7KFwi8tIDDA6OSuOi9jjDxYgrqv/kligxb/M7jeQsQ5VHWI=; Received: from mout-b-203.mailbox.org ([195.10.208.52]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQNVR-000000004rp-0qq3 for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 11:25:46 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA512) (No client certificate requested) by mout-b-203.mailbox.org (Postfix) with ESMTPS id 4jNSBm65h7zLlRt for ; Mon, 09 Nov 2026 12:25:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794223536; 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=f4SnrhR9D2361nQa4fNcldoJKwFCEok70Fp5pR9X97g=; b=itsdz3EGO+tvK0Dwf7xoQ/wO20NOaVh58kNbVIBcQ18A/EhIW4q3XsvPSsGQ9jlj6LprRm OWIVsIkZf/tNFs95nhOlwxXnclBtluq+GKxKyopEmnGcb8gR7itdIC4m9RVymsrdndiMOD VIHsX1hQqcxjHIH+ZejzN1+rKd77DL2G4D05dZwom9nYYM9a0wEJBPixeTkLtGs3RG+WAs 4DqA7s+E9GAqiI0Z+9mdlhL3Z8D1nevXp5V5aVpsq8kWYmIzRPu5HfuOUtyCTPJDQqqb9Y wocVKHJEgv+TZlFFPzb11r4blQDu53RIw6McBz5duj4GfY6EKbPFQgBmsOtsWQ== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 12:25:22 +0100 Message-ID: <62065a69f01a64708cc34e6eeff159bb4bbc5f48.1794223133.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNSBm65h7zLlRt 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: 1xQNVR-000000004rp-0qq3 Subject: [Openvpn-devel] [PATCH ovpn net-next v3 7/8] 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: 1881379753242480941 X-GMAIL-MSGID: 1881379753242480941 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 --- 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 11:25: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: 5620 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp529108lat; Mon, 9 Nov 2026 03:25:51 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErF199vm6lmgca4uxDgIAeMVZe8cR3RdYpr1l3hl656vAlCEQhvxmTTcnrTj7uvj5iHyzf+8sUMtcsc=@openvpn.net X-Received: by 2002:a05:7023:a8d:b0:15c:1679:1cc7 with SMTP id a92af1059eb24-1b39fef9816mr6622706c88.37.1794223551343; Mon, 09 Nov 2026 03:25:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794223551; cv=none; d=google.com; s=arc-20260327; b=URIwBx+SUs2fFKTYzLL6h3WCMYJKtOyIUitdPVgPpAmshnvk4SO910Mhf7dcOlg/CP jzVmZH5WJzciNUFup3BqYww/nYqtIIPUNVOJaFHRLvgInWeUH3ZE9tKMLFXxZqUrm4e3 J6d0oc5G+wyTgFk4SqjVs+ZH8ZAlyluGmvsrmDAVz+T++HAy5VuCwQFD29lPgXo/H0Y9 g7IteUG2mxaf1c/w15hzWPY5D8NZWN7LmLACVK1rl1vRf9+t2fEiLoPT1+xedoo0qRR0 cJFCgwCUPXOGqDbbepV5GXReZ9ok58ig2fJZ/kxEkgPkGYtRaISi+2hfc/KPfIPJtuBz cH6g== 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=5dfvVCTiLqZCc1MSEmOdGQdFPvbk0HKkzsiNvZdEUKw=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=WaC/as/EMtbBbCAHm71kR3AFgY5kd3pv6tmRvbwaty0Kl+xibQbBKWhcb39X0ldDUt pR8vvUtKUJAhU8kFGYCLTveqw89OoTL+r/4R44TTNfEjSP8rbrXeZqqPYfRcvpE8pdFC r3Di63cU5Ml7rGzL6KW4R/nGjxXJpanpWpV5VQhxWnG016WgeM+yKaUdYwmvb7voaxGS //Vh9NAVsycEz2hu95F7M4UBONfHwb2PXdpkvRcR9ScaH4gEXptwoiYDbFjrXFIfQupn eOtK1MesmzD2JdT3l080E0Fg+VTTynR7/0CdsFQNqoMOeQXk4W5CRNMJCYHCEeP7Grfg v+xA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b="hEG95s7/"; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=ifFxB2XN; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=cCK35G4A; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b="LAUzL/t3"; 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 a92af1059eb24-1b3773fb117si18220748c88.94.2026.11.09.03.25.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 03:25:51 -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="hEG95s7/"; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=ifFxB2XN; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=cCK35G4A; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b="LAUzL/t3"; 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=5dfvVCTiLqZCc1MSEmOdGQdFPvbk0HKkzsiNvZdEUKw=; b=hEG95s7/CJqT4g o6q8sM+GYnZY9rhEtVe8/0nJ9W6f3CMkc9WUuBJqfLwDY/xkBRzvOUcLOfh78DXiHTnfpNtBsY+XK iwDer0S09RiWMRuRO4ywxMBC37rQ/ro8XLiofsmyGPLtK6S7QLVNEDexcWcgsKRmJ7sSWJQyZfBrZ OLU=; 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 1xQNVW-0000000029i-1ZY5; Mon, 09 Nov 2026 11:25:50 +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 1xQNVS-0000000029L-49mb for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 11:25:47 +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=PD9n24/M69KubeuTh9zTRMsOrUs+fGxEuQskdm3aspg=; b=ifFxB2XNRs3Eu389egacjj+kRI ym9CEGi1ROQvRTGr0UYjGcRMMv3fPVhNERPlo3j1zxWfOTCg0kVLN363gVNh3Lloj1G1Z0xIJRu9M aCtrql8LjXvtv1Yw2prrHJAia25bXAqCu/hGjpjDz4gbnWbIHwI3YE9Yvl9LWMhXuoEM=; 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=PD9n24/M69KubeuTh9zTRMsOrUs+fGxEuQskdm3aspg=; b=cCK35G4APcW3aqlffkjwc54Eoe E/GEDfwKsbgfINc0upVxiHMOhW2WU/eqwM+bQ4BsbMgzu/oU7fU4cmtp5EUUlfdkiIe4Bjl7R0neq anSd1L0GxTa9xpWhpvj2MWJ4y9nhvYKwcpCjZ4dDJrM768so2kDRu3eRlqcIDzSN68fU=; Received: from mout-b-206.mailbox.org ([195.10.208.51]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQNVQ-000000004ro-28qm for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 11:25:46 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (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 4jNSBn1Pp8zCc for ; Mon, 09 Nov 2026 12:25:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794223537; 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=PD9n24/M69KubeuTh9zTRMsOrUs+fGxEuQskdm3aspg=; b=LAUzL/t372WD4JKfTUM3gw4uxw+YFLk1Ivd9cVoXY+rrmcHyKWCC+3c153Is+Zvdn/SyIe 5Fq1Fum+bw8aEGYYz2LRfRU1cbKQoVVZcARv5r+nciglYkIHjq1MpNq2qrTrJrNVoYWKZE gr96Z6cAQUs5vMYkWekddIFW14AK35NneKtkSgaFAUFv1OlHytzKRsrbU47pwDv0KURCB6 DnofVxLwncMc9y80u7Ck/0mo50ZFSefOD3YaN37crL9Hj+0ghdKaONYJsjjb2XmUVtXFKp uAhikA7E1Jy2gPxw7sNob41jDk/LeKZrXJMy4XffA++LtAMCtTlSnw8+xv37uw== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 12:25:23 +0100 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNSBn1Pp8zCc 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: 1xQNVQ-000000004ro-28qm Subject: [Openvpn-devel] [PATCH ovpn net-next v3 8/8] 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: 1881379754198420395 X-GMAIL-MSGID: 1881379754198420395 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 --- 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 4caf1837b59e..cd50f7c206a6 100644 --- a/drivers/net/ovpn/io.c +++ b/drivers/net/ovpn/io.c @@ -374,30 +374,30 @@ static bool ovpn_encrypt_gso_queue(struct sk_buff_head *skbs, struct sk_buff *batch, unsigned int segments) { + struct ovpn_aead_gso_ctx ctx = { }; unsigned int offset = 0, i, len; 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); @@ -411,9 +411,11 @@ static bool ovpn_encrypt_gso_queue(struct sk_buff_head *skbs, offset += len; } + 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;