From patchwork Mon Nov 9 17:16:24 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5639 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:63cb:10b0:11a:a05e:cb97 with SMTP id w11-n1csp983513lat; Mon, 9 Nov 2026 09:18:36 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHm2T2Uu1Y34CrHnK1W/4Ze71kWyxEZCC01ua/oV6FrJ72TjJ2zGlZpgfX4a1qKXiTbuOZYuQd2rZo=@openvpn.net X-Received: by 2002:a05:6808:2386:b0:4b3:7efc:e970 with SMTP id 5614622812f47-5683c9dfdf3mr219575b6e.5.1794244613607; Mon, 09 Nov 2026 09:16:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794244613; cv=none; d=google.com; s=arc-20260327; b=fvj+wTjeNcelW+0ejy64aWXYSYWlGnnw6vp3f0dhSRTBY6o2T+CPwt4QBteu1S0M9l h+hmRatZkdgBwxI80uv4fOg76iuaGRbHaQdxdB7ZdXb6ZgHe2s37TqN5saLn1Dc9oKYM H4fXjETmUniUTJULMuMedIaGz6NJauSWuOePBfThRjDr8II8f7iKaTi9Pap0TZ3einmf 9r/emydlu4GWr0+ysapZAiFlWWEBkXISrNyOXwQXSsP8qcydmJ+wBfvSzrX0nmGMLR4h NxeOpYIS9f/SuXz8KinpsYZ4xt3zpqI/m5YoXwfTGJUClmMH2mM2Blv9ZeaGq10F3hxP sP1w== 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=C8ZTkCdKxhMg3QkWhSNVDrvU4NmJc30oL5Yz1eX+qLU=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=IVVWKZKRdnjlziJvCPg0aJLuGHIzBvpDfNuYRV9gSYBN0HUKiUxCO0EY3vNJ1UiwIx yo6V7634TL4vrF3lDOUzeLRKsaDghZhWiDPbhYhwvNbABgcC2SFLlmNLFXavLZc7WQz9 wn2i5tXrWavFw2e+QftMWunuWVUcDYWticDPk9IQOnSYQwbNqwkyqee4e6IfwqWzhVbw FTyb/SoNfmOq9bS5MT0mH1ZrWIxAZncnXATHx+02zKo4Pz8Su1r0d+tZZTBLzxd2c4b1 wf/VLwS+7BcBDKKpTA1oBnJXdsFa19dmwrCfDMyP3zcqCDLQfv9Os6LISk2zIu6W16r4 d+3Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=UE2tVeop; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=PT1G7RzW; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=aSRz7s3l; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=qUDlqA1Z; 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-56813b97ef7si5212129b6e.78.2026.11.09.09.16.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2026 09:16:53 -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=UE2tVeop; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=PT1G7RzW; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=aSRz7s3l; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=qUDlqA1Z; 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=C8ZTkCdKxhMg3QkWhSNVDrvU4NmJc30oL5Yz1eX+qLU=; b=UE2tVeop3mMBTO w1s26PeJQTZF7wxyW/CYNcERnZp+SQa0tchOI2W2sTTFoLGBx/dF95IOF0uJcPANAGha5NQOACBZz iGIFFUeS3w/yuwQcstPaFPnG1bHshmcKrFVa4WCpuCQ8KjjBkrPAGeIwCf2Am5TDUySk3K0v5yyTa hSI=; 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 1xQSzE-000000005T2-0BbC; Mon, 09 Nov 2026 17:16:52 +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 1xQSzB-000000005Si-2zdX for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:49 +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=ddgVDKqdiAxFMEY2+uct1UMmmeth1+b6Yi9Xo1BcFUc=; b=PT1G7RzWqo7UUwJuk2L+/2Z2/2 FB0jJqppzthe8UyrqsnL5I/k1QAknm60ycgISYWgCWRxzppDY0gBZ4xup7jZAaj0XWBsajdlNJp3g 2iCtnLRcpN4a4ARRSe2/CW6QZS2AtXX5+kw+KqFO7SR4veCtH85wUIvLua/SmOUEWZBA=; 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=ddgVDKqdiAxFMEY2+uct1UMmmeth1+b6Yi9Xo1BcFUc=; b=aSRz7s3l5UhEC1rYSYzByhLgm1 /1IHiY8SqSd4GUl++ADRfL4Nbm94Nrb3UcB9Iln6DdonQjkFS6LgPiPp+/xRTupOjYh0esDl23ovS wTd3abq3pdDKSaXE7CbNXCnjkgbp6UkA55N3Gr64+zS6JywwpTecnDi1QMZOseGqo+LI=; 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.100.1) id 1xQSz8-000000003aZ-3HAa for openvpn-devel@lists.sourceforge.net; Mon, 09 Nov 2026 17:16:49 +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-210.mailbox.org (Postfix) with ESMTPS id 4jNbzq0wV5zFqX2 for ; Mon, 09 Nov 2026 18:16:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794244599; 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=ddgVDKqdiAxFMEY2+uct1UMmmeth1+b6Yi9Xo1BcFUc=; b=qUDlqA1ZZwwnB7twU+T5XDdwS1BmywCq/Qv5OYRO/xncpDNCML4B/OFsrPP6CzGtKCNCYM idVRXtDroOyvhvqh8lCjkHMbBDJyUgpxUWaLpuyVoepZ0Eec4xNFCX1AICeCzQWZg1+svv JcVopBRvzRVTuQSJdo+3HAeujtTZp/Nuer+ZfZ/I3dhqj35KETC1NFKOQZmZifaGVSctK1 p+i+FM0qhHmf5ZFb7oyznZtHWUl6OZw7og78/luIr/D100I/t8tvmQbtrvRhYd615JNMKf HYwRDy52ZXSkaiBCRTOSOZ58Wydv1hnHOm28n+dUoTW7yNlGT/aHBf/q9mwLNg== 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 18:16:24 +0100 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jNbzq0wV5zFqX2 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: 1xQSz8-000000003aZ-3HAa Subject: [Openvpn-devel] [PATCH ovpn net-next v5 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: 1881401839742773213 X-GMAIL-MSGID: 1881401839742773213 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 v4 https://lore.kernel.org/openvpn-devel/26e88846a6e2ebcd4a64c50d61edff9ccf6161ac.1794234673.git.ralf@mandelbit.com/ 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,