From patchwork Mon Nov 9 15:09:06 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5626 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp802956lat; Mon, 9 Nov 2026 07:09:34 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHQ+iApvivsa8naOL84vQnCbF66w5xxEyAX2MtbLUQVHjREZMObGq4g/WahzRif3V16d9NXj88adlY=@openvpn.net X-Received: by 2002:a05:7022:1586:b0:13e:5a50:1e17 with SMTP id a92af1059eb24-1b39fe32b51mr7091058c88.3.1794236974249; Mon, 09 Nov 2026 07:09:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794236974; cv=none; d=google.com; s=arc-20260327; b=dApF1nqfln5dvZZ0Hu/W1NokoOapFYy7EE3gyehbkP8BblZNeAh0vPcARA8q+euS/l mvsHnNj3s0X1u04icNOnLlBj6q1Bgs5t1RtheAuDLkzOh5uICzxyKmK1rdhDMLLBmuAo PRQwmn03TwjYVHAB1rCldTFwxUkjwMCCBrwIsiBsLbNW4Mk4W+QpVYVnzRjnxxO8uqsf UFHlmdtpojM+XyiUnyvg2Nk/ohfrTO5/7ICiVN2PIijpK9vPjco7iR0imUt0YyPDPsXk QHkjBEa2Eo98TZV+Hduf4cj7gzyZSe4/vYv9bN7/1iFU5JzQaUMk2x9PLbib6DXvg1qA yHCw== 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=wXO35jSIBWuW6YLtVe+MSc1Mt6JuiiXvuRrvbKn9cAQ=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=cjSXOtJjil8rCb5NsXfXEm05U+TUFH/jFt/1mWFMEvUm223OpgkkOsWqHh4rjzVJrr n/YmODceKAHcUx+um35ZKkSQjglHXnVLxYsthM0jB/YlO9+1m2TAH6ZSnYhV8Oq9vL0a 2H4KyjLJEQEZJTZyXQq/qg82bCLfieZpoOF5jnWwt0CflNI8+Axi06c5Lf0czqquhpSm QtBaK82KUmaxe5YrIl7yQ9WU7Yt58dE0xB6f8Xei14l/5t2AWBC5dKPpd/vXardGsNCf a+ufcAwWgjWi/j1N7qgNF46J8LxzQtYR7MMGQ9OghJopigq9Ft+Xk8yRW6S+dDH6WoM/ 4fNg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=ldOa5EK0; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=WyNdTUT0; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=cBiF8p3D; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=1eTQr8b1; 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-1b3773f37c3si14807517c88.87.2026.11.09.07.09.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 07:09:34 -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=ldOa5EK0; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=WyNdTUT0; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=cBiF8p3D; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=1eTQr8b1; 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=wXO35jSIBWuW6YLtVe+MSc1Mt6JuiiXvuRrvbKn9cAQ=; b=ldOa5EK08iHnha p2WD8lew3bRYlH09W7wa0OICmhtZFoEcFDo2LHqSx+B5PKscOSUwHYRD1TVPLXaTyCrwh+++WiEeW hr0vrBRSPFwB6r/DTltKXEdO/ygwZkYWtojHxywU5UZNZePzKLPRbMgl9e4HwYHf624P6BM3464b/ S5M=; 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 1xQQzz-000000000Qj-386B; Mon, 09 Nov 2026 15:09:31 +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 1xQQzx-000000000Q7-2HBe for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:29 +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=+hy7QY9vUA0VkC1z6FxlLYPhg9/BzeLxcgBcB7cjAwg=; b=WyNdTUT0GcEsjfvdq7rUvIjAL4 kaDTI+p3qBWwXivqeTNv63Q4Q5LWJqgio1WIgaDishFsU3pR30l8T+OiZOSasytY26/TNil/JgxOR 5xGy0m4LL8d9+a94HrSZYk0dFXngsG0Us9LF0aTUdXWuJyEX4WMjRo8i8ea5NrRK7ZiM=; 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=+hy7QY9vUA0VkC1z6FxlLYPhg9/BzeLxcgBcB7cjAwg=; b=cBiF8p3DfIE/N/qjUJO8iWDxfS vmwIZtwD5OUrdhZjqA+n+Q+eXa2kGyH7zvenf8m/V8b6UH6czea843ox4AUVg6sDA/md33Ip6zguL gBKtL0CqmDLgDusZgWVaJntH1T47cK7AjTpeTHd9w4Buflmwf267BejqbUznVtFgJsN8=; Received: from mout-b-106.mailbox.org ([195.10.208.46]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xQQzv-000000001VH-3St7 for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 15:09:29 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (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-106.mailbox.org (Postfix) with ESMTPS id 4jNY8w0fW5zNldY for ; Mon, 09 Nov 2026 16:09:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794236960; 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=+hy7QY9vUA0VkC1z6FxlLYPhg9/BzeLxcgBcB7cjAwg=; b=1eTQr8b12FNcqftyECZ+fPiJ/zpqVL/jI1+u9JqiokXtJ61/bAFYLc5ZB3zWVjqLWmvIcS vUF7QfFNhjWALVVhtAemffUcjL3oR0/ZNjFO1CYHeK6F7513/0pyo9UbWBL7JSsD0d2FUl RszqA0EdVNgNhZGG8rdpsYE0eBxHYBPTYv4Lg18YHKi6FAjvtKxhPsW5Eb9+ZD4vC7/gS6 0kzsAMmxE0v/ygOL4zSSIL0IMe3oiMy+26Za2jw50PrC9bzGutB5YTRiQdYZM1uBtbI3TC Wj4qhzyXoJxN1FEHHRvNqTEFHrFspM3VY8+fBGMZTbW0grd08MFisZMLhfTRbA== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Nov 2026 16:09:06 +0100 Message-ID: <26e88846a6e2ebcd4a64c50d61edff9ccf6161ac.1794234673.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNY8w0fW5zNldY 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: Each encrypted GSO record currently builds its authenticated header in request-local scratch storage, copies it into the final UDP GSO aggregate and then maps that range again as destination AAD. Map the final output range first and, when it is represented by one base-page-contained scatterlist entry, construct the header directly there. Use the same entry as source and destination AAD since t [...] 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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1xQQzv-000000001VH-3St7 Subject: [Openvpn-devel] [PATCH ovpn net-next v4 8/9] ovpn: place GSO record AAD directly in output 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: 1881393829627671858 X-GMAIL-MSGID: 1881393829627671858 Each encrypted GSO record currently builds its authenticated header in request-local scratch storage, copies it into the final UDP GSO aggregate and then maps that range again as destination AAD. Map the final output range first and, when it is represented by one base-page-contained scatterlist entry, construct the header directly there. Use the same entry as source and destination AAD since the AEAD interface does not write destination AAD and permits the two entries to alias. Use an unaligned-safe opcode store because a record's offset in the aggregate need not be naturally aligned. Retain the scratch-and-copy path as a fallback when the output range cannot be mapped suitably. In a balanced three-round matrix, direct placement increased throughput by 2.1% and reduced cycles and instructions per byte by 1.3% and 1.0%. Signed-off-by: Ralf Lici --- No changes since v3 https://lore.kernel.org/openvpn-devel/62065a69f01a64708cc34e6eeff159bb4bbc5f48.1794223133.git.ralf@mandelbit.com/ Changes since v2 https://lore.kernel.org/openvpn-devel/20261102164353.459969-10-ralf@mandelbit.com/ - Use an unaligned-safe store when constructing AAD directly in the output aggregate. (Sashiko) - Refresh the measurements. New in v2. drivers/net/ovpn/crypto_aead.c | 64 ++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index a75a0bf65c89..763fd4f2cc25 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -8,7 +8,9 @@ */ #include +#include #include +#include #include #include #include @@ -169,10 +171,33 @@ static void ovpn_aead_encrypt_header(struct ovpn_peer *peer, /* add the packet opcode and wire nonce as associated data */ op = ovpn_opcode_compose(OVPN_DATA_V2, ks->key_id, peer->tx_id); BUILD_BUG_ON(sizeof(op) != OVPN_OPCODE_SIZE); - *(__force __be32 *)data = htonl(op); + put_unaligned_be32(op, data); memcpy(data + OVPN_OPCODE_SIZE, iv, OVPN_NONCE_WIRE_SIZE); } +static bool ovpn_aead_encrypt_header_direct(struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, + u32 pktid, u8 *iv, + struct scatterlist *sg) +{ + unsigned int offset, page_offset; + struct page *page; + void *addr; + + offset = sg->offset; + page_offset = offset_in_page(offset); + if (page_offset + OVPN_AAD_SIZE > PAGE_SIZE) + return false; + + /* an SG offset can address a later base page in a compound page */ + page = sg_page(sg) + (offset >> PAGE_SHIFT); + addr = kmap_local_page(page); + ovpn_aead_encrypt_header(peer, ks, pktid, iv, addr + page_offset); + kunmap_local(addr); + + return true; +} + int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb, struct sk_buff *gso_skb, unsigned int offset, @@ -184,6 +209,7 @@ int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, struct aead_request *req; unsigned int payload_off; int dst_idx, mapped, ret; + bool direct_aad; u8 *aad, *iv; req = ovpn_aead_request_alloc(ks->encrypt, skb, src_nents + dst_nents, @@ -194,26 +220,42 @@ int ovpn_aead_encrypt_gso(struct ovpn_peer *peer, dst = src + src_nents; aad = (u8 *)(dst + dst_nents); - ovpn_aead_encrypt_header(peer, ks, pktid, iv, aad); - - ret = skb_store_bits(gso_skb, offset, aad, OVPN_AAD_SIZE); - if (unlikely(ret < 0)) - return ret; - /* encrypt out of place from the original segmented skb directly into * its final range in the UDP GSO skb */ sg_init_table(src, src_nents); - sg_set_buf(src, aad, OVPN_AAD_SIZE); + /* use the final output bytes as source AAD too when they can be safely + * written through one base-page mapping + */ + mapped = skb_to_sgvec_nomark(gso_skb, src, offset, OVPN_AAD_SIZE); + if (unlikely(mapped < 0)) + return mapped; + direct_aad = mapped == 1 && + ovpn_aead_encrypt_header_direct(peer, ks, pktid, iv, src); + if (unlikely(!direct_aad)) { + ovpn_aead_encrypt_header(peer, ks, pktid, iv, aad); + ret = skb_store_bits(gso_skb, offset, aad, OVPN_AAD_SIZE); + if (unlikely(ret < 0)) + return ret; + sg_set_buf(src, aad, OVPN_AAD_SIZE); + } + mapped = skb_to_sgvec_nomark(skb, src + 1, 0, skb->len); if (unlikely(mapped < 0)) return mapped; sg_mark_end(&src[mapped]); sg_init_table(dst, dst_nents); - dst_idx = skb_to_sgvec_nomark(gso_skb, dst, offset, OVPN_AAD_SIZE); - if (unlikely(dst_idx < 0)) - return dst_idx; + if (likely(direct_aad)) { + /* destination AAD is not written and may alias source AAD */ + sg_set_page(dst, sg_page(src), src->length, src->offset); + dst_idx = 1; + } else { + dst_idx = skb_to_sgvec_nomark(gso_skb, dst, offset, + OVPN_AAD_SIZE); + if (unlikely(dst_idx < 0)) + return dst_idx; + } payload_off = offset + OVPN_AAD_SIZE + OVPN_AUTH_TAG_SIZE; mapped = skb_to_sgvec_nomark(gso_skb, dst + dst_idx, payload_off,