From patchwork Fri Nov 13 15:51:08 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5687 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:18c:b0:11a:a05e:cb97 with SMTP id 12csp372174lag; Fri, 13 Nov 2026 07:52:11 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErEa3TQ83V9uhTN2qcvuPx7JiYwED6ZQ9L012Hoewmv7ogqIjGWjV0X4glzJx7vW0/rKPNv4RspfQhc=@openvpn.net X-Received: by 2002:a05:7022:f20f:b0:1b3:b53e:b4cd with SMTP id a92af1059eb24-1b5031003e7mr3253109c88.21.1794585130684; Fri, 13 Nov 2026 07:52:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794585130; cv=none; d=google.com; s=arc-20260327; b=pczPcesr23lVIamu6IzUpxuOWfmUOVPfDMyGLwcjZrHzK6XA0/Pbo9WtX7O+J0AZfA CYl5kPSajwEsNnN26uDYg6QKdODaHWk1N2zBTqg4Ys2D9n/M2btkrzgR0Vwr8jleoenc LP4WVaptpfOqsUgj8Hsi6mxzuibsIoulMhGCVndfnpLa1Ogh/WrL+vYQlZL31pC+a1d4 RhnBaikjOC8T8gAErbOCWBmmQyuOxsWj4W9tRMluZLyxuG3djubSVY9bXI6e2spmFB10 6HCdOtv7KlPyyKgSTU+wNICVyKaGoD5LN9VhzW8T6/eqztwR58PkSehlJW68n8JwBzkX NSNw== 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=zK2wJ4e5yzgYnPj8g59I+4BUAtVHRQjs/GmRPncJqbg=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=o/1QTKID2varaHJLzF7O6KSKidJ+QykfteU6REfwwf0WGA6aMdX+xEzv28aPHLtmOV N61iFycV1dANIRvRE5LaSCUpp/DJXMDyArtXzRpEXFDqY//9TMYfnCvMU6FG3Rj6YhrZ u/xVauEa2VYtuZhmD5hA9B/1VZrMrLgGhYSuxFEoeBQJLel/nklWlbaKJ6uVf6Hz+Us2 1zQ8a01m7N+veax52yfFF8/pfAJuVbIRTDyrtccGLPsqGVZsbBkNLTQV5touS8olEu+P JdV7MJFHLaJ/8ZTS7V6Ouu8sWD0HIzoa4lh0Xp/QT/oXBet9UUsLO6X4QHCQVhzimAYB y1fA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=mI8uaQ+3; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=RNfRpArw; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=d47gKE8U; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=s3m+thhl; 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-1b50320b21fsi7476124c88.39.2026.11.13.07.52.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Nov 2026 07:52: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=mI8uaQ+3; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=RNfRpArw; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=d47gKE8U; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=s3m+thhl; 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=zK2wJ4e5yzgYnPj8g59I+4BUAtVHRQjs/GmRPncJqbg=; b=mI8uaQ+3PKhRWa T2jDaNnrjYckuTttsFNd49HfesiY8ioEAmhIkEYNmEBwYDXht9l/rHjW+gTs/YpfmMgf8PQghARU8 ecuLpd8/uN58EA62onav0W+B7lueqHiy0oltZrRP3QmPxfGAPNyX29qK2mQfTeF/4nxt9a+4Z7apd f30=; 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 1xRtZP-000000001cg-1IYY; Fri, 13 Nov 2026 15:52:07 +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 1xRtZ3-000000001bq-1GsS for openvpn-devel@lists.sourceforge.net; Fri, 13 Nov 2026 15:51:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=EBaMv1Up8WZ2SIVrIOfS6UCMtGuwmpcraujElV/HPG4=; b=RNfRpArwnC8fvMDJdWbTk+4zEj agE8GomcxijSeVXXvz67VYyf9W3sadTsPOIJTJ4jD5KscXlsWBLys+MC/XgZQiJ6LFwaI1zss+KNh TUi5UFsiZeKCWqJ3R9cPrw0Ca9MZlvSlskyCWlki5oJfkSIG6Ru2WKGQo6Y4s3nIoyVs=; 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=EBaMv1Up8WZ2SIVrIOfS6UCMtGuwmpcraujElV/HPG4=; b=d47gKE8UdcspGHd4JeZ4b3UKz4 pMkpsqRfs8CgZA+tBWQVB7KEy1yXL+dIMDOISqC4m6ilk7N09F9YpXiGW7JUldXvJFJS1Cc0galDP wZFJQiq4kyUuhtMIQKINzaIw5WeOXC5qn3oRDuzfDBUNfX+dnlvzcj/kOx2XBtrSwnYU=; 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 1xRtYp-0000000082g-1Mr1 for openvpn-devel@lists.sourceforge.net; Fri, 13 Nov 2026 15:51:33 +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 4jR1vb3NZyz9tHg for ; Fri, 13 Nov 2026 16:51:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794585083; 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=EBaMv1Up8WZ2SIVrIOfS6UCMtGuwmpcraujElV/HPG4=; b=s3m+thhlkUmhrDY4KsmIDXQiO2uCzxBlRgxs4Cow/6HIRb354D3fDlJ0+QOKc3oApjgOfc nYUzTm3EhEJzj/q5YZ4WQhcFVWK0dkS8lHeALpsFUCDiTRywBKw2xrW1Azy+k1T7RIY1YA yBU0M05yKuEhIXMjadl2bPh/uzBzvFeczWd8rxF2TKpTKpbVZw6NcAn6Ki2/1e615T1t33 WXVFmhCMIfiOq4FOKDsAnv82U0ERXODpUL1kcAKOswlYm9egdK1tmQfbDWUNFLj2rZ1zET 2tNeGeotOEgHJGFfszD2/q9ews/yoRbQ5NFGxTI89Vy2hDoDn2VjfbEhAp+HDw== 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: Fri, 13 Nov 2026 16:51:08 +0100 Message-ID: <94de56d9eeb2f85498789fca8398b3399fc4e3bf.1794584066.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jR1vb3NZyz9tHg X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-2.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The UDP GSO batching loops work directly on the queue of materialized segments. Let them work on a source which tracks the number of records, the next one and their lengths instead. The segment queue [...] 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: 1xRtYp-0000000082g-1Mr1 Subject: [Openvpn-devel] [PATCH ovpn net-next 3/5] ovpn: batch GSO records from a generic source 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: 1881758898100078641 X-GMAIL-MSGID: 1881758898100078641 The UDP GSO batching loops work directly on the queue of materialized segments. Let them work on a source which tracks the number of records, the next one and their lengths instead. The segment queue remains the only source, so there is no functional change. This prepares for records which are ranges of one parent skb. Signed-off-by: Ralf Lici --- drivers/net/ovpn/gso.c | 138 ++++++++++++++++++++++++----------------- 1 file changed, 80 insertions(+), 58 deletions(-) diff --git a/drivers/net/ovpn/gso.c b/drivers/net/ovpn/gso.c index e72f835e2a60..432738812548 100644 --- a/drivers/net/ovpn/gso.c +++ b/drivers/net/ovpn/gso.c @@ -32,11 +32,18 @@ sizeof(struct ipv6hdr) - \ sizeof(struct udphdr) - 1) -static bool ovpn_gso_encrypt_queue(struct sk_buff_head *skbs, +struct ovpn_gso_source { + unsigned int segments; + unsigned int next; + unsigned int record_len; + unsigned int last_record_len; + struct sk_buff_head *skbs; +}; + +static bool ovpn_gso_encrypt_batch(struct ovpn_gso_source *src, struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, - struct sk_buff *batch, - unsigned int segments) + struct sk_buff *batch, unsigned int segments) { unsigned int offset = 0, moved = 0, i, len; struct ovpn_aead_gso_ctx ctx = { }; @@ -57,7 +64,8 @@ static bool ovpn_gso_encrypt_queue(struct sk_buff_head *skbs, } for (i = 0; i < segments; i++) { - skb = __skb_dequeue(skbs); + skb = __skb_dequeue(src->skbs); + src->next++; len = skb->len + OVPN_DATA_V2_OVERHEAD; ret = ovpn_aead_encrypt_gso(&ctx, peer, ks, skb, batch, offset, @@ -162,6 +170,67 @@ static struct sk_buff *ovpn_gso_alloc(const struct sk_buff *first_segment, return gso_skb; } +static void ovpn_gso_send_batch(struct ovpn_gso_source *src, + struct ovpn_peer *peer) +{ + unsigned int max_segs, batch_len, batch_segs, batch_start; + struct ovpn_crypto_key_slot *ks; + struct sk_buff *batch; + + max_segs = min_t(unsigned int, UDP_MAX_SEGMENTS, + OVPN_GSO_MAX_PAYLOAD / + (src->record_len + OVPN_DATA_V2_OVERHEAD)); + + /* if even two encrypted records cannot fit, leave the source for the + * ordinary transmit path + */ + if (max_segs < 2) + return; + + /* An input GSO skb might produce more than max_segs records, so + * consume as many as can fit in each aggregate. A final materialized + * one, or the remainder after a failure, stays for the ordinary path. + */ + while (src->segments - src->next > 1) { + batch_start = src->next; + batch_segs = min(src->segments - src->next, max_segs); + + /* acquire shared state before allocating/consuming anything */ + ks = ovpn_encrypt_refs_get(peer); + if (unlikely(!ks)) + break; + /* recheck in case the key was swapped */ + if (unlikely(ks->async)) { + ovpn_crypto_key_slot_put(ks); + ovpn_peer_put(peer); + break; + } + + /* all but the final input record have the same length, so + * start with the full-size calculation and adjust only the + * final group below + */ + batch_len = batch_segs * + (src->record_len + OVPN_DATA_V2_OVERHEAD); + if (batch_start + batch_segs == src->segments) + batch_len -= src->record_len - src->last_record_len; + + batch = ovpn_gso_alloc(skb_peek(src->skbs), batch_len, + batch_segs); + if (unlikely(!batch)) { + ovpn_crypto_key_slot_put(ks); + ovpn_peer_put(peer); + break; + } + + if (unlikely(!ovpn_gso_encrypt_batch(src, peer, ks, batch, + batch_segs))) { + kfree_skb(batch); + break; + } + } +} + /** * ovpn_gso_send - encrypt materialized segments into UDP GSO aggregates * @skbs: segments of one GSO skb, all but the last of the same length @@ -174,61 +243,14 @@ static struct sk_buff *ovpn_gso_alloc(const struct sk_buff *first_segment, */ void ovpn_gso_send(struct sk_buff_head *skbs, struct ovpn_peer *peer) { - unsigned int max_segs, seg_len, batch_len, segs; - struct ovpn_crypto_key_slot *ks; - struct sk_buff *batch; + struct ovpn_gso_source src = { + .segments = skb_queue_len(skbs), + .record_len = skb_peek(skbs)->len, + .last_record_len = skb_peek_tail(skbs)->len, + .skbs = skbs, + }; - seg_len = skb_peek(skbs)->len + OVPN_DATA_V2_OVERHEAD; - max_segs = min_t(unsigned int, UDP_MAX_SEGMENTS, - OVPN_GSO_MAX_PAYLOAD / seg_len); - - /* if even two encrypted skbs cannot fit, leave the whole queue for the - * ordinary transmit path - */ - if (max_segs < 2) - return; - - /* An input GSO skb might produce more than max_segs segments, so we - * consume as many as we can for each iteration. A final single skb, or - * any remainder left after batching stops, stays queued and falls back - * to the ordinary transmit path. - */ - while (skb_queue_len(skbs) > 1) { - segs = min_t(unsigned int, skb_queue_len(skbs), max_segs); - /* acquire shared state before allocating/consuming anything */ - ks = ovpn_encrypt_refs_get(peer); - if (unlikely(!ks)) - return; - /* recheck in case the key was swapped */ - if (unlikely(ks->async)) { - ovpn_crypto_key_slot_put(ks); - ovpn_peer_put(peer); - return; - } - - /* all but the final input skb have the same length, so start - * with the full-size calculation and adjust only the final - * group below - */ - batch_len = segs * (skb_peek(skbs)->len + - OVPN_DATA_V2_OVERHEAD); - if (segs == skb_queue_len(skbs)) - batch_len -= skb_peek(skbs)->len - - skb_peek_tail(skbs)->len; - - batch = ovpn_gso_alloc(skb_peek(skbs), batch_len, segs); - if (unlikely(!batch)) { - ovpn_crypto_key_slot_put(ks); - ovpn_peer_put(peer); - return; - } - - if (unlikely(!ovpn_gso_encrypt_queue(skbs, peer, ks, - batch, segs))) { - kfree_skb(batch); - return; - } - } + ovpn_gso_send_batch(&src, peer); } /**