[Openvpn-devel,net-next,v3,6/6] ovpn: prefetch encrypted records before GRO batch decryption
| Message ID | 874ca8e9efb787fd37a942817239c8ba1a4fa4b3.1794388607.git.ralf@mandelbit.com |
|---|---|
| State | New |
| Headers |
Return-Path: <openvpn-devel-bounces@lists.sourceforge.net>
Delivered-To: patchwork@openvpn.net
Received: by 2002:a05:6022:529c:b0:11a:a05e:cb97 with SMTP id x28csp179274lax;
Wed, 11 Nov 2026 01:23:05 -0800 (PST)
X-Forwarded-Encrypted: i=2;
AL+hErFyJIi+mv3NrD+/dlf+6wu+f4udXbWUTtlSdb71dZn8CDnFs38GW14aQddHhE7pSglIG6YD2PZEgNY=@openvpn.net
X-Received: by 2002:a05:7300:561c:b0:36e:2626:4ace with SMTP id
5a478bee46e88-3768366a866mr2610164eec.5.1794388985225;
Wed, 11 Nov 2026 01:23:05 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1794388985; cv=none;
d=google.com; s=arc-20260327;
b=SVghtTwjVSCMRbBdGTSert6vd+xZ1BqBue53NcICol7IVM7JZb76K2nRiDw31glcF+
39hPtOYcgzfTPn+oVs4BjhTB5bBlFnaL1miUD3gAqk6+gL48QItoD+m2l8RmS/Jz7VlP
8WFIfAtO0lreA+DHv0e+a1z9+B9LPVOVOpNb/z+gP5Ju7SJIG7li7jOZBZSuWGMFRDGd
VLk+0NLXrGMuJM3Vc+rmNg33khIADuB9XqC1CCpxkU5xPWiPmjz005QOMJE/1+tSy+zE
cfJQOBcb+0vaRU5Docw9LsLHcKfMDXxT0pFdNBf87kaVmjGhFLChLgOvLc5NS1RTpAyz
6ZVA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;
s=arc-20260327;
h=errors-to:content-transfer-encoding:list-subscribe:list-help
:list-post:list-archive:list-unsubscribe:list-id:precedence:subject
:mime-version:references:in-reply-to:message-id:date:to:from
:dkim-signature:dkim-signature:dkim-signature:dkim-signature;
bh=W85Qy5Gi5Jg7rBf0qb3WikHos83uBthfhWymNWrJsFM=;
fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=;
b=X55+m7i9FVeELqKPGpizfptvScHNCYecvc59UsxAEflyLXKe5opVTk5zWi9xPnBbGN
RYus5rzg853S3HWgCbDzw3pFOjaQfwLb8pfFOpMndTu1ZOEN91UsnH7+/CHC0TKqdpl9
s5I0lgo917xuFVUgf8bCD1hdM9/BQiurXFGpj8Vk3NVhJqOCcYCIREU4pIUElktXDBp6
viLMIBLee3enHLczhfbo4X48tNep9ZQWAoD9XS14LUtvC84VHe2y73RdpHS4KvuIEMe7
AiyqR82npoKR28pRj2/XmCnYXWpUMSxfBu1L9/29BuMImoymFUhbDddpdf5R/7cAO1nN
R1Eg==;
dara=google.com
ARC-Authentication-Results: i=1; mx.google.com;
dkim=pass header.i=@lists.sourceforge.net header.s=beta
header.b=fVFL5Zki;
dkim=neutral (body hash did not verify) header.i=@sourceforge.net
header.s=x header.b=HQyMTNqm;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b="YdEC3r5/";
dkim=neutral (body hash did not verify) header.i=@mandelbit.com
header.s=MBO0001 header.b=VgYq4cUp;
spf=pass (google.com: domain of
openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as
permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net
Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7])
by mx.google.com with ESMTPS id
5a478bee46e88-37520616b4dsi10109972eec.33.2026.11.11.01.23.04
(version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
Wed, 11 Nov 2026 01:23:05 -0800 (PST)
Received-SPF: pass (google.com: domain of
openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as
permitted sender) client-ip=216.105.38.7;
Authentication-Results: mx.google.com;
dkim=pass header.i=@lists.sourceforge.net header.s=beta
header.b=fVFL5Zki;
dkim=neutral (body hash did not verify) header.i=@sourceforge.net
header.s=x header.b=HQyMTNqm;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b="YdEC3r5/";
dkim=neutral (body hash did not verify) header.i=@mandelbit.com
header.s=MBO0001 header.b=VgYq4cUp;
spf=pass (google.com: domain of
openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as
permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type:
List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:
Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender:
Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From:
Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post:
List-Owner; bh=W85Qy5Gi5Jg7rBf0qb3WikHos83uBthfhWymNWrJsFM=; b=fVFL5ZkiOnU1Lw
64Q04KlOXFSRNNVrEkG4Yylc8WEheC9r70ffdLMzt6S7ZAar08NfbcwwvqAuqzBIuThL0f8dIMcg+
BdVZp0DOm8gU+qMclbLF0f82UynAXFgUsDlfV4WULWOQGX612zmhy0+6K8PIL8X0ZptD/SihIy2Mt
aU8=;
Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com)
by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.100.1)
(envelope-from <openvpn-devel-bounces@lists.sourceforge.net>)
id 1xR4Xo-000000005EN-12Dx;
Wed, 11 Nov 2026 09:23:04 +0000
Received: from [172.30.29.66] (helo=mx.sourceforge.net)
by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1)
(envelope-from <ralf@mandelbit.com>) id 1xR4Xn-000000005EF-2jGk
for openvpn-devel@lists.sourceforge.net;
Wed, 11 Nov 2026 09:23:03 +0000
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References:
In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:
Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:
List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive;
bh=Qvh3gCSy7RRLdCBAaw/mKlXByRy9A7eo6jF1P58RciE=; b=HQyMTNqmwiOCuFfWOrgWIiMdqw
N0iiQTQs24vmOZY65gschtDKtA7XHP8ZMxp1tsaONVnSX7aEOprpnIfRf4tayl+rOnVPBAwgqTU9u
dhkTuaPsPn1IOgBXpkQuIvEka5FzfB7/dPyypibge4Bd76WkZASZYfiHyMU+8MKJFatY=;
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x
;
h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:
Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID:
Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Unsubscribe-Post:
List-Subscribe:List-Post:List-Owner:List-Archive;
bh=Qvh3gCSy7RRLdCBAaw/mKlXByRy9A7eo6jF1P58RciE=; b=YdEC3r5/dbgsjxEpsN8N6JPIZX
MOIQnOWWvSDSrl2NJMnXEXApunXZuY4yIM6xXgcF5BSbqA/Ea8KegW40aBS52Max3s0vzv53emUNX
F9Q5/vpFms4jc60K3ka35AZ6cAnf64uZdELVaDAhlSYXxaoPHWXc4hVdLvi4fJ4QTOpw=;
Received: from mout-b-105.mailbox.org ([195.10.208.50])
by sfi-mx-1.v28.lw.sourceforge.com with esmtps
(TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1)
id 1xR4Xl-000000000H4-3Xla for openvpn-devel@lists.sourceforge.net;
Wed, 11 Nov 2026 09:23:03 +0000
Received: from smtp202.mailbox.org (smtp202.mailbox.org
[IPv6:2001:67c:2050:b231:465::202])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits)
server-digest
SHA256) (No client certificate requested)
by mout-b-105.mailbox.org (Postfix) with ESMTPS id 4jPdNF3rsFz9syq
for <openvpn-devel@lists.sourceforge.net>;
Wed, 11 Nov 2026 10:22:53 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com;
s=MBO0001; t=1794388973;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references;
bh=Qvh3gCSy7RRLdCBAaw/mKlXByRy9A7eo6jF1P58RciE=;
b=VgYq4cUp9MD8MAhje7tSS6vuoc7MDMDDOus4Jgt/rMRMDwdpg4pOH3ftH1WOmIdjtD3WuV
wmbobvEIsVfZxWireIpjLioGHPr3MXfB4n2om/FeFtG5COYSKqDU3RkNCrIm6fCk5fD4LV
xgj4ZPT2lq071rxNnmSA25e0uBZt8rtjeGjIDI3OUtKat3SAjhlTTqWc5lasv8MaQYFxVA
MaQ5gqPhvNVNqh8JiHsVK+zL14dzJOGUQ+PBDkqXZw0N1SqpObdFhFwl+ytr2LDlbPgDvG
iwQJjvlNVMQx9F0rcsAigQQjR2C2pmBIL/QCK0A7uL7BUA3+3hH2HFwcOwIFdg==
Authentication-Results: outgoing_mbo_mout; dkim=none;
spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates
2001:67c:2050:b231:465::202 as permitted sender)
smtp.mailfrom=ralf@mandelbit.com
From: Ralf Lici <ralf@mandelbit.com>
To: openvpn-devel@lists.sourceforge.net
Date: Wed, 11 Nov 2026 10:22:38 +0100
Message-ID:
<874ca8e9efb787fd37a942817239c8ba1a4fa4b3.1794388607.git.ralf@mandelbit.com>
X-Mailer: git-send-email 2.56.0
In-Reply-To: <cover.1794388607.git.ralf@mandelbit.com>
References: <cover.1794388607.git.ralf@mandelbit.com>
MIME-Version: 1.0
X-Rspamd-Queue-Id: 4jPdNF3rsFz9syq
X-Spam-Score: -0.2 (/)
X-Spam-Report: Spam detection software,
running on the system "sfi-spamd-2.hosts.colo.sdot.me",
has NOT identified this incoming email as spam. The original
message has been attached to this so you can view it or label
similar future email. If you have any questions, see
the administrator of that system for details.
Content preview: Frag-list GRO exposes later encrypted records before the
receive
path decrypts the current one. Use this lookahead to request write ownership
of linear ciphertext cache lines two records in advance, a [...]
Content analysis details: (-0.2 points, 5.0 required)
pts rule name description
---- ----------------------
--------------------------------------------------
-0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's
domain
0.1 DKIM_SIGNED Message has a DKIM or DK signature,
not necessarily valid
-0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from
envelope-from domain
-0.1 DKIM_VALID Message has at least one valid DKIM or DK signature
X-Headers-End: 1xR4Xl-000000000H4-3Xla
Subject: [Openvpn-devel] [PATCH ovpn net-next v3 6/6] ovpn: prefetch
encrypted records before GRO batch decryption
X-BeenThere: openvpn-devel@lists.sourceforge.net
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: <openvpn-devel.lists.sourceforge.net>
List-Unsubscribe: <https://lists.sourceforge.net/lists/options/openvpn-devel>,
<mailto:openvpn-devel-request@lists.sourceforge.net?subject=unsubscribe>
List-Archive:
<http://sourceforge.net/mailarchive/forum.php?forum_name=openvpn-devel>
List-Post: <mailto:openvpn-devel@lists.sourceforge.net>
List-Help: <mailto:openvpn-devel-request@lists.sourceforge.net?subject=help>
List-Subscribe: <https://lists.sourceforge.net/lists/listinfo/openvpn-devel>,
<mailto:openvpn-devel-request@lists.sourceforge.net?subject=subscribe>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: openvpn-devel-bounces@lists.sourceforge.net
X-getmail-retrieved-from-mailbox: Inbox
X-GMAIL-THRID: 1881553224320281611
X-GMAIL-MSGID: 1881553224320281611
|
| Series |
ovpn: construct and process GRO batches
|
|
Commit Message
Ralf Lici
Nov. 11, 2026, 9:22 a.m. UTC
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 <ralf@mandelbit.com>
---
No changes since v2 https://lore.kernel.org/openvpn-devel/bad00484f77503ede2affa16075325a00b5cef04.1794329430.git.ralf@mandelbit.com/
No changes since v1 https://lore.kernel.org/openvpn-devel/e18ef3363a3d5167cddb8b0528d447ba1d5aa2ed.1794314969.git.ralf@mandelbit.com/
drivers/net/ovpn/udp.c | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
Comments
Hi Ralf, On 11/11/2026 10:22, Ralf Lici wrote: > 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. I tried issuing the prefetch earlier: in ovpn_udp_gro_receive_fraglist(), when each record joins the aggregate, instead of in ovpn_udp_recv() right before decryption. The lines are then requested one record at a time, as the packets arrive, and they are already cached when the batch is decrypted, including the first records of the batch, which the window can only prime right before they are decrypted. On our perf branch (your v3 plus some RX changes of ours), single stream over UDP transport, ConnectX-5 back to back, mlx5 with RX look-ahead prefetch, NIC MTU 1500, 3 rounds, Gbit/s: window join TCP aes 40.71 43.56 +7.0% aegis128x4 44.01 45.19 +2.7% UDP GSO aes 44.86 48.29 +7.6% aegis128x4 47.20 52.34 +10.9% "window" is your patch 6, "join" is the change below, everything else is identical. The receiving CPU spends 3-14% fewer cycles per packet, about twice as many demand fills are served from L2, and in the UDP GSO test the receiver drops half as many packets. On the previous GRO design, with the stock mlx5 driver, I had measured +0.8% to +10.2%. The change against your v3: diff --git a/drivers/net/ovpn/udp.c b/drivers/net/ovpn/udp.c index 2f77acc47bd9..66d80a4268db 100644 --- a/drivers/net/ovpn/udp.c +++ b/drivers/net/ovpn/udp.c @@ -35,9 +35,6 @@ /* 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; @@ -94,6 +91,11 @@ static struct sk_buff *ovpn_udp_gro_receive_fraglist(struct sock *sk, NAPI_GRO_CB(skb)->encap_mark = 0; NAPI_GRO_CB(skb)->is_flist = 1; + /* the record is decrypted only after its aggregate is delivered: start + * fetching its linear data now, one record at a time + */ + ovpn_udp_prefetchw_linear(skb); + list_for_each_entry(p, head, list) { if (!NAPI_GRO_CB(p)->same_flow) continue; @@ -249,7 +251,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; + struct sk_buff *skb, *next; const __be16 proto = list->protocol; const u32 priority = list->priority; #ifdef CONFIG_NET_SCHED @@ -259,23 +261,8 @@ 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; - int i; - - /* a fraglist GRO aggregate makes later ciphertext visible before the - * current record is decrypted, so we prime the first two records, then - * keep the cache hints the same distance ahead while draining the list - */ - prefetch = list->next ? list : NULL; - for (i = 0; i < OVPN_UDP_GRO_PREFETCH_DISTANCE && prefetch; i++) { - ovpn_udp_prefetchw_linear(prefetch); - prefetch = prefetch->next; - } skb_list_walk_safe(list, skb, next) { - if (prefetch) { - ovpn_udp_prefetchw_linear(prefetch); - prefetch = prefetch->next; - } /* propagate post-GRO metadata from the list head, and clear * the state which the receive stack consumed on the head only */ Records that GRO refuses (not DATA_V2, already GSO, inside FOU/GUE) take the flush path before the prefetch, so they are not touched; records that start a new aggregate, or are delivered alone, are prefetched too. Let me know what you think and if you want to fold this change into patch 6. Cheers, -- Antonio Quartulli
Hi Antonio, I think the idea is a valid optimization but, as you reported, currently it doesn't translate to a measurable improvement on top of GRO v3. As long as decryption dominates the per-record cost, prefetching two records ahead while the current one is decrypted already hides most of the memory latency. There's also a scenario where this change can make things worse: if RPS is enabled on the ethernet interface, the GRO NAPI issues the prefetch on the wrong CPU (that is, not the one responsible for decryption). When the skb then arrives in ovpn, there's no longer any prefetching happening and the crypto stalls on data owned by the GRO CPU. On your perf-next, steering to a CPU on the other CCD already costs the window a lot (38.1 -> 24.2 Gbit/s), and join loses another 31% on top of that (16.7 Gbit/s). On Wed, 25 Nov 2026 14:58:21 +0100, Antonio Quartulli <a@unstable.cc> wrote: > On 25/11/2026 02:52, Antonio Quartulli wrote: > > On our perf branch (your v3 plus some RX changes of ours), single stream > > over UDP transport, ConnectX-5 back to back, mlx5 with RX look-ahead > > prefetch, NIC MTU 1500, 3 rounds, Gbit/s: > [...] > > A follow-up, now measured on your series alone: your GSO v5 + GRO v3, > same setup (on a 7.4-rc4 based kernel), AES-GCM, 3 rounds, Gbit/s: > > window join > TCP 30.57 31.04 +1.5% > UDP GSO 32.26 32.18 -0.2% > I started with the posted series (GSO v5 + GRO v3) on my usual setup (9950X with a CX5 hairpin, one pinned TCP flow): Gbit/s RX CPU cycles/B window join join vs window stock mlx5 24.96 25.07 +1.1% + mlx5 prefetch v2 27.45 27.50 -1.2% + TSO series 29.97 30.13 +0.1% Then I also ran your perf-next branch as of today (4a8182fa1798): Gbit/s RX CPU cycles/B window join join vs window TCP 38.14 38.39 -1.7% inner UDP GSO 24.49 24.52 -0.2% So the receive cost does drop a bit with TCP once the path is cheaper, but I can't reproduce the throughput gain yet. A window distance of 4 instead of 2 gets about half of the TCP saving (-0.9%). I also wonder how your UDP GSO runs reach 45-48 Gbit/s: here the sender offers about that much, but the receiver can't keep up, the NIC drops about half, and ~24.5 Gbit/s arrives. Is yours the received rate? What's the secret recipe? As expected, with RPS on the physical port, steering to a CPU on the other CCD already costs the window a lot (38.1 -> 24.2 Gbit/s), and join loses another 31% on top of that (16.7 Gbit/s), with the decrypting CPU reading the ciphertext from DRAM. > Given that, I think it fits better as a follow-up than folded into > patch 6: no need to respin v3 for it. > Agreed. Cheers!
diff --git a/drivers/net/ovpn/udp.c b/drivers/net/ovpn/udp.c index e3a8aa83344f..2f77acc47bd9 100644 --- a/drivers/net/ovpn/udp.c +++ b/drivers/net/ovpn/udp.c @@ -6,9 +6,11 @@ * Author: Antonio Quartulli <antonio@openvpn.net> */ +#include <linux/cache.h> #include <linux/netdevice.h> #include <linux/inetdevice.h> #include <linux/if_vlan.h> +#include <linux/prefetch.h> #include <linux/skbuff.h> #include <linux/socket.h> #include <linux/udp.h> @@ -33,6 +35,21 @@ /* like UDP and TCP frag-list GRO */ #define OVPN_UDP_GRO_CNT_MAX 64 +/* leave enough work between a cache hint and the record which consumes it */ +#define OVPN_UDP_GRO_PREFETCH_DISTANCE 2 + +static void ovpn_udp_prefetchw_linear(const struct sk_buff *skb) +{ + unsigned long addr = (unsigned long)skb->data; + unsigned long end = addr + skb_headlen(skb); + + /* crypto overwrites data in place, so request write ownership of each + * linear cache line before the AEAD implementation reaches it + */ + for (; addr < end; addr = ALIGN(addr + 1, L1_CACHE_BYTES)) + prefetchw((void *)addr); +} + static bool ovpn_udp_gro_header(struct sk_buff *skb, u32 *header) { const unsigned int offset = skb_gro_offset(skb); @@ -232,6 +249,7 @@ static struct sk_buff *ovpn_udp_gso_prepare(struct sk_buff *skb, u32 header) static void ovpn_udp_recv(struct ovpn_peer *peer, struct sk_buff *list) { + struct sk_buff *skb, *next, *prefetch; const __be16 proto = list->protocol; const u32 priority = list->priority; #ifdef CONFIG_NET_SCHED @@ -241,9 +259,23 @@ static void ovpn_udp_recv(struct ovpn_peer *peer, struct sk_buff *list) const u32 secmark = list->secmark; #endif const int skb_iif = list->skb_iif; - struct sk_buff *skb, *next; + int i; + + /* a fraglist GRO aggregate makes later ciphertext visible before the + * current record is decrypted, so we prime the first two records, then + * keep the cache hints the same distance ahead while draining the list + */ + prefetch = list->next ? list : NULL; + for (i = 0; i < OVPN_UDP_GRO_PREFETCH_DISTANCE && prefetch; i++) { + ovpn_udp_prefetchw_linear(prefetch); + prefetch = prefetch->next; + } skb_list_walk_safe(list, skb, next) { + if (prefetch) { + ovpn_udp_prefetchw_linear(prefetch); + prefetch = prefetch->next; + } /* propagate post-GRO metadata from the list head, and clear * the state which the receive stack consumed on the head only */