From patchwork Tue Nov 10 12:54:18 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5650 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:20a6:b0:11a:a05e:cb97 with SMTP id 38csp991107lad; Tue, 10 Nov 2026 04:54:45 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFciYbrsfCwOn1tS4jKBg0rmcHaGy9+fNGnop422CwNU2Tqh6XozI+kVZkmiV4XwSRVMCIVS3iXLaE=@openvpn.net X-Received: by 2002:a05:7300:f791:b0:36a:54a0:6b4c with SMTP id 5a478bee46e88-3751f462215mr3339381eec.25.1794315284796; Tue, 10 Nov 2026 04:54:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794315284; cv=none; d=google.com; s=arc-20260327; b=snT042HoE053zYjYo9u/voxsUwm7Gndh1KcQ3U1BS0Slfa7lUmzMmwfg7fJADjd+Fu e3ukY1ocAkkWlaMA69tfZWZAoQ0eU9isYMx1tenO9JM1lFRcnaAZeiEvb2ia6pZAtBKi D5dL7gnf2bsDoNOZDGH0nXu7v8FA2g4kZj3QrbmlvXAZKOLG0Faair8rtUd2kO5dRH8Z zQP8nW0Urehz8qAy7iylqlkn6j/g/he3mjAkpRqN41MU9eV5jn0/vbWI0wQuZyEwS+xi E6t/6Uub8hvayXh5gtKkhSsc3E6rQBSqS3zCPo4QQ1uSChZ+7uFYo0aCeEnAANiU8sBd kpZQ== 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=J2+BxVAK6ZDpT4IiWUJLKqE4NDeXGNSyO7CMv9H6u54=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=AgzlrmkzZTzVPW1udJ2ywkf9pUsd/g3xYdEupil5YtBV7DW2VgAUcb0TpBWqCKjNsl dy8UobXpWpWJmmeBFTt8OmBO62rhqWzYDFi88558QiDkwALD3UugeZp6oNQXibPJ/P+R 8LE7eo9AwG1bQREGAkRqllUdH1XvoLZJ0ogOwEC4+OSU0q4+dfEs4o8JiLCjCp2Novnr sNENhrxEMBNC0zyzZpOma1De94wLtc454kqVl8kKIvgLA0Dal41FVQ7V7ZDQKCN2UUaf m9q+jVvB7tLV0zVJd0WmSMp3q5FPyzbEM6fDj6rB2ola9d3DPeiBqtR2UFjEKMlAYigE Rm3g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=joXv5H5w; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=MC39lsON; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=CfbH+s1b; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=ecIlWRRX; 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-37520616b4dsi5376259eec.33.2026.11.10.04.54.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Nov 2026 04:54:44 -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=joXv5H5w; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=MC39lsON; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=CfbH+s1b; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=ecIlWRRX; 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=J2+BxVAK6ZDpT4IiWUJLKqE4NDeXGNSyO7CMv9H6u54=; b=joXv5H5wAG8VU6 OFfFB/JLsZOMsWRlOfxcCnYNsVGEgJeFwIp/grE4rDlGiD4ZdCcmyK+zmRQHJm3Q59zbaJAHfbsQR J0qjlPFnTluj+2vPQJ6JQJriCJIHw+2jDdPDSVTfAAQckEUCfd5w/X4wo2zgKuf1gODLzpbbjKJlu gtM=; 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 1xQlN5-0000000036U-3RPm; Tue, 10 Nov 2026 12:54:43 +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 1xQlN2-0000000036L-37le for openvpn-devel@lists.sourceforge.net; Tue, 10 Nov 2026 12:54:41 +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=U2n8iLBacCTUJs3hxa/hr4k4HFHX3K0NvoaPjc15GZ4=; b=MC39lsONbjejSxVZv/JLv9Wbhm qLSalwu+M6/Htt/VNkrYuQZEAoG48UNOkReeU47DZrnA6czHzKo9zj/Y7V9kI9XEhIf9NBlo/e5Q0 UqxFkR22HgzF+zToybzvQpfpClSTwmktCdAfxdht8gVDKvP2w862iU+X0NKJnp4dsq50=; 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=U2n8iLBacCTUJs3hxa/hr4k4HFHX3K0NvoaPjc15GZ4=; b=CfbH+s1bLqlOVi49BmjgQGKRci F50m+euS6A0EfFntRF0C6nGqOUiGHlXFD2sNZeSCsWFdn2pEx/GGANKEqVCRxbKZhN+gy5atHz3Sn eQpqA2myI7rvyjuBgMRegW5n2qnfuaZ15AMsQIW/QZ/oP7XrGzptCLQ+OcqP5QCn1ZTg=; Received: from mout-b-203.mailbox.org ([195.10.208.52]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQlMz-00000000698-2cS5 for openvpn-devel@lists.sourceforge.net; Tue, 10 Nov 2026 12:54:40 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA512) (No client certificate requested) by mout-b-203.mailbox.org (Postfix) with ESMTPS id 4jP66s5QgYzLm8p for ; Tue, 10 Nov 2026 13:54:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794315269; 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=U2n8iLBacCTUJs3hxa/hr4k4HFHX3K0NvoaPjc15GZ4=; b=ecIlWRRXiVgxl6VCCkj73yHCuHBrzKMZ28aMoI+59ReBXNvUXcqKhRmWqzACrm1vKWRTgI RJCqMBj/IOqyWjbIEdbc9pFaVvM574uRp715PiG2UqUTAPQV1IPRBefhn7/TuuE9JhOQsU c1H21E5ubOjW5LGDkUzijTy2LuNlLh3M9KPj518cXooFjeDtGx5bcTNMe0oehJ+0yyCjjt vIRsWn93woGH+MkVBSAVA9EBJkyJlQctQ6L2VVRFLNeCtO162nTDdPaB6Tx9cqwqZaAy8j f8/P+MU6He8ds0pJeK+zRIcCOag34Uvzrf6QadNYbsIpW5jKCSh2SpyvyOiqww== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Tue, 10 Nov 2026 13:54:18 +0100 Message-ID: <19426aa5f9a5805f925014be8b057dc2fba335d7.1794314969.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jP66s5QgYzLm8p 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: 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 Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-Headers-End: 1xQlMz-00000000698-2cS5 Subject: [Openvpn-devel] [PATCH ovpn net-next 1/5] 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: 1881475943947584345 X-GMAIL-MSGID: 1881475943947584345 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. GRO has already validated every datagram in this representation, while the aggregate checksum state does not describe the complete skb. Treat the opt-in as provisional, that is, bypass the pre-encapsulation checksum check, but segment the aggregate and process every datagram normally if the callback is absent or declines it. A declining callback must leave the aggregate unmodified apart from layout-only pulls. This keeps the combined representation away from the UDP socket and leaves callbacks which do not opt in protected as before. 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 --- include/linux/udp.h | 12 ++++++++++++ include/net/udp_tunnel.h | 1 + net/core/gro.c | 1 + net/ipv4/udp.c | 37 ++++++++++++++++++++++++++++++------- net/ipv4/udp_tunnel_core.c | 10 ++++++++++ net/ipv6/udp.c | 37 ++++++++++++++++++++++++++++++------- 6 files changed, 84 insertions(+), 14 deletions(-) diff --git a/include/linux/udp.h b/include/linux/udp.h index 998906ec3b32..2a0c45ddd7b1 100644 --- a/include/linux/udp.h +++ b/include/linux/udp.h @@ -67,6 +67,11 @@ 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 packet contents unchanged. Layout-only + * pulls are permitted. + */ + UDP_FLAGS_ENCAP_ACCEPT_FRAGLIST, }; /* per NUMA structure for lockless producer usage. */ @@ -211,6 +216,13 @@ static inline bool udp_encap_needed(void) return false; } +static inline bool udp_encap_accepts_fraglist(struct sock *sk, + struct sk_buff *skb) +{ + return skb_is_gso(skb) && udp_test_bit(ENCAP_ACCEPT_FRAGLIST, sk) && + skb_shinfo(skb)->gso_type == (SKB_GSO_UDP_L4 | SKB_GSO_FRAGLIST); +} + 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 ff828a3dce3c..069df5d96075 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..9b17ae823e56 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -2391,7 +2391,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); @@ -2424,14 +2425,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)) + /* GRO validated every datagram before constructing an + * accepted frag-list. Its aggregate checksum state + * does not describe the complete skb, so validate only + * after a fallback to individual datagrams. + */ + 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 +2452,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 +2485,15 @@ 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))) { + 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 +2502,7 @@ 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); + 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..411073068075 100644 --- a/net/ipv4/udp_tunnel_core.c +++ b/net/ipv4/udp_tunnel_core.c @@ -71,6 +71,11 @@ 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); + /* Disable multicast loopback */ inet_clear_bit(MC_LOOP, sk); @@ -87,6 +92,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..1b3d3adb3f44 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -810,7 +810,8 @@ 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) +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); @@ -840,14 +841,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)) + /* GRO validated every datagram before constructing an + * accepted frag-list. Its aggregate checksum state + * does not describe the complete skb, so validate only + * after a fallback to individual datagrams. + */ + 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 +868,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 +902,15 @@ 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))) { + 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 +918,7 @@ 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); + 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 Tue Nov 10 12:54:19 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5651 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:20a6:b0:11a:a05e:cb97 with SMTP id 38csp991129lad; Tue, 10 Nov 2026 04:54:46 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErGCT/Dz6jtppXMtUnFylaZ5faXmlKey2+ObdVW/J/Y2FCw0WoU5AWUZ5kBPGiUh/wHBglpni3pn8zU=@openvpn.net X-Received: by 2002:a05:7301:5f0b:b0:375:dc5b:43fa with SMTP id 5a478bee46e88-375dc5b471bmr1032891eec.8.1794315285952; Tue, 10 Nov 2026 04:54:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794315285; cv=none; d=google.com; s=arc-20260327; b=BleY8oK2QgB2MPvuG6oaviA7rVce+PpLX3+DzRmfSswILmCAYAhNtld/oooiEWxaSi VXEcD+lX0jBBGDWRAsNwQwVDZ1CzDXx8jqK88JIexSKORWpUfmRbkvdZcFdoDzUIZp3Z Fy3oCXFE22rm61ZCP0zi0gjdEiVMRmHh042ITC5s+6fHVxIObEw90Zl9HJhL8lK9cEz5 1CQnGYoHaSiJjx33MCQN87sbx1ht3+CVRUTHp63MeAOqaHZ+9RyRVK4AGTRXKXwWEUgJ DMWJqIAiCyjjrbRPPGIe5rAID91phIWpEMzTTgO8o5jlfu5H20iIdRwMMDZ3/EtIwqi/ tSuQ== 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=3MO0bQB7Slml/uIGCEztGg6/AORspcx3TM9Op+XphXU=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=RpZPYRkdcy7a5dyg9Cv2TplGWmRZA30RLQ1uI1GUetUr3d8jJ8T20va1ozZ+kXQpWJ jV7r9WoqtiPu7O7fYIpaFKdYT2UOOBwf1lsg6Ml1N4OZ5g4EbSpGRaILMs1SHg0bgqbf njdyoOxV5nPdMRjDSliTLDCCzKiGXl7b7988Vl9yhbbHD8UIZ/Y8Erew7UNCEXHAQYqG Dbi+f/VscnraZC1qyCRbakz7e/oVpilmxGHW0nZndefZ1Pyxn+66XPyQs/mLUww+WZXv RPpeOQB2VFUqRPHFoDUIAiae5EFZuMZiLif52kLxwC9lVo9M+ZlyZ6d6pionDLggUF48 5mHg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=H235mSgd; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=TU1Iyl6T; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=jN2A1CXX; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=yI3hUrDn; 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-37520cfe353si8727763eec.39.2026.11.10.04.54.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Nov 2026 04:54:45 -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=H235mSgd; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=TU1Iyl6T; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=jN2A1CXX; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=yI3hUrDn; 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=3MO0bQB7Slml/uIGCEztGg6/AORspcx3TM9Op+XphXU=; b=H235mSgdPIlp17 MELhWg7KmV8u2LTAdSJJpugtXnJdDIsW4roynl95JGyBS4zF+K3+N2C21vm7UeG8N6wuDvVrMBVK9 rlNiWRbR1+8Bm1vlbmty74iTZAPMdgQl3CagFb4ywNe4vkkufF7WA/XV5sEBOmWnh8l0z5UqzBUbS WOY=; 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 1xQlN7-000000002Xk-09oQ; Tue, 10 Nov 2026 12:54:45 +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 1xQlN3-000000002Ge-1B5b for openvpn-devel@lists.sourceforge.net; Tue, 10 Nov 2026 12:54:41 +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=HM7l677bUmBZzk5x8I/3eHlKMvtv+le18ZrOljyKfM4=; b=TU1Iyl6TbxXpNFLvMp3OtwxRBB 62LLzrR7gCRy+pQEkIoh65CLbhD1XOV36+mFU9e+ZPJ0w3S8b4lOyd9dgAd8DD3w1Gy4LjGBUpnKa Dv0+rqmDSA/4PN0P+gO4SkcchiV6tdK/M95sOiy1vCMXVah4u1hu8qQhOBPFblAOzUQs=; 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=HM7l677bUmBZzk5x8I/3eHlKMvtv+le18ZrOljyKfM4=; b=jN2A1CXXEMSq/STN1CJHnDVheL r4+KkdjluzCtljbKIOFWIUJWL9feVE006ce6UqMN/y0y9lvKY0pThB+oI1OogHSKCn7gmkH8VJRm7 F1sFQEvfPj6Ub0XLYR8gcc98pkmA2RMQPyZPOqC57xq/X2lskeNk/iKQHT1KGKi3rLZ4=; Received: from mout-b-206.mailbox.org ([195.10.208.51]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQlN0-000000006Ks-230j for openvpn-devel@lists.sourceforge.net; Tue, 10 Nov 2026 12:54:41 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-206.mailbox.org (Postfix) with ESMTPS id 4jP66t0Ws4zWX for ; Tue, 10 Nov 2026 13:54:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794315270; 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=HM7l677bUmBZzk5x8I/3eHlKMvtv+le18ZrOljyKfM4=; b=yI3hUrDn39qdc8+y5/tVQ09+jD8v4j7fzKUS+y1n/vTN5J/bFatmWvLEoxrcqz/Fzg1YMc WTirwjYr1tTH+0LSNHxj2hn5EI2cIxG1VpMU37nK6WA4cvP+eTpha5n02om7IfsSPv2fU0 vOo2Y/M+MEuzoFeQ/3CQ3A6AXHZ/8QLwUwEAmMy+NbHjhtwL8tK2AlEUoNlAjaDj05caQg rs4t1ccIxPRwU4z7RPvITEs/GzKKKVKt5Ujuctb4F78bbmyrha+VSKUaUoRDuszNga5W2a 8KuukkgmJHXp1yTpRtT0UsJy40RsGhojxITZ3HJGNVq8fMzzRZJXWpwDMfEaWA== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Tue, 10 Nov 2026 13:54:19 +0100 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jP66t0Ws4zWX 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_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 Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-Headers-End: 1xQlN0-000000006Ks-230j Subject: [Openvpn-devel] [PATCH ovpn net-next 2/5] 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: 1881475945046342685 X-GMAIL-MSGID: 1881475945046342685 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. 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 --- include/linux/udp.h | 1 + include/net/udp_tunnel.h | 2 ++ net/ipv4/udp_offload.c | 59 +++++++++++++++++++++++++++++++++----- net/ipv4/udp_tunnel_core.c | 25 +++++++++++++--- 4 files changed, 76 insertions(+), 11 deletions(-) diff --git a/include/linux/udp.h b/include/linux/udp.h index 2a0c45ddd7b1..e81ed7248ea0 100644 --- a/include/linux/udp.h +++ b/include/linux/udp.h @@ -72,6 +72,7 @@ enum { * pulls are permitted. */ 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 cf07c3c6611a..9d6a5a52d879 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 411073068075..f8fe5f673441 100644 --- a/net/ipv4/udp_tunnel_core.c +++ b/net/ipv4/udp_tunnel_core.c @@ -71,10 +71,22 @@ 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); + 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 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); @@ -89,13 +101,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 Tue Nov 10 12:54:20 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5648 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:20a6:b0:11a:a05e:cb97 with SMTP id 38csp991097lad; Tue, 10 Nov 2026 04:54:44 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHW7OsLWY88U8SuZyT++ha5Uy5NV+4pZ/XDQAqtHYnWFEkM0Iiex6XIabf6gguFWC46NF0hnNZlEdQ=@openvpn.net X-Received: by 2002:a05:7022:2514:b0:185:b157:f271 with SMTP id a92af1059eb24-1b3b607af36mr4489368c88.23.1794315284383; Tue, 10 Nov 2026 04:54:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794315284; cv=none; d=google.com; s=arc-20260327; b=VBJdp1Akd6eU5N1kL89wUV/0tZhbsUNRyz58RZIcqG07dP+tZJo/pQLwvaDqgVfAj2 PYKqCF9u1IdlgDp/saQx1n5jkc1juf58HXxOJ4swb92V7fyEwQ3p6//ida/c2FdTUi4h m9k06tLUPv2Z1B3Qw3KFcABy8I54XcKD7R/S/mV8+AcjEVz8uHtUJYRs94kxQLQkYr8x JKeQz17tgOCtxNns/5LVJ5lrQv7Q3GtovwA3OSFTwYb3RA8lz8EJ72bDsemOVvlPkFc9 31i6wX4y1oofkVFpQSvaC6sqNrmos/vLRV5DD6vHSJWUMk4qLIlwVAeOT/Ktg6SQ4eac l6pg== 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=pKDVzIbX63cIS0nOOvLB4mNlrnKCP7Og2agKcJomO60=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=OQGMf1yzfUpxXchjfEWVo5QBartJV7yA6io6RGV9vc9JmImyEu/dGHh3XQNVi5FzMF f4j1xLBVI4EfREPnxrcKdG+ok33AWd8Hra6vm5JYtEiZA3VJ4rfd3EJEy/oJ6cu9P8Ev d39KToTDZGngM38QG1J6L5UVs7MwPX7tn598qc0HlYRRZ5s8/R5v5eRbkclVEIYnFyic xVPRBtStCTQ5ms340CtT+mTrioLSW5+nQtQoPl5eMeVxDbznfJSFFiQiZoDaasP3gzB9 nw0hhqvyLioXuMapA4KQKdIZds3HBvQG/+LDZorJm6cv/FzuXJhrrFNA13MK29kix0hA oPfw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=Z06Dc6rE; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=W00m0oFE; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=bTpfC3qc; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=vOV8xGAh; 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-1b3b5b818f5si6499162c88.40.2026.11.10.04.54.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Nov 2026 04:54:44 -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=Z06Dc6rE; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=W00m0oFE; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=bTpfC3qc; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=vOV8xGAh; 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=pKDVzIbX63cIS0nOOvLB4mNlrnKCP7Og2agKcJomO60=; b=Z06Dc6rESRvIlB c1Bna/GDH/mLVe1OQw2dWVOO7RQiXppwpgrDHjJIjGIMDfCCS4N/PJIP8MHWOCYiWamt9rSBF0zKy XyRszcKQ0Ntvk16WYtgugYKRdErnIpC4veQZSNWek3/Jjy81RAxFBJZPQwyZ/QL0jqlKAsvdfGV5b qOI=; 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 1xQlN4-000000002Gl-3BbF; Tue, 10 Nov 2026 12:54:42 +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 1xQlN2-000000002GS-2B41 for openvpn-devel@lists.sourceforge.net; Tue, 10 Nov 2026 12:54:40 +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=8/3PaZn0SgeiLxN7L/OeSDL7Mc+IOLoQUhFbk+5cyVY=; b=W00m0oFEH08NfV97Wtz4A6JNDR 5GeA2NJA9Ao8CkaNbiCkugPcclop1PV7lz9J6OW7xyvTOrNv4EdQiRwAdxGnBSCU8SZwW3EX0YUHK aM/Yon/oKURqojVXksx8V47YZAT3xCG6JLoTjyZULhUbO0VRqgpVu4GL55WHjiKOFd/4=; 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=8/3PaZn0SgeiLxN7L/OeSDL7Mc+IOLoQUhFbk+5cyVY=; b=bTpfC3qcD5Ja8l5N+m1DEAJKHo PXg/BJvfWLOq7jigPGe39aMZ9Of7YqQZ6E0a8b5NJhQ/vDXMnyZLvqkAav9Jp0sCGgaprmKEhTyJk IpVzA/OMhNpu6rhMwdEF3KZmuVp4VQq83pO5t0lGy5iV9dYlKWb2VWTs4e9OYo9tiVok=; Received: from mout-b-210.mailbox.org ([195.10.208.40]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQlN0-0000000069A-0x4o for openvpn-devel@lists.sourceforge.net; Tue, 10 Nov 2026 12:54:40 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-210.mailbox.org (Postfix) with ESMTPS id 4jP66t2rSMzFphR for ; Tue, 10 Nov 2026 13:54:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794315270; 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=8/3PaZn0SgeiLxN7L/OeSDL7Mc+IOLoQUhFbk+5cyVY=; b=vOV8xGAhVjA/R3MqiT5sG+Av69ztrGdf1VhJquhtOCLvNaMr7VFKaB2yj7e2wSJiQbVGBM +3A4E3fHrmZX26VqIM8zDKJc9LkwX6vLmqWx1JoysRWRE28WWYYCby4sqJtM4l0AKTP1Pg JVgi93i9UtZ1bD/yT7CDOkzWceYxcNcSdVPHHFfAc1cpLIdYGOmksS9Xm89RKRJaBecBqN 4Ot+47iWnNTkIUYtZpREUI/aNdUBTgLdyeUc27HzOeZbpvQ5U5B20abx/voXQ4BH/8z67X l836hC/E9XTO6BpmGdFhKuBPXIogmZntjDa7WP4s5MaVzIzs+ap/mldo0MKORw== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Tue, 10 Nov 2026 13:54:20 +0100 Message-ID: <99b9cccf9845899bc36e92165d9443499fe8a284.1794314969.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jP66t2rSMzFphR 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: 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 Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-Headers-End: 1xQlN0-0000000069A-0x4o Subject: [Openvpn-devel] [PATCH ovpn net-next 3/5] 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: 1881475943494250336 X-GMAIL-MSGID: 1881475943494250336 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 --- net/ipv4/udp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 9b17ae823e56..db0b60ae6859 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -2999,6 +2999,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) @@ -3011,6 +3014,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 Tue Nov 10 12:54:21 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5649 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:20a6:b0:11a:a05e:cb97 with SMTP id 38csp991098lad; Tue, 10 Nov 2026 04:54:44 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHYzbC/1xfagZ1WfZpaRi2B7lB3DlkM6m0d0g/8ClDcDgsbFcx03RDtrB2aKzUlZzTGogz+QQx+ibU=@openvpn.net X-Received: by 2002:a05:7022:ea47:20b0:1ae:e7c4:9a15 with SMTP id a92af1059eb24-1b3b5f9d9fcmr3639104c88.3.1794315284197; Tue, 10 Nov 2026 04:54:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794315284; cv=none; d=google.com; s=arc-20260327; b=HT+ya9VZzJPBvpaON4gO63CSh1S7JoCmlbY3KVT2MmVnJ6sLbwHtdg88N6GKhQa5AK sjyz3+U1mEE+dpfbdGvbcvidILWbZX1VgXFBE/Bb1mrdGrLqlv2TYdrtvQmCJ8YevX6j liIJpfsqN6GWrd3bY24/Dp7rHS6TRgM4B8JWwsnTdJTG5TSdUpSGsSqj/WyKS3mIJTKR 6VAbpRID5AW2iIMiSvifB5EGQ+CL0+eDVCsebG4TiX9YzwaxjSapskxo7EjJdMuTBw3H XPJqfnyXvCUU4+kIbNokn/YOzd0xuYOz3kv8oSZttKGm1WWlUQVYgR7v7JJU5ZJxAqWE HK4g== 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=rPrVTZ3SxqKfYxwxthtttGj+93BzlOLKZN5PHB0oDI8=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=Qp3EpGx7+csngtgh9zIlg/sWdEbIVYGynDR+bmWdJFnZC6gn4Yiz5cfD7qxi1aRTmT 0fcgtGL9+g39A7gg7NaXYPOEl6xlPKJFj+4ApEl/wHxi5JGXuCkxw7p0QyYBaMcYdIlR mtyv2nraCaZiLQPBnfdmckD8gCDQhAHdyropw6Q2GnToM++/UOBrUZZe2K0DRgEGQjKL pjv3ilHQzjzACooFhwdQkGZUt7ppke9M9TER4LXJjZb6VClSOEbBjsVadBwiD73wR+zX X5rjO5uHmW+bLmE7ERNH7PbKUC/yGj1YXIWR15SzdyXix6Sp8WGpvCHeniU/2bZ4y8yv 5s0g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=A3YVLjEg; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=eTtVwUtp; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=F2zkchlB; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=NRdVK9Is; 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-1b3b5b5b1f1si6765087c88.26.2026.11.10.04.54.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Nov 2026 04:54:44 -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=A3YVLjEg; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=eTtVwUtp; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=F2zkchlB; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=NRdVK9Is; 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=rPrVTZ3SxqKfYxwxthtttGj+93BzlOLKZN5PHB0oDI8=; b=A3YVLjEgVyXMTG fQw19RD5BXBMq5Iue0hhX7n4MVNIH6A+NyYvI4sqIT1Td9lE8QZYHlEqmDn5iTDLtY5sTJB2i28Ls gqGGqY+czL7QzToOjSE7hgHozbmMhOSevD2pH79udxMDJOIrG3/vbiyAjf+35RZ2pAM+ThlGivHT/ 9v4=; 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 1xQlN3-000000001zu-2wQY; Tue, 10 Nov 2026 12:54:41 +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 1xQlN2-000000001zh-37vB for openvpn-devel@lists.sourceforge.net; Tue, 10 Nov 2026 12:54:40 +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=kPjHYoNl1bcseJRTim0VG+gVfBdpOqSPHDYIEqj20JI=; b=eTtVwUtpnNyAFQjS9I9nrI7V+s KRexAeKqjXgJz7dLacgrS/V1Z5UoA3qW6e9CNTnzZY6hVnsqSAPsn7b5qupCcCTJGRTf9+oOHcOTp OsamMeTMrFlfDS2QXMKeThhx8seyW1FGuStkg94fs8fgQpwvEttbivLHXipWlE9IQ0pA=; 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=kPjHYoNl1bcseJRTim0VG+gVfBdpOqSPHDYIEqj20JI=; b=F2zkchlBV49fbubNkQoMdTCGn2 3GPDVrmYbpNRON9WoCswo8z84t1rUzRlYYrU23eMuBa8pOXJNzDiMEmD5t29TczuNwrHKE4Cj6cNW GUG9FcaUHfZJGNvJ6CbbYxD0VirBsZHiUD9ZbYNJy4ZsNBBAml7T5bg91gAvqTHP1pyY=; 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 1xQlN1-0000000069B-0K5Q for openvpn-devel@lists.sourceforge.net; Tue, 10 Nov 2026 12:54:40 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-107.mailbox.org (Postfix) with ESMTPS id 4jP66t5JdNz3y6x for ; Tue, 10 Nov 2026 13:54:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794315270; 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=kPjHYoNl1bcseJRTim0VG+gVfBdpOqSPHDYIEqj20JI=; b=NRdVK9IsaCnX5D0kWqHE1XUAIbku8+TTIJuZ+cL1KChigKQt2Y3V3sik1ee4efNDZklUZb ucKDlPcfocAWNWrNVSPHIqeRxegS4y6GMO5kxiXIT2Keo2jp2vKme7o/cx6pnMdMtHj99s 3Z46AVebfqLoH6MDGIz2Wg6WMTFNQxJpBai/FDJ1CpTas318MkUA1bWxynDbbFLDbcCaqN OND8szfIaLwO+PpZ1xQ55JEiyX7kYY5od3VcP0bXHl1dH9dy48oihzntOsp7uxYVNBy7Yi MYvK5zz9ZynvnbUiVbMJvMKeoFWGMCIc+A6OJgoJePTyyTvVGUxKONWakOKByA== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Tue, 10 Nov 2026 13:54:21 +0100 Message-ID: <36b08ba627b885149ef45de3b6a26c52f857387d.1794314969.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jP66t5JdNz3y6x 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: 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_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1xQlN1-0000000069B-0K5Q Subject: [Openvpn-devel] [PATCH ovpn net-next 4/5] 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: 1881475943278370124 X-GMAIL-MSGID: 1881475943278370124 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, 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. 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, and clear the consumed outer VLAN tag. The socket also opts into the detachable GRO receive contract, since it's owned by userspace. 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 --- drivers/net/ovpn/udp.c | 300 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 291 insertions(+), 9 deletions(-) diff --git a/drivers/net/ovpn/udp.c b/drivers/net/ovpn/udp.c index 055cdb1bee13..98f55f178a95 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,235 @@ #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; + u32 header, header2; + int ret = 0, nhoff; + bool 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. + */ + if (NAPI_GRO_CB(skb)->flush || skb->encapsulation || + !ovpn_udp_gro_header(skb, &header) || + FIELD_GET(OVPN_OPCODE_PKTTYPE_MASK, header) != OVPN_DATA_V2 || + skb_is_gso(skb)) { + NAPI_GRO_CB(skb)->flush = 1; + list_for_each_entry(p, head, list) + if (NAPI_GRO_CB(p)->same_flow) + return p; + return NULL; + } + + /* 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 + */ + if (NAPI_GRO_CB(p)->encap_mark || !NAPI_GRO_CB(p)->is_flist || + !ovpn_udp_gro_header(p, &header2) || header != header2) + return p; + + /* GRO has already matched the outer addresses and UDP ports; + * check the remaining outer IP fields + */ + 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 || 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; +} + +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 (its outer + * VLAN tag was already consumed by the receive stack) + */ + skb->protocol = proto; + skb->skb_iif = skb_iif; + skb->priority = priority; + __vlan_hwaccel_clear_tag(skb); +#ifdef CONFIG_NETWORK_SECMARK + skb->secmark = secmark; +#endif +#ifdef CONFIG_NET_SCHED + skb->tc_index = tc_index; +#endif + 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 +301,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); @@ -85,6 +319,16 @@ static int ovpn_udp_encap_recv(struct sock *sk, struct sk_buff *skb) goto drop_noovpn; } + /* only an accepted frag-list aggregate can carry OpenVPN records, and + * UDP can segment it if we hand it back + */ + if (skb_is_gso(skb)) { + if (unlikely(skb_shinfo(skb)->gso_type != + (SKB_GSO_UDP_L4 | SKB_GSO_FRAGLIST))) + goto drop; + aggregate = true; + } + /* Make sure the first 4 bytes of the skb data buffer after the UDP * header are accessible. * They are required to fetch the OP code, the key ID and the peer ID. @@ -96,7 +340,8 @@ static int ovpn_udp_encap_recv(struct sock *sk, struct sk_buff *skb) 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 +351,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 +364,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 +772,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; @@ -558,16 +821,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 Tue Nov 10 12:54:22 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5647 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:20a6:b0:11a:a05e:cb97 with SMTP id 38csp991091lad; Tue, 10 Nov 2026 04:54:44 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErEErzZoTLOCZ9QdkkCU51bP3onIY22kHO2Fr5zRvxIwgVnqvzjknsOffq442u+q/Z8gcWujFRN4v+A=@openvpn.net X-Received: by 2002:a05:693c:6384:10b0:369:f05d:6c5c with SMTP id 5a478bee46e88-3751f467bcamr3712192eec.28.1794315284212; Tue, 10 Nov 2026 04:54:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794315284; cv=none; d=google.com; s=arc-20260327; b=BsfjldVIjmWED7jmhIzaO9LVEbKoe6c5I6MDrQyqgYx3/EArjKJeddDhc9XdKhIIbu O40fASASKnwmg8kQRF1h4xmerXZodNWndiBbVzFv0mABTWkSUH2gYzQhhLsKW+SewWf0 H6Sd8x2N1XPTVLqkmgPsfeor8Oy/1jKCEvfOl0x9HYKn9ZbITajTpXH00EfTUvYwooZI nCg5SaLgqTORo4WIohHozVQMk2Al4DKNZp3Gy4bDSplB8QEaoKFuSpHzxzCOYrAc9VsV KKzPX94xZA2nWIx/C8Wc+zGRxC8H5/9/sbH31mdAvDTN+3Mtadb3NdUXLhW4YWS2CbGg roKA== 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=3j+uqIvo1lqVzgy7ac0eQVCdIwiQ0XbwVkISHi45T1s=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=EXIZ1UBshPUbgivb5LD3InHrUKBlvySUY34zqT9M6gD7tuh4FDgsLFZWXcvvRaCrg3 GHRbv5kOHrtksSmo+zOd2Q+k0qLqFRXEXdHFmxfTVjTncMaYxKp54Zo4WcSxC9XreRg0 y39dMC+LkpsSeEF1BEUAbc6Bfe/jEg40whvQ9qeax621mD3x7tcH+5scQ3LWZ/tFC/ld tcEVB+weth/mo5+x+3t8tmUbY0duld71FCC35ddMdFbet/pRdU+GTtf6uU3MPc8z6g5l JuWpqU1FagdDRZXHlrzdlpPBA5mQAyVREFLyHXqIptdZFVlwY5nOP2v7Y0mSxR2cibAb 5CBw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=jtsSVGsl; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=YeYVaPm8; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=fCJ1w7TX; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=gLFphV2X; 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-37521baeb7csi8114246eec.72.2026.11.10.04.54.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Nov 2026 04:54:44 -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=jtsSVGsl; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=YeYVaPm8; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=fCJ1w7TX; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=gLFphV2X; 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=3j+uqIvo1lqVzgy7ac0eQVCdIwiQ0XbwVkISHi45T1s=; b=jtsSVGslsVU806 qyYJSg4J5MPyRiCmiBQx0UUEyydSLPFa+DbA+EG4ydrutkpemhjcA4sHI7R3ZbZkJ3VZNzheDoUGO zQCLbp6SI8wNvxpzNP0TnfEgf/278HOwqS+9isQ7DltLmdIeAIQo9WH0ffkiDmWzylE9pRKRhiTDg wP4=; 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 1xQlN4-000000003a3-2ea2; Tue, 10 Nov 2026 12:54:42 +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 1xQlN2-000000003XX-2cw9 for openvpn-devel@lists.sourceforge.net; Tue, 10 Nov 2026 12:54:40 +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=GqdbuE3mSirmZSdVViH0kHFEtbJPBrMkotBmVQZXo6E=; b=YeYVaPm8/923RrzrPZ/RbBEXqK ZydrYD0OzcQTPQ6qQb7zy5gdcFcNF6a5It4BQ5u8QDwAnau8I8wfGbNEtMCucX0bUHewXpyPxYCTH /+J41Kz94uyZ8RXZ/Tsl5HQAT/Z+/QWC7GasP0XfQh0n5vj2TicTRM2FWQtslyqRGdI0=; 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=GqdbuE3mSirmZSdVViH0kHFEtbJPBrMkotBmVQZXo6E=; b=fCJ1w7TX30DJ+n80G9S1SFXmPY vkBwzyNq5ZqOz+b7+F57XOBFIpegQs8Wh+ET7B0vxgNC7SFLPPRfwYIaplkDkXcLbMtIhY/swvk89 RqjCZh8A35YT59+PpuAEdNYn9ENccGU4HZeeOVP5PuXnOH9cXyZs2GfRbhEAEXd0kkZ4=; Received: from mout-b-112.mailbox.org ([195.10.208.42]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQlN0-000000006Kt-3wLh for openvpn-devel@lists.sourceforge.net; Tue, 10 Nov 2026 12:54:40 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-112.mailbox.org (Postfix) with ESMTPS id 4jP66v0T28z5wvg for ; Tue, 10 Nov 2026 13:54:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794315271; 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=GqdbuE3mSirmZSdVViH0kHFEtbJPBrMkotBmVQZXo6E=; b=gLFphV2XWKhU1jxHbSFbzm+eeJbJlX+ohtJd4LjbPwLzvYZTC2uiWCpJW7RAZgTdmiiCq/ e5JWfs5eKDh+j606sqmqXWY35p6flVngpyMH+oART1UFq0eLksDYl3sHrZywSdmZBMQ4Mk w/yPHxjH/HMwLishDd2+V9FrbtUwka0wEQsAYRzNmdOK1VrEv392icJBNDhD2sQA/c9cds IN+Siu08Lcb5pcxA1L1oXOrSMZx5/uQJll9e3xj8t/5t5HCdLNsWG6tcZiOzQyZ4NayNjQ HIHdEvRFgXdDjUiMGiMBAvdgAJb1QymMiQyt1DRUfdfi2ba6G39ik2/WRK47tQ== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Tue, 10 Nov 2026 13:54:22 +0100 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jP66v0T28z5wvg 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_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1xQlN0-000000006Kt-3wLh Subject: [Openvpn-devel] [PATCH ovpn net-next 5/5] 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: 1881475943650665559 X-GMAIL-MSGID: 1881475943650665559 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 --- 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 98f55f178a95..5e5e48c02e13 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); @@ -220,6 +237,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 @@ -229,9 +247,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 (its outer * VLAN tag was already consumed by the receive stack) */