From patchwork Wed Nov 11 09:22:33 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5664 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:529c:b0:11a:a05e:cb97 with SMTP id x28csp179294lax; Wed, 11 Nov 2026 01:23:06 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFdMUneYAznzhxKwE/OuhwgFvXtJbv9yGspRWE8YoCQ9v8TJQNJkZeRIfvULW9mfg+LiY13urjeHAE=@openvpn.net X-Received: by 2002:a05:7022:7f0d:b0:1b2:6a01:f55e with SMTP id a92af1059eb24-1b3c034accemr1669539c88.34.1794388986370; Wed, 11 Nov 2026 01:23:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794388986; cv=none; d=google.com; s=arc-20260327; b=IwHor35hC3QNHe60zcL27wxYHT1+qCVTwozgLs8ofc5GQln5NeVB9RWfE7P1QblLRw LUYnkwN92ex8kkFrsyLeX7qY9mYtSFGG0vhvedVxjM80FW3qrar6vZsjdM30gTar6rSN GFgXnTNF8KBKllmS+IKTxPa6YV/9ylTK5XK48dyCG60mNGQxhlklyr950p+f0g4Yqo/r SKiqrpYskscpFhZ0F62P1zr2KS1mYkNhLw4SKj13WPnsQfkPnk/XMyyiTloYs+Pi6TrY Sc2ld3QlHfNkcxDGwUQZIzCKsxoE/WGMhvQl22hKiCJhzbrVIl7/Lt2Nrn6UiynhvTYP aBkQ== 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=1RgWIQ23pinrNad01YgWGPVqyMlp3Vrad6ZQYDGmd4c=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=QB3h13+K6o3a7t6v6Ggs7m1DYfMG0zeI8+l6hspcy6UE7d/yXCwFBgmQHqHNwS+sb5 +iEs0JnuuF/BepmecQy4DqpjvtxZH3Hdk3ObHO4Dl8/YcOYRzb5X5EE2a4poxuRRBM2A 3WH0ERnhdXWSzgW2YGJS0d3geasygj1aiWwkUQcL4HmwD7El1ETxQD5+xLtPsrWOfRpE BtdAwREVaOugl4LScztJnsLTa9JhyclFc4RpOoM3wKp02+gZXSzG7OvkCCEWutjnnV4C rQTUmATyaAAfWyeau6u+UGuWjn3disSzKUfw40h/GjGv3S1xh+09umyV78RpseACnxlT gKcA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=N2SqE2cc; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="Wequ/hJp"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=LqZGIRAq; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=idf5sbnC; 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-1b3b5b5b3d2si12161093c88.24.2026.11.11.01.23.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Nov 2026 01:23:06 -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=N2SqE2cc; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="Wequ/hJp"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=LqZGIRAq; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=idf5sbnC; 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=1RgWIQ23pinrNad01YgWGPVqyMlp3Vrad6ZQYDGmd4c=; b=N2SqE2ccWIMI1c nndn42MF6Q8yzFCHF3euKOJDkOAaUiJcMPskKnakpE/ELzBM6wppV9ajxITn/gaIOxqZ8L8dg/h0M +MDsCzRiim9F11X8Mr9cLTypE4u5h4mLy3AVEZWBKRdWWRLA4DgxgAvAlMZ3vjTMR4j6/FjVsAs7V Bpw=; 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 1xR4Xp-000000007j0-0yGs; Wed, 11 Nov 2026 09:23:05 +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 1xR4Xn-000000007id-1ibZ for openvpn-devel@lists.sourceforge.net; Wed, 11 Nov 2026 09:23:03 +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=W/tkeexmTBMNx+luhMicTuv3rYXR3u4+M+UMH8sFDD8=; b=Wequ/hJpB0uAOPZjul/o+w0M8m P3s1P8PpNpqvwrk9YMDRVPRnVcpRSIhVpFeg+kzimnNRnFt3sVSjnVJrGr7ToUGTOnv4Scmmvl5rf 71oiBIG7L91SeH/2cYJ1WTEcf8yB7q70BYGS4O4B0hwMexPa0V8w3qhSrUI8HfjC9riA=; 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=W/tkeexmTBMNx+luhMicTuv3rYXR3u4+M+UMH8sFDD8=; b=LqZGIRAqJwDfMmiEDQL/RF/eVT P1i6L29wymc+q/9viMZdz6vsYCh1NEEjMzXlwKE9cjr1KiSwsL/40XkCgEinBHFoHNm7eENteuKZK lFfOS8umwdoRWU+++I18A+jq6UfcJrzmZ5mP560w2wcCcmFpzsoIoqnQhRcQOQK1f2zQ=; Received: from mout-b-203.mailbox.org ([195.10.208.52]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xR4Xj-000000002Ck-1H3F for openvpn-devel@lists.sourceforge.net; Wed, 11 Nov 2026 09:23:03 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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 4jPdNB6WmdzLmHq for ; Wed, 11 Nov 2026 10:22:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794388970; 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=W/tkeexmTBMNx+luhMicTuv3rYXR3u4+M+UMH8sFDD8=; b=idf5sbnCYiJBv0ZlkshOBHVB6cm3hzuwXCeagccUr9QX6935PfS0RRd/BjBPVUEGXAte05 6AS1Gj+4MysSknU/li744kIdNxz2UcEyKUJe4/EGCFgOmvUU9yFAfZS6o+DowepKnZJTm9 90uqC7HdZieuZq+2TnJ6xjHEYkuaMk4c6MPZT3f2Bn3JX/ejKiRmQrTT82yrT8oBJ/mM79 T5YzGEFOW2e3hoT1vARli/EfraIMTS8SBCrR4YBSUHGD5vNYo7BzE4PU7Onhsob5RYO1OM Dj/UDcrjf6qWNAEXIIyEY0e/mASDvKQy+LvRbq0C0F9qN5Gd6oppVCGbolRTyA== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::202 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Wed, 11 Nov 2026 10:22:33 +0100 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jPdNB6WmdzLmHq 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: Frag-list GRO validates the UDP checksum of every datagram before linking it into an aggregate. Completion makes the head's uh->len span the whole aggregate, but keeps uh->check for the first datagram [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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 Message has at least one valid DKIM or DK signature X-Headers-End: 1xR4Xj-000000002Ck-1H3F Subject: [Openvpn-devel] [PATCH ovpn net-next v3 1/6] udp: keep the GRO checksum verdict for CHECKSUM_COMPLETE frag-lists 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: 1881553225259998029 X-GMAIL-MSGID: 1881553225259998029 Frag-list GRO validates the UDP checksum of every datagram before linking it into an aggregate. Completion makes the head's uh->len span the whole aggregate, but keeps uh->check for the first datagram, which segmentation restores, so only the checksum state can carry that verdict. Completion records it by turning a CHECKSUM_NONE head into CHECKSUM_UNNECESSARY, but leaves a CHECKSUM_COMPLETE head untouched, whose checksum then covers only the first datagram. Commit f0b8c3034556 ("udp: do not transition UDP GRO fraglist partial checksums to unnecessary") limited the conversion to CHECKSUM_NONE so that CHECKSUM_PARTIAL packets are not marked as validated. It kept CHECKSUM_COMPLETE because segmentation restores valid datagrams, but the aggregate is validated before it is segmented. Any later validation of such an aggregate fails. udp4_csum_init and udp6_csum_init compute the complete checksum of an aggregate no longer than CHECKSUM_BREAK and drop it as a checksum error. For a larger aggregate, conntrack's nf_checksum in PRE_ROUTING falls back to a software checksum of the whole skb, which fails, marks the packet invalid and sets csum_complete_sw, so UDP drops the aggregate too. Record the verdict for a CHECKSUM_COMPLETE head as for a device which validated the checksums itself, so that completion yields the same CHECKSUM_UNNECESSARY state as for CHECKSUM_NONE and CHECKSUM_UNNECESSARY. CHECKSUM_PARTIAL stays as that commit intended. With rx-gro-list enabled on an mlx5 port, which reports CHECKSUM_COMPLETE, a 100 Mbit/s flow of 30-byte UDP datagrams to a local socket raised UdpInCsumErrors by 3880 in five seconds and lost exactly twice as many datagrams, one pair per dropped aggregate. With rx-gro-list disabled, the counter stayed at zero. TCP frag-list completion follows the same pattern and is not changed here. Sashiko reported the issue while reviewing an ovpn series which uses frag-list GRO. Fixes: f0b8c3034556 ("udp: do not transition UDP GRO fraglist partial checksums to unnecessary") Signed-off-by: Ralf Lici --- Changes since v2 https://lore.kernel.org/openvpn-devel/86994f75fd7d92f745f06e4392f89ff2ee12c3d8.1794329430.git.ralf@mandelbit.com/ - Reference the commit which stopped converting CHECKSUM_COMPLETE in the Fixes tag. (Sashiko) - Explain why only the checksum state can carry the GRO verdict. New in v2. net/ipv4/udp_offload.c | 8 ++++++++ net/ipv6/udp_offload.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index cf07c3c6611a..572a65cd8977 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -965,6 +965,14 @@ INDIRECT_CALLABLE_SCOPE int udp4_gro_complete(struct sk_buff *skb, int nhoff) skb_shinfo(skb)->gso_type |= (SKB_GSO_FRAGLIST|SKB_GSO_UDP_L4); skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count; + /* GRO validated every datagram, but a CHECKSUM_COMPLETE value + * covers only the first one: keep the verdict instead, as for + * a device which validated the checksums itself + */ + if (skb->ip_summed == CHECKSUM_COMPLETE) { + skb->ip_summed = CHECKSUM_UNNECESSARY; + skb->csum_level = 0; + } __skb_incr_checksum_unnecessary(skb); return 0; diff --git a/net/ipv6/udp_offload.c b/net/ipv6/udp_offload.c index 7370bcb80332..0b7ced2b5394 100644 --- a/net/ipv6/udp_offload.c +++ b/net/ipv6/udp_offload.c @@ -176,6 +176,14 @@ int udp6_gro_complete(struct sk_buff *skb, int nhoff) skb_shinfo(skb)->gso_type |= (SKB_GSO_FRAGLIST|SKB_GSO_UDP_L4); skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count; + /* GRO validated every datagram, but a CHECKSUM_COMPLETE value + * covers only the first one: keep the verdict instead, as for + * a device which validated the checksums itself + */ + if (skb->ip_summed == CHECKSUM_COMPLETE) { + skb->ip_summed = CHECKSUM_UNNECESSARY; + skb->csum_level = 0; + } __skb_incr_checksum_unnecessary(skb); return 0; From patchwork Wed Nov 11 09:22:34 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5668 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:529c:b0:11a:a05e:cb97 with SMTP id x28csp179378lax; Wed, 11 Nov 2026 01:23:11 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFmTgdTgZvv7saZ3uGnoJevcrXdCv/lqwpyINZWHTOnXEnMXgZUqWWu9CwHSyi3IApatn9XF9KB/AI=@openvpn.net X-Received: by 2002:a05:7022:1706:b0:179:a1d0:be39 with SMTP id a92af1059eb24-1b3c036c2ecmr1725125c88.29.1794388990816; Wed, 11 Nov 2026 01:23:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794388990; cv=none; d=google.com; s=arc-20260327; b=Q5vYNLR7/A4b9AzUiQQcIw6LcE1HFZuqXxay0KfpTZUq6z3A5d6Fy+HM1IplPBnztm CzllcfMBPBJS5eT3Sxnwv032esLujzP29VnsRf29YCffBKg1wWv7X5Ui9BbjhptNVhai 7XYUAGUBID/yb/v4PqwXin7VWx8Im48D6yAXQ3dhi9eM/Z1PCz2tmDwfVJrekEgDsYLr a+saiPr6TGchTtYQ9TkYn29msyiURM9+PQheRbUsULgFRrL5UxxTdNswfAWi3Q9FD78X LsxBuartl8sW9bGZ40bA5aBdaZXJWqrUNEQWHrHYb2GIOhjqiI6LJJlA5QY6dxtz+FYX dUog== 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=ZCI4WX9urXGp1BS7KrnHMvXYKgu7O/1hV0EoHqBUch8=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=k5bpC6BRtsIVscuGFEBZtPL/E/KyIkPZD6y1uh8AM43PGI6GkHOcgPQ9FVj1KqO6MT LX1MFamXNp5NU1Zq6KXqrwpAFvL29SeCzCfIuxQ2qM1u06b/5a+OT+DCshskr5CJoOX6 7GsYk+AJhXU8IhBWoyoA+pANDhmsDX3Xcgqyob0prd3oImruxcPPlCmXhkJwVL+vSDEa TQvFj7h6bhw6HkTjuHY7vSnqWYGm6Ma8d2plAexS42AbgrwZspe+C0VWBKUgb7nWZl9Q 2sNfIETwvgPL5/11zeI9YSgZ85sGcsnarxj1LRcyGQo+UrPiTt/VKyO2TNrEYnng3iYN +zug==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=IsrBWQyT; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="RqOs/mdW"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=RJ2QD0l7; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=rEVNQob+; 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-1b3b5b5b264si13803662c88.28.2026.11.11.01.23.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Nov 2026 01:23:10 -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=IsrBWQyT; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="RqOs/mdW"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=RJ2QD0l7; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=rEVNQob+; 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=ZCI4WX9urXGp1BS7KrnHMvXYKgu7O/1hV0EoHqBUch8=; b=IsrBWQyTd1tEeX CVP6JLNcSAkYHIaG1MwR4Tus2xQVgcHyZJslxekdwhnQyVPVsubnYEOg5lH+W6mYO0q0r+QhZLjMn o70ue4mytQBKJ6ZWgx8TaASzf6jr0XnA0MnTxQaDW9QQWJ5zN50BwWNiAL6+59R2Rn5HzHdd3mjyf fKE=; 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 1xR4Xt-00000000473-2dHH; Wed, 11 Nov 2026 09:23:09 +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 1xR4Xo-0000000045W-2wsE for openvpn-devel@lists.sourceforge.net; Wed, 11 Nov 2026 09:23:04 +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=084KPNDCCCHfZL3eU73waUDv5CsaEDM4nGC1XpT7NfI=; b=RqOs/mdWC2CkO5hPvnHtvJu0bs 57N3Dro3jQG3qxQcMWYLyqVkHHj1hj4aBS23Fk6nRC0qVA+2/S8PnGyVPCcuytLphn9Rc/5PEb3rQ ojB+V3RbgOXCvpAw5OEPkUyVx1DuoxUbTp7BhGTPwMwyvS6wp+gNLDEyLc9kzkvEGZRE=; 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=084KPNDCCCHfZL3eU73waUDv5CsaEDM4nGC1XpT7NfI=; b=RJ2QD0l7DSqQeuVXjlj4qNdTqF xlNEFrhFizXikjRIdHTS4HNQJbEA7MjspN/QG6J2hl4jz0EojM3uRf0EYsBzym9DucKh9VvqL7l5u o6prN8GRT5U/F68sP1/uO7t2MPaHnR0p5EoX6cfuVnyp/ykE7fZRrfr0vXRwS6Vu0ccc=; Received: from mout-b-206.mailbox.org ([195.10.208.51]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xR4Xk-000000000Gy-0gsl for openvpn-devel@lists.sourceforge.net; Wed, 11 Nov 2026 09:23:04 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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 4jPdNC455GzZQ for ; Wed, 11 Nov 2026 10:22:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794388971; 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=084KPNDCCCHfZL3eU73waUDv5CsaEDM4nGC1XpT7NfI=; b=rEVNQob+BHYeVQpMsutqgeMRbZ+Zm2A1f2E4bOTUYJBLUNTx93CZqqHL88JdFiPTTr8fYB /RfvxlI/UDETzQnXzLwkPWzLO4bX7lnsxfvs4OY8pl/sGh9KsBTUQDjc9eybZOv4e6qcvQ M4xhHGgJB3DUy9XVOoBi/MUONyzJ0TdzazADAPJhsIHNcS8gEEkNkea3GD5t8b6m6xQf3R 4B6qzr/e2kowqMeBH2owEfd9LD+fUaIf5JP7NNSY/CgXhhPKVRc9pUVwhboG0WbF9bHbPc xRfc9YvY8z4Ki97Y7jtvALKPpamhUjIkF+wicx4lESMlRtgWMfOqnv/YgcUobQ== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::202 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Wed, 11 Nov 2026 10:22:34 +0100 Message-ID: <580d7d51ddbdd7961a69538fe0301fe9c93a22db.1794388607.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jPdNC455GzZQ 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: Since commit 3d010c8031e3 ("udp: do not accept non-tunnel GSO skbs landing in a tunnel"), udp_unexpected_gso segments generic UDP L4 and frag-list GSO before passing packets to an encapsulation callba [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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 Message has at least one valid DKIM or DK signature X-Headers-End: 1xR4Xk-000000000Gy-0gsl Subject: [Openvpn-devel] [PATCH ovpn net-next v3 2/6] udp: let encapsulation callbacks consume UDP frag-list GSO 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: 1881553230365162873 X-GMAIL-MSGID: 1881553230365162873 Since commit 3d010c8031e3 ("udp: do not accept non-tunnel GSO skbs landing in a tunnel"), udp_unexpected_gso segments generic UDP L4 and frag-list GSO before passing packets to an encapsulation callback, because GRO socket lookup cannot prove that such an aggregate will not later reach a tunnel. This protects callbacks which only understand UDP tunnel GSO packets, but also prevents an encapsulator from deliberately batching independent outer UDP records as a standard frag-list aggregate. Add an explicit per-socket opt-in for an encap_rcv callback which accepts the exact SKB_GSO_UDP_L4 | SKB_GSO_FRAGLIST representation. Publish acceptance only after the callbacks which consume that representation, and read it with acquire ordering. GRO validated every datagram before linking it into this representation, while the header checksum of the aggregate covers only the first one, and a tunnel can reset the checksum state on the way. Trust the GRO verdict for an accepted aggregate instead of checking it before encapsulation, as udp_post_segment_fix_csum does after segmentation. Treat the opt-in as provisional: segment the aggregate and process every datagram normally if the callback is absent or declines it. A declining callback must leave the aggregate unmodified. This keeps the combined representation away from the UDP socket and leaves callbacks which do not opt in protected as before. Check the inbound XFRM policy and reset conntrack state once for an aggregate passed to such a callback. Its datagrams share the verdict, and a check after a fallback would lack the state which the first one consumed. Preserve the sampled acceptance decision across concurrent callback changes and account every consumed datagram in UDP statistics. Consuming the aggregate whole avoids rebuilding every datagram only for the encapsulator to discard its outer headers, and lets the callback amortize per-batch work and look ahead across records. With this series and the ovpn UDP GSO transmit series applied, five interleaved 60-second iperf3 -Z single-flow AES-128-GCM runs in each direction over two directly connected 100-Gbit/s mlx5 ports, after a 10-second warm-up, compared direct consumption by the ovpn GRO callback with the same kernel in which ovpn declines every aggregate: Forward Reverse UDP segmentation 20.561 Gbit/s 20.498 Gbit/s Direct consumption 25.741 Gbit/s 25.150 Gbit/s Direct consumption improved throughput by 25.2% forward and 22.7% reverse, and reduced mean cycles per byte across the monitored data-path CPUs by 10.6% and 8.2%, respectively. Export skb_gro_receive_list, already shared by the core UDP and TCP frag-list GRO paths, so modular encapsulators can construct the same standard representation. Signed-off-by: Ralf Lici --- Changes since v2 https://lore.kernel.org/openvpn-devel/22dd867c764497525c4544c90fe08b23dbb6616e.1794329430.git.ralf@mandelbit.com/ - Restore the pre-encapsulation checksum bypass for accepted aggregates, since a tunnel can reset their checksum state. (Sashiko) Changes since v1 https://lore.kernel.org/openvpn-devel/19426aa5f9a5805f925014be8b057dc2fba335d7.1794314969.git.ralf@mandelbit.com/ - Drop the pre-encapsulation checksum bypass, made redundant by the previous patch. (Sashiko) - Check the inbound XFRM policy and reset conntrack state once for an accepted aggregate, and count all its datagrams on a drop. (Sashiko) - Read frag-list acceptance with acquire ordering and warn when setting up a socket which still accepts frag-lists. (Sashiko) - Require a declined aggregate to be left unmodified, without the allowance for layout-only pulls. include/linux/udp.h | 17 +++++++++ include/net/udp_tunnel.h | 1 + net/core/gro.c | 1 + net/ipv4/udp.c | 73 +++++++++++++++++++++++++++++++------- net/ipv4/udp_tunnel_core.c | 12 +++++++ net/ipv6/udp.c | 73 +++++++++++++++++++++++++++++++------- 6 files changed, 151 insertions(+), 26 deletions(-) diff --git a/include/linux/udp.h b/include/linux/udp.h index 998906ec3b32..cb3fd34d56f6 100644 --- a/include/linux/udp.h +++ b/include/linux/udp.h @@ -67,6 +67,10 @@ enum { UDP_FLAGS_ACCEPT_FRAGLIST, UDP_FLAGS_ACCEPT_L4, UDP_FLAGS_ENCAP_ENABLED, /* This socket enabled encap */ + /* encap_rcv accepts UDP L4 frag-list GSO. If it does not consume such + * an aggregate, it must leave it unmodified. + */ + UDP_FLAGS_ENCAP_ACCEPT_FRAGLIST, }; /* per NUMA structure for lockless producer usage. */ @@ -211,6 +215,19 @@ static inline bool udp_encap_needed(void) return false; } +static inline bool udp_encap_accepts_fraglist(struct sock *sk, + struct sk_buff *skb) +{ + /* pairs with set_mask_bits in setup_udp_tunnel_sock, so the callbacks + * published before acceptance are visible once it is observed + */ + return skb_is_gso(skb) && + skb_shinfo(skb)->gso_type == + (SKB_GSO_UDP_L4 | SKB_GSO_FRAGLIST) && + test_bit_acquire(UDP_FLAGS_ENCAP_ACCEPT_FRAGLIST, + &udp_sk(sk)->udp_flags); +} + static inline bool udp_unexpected_gso(struct sock *sk, struct sk_buff *skb) { if (!skb_is_gso(skb)) diff --git a/include/net/udp_tunnel.h b/include/net/udp_tunnel.h index 498b7b262fa9..a540e86d5f84 100644 --- a/include/net/udp_tunnel.h +++ b/include/net/udp_tunnel.h @@ -85,6 +85,7 @@ struct udp_tunnel_sock_cfg { void *sk_user_data; /* user data used by encap_rcv call back */ /* Used for setting up udp_sock fields, see udp.h for details */ __u8 encap_type; + unsigned long udp_flags; udp_tunnel_encap_rcv_t encap_rcv; udp_tunnel_encap_err_lookup_t encap_err_lookup; udp_tunnel_encap_err_rcv_t encap_err_rcv; diff --git a/net/core/gro.c b/net/core/gro.c index 1b033855a20d..1cac10516262 100644 --- a/net/core/gro.c +++ b/net/core/gro.c @@ -266,6 +266,7 @@ int skb_gro_receive_list(struct sk_buff *p, struct sk_buff *skb) return 0; } +EXPORT_SYMBOL(skb_gro_receive_list); static void gro_complete(struct gro_node *gro, struct sk_buff *skb) { diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 303d0102519a..cd209298012d 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -2383,6 +2383,29 @@ static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) return 0; } +/* Check the inbound policy and reset conntrack state, dropping the skb on + * failure. An accepted frag-list aggregate is checked once: its datagrams + * share the verdict, and a check after a fallback would lack the state which + * the first one consumed. + */ +static bool udp_queue_rcv_policy(struct sock *sk, struct sk_buff *skb, + bool encap_fraglist) +{ + if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) { + unsigned int segs = encap_fraglist ? + skb_shinfo(skb)->gso_segs : 1; + + __SNMP_ADD_STATS(sock_net(sk)->mib.udp_statistics, + UDP_MIB_INERRORS, segs); + numa_drop_add(&udp_sk(sk)->drop_counters, segs); + sk_skb_reason_drop(sk, skb, SKB_DROP_REASON_XFRM_POLICY); + return false; + } + nf_reset_ct(skb); + + return true; +} + /* returns: * -1: error * 0: success @@ -2391,7 +2414,8 @@ static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) * Note that in the success and error cases, the skb is assumed to * have either been requeued or freed. */ -static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) +static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb, + bool encap_fraglist) { enum skb_drop_reason drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; struct udp_sock *up = udp_sk(sk); @@ -2400,12 +2424,6 @@ static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) /* * Charge it to the socket, dropping if the queue is full. */ - if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) { - drop_reason = SKB_DROP_REASON_XFRM_POLICY; - goto drop; - } - nf_reset_ct(skb); - if (static_branch_unlikely(&udp_encap_needed_key) && READ_ONCE(up->encap_type)) { int (*encap_rcv)(struct sock *sk, struct sk_buff *skb); @@ -2424,14 +2442,25 @@ static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) /* if we're overly short, let UDP handle it */ encap_rcv = READ_ONCE(up->encap_rcv); if (encap_rcv) { + unsigned int segs = encap_fraglist ? + skb_shinfo(skb)->gso_segs : 1; int ret; - /* Verify checksum before giving to encap */ - if (udp_lib_checksum_complete(skb)) + /* Verify checksum before giving to encap. The header + * checksum of an accepted frag-list covers only its + * first datagram, so trust the GRO verdict instead, as + * udp_post_segment_fix_csum does after segmentation. + */ + if (!encap_fraglist && udp_lib_checksum_complete(skb)) goto csum_error; ret = encap_rcv(sk, skb); - if (ret <= 0) { + if (!ret) { + __SNMP_ADD_STATS(net->mib.udp_statistics, + UDP_MIB_INDATAGRAMS, segs); + return 0; + } + if (ret < 0 && !encap_fraglist) { __UDP_INC_STATS(net, UDP_MIB_INDATAGRAMS); return -ret; } @@ -2440,6 +2469,13 @@ static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) /* FALLTHROUGH -- it's a UDP Packet */ } + /* The encapsulator did not consume an aggregate it had opted into so + * we ask udp_queue_rcv_skb to retry after segmentation rather than + * exposing multiple datagrams to the socket as one. + */ + if (encap_fraglist) + return -EAGAIN; + prefetch(&sk->sk_rmem_alloc); if (rcu_access_pointer(sk->sk_filter) && udp_lib_checksum_complete(skb)) @@ -2466,11 +2502,18 @@ static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) static int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) { + bool encap_fraglist = udp_encap_accepts_fraglist(sk, skb); struct sk_buff *next, *segs; int ret; - if (likely(!udp_unexpected_gso(sk, skb))) - return udp_queue_rcv_one_skb(sk, skb); + if (likely(encap_fraglist || !udp_unexpected_gso(sk, skb))) { + if (!udp_queue_rcv_policy(sk, skb, encap_fraglist)) + return -1; + + ret = udp_queue_rcv_one_skb(sk, skb, encap_fraglist); + if (likely(ret != -EAGAIN)) + return ret; + } BUILD_BUG_ON(sizeof(struct udp_skb_cb) > SKB_GSO_CB_OFFSET); __skb_push(skb, -skb_mac_offset(skb)); @@ -2479,7 +2522,11 @@ static int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) __skb_pull(skb, skb_transport_offset(skb)); udp_post_segment_fix_csum(skb); - ret = udp_queue_rcv_one_skb(sk, skb); + /* datagrams of a declined aggregate share its verdict */ + if (!encap_fraglist && !udp_queue_rcv_policy(sk, skb, false)) + continue; + + ret = udp_queue_rcv_one_skb(sk, skb, false); if (ret > 0) ip_protocol_deliver_rcu(dev_net(skb->dev), skb, ret); } diff --git a/net/ipv4/udp_tunnel_core.c b/net/ipv4/udp_tunnel_core.c index a128fe85620d..c023344891a2 100644 --- a/net/ipv4/udp_tunnel_core.c +++ b/net/ipv4/udp_tunnel_core.c @@ -71,6 +71,13 @@ static bool sk_saddr_any(struct sock *sk) void setup_udp_tunnel_sock(struct net *net, struct sock *sk, struct udp_tunnel_sock_cfg *cfg) { + const unsigned long allowed = BIT(UDP_FLAGS_ENCAP_ACCEPT_FRAGLIST); + unsigned long flags = cfg->udp_flags & allowed; + + WARN_ON_ONCE(cfg->udp_flags & ~allowed); + /* a socket must stop accepting frag-lists before it is set up again */ + WARN_ON_ONCE(udp_test_bit(ENCAP_ACCEPT_FRAGLIST, sk)); + /* Disable multicast loopback */ inet_clear_bit(MC_LOOP, sk); @@ -87,6 +94,11 @@ void setup_udp_tunnel_sock(struct net *net, struct sock *sk, udp_sk(sk)->gro_receive = cfg->gro_receive; udp_sk(sk)->gro_complete = cfg->gro_complete; + /* Publish frag-list acceptance only after the callbacks which consume + * that representation + */ + set_mask_bits(&udp_sk(sk)->udp_flags, allowed, flags); + udp_tunnel_encap_enable(sk); udp_tunnel_update_gro_rcv(sk, true); diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 59f9872c3552..d678d998e180 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -810,18 +810,36 @@ static int __udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) return 0; } -static int udpv6_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) +/* Check the inbound policy and reset conntrack state, dropping the skb on + * failure. An accepted frag-list aggregate is checked once: its datagrams + * share the verdict, and a check after a fallback would lack the state which + * the first one consumed. + */ +static bool udpv6_queue_rcv_policy(struct sock *sk, struct sk_buff *skb, + bool encap_fraglist) { - enum skb_drop_reason drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; - struct udp_sock *up = udp_sk(sk); - struct net *net = sock_net(sk); - if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) { - drop_reason = SKB_DROP_REASON_XFRM_POLICY; - goto drop; + unsigned int segs = encap_fraglist ? + skb_shinfo(skb)->gso_segs : 1; + + __SNMP_ADD_STATS(sock_net(sk)->mib.udp_stats_in6, + UDP_MIB_INERRORS, segs); + numa_drop_add(&udp_sk(sk)->drop_counters, segs); + sk_skb_reason_drop(sk, skb, SKB_DROP_REASON_XFRM_POLICY); + return false; } nf_reset_ct(skb); + return true; +} + +static int udpv6_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb, + bool encap_fraglist) +{ + enum skb_drop_reason drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; + struct udp_sock *up = udp_sk(sk); + struct net *net = sock_net(sk); + if (static_branch_unlikely(&udpv6_encap_needed_key) && READ_ONCE(up->encap_type)) { int (*encap_rcv)(struct sock *sk, struct sk_buff *skb); @@ -840,14 +858,25 @@ static int udpv6_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) /* if we're overly short, let UDP handle it */ encap_rcv = READ_ONCE(up->encap_rcv); if (encap_rcv) { + unsigned int segs = encap_fraglist ? + skb_shinfo(skb)->gso_segs : 1; int ret; - /* Verify checksum before giving to encap */ - if (udp_lib_checksum_complete(skb)) + /* Verify checksum before giving to encap. The header + * checksum of an accepted frag-list covers only its + * first datagram, so trust the GRO verdict instead, as + * udp_post_segment_fix_csum does after segmentation. + */ + if (!encap_fraglist && udp_lib_checksum_complete(skb)) goto csum_error; ret = encap_rcv(sk, skb); - if (ret <= 0) { + if (!ret) { + __SNMP_ADD_STATS(net->mib.udp_stats_in6, + UDP_MIB_INDATAGRAMS, segs); + return 0; + } + if (ret < 0 && !encap_fraglist) { __UDP6_INC_STATS(net, UDP_MIB_INDATAGRAMS); return -ret; } @@ -856,6 +885,13 @@ static int udpv6_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) /* FALLTHROUGH -- it's a UDP Packet */ } + /* The encapsulator did not consume an aggregate it had opted into so + * we ask udpv6_queue_rcv_skb to retry after segmentation rather than + * exposing multiple datagrams to the socket as one. + */ + if (encap_fraglist) + return -EAGAIN; + prefetch(&sk->sk_rmem_alloc); if (rcu_access_pointer(sk->sk_filter) && udp_lib_checksum_complete(skb)) @@ -883,11 +919,18 @@ static int udpv6_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) static int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) { + bool encap_fraglist = udp_encap_accepts_fraglist(sk, skb); struct sk_buff *next, *segs; int ret; - if (likely(!udp_unexpected_gso(sk, skb))) - return udpv6_queue_rcv_one_skb(sk, skb); + if (likely(encap_fraglist || !udp_unexpected_gso(sk, skb))) { + if (!udpv6_queue_rcv_policy(sk, skb, encap_fraglist)) + return -1; + + ret = udpv6_queue_rcv_one_skb(sk, skb, encap_fraglist); + if (likely(ret != -EAGAIN)) + return ret; + } __skb_push(skb, -skb_mac_offset(skb)); segs = udp_rcv_segment(sk, skb, false); @@ -895,7 +938,11 @@ static int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) __skb_pull(skb, skb_transport_offset(skb)); udp_post_segment_fix_csum(skb); - ret = udpv6_queue_rcv_one_skb(sk, skb); + /* datagrams of a declined aggregate share its verdict */ + if (!encap_fraglist && !udpv6_queue_rcv_policy(sk, skb, false)) + continue; + + ret = udpv6_queue_rcv_one_skb(sk, skb, false); if (ret > 0) ip6_protocol_deliver_rcu(dev_net(skb->dev), skb, ret, true); From patchwork Wed Nov 11 09:22:35 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5666 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:529c:b0:11a:a05e:cb97 with SMTP id x28csp179338lax; Wed, 11 Nov 2026 01:23:09 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHDDFZBk4ZA9WZ++lL4CSNASIs4ZDIiKytjNi24gojavGFFYRRaLs3Txe5IotMldu+Be235KewBtVM=@openvpn.net X-Received: by 2002:a05:7300:bf91:b0:372:fa14:8b6c with SMTP id 5a478bee46e88-37685d7532amr2812182eec.19.1794388988674; Wed, 11 Nov 2026 01:23:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794388988; cv=none; d=google.com; s=arc-20260327; b=Kka+uLZ1xIWu9mUO1PJz2zmikcOaD6dvXhNq31qU9RI5BPPefR+gg25gzD/9Xg98Ai j/h8nBROlkcpIM6ZiANUdQTK9dqDFXrpRdZRGBkjKcdaqm7DfrwcMl4YDjbHiMDSye/K 6eRe4rIM1mY7DbFSle1O5iRnkIfyzumlMQmjk7X135OjcFkukEkI5xyLPkrNt3ZU6iIu tqUkDVKN24TDE4kIz++ss5+9UohEOWH+EUdMTG6XpjxYNQ/MMypY1HvYHd3dbflU59ZK j8Hj6Se5wE89tOAMRDfzmm/q5IrSXk7wgzLeYpZBshPtqSfQ6g09ca9XUpoTq25G38I0 ksdg== 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=g5fr8icRy1MupMZ5crWEDjoirxxMMRUwVimPagPQGog=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=LWf1xhjv30kbKYZxnIqhcpcA6c77qUdj/0d7nPxbxNhw3uOULFRhQ+gqw+D4bCWCKi s72jV7oWm94u5HWST61RYUa1A2EPo62H1O2wzgTePA7lLCs6/ZIGpGmyFuaSj2evZ5HQ 6JepUVdotVIRz4CdfLsK9rE84Dt0FfoPvod/LFeBFugXf9/tyrFjb0ZWxQMgp+fOCS2/ C7Wy/ac1BSPVBb0NkJta0yJlAhuMk1EryzL8gcDrydULpvOT63R/MYP1qdVm2ET+g+aw iLbCXIw1B0Jg66E/GcL7QhFxh13RwBdzFrqowIUc3DuMLoKArhZykYXtJzjeLO3gql7F DyBg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=DVuqDVQ1; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=TgIlE3lT; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="VKj/nA7x"; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=1aENigcm; 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-375214db1c2si13806364eec.59.2026.11.11.01.23.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Nov 2026 01:23:08 -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=DVuqDVQ1; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=TgIlE3lT; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="VKj/nA7x"; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=1aENigcm; 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=g5fr8icRy1MupMZ5crWEDjoirxxMMRUwVimPagPQGog=; b=DVuqDVQ1OpO6s2 K1plCRvjpBEuN2lPhCljA0u3pivA1zJFVyPpHwD5GsQESmSAPtHAZcXosTsaBUq5jBm+vHjKatFXE gUJtaFVr+oh3P9+lzHdMfazrNOK+lmD2x+SxgsREo28NzdrUEtFeYWELQpiGF/v6lcu9oH6VAIu9b uPY=; 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 1xR4Xr-000000007jz-3EGK; Wed, 11 Nov 2026 09:23:07 +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 1xR4Xo-000000007iq-3528 for openvpn-devel@lists.sourceforge.net; Wed, 11 Nov 2026 09:23:04 +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=nWGBoFuVw8sf3M2NuYrXemkmZ4y5KR8dGdrejn80+aU=; b=TgIlE3lT+yc1h9jYH+Xwm8aLJY R1Bnyda1H2xgbOFYm9b1z91z3W4SUYnI+G6dtRHQnXqtrkH6s3DBb7rNUfVB5Bo9gLc4T3flSi74H mCQyMVOWc2scazjWLQgSBCfPMc7ZcTkZhK+IFqiInWKlKXvz7md0psaCUfyFpKiD6+Ic=; 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=nWGBoFuVw8sf3M2NuYrXemkmZ4y5KR8dGdrejn80+aU=; b=VKj/nA7xtlHP619umz8xLdVnQe 73b+LQpTJT+BNUCRaz0z1ZCoWfs3wf84WMO1Ns5q+QmW+nYYh8v3laeNW9uuIPumetbn9mlAo7i0c C3lgK/uUf6zSA+fhMAigbcISu1Sut0xZXBqjVGwAV6L2p402RDKClFEXzTuY8gNipYkc=; Received: from mout-b-107.mailbox.org ([195.10.208.47]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xR4Xk-000000000Gz-1LPp for openvpn-devel@lists.sourceforge.net; Wed, 11 Nov 2026 09:23:04 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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-107.mailbox.org (Postfix) with ESMTPS id 4jPdND0CGHz3xgc for ; Wed, 11 Nov 2026 10:22:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794388972; 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=nWGBoFuVw8sf3M2NuYrXemkmZ4y5KR8dGdrejn80+aU=; b=1aENigcmK1eK7/Fssp2UEDFbJEHaui9ERSe2gxU26IjwndqNQYoMYyLVwOt9dppFm0Qjjx 3QgCzS8CJ0jVWynF+ysPL7X1kyetDJi9/KZ5B8jb3nHJvk6bpC2gozo4JsmvpNgO3ifyGP R04EvYZKrvTlcPmjSbTwvpSouWAQDHoiudP71OoyvP7lsJusGLGrytKM5fpHLWtWjWFuZE pK4b3pLun/mFtk1fPA3Q4joGeZYs58KUQlnUo474fqy3iWjMLJJYpV1IL/xHxvzQXexvLl Rx6IZM20VqdGO2a3Ok8YwQasdfqQ8Ddb+SFeJ3rYjZ8p1YJQTmF0B67VFIs3Uw== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::202 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Wed, 11 Nov 2026 10:22:35 +0100 Message-ID: <273ffd1c70b54e1075366166e0f80310f85c55e8.1794388607.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jPdND0CGHz3xgc 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 tunnel GRO callbacks normally remain installed until their socket is destroyed. This permits the tunnel callback registry to use one callback as a global static-call target when only one tunnel ty [...] 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_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 X-Headers-End: 1xR4Xk-000000000Gz-1LPp Subject: [Openvpn-devel] [PATCH ovpn net-next v3 3/6] udp_tunnel: support detachable GRO receive callbacks 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: 1881553228127692476 X-GMAIL-MSGID: 1881553228127692476 UDP tunnel GRO callbacks normally remain installed until their socket is destroyed. This permits the tunnel callback registry to use one callback as a global static-call target when only one tunnel type is active. A userspace-owned socket can instead outlive its association with an encapsulator. Allow a receive callback which produces only standard UDP frag-list GSO to opt out of the callback registry and be detached while the socket remains live. Such aggregates need no tunnel completion callback and remain valid after detach. The socket must not already have a GRO callback, which would stay pinned in the registry. Publish the detachable dispatch mode before the callback, then publish frag-list acceptance only after all callbacks which consume that representation. Load each callback once before invocation. Provide a helper which removes the socket from GRO lookup, clears its callbacks and frag-list acceptance, and waits for in-flight network readers before retiring detachable dispatch mode. Keep the helper in udp_offload.c, which is built into the UDP stack even when NET_UDP_TUNNEL is a module, so built-in callers do not gain a dependency on udp_tunnel.ko. Existing tunnel sockets retain the static-call path and semantics. Signed-off-by: Ralf Lici --- No changes since v2 https://lore.kernel.org/openvpn-devel/a98eab82229da1233a8debbe146feddc57e87c10.1794329430.git.ralf@mandelbit.com/ Changes since v1 https://lore.kernel.org/openvpn-devel/a648e3aea95cdd32b6411a2a920ada54905ba293.1794314969.git.ralf@mandelbit.com/ - Warn if a detachable socket already has a GRO callback, which would stay pinned in the registry. (Sashiko) include/linux/udp.h | 1 + include/net/udp_tunnel.h | 2 ++ net/ipv4/udp_offload.c | 59 +++++++++++++++++++++++++++++++++----- net/ipv4/udp_tunnel_core.c | 29 ++++++++++++++++--- 4 files changed, 80 insertions(+), 11 deletions(-) diff --git a/include/linux/udp.h b/include/linux/udp.h index cb3fd34d56f6..3ae7ef796abb 100644 --- a/include/linux/udp.h +++ b/include/linux/udp.h @@ -71,6 +71,7 @@ enum { * an aggregate, it must leave it unmodified. */ UDP_FLAGS_ENCAP_ACCEPT_FRAGLIST, + UDP_FLAGS_GRO_RCV_DETACHABLE, /* gro_receive may be detached */ }; /* per NUMA structure for lockless producer usage. */ diff --git a/include/net/udp_tunnel.h b/include/net/udp_tunnel.h index a540e86d5f84..3a137901c88b 100644 --- a/include/net/udp_tunnel.h +++ b/include/net/udp_tunnel.h @@ -211,10 +211,12 @@ static inline int udp_tunnel_handle_offloads(struct sk_buff *skb, bool udp_csum) #if IS_ENABLED(CONFIG_NET_UDP_TUNNEL) void udp_tunnel_update_gro_lookup(struct net *net, struct sock *sk, bool add); void udp_tunnel_update_gro_rcv(struct sock *sk, bool add); +void udp_tunnel_detach_gro(struct sock *sk); #else static inline void udp_tunnel_update_gro_lookup(struct net *net, struct sock *sk, bool add) {} static inline void udp_tunnel_update_gro_rcv(struct sock *sk, bool add) {} +static inline void udp_tunnel_detach_gro(struct sock *sk) {} #endif static inline void udp_tunnel_cleanup_gro(struct sock *sk) diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index 572a65cd8977..61b4e226d091 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -82,6 +82,10 @@ void udp_tunnel_update_gro_rcv(struct sock *sk, bool add) struct udp_sock *up = udp_sk(sk); int i, old_gro_type_nr; + /* Dynamically detached callbacks cannot be static-call targets. */ + if (udp_test_bit(GRO_RCV_DETACHABLE, sk)) + return; + if (!UDP_MAX_TUNNEL_TYPES || !up->gro_receive) return; @@ -144,10 +148,45 @@ void udp_tunnel_update_gro_rcv(struct sock *sk, bool add) } EXPORT_SYMBOL_GPL(udp_tunnel_update_gro_rcv); +/** + * udp_tunnel_detach_gro - detach GRO callbacks from a live UDP socket + * @sk: UDP tunnel socket + * + * The caller must hold the socket lock and keep callback state alive until + * this function returns. + */ +void udp_tunnel_detach_gro(struct sock *sk) +{ + sock_owned_by_me(sk); + + if (WARN_ON_ONCE(!udp_test_bit(GRO_RCV_DETACHABLE, sk))) + return; + + udp_tunnel_update_gro_lookup(sock_net(sk), sk, false); + WRITE_ONCE(udp_sk(sk)->gro_receive, NULL); + WRITE_ONCE(udp_sk(sk)->gro_complete, NULL); + /* No new frag-list aggregates can be formed after gro_receive is + * cleared. Any aggregate already held by GRO may safely be segmented + * before encap_rcv. + */ + udp_clear_bit(ENCAP_ACCEPT_FRAGLIST, sk); + + /* Readers which captured a callback before it was cleared must keep + * bypassing the static-call path until they have completed. + */ + synchronize_net(); + udp_clear_bit(GRO_RCV_DETACHABLE, sk); +} +EXPORT_SYMBOL_GPL(udp_tunnel_detach_gro); + static struct sk_buff *udp_tunnel_gro_rcv(struct sock *sk, + udp_tunnel_gro_receive_t gro_receive, struct list_head *head, struct sk_buff *skb) { + if (unlikely(udp_test_bit(GRO_RCV_DETACHABLE, sk))) + return call_gro_receive_sk(gro_receive, sk, head, skb); + if (static_branch_likely(&udp_tunnel_static_call)) { if (unlikely(gro_recursion_inc_test(skb))) { NAPI_GRO_CB(skb)->flush |= 1; @@ -155,16 +194,17 @@ static struct sk_buff *udp_tunnel_gro_rcv(struct sock *sk, } return static_call(udp_tunnel_gro_rcv)(sk, head, skb); } - return call_gro_receive_sk(udp_sk(sk)->gro_receive, sk, head, skb); + return call_gro_receive_sk(gro_receive, sk, head, skb); } #else static struct sk_buff *udp_tunnel_gro_rcv(struct sock *sk, + udp_tunnel_gro_receive_t gro_receive, struct list_head *head, struct sk_buff *skb) { - return call_gro_receive_sk(udp_sk(sk)->gro_receive, sk, head, skb); + return call_gro_receive_sk(gro_receive, sk, head, skb); } #endif @@ -776,6 +816,7 @@ static struct sk_buff *udp_gro_receive_segment(struct list_head *head, struct sk_buff *udp_gro_receive(struct list_head *head, struct sk_buff *skb, struct udphdr *uh, struct sock *sk) { + udp_tunnel_gro_receive_t gro_receive = NULL; struct sk_buff *pp = NULL; struct sk_buff *p; struct udphdr *uh2; @@ -794,7 +835,9 @@ struct sk_buff *udp_gro_receive(struct list_head *head, struct sk_buff *skb, * cases. Such packets should be caught in udp_unexpected_gso later. */ NAPI_GRO_CB(skb)->is_flist = 0; - if (!sk || !udp_sk(sk)->gro_receive) { + if (sk) + gro_receive = READ_ONCE(udp_sk(sk)->gro_receive); + if (!gro_receive) { /* If the packet was locally encapsulated in a UDP tunnel that * wasn't detected above, do not GRO. */ @@ -841,7 +884,7 @@ struct sk_buff *udp_gro_receive(struct list_head *head, struct sk_buff *skb, skb_gro_pull(skb, sizeof(struct udphdr)); /* pull encapsulating udp header */ skb_gro_postpull_rcsum(skb, uh, sizeof(struct udphdr)); - pp = udp_tunnel_gro_rcv(sk, head, skb); + pp = udp_tunnel_gro_rcv(sk, gro_receive, head, skb); out: skb_gro_flush_final(skb, pp, flush); @@ -920,6 +963,7 @@ int udp_gro_complete(struct sk_buff *skb, int nhoff, { struct udphdr *uh = (struct udphdr *)(skb->data + nhoff); unsigned int newlen = skb->len - nhoff; + udp_tunnel_gro_complete_t gro_complete = NULL; struct sock *sk; int err; @@ -927,7 +971,9 @@ int udp_gro_complete(struct sk_buff *skb, int nhoff, sk = INDIRECT_CALL_INET(lookup, udp6_lib_lookup_skb, udp4_lib_lookup_skb, skb, uh->source, uh->dest); - if (sk && udp_sk(sk)->gro_complete) { + if (sk) + gro_complete = READ_ONCE(udp_sk(sk)->gro_complete); + if (gro_complete) { skb_shinfo(skb)->gso_type = uh->check ? SKB_GSO_UDP_TUNNEL_CSUM : SKB_GSO_UDP_TUNNEL; @@ -940,8 +986,7 @@ int udp_gro_complete(struct sk_buff *skb, int nhoff, * functions to make them set up the inner offsets. */ skb->encapsulation = 1; - err = udp_sk(sk)->gro_complete(sk, skb, - nhoff + sizeof(struct udphdr)); + err = gro_complete(sk, skb, nhoff + sizeof(struct udphdr)); } else { err = udp_gro_complete_segment(skb); } diff --git a/net/ipv4/udp_tunnel_core.c b/net/ipv4/udp_tunnel_core.c index c023344891a2..426c5e4ac583 100644 --- a/net/ipv4/udp_tunnel_core.c +++ b/net/ipv4/udp_tunnel_core.c @@ -71,12 +71,28 @@ static bool sk_saddr_any(struct sock *sk) void setup_udp_tunnel_sock(struct net *net, struct sock *sk, struct udp_tunnel_sock_cfg *cfg) { - const unsigned long allowed = BIT(UDP_FLAGS_ENCAP_ACCEPT_FRAGLIST); + const unsigned long allowed = BIT(UDP_FLAGS_GRO_RCV_DETACHABLE) | + BIT(UDP_FLAGS_ENCAP_ACCEPT_FRAGLIST); unsigned long flags = cfg->udp_flags & allowed; WARN_ON_ONCE(cfg->udp_flags & ~allowed); /* a socket must stop accepting frag-lists before it is set up again */ WARN_ON_ONCE(udp_test_bit(ENCAP_ACCEPT_FRAGLIST, sk)); + set_mask_bits(&udp_sk(sk)->udp_flags, BIT(UDP_FLAGS_GRO_RCV_DETACHABLE), + flags & BIT(UDP_FLAGS_GRO_RCV_DETACHABLE)); + if (flags & BIT(UDP_FLAGS_GRO_RCV_DETACHABLE)) { + WARN_ON_ONCE(cfg->gro_complete || + !(flags & BIT(UDP_FLAGS_ENCAP_ACCEPT_FRAGLIST))); + /* the registry ignores detachable sockets, so a callback which + * is already registered there would stay pinned + */ + WARN_ON_ONCE(udp_sk(sk)->gro_receive); + /* The socket may already be receiving packets so drain readers + * which could have observed the old dispatch mode before + * publishing the detachable callback. + */ + synchronize_net(); + } /* Disable multicast loopback */ inet_clear_bit(MC_LOOP, sk); @@ -91,13 +107,18 @@ void setup_udp_tunnel_sock(struct net *net, struct sock *sk, udp_sk(sk)->encap_err_rcv = cfg->encap_err_rcv; udp_sk(sk)->encap_err_lookup = cfg->encap_err_lookup; udp_sk(sk)->encap_destroy = cfg->encap_destroy; - udp_sk(sk)->gro_receive = cfg->gro_receive; - udp_sk(sk)->gro_complete = cfg->gro_complete; + WRITE_ONCE(udp_sk(sk)->gro_complete, cfg->gro_complete); + /* Publish receive after the completion callback which its aggregates + * may later require + */ + WRITE_ONCE(udp_sk(sk)->gro_receive, cfg->gro_receive); /* Publish frag-list acceptance only after the callbacks which consume * that representation */ - set_mask_bits(&udp_sk(sk)->udp_flags, allowed, flags); + set_mask_bits(&udp_sk(sk)->udp_flags, + BIT(UDP_FLAGS_ENCAP_ACCEPT_FRAGLIST), + flags & BIT(UDP_FLAGS_ENCAP_ACCEPT_FRAGLIST)); udp_tunnel_encap_enable(sk); From patchwork Wed Nov 11 09:22:36 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5665 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:529c:b0:11a:a05e:cb97 with SMTP id x28csp179311lax; Wed, 11 Nov 2026 01:23:07 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHf1yDRY+3o9g+hGJDapa4JCeIlITygnDLIRZ33dkg1EcH+in7xVSwEno9wCV19L7oWX3vZ+L29Guc=@openvpn.net X-Received: by 2002:a05:701b:42c7:20b0:149:1b5b:1f25 with SMTP id a92af1059eb24-1b3c02f369dmr1840799c88.15.1794388987490; Wed, 11 Nov 2026 01:23:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794388987; cv=none; d=google.com; s=arc-20260327; b=eZa5fYIsrcKKLk35z3tQxgbKnSvOTEKp/XBmAzJ6Xn0Gg09MHE2fwXWQK2EeujkV0/ DOFpqBIPY4VqgsSxru6giKxWq64svkbrsr0GLZN2HaOXQsfpaFlMfSNd/BsA6Uk64kjc NQp0oMw3qQw7NnqGD9NdKgTB4JEQ45RvLnu5IG/18E+PBspFcHwXsoqwNtGWY/s+Pf8k dQ7jFRlqRqxgtrXmNNtvdRgapzbKnrGz9or3cIw273mS1c/WtJ0TMLWj43Mri7xvy4FS mIEfaVC6caAh6cdnlVMrEMO9BHr0DFdRkUSJCCcL8QmBBHIVSTqklT1BjSEJRrrOtPtT woVA== 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=O3vyv5ihnOqPjNs/wWsASCyZZy4BWA3V/ecolNEBnbk=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=FiokmA9p55cHZRELI2nNPFKc35Yekcxi+/W2B3/pTKsS8yujl7Pnyvxc6MZBn9KF90 wJTfvbeiro+1Za5a2sQUdaeBxtj84sQlJoI/tQvFdGRh/GVScOaSFP9kEe/kckWO9T/7 9vS3VXi+P/jMgkt92kfxgroNeE0e5BV9LcUaTz4vbZtUInnYuqdDWq506RvGjCN7N0QG XUjZNohD928hRMErmxF8jeazm0ltpN+8dxFs+Yp/pgPeBqeiogUPftbQKvdUfSxOD5By VVb/3Picu0sc8HcJyEDVZo3urLE7KJZVaqdPFLDA97Vp78k55O+3KoMRzoMgwKC9Cqa/ 8sZA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=HoDiIX3V; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=lj6BLI2g; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=GspAkH5J; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=LV5QsXdy; 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-1b3b5b85c2dsi11861202c88.52.2026.11.11.01.23.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Nov 2026 01:23:07 -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=HoDiIX3V; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=lj6BLI2g; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=GspAkH5J; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=LV5QsXdy; 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=O3vyv5ihnOqPjNs/wWsASCyZZy4BWA3V/ecolNEBnbk=; b=HoDiIX3VnupInW P1NfnT/rxYKEcZvWhqXU+AlSTHjmkjk6spi/v1EN/rlT6BnOHw0RmXOtTrPd63WvtIPQ/K0y2f8Ky 3mZc9A6n6lpSiNJEtKMkTuWkZ3r1jxqKP6BA8+nunW+r1UxeIItHe7bLLeoMn4rQzF6m8KrcWq1AT ehI=; 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 1xR4Xq-000000005FC-1lsd; Wed, 11 Nov 2026 09:23:06 +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 1xR4Xo-000000005En-49l9 for openvpn-devel@lists.sourceforge.net; Wed, 11 Nov 2026 09:23:05 +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=NWxzyACZrjKlNEi9Ekvf5Xkk8zf9Lmdth5Lz3f1rzZg=; b=lj6BLI2gsyCDttpm7rRKcIV67U UInArHMLlWzYM7Pwa2YCBubm48dYptFuAYc8gpGxU68To77lLVOQhqZfklRi5bm9Qwa6owYqZvZYt 7UefIkYcz+i30L8HoUc0fDmTmXtIAqcg+M6L1hrgJIzmVXBRikzj7QDqXf4Fsoj5ViOE=; 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=NWxzyACZrjKlNEi9Ekvf5Xkk8zf9Lmdth5Lz3f1rzZg=; b=GspAkH5J+zLnA9B+hycKWfElV2 tGVH7lbeqQNHpbjxDLLN1tOeUZ7IVR2EbGk7ycn5QMtjIydCD9QgJkywHufSiduiKaaOCIws2xYLe fFVmCcfKZhpvSv/m8hDeYtU1GkElQQL0oBbJhmkUKjVLJ537/DwliWs628Z3OxZkHbPo=; Received: from mout-b-202.mailbox.org ([195.10.208.62]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xR4Xk-000000000H0-2YtM for openvpn-devel@lists.sourceforge.net; Wed, 11 Nov 2026 09:23:04 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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 4jPdND48DMzKnht for ; Wed, 11 Nov 2026 10:22:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794388972; 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=NWxzyACZrjKlNEi9Ekvf5Xkk8zf9Lmdth5Lz3f1rzZg=; b=LV5QsXdyFO7btNoGrWvglJlSwg5JVvY9RluYO6xybS++lnvA0uI0jFdQj/J2kQRLeqV/mo U7fGIoLN0JXjsvxEui4pZSnaYkMiQQstQZ5jLJv3Fr8xy+kzGzbJ6O/lud+6RdEU/3t+d7 U8r9KpvZrNiMqYHENbvpbLRwf5+yKDDVZtMRSFIf9cjPh5ogfDz1HtuX25PaiqV01NA5G8 CFhVz5Ld608JiuTukz6uxmCumsOatqhElySMjKEHNf+4RmLeWVXHD2K0tuQOMWGciM1WtI U538R24LYGwYJ3tDp479JBIQ3IqhSC54qvaaH0mf0asYscst5ukGrUHe+0mcMw== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::202 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Wed, 11 Nov 2026 10:22:36 +0100 Message-ID: <2efa96ff65307b419ee319e91eccd064db50aa27.1794388607.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jPdND48DMzKnht 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: A UDP socket may retain a detachable tunnel GRO callback while it remains visible to userspace. If userspace subsequently changes UDP_ENCAP, replacing the encapsulation callbacks without first retirin [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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 Message has at least one valid DKIM or DK signature X-Headers-End: 1xR4Xk-000000000H0-2YtM Subject: [Openvpn-devel] [PATCH ovpn net-next v3 4/6] udp: detach tunnel GRO before changing UDP encapsulation 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: 1881553227034091383 X-GMAIL-MSGID: 1881553227034091383 A UDP socket may retain a detachable tunnel GRO callback while it remains visible to userspace. If userspace subsequently changes UDP_ENCAP, replacing the encapsulation callbacks without first retiring GRO leaves the old callback lifetime and frag-list acceptance state active. Validate the requested encapsulation type, then detach such a GRO callback before installing the new encapsulation implementation. Existing sockets are unaffected because no current user enables detachable GRO callbacks. UDP_ENCAP already permits userspace to change the encapsulation type of a live socket even when driver state remains attached to it. Resolving that pre-existing ownership issue is outside the scope of this change. This only keeps detachable GRO state and callback lifetimes consistent when the existing transition occurs; it does not make cross-encapsulator ownership handoff supported. Signed-off-by: Ralf Lici --- No changes since v2 https://lore.kernel.org/openvpn-devel/26279b0076d6ad26368041341247897fc1e95f08.1794329430.git.ralf@mandelbit.com/ No changes since v1 https://lore.kernel.org/openvpn-devel/99b9cccf9845899bc36e92165d9443499fe8a284.1794314969.git.ralf@mandelbit.com/ net/ipv4/udp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index cd209298012d..913897888bbb 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -3023,6 +3023,9 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname, case 0: #ifdef CONFIG_XFRM case UDP_ENCAP_ESPINUDP: + if (udp_test_bit(GRO_RCV_DETACHABLE, sk)) + udp_tunnel_detach_gro(sk); + set_xfrm_gro_udp_encap_rcv(val, sk->sk_family, sk); #if IS_ENABLED(CONFIG_IPV6) if (sk->sk_family == AF_INET6) @@ -3035,6 +3038,9 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname, #endif fallthrough; case UDP_ENCAP_L2TPINUDP: + if (udp_test_bit(GRO_RCV_DETACHABLE, sk)) + udp_tunnel_detach_gro(sk); + WRITE_ONCE(up->encap_type, val); udp_tunnel_encap_enable(sk); break; From patchwork Wed Nov 11 09:22:37 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5667 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:529c:b0:11a:a05e:cb97 with SMTP id x28csp179349lax; Wed, 11 Nov 2026 01:23:09 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErH89QR7OUYLJgBlTEvP/wEgvkwIt01y8/bkyYpJ9VWj81wgzLcrNEOW7gauvJEoctGjl/UwdEZtMm4=@openvpn.net X-Received: by 2002:a05:7022:b88c:b0:1b3:b3d5:566f with SMTP id a92af1059eb24-1b3c03535cfmr1689969c88.11.1794388988939; Wed, 11 Nov 2026 01:23:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794388988; cv=none; d=google.com; s=arc-20260327; b=JpTOoGpNxhwwuWPlVwvsNLPzDvofkmU3Ac42Tu9Xr+tZKXkTQdT55wj9+JboN6UeOX l/DM5yKz0tpdy3zALcAK7uUl83f/i/ynIyM/Rtrkcqfe+oXDqplmMBGFZkvAlLf83RxC jtia5P8ij0Fcq0184dTmPcHodtns2XvKYPRoom5FjLCrfsjP/LvphWn+j4c/59rjMZKT 5z479mEKTs5OwrH1K+4tFwIr41GY/PuQMufNHkkudSXsyZtMhYmx3ux5fZSQY5MvUfD3 P43tbSExQbtXeQfZXMpCuK5UcTd9CUmdmG8okpSAvc2+fV/EliNznqgk1FGRrb1qPZOg PBLQ== 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=h+U6KRhoh8Os1Cibi8lI0fnxblRiqbFWo+vjGhCaRN0=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=aihy0PBvB8xu1SFf43q8y+xESN0LYtVj0hnQ/ADvSeSQJnKNO/6Z76fSYA62vBLsSo 2ZpNzJYd5MMUz6/40ZgLZ4g1B8YGW/T00C65iZc60nWKM/15aIoyWw1MR5fdm11mr8yJ h4wIrq9S43um3LY91r7lFGIL/OQ/0FJcP4McOWmE9rCsTEo/RGCv3D+73VsS+M93TLgN 57Ie8zd2bqG7ZccmEDOdMT3+HaSwUi6IlNNzHcosZmhpmJkYMAMC/2rISk4zF6UqbUnp ekZIjd5oS9Q+xZdOdpBkPKejZiQ89up4abdVy7VNLBI4efzr2aq9p0L9ZCL2JoO6VLXH nSpQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=e6oOmlQk; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=PUUslnRC; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=lb7jJ6qD; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=1ddtzM33; 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-1b3b5b5b3d2si12161356c88.24.2026.11.11.01.23.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Nov 2026 01:23:08 -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=e6oOmlQk; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=PUUslnRC; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=lb7jJ6qD; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=1ddtzM33; 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=h+U6KRhoh8Os1Cibi8lI0fnxblRiqbFWo+vjGhCaRN0=; b=e6oOmlQksGAxN4 OK/uY44xWMlYJmfBJULfQVR2wxuZZeFih8MEofYYiAsFzszVUqxmjVJ9bRaRCR1N2yW6+TsHsB2Bu fn2NlpSjT/sajbapZRYvZ5Ewq83FNwpJXK9SxFDEU+9UIjful3snmFxbICfm/VpjEcnR+S4/sNn/Z 2b0=; 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 1xR4Xr-000000003GX-3WiK; Wed, 11 Nov 2026 09:23:07 +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 1xR4Xp-000000003G2-2KCe for openvpn-devel@lists.sourceforge.net; Wed, 11 Nov 2026 09:23:05 +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=3zeY0gWPKuL4F9+3wikbp6LY0irXgWjcnzKxjkhZGhc=; b=PUUslnRCKd/ZF12/y+HhqO8hdb XLjzv1uiTS1Zo+R50pWI/VFLfKWc9llnIxWaIvsFac8oo/3eAKX8SyaiKaULMURJAPil4bZTTzr/x TRJgb2yny6pwC4iUAXSnh1LTtk2W4nAiEn42uPFZmSU5kYyhszT0C1iiF0ZbY/slu20o=; 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=3zeY0gWPKuL4F9+3wikbp6LY0irXgWjcnzKxjkhZGhc=; b=lb7jJ6qDpGt0dfoJLSkCxq4j0w yXlyPr//dJ1J4jXxTQsFM1IrDhYOQ9EEJF4IBCwHZiX0K8T9iHYNC1hb5pLX4rqgqVK0XLFq8ocu9 9ZkLu/jHIKYu1EdxZVeVRcIRRWYAR8094tH4yECksmXuoCTE5HcMOadmJM2Edrh9eHgc=; Received: from mout-b-206.mailbox.org ([195.10.208.51]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xR4Xl-000000000H2-1MH9 for openvpn-devel@lists.sourceforge.net; Wed, 11 Nov 2026 09:23:05 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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 4jPdNF0D02zb8 for ; Wed, 11 Nov 2026 10:22:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794388973; 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=3zeY0gWPKuL4F9+3wikbp6LY0irXgWjcnzKxjkhZGhc=; b=1ddtzM33bEeEECafVsOuboWKnJZHe27BHyR8ws/QmM1VKmAl5ShPr6GEylaaa33w39V4et bVli+ipqPQphaKb9CBMjlYZI4rel2A6WyNvIzJVh2x5fFKYlvzU+lrNP588YPo+F1BVnvL o2h2WbAzoKPHQBS/Oy4R54zbqtDu4It3jwirn7xwthnTsIn/GWcXgAEEgaxwPH61PQ1G0Q 6T2Ky3Zg/k2yqFoGouj7ER5oNSXDcd7mvtm+UAM7ohT9xz+Ts1hYvro7EbZN2WmlvBsNVx jHogxLe81rkSsbCXEMvWGRL+a1sInJ8RZe+nt/wRaUQKT11laAmrc5tyb2nAbg== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::202 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Wed, 11 Nov 2026 10:22:37 +0100 Message-ID: <6b18f9a151ef61c7948e82287beeca1993e544f4.1794388607.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jPdNF0D02zb8 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: Register a UDP tunnel GRO receive callback for ovpn data sockets and coalesce compatible DATA_V2 records from one transport flow. Keep every encrypted record as a separate frag-list entry so the recei [...] 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_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 X-Headers-End: 1xR4Xl-000000000H2-1MH9 Subject: [Openvpn-devel] [PATCH ovpn net-next v3 5/6] ovpn: coalesce UDP data records with GRO 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: 1881553228890615066 X-GMAIL-MSGID: 1881553228890615066 Register a UDP tunnel GRO receive callback for ovpn data sockets and coalesce compatible DATA_V2 records from one transport flow. Keep every encrypted record as a separate frag-list entry so the receive path can authenticate it independently. Match the complete opcode, key and peer header and require compatible outer-network and checksum state. Flush on short records, differing segment geometry, existing GSO input, records inside FOU or GUE, or the 64-record limit. Complete a held aggregate before an incompatible record from the same transport flow, preventing the new record from overtaking it. GRO socket lookup is not authoritative, so a generic UDP frag-list aggregate may later land on an ovpn socket, for example after DNAT. Consume only aggregates with standard, unmodified geometry, private head and child skbs, linear and uniform OpenVPN headers, and an outer tuple unchanged since GRO. Decline every other aggregate so UDP segments it and retries delivery one datagram at a time. Inspect aggregates without pulling, since a declined one must reach UDP unmodified. Detach compatible frag lists directly instead of rebuilding standalone UDP packets whose outer headers would be discarded after decryption. Repair the aggregate head accounting, retain the outer headers needed for authenticated endpoint updates, propagate post-GRO protocol, ingress interface, priority, security mark and tc index metadata to every record. Clear the outer VLAN tag, redirect and classification flags and delivery time, which the receive stack consumed on the head only. The socket also opts into the detachable GRO receive contract, since it's owned by userspace. Refuse a socket which another encapsulation, such as ESP-in-UDP, has configured without setting sk_user_data, since its GRO callback could not be replaced. Teardown removes callbacks only while they remain owned by ovpn and waits for readers which may already have captured one. This keeps ovpn detachable GRO state and callback lifetimes consistent if UDP_ENCAP changes the socket configuration. The GRO implementation does not depend on the linked ovpn UDP GSO transmit series, but the measurement kernel carried it so that transmit did not limit throughput. On two directly connected 100-Gbit/s mlx5 ports, five interleaved 60-second iperf3 -Z single-flow AES-128-GCM runs in each direction, after a 10-second warm-up, produced the following mean throughput: Forward Reverse Without GRO 18.721 Gbit/s 18.777 Gbit/s With GRO 21.542 Gbit/s 21.366 Gbit/s GRO improved throughput by 15.1% forward and 13.8% reverse. Mean cycles and instructions per byte across the monitored data-path CPUs fell from 4.535 to 4.207 (7.2%) and from 10.913 to 9.417 (13.7%), respectively. Link: https://lore.kernel.org/openvpn-devel/cover.1794244231.git.ralf@mandelbit.com/ Signed-off-by: Ralf Lici --- Changes since v2 https://lore.kernel.org/openvpn-devel/3f88e036a4684c371956d26962e2ce6d02d61ab1.1794329430.git.ralf@mandelbit.com/ - Refuse records inside FOU or GUE in the GRO callback. (Sashiko) - Mark the rare admission conditions as unlikely and complete held records through a common exit. Changes since v1 https://lore.kernel.org/openvpn-devel/36b08ba627b885149ef45de3b6a26c52f857387d.1794314969.git.ralf@mandelbit.com/ - Refuse a socket which another encapsulation has configured without setting sk_user_data. (Sashiko) - Read a held aggregate's header without pulling it. (Sashiko) - Check aggregates in the encap callback without pulling them. (Sashiko) - Clear the redirect, classification and delivery time state which the receive stack consumed on the aggregate head only. (Sashiko) - Test skb_is_gso before pulling a new record's header. drivers/net/ovpn/udp.c | 336 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 325 insertions(+), 11 deletions(-) diff --git a/drivers/net/ovpn/udp.c b/drivers/net/ovpn/udp.c index 055cdb1bee13..e3a8aa83344f 100644 --- a/drivers/net/ovpn/udp.c +++ b/drivers/net/ovpn/udp.c @@ -8,11 +8,14 @@ #include #include +#include #include #include #include +#include #include #include +#include #include #include #include @@ -27,6 +30,252 @@ #include "socket.h" #include "udp.h" +/* like UDP and TCP frag-list GRO */ +#define OVPN_UDP_GRO_CNT_MAX 64 + +static bool ovpn_udp_gro_header(struct sk_buff *skb, u32 *header) +{ + const unsigned int offset = skb_gro_offset(skb); + + /* GRO replaces its frag0 pointer after holding an skb, so keep the + * openvpn header linear for later candidate comparisons + */ + if (!pskb_may_pull(skb, offset + OVPN_OPCODE_SIZE)) + return false; + + *header = get_unaligned_be32(skb->data + offset); + return true; +} + +static struct sk_buff *ovpn_udp_gro_receive_fraglist(struct sock *sk, + struct list_head *head, + struct sk_buff *skb) +{ + const unsigned int gso_size = skb_gro_len(skb); + struct sk_buff *p, *pp = NULL; + int ret = 0, nhoff; + bool ip_flush; + u32 header; + + /* FOU and GUE clear encap_mark and set is_fou before passing the inner + * UDP packet to GRO, so frag-list completion would run on their outer + * UDP header and skip their own completion + */ + if (unlikely(NAPI_GRO_CB(skb)->flush || NAPI_GRO_CB(skb)->is_fou || + skb->encapsulation || skb_is_gso(skb))) + goto flush; + + if (!ovpn_udp_gro_header(skb, &header) || + FIELD_GET(OVPN_OPCODE_PKTTYPE_MASK, header) != OVPN_DATA_V2) + goto flush; + + /* udp_gro_receive sets encap_mark before invoking a tunnel callback, + * normally because the callback recurses into an inner protocol. ovpn + * retains complete outer UDP records instead, so clear it and use + * ordinary UDP frag-list completion. + */ + NAPI_GRO_CB(skb)->encap_mark = 0; + NAPI_GRO_CB(skb)->is_flist = 1; + + list_for_each_entry(p, head, list) { + if (!NAPI_GRO_CB(p)->same_flow) + continue; + + /* A different representation, opcode, key or peer ID completes + * the held aggregate; this record can start the next one. + * Read the held header without pulling which might change the + * skb shape. + */ + if (NAPI_GRO_CB(p)->encap_mark || !NAPI_GRO_CB(p)->is_flist || + skb_headlen(p) < skb_gro_offset(p) + OVPN_OPCODE_SIZE || + get_unaligned_be32(p->data + skb_gro_offset(p)) != header) + return p; + + /* GRO has already matched the outer addresses and UDP ports; + * check the remaining outer IP fields + */ + ip_flush = gro_receive_network_flush(udp_hdr(skb), + udp_hdr(p), p); + + /* The first record determines the nominal GSO size. A shorter + * final record may follow it, but a larger record cannot. + * Checksum metadata must also be uniform because the aggregate + * exposes only one checksum state. + */ + if (gso_size > skb_shinfo(p)->gso_size || ip_flush || + skb->ip_summed != p->ip_summed || + skb->csum_level != p->csum_level) { + pp = p; + } else { + /* skb_gro_receive_list pulls the headers already + * processed by GRO before linking this skb to the + * record list so we have to manually preserve the + * outer network header location for later handling + */ + nhoff = NAPI_GRO_CB(skb)->network_offset; + skb_set_network_header(skb, nhoff); + ret = skb_gro_receive_list(p, skb); + } + + /* complete the aggregate if the append failed, or after + * appending a shorter final record, or after reaching the + * record-count limit + */ + if (ret || gso_size != skb_shinfo(p)->gso_size || + NAPI_GRO_CB(p)->count >= OVPN_UDP_GRO_CNT_MAX) + pp = p; + + return pp; + } + + return NULL; + +flush: + /* A packet which cannot join an aggregate must not overtake records of + * the same flow which GRO is still holding. Complete those first, as + * the other GRO handlers do. + */ + NAPI_GRO_CB(skb)->flush = 1; + list_for_each_entry(p, head, list) + if (NAPI_GRO_CB(p)->same_flow) + return p; + return NULL; +} + +static bool ovpn_udp_outer_match(const struct sk_buff *head, + const struct sk_buff *frag) +{ + const struct udphdr *uhf = udp_hdr(frag); + const struct udphdr *uhh = udp_hdr(head); + + /* NAT might have rewritten endpoints after GRO */ + if (unlikely(uhh->source != uhf->source || uhh->dest != uhf->dest)) + return false; + + switch (head->protocol) { + case htons(ETH_P_IP): + return ip_hdr(head)->saddr == ip_hdr(frag)->saddr && + ip_hdr(head)->daddr == ip_hdr(frag)->daddr; + case htons(ETH_P_IPV6): + return ipv6_addr_equal(&ipv6_hdr(head)->saddr, + &ipv6_hdr(frag)->saddr) && + ipv6_addr_equal(&ipv6_hdr(head)->daddr, + &ipv6_hdr(frag)->daddr); + default: + return false; + } +} + +/* validate an skb and turn it into a list of uniform OpenVPN records or return + * NULL without modifying an aggregate which UDP must segment + */ +static struct sk_buff *ovpn_udp_gso_prepare(struct sk_buff *skb, u32 header) +{ + unsigned int len = 0, truesize = 0; + struct sk_buff *list, *record; + + if (!skb_is_gso(skb)) { + skb_mark_not_on_list(skb); + goto out; + } + + list = skb_shinfo(skb)->frag_list; + if (unlikely(!list)) + return NULL; + + /* if any of the skbs is not private, ask the stack to segment */ + if (unlikely(skb_shared(skb) || skb_cloned(skb))) + return NULL; + + /* transformations after GRO only update the aggregate head: if its + * outer tuple changed, ask UDP to propagate it while segmenting + */ + if (unlikely(skb_pagelen(skb) != sizeof(struct udphdr) + + skb_shinfo(skb)->gso_size || + !ovpn_udp_outer_match(skb, list))) + return NULL; + + skb_walk_frags(skb, record) { + /* if the OpenVPN header is not uniform (batch created by + * generic GRO by coalescing unrelated packets) ask the stack + * to segment and handle each segment independently + */ + if (unlikely(skb_shared(record) || skb_cloned(record) || + skb_headlen(record) < OVPN_OPCODE_SIZE || + get_unaligned_be32(record->data) != header)) + return NULL; + + len += record->len; + truesize += record->truesize; + } + + if (unlikely(skb->data_len < len || skb->len < len || + skb->truesize < truesize)) + return NULL; + + /* detach the exclusively owned fraglist */ + skb_shinfo(skb)->frag_list = NULL; + skb->data_len -= len; + skb->truesize -= truesize; + skb->len -= len; + skb->next = list; + skb_gso_reset(skb); + +out: + /* skb_gro_receive_list has already pulled the UDP headers from child + * records, while the aggregate head still starts at UDP, so pull its + * header too before returning the list + */ + __skb_pull(skb, sizeof(struct udphdr)); + return skb; +} + +static void ovpn_udp_recv(struct ovpn_peer *peer, struct sk_buff *list) +{ + const __be16 proto = list->protocol; + const u32 priority = list->priority; +#ifdef CONFIG_NET_SCHED + const u16 tc_index = list->tc_index; +#endif +#ifdef CONFIG_NETWORK_SECMARK + const u32 secmark = list->secmark; +#endif + const int skb_iif = list->skb_iif; + struct sk_buff *skb, *next; + + skb_list_walk_safe(list, skb, next) { + /* propagate post-GRO metadata from the list head, and clear + * the state which the receive stack consumed on the head only + */ + skb->protocol = proto; + skb->skb_iif = skb_iif; + skb->priority = priority; +#ifdef CONFIG_NETWORK_SECMARK + skb->secmark = secmark; +#endif +#ifdef CONFIG_NET_SCHED + skb->tc_index = tc_index; +#endif + __vlan_hwaccel_clear_tag(skb); + skb_reset_redirect(skb); +#ifdef CONFIG_NET_XGRESS + skb->tc_skip_classify = 0; +#endif + skb_clear_delivery_time(skb); + skb_mark_not_on_list(skb); + + /* keep the current reference alive for the next record before + * handing this one to crypto + */ + if (next && unlikely(!ovpn_peer_hold(peer))) { + DEBUG_NET_WARN_ON_ONCE(1); + kfree_skb_list(next); + next = NULL; + } + ovpn_recv(peer, skb); + } +} + /* Retrieve the corresponding ovpn object from a UDP socket * rcu_read_lock must be held on entry */ @@ -69,7 +318,9 @@ static int ovpn_udp_encap_recv(struct sock *sk, struct sk_buff *skb) struct ovpn_socket *ovpn_sock; struct ovpn_priv *ovpn; struct ovpn_peer *peer; - u32 peer_id; + bool aggregate = false; + struct sk_buff *list; + u32 header, peer_id; u8 opcode; ovpn_sock = ovpn_socket_from_udp_sock(sk); @@ -89,14 +340,28 @@ static int ovpn_udp_encap_recv(struct sock *sk, struct sk_buff *skb) * header are accessible. * They are required to fetch the OP code, the key ID and the peer ID. */ - if (unlikely(!pskb_may_pull(skb, sizeof(struct udphdr) + - OVPN_OPCODE_SIZE))) { + if (skb_is_gso(skb)) { + /* Only an accepted frag-list aggregate can carry OpenVPN + * records. It is checked without pulling, since one which we + * decline must reach UDP unmodified so that it can segment it. + */ + if (unlikely(skb_shinfo(skb)->gso_type != + (SKB_GSO_UDP_L4 | SKB_GSO_FRAGLIST))) + goto drop; + aggregate = true; + + if (unlikely(skb_headlen(skb) < + sizeof(struct udphdr) + OVPN_OPCODE_SIZE)) + goto drop; + } else if (unlikely(!pskb_may_pull(skb, sizeof(struct udphdr) + + OVPN_OPCODE_SIZE))) { net_dbg_ratelimited("%s: packet too small from UDP socket\n", netdev_name(ovpn->dev)); goto drop; } - opcode = ovpn_opcode_from_skb(skb, sizeof(struct udphdr)); + header = get_unaligned_be32(skb->data + sizeof(struct udphdr)); + opcode = FIELD_GET(OVPN_OPCODE_PKTTYPE_MASK, header); if (unlikely(opcode != OVPN_DATA_V2)) { /* DATA_V1 is not supported */ if (opcode == OVPN_DATA_V1) @@ -106,7 +371,7 @@ static int ovpn_udp_encap_recv(struct sock *sk, struct sk_buff *skb) return 1; } - peer_id = ovpn_peer_id_from_skb(skb, sizeof(struct udphdr)); + peer_id = FIELD_GET(OVPN_OPCODE_PEERID_MASK, header); /* some OpenVPN server implementations send data packets with the * peer-id set to UNDEF. In this case we skip the peer lookup by peer-id * and we try with the transport address @@ -119,12 +384,27 @@ static int ovpn_udp_encap_recv(struct sock *sk, struct sk_buff *skb) if (unlikely(!peer)) goto drop; - /* pop off outer UDP header */ - __skb_pull(skb, sizeof(struct udphdr)); - ovpn_recv(peer, skb); + /* A generic aggregate may contain records for different consumers and + * post-GRO transformations may have changed only its head. Prepare + * only a private, unmodified aggregate with uniform opcode, key ID and + * peer ID; otherwise return it to UDP for segmentation. + */ + list = ovpn_udp_gso_prepare(skb, header); + if (unlikely(!list)) { + ovpn_peer_put(peer); + return 1; + } + + ovpn_udp_recv(peer, list); return 0; drop: + /* let UDP segment an accepted aggregate so that every datagram gets + * its own verdict + */ + if (aggregate) + return 1; + ovpn_dev_dstats_rx_dropped(ovpn->dev); drop_noovpn: kfree_skb(skb); @@ -512,8 +792,11 @@ int ovpn_udp_socket_attach(struct ovpn_socket *ovpn_sock, struct socket *sock, struct udp_tunnel_sock_cfg cfg = { .sk_user_data = ovpn_sock, .encap_type = UDP_ENCAP_OVPNINUDP, + .udp_flags = BIT(UDP_FLAGS_GRO_RCV_DETACHABLE) | + BIT(UDP_FLAGS_ENCAP_ACCEPT_FRAGLIST), .encap_rcv = ovpn_udp_encap_recv, .encap_destroy = ovpn_udp_encap_destroy, + .gro_receive = ovpn_udp_gro_receive_fraglist, }; struct ovpn_socket *old_data; int ret; @@ -522,6 +805,18 @@ int ovpn_udp_socket_attach(struct ovpn_socket *ovpn_sock, struct socket *sock, rcu_read_lock(); old_data = rcu_dereference_sk_user_data(ovpn_sock->sk); if (!old_data) { + /* another encapsulation (such as ESP-in-UDP) may own the + * socket without setting sk_user_data, and the GRO callback + * which it may have registered cannot be replaced + */ + if (READ_ONCE(udp_sk(ovpn_sock->sk)->encap_type) || + READ_ONCE(udp_sk(ovpn_sock->sk)->gro_receive)) { + rcu_read_unlock(); + netdev_dbg(ovpn->dev, + "provided socket already taken by other user\n"); + return -EBUSY; + } + /* socket is currently unused - we can take it */ rcu_read_unlock(); setup_udp_tunnel_sock(sock_net(ovpn_sock->sk), sock->sk, &cfg); @@ -558,16 +853,35 @@ int ovpn_udp_socket_attach(struct ovpn_socket *ovpn_sock, struct socket *sock, */ void ovpn_udp_socket_detach(struct ovpn_socket *ovpn_sock) { + struct udp_sock *up = udp_sk(ovpn_sock->sk); struct sock *sk = ovpn_sock->sk; + /* Stop accepting aggregates while encap_rcv is still available. A + * reader which sampled acceptance before it was cleared can either be + * consumed by ovpn or fall back to UDP segmentation. + */ + if (udp_test_bit(GRO_RCV_DETACHABLE, sk) && + READ_ONCE(up->gro_receive) == ovpn_udp_gro_receive_fraglist) + udp_tunnel_detach_gro(sk); + + /* UDP_ENCAP may have replaced encap_rcv while leaving other ovpn state + * attached. Clear only callbacks still owned by ovpn. The final RCU + * grace period in ovpn_socket_release drains readers which captured + * encap_rcv before this point. + */ + if (READ_ONCE(up->encap_rcv) == ovpn_udp_encap_recv) + WRITE_ONCE(up->encap_rcv, NULL); + if (READ_ONCE(up->encap_destroy) == ovpn_udp_encap_destroy) + WRITE_ONCE(up->encap_destroy, NULL); + /* Re-enable multicast loopback */ inet_set_bit(MC_LOOP, sk); /* Disable CHECKSUM_UNNECESSARY to CHECKSUM_COMPLETE conversion */ inet_dec_convert_csum(sk); - WRITE_ONCE(udp_sk(sk)->encap_type, 0); - WRITE_ONCE(udp_sk(sk)->encap_rcv, NULL); - WRITE_ONCE(udp_sk(sk)->encap_destroy, NULL); + /* UDP_ENCAP might have rewritten the encap_type */ + if (READ_ONCE(up->encap_type) == UDP_ENCAP_OVPNINUDP) + WRITE_ONCE(up->encap_type, 0); rcu_assign_sk_user_data(sk, NULL); } From patchwork Wed Nov 11 09:22:38 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5663 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:529c:b0:11a:a05e:cb97 with SMTP id x28csp179274lax; Wed, 11 Nov 2026 01:23:05 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFyJIi+mv3NrD+/dlf+6wu+f4udXbWUTtlSdb71dZn8CDnFs38GW14aQddHhE7pSglIG6YD2PZEgNY=@openvpn.net X-Received: by 2002:a05:7300:561c:b0:36e:2626:4ace with SMTP id 5a478bee46e88-3768366a866mr2610164eec.5.1794388985225; Wed, 11 Nov 2026 01:23:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794388985; cv=none; d=google.com; s=arc-20260327; b=SVghtTwjVSCMRbBdGTSert6vd+xZ1BqBue53NcICol7IVM7JZb76K2nRiDw31glcF+ 39hPtOYcgzfTPn+oVs4BjhTB5bBlFnaL1miUD3gAqk6+gL48QItoD+m2l8RmS/Jz7VlP 8WFIfAtO0lreA+DHv0e+a1z9+B9LPVOVOpNb/z+gP5Ju7SJIG7li7jOZBZSuWGMFRDGd VLk+0NLXrGMuJM3Vc+rmNg33khIADuB9XqC1CCpxkU5xPWiPmjz005QOMJE/1+tSy+zE cfJQOBcb+0vaRU5Docw9LsLHcKfMDXxT0pFdNBf87kaVmjGhFLChLgOvLc5NS1RTpAyz 6ZVA== 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=W85Qy5Gi5Jg7rBf0qb3WikHos83uBthfhWymNWrJsFM=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=X55+m7i9FVeELqKPGpizfptvScHNCYecvc59UsxAEflyLXKe5opVTk5zWi9xPnBbGN RYus5rzg853S3HWgCbDzw3pFOjaQfwLb8pfFOpMndTu1ZOEN91UsnH7+/CHC0TKqdpl9 s5I0lgo917xuFVUgf8bCD1hdM9/BQiurXFGpj8Vk3NVhJqOCcYCIREU4pIUElktXDBp6 viLMIBLee3enHLczhfbo4X48tNep9ZQWAoD9XS14LUtvC84VHe2y73RdpHS4KvuIEMe7 AiyqR82npoKR28pRj2/XmCnYXWpUMSxfBu1L9/29BuMImoymFUhbDddpdf5R/7cAO1nN R1Eg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=fVFL5Zki; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=HQyMTNqm; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="YdEC3r5/"; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=VgYq4cUp; 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-37520616b4dsi10109972eec.33.2026.11.11.01.23.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Nov 2026 01:23:05 -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=fVFL5Zki; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=HQyMTNqm; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="YdEC3r5/"; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=VgYq4cUp; 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=W85Qy5Gi5Jg7rBf0qb3WikHos83uBthfhWymNWrJsFM=; b=fVFL5ZkiOnU1Lw 64Q04KlOXFSRNNVrEkG4Yylc8WEheC9r70ffdLMzt6S7ZAar08NfbcwwvqAuqzBIuThL0f8dIMcg+ BdVZp0DOm8gU+qMclbLF0f82UynAXFgUsDlfV4WULWOQGX612zmhy0+6K8PIL8X0ZptD/SihIy2Mt aU8=; 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 1xR4Xo-000000005EN-12Dx; Wed, 11 Nov 2026 09:23:04 +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 1xR4Xn-000000005EF-2jGk for openvpn-devel@lists.sourceforge.net; Wed, 11 Nov 2026 09:23:03 +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=Qvh3gCSy7RRLdCBAaw/mKlXByRy9A7eo6jF1P58RciE=; b=HQyMTNqmwiOCuFfWOrgWIiMdqw N0iiQTQs24vmOZY65gschtDKtA7XHP8ZMxp1tsaONVnSX7aEOprpnIfRf4tayl+rOnVPBAwgqTU9u dhkTuaPsPn1IOgBXpkQuIvEka5FzfB7/dPyypibge4Bd76WkZASZYfiHyMU+8MKJFatY=; 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=Qvh3gCSy7RRLdCBAaw/mKlXByRy9A7eo6jF1P58RciE=; b=YdEC3r5/dbgsjxEpsN8N6JPIZX MOIQnOWWvSDSrl2NJMnXEXApunXZuY4yIM6xXgcF5BSbqA/Ea8KegW40aBS52Max3s0vzv53emUNX F9Q5/vpFms4jc60K3ka35AZ6cAnf64uZdELVaDAhlSYXxaoPHWXc4hVdLvi4fJ4QTOpw=; Received: from mout-b-105.mailbox.org ([195.10.208.50]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xR4Xl-000000000H4-3Xla for openvpn-devel@lists.sourceforge.net; Wed, 11 Nov 2026 09:23:03 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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 4jPdNF3rsFz9syq for ; Wed, 11 Nov 2026 10:22:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794388973; 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=Qvh3gCSy7RRLdCBAaw/mKlXByRy9A7eo6jF1P58RciE=; b=VgYq4cUp9MD8MAhje7tSS6vuoc7MDMDDOus4Jgt/rMRMDwdpg4pOH3ftH1WOmIdjtD3WuV wmbobvEIsVfZxWireIpjLioGHPr3MXfB4n2om/FeFtG5COYSKqDU3RkNCrIm6fCk5fD4LV xgj4ZPT2lq071rxNnmSA25e0uBZt8rtjeGjIDI3OUtKat3SAjhlTTqWc5lasv8MaQYFxVA MaQ5gqPhvNVNqh8JiHsVK+zL14dzJOGUQ+PBDkqXZw0N1SqpObdFhFwl+ytr2LDlbPgDvG iwQJjvlNVMQx9F0rcsAigQQjR2C2pmBIL/QCK0A7uL7BUA3+3hH2HFwcOwIFdg== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::202 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Wed, 11 Nov 2026 10:22:38 +0100 Message-ID: <874ca8e9efb787fd37a942817239c8ba1a4fa4b3.1794388607.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jPdNF3rsFz9syq 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: Frag-list GRO exposes later encrypted records before the receive path decrypts the current one. Use this lookahead to request write ownership of linear ciphertext cache lines two records in advance, a [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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 Message has at least one valid DKIM or DK signature X-Headers-End: 1xR4Xl-000000000H4-3Xla Subject: [Openvpn-devel] [PATCH ovpn net-next v3 6/6] ovpn: prefetch encrypted records before GRO batch decryption 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: 1881553224320281611 X-GMAIL-MSGID: 1881553224320281611 Frag-list GRO exposes later encrypted records before the receive path decrypts the current one. Use this lookahead to request write ownership of linear ciphertext cache lines two records in advance, and maintain the same distance throughout the batch, overlapping their memory access latency with the current AEAD operation. An ordinary single-record UDP receive has no later record and therefore skips the prefetch path. Only prefetch the linear part of each skb. Walking non-linear fragments here would duplicate the scatterlist walk performed by crypto and could cost more than the cache hint saves. This optimization primarily targets synchronous software AEAD, where the CPU which issues the hint subsequently overwrites the prefetched lines. An asynchronous accelerator may instead access them through DMA and is not expected to benefit in the same way; the cache hint remains correctness-neutral. With the ovpn UDP GSO transmit series also applied, five interleaved 60-second iperf3 -Z single-flow AES-128-GCM runs in each direction over two directly connected 100-Gbit/s mlx5 ports, after a 10-second warm-up, produced the following mean throughput: Forward Reverse Without RX prefetch 21.542 Gbit/s 21.366 Gbit/s With RX prefetch 25.741 Gbit/s 25.150 Gbit/s RX prefetch improved throughput by 19.5% forward and 17.7% reverse. Mean cycles per byte across the monitored data-path CPUs fell from 4.207 to 3.896, a 7.4% reduction. A same-binary comparison using the aforementioned setup found distances one and two effectively tied forward, while distance two was 3.3% faster reverse and less variable. Signed-off-by: Ralf Lici --- No changes since v2 https://lore.kernel.org/openvpn-devel/bad00484f77503ede2affa16075325a00b5cef04.1794329430.git.ralf@mandelbit.com/ No changes since v1 https://lore.kernel.org/openvpn-devel/e18ef3363a3d5167cddb8b0528d447ba1d5aa2ed.1794314969.git.ralf@mandelbit.com/ drivers/net/ovpn/udp.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/net/ovpn/udp.c b/drivers/net/ovpn/udp.c index e3a8aa83344f..2f77acc47bd9 100644 --- a/drivers/net/ovpn/udp.c +++ b/drivers/net/ovpn/udp.c @@ -6,9 +6,11 @@ * Author: Antonio Quartulli */ +#include #include #include #include +#include #include #include #include @@ -33,6 +35,21 @@ /* like UDP and TCP frag-list GRO */ #define OVPN_UDP_GRO_CNT_MAX 64 +/* leave enough work between a cache hint and the record which consumes it */ +#define OVPN_UDP_GRO_PREFETCH_DISTANCE 2 + +static void ovpn_udp_prefetchw_linear(const struct sk_buff *skb) +{ + unsigned long addr = (unsigned long)skb->data; + unsigned long end = addr + skb_headlen(skb); + + /* crypto overwrites data in place, so request write ownership of each + * linear cache line before the AEAD implementation reaches it + */ + for (; addr < end; addr = ALIGN(addr + 1, L1_CACHE_BYTES)) + prefetchw((void *)addr); +} + static bool ovpn_udp_gro_header(struct sk_buff *skb, u32 *header) { const unsigned int offset = skb_gro_offset(skb); @@ -232,6 +249,7 @@ static struct sk_buff *ovpn_udp_gso_prepare(struct sk_buff *skb, u32 header) static void ovpn_udp_recv(struct ovpn_peer *peer, struct sk_buff *list) { + struct sk_buff *skb, *next, *prefetch; const __be16 proto = list->protocol; const u32 priority = list->priority; #ifdef CONFIG_NET_SCHED @@ -241,9 +259,23 @@ static void ovpn_udp_recv(struct ovpn_peer *peer, struct sk_buff *list) const u32 secmark = list->secmark; #endif const int skb_iif = list->skb_iif; - struct sk_buff *skb, *next; + int i; + + /* a fraglist GRO aggregate makes later ciphertext visible before the + * current record is decrypted, so we prime the first two records, then + * keep the cache hints the same distance ahead while draining the list + */ + prefetch = list->next ? list : NULL; + for (i = 0; i < OVPN_UDP_GRO_PREFETCH_DISTANCE && prefetch; i++) { + ovpn_udp_prefetchw_linear(prefetch); + prefetch = prefetch->next; + } skb_list_walk_safe(list, skb, next) { + if (prefetch) { + ovpn_udp_prefetchw_linear(prefetch); + prefetch = prefetch->next; + } /* propagate post-GRO metadata from the list head, and clear * the state which the receive stack consumed on the head only */