From patchwork Mon Nov 9 15:08:59 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5629 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp802989lat; Mon, 9 Nov 2026 07:09:35 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErG/rh5rrYEHwQR2L55oKm9tmiqOyGmjh5cZvV7MbC7/a4I78bfguAa7NwLFBgm3FN5vGdTYY+c4hPI=@openvpn.net X-Received: by 2002:a05:7301:4184:b0:369:d8e1:7bb6 with SMTP id 5a478bee46e88-3725dd5b724mr9764737eec.25.1794236975120; Mon, 09 Nov 2026 07:09:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794236975; cv=none; d=google.com; s=arc-20260327; b=J1fZSMBaNDvgxl+DSw+fi/aqgezUSaUKdqOpalIJ3gposWuWjwiVhbBK8VuKa83Fkd /s/z1pmCZGcXkYqgTS+nQFD0O4jvDfQcPSRZqPkzQCBurkNs8k7AVUnz8ByCbI3P54ij zKIHGtM+p+gezCjghp63265OXbqrRj6YG1jgcjyHFGecWgeYvwI8oXNCtwyFvhqpExGe CDsoonUZdYhFvRMarPJFNHxX/slgHLj/Sw6bvYWPvUXHtFEzh96IBYW9/cBCPglwnc2J +ThChQL2uLXUd+zJ+gr7I7ZQmtuZcx7ZFb0pe5Y0l1wOdfZnrOTCqMFpMN5zKj10M0+u h7mw== 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=SIXYczPTdIitmzjlXxErsLSQ2Mo3GUzDqiadpVUYBOk=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=V/e3F2AAlh+y7bpLpljr98wi4+tnxfm+1nT/thHk4fyWU4wnklGzUlxSzdQ/RXcas/ OuUXo811q5ELJPw7QlbR/dydSeV3Zp4NG0mNMwhS650HUGzSrZ3sMl8UNSAVmCNCadDw gNsLHiaVSYWN2yRuUqRq+/3o7Sh/dTAWo/TkPmfWp+qImr2OBQubThjtCBZYozDKjrP2 e8l/fsBvbjWH+CoCyfWFNo3ut7EFUkMuKDx5IvWpRV/TkZd9+Sb3Qgqn0HTlz2Kb5wsb loYfBT7OtaJO3ehoVgap/N4IvPwSQhyNb+X2PcYPTaNEbzssWrqlhmv9ySRKzleSN4dH oydw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=ex+i+MS6; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="DS/dw1M/"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="b7Ew/dl8"; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=gAh1skH3; 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-372662e5030si15832462eec.62.2026.11.09.07.09.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 07:09:35 -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=ex+i+MS6; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="DS/dw1M/"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="b7Ew/dl8"; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=gAh1skH3; 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=SIXYczPTdIitmzjlXxErsLSQ2Mo3GUzDqiadpVUYBOk=; b=ex+i+MS6L2h106 xYoQdSTEMwq4ukaysyfCmPiFz1TxuC4E4mWYo4wPTtqdjKsx9T/oF/pFRjpxDnXFiiHVuGLjunzeI AqCdwrViwRkWk0vw8TderUUgVn/+dcv2ojp9mNaCH5vPlhluyzdHh7KCvKbbIp4Ty9xCHJy27UBUe 6Ig=; 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 1xQR02-0000000077C-00Qg; Mon, 09 Nov 2026 15:09:34 +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 1xQQzx-0000000076n-3yJN for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:29 +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=DsUvHiZzA0X3d9MB8xLhFqQ6M0QUsqOo7UhbLt7FMEg=; b=DS/dw1M/dVuNayUnFS2E2CbmW/ F+X4z0Flm3ZT6BsqnGgkSFIRUsdGONpGGCUA2hjBf+hCG3s98Lepa0+6y2TqAtAFh36Nn2lAhCdmx OEOL6+J50UR+3z7ExgJ2VVapJfR4G42E1r2rJnjvaqPCRrd5iWFbXebqHfbXRNbTMXg4=; 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=DsUvHiZzA0X3d9MB8xLhFqQ6M0QUsqOo7UhbLt7FMEg=; b=b7Ew/dl82BFliBld9QAI2DXTNf 0opW6a9+T1PfBnA4Ea4s/tF53bPGp4SjZapc3HYEFh2mbD/LDIN3ZblnDov+i+IHj64/bQnmdvJfX hnqJt2x3dYQwDXi3w3lqGWp9t8n5txhpgBxIAswRz7XNUHuKsMiWhoNOUUVpj5JDhaCk=; Received: from mout-b-110.mailbox.org ([195.10.208.55]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQQzu-000000000Ec-1TVq for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:29 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-110.mailbox.org (Postfix) with ESMTPS id 4jNY8s5c77zNlbJ for ; Mon, 09 Nov 2026 16:09:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794236958; 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=DsUvHiZzA0X3d9MB8xLhFqQ6M0QUsqOo7UhbLt7FMEg=; b=gAh1skH3XW8ha7BAhbkIBWyC/EyGXTLe+GuGK4usymDAh1GPzKbZVEERfB7FTEeYAYQbMj nMtkGuT46LM2Nh5LDNw1DJOhyDtH6FU4AAnoUEy5ZEeEBGBMg0HsNQxsf40dDfXZxdM9E7 yIHenU7fe4jIE+HvHIK/TJq2Kw7ZE1LK5ffAozKZb7qgL61lZj2rBlLjo12FUZdVrCLXyX 1vNMm9cHZyM3Pj/TF/+tZjpH+aFGLJOblPndN9lF48JEmbjprmn3LfxCPeJjOaKc4/kdw/ y2Hni4RthwYM/MvnOdIU87Krvf0YD4PUiHJ9bX30ksX3WhPQBLQ6Q7r5i90Ljw== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 16:08:59 +0100 Message-ID: <1025ad1b437a4eb410967703dfd784a4ba8c30f5.1794234673.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNY8s5c77zNlbJ 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: 1xQQzu-000000000Ec-1TVq Subject: [Openvpn-devel] [PATCH ovpn net-next v4 1/9] ovpn: advertise checksum offload for GSO packets X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881393830809521738 X-GMAIL-MSGID: 1881393830809521738 ovpn already advertises software GSO support and segments GSO skbs in its transmit path. However, without checksum offload in the device features, the networking core has to segment GSO packets before they reach ovpn because TCP GSO packets normally carry CHECKSUM_PARTIAL state. Advertise NETIF_F_HW_CSUM so the stack can pass such packets to ovpn. Complete partial checksums after any GSO segmentation and before submitting packets for encryption, since the inner packet checksum can no longer be fixed after the packet has been encrypted. Also pass the ovpn feature set to skb_gso_segment with GSO capabilities masked out: this forces software segmentation, but still lets the segmenter preserve supported non-GSO properties such as non-linear skb data instead of needlessly linearizing. Account peer packet statistics for every segment which survives segmentation rather than once for the original GSO skb. Signed-off-by: Ralf Lici --- No changes since v3 https://lore.kernel.org/openvpn-devel/1025ad1b437a4eb410967703dfd784a4ba8c30f5.1794223133.git.ralf@mandelbit.com/ Changes since v2 https://lore.kernel.org/openvpn-devel/20261102164353.459969-2-ralf@mandelbit.com/ - Account peer packet statistics for every segment which survives GSO segmentation rather than once for the original GSO skb. (Sashiko) No changes since v1 https://lore.kernel.org/openvpn-devel/1bbfde37488ade61928554db3a119525adf7b608.1790843153.git.ralf@mandelbit.com/ drivers/net/ovpn/io.c | 23 ++++++++++++++++++++--- drivers/net/ovpn/main.c | 2 +- drivers/net/ovpn/stats.h | 10 +++++++++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/net/ovpn/io.c b/drivers/net/ovpn/io.c index f14eb4e6c46a..3b0c9b30e879 100644 --- a/drivers/net/ovpn/io.c +++ b/drivers/net/ovpn/io.c @@ -356,6 +356,7 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) struct ovpn_priv *ovpn = netdev_priv(dev); struct sk_buff *segments, *curr, *next; struct sk_buff_head skb_list; + netdev_features_t features; unsigned int tx_bytes = 0; struct ovpn_peer *peer; __be16 proto; @@ -390,8 +391,13 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) skb_dst_drop(skb); if (skb_is_gso(skb)) { - segments = skb_gso_segment(skb, 0); - if (IS_ERR(segments)) { + /* force software segmentation, but keep ovpn's non-GSO feature + * bits so the generated segments can preserve non-linear skb + * data where possible + */ + features = netif_skb_features(skb); + segments = skb_gso_segment(skb, features & ~NETIF_F_GSO_MASK); + if (IS_ERR_OR_NULL(segments)) { ret = PTR_ERR(segments); net_err_ratelimited("%s: cannot segment payload packet: %d\n", netdev_name(dev), ret); @@ -416,6 +422,16 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) continue; } + /* NETIF_F_HW_CSUM requires completing partial checksums */ + if (unlikely(curr->ip_summed == CHECKSUM_PARTIAL && + skb_checksum_help(curr) < 0)) { + net_err_ratelimited("%s: skb_checksum_help failed for payload packet\n", + netdev_name(dev)); + ovpn_dev_dstats_tx_dropped(ovpn->dev); + kfree_skb(curr); + continue; + } + /* only count what we actually send */ tx_bytes += curr->len; __skb_queue_tail(&skb_list, curr); @@ -430,7 +446,8 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) } skb_list.prev->next = NULL; - ovpn_peer_stats_increment_tx(&peer->vpn_stats, tx_bytes); + ovpn_peer_stats_add_tx(&peer->vpn_stats, tx_bytes, + skb_queue_len(&skb_list)); ovpn_send(ovpn, skb_list.next, peer); return NETDEV_TX_OK; diff --git a/drivers/net/ovpn/main.c b/drivers/net/ovpn/main.c index 0708249e9607..28e1eb06e127 100644 --- a/drivers/net/ovpn/main.c +++ b/drivers/net/ovpn/main.c @@ -157,7 +157,7 @@ static const struct ethtool_ops ovpn_ethtool_ops = { static void ovpn_setup(struct net_device *dev) { - netdev_features_t feat = NETIF_F_SG | NETIF_F_GSO | + netdev_features_t feat = NETIF_F_HW_CSUM | NETIF_F_SG | NETIF_F_GSO | NETIF_F_GSO_SOFTWARE | NETIF_F_HIGHDMA; dev->needs_free_netdev = true; diff --git a/drivers/net/ovpn/stats.h b/drivers/net/ovpn/stats.h index 3a45b97c0056..9331f5e9179b 100644 --- a/drivers/net/ovpn/stats.h +++ b/drivers/net/ovpn/stats.h @@ -40,10 +40,18 @@ static inline void ovpn_peer_stats_increment_rx(struct ovpn_peer_stats *stats, ovpn_peer_stats_increment(&stats->rx, n); } +static inline void ovpn_peer_stats_add_tx(struct ovpn_peer_stats *stats, + const unsigned int bytes, + unsigned int packets) +{ + atomic64_add(bytes, &stats->tx.bytes); + atomic64_add(packets, &stats->tx.packets); +} + static inline void ovpn_peer_stats_increment_tx(struct ovpn_peer_stats *stats, const unsigned int n) { - ovpn_peer_stats_increment(&stats->tx, n); + ovpn_peer_stats_add_tx(stats, n, 1); } static inline void ovpn_dev_dstats_tx_dropped(struct net_device *dev) From patchwork Mon Nov 9 15:09:00 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5622 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp802949lat; Mon, 9 Nov 2026 07:09:34 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErEpTN50F1MPTF289e1qDsUNGaEprlRD65ZwOj4GijW13dAnCvky+5mj5Bve19x+pMycEhO8+w9fBIQ=@openvpn.net X-Received: by 2002:a05:701b:2618:b0:1b2:559b:67ed with SMTP id a92af1059eb24-1b39feaecc0mr5723712c88.26.1794236974221; Mon, 09 Nov 2026 07:09:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794236974; cv=none; d=google.com; s=arc-20260327; b=fS2wr7UHju1iJeQDCB5j//cJBXciMIUJRTO3FbIXZ68/z15mJxyPXOzfOiUXXXtdeA qeeZXjJ3MIEfPHCt8vvq++GwBGM8SArKNVtSVAgwCI3VpcJgQDW17NvvyW58J5S/u4qy w/d4wurPGDifkOh3dh27R7RVyolMwXOMgtYarI/QeauHDWgxYeGgB4ZYgo1IBJj1CZXF LSfbL5tVUJa19R9UaJuXcglJGHFeY2PHSgAITzA7g5HJ8xAsl2jsEqvNzWHcXKeD2XcY ZPcIrwyBIdJBSLLM1rzEhOTY3QMsoR3KCDVKty8W8zOu9WqvfJS/6kxVjqUZJtDUr295 4Zig== 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=odlpY7JwXfEGYJJMlybtC2ECDkb6df8Y3E8LQzRPdYo=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=HE20OBpvG5GKAEJM7x/4hBj62NpalV5SrjCMg7A5t310c3ZghVo/1L6St7TWM8xP/s 0h/JokpISaqQHhGtlhVGXWR87NuGDsQtupNfVE4Ym9Rhi130QOFeTsbirV85wKpFsuIH grSkMw32qoW9yGafRrXA/xN6w0YcP2EmQC39b/3+R3yzuiKAmlkGVDdyNq89qpD32pIb 9j4lsvXt7kw2/g2FYui+otL/YNZc8//cFf7S07b2l1grV7XUq/ntkS1flb4eseuVdSOZ DvCkoeY8EsqHBrbfGzRapbALYKHw0lMF1hj8r0yr8zbZBNzeswG3aHjRr0hIioQnrAnH UElQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=KIm0s04b; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=d0hMI8ia; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=eA7MYSIx; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b="OH/xkFJk"; 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-1b3752c3f2esi14807658c88.5.2026.11.09.07.09.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 07:09:34 -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=KIm0s04b; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=d0hMI8ia; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=eA7MYSIx; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b="OH/xkFJk"; 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=odlpY7JwXfEGYJJMlybtC2ECDkb6df8Y3E8LQzRPdYo=; b=KIm0s04b/ZsbEf 9MZJy2wE4IgoU/o3tNFou7y7zLs5kK+f3S7D0imsVti/D6uJ3zP697d8de8jibEBzk8uA+7YXvm3p wfZpsBkmgKaoxfp49vAuAvKa9uipx5psAxuuX3oeoB5FzbfdjbG9u773dRV+iE5SMCcvBUmDWPHIV fMY=; 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 1xQQzz-000000006HI-1myf; Mon, 09 Nov 2026 15:09:31 +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 1xQQzw-000000006H1-46bV for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:28 +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=3q7N4wO4Je0A/m5UkoGIPDRwnmB52vnHgiQtYTDrKGg=; b=d0hMI8ia/9L7q9O15f+u2xO0GP 8CWahyGPoR9j9ovcgaYxehdK6ng5OgDCK95lLyXqWuF2ptLl0WS8le8LC+4l8rMZfM9+6/X6Iip0u k5DAgmtl8xC+wiEPPJz0yPFCDMIoIIoIN15Gl9jBvHIh2sjT2pseUbJ1pArgrJB9vMxk=; 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=3q7N4wO4Je0A/m5UkoGIPDRwnmB52vnHgiQtYTDrKGg=; b=eA7MYSIxCXKWsSnJbIaOjgucts EfzwJ28I1ZqVFANwkmQm/KG0UjVEyxVo/aqQwt/DWYP1LIcCO9FUpEs7roZj7VNGdrpKqKBiBaNrh 7wU+IraUPVI2IMrGn+/6GUh4zdMf5mmBs+vTC0L75wThpQZ7UT4Jo7DO0qxuW8fuN2sM=; 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 1xQQzu-000000000En-2mdK for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:28 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-202.mailbox.org (Postfix) with ESMTPS id 4jNY8t2TZ7zKnTh for ; Mon, 09 Nov 2026 16:09:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794236959; 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=3q7N4wO4Je0A/m5UkoGIPDRwnmB52vnHgiQtYTDrKGg=; b=OH/xkFJkOaHBVb/ZXowq1ceNbZD2vvu3yHeXu6kDtbQwojjgDUQEW2dEW0uW6+s+j56v0w B9cFT3LmwkArdbPfXoHRjXdtZXBEOc89Ac1x1vKNrNLt9TfgE01Wr2C77w4TDTQnhVJCVz WQdusLLtlMQLZZ5jjQY/MiaOeLFpXUoSyuyxoOxYvAwoDP7l+qXwTXg2VZVvti9qc/YVDT hX6Q+cYOYQLG/QVf2UNdxaUNw50ihRKMEQJJ2fDuM2lomUz4Zza5b+r7L75T+y5R7PTpYY xUbhJV92m2b+BljYrY537zhR/NOP8OPtKBzkLqpi1+LEsj2mXW7747LS+9F3bw== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 16:09:00 +0100 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNY8t2TZ7zKnTh 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: 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 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: 1xQQzu-000000000En-2mdK Subject: [Openvpn-devel] [PATCH ovpn net-next v4 2/9] ovpn: accept frag-list GSO input X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881393829637156061 X-GMAIL-MSGID: 1881393829637156061 Forwarded TCP traffic can be coalesced into SKB_GSO_FRAGLIST when the receiving host has no local TCP socket for the flow. Although ovpn segments every GSO input itself, it does not advertise NETIF_F_FRAGLIST, so generic transmit validation segments these aggregates before calling ovpn_net_xmit. That segmentation is functionally correct, but causes ovpn_net_xmit to be invoked separately for every resulting packet. Advertise frag-list storage so ovpn receives the aggregate intact and performs protocol validation and destination-to-peer lookup once before segmenting it. Frag-list GSO segmentation recovers the complete child skbs, which can then be encrypted in place and transmitted independently. The feature also admits non-GSO frag lists, which describe one packet split across several skbs. Let skb_cow_data preserve small lists directly. If a list exceeds the AEAD scatterlist limit, linearize it and continue rather than rejecting an otherwise valid packet. Signed-off-by: Ralf Lici --- No changes since v3 https://lore.kernel.org/openvpn-devel/d9c14824ec8786328076546ede61c98e21cf88ed.1794223133.git.ralf@mandelbit.com/ Changes since v2 https://lore.kernel.org/openvpn-devel/20261102164353.459969-3-ralf@mandelbit.com/ - Update the commit message now that fixed-size frag-list GSO input can use the UDP GSO output path. No changes since v1 https://lore.kernel.org/openvpn-devel/5baa1d94e29e7b109ffd412b4f1d5d113a319389.1790843153.git.ralf@mandelbit.com/ drivers/net/ovpn/crypto_aead.c | 8 ++++++-- drivers/net/ovpn/main.c | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index 74eaf6fac2f5..2af493fd5735 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -168,8 +168,12 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, if (unlikely(nfrags < 0)) return nfrags; - if (unlikely(nfrags + 2 > (MAX_SKB_FRAGS + 2))) - return -ENOSPC; + if (unlikely(nfrags > MAX_SKB_FRAGS)) { + ret = skb_linearize(skb); + if (unlikely(ret)) + return ret; + nfrags = 1; + } /* allocate temporary memory for iv, sg and req */ tmp = kmalloc(ovpn_aead_crypto_tmp_size(ks->encrypt, nfrags), diff --git a/drivers/net/ovpn/main.c b/drivers/net/ovpn/main.c index 28e1eb06e127..ac4e0d85e215 100644 --- a/drivers/net/ovpn/main.c +++ b/drivers/net/ovpn/main.c @@ -158,7 +158,8 @@ static const struct ethtool_ops ovpn_ethtool_ops = { static void ovpn_setup(struct net_device *dev) { netdev_features_t feat = NETIF_F_HW_CSUM | NETIF_F_SG | NETIF_F_GSO | - NETIF_F_GSO_SOFTWARE | NETIF_F_HIGHDMA; + NETIF_F_GSO_SOFTWARE | NETIF_F_FRAGLIST | + NETIF_F_HIGHDMA; dev->needs_free_netdev = true; From patchwork Mon Nov 9 15:09:01 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5630 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp805857lat; Mon, 9 Nov 2026 07:11:28 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErH3k92V2lT+2xXJa3wFhj+cr3FR18NsmT6M3Z+kLtUzMjCGasOM+Hl5lkjuZzYR6q2GAiZekjWdlNw=@openvpn.net X-Received: by 2002:a05:7023:903:b0:1ab:de8b:5f0f with SMTP id a92af1059eb24-1b39fecc2efmr7844309c88.40.1794236974388; Mon, 09 Nov 2026 07:09:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794236974; cv=none; d=google.com; s=arc-20260327; b=hibl2fS6e3fPIH79yPqc5K7kg0OxteCXOKFskWKrP/knLJsS47+mfFGJS8glqAnXar VG8M+djl7UhGnlmoTHlgFythXC11TnakG16z5NvZo0L35sHr26ba/DHgkPJuU7ExMXRl tU/clTuwZUmCIYnPgJPuenD4Z7NCin2dQzQKudPNnt3h8hO8SbVfwALfynEgr8kNyjky u7a8HPKWQKJ1U+EQ5I6tQCncxk3yo71aWuATfud1jwrdOJz5NraW1EU7pQLZrKUCxIjO Saz+IYzaXkNBRVRdqfSyWz7m7XMk8JA5s3QMdwUi9Ee5IsEGaPI0LL7E1oUXTa6jiwAB tygg== 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=eFcFZP6PEWMYnNagD34oHmHiEQ8/cUfxxt378T6VuR8=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=YtJkJ7NahuQfdnq+13MrDezNsM+bC/NqvGC8qH5XJpjOmWmClf+MPRwQ3bJyFxnCmY 311BWozZPLR9NmoIF2+SZ60iuaQFAaaKhnxWhfqbsOXp9UPqw7jsn/BOIePrW4m79cwr 6hiJkF/iHVJluxHbzz54J8fGCT3NwxqZg57G5mPtPQ4+ECWu06s2i8/ZmTrc/oErd0oK 5ExFM55CnxpL9uG1aXIyQv92OxUO/qEAz7KoMR3Uha2yM0Tj0DEop60C6M0InifvCRQ6 pb3GDTzsgHgwJJqU5Hhmjh3J6b1C1qhp065hepKUt+MnlGGdE5EPu2gwEir0mz4ikkZu A7GA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=m8q0dZqS; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="W/I/Rn1h"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=IJET5EjT; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=j2SK6PXr; 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-1b375727088si14890117c88.38.2026.11.09.07.09.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 07:09:34 -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=m8q0dZqS; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="W/I/Rn1h"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=IJET5EjT; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=j2SK6PXr; 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=eFcFZP6PEWMYnNagD34oHmHiEQ8/cUfxxt378T6VuR8=; b=m8q0dZqSKCiHBa McJfaBhTnyJbRpEUt4978jzZroo3KvE7AxBd/cIWumVOWE3H2DL7BlpyLmOjutRN+kPNdrsZS8iQk 79jGva1F+lH5txINNpljFxHYOrkIOkXVI4/sQ271kGnGUnzK2W+XQmjCsnsNkRtUFNTIBeKyEIKzx zDA=; 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 1xQQzy-000000007mT-1njo; Mon, 09 Nov 2026 15:09:30 +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 1xQQzw-000000007mF-272E for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:28 +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=OSH5Sn/CGXTgNt4y/MmtS3tGaMleXr/Ex8KIwZGrEc8=; b=W/I/Rn1h/BcoMnb6ne2dfMLE4q YKWxWVELDkBFfK6UZQ1La4n3dnfDGqbbC3iRDS7onW3B8ZJ3d1c1hj5g11ts/U260gWyiCNcfbYuu KzbnVjM/PNMo+2JlCYXZV2/6wE7GiWUVHvAn/9+7RVguGBWtsTLYuHumayKH7o90hnDE=; 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=OSH5Sn/CGXTgNt4y/MmtS3tGaMleXr/Ex8KIwZGrEc8=; b=IJET5EjTn+o2jF8KqXIeXiudeH +lXHDWA3a+wGbk72WVlqfSqDrRVkpeV/Ph1jAaGPQDYxsreAYByjKra49Eu7V4EHUQzmX5g/I0kfL xbhDUe6hr2PCk+5Ra3WxwrkqnNKH+cqTOVsxUXT9G2g+J5OrmjJ0ttO2ZQSMgEzlwpjA=; 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 1xQQzv-000000001VF-06Uo for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:28 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA512) (No client certificate requested) by mout-b-203.mailbox.org (Postfix) with ESMTPS id 4jNY8t4Mg8zLlrM for ; Mon, 09 Nov 2026 16:09:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794236958; 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=OSH5Sn/CGXTgNt4y/MmtS3tGaMleXr/Ex8KIwZGrEc8=; b=j2SK6PXr5+dkluuPUULGYvujm9H2SVtgPdyM6SKOMpCuzserM7gVsRvGtrpY8x40rj3/fc 9TJ4Uhf5O1cBNzyc1UZ4pBc14KFD4d2lSb6XEHtDyXEGvHKkLOV9iZEnwxAF7Sv3ZKmdfZ 98gMH7Ss+pMPRF8Z5NbDMfuUpvUjm4s5ifjhBY3Y8WwDOq7f+hng4eXDzgJ6wTYaPYqQM8 3yqhFkCDDCTmOXfRUNrgkk8nPs4cLJSU/mkNIPqtarJmiCcvoSoRkc5k5N1STt68go4iZz eaGjHyzixt5YR+g6bMXtIh54u6ertL4LjPfDjz8DiLInIqqJd03Sofyjlsb9ZA== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 16:09:01 +0100 Message-ID: <2f20065198c3c020b9612b52d5452e8028fbca77.1794234673.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNY8t4Mg8zLlrM X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-2.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Move DATA_V2 framing sizes to the protocol header and factor request allocation and header construction into helpers. This prepares the transmit path for an out-of-place encryption destination without [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-Headers-End: 1xQQzv-000000001VF-06Uo Subject: [Openvpn-devel] [PATCH ovpn net-next v4 3/9] ovpn: refactor AEAD encryption helpers X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881393829385584135 X-GMAIL-MSGID: 1881393829385584135 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 v3 https://lore.kernel.org/openvpn-devel/2f20065198c3c020b9612b52d5452e8028fbca77.1794223133.git.ralf@mandelbit.com/ No changes since v2 https://lore.kernel.org/openvpn-devel/20261102164353.459969-4-ralf@mandelbit.com/ No changes since v1 https://lore.kernel.org/openvpn-devel/f075b9782b14d64756c84e132c138482f08287b9.1790843153.git.ralf@mandelbit.com/ drivers/net/ovpn/crypto_aead.c | 97 ++++++++++++++++++++-------------- drivers/net/ovpn/io.h | 3 +- drivers/net/ovpn/proto.h | 4 ++ 3 files changed, 63 insertions(+), 41 deletions(-) diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index 2af493fd5735..30299581422d 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -24,9 +24,6 @@ #include "proto.h" #include "skb.h" -#define OVPN_AUTH_TAG_SIZE 16 -#define OVPN_AAD_SIZE (OVPN_OPCODE_SIZE + OVPN_NONCE_WIRE_SIZE) - #define ALG_NAME_AES "gcm(aes)" #define ALG_NAME_CHACHAPOLY "rfc7539(chacha20,poly1305)" @@ -42,7 +39,7 @@ static int ovpn_aead_encap_overhead(const struct ovpn_crypto_key_slot *ks) * an AEAD request structure with extra space for SG * and IV. * @tfm: the AEAD cipher handle - * @nfrags: the number of fragments in the skb + * @nents: the number of scatterlist entries * * This function calculates the size of a contiguous memory block that includes * the initialization vector (IV), the AEAD request, and an array of scatterlist @@ -54,7 +51,7 @@ static int ovpn_aead_encap_overhead(const struct ovpn_crypto_key_slot *ks) * Return: the size of the temporary memory that needs to be allocated */ static unsigned int ovpn_aead_crypto_tmp_size(struct crypto_aead *tfm, - const unsigned int nfrags) + const unsigned int nents) { unsigned int len = OVPN_NONCE_SIZE; @@ -70,8 +67,8 @@ static unsigned int ovpn_aead_crypto_tmp_size(struct crypto_aead *tfm, /* round up to the next multiple of the scatterlist alignment */ len = ALIGN(len, __alignof__(struct scatterlist)); - /* add enough space for nfrags + 2 scatterlist entries */ - len += array_size(sizeof(struct scatterlist), nfrags + 2); + /* add enough space for the scatterlist entries */ + len += array_size(sizeof(struct scatterlist), nents); return len; } @@ -135,6 +132,53 @@ static struct scatterlist *ovpn_aead_crypto_req_sg(struct crypto_aead *aead, __alignof__(struct scatterlist)); } +static struct aead_request *ovpn_aead_request_alloc(struct crypto_aead *aead, + struct sk_buff *skb, + unsigned int nents, u8 **iv) +{ + struct aead_request *req; + void *tmp; + + /* allocate IV, request and scatterlist entries in one block */ + tmp = kmalloc(ovpn_aead_crypto_tmp_size(aead, nents), GFP_ATOMIC); + if (unlikely(!tmp)) + return ERR_PTR(-ENOMEM); + + ovpn_skb_cb(skb)->crypto_tmp = tmp; + *iv = ovpn_aead_crypto_tmp_iv(aead, tmp); + req = ovpn_aead_crypto_tmp_req(aead, *iv); + + return req; +} + +static int ovpn_aead_encrypt_header(struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, + u8 *iv, u8 *data) +{ + u32 pktid, op; + int ret; + + /* obtain packet ID, which is used both as a first + * 4 bytes of nonce and last 4 bytes of associated data. + */ + ret = ovpn_pktid_xmit_next(&ks->pid_xmit, &pktid); + if (unlikely(ret < 0)) + return ret; + + /* concat 4 bytes packet id and 8 bytes nonce tail into 12 bytes + * nonce + */ + ovpn_pktid_aead_write(pktid, ks->nonce_tail_xmit, iv); + + /* add the packet opcode and wire nonce as associated data */ + op = ovpn_opcode_compose(OVPN_DATA_V2, ks->key_id, peer->tx_id); + BUILD_BUG_ON(sizeof(op) != OVPN_OPCODE_SIZE); + *(__force __be32 *)data = htonl(op); + memcpy(data + OVPN_OPCODE_SIZE, iv, OVPN_NONCE_WIRE_SIZE); + + return 0; +} + int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb) { @@ -143,8 +187,6 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *trailer; struct scatterlist *sg; int nfrags, ret; - u32 pktid, op; - void *tmp; u8 *iv; ovpn_skb_cb(skb)->peer = peer; @@ -175,16 +217,9 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, nfrags = 1; } - /* allocate temporary memory for iv, sg and req */ - tmp = kmalloc(ovpn_aead_crypto_tmp_size(ks->encrypt, nfrags), - GFP_ATOMIC); - if (unlikely(!tmp)) - return -ENOMEM; - - ovpn_skb_cb(skb)->crypto_tmp = tmp; - - iv = ovpn_aead_crypto_tmp_iv(ks->encrypt, tmp); - req = ovpn_aead_crypto_tmp_req(ks->encrypt, iv); + req = ovpn_aead_request_alloc(ks->encrypt, skb, nfrags + 2, &iv); + if (IS_ERR(req)) + return PTR_ERR(req); sg = ovpn_aead_crypto_req_sg(ks->encrypt, req); /* sg table: @@ -206,28 +241,12 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, __skb_push(skb, tag_size); sg_set_buf(sg + ret + 1, skb->data, tag_size); - /* obtain packet ID, which is used both as a first - * 4 bytes of nonce and last 4 bytes of associated data. - */ - ret = ovpn_pktid_xmit_next(&ks->pid_xmit, &pktid); + /* make space for the additional data and push it to the front */ + __skb_push(skb, OVPN_AAD_SIZE); + ret = ovpn_aead_encrypt_header(peer, ks, iv, skb->data); if (unlikely(ret < 0)) return ret; - /* concat 4 bytes packet id and 8 bytes nonce tail into 12 bytes - * nonce - */ - ovpn_pktid_aead_write(pktid, ks->nonce_tail_xmit, iv); - - /* make space for packet id and push it to the front */ - __skb_push(skb, OVPN_NONCE_WIRE_SIZE); - memcpy(skb->data, iv, OVPN_NONCE_WIRE_SIZE); - - /* add packet op as head of additional data */ - op = ovpn_opcode_compose(OVPN_DATA_V2, ks->key_id, peer->tx_id); - __skb_push(skb, OVPN_OPCODE_SIZE); - BUILD_BUG_ON(sizeof(op) != OVPN_OPCODE_SIZE); - *((__force __be32 *)skb->data) = htonl(op); - /* AEAD Additional data */ sg_set_buf(sg, skb->data, OVPN_AAD_SIZE); @@ -281,7 +300,7 @@ int ovpn_aead_decrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, return -ENOSPC; /* allocate temporary memory for iv, sg and req */ - tmp = kmalloc(ovpn_aead_crypto_tmp_size(ks->decrypt, nfrags), + tmp = kmalloc(ovpn_aead_crypto_tmp_size(ks->decrypt, nfrags + 2), GFP_ATOMIC); if (unlikely(!tmp)) return -ENOMEM; diff --git a/drivers/net/ovpn/io.h b/drivers/net/ovpn/io.h index db9e10f9077c..1a94f0fda1d1 100644 --- a/drivers/net/ovpn/io.h +++ b/drivers/net/ovpn/io.h @@ -11,8 +11,7 @@ #define _NET_OVPN_OVPN_H_ /* DATA_V2 header size with AEAD encryption */ -#define OVPN_HEAD_ROOM (OVPN_OPCODE_SIZE + OVPN_NONCE_WIRE_SIZE + \ - 16 /* AEAD TAG length */ + \ +#define OVPN_HEAD_ROOM (OVPN_DATA_V2_OVERHEAD + \ max(sizeof(struct udphdr), sizeof(struct tcphdr)) +\ max(sizeof(struct ipv6hdr), sizeof(struct iphdr))) diff --git a/drivers/net/ovpn/proto.h b/drivers/net/ovpn/proto.h index b7d285b4d9c1..f3b305cbefe5 100644 --- a/drivers/net/ovpn/proto.h +++ b/drivers/net/ovpn/proto.h @@ -39,6 +39,10 @@ #define OVPN_NONCE_WIRE_SIZE (OVPN_NONCE_SIZE - OVPN_NONCE_TAIL_SIZE) #define OVPN_OPCODE_SIZE 4 /* DATA_V2 opcode size */ +#define OVPN_AUTH_TAG_SIZE 16 +#define OVPN_AAD_SIZE (OVPN_OPCODE_SIZE + \ + OVPN_NONCE_WIRE_SIZE) +#define OVPN_DATA_V2_OVERHEAD (OVPN_AAD_SIZE + OVPN_AUTH_TAG_SIZE) #define OVPN_OPCODE_KEYID_MASK 0x07000000 #define OVPN_OPCODE_PKTTYPE_MASK 0xF8000000 #define OVPN_OPCODE_PEERID_MASK 0x00FFFFFF From patchwork Mon Nov 9 15:09:02 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5623 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp802953lat; Mon, 9 Nov 2026 07:09:34 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErEmkz9fXwCtC96fGS8/rbwyBGkMTLQ2dYarB/7Q3a1Wr90y5uAMpjLYd0UQ3LxLLNnUjBc4eO3J2xg=@openvpn.net X-Received: by 2002:a05:693c:80dc:b0:372:601a:6278 with SMTP id 5a478bee46e88-372601a632bmr8111574eec.33.1794236974231; Mon, 09 Nov 2026 07:09:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794236974; cv=none; d=google.com; s=arc-20260327; b=SSrn04eBDEeyO0lDulPaQIF0o1YXW9VtiYCQghEutl8Gy0tOlOsZLCx2rxqDN5Lsw1 HexQZdL6A2oBpSmpFOVgqXCUKqKHfctk6UzetWpeOjJtqHR7Ap5yCcPP+ZweWQXOKQfi CZHwKKPzyvsTh9SxiQZyp3wa6oQTI+Zvl30RCXVcaU/VzrtTcMuBELpTdt6/OdYqHZOJ yhfcqkDu+HOG6+0tGL226JCSdpe41UTMTj6+Q4oYWyYCMTDoQXbd2oyWSCO2N4N8qAK2 Oo22PaBlXgIuL+7z2ozknLWiNCgiWCMFCfTLHUDtOmqAPD3XJmBgy74Yuv6RS1oK3LSr VrgQ== 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=XoFwCjoWgDpOHTgXyiq+FNFAdrI/y7uPXK856FbJJ7o=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=VgHeVHlSUq4CcQ69/3jD9Cx2XFZHPv06wuXcJZUmbFMnvchyOShKvHyUya9HF5eNh0 ivwzUBxR90nQKK1gFcR2F1jL72yDqTiR5bwruL+PMHk3fTa612h1bE9VNHFruKVlef+y 58vuGYduKeI9wp3fY7GHQ1LNYmQRWmY5tUVmfyRU/HMWKuSWlO+8yHkPbJUGnF+tvWMU +Nvl0mqvdPxDHIlLHSHoCb5NZ1Q+3YXPf+gYJSHXI6q4bGJX9EFyk6oOekmVb47hiEd4 bJoCb3lDCrMFHur965V2la/2Zne8baRrSkgN5tapZKShWHmgTw030hDiCOYouSdarMGp MamA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=Z5j22aRZ; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Io2IexEQ; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="EA/MlCNB"; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=LnWoQXdV; 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-37266bcbd69si13903058eec.80.2026.11.09.07.09.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 07:09:34 -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=Z5j22aRZ; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Io2IexEQ; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="EA/MlCNB"; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=LnWoQXdV; 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=XoFwCjoWgDpOHTgXyiq+FNFAdrI/y7uPXK856FbJJ7o=; b=Z5j22aRZPBsAsq WaIZHjQJ16hRymEAzmiQ4BL1+Rq/kKkwRXB5THerVfxzbZoMCX/gQXnZr+mi9ytLBLpx4jQqMJT2T pL31ZugUkQYKhYAVnPZXmodyRkrPrZJ3zhEQGYms8xLh0RDG2aaxXi/+NpdrPUMkq8o7Lz+Pzezpe Fck=; 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 1xQQzy-0000000076v-3QlP; Mon, 09 Nov 2026 15:09:30 +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 1xQQzw-0000000076f-2dHU for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:28 +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=PO82ieRgqZM5Ro5q9/54BT5ufq6qtRF29d2pxlBvaoc=; b=Io2IexEQ3TSkK4+iR/ic7nqysG kpHKRd6MD4XriRLdW/aUnDKQ79ZTvTF9OQFRfnw6a2T8Ze4uAauTWgh5OTzqQ5rdAF0ZCXczJ21H9 75PTYgokDFTOnmpaNwL+8RqQknjvuP8JkrACF9VdS7YXyqksVs0oXRNYOiVP8CHIWOTo=; 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=PO82ieRgqZM5Ro5q9/54BT5ufq6qtRF29d2pxlBvaoc=; b=EA/MlCNBz1c7j2FqekjRtKJhSV WhdJq70lL4khRJg7YvCbtT5w0wL5yFNEk7Un0AiIOsrU+0ayJjY2lDbLwO8z7XMVwFjk5V0X+DJX0 d6YRnQgCTVkinQB1esXefst8fvAkA29V2uu3lErRrPX7j+YUQ2XhlVqN7TeupQNX5SRI=; 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 1xQQzv-000000000Eo-0NxD for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:28 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-210.mailbox.org (Postfix) with ESMTPS id 4jNY8t67dGzFqrD for ; Mon, 09 Nov 2026 16:09:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794236958; 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=PO82ieRgqZM5Ro5q9/54BT5ufq6qtRF29d2pxlBvaoc=; b=LnWoQXdV+DiY3hSrfyYapuBZWPlm5DAAbLkNyQfOjR+EQTW50KGScz4qNgqx/1GWDzQlEh nTeWzL9gsEYPQ/b7djldxgcFqAKoaqqCQoD1kzsipSl6LQ3MxDYDAvjyjH5ztxDqXrxrSd 0QdRL5cwUZ6F0IJzLNT9Icuj5TOZNm237/Og9Wb38T6OBkORK2M1Z843i6DOyO3JEMmYeU zfALJsnsmLVDpryZmpm7rL0awvLQ08yhm9Fp9rI3hftKshLEkLR1T9xaIGjwW5P0mVdCI4 1aTpOG5P/y13L0atoMeE/PN2ldfsbz+tizu7/eLxu2pkcuCEYKBH6pSpFPxkxw== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 16:09:02 +0100 Message-ID: <1533a769382fd369d6f3e839d870f42efd1b4809.1794234673.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNY8t67dGzFqrD X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The UDP GSO output path introduced next requires a synchronous encrypt transform. Record the transform type in the immutable key slot when it is created, avoiding repeated inspection of the crypto alg [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1xQQzv-000000000Eo-0NxD Subject: [Openvpn-devel] [PATCH ovpn net-next v4 4/9] ovpn: record asynchronous transmit crypto X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881393829585044017 X-GMAIL-MSGID: 1881393829585044017 The UDP GSO output path introduced next requires a synchronous encrypt transform. Record the transform type in the immutable key slot when it is created, avoiding repeated inspection of the crypto algorithm flags in the data path. Signed-off-by: Ralf Lici --- No changes since v3 https://lore.kernel.org/openvpn-devel/1533a769382fd369d6f3e839d870f42efd1b4809.1794223133.git.ralf@mandelbit.com/ New in v3. drivers/net/ovpn/crypto.h | 2 ++ drivers/net/ovpn/crypto_aead.c | 1 + 2 files changed, 3 insertions(+) diff --git a/drivers/net/ovpn/crypto.h b/drivers/net/ovpn/crypto.h index e3feb16d5498..8ce324e9b58f 100644 --- a/drivers/net/ovpn/crypto.h +++ b/drivers/net/ovpn/crypto.h @@ -39,6 +39,8 @@ struct ovpn_peer_key_reset { struct ovpn_crypto_key_slot { u8 key_id; + /* whether the encrypt transform is asynchronous */ + bool async; struct crypto_aead *encrypt; struct crypto_aead *decrypt; diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index 30299581422d..5e5320338165 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -462,6 +462,7 @@ ovpn_aead_crypto_key_slot_new(const struct ovpn_key_config *kc) ks->encrypt = NULL; goto destroy_ks; } + ks->async = crypto_tfm_is_async(crypto_aead_tfm(ks->encrypt)); ks->decrypt = ovpn_aead_init("decrypt", alg_name, kc->decrypt.cipher_key, From patchwork Mon Nov 9 15:09:03 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5624 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp802951lat; Mon, 9 Nov 2026 07:09:34 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErGPMiwziTXsEBvnyFLCd6p/hlIgdZ3fQD6AVg6OBeG/vO03+6meuyw6DKjikwZyeEYzJaPE7KBpjg0=@openvpn.net X-Received: by 2002:a05:7301:430c:b0:36e:97b4:1071 with SMTP id 5a478bee46e88-37257aa2df0mr7427404eec.14.1794236974229; Mon, 09 Nov 2026 07:09:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794236974; cv=none; d=google.com; s=arc-20260327; b=DApIUqXe1mNO5NbL5+tMRpYxodK1QFWUmpQHdbxbbAe6Ph4qsYPuQK6G8LLngyliuO 7Cnw8uUJ0fd6fsVvsZhTAdBiiJ3Zf+jXg60YzRbSusTlUVMfCh1LiLS90ls3BMTtkzpF 6XfoWErGK2/2+I3NOltpsTX/TI9Tp3NhXLWDqb23AQPuJYWJyYwO4wGbZtiStAsbduFM 5ZmwyYL8/DSv/0q5u6aCzVZt8EtFp1M7IsiTkMu3bk+EvF/ATR/wbKd6Wzrs61U/c2tD iDWEKgC+6KrMayB8uf3ttgkzEEJWnOCXTfcXXmcwCZWZvyu4N+3LSPQFQOELCl4ZXEkT qcpg== 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=WAw8KufN5s8i8XyOPzWMURaRGG/iIYhnnaA+5OeAi44=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=LKfSgiv/hOxBg6jhlJfRKmwQQJRHkI6pO623WKQyiGKDxHzOaOe0Pnoy1v6q58g57O JJdLeWJlDGi4G54VDMpFZmZFnTTun7/Hzerq9pI5XW1i+kLsoUw9gQiBFExxx0zA4eip 3kQgO6J4PNnIjxEP/r4UVIwum3cti4m2nufjvO/2YLnNeRad2Wcp3p+F4H0fkLkaaamG CIAszBc3XwYH+Hzi39ohGKtwaxYbMrg8oWHxwlF2Eu3K7NDLkEu09A91kLIY1c/sewLA N2R5RRjG6jol46ICz0m/3897uAH1j4+mRO6YSAzyuvXesWuzeL+ByFgKaLYpNWoDDKt7 BatQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=MxT9cP5f; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=bfAIRvhG; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=XMZurP34; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=gatLuNZa; 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-37265cfce6fsi17401705eec.37.2026.11.09.07.09.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 07:09:34 -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=MxT9cP5f; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=bfAIRvhG; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=XMZurP34; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=gatLuNZa; 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=WAw8KufN5s8i8XyOPzWMURaRGG/iIYhnnaA+5OeAi44=; b=MxT9cP5fSXaGC7 HZTOn1e/HU3+dR1siGchable5RiIidHOnEa3wkjqJ4Sn7cds7HR1+/iqcZsmNGKcnniUlNTObr1Jr 5Kpi7PHBWR8E3a7wXppKYJCJgjA66c0BJ8Njh6yk4elXizlbSU4lQ/TKjn9djIrDsOEswoXBleN0t cyU=; 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 1xQR00-000000007mq-2GrD; Mon, 09 Nov 2026 15:09:32 +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 1xQQzx-000000007mM-3yTh for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:29 +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=rh0qPPlKu8oxeCnqlkYjkHoCwL/5rgHYqYqMPZGL0bM=; b=bfAIRvhGqCG+vHJ7mTDgkFer+N EuNt+5dLgKYg+UhbTGVJDZ0GYERhRlyqUspO1NCmz27AyjdQFWBzAbqjLRC7Xd1GyzC5rcRkVRcRH YsqH1xFBL0tGByg34YmLCfWOeDvvS9BW9yh8VRME0DItF8axeHtWt+R7Nn+FFCYBnqdM=; 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=rh0qPPlKu8oxeCnqlkYjkHoCwL/5rgHYqYqMPZGL0bM=; b=XMZurP343UsP67nhjtbyXdDRJm rDnIj/mbWcdPFt43HIkhZrYrBz/RuN9u1GRLZ2blRFAuJ/rFLFh+n7TvTXmCCuRlAcO9NSaI0V2L8 itQKf94rdg7yxHJrrcO4VjT3/J2FZIsZOatsv3v38WmOefvAz9wLfQzsnv5t7x9H1Yfo=; Received: from mout-b-112.mailbox.org ([195.10.208.42]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQQzv-000000001VE-12R7 for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:29 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-112.mailbox.org (Postfix) with ESMTPS id 4jNY8v1D87z5wXZ for ; Mon, 09 Nov 2026 16:09:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794236959; 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=rh0qPPlKu8oxeCnqlkYjkHoCwL/5rgHYqYqMPZGL0bM=; b=gatLuNZaAFg7IyZ8B2qvtk0axyKDCN/FauJAYTY40RZSAz9She3wdBMabpaI/jzd1oRSTl dJtxtEBCP9eF/5dSymYua8A6RKL3OKA0HvnkTVM+19E+3chykatfdFDggq/2TY+Y7zVcAE Co76NGkff0djDKPyMe6MXoLZF75YGAEXExg6dGBLbD/Zea6P6T+b9xUM3sdmmHlqoWAYv3 BvXEWCzU5t8ed5eyQovwiKRRA+pbg4yNB91JCd8GbXBN0BSqmCGIBKjGyK8FYwswSfAZi9 HSL7MSDzkkfi7zp70NBjg/JS4SgPIcJTSHllxUArMRPFfs+uHAsuc1fxOopjQA== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 16:09:03 +0100 Message-ID: <84055d076e4df97aa0658920a14359d8543c7a84.1794234673.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNY8v1D87z5wXZ X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: UDP GSO segmentation currently propagates socket write ownership only when the aggregate uses sock_wfree. An encapsulator such as ovpn can instead retain ownership from the payload socket, including t [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1xQQzv-000000001VE-12R7 Subject: [Openvpn-devel] [PATCH ovpn net-next v4 5/9] udp: preserve write ownership across GSO segmentation X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881393829400567318 X-GMAIL-MSGID: 1881393829400567318 UDP GSO segmentation currently propagates socket write ownership only when the aggregate uses sock_wfree. An encapsulator such as ovpn can instead retain ownership from the payload socket, including tcp_wfree, while repackaging its data as UDP GSO. In that case the destructor remains on the aggregate and runs when software segmentation consumes it, before the resulting UDP packets complete transmission. This releases the write-memory charge early and can wake TCP Small Queues prematurely. Use is_skb_wmem to recognize the standard write-accounting destructors and propagate the original destructor to every segment. These destructors all release ownership using skb->sk and skb->truesize, so the existing truesize adjustment remains applicable. Skbs owned through sock_wfree are handled as before. Signed-off-by: Ralf Lici --- New in v4. net/ipv4/udp_offload.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index cf07c3c6611a..d41529030fbb 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -481,6 +481,7 @@ static struct sk_buff *__udp_gso_segment_list(struct sk_buff *skb, struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, netdev_features_t features, bool is_ipv6) { + void (*destructor)(struct sk_buff *skb) = gso_skb->destructor; struct sock *sk = gso_skb->sk; unsigned int sum_truesize = 0; struct sk_buff *segs, *seg; @@ -542,7 +543,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, skb_pull(gso_skb, sizeof(*uh)); /* clear destructor to avoid skb_segment assigning it to tail */ - copy_dtor = gso_skb->destructor == sock_wfree; + copy_dtor = is_skb_wmem(gso_skb); if (copy_dtor) { gso_skb->destructor = NULL; gso_skb->sk = NULL; @@ -551,7 +552,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, segs = skb_segment(gso_skb, features); if (IS_ERR_OR_NULL(segs)) { if (copy_dtor) { - gso_skb->destructor = sock_wfree; + gso_skb->destructor = destructor; gso_skb->sk = sk; } return segs; @@ -571,7 +572,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, for (;;) { if (copy_dtor) { - seg->destructor = sock_wfree; + seg->destructor = destructor; seg->sk = sk; sum_truesize += seg->truesize; } From patchwork Mon Nov 9 15:09:04 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5628 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp802954lat; Mon, 9 Nov 2026 07:09:34 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFrnlCgOaWwCkWwXnCUKrFCQN30rHZP5mt6Ou8gDkhZoilD+pudcKZULYQDCLtrTcX1fUTI+4vkluk=@openvpn.net X-Received: by 2002:a05:693c:88c7:10b0:372:14fb:2573 with SMTP id 5a478bee46e88-3725670cb06mr7716670eec.20.1794236974242; Mon, 09 Nov 2026 07:09:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794236974; cv=none; d=google.com; s=arc-20260327; b=rJ41gm2eGaiz6ihcE4IBEpCC8HL/ZbcUFfTXamwlaGz35cioxJm3279xdJ3aTPPUcB VcB1TASy5shPBtkWWj2B8sYtZuOhAyvH8xzT3yka8jvQZH7DlxTNQDXzOMeIAHvHJ5Df jp/7mKWLOUvRb8YLYtuOUEFZGtgNka9coROY+vDQVubTxLiUB4GAADNSOPJf7Xy2zLS/ T5Uaz6yCmUNKagX/sfGEO+30QU0e6pHpw1WeBrOYljaPy2KCwwxMmmIwAAxj8HPzc0pM ss1dCqdwSS8mw3gJwQSmFZnqDGKJ0bi1TQza4eC27TK/QgXfBT8wqqjVK10RbUUnw5jS hiFQ== 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=akfbjurHbRJAb4AUanhNyABc73BGyix69uKbG/owSQg=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=MkJeXZiLxm4XgoB90EcRSiQTYT2ensMr6In9TwGdrayBEgvnj+kXNehN1+/QpwNuzK CWLPIWvMk+hqagjTz6uz1+gvWDe6Suk5IAsQG6MfEwu0suJdKa5NpNuS6D/Fu9ER0WeD M5r4TR/3WfT5ZGCMWaEwNKFtryvn0Jsktdt4xFxTzDqU0bzSnGP/G1LG2VH7Tj7h/31u aKkCB4dH0nrLrO9KfykAbTCUaDIHF4H6Ynl29Gjz+4AqvhhqpMhZ5jL/W6I7yWM5C1pT Vikt0Vd0kU/kISJ37kzjgaDE13fS1tWi5ZxCpEi/s0dKJJzc0oPiVDNf/yehD5/+kt46 dKtA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=P1a6Pyo5; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=YweB5DXu; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Ivbymku7; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=Lv8+yCef; 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-37265d04947si14474900eec.46.2026.11.09.07.09.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 07:09:34 -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=P1a6Pyo5; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=YweB5DXu; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Ivbymku7; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=Lv8+yCef; 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=akfbjurHbRJAb4AUanhNyABc73BGyix69uKbG/owSQg=; b=P1a6Pyo5C8IUyY hBaeIyBUCEL0y1TLtZ37xlXxMs08yKQr4R87XSFlfrBviHlr+qcQWjUxTR1JAJPKA8F9dDH4OgAJr GB6U0CmEDI/3Nsyjr+lMmaVHBtxL4pryzrntDEVVkc9E0o5WDK+5RpsCU77p0GL5h2hH68ZmEDc3E TG4=; 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 1xQR00-000000007mx-2wHf; Mon, 09 Nov 2026 15:09:32 +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 1xQQzz-000000007mb-1Pe3 for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:31 +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=KLO/O2KVoWTBa37+M6aiKIC6X9jGZ2c2ot+uqn8zUU8=; b=YweB5DXuNkK0xiPpgX4F02wLO7 p3fQdGNaW+o0+zkJuwctgswmP6sbTY9gmokoxTBAmWBvwi60ZoG445jza04uWc9k/zwwFGNWEZJJL dpbGmOYV3rIUmydIS4pnArs4xq4ZA4uDzEc2aH5uM6oSvqYYACr3uxNANyXE5GK/zkh8=; 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=KLO/O2KVoWTBa37+M6aiKIC6X9jGZ2c2ot+uqn8zUU8=; b=Ivbymku7eMP0YgIRX2LgVCN1J2 lGeYfEUzYo+rIzFqB3MIgCBF3q9S9D/kiPRn9yi/DyE0sWnHBOS4wrJF1FS/KR2dbW07kJOI8a+0R /dysKvLoHi3+BhfQVhivrIE6vsR4ZKe8NeACKKb3shE3bgjhK0biPVffJ4clZTZtfE0U=; Received: from mout-b-206.mailbox.org ([195.10.208.51]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQQzv-000000000Eq-1vM5 for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:31 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-206.mailbox.org (Postfix) with ESMTPS id 4jNY8v41L4zGX for ; Mon, 09 Nov 2026 16:09:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794236959; 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=KLO/O2KVoWTBa37+M6aiKIC6X9jGZ2c2ot+uqn8zUU8=; b=Lv8+yCeflFL3TQyFnlmi0kGTFcqdP5Naljj8YXJFeuETHkDQA2L3sAn88ssw27u5tSd9/Q DHh0y5md1aNM7De5VZXZ5yCU2Zy+TSXAdu1RW1ZWx2G5j6sctxIWLyzhxSGadQJEb8tCYH rfxG/V7UcLjCdJxi9d7APFwOyLm130ozXhNND3nR3IqsEqzaHdaEVym6QEcIaaGfbLJlP/ NDIYw7h4Z+Jaj95oU0IaTBfuqHIO4ssQ8hW2V9Xt7wyri2OyTreAqI2R671TvSR0uhTGOX gt3F0NdBzCHMte2QH8mIeGzIykTb5Kxq1Xszbmwoa71gTJNxrunYenN3dQr4Nw== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 16:09:04 +0100 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNY8v41L4zGX 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: 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 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: 1xQQzv-000000000Eq-1vM5 Subject: [Openvpn-devel] [PATCH ovpn net-next v4 6/9] ovpn: convert GSO input into UDP GSO output X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881393829869314655 X-GMAIL-MSGID: 1881393829869314655 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 v3 https://lore.kernel.org/openvpn-devel/55ca5e8f9f2fb9939ee28deeb42aa6bd5476a136.1794223133.git.ralf@mandelbit.com/ - Reserve LL_MAX_HEADER when sizing output aggregates so the final skb stays below lower-device GSO limits after its link header is pushed. (Sashiko) - Only batch segments which share the same socket owner and destructor. (Sashiko) Changes since v2 https://lore.kernel.org/openvpn-devel/20261102164353.459969-5-ralf@mandelbit.com/ - Restrict UDP GSO output to synchronous AEAD transforms and remove the asynchronous batch-completion machinery. - Let fixed-size frag-list GSO input use the UDP GSO output path; only GSO_BY_FRAGS input remains on the in-place path. - Transfer socket write ownership with the input skb's original destructor so TCP Small Queues wakeups remain correct. (Sashiko) - Preserve timestamp and ooo_okay metadata on the replacement aggregate. - Reset the replacement skb's inner network header so tunnel byte accounting excludes reserved headroom, and document that device tx_packets counts output GSO skbs. (Sashiko) - Refresh the measurements, including a lower-device software-segmentation control. Changes since v1 https://lore.kernel.org/openvpn-devel/47eee3045f402b2baf7db759bc9cfd35dee8f73d.1790843153.git.ralf@mandelbit.com/ - Release successfully encrypted source skbs with consume_skb after their data has been transferred to the output aggregate. (Antonio) drivers/net/ovpn/crypto_aead.c | 101 ++++++++-- drivers/net/ovpn/crypto_aead.h | 4 + drivers/net/ovpn/io.c | 343 ++++++++++++++++++++++++++++----- drivers/net/ovpn/stats.h | 6 +- drivers/net/ovpn/tcp.c | 4 +- drivers/net/ovpn/udp.c | 26 ++- 6 files changed, 405 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..c9f926a9e55d 100644 --- a/drivers/net/ovpn/io.c +++ b/drivers/net/ovpn/io.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include "ovpnpriv.h" #include "peer.h" @@ -32,6 +34,14 @@ const unsigned char ovpn_keepalive_message[OVPN_KEEPALIVE_SIZE] = { 0x07, 0xed, 0x2d, 0x0a, 0x98, 0x1f, 0xc7, 0x48 }; +/* gso_within_dev_limits() requires skb->len, which by then includes the + * link-layer and outer network headers, to stay below gso_max_size + */ +#define OVPN_UDP_GSO_MAX_PAYLOAD (GSO_LEGACY_MAX_SIZE - \ + LL_MAX_HEADER - \ + sizeof(struct ipv6hdr) - \ + sizeof(struct udphdr) - 1) + /** * ovpn_is_keepalive - check if skb contains a keepalive message * @skb: packet to check @@ -234,43 +244,23 @@ void ovpn_recv(struct ovpn_peer *peer, struct sk_buff *skb) ovpn_decrypt_post(skb, ovpn_aead_decrypt(peer, ks, skb)); } -void ovpn_encrypt_post(void *data, int ret) +static void ovpn_encrypt_key_exhausted(struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks) +{ + netdev_warn(peer->ovpn->dev, "killing key %u for peer %u\n", + ks->key_id, peer->id); + if (ovpn_crypto_kill_key(&peer->crypto, ks->key_id)) + /* let userspace know so that a new key must be negotiated */ + ovpn_nl_key_swap_notify(peer, ks->key_id); +} + +static void ovpn_encrypt_send(struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, + struct sk_buff *skb, unsigned int packets) { - struct ovpn_crypto_key_slot *ks; - struct sk_buff *skb = data; struct ovpn_socket *sock; - struct ovpn_peer *peer; unsigned int orig_len; - /* encryption is happening asynchronously. This function will be - * called later by the crypto callback with a proper return value - */ - if (unlikely(ret == -EINPROGRESS)) - return; - - ks = ovpn_skb_cb(skb)->ks; - peer = ovpn_skb_cb(skb)->peer; - - /* crypto is done, cleanup skb CB and its members */ - kfree(ovpn_skb_cb(skb)->crypto_tmp); - - if (unlikely(ret == -ERANGE)) { - /* we ran out of IVs and we must kill the key as it can't be - * use anymore - */ - netdev_warn(peer->ovpn->dev, - "killing key %u for peer %u\n", ks->key_id, - peer->id); - if (ovpn_crypto_kill_key(&peer->crypto, ks->key_id)) - /* let userspace know so that a new key must be negotiated */ - ovpn_nl_key_swap_notify(peer, ks->key_id); - - goto err; - } - - if (unlikely(ret < 0)) - goto err; - skb_mark_not_on_list(skb); orig_len = skb->len; @@ -291,45 +281,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 +469,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 +477,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 +608,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 +637,8 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) if (unlikely(!curr)) { net_err_ratelimited("%s: skb_share_check failed for payload packet\n", netdev_name(dev)); - ovpn_dev_dstats_tx_dropped(ovpn->dev); + ovpn_dev_dstats_tx_dropped(ovpn->dev, 1); + gso_out = false; continue; } @@ -427,11 +647,23 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) skb_checksum_help(curr) < 0)) { net_err_ratelimited("%s: skb_checksum_help failed for payload packet\n", netdev_name(dev)); - ovpn_dev_dstats_tx_dropped(ovpn->dev); + ovpn_dev_dstats_tx_dropped(ovpn->dev, 1); kfree_skb(curr); + gso_out = false; continue; } + /* one aggregate can carry only one write owner, so batch only + * segments that share it + */ + if (gso_out && !skb_queue_empty(&skb_list)) { + struct sk_buff *prev = skb_peek_tail(&skb_list); + + if (unlikely(prev->sk != curr->sk || + prev->destructor != curr->destructor)) + gso_out = false; + } + /* only count what we actually send */ tx_bytes += curr->len; __skb_queue_tail(&skb_list, curr); @@ -444,10 +676,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 +692,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 15:09:05 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5627 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp802967lat; Mon, 9 Nov 2026 07:09:34 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErGP0Dm9KS0xbjbl2VvvPfGd+KCRd7xa1aT3z6zknfoFtOS/OsgXskgMoFj+Km7qhJnJ7Drccf4DDuM=@openvpn.net X-Received: by 2002:a05:7301:da0a:b0:36a:1434:c691 with SMTP id 5a478bee46e88-37256bed190mr7099738eec.14.1794236974231; Mon, 09 Nov 2026 07:09:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794236974; cv=none; d=google.com; s=arc-20260327; b=JIfqiwAQXxu6qtc3hNCDiv00fiY50bch2GRhsksjKpq0gqpZ7wm9/rUkFQv0UEK3tw 2wiRVjEQR+rKRMDMHmubsVeVg1yCb0d9KRrti8Z2fbEmvow3J3/BFCSlJFAmYSuMFsY0 9mj81rkSrwPYA3yM+rP7FFpJqhR4Ci9ygMDWj4Gwdi9NqiRABZ4+u5ZbJuhpOnXQ4dPe /c218fY/xJ5F/toPRhmwFXErHrb0s7EYFb7mylJUIMpbsljr+++43+GeQ+nY4IZFakXv 2o/ca2mY2SN5DqBmvZtNwaRt6F9jubHbDh+qacqkyhuDgygzoEtv9oRl+KSp1uFR+0CX tLLg== 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=aG99o/pOwZqi0ZkOPft4EhtVsItcepwAnbRoaMvxYuo=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=Hd/EnfSU6pNRlnQEoCbp4coszHYHt4mu/4y9o5nboiW7X2tle5pVZd4xL2urg5Ly0V KREswkK/Eg3y6jJzPD5FIuIT7z2xC9E4S9DYADqJHoxckLRDSsefUs0drDjmQz/1sPqc dMQfCFx9fTnkKFuf8Mcx5OrnVkb/+4SxhiY1VxgXwQbTevq6OxPrlTU6buR9MZFWF+a4 S+3cbj+B1mdL/ltYBLwjjBP4c9Ivtb2HsSvqhptXrg2g6UfdVEYFr4TqGebdviD6Ynw6 kTLGKTg/SjLhSRnLOQI6mn8Lk6KA7PhXN6vuVXtDQCCEZBlUn99MiRxReovBVeuDOhp/ kniA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=LYHuYQXK; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=GqNwswgB; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="mp3OiO1/"; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=Jniu5jff; 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-372657126bcsi14200973eec.21.2026.11.09.07.09.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 07:09:34 -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=LYHuYQXK; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=GqNwswgB; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="mp3OiO1/"; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=Jniu5jff; 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=aG99o/pOwZqi0ZkOPft4EhtVsItcepwAnbRoaMvxYuo=; b=LYHuYQXKmGQd0T PwlBjImbo/9k9wRpB9pIQ08zdMNHM3orbW0D2NLsvkSBi5El/OSuN1IhFysIbPRU11W1PEXnhLj04 DWY8pjVwCyh6IM/WwEdHDqR8qPAG3Qy+yQ07nWjEcL1ruvFljD4ZaFlY27waEDo7bbd+uQhJq2QA7 ffs=; 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 1xQQzz-000000006HP-2neb; Mon, 09 Nov 2026 15:09:31 +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 1xQQzy-000000006H9-19Q3 for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:30 +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=9LqqP5xv5a/w6HSVJBBINBwY6NnUZVjCw/PyLHVHUDU=; b=GqNwswgBSYeapY7zBSO/hHO/Cc TZwr3OG9rkO+tNjc1VX0A1SxhnLg86qPnu4ilN+1XVFsw8hGsHts9qlY3ckoQY+sV770dRr2tbWPn dPwSLv+PyMyaYnEMCP1EBPy6JM1nx4ZvPPBEbmmHxO15Wilk4EcvtO4Zok+oVdZRP4Og=; 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=9LqqP5xv5a/w6HSVJBBINBwY6NnUZVjCw/PyLHVHUDU=; b=mp3OiO1/BuiY0Du2f9Y7zCxclq fjGoUa6VG460HCpSMoU6CpcSnUh/lz8zm6Uy9FJhd3nBu6NnJ4+i2OMBaeWY0wyudxRigtC2JfFH9 K1WZTTnmIBSAbcQS6jigEpPpsixiLgBmYpITg6T+IOhkUzWQlsmuZqREv3pMDLOoZz8I=; Received: from mout-b-105.mailbox.org ([195.10.208.50]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQQzw-000000000Er-0xof for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:30 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-105.mailbox.org (Postfix) with ESMTPS id 4jNY8v5pmjz9syq for ; Mon, 09 Nov 2026 16:09:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794236959; 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=9LqqP5xv5a/w6HSVJBBINBwY6NnUZVjCw/PyLHVHUDU=; b=Jniu5jffayt8KastuvKUPjo94NSPP7nh5vSCR7SttTPTzdnW4MJ4d31Pa1Bzphp23J1KY+ awm9nIZMXl5sy59QXDsqPYzImy0rlpfib/+kv/DaNOiIAH77/Qp1KKDknjaQx/DSNyGVYe rNETiOVbgfP9lzpIedzrm/fLQ18bw2kLPTTmWbCnzxPgpuCBQFVdhBtgvgexkz9pvQIBWZ 2WxBEwy48FQMbbTkipnacVf7Mp/RKSUAnTLV2xexuURIjGw0+AivV/x3Hz3lxbEWVutam0 5pNZbS9NVApyNW1INaBLkSK8odNH79qp97H9KXnr3bV8tNePXiOPpcqLh0bcxw== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 16:09:05 +0100 Message-ID: <3f40c3db4152e57b0c8b67edb1afe739cba60947.1794234673.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNY8v5pmjz9syq X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The UDP GSO 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_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: 1xQQzw-000000000Er-0xof Subject: [Openvpn-devel] [PATCH ovpn net-next v4 7/9] ovpn: reserve packet-ID ranges for UDP GSO batches X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881393829760379295 X-GMAIL-MSGID: 1881393829760379295 The UDP GSO path currently allocates one packet ID for every input segment. This performs one atomic update per segment even though the whole batch is prepared by a single caller. Reserve the complete consecutive range before dequeuing any input skb, then assign its IDs to segments in queue order. This reduces packet-ID allocation to one atomic operation per batch and leaves the input queue intact when no complete range remains, allowing the ordinary transmit path to retry with a newly installed key. If the requested range would cross the end of the packet-ID space, publish exhaustion immediately. Packet IDs abandoned after a later encryption failure remain unused, so an AEAD IV is never reused. Signed-off-by: Ralf Lici --- No changes since v3 https://lore.kernel.org/openvpn-devel/b7eeace194390a817c6b1105a5f2e294329fc4b9.1794223133.git.ralf@mandelbit.com/ Changes since v2 https://lore.kernel.org/openvpn-devel/20261102164353.459969-6-ralf@mandelbit.com/ - Adapt to the synchronous UDP GSO path; no intended functional change. No changes since v1 https://lore.kernel.org/openvpn-devel/a7138d54319d501b6ba7f1d50dce65cb8d2c3e46.1790843153.git.ralf@mandelbit.com/ drivers/net/ovpn/crypto_aead.c | 7 ++--- drivers/net/ovpn/crypto_aead.h | 2 +- drivers/net/ovpn/io.c | 17 +++++++++--- drivers/net/ovpn/pktid.h | 48 ++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 9 deletions(-) diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index 26305984197e..a75a0bf65c89 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -175,7 +175,8 @@ static void ovpn_aead_encrypt_header(struct ovpn_peer *peer, int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb, - struct sk_buff *gso_skb, unsigned int offset) + struct sk_buff *gso_skb, unsigned int offset, + u32 pktid) { const unsigned int dst_nents = skb_shinfo(gso_skb)->nr_frags + 4; const unsigned int src_nents = skb_shinfo(skb)->nr_frags + 2; @@ -184,7 +185,6 @@ int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, unsigned int payload_off; int dst_idx, mapped, ret; u8 *aad, *iv; - u32 pktid; req = ovpn_aead_request_alloc(ks->encrypt, skb, src_nents + dst_nents, OVPN_AAD_SIZE, &iv); @@ -194,9 +194,6 @@ int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, dst = src + src_nents; aad = (u8 *)(dst + dst_nents); - ret = ovpn_pktid_xmit_next(&ks->pid_xmit, &pktid); - if (unlikely(ret < 0)) - return ret; ovpn_aead_encrypt_header(peer, ks, pktid, iv, aad); ret = skb_store_bits(gso_skb, offset, aad, OVPN_AAD_SIZE); diff --git a/drivers/net/ovpn/crypto_aead.h b/drivers/net/ovpn/crypto_aead.h index 8b444744944e..92e8ed76fba6 100644 --- a/drivers/net/ovpn/crypto_aead.h +++ b/drivers/net/ovpn/crypto_aead.h @@ -20,7 +20,7 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb, struct sk_buff *gso_skb, - unsigned int offset); + unsigned int offset, u32 pktid); int ovpn_aead_decrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb); diff --git a/drivers/net/ovpn/io.c b/drivers/net/ovpn/io.c index c9f926a9e55d..41ced8291a91 100644 --- a/drivers/net/ovpn/io.c +++ b/drivers/net/ovpn/io.c @@ -377,20 +377,31 @@ static bool ovpn_encrypt_gso_queue(struct sk_buff_head *skbs, { unsigned int offset = 0, 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 15:09:06 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5626 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp802956lat; Mon, 9 Nov 2026 07:09:34 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHQ+iApvivsa8naOL84vQnCbF66w5xxEyAX2MtbLUQVHjREZMObGq4g/WahzRif3V16d9NXj88adlY=@openvpn.net X-Received: by 2002:a05:7022:1586:b0:13e:5a50:1e17 with SMTP id a92af1059eb24-1b39fe32b51mr7091058c88.3.1794236974249; Mon, 09 Nov 2026 07:09:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794236974; cv=none; d=google.com; s=arc-20260327; b=dApF1nqfln5dvZZ0Hu/W1NokoOapFYy7EE3gyehbkP8BblZNeAh0vPcARA8q+euS/l mvsHnNj3s0X1u04icNOnLlBj6q1Bgs5t1RtheAuDLkzOh5uICzxyKmK1rdhDMLLBmuAo PRQwmn03TwjYVHAB1rCldTFwxUkjwMCCBrwIsiBsLbNW4Mk4W+QpVYVnzRjnxxO8uqsf UFHlmdtpojM+XyiUnyvg2Nk/ohfrTO5/7ICiVN2PIijpK9vPjco7iR0imUt0YyPDPsXk QHkjBEa2Eo98TZV+Hduf4cj7gzyZSe4/vYv9bN7/1iFU5JzQaUMk2x9PLbib6DXvg1qA yHCw== 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=wXO35jSIBWuW6YLtVe+MSc1Mt6JuiiXvuRrvbKn9cAQ=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=cjSXOtJjil8rCb5NsXfXEm05U+TUFH/jFt/1mWFMEvUm223OpgkkOsWqHh4rjzVJrr n/YmODceKAHcUx+um35ZKkSQjglHXnVLxYsthM0jB/YlO9+1m2TAH6ZSnYhV8Oq9vL0a 2H4KyjLJEQEZJTZyXQq/qg82bCLfieZpoOF5jnWwt0CflNI8+Axi06c5Lf0czqquhpSm QtBaK82KUmaxe5YrIl7yQ9WU7Yt58dE0xB6f8Xei14l/5t2AWBC5dKPpd/vXardGsNCf a+ufcAwWgjWi/j1N7qgNF46J8LxzQtYR7MMGQ9OghJopigq9Ft+Xk8yRW6S+dDH6WoM/ 4fNg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=ldOa5EK0; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=WyNdTUT0; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=cBiF8p3D; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=1eTQr8b1; 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-1b3773f37c3si14807517c88.87.2026.11.09.07.09.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 07:09:34 -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=ldOa5EK0; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=WyNdTUT0; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=cBiF8p3D; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=1eTQr8b1; 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=wXO35jSIBWuW6YLtVe+MSc1Mt6JuiiXvuRrvbKn9cAQ=; b=ldOa5EK08iHnha p2WD8lew3bRYlH09W7wa0OICmhtZFoEcFDo2LHqSx+B5PKscOSUwHYRD1TVPLXaTyCrwh+++WiEeW hr0vrBRSPFwB6r/DTltKXEdO/ygwZkYWtojHxywU5UZNZePzKLPRbMgl9e4HwYHf624P6BM3464b/ S5M=; 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 1xQQzz-000000000Qj-386B; Mon, 09 Nov 2026 15:09:31 +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 1xQQzx-000000000Q7-2HBe for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:29 +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=+hy7QY9vUA0VkC1z6FxlLYPhg9/BzeLxcgBcB7cjAwg=; b=WyNdTUT0GcEsjfvdq7rUvIjAL4 kaDTI+p3qBWwXivqeTNv63Q4Q5LWJqgio1WIgaDishFsU3pR30l8T+OiZOSasytY26/TNil/JgxOR 5xGy0m4LL8d9+a94HrSZYk0dFXngsG0Us9LF0aTUdXWuJyEX4WMjRo8i8ea5NrRK7ZiM=; 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=+hy7QY9vUA0VkC1z6FxlLYPhg9/BzeLxcgBcB7cjAwg=; b=cBiF8p3DfIE/N/qjUJO8iWDxfS vmwIZtwD5OUrdhZjqA+n+Q+eXa2kGyH7zvenf8m/V8b6UH6czea843ox4AUVg6sDA/md33Ip6zguL gBKtL0CqmDLgDusZgWVaJntH1T47cK7AjTpeTHd9w4Buflmwf267BejqbUznVtFgJsN8=; 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 1xQQzv-000000001VH-3St7 for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:29 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-106.mailbox.org (Postfix) with ESMTPS id 4jNY8w0fW5zNldY for ; Mon, 09 Nov 2026 16:09:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794236960; 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=+hy7QY9vUA0VkC1z6FxlLYPhg9/BzeLxcgBcB7cjAwg=; b=1eTQr8b12FNcqftyECZ+fPiJ/zpqVL/jI1+u9JqiokXtJ61/bAFYLc5ZB3zWVjqLWmvIcS vUF7QfFNhjWALVVhtAemffUcjL3oR0/ZNjFO1CYHeK6F7513/0pyo9UbWBL7JSsD0d2FUl RszqA0EdVNgNhZGG8rdpsYE0eBxHYBPTYv4Lg18YHKi6FAjvtKxhPsW5Eb9+ZD4vC7/gS6 0kzsAMmxE0v/ygOL4zSSIL0IMe3oiMy+26Za2jw50PrC9bzGutB5YTRiQdYZM1uBtbI3TC Wj4qhzyXoJxN1FEHHRvNqTEFHrFspM3VY8+fBGMZTbW0grd08MFisZMLhfTRbA== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 16:09:06 +0100 Message-ID: <26e88846a6e2ebcd4a64c50d61edff9ccf6161ac.1794234673.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNY8w0fW5zNldY 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: 1xQQzv-000000001VH-3St7 Subject: [Openvpn-devel] [PATCH ovpn net-next v4 8/9] ovpn: place GSO record AAD directly in output X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881393829627671858 X-GMAIL-MSGID: 1881393829627671858 Each encrypted GSO record currently builds its authenticated header in request-local scratch storage, copies it into the final UDP GSO aggregate and then maps that range again as destination AAD. Map the final output range first and, when it is represented by one base-page-contained scatterlist entry, construct the header directly there. Use the same entry as source and destination AAD since the AEAD interface does not write destination AAD and permits the two entries to alias. Use an unaligned-safe opcode store because a record's offset in the aggregate need not be naturally aligned. Retain the scratch-and-copy path as a fallback when the output range cannot be mapped suitably. In a balanced three-round matrix, direct placement increased throughput by 2.1% and reduced cycles and instructions per byte by 1.3% and 1.0%. Signed-off-by: Ralf Lici --- No changes since v3 https://lore.kernel.org/openvpn-devel/62065a69f01a64708cc34e6eeff159bb4bbc5f48.1794223133.git.ralf@mandelbit.com/ Changes since v2 https://lore.kernel.org/openvpn-devel/20261102164353.459969-10-ralf@mandelbit.com/ - Use an unaligned-safe store when constructing AAD directly in the output aggregate. (Sashiko) - Refresh the measurements. New in v2. drivers/net/ovpn/crypto_aead.c | 64 ++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index a75a0bf65c89..763fd4f2cc25 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -8,7 +8,9 @@ */ #include +#include #include +#include #include #include #include @@ -169,10 +171,33 @@ static void ovpn_aead_encrypt_header(struct ovpn_peer *peer, /* add the packet opcode and wire nonce as associated data */ op = ovpn_opcode_compose(OVPN_DATA_V2, ks->key_id, peer->tx_id); BUILD_BUG_ON(sizeof(op) != OVPN_OPCODE_SIZE); - *(__force __be32 *)data = htonl(op); + put_unaligned_be32(op, data); memcpy(data + OVPN_OPCODE_SIZE, iv, OVPN_NONCE_WIRE_SIZE); } +static bool ovpn_aead_encrypt_header_direct(struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, + u32 pktid, u8 *iv, + struct scatterlist *sg) +{ + unsigned int offset, page_offset; + struct page *page; + void *addr; + + offset = sg->offset; + page_offset = offset_in_page(offset); + if (page_offset + OVPN_AAD_SIZE > PAGE_SIZE) + return false; + + /* an SG offset can address a later base page in a compound page */ + page = sg_page(sg) + (offset >> PAGE_SHIFT); + addr = kmap_local_page(page); + ovpn_aead_encrypt_header(peer, ks, pktid, iv, addr + page_offset); + kunmap_local(addr); + + return true; +} + int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb, struct sk_buff *gso_skb, unsigned int offset, @@ -184,6 +209,7 @@ int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, struct aead_request *req; unsigned int payload_off; int dst_idx, mapped, ret; + bool direct_aad; u8 *aad, *iv; req = ovpn_aead_request_alloc(ks->encrypt, skb, src_nents + dst_nents, @@ -194,26 +220,42 @@ int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, dst = src + src_nents; aad = (u8 *)(dst + dst_nents); - ovpn_aead_encrypt_header(peer, ks, pktid, iv, aad); - - ret = skb_store_bits(gso_skb, offset, aad, OVPN_AAD_SIZE); - if (unlikely(ret < 0)) - return ret; - /* encrypt out of place from the original segmented skb directly into * its final range in the UDP GSO skb */ sg_init_table(src, src_nents); - sg_set_buf(src, aad, OVPN_AAD_SIZE); + /* use the final output bytes as source AAD too when they can be safely + * written through one base-page mapping + */ + mapped = skb_to_sgvec_nomark(gso_skb, src, offset, OVPN_AAD_SIZE); + if (unlikely(mapped < 0)) + return mapped; + direct_aad = mapped == 1 && + ovpn_aead_encrypt_header_direct(peer, ks, pktid, iv, src); + if (unlikely(!direct_aad)) { + ovpn_aead_encrypt_header(peer, ks, pktid, iv, aad); + ret = skb_store_bits(gso_skb, offset, aad, OVPN_AAD_SIZE); + if (unlikely(ret < 0)) + return ret; + sg_set_buf(src, aad, OVPN_AAD_SIZE); + } + mapped = skb_to_sgvec_nomark(skb, src + 1, 0, skb->len); if (unlikely(mapped < 0)) return mapped; sg_mark_end(&src[mapped]); sg_init_table(dst, dst_nents); - dst_idx = skb_to_sgvec_nomark(gso_skb, dst, offset, OVPN_AAD_SIZE); - if (unlikely(dst_idx < 0)) - return dst_idx; + if (likely(direct_aad)) { + /* destination AAD is not written and may alias source AAD */ + sg_set_page(dst, sg_page(src), src->length, src->offset); + dst_idx = 1; + } else { + dst_idx = skb_to_sgvec_nomark(gso_skb, dst, offset, + OVPN_AAD_SIZE); + if (unlikely(dst_idx < 0)) + return dst_idx; + } payload_off = offset + OVPN_AAD_SIZE + OVPN_AUTH_TAG_SIZE; mapped = skb_to_sgvec_nomark(gso_skb, dst + dst_idx, payload_off, From patchwork Mon Nov 9 15:09:07 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5625 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp802957lat; Mon, 9 Nov 2026 07:09:34 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFiQ5LZdl9qiAHeG0doIarEu4k+9NdUCTDY4iCOEAWySvGE7jGl0yirAiCZOlWt1BhiTmo8wPxGKlQ=@openvpn.net X-Received: by 2002:a05:7022:3f0d:b0:199:4f68:7710 with SMTP id a92af1059eb24-1b39fe2a7fbmr6902608c88.2.1794236974233; Mon, 09 Nov 2026 07:09:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794236974; cv=none; d=google.com; s=arc-20260327; b=OZpYBRVkcSU2QNHcJ0HxUjSArlqVqu551sJkz8MZJYgeOy4s1HL/f/dYWwkoAJbSO8 x1lQM6OdCKJEo1H5GO3ChnTZo2dyNGQcGTkORhBQxxgOHR+nlzIN/D3HC+noE78xE8LR nqtoSqmMG8b4r3mrqtUYETCH8rHhZjFDH96wVP9aeCF397FwZodhdu09/uaZEy4LvEBj XylUwSorpqw7xvr9soFW6z7rY3w71e3EGT4GTNuSQkXIQq24YlM5uegif67xkBVGBmRO AxuktP3sao72k3jnr9Z0WwntfXBuGA1OpNCIELQtuW7sbAVwl101hJADYYw4OVCu/exz QMfw== 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=2wpdEHdzvEHKmO1QndhPHa0ldVHKN9LLrODv5OISPAE=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=n6cjxERGGGjuy5GUd3BR8AGpQF9B5/6+hGABKdZHChiQSWUw8/VEu1zDZhnvWE1G5Y JfFwGrFLuRIYaL0mPRtMKyNG8xGz1soE2cV52aao3W9zibJfYmLkOAjDECVekNfkoOwt HDuWacugBBs0n9FVstZ0XljKZdSfuZx8ugehqH85JdCYYHUVfTiEW4e0NU14LlX7zsgD 1stow8Ip/QxDIZuX7+dsc4SbfQSkIm/1A3B6vRCk2fCbCUXj/zQcvRbD9MVWf6p7cC9c jIBbqKJ7DHaDlz7o2T+g/3bWgygyVugbthBepFmJGc+eZbZqCF1GqpekjTdiAQrzeeK0 dJcg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=LEKyoS9Q; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=chBnzBE8; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=HkhlMFLb; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=K7rdvtUe; 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-1b375727634si21238986c88.45.2026.11.09.07.09.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 07:09:34 -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=LEKyoS9Q; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=chBnzBE8; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=HkhlMFLb; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=K7rdvtUe; 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=2wpdEHdzvEHKmO1QndhPHa0ldVHKN9LLrODv5OISPAE=; b=LEKyoS9Q9dpnbl 01MP75cr4GKkOxo3oPX9KolBJyGjCxs9UrB69iRPrx5oAVNY/Vs9+s0CWYndm62DP6Is8FJ1ZnBPA fZchGeWOFTx6gVYzvMJQcDYsQL6/jMMbfCwV2ioDoxa2eW3CabvuxD/0qSEuBM+NN/JauzpR36vbV igs=; 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 1xQQzz-000000000Qq-3c5c; Mon, 09 Nov 2026 15:09:31 +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 1xQQzy-000000000QJ-27Af for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:30 +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=cLGKfJQ0a4StvbMy02O0w/rfH0UYvycgvlho3vjhiV8=; b=chBnzBE8N2JV90xOOKwitHhU6H yL16gOCXKteLIwLqcJ5c7qww41okiZVlUzvXN0dTMKrh+D8GBA9wsacyz9xMpyRhR6rA4fRUg6FYe lDALWXV7W38JUWaUkIRcn5Nv32Dgr0AFOIXiVItWBVi4Cg8TsNVf3JhFV9i2mD0SO5OE=; 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=cLGKfJQ0a4StvbMy02O0w/rfH0UYvycgvlho3vjhiV8=; b=HkhlMFLbjubLif+d5hCW1FqUgj TX8s43SmdW5deniVU7kKZfbz+wK6j3tiOeUjCetKRgCbxAMxQPNFbs2uU54/3WWOKuUPoyuB5s9k+ FHwkuu/Id5GX+vwUvwsxl01wKJY3PaCR5jiQCp+4RXxU7R5W3kznnMXpQKDKH4Oql/84=; 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 1xQQzw-000000001VI-1kth for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:30 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-110.mailbox.org (Postfix) with ESMTPS id 4jNY8w2rJvzNkGy for ; Mon, 09 Nov 2026 16:09:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794236960; 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=cLGKfJQ0a4StvbMy02O0w/rfH0UYvycgvlho3vjhiV8=; b=K7rdvtUe2KPE7iVJ2QIS/cCzVDNP98rVlNYCQrDaKoSqMFk35rWCXALy9Rh3E6Qf3475zQ e8yOJC+x5dMhHIOg/pYZXY9/FfmHPZ5DTQHNmGSoUJU/fPK0IuqJtknEFaRllRaRxYg+3R 0JvE6m+ei5ckSokfOCw4rKRk3d/NaXyhJcWaczSVrFG5K5RjQYpLOWLIjgG++MKHqoRptG R1INZJVNy2HpkY2t0OBiFbIGqf/RpiuNyvw0hVsiM51P/25JxTd01TQBRw0nYHz1HS32+s qtwa1FvtDU3Ir5/f4mNRGYA4rZyKv3O39+InySNJt3ZJPP2jSVIv1sSRjiE8TQ== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 16:09:07 +0100 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNY8w2rJvzNkGy X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: UDP GSO 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_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: 1xQQzw-000000001VI-1kth Subject: [Openvpn-devel] [PATCH ovpn net-next v4 9/9] ovpn: reuse one AEAD request per UDP GSO batch X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881393829838907260 X-GMAIL-MSGID: 1881393829838907260 UDP GSO aggregation is restricted to synchronous transforms, so each AEAD request is complete before the next record is prepared. The request, IV, scatterlists and fallback AAD scratch space therefore need not be allocated separately for every record. Keep the small context descriptor on the stack and allocate one backing area containing a source table, destination table and crypto request for the complete batch. Rebuild the table contents and update the IV for each record. Initialize the transform, callback and associated-data length once because they remain constant. This replaces one allocation and free per record with one per batch while retaining the same output layout and error handling. On two directly connected 100-Gbit/s mlx5 ports using one zero-copy TCP flow, AES-128-GCM and a 1408-byte tunnel MTU, mean cycles per byte decreased from 4.849 to 4.680 (-3.5%) and instructions per byte from 10.563 to 10.354 (-2.0%). Signed-off-by: Ralf Lici --- No changes since v3 https://lore.kernel.org/openvpn-devel/abf6a5a2236f03dc8d4d1f14a94ac19507af7007.1794223133.git.ralf@mandelbit.com/ New in v3. drivers/net/ovpn/crypto_aead.c | 102 +++++++++++++++++++-------------- drivers/net/ovpn/crypto_aead.h | 25 ++++++-- drivers/net/ovpn/io.c | 14 +++-- 3 files changed, 89 insertions(+), 52 deletions(-) diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index 763fd4f2cc25..e27b8c47c0fb 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -136,17 +136,13 @@ static struct scatterlist *ovpn_aead_crypto_req_sg(struct crypto_aead *aead, static struct aead_request *ovpn_aead_request_alloc(struct crypto_aead *aead, struct sk_buff *skb, - unsigned int nents, - unsigned int extra, u8 **iv) + unsigned int nents, u8 **iv) { struct aead_request *req; void *tmp; - /* allocate IV, request, scatterlist entries and caller scratch space - * in one block - */ - tmp = kmalloc(ovpn_aead_crypto_tmp_size(aead, nents) + extra, - GFP_ATOMIC); + /* allocate IV, request and scatterlist entries in one block */ + tmp = kmalloc(ovpn_aead_crypto_tmp_size(aead, nents), GFP_ATOMIC); if (unlikely(!tmp)) return ERR_PTR(-ENOMEM); @@ -198,86 +194,108 @@ static bool ovpn_aead_encrypt_header_direct(struct ovpn_peer *peer, return true; } -int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, +int ovpn_aead_gso_ctx_init(struct ovpn_aead_gso_ctx *ctx, + struct ovpn_crypto_key_slot *ks, + struct sk_buff *gso_skb) +{ + const unsigned int dst_nents = skb_shinfo(gso_skb)->nr_frags + 4; + const unsigned int src_nents = MAX_SKB_FRAGS + 2; + unsigned int tmp_size; + + tmp_size = ovpn_aead_crypto_tmp_size(ks->encrypt, + src_nents + dst_nents); + tmp_size += OVPN_AAD_SIZE; + ctx->tmp = kmalloc(tmp_size, GFP_ATOMIC); + if (unlikely(!ctx->tmp)) + return -ENOMEM; + + ctx->dst_nents = dst_nents; + ctx->iv = ovpn_aead_crypto_tmp_iv(ks->encrypt, ctx->tmp); + ctx->req = ovpn_aead_crypto_tmp_req(ks->encrypt, ctx->iv); + ctx->src = ovpn_aead_crypto_req_sg(ks->encrypt, ctx->req); + ctx->dst = ctx->src + src_nents; + ctx->aad = (u8 *)(ctx->dst + dst_nents); + aead_request_set_tfm(ctx->req, ks->encrypt); + aead_request_set_callback(ctx->req, 0, NULL, NULL); + aead_request_set_ad(ctx->req, OVPN_AAD_SIZE); + + return 0; +} + +void ovpn_aead_gso_ctx_free(struct ovpn_aead_gso_ctx *ctx) +{ + kfree(ctx->tmp); +} + +int ovpn_aead_encrypt_gso(struct ovpn_aead_gso_ctx *ctx, struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb, struct sk_buff *gso_skb, unsigned int offset, u32 pktid) { - const unsigned int dst_nents = skb_shinfo(gso_skb)->nr_frags + 4; - const unsigned int src_nents = skb_shinfo(skb)->nr_frags + 2; - struct scatterlist *src, *dst; - struct aead_request *req; unsigned int payload_off; int dst_idx, mapped, ret; bool direct_aad; - u8 *aad, *iv; - - req = ovpn_aead_request_alloc(ks->encrypt, skb, src_nents + dst_nents, - OVPN_AAD_SIZE, &iv); - if (IS_ERR(req)) - return PTR_ERR(req); - src = ovpn_aead_crypto_req_sg(ks->encrypt, req); - dst = src + src_nents; - aad = (u8 *)(dst + dst_nents); /* encrypt out of place from the original segmented skb directly into * its final range in the UDP GSO skb */ - sg_init_table(src, src_nents); + sg_init_table(ctx->src, skb_shinfo(skb)->nr_frags + 2); /* use the final output bytes as source AAD too when they can be safely * written through one base-page mapping */ - mapped = skb_to_sgvec_nomark(gso_skb, src, offset, OVPN_AAD_SIZE); + mapped = skb_to_sgvec_nomark(gso_skb, ctx->src, offset, + OVPN_AAD_SIZE); if (unlikely(mapped < 0)) return mapped; direct_aad = mapped == 1 && - ovpn_aead_encrypt_header_direct(peer, ks, pktid, iv, src); + ovpn_aead_encrypt_header_direct(peer, ks, pktid, ctx->iv, + ctx->src); if (unlikely(!direct_aad)) { - ovpn_aead_encrypt_header(peer, ks, pktid, iv, aad); - ret = skb_store_bits(gso_skb, offset, aad, OVPN_AAD_SIZE); + ovpn_aead_encrypt_header(peer, ks, pktid, ctx->iv, ctx->aad); + ret = skb_store_bits(gso_skb, offset, ctx->aad, + OVPN_AAD_SIZE); if (unlikely(ret < 0)) return ret; - sg_set_buf(src, aad, OVPN_AAD_SIZE); + sg_set_buf(ctx->src, ctx->aad, OVPN_AAD_SIZE); } - mapped = skb_to_sgvec_nomark(skb, src + 1, 0, skb->len); + mapped = skb_to_sgvec_nomark(skb, ctx->src + 1, 0, skb->len); if (unlikely(mapped < 0)) return mapped; - sg_mark_end(&src[mapped]); + sg_mark_end(&ctx->src[mapped]); - sg_init_table(dst, dst_nents); + sg_init_table(ctx->dst, ctx->dst_nents); if (likely(direct_aad)) { /* destination AAD is not written and may alias source AAD */ - sg_set_page(dst, sg_page(src), src->length, src->offset); + sg_set_page(ctx->dst, sg_page(ctx->src), ctx->src->length, + ctx->src->offset); dst_idx = 1; } else { - dst_idx = skb_to_sgvec_nomark(gso_skb, dst, offset, + dst_idx = skb_to_sgvec_nomark(gso_skb, ctx->dst, offset, OVPN_AAD_SIZE); if (unlikely(dst_idx < 0)) return dst_idx; } payload_off = offset + OVPN_AAD_SIZE + OVPN_AUTH_TAG_SIZE; - mapped = skb_to_sgvec_nomark(gso_skb, dst + dst_idx, payload_off, - skb->len); + mapped = skb_to_sgvec_nomark(gso_skb, ctx->dst + dst_idx, + payload_off, skb->len); if (unlikely(mapped < 0)) return mapped; dst_idx += mapped; - mapped = skb_to_sgvec_nomark(gso_skb, dst + dst_idx, + mapped = skb_to_sgvec_nomark(gso_skb, ctx->dst + dst_idx, offset + OVPN_AAD_SIZE, OVPN_AUTH_TAG_SIZE); if (unlikely(mapped < 0)) return mapped; dst_idx += mapped; - sg_mark_end(&dst[dst_idx - 1]); + sg_mark_end(&ctx->dst[dst_idx - 1]); - aead_request_set_tfm(req, ks->encrypt); - aead_request_set_callback(req, 0, NULL, NULL); - aead_request_set_crypt(req, src, dst, skb->len, iv); - aead_request_set_ad(req, OVPN_AAD_SIZE); + aead_request_set_crypt(ctx->req, ctx->src, ctx->dst, skb->len, + ctx->iv); - return crypto_aead_encrypt(req); + return crypto_aead_encrypt(ctx->req); } int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, @@ -319,7 +337,7 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, nfrags = 1; } - req = ovpn_aead_request_alloc(ks->encrypt, skb, nfrags + 2, 0, &iv); + req = ovpn_aead_request_alloc(ks->encrypt, skb, nfrags + 2, &iv); if (IS_ERR(req)) return PTR_ERR(req); sg = ovpn_aead_crypto_req_sg(ks->encrypt, req); diff --git a/drivers/net/ovpn/crypto_aead.h b/drivers/net/ovpn/crypto_aead.h index 92e8ed76fba6..c0c777410661 100644 --- a/drivers/net/ovpn/crypto_aead.h +++ b/drivers/net/ovpn/crypto_aead.h @@ -15,12 +15,29 @@ #include #include +struct aead_request; +struct scatterlist; + +struct ovpn_aead_gso_ctx { + struct aead_request *req; + struct scatterlist *src; + struct scatterlist *dst; + void *tmp; + u8 *iv; + u8 *aad; + unsigned int dst_nents; +}; + int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb); -int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, - struct ovpn_crypto_key_slot *ks, - struct sk_buff *skb, struct sk_buff *gso_skb, - unsigned int offset, u32 pktid); +int ovpn_aead_gso_ctx_init(struct ovpn_aead_gso_ctx *ctx, + struct ovpn_crypto_key_slot *ks, + struct sk_buff *gso_skb); +void ovpn_aead_gso_ctx_free(struct ovpn_aead_gso_ctx *ctx); +int ovpn_aead_encrypt_gso(struct ovpn_aead_gso_ctx *ctx, struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, struct sk_buff *skb, + struct sk_buff *gso_skb, unsigned int offset, + u32 pktid); int ovpn_aead_decrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb); diff --git a/drivers/net/ovpn/io.c b/drivers/net/ovpn/io.c index 41ced8291a91..b07e0ed6f95e 100644 --- a/drivers/net/ovpn/io.c +++ b/drivers/net/ovpn/io.c @@ -375,30 +375,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); @@ -412,9 +412,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;