From patchwork Wed Sep 16 06:52:47 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5351 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:6446:b0:8a0:ea1f:253a with SMTP id n6csp5853250mag; Tue, 15 Sep 2026 23:53:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvBwTurSfWawg5zC9cDWbUi/S2WU2y5xrrByhGOKps9KzT064FjvFbcpIDqC2rPG5Ae9WyrElOdxV+tg=@openvpn.net X-Received: by 2002:a05:6808:1202:b0:4be:84c2:9836 with SMTP id 5614622812f47-4ca4ac0e54dmr2805705b6e.1.1789541598354; Tue, 15 Sep 2026 23:53:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1789541598; cv=none; d=google.com; s=arc-20260327; b=eMMnscpwVMCZkTdmQgWaWZgoOsNcPHJUrLtTjEeaeHOjAgDz5QN+XJdavwBB5Wglau PnR42f7TpHF45P8YDAnsgRfYD9wYp3NNPogB7+D4WGuVL7oKci1bfUkZkP845pIh2dWW dmyl2+j49+xD6BRdH9lbyrttIh/+k7UUMDFKOowrADiXD0v5x+38lbRAayKVVCYV4adu cdc/vKHTy9RHpOMAnc63R9hsRSiVRIoUwd7jusicmpLJTn2JkCBSM8wjhROPrAE1+keL VRO9MMMrSzOlEA8LDpaj0WSgxlaayhRcf8Cocso7NNrggfHWqs/hNEg3D5wlGy1Z+Loa zO9A== 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=iei6ny9eGSMnCN+hQOO5H1GkevsRlg9PuuVOWUgcNQI=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=KjJKrWSBvoKJvMs+DrhJiR7yUaSeObGejN8C8jmZ+qvMEQa4Ea+qXbw/Zvn8xN7zOq 9Y9QozRrar2DN8an29cS0rIs9s/ehJmObPcnLoUUo4WKrAh3bCuXKSyzLdgEf2sVC9ZX 7fkLybzRlwpUCjKHuDbm/AhLFH50ih1D4Vyxr9ZxRXbh5uvP/X2QJZ88oyCjDCZz5+yH HhxSLYOR1PkRYNWFUR8rg1AIINsTMsfmtIJGiG6gSxzHhuO/LkEkJ5WoLEQa9NywzXM0 fXZzUkNoZ83u7LC8INE8AvNK8Uw78m/V8AlT5SBmBP1FfxHlKFrnlBDMleF0IuI9wr0m enng==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=TC5P41wl; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=frhoYRdE; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=N+vTwZSP; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=flk6s9Lj; 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 5614622812f47-4ca242e2bfdsi2528613b6e.27.2026.09.15.23.53.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Sep 2026 23:53:18 -0700 (PDT) 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=TC5P41wl; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=frhoYRdE; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=N+vTwZSP; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=flk6s9Lj; 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-Owner; bh=iei6ny9eGSMnCN+hQOO5H1GkevsRlg9PuuVOWUgcNQI=; b=TC5P41wlD+r4B1ah9dEWANBgmQ XXyb8g5TvlVdRHmm3ViTIjjqU9uhGOL+9dct6o4NVLe/nb/F+H4kIhfR23oxoTiGa+A76a40Ixr8E pRU7R+0GbcdRaZowI+jI4kKiWa9TKzVCm58McoL/DSjLsO4QdM9qGLPiHYTfyvqla26U=; 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.95) (envelope-from ) id 1x6jW4-00042p-Ch; Wed, 16 Sep 2026 06:53:13 +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.95) (envelope-from ) id 1x6jW2-00042V-DR for openvpn-devel@lists.sourceforge.net; Wed, 16 Sep 2026 06:53:11 +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-Subscribe:List-Post:List-Owner:List-Archive; bh=aU4jL3pubYAoO8V+Pm6EnvN0CS+ibHARwsKWzVcq5IU=; b=frhoYRdEIAehdVXl9HHpLIzJBz XXTxd8JHmfDF5HEwnsF5tn89kv0qNDOGpn2jtIh++vYciEm2Cn9UVCo8tSVEkwwiYicXpOcSPPP01 /DYJjNuGxQi4V2Pk4zRR1GC5Zuc9mVBmjAfmcssX/u1U6xJDsFyFtbmARApPkLVqVB7Y=; 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-Subscribe: List-Post:List-Owner:List-Archive; bh=aU4jL3pubYAoO8V+Pm6EnvN0CS+ibHARwsKWzVcq5IU=; b=N+vTwZSPcBWvf76h8Mky/y9vhV v+Uu3KqI1AlIgGkb7Lpfh4KaZ0W2ew7ABQKhFjN2mqASq9Ipk4rZY40UxST+KR2lSVuW/cKRX8tCC +cZ68Ny+6m1HYRkq0l9psYzkGGICWSTW+W/EZezPlY1dOsosib0luf+yJDBfxYpZxenU=; Received: from mout-b-210.mailbox.org ([195.10.208.40]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1x6jW1-0001sh-Ke for openvpn-devel@lists.sourceforge.net; Wed, 16 Sep 2026 06:53:11 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-210.mailbox.org (Postfix) with ESMTPS id 4hl8j90zBVzFqwW for ; Wed, 16 Sep 2026 08:53:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1789541581; 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=aU4jL3pubYAoO8V+Pm6EnvN0CS+ibHARwsKWzVcq5IU=; b=flk6s9LjnGdNwiSQoZHSHxPEZrif3PMXOCEbDN9t45Wr9o0p8R1nqDpUuwzhslMJ6m6e8H rYLQotWI5G3PK0V/NGM9z8zJoHkXDLkmCW+4E+r6zaO40jlq1JacddAYZ4/d3SCQynEjbE qlyA2urd9Ugh+5IFL7+8aexPyw0JLH2E/Jup+yDvY93NJ9f3DQjZoOWwGiX73pgW04HSRa XuKLmGll5dTu1g7HHE+is9DpHGSChe8V+1VrPuY3/5hJksk+ArUMv9gbqIas9vGxVbmUkN RpLH7OepiUhH7OQX3v4GfQXI8ftPbL5G43Zt/6nJgFg/ekkOVMdVAlvygCWN7Q== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::1 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Wed, 16 Sep 2026 08:52:47 +0200 Message-ID: <4d8357e320fc7c8fd4ab6e42a0bc38b275b1ff5d.1789540779.git.ralf@mandelbit.com> In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4hl8j90zBVzFqwW 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: 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_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1x6jW1-0001sh-Ke Subject: [Openvpn-devel] [RFC ovpn net-next v2 6/9] 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: 1876470371323254050 X-GMAIL-MSGID: 1876470371323254050 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. A same-binary comparison using three 30-second samples per direction found distances one and two effectively tied forward, while distance two was 3.3% faster reverse and less variable in both directions. Profiling also measured slightly fewer decrypt cycles at distance two than at one, while wider distances provided no repeatable benefit. On a direct 100 Gbit/s ConnectX-5 link using one TCP stream, AES-128-GCM, a 1408-byte inner MTU and 8192-entry rings, five interleaved 60-second samples per direction increased throughput by 16.9% forward and 18.0% reverse. Signed-off-by: Ralf Lici --- No changes since v1 https://lore.kernel.org/openvpn-devel/712708baf265c5509aed4f9d476abf514a242b8a.1789485693.git.ralf@mandelbit.com/ drivers/net/ovpn/io.h | 14 ++++++++++++++ drivers/net/ovpn/udp.c | 21 ++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/net/ovpn/io.h b/drivers/net/ovpn/io.h index 1a94f0fda1d1..49180214fe08 100644 --- a/drivers/net/ovpn/io.h +++ b/drivers/net/ovpn/io.h @@ -10,6 +10,9 @@ #ifndef _NET_OVPN_OVPN_H_ #define _NET_OVPN_OVPN_H_ +#include +#include + /* DATA_V2 header size with AEAD encryption */ #define OVPN_HEAD_ROOM (OVPN_DATA_V2_OVERHEAD + \ max(sizeof(struct udphdr), sizeof(struct tcphdr)) +\ @@ -21,6 +24,17 @@ #define OVPN_KEEPALIVE_SIZE 16 extern const unsigned char ovpn_keepalive_message[OVPN_KEEPALIVE_SIZE]; +static inline void ovpn_skb_prefetchw(const struct sk_buff *skb) +{ + unsigned int offset; + + /* crypto overwrites data in place, so request write ownership of each + * linear cache line before the AEAD implementation reaches it + */ + for (offset = 0; offset < skb_headlen(skb); offset += L1_CACHE_BYTES) + prefetchw(skb->data + offset); +} + netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev); void ovpn_recv(struct ovpn_peer *peer, struct sk_buff *skb); diff --git a/drivers/net/ovpn/udp.c b/drivers/net/ovpn/udp.c index adce9dd8629e..ca3344646a27 100644 --- a/drivers/net/ovpn/udp.c +++ b/drivers/net/ovpn/udp.c @@ -32,6 +32,9 @@ /* 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 bool ovpn_udp_gro_header(struct sk_buff *skb, u32 *header) { const unsigned int offset = skb_gro_offset(skb); @@ -178,12 +181,28 @@ static struct sk_buff *ovpn_udp_gro_detach(struct sk_buff *skb) static void ovpn_udp_recv(struct ovpn_peer *peer, struct sk_buff *skb) { - struct sk_buff *next; + struct sk_buff *next, *prefetch; + unsigned int i; skb->next = ovpn_udp_gro_detach(skb); + /* a frag-list 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 = skb->next ? skb : NULL; + for (i = 0; i < OVPN_UDP_GRO_PREFETCH_DISTANCE && prefetch; i++) { + ovpn_skb_prefetchw(prefetch); + prefetch = prefetch->next; + } + skb_list_walk_safe(skb, skb, next) { + if (prefetch) { + ovpn_skb_prefetchw(prefetch); + prefetch = prefetch->next; + } + skb_mark_not_on_list(skb); /* keep the current reference alive for the next record before