From patchwork Fri Nov 13 15:51: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: 5685 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:18c:b0:11a:a05e:cb97 with SMTP id 12csp372167lag; Fri, 13 Nov 2026 07:52:11 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErEMpxE1c/8ynOpMug1pcZ31PBP7pJE00GkA16IcebOwrA79DObsPUuWqJ+UjeuUd7Ei4O4dE7UXal0=@openvpn.net X-Received: by 2002:a05:693c:414c:10b0:369:9062:c392 with SMTP id 5a478bee46e88-379680cf511mr2861137eec.37.1794585130680; 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=VyvxrhNnZ5loWke/EcHEtk1P0sx38KCWudtmf73MsV5pne3aQaVD56uzVbrpO7EmTv Xlh8sem19pEtu2We1RVjB4CUOYUnKUH/OVknvhPu9pmk4ZbJPRe1tMoIiW6WLisbAalD NirX4WjO2YE47lA6/v/hzpU76hNvy15sLtw+PG4VKdn2QWpFCRvawYx+q9NcEdjwxigz F59pV9Hknl/rnO7HnD6LNWFxXkPwLz0RmzuXPQKL2R751VXADZ1Ut1yhz76gSzKIMhAN RmjtXE2pQ+G4jUdIyN7Gx4vfFglBrHKEVPhmGb0kxSJqAjZym9p1LlUlrkIFQprK07Ch 6qPw== 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=JgZErJnpRdqIlrcUOLBSyAe0Tqhwpk7LcLRP0o117L8=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=oSxSN0b2aHey0aR0sSojRwPlKgQuwDc0k/HVZNF90hh5MEb0vZqAVIuP3kNxY03iCP 5BhF/sM80JpmG50FMCTUPG97VqRxzhxc6PHFTeQmxC5doqxKLy+J5SBihLuTlSGrF+ep GqkSxADaRYR2oynO1vzW+dt6D67s6Cq6A9p/3IHPs8yhTMKdn+vOmDhsDa4x1EW6L9qq +t4E7X4LmR+6cyW8mPjmRDKbWkzmBqnUnTAt4qHj1g0ECd4t9jozAVFC5G69kU3CjOUd tlMUZ1d6wjPnwT+afmfkAyNh0otgbEAdhRcCW6CwZO+kJiBK6tU8mIsEQWlqlrYdMoq6 cZhA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=MXc2G4Q7; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=abMnQwHM; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=b7EdUswT; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=ZeqjcpCE; 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-3795a0973basi7935950eec.36.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=MXc2G4Q7; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=abMnQwHM; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=b7EdUswT; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=ZeqjcpCE; 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=JgZErJnpRdqIlrcUOLBSyAe0Tqhwpk7LcLRP0o117L8=; b=MXc2G4Q7MG5o87 YMLkMkDZEzFi/nTJQ4TBgAEwlNTq5fJJTcbSP83VjzXhjClT4FqsshwrgufhCAVewflPsHyqEqArS TrBNmHQXJNwSXe1nPHekl9jepaMoRoiHYTReYYHG53G0T6qxEaBx1IqGbvLh8rsLixh34MYYKM1kD 6kc=; 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-000000001cn-2CdN; 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-000000001bt-1LEd 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=PnishJYZCdOosstd08Ph7cb7j/Qs7x0wTJFNKRd92y0=; b=abMnQwHMwHznijIAaf7dB19ssR VTYtVi0vSpfaSWsY5volT98JUTpMhwvcMsTieHX9+5lFPe5PJCjBDWDXte2eqfvk0V1lZRnp/uCBa 5EOkXp2wFOA4vvMfEwxqcv5BR+9r8XnfI7ImaEnNtvk+WkoWCQ6GN6VQYnH48m2TLSNI=; 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=PnishJYZCdOosstd08Ph7cb7j/Qs7x0wTJFNKRd92y0=; b=b7EdUswT9UwMw9/ZaGW9LuvHzD tILQr5Xzp4POAARexoLd01YoUyLFTM074qXw1SWrqBOQFhAidH5u/Y2LX2+dop0/KhTxdkFQmqbOQ ndQVAy2Pyd7SDeuPJhKjmE9qqPR/wzWBk2wc+hnBOT3Bvjo0f2G2QUlE21j+VgsWrK4g=; Received: from mout-b-107.mailbox.org ([195.10.208.47]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xRtYp-0000000082e-0YDt for openvpn-devel@lists.sourceforge.net; Fri, 13 Nov 2026 15:51:35 +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-107.mailbox.org (Postfix) with ESMTPS id 4jR1vZ5Fh6z3xwJ for ; Fri, 13 Nov 2026 16:51:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794585082; 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=PnishJYZCdOosstd08Ph7cb7j/Qs7x0wTJFNKRd92y0=; b=ZeqjcpCEUaSHs8fOcVMzuZ6KCgJGmQb/0qvZ/dzo4/eobotu5ksaPF1AgaCCVhJQ2bBx2p FWwUM3kWgdzqvzQbKyuXEMzUX17GeMulshjev9mpNhMUGecQd1ZfxhdydRs2XBDwO0E5TF eLWzKTD/nRsfDuql7boz4OsQFlarMSXFdu+Gnc/50ot/4PtU4Bliodo/SfcKiasd1bkTTf /zolt+HecoR7saOTDlvFSx++ouL7ff2w85L/UsvlMV2cp4EI5mBUAreAoi7sOS3oop7ku7 GJCKRcVovVRuPT8SUOtCvzn3NOFrQ8lxyViwWg0uKxogkt/mzhe01L6m7YK71A== 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:06 +0100 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jR1vZ5Fh6z3xwJ 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: tso_build_data advances both the TCP sequence number used by the next tso_build_hdr call and a cursor over the payload's virtual addresses. Callers which walk the payload in some other way, such as bn [...] 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-0000000082e-0YDt Subject: [Openvpn-devel] [PATCH ovpn net-next 1/5] net: tso: advance header state independently of the data cursor 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: 1881758898125061543 X-GMAIL-MSGID: 1881758898125061543 tso_build_data advances both the TCP sequence number used by the next tso_build_hdr call and a cursor over the payload's virtual addresses. Callers which walk the payload in some other way, such as bnxt_sw_udp_gso_xmit through tso_dma_map, can skip tso_build_data only because UDP headers carry no sequence number, so a TCP user of the same pattern has no way to advance the header state. Add tso_advance_hdr for that and use it in tso_build_data. Signed-off-by: Ralf Lici --- include/net/tso.h | 15 +++++++++++++++ net/core/tso.c | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/net/tso.h b/include/net/tso.h index da82aabd1d48..0a8020274882 100644 --- a/include/net/tso.h +++ b/include/net/tso.h @@ -18,6 +18,21 @@ struct tso_t { u32 tcp_seq; }; +/** + * tso_advance_hdr - advance the header state past a segment's payload + * @tso: TSO state initialized by tso_start + * @size: payload length of the segment just built + * + * tso_build_data does this while also moving its cursor over the payload's + * virtual addresses. Callers which walk the payload in some other way, for + * example through tso_dma_map, use this to keep the TCP sequence number of + * the following headers correct. + */ +static inline void tso_advance_hdr(struct tso_t *tso, int size) +{ + tso->tcp_seq += size; /* not worth avoiding this operation for UDP */ +} + /* Calculate the worst case buffer count */ static inline int tso_count_descs(const struct sk_buff *skb) { diff --git a/net/core/tso.c b/net/core/tso.c index d2934bcfa795..c091bee795a7 100644 --- a/net/core/tso.c +++ b/net/core/tso.c @@ -47,7 +47,7 @@ EXPORT_SYMBOL(tso_build_hdr); void tso_build_data(const struct sk_buff *skb, struct tso_t *tso, int size) { - tso->tcp_seq += size; /* not worth avoiding this operation for UDP */ + tso_advance_hdr(tso, size); tso->size -= size; tso->data += size; From patchwork Fri Nov 13 15:51:07 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5688 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:18c:b0:11a:a05e:cb97 with SMTP id 12csp372171lag; Fri, 13 Nov 2026 07:52:11 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErEp6uqJt5zNwXwx9OqBogdSRETD80oaiRJE5XwZDFbP8mjodilDmrF8nD9KFiPxYIsXUy1eRfDUlwU=@openvpn.net X-Received: by 2002:a05:701b:4508:10b0:143:5cb4:30 with SMTP id a92af1059eb24-1b50302e917mr2686354c88.3.1794585130692; 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=Z7HmCd9319XHkI6atonBiNXa8EcLG9gJ0cC+tlUWVqFzOgEtM+zZFWO7I3Rbsxxj0H KdbEaoxE/TEUZIiyDK/HUqs7693L+qi6AhK4lRlh5LGudonlLfxhbh3zYc4xLbj3Pyn/ N1MLDwaHjuxPz0eHZTWUfMArsdU8FThQc3py9iKgzuzVpZEo/mfTC+4Bmglyj4fLFwJm C/lkler0M7bD/kEewqh8woWNajWiyXHXdZZ3MXnEbfVv7rSa+lldZzfPq7wxu4uPlOxT EjJ8AdqMOTN5WfLY83Ly2xs0egzt9lFpDXYmST7MQHjFR+6q08oQpUYk48xyeSDDmoR6 l7Og== 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=me9GZVrHvdS0MQWNH+IRecaWU2UJAfAsuwPmcwtEHhI=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=RhvuLoO47KT0LYsNN1cj7z7IXnxrC/JdOWrMSwyR9RuNcVetyX65tRw1POwElolm39 /tfWKczzWsZrQYBdF6ohrCKz3kTpizj8cCHIH4mSjcZKPVKkCnHYcX2OCrmVmT5PPYSx 84bj6w5yaY0AMrmEG8cXSn1BEv6uM74XxeYLoBEZdb2DZTjDUvyCRndnQ5usOKGFNrKn Hrslzbxq9DoKhDI3/4yDWN7j1wqJgzDVHDorsheiZMfgozlSVCiaaNjgS/6dr1FtmNv6 5oey0s/3SHKBE04IDxdw6RjBido+QvAFtiNCZxa9MQadd4xTT/5Pn9ydqnUE3NMOmMTI l6HA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=RGNm6d11; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Tj2wCWkU; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=B5xV5dcz; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b="xRaYCeU/"; 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-1b5031fdc39si8481318c88.31.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=RGNm6d11; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Tj2wCWkU; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=B5xV5dcz; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b="xRaYCeU/"; 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=me9GZVrHvdS0MQWNH+IRecaWU2UJAfAsuwPmcwtEHhI=; b=RGNm6d11UDmucU VgD5NUjrBGaatLnFdtr9Bgd//+tyF3n8xxPulvb1UxEMJiaRdO5b6MYi0buC3Oj8CDPnpP2PB3HOv zcVlI5Qna53MoYKCEuj0XMjLIDAX6xx7k/uHcYYhnx0eX1x1W5XE5Lw4V+p9JstENRvP4g4glef1A 4CI=; 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 1xRtZO-000000004Uy-04k3; Fri, 13 Nov 2026 15:52:06 +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 1xRtYt-000000004T3-48Gx for openvpn-devel@lists.sourceforge.net; Fri, 13 Nov 2026 15:51:35 +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=mVcgOc/6jqabEurARzwcWmJoCTjK8Upr10NfmsTxMRM=; b=Tj2wCWkUOq34yn+f/PEiWSA+Rv 2X9UurMQtKQie990UVT5d0U9D32VOHsb9HYlUPWdaJprFpWH28wAFdYKHpasbeuurDg8ur7eWcwzd 64ZzvXFg9upvxDeHNtcHlY10+wmp6C9aucRegpLjg4M1qBJ53HU1iPAMxp3k4HjcKfxA=; 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=mVcgOc/6jqabEurARzwcWmJoCTjK8Upr10NfmsTxMRM=; b=B5xV5dczWZH+lvS4Nk3peVxmDd D4L9FwamW/9we3bAkdht8ey7FnXDzg5DV017cip2a/Uumpy/tqyBT0SOqoOY9j/5v6Jp68b0MCVyA mnyDNS81QpFru1ugNbR43fOlsuS4fh7cxZZggLTAVTv1+VMxeKpBrq3JM+4med0dGHt8=; Received: from mout-b-201.mailbox.org ([195.10.208.61]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xRtYp-0000000082f-01CM for openvpn-devel@lists.sourceforge.net; Fri, 13 Nov 2026 15:51:35 +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-201.mailbox.org (Postfix) with ESMTPS id 4jR1vb0qfRzLm4P 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=mVcgOc/6jqabEurARzwcWmJoCTjK8Upr10NfmsTxMRM=; b=xRaYCeU/TCnILYa1PXGFZdZnJjnzOfnvG9P1Q/LlWNyZUEcNLSsSrRpRd+buoMPv5BK6Uk JwmlpArteR9wtqwQnB9QmDtAEvRipfxXhj9T0sTML6WCpSHEM0YOLZbZMb61TiSg5P1e3Q 0xOsg1FdUQ6Q+fDPuFnv7r1C0v7xoCppP1459QbQoJstzsF3kDBQT/UNtZI7ZFvZREwBvt vpEADBF+26CEjRl7h+uaArhQJYp3V5MlMIE6Jbx4xJNWnndvNCu0Vuy5zc4u3w71N4yUh3 YuJelHO1e7R12F3wYyyoT0/Muz9GTo/ESJjKoGF8QPwoteazJhCxRK+hi665lA== 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:07 +0100 Message-ID: <495e358cb20aa2fac12d9e28e96a57bd814fa464.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: 4jR1vb0qfRzLm4P 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 transmit path makes up almost half of io.c and is about to grow further. Move it to its own file, giving its functions an ovpn_gso_ prefix, and expose the helpers it shares with the ordina [...] 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-0000000082f-01CM Subject: [Openvpn-devel] [PATCH ovpn net-next 2/5] ovpn: move UDP GSO transmit batching to gso.c 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: 1881758897889469035 X-GMAIL-MSGID: 1881758897889469035 The UDP GSO transmit path makes up almost half of io.c and is about to grow further. Move it to its own file, giving its functions an ovpn_gso_ prefix, and expose the helpers it shares with the ordinary transmit path through io.h. The receive side stays in udp.c, as UDP GRO is set up through the socket's encapsulation callbacks. No functional change. Signed-off-by: Ralf Lici --- drivers/net/ovpn/Makefile | 1 + drivers/net/ovpn/gso.c | 262 ++++++++++++++++++++++++++++++++++++++ drivers/net/ovpn/gso.h | 20 +++ drivers/net/ovpn/io.c | 238 ++-------------------------------- drivers/net/ovpn/io.h | 6 + 5 files changed, 298 insertions(+), 229 deletions(-) create mode 100644 drivers/net/ovpn/gso.c create mode 100644 drivers/net/ovpn/gso.h diff --git a/drivers/net/ovpn/Makefile b/drivers/net/ovpn/Makefile index 229be66167e1..9f993a532d84 100644 --- a/drivers/net/ovpn/Makefile +++ b/drivers/net/ovpn/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_OVPN) := ovpn.o ovpn-y += bind.o ovpn-y += crypto.o ovpn-y += crypto_aead.o +ovpn-y += gso.o ovpn-y += main.o ovpn-y += io.o ovpn-y += netlink.o diff --git a/drivers/net/ovpn/gso.c b/drivers/net/ovpn/gso.c new file mode 100644 index 000000000000..e72f835e2a60 --- /dev/null +++ b/drivers/net/ovpn/gso.c @@ -0,0 +1,262 @@ +// SPDX-License-Identifier: GPL-2.0 +/* OpenVPN data channel offload + * + * Copyright (C) 2026 OpenVPN, Inc. + * + * Author: Antonio Quartulli + * Ralf Lici + */ + +#include +#include +#include +#include + +#include "ovpnpriv.h" +#include "peer.h" +#include "io.h" +#include "gso.h" +#include "crypto.h" +#include "crypto_aead.h" +#include "pktid.h" +#include "proto.h" +#include "skb.h" +#include "socket.h" +#include "stats.h" + +/* gso_within_dev_limits() requires skb->len, which by then includes the + * link-layer and outer network headers, to stay below gso_max_size + */ +#define OVPN_GSO_MAX_PAYLOAD (GSO_LEGACY_MAX_SIZE - \ + LL_MAX_HEADER - \ + sizeof(struct ipv6hdr) - \ + sizeof(struct udphdr) - 1) + +static bool ovpn_gso_encrypt_queue(struct sk_buff_head *skbs, + struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, + struct sk_buff *batch, + unsigned int segments) +{ + unsigned int offset = 0, moved = 0, i, len; + struct ovpn_aead_gso_ctx ctx = { }; + struct sk_buff *skb; + u32 first_pktid; + int ret; + + if (unlikely(ovpn_aead_gso_ctx_init(&ctx, ks, batch))) + goto err; + + /* reserve the complete range before dequeuing any input skb so that a + * failure leaves the ordinary transmit path available as a fallback + */ + if (unlikely(ovpn_pktid_xmit_range(&ks->pid_xmit, segments, + &first_pktid))) { + ovpn_encrypt_key_exhausted(peer, ks); + goto err; + } + + for (i = 0; i < segments; i++) { + skb = __skb_dequeue(skbs); + len = skb->len + OVPN_DATA_V2_OVERHEAD; + + ret = ovpn_aead_encrypt_gso(&ctx, peer, ks, skb, batch, offset, + first_pktid + i); + if (unlikely(ret < 0)) { + DEBUG_NET_WARN_ON_ONCE(ret == -EINPROGRESS || + ret == -EBUSY); + ovpn_dev_dstats_tx_dropped(peer->ovpn->dev, i + 1); + kfree_skb(skb); + break; + } + + /* pass on the TX timestamp request, which GSO segmentation + * attached to the segment holding the timestamped byte + */ + if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_ANY_TSTAMP)) { + skb_shinfo(batch)->tx_flags |= + skb_shinfo(skb)->tx_flags & SKBTX_ANY_TSTAMP; + skb_shinfo(batch)->tskey = skb_shinfo(skb)->tskey; + } + + /* the encrypted data now lives in the aggregate, which already + * carries the write charge, so free the segment without its + * destructor, which for TCP would wake TSQ before the batch has + * left the host + */ + if (batch->sk) { + moved += skb->truesize; + skb->destructor = NULL; + skb->sk = NULL; + } + consume_skb(skb); + offset += len; + } + + /* the aggregate's own charge keeps sk_wmem_alloc above zero */ + if (moved) + WARN_ON_ONCE(refcount_sub_and_test(moved, + &batch->sk->sk_wmem_alloc)); + if (unlikely(i < segments)) + goto err; + + ovpn_aead_gso_ctx_free(&ctx); + ovpn_encrypt_send(peer, ks, batch, segments); + return true; +err: + ovpn_aead_gso_ctx_free(&ctx); + ovpn_crypto_key_slot_put(ks); + ovpn_peer_put(peer); + return false; +} + +static struct sk_buff *ovpn_gso_alloc(const struct sk_buff *first_segment, + unsigned int batch_len, + unsigned int segments) +{ + struct sk_buff *gso_skb; + int ret; + + gso_skb = alloc_skb_with_frags(OVPN_HEAD_ROOM, batch_len, + SKB_FRAG_PAGE_ORDER, &ret, GFP_ATOMIC); + if (unlikely(!gso_skb)) + return NULL; + + skb_reserve(gso_skb, OVPN_HEAD_ROOM); + skb_reset_inner_network_header(gso_skb); + gso_skb->len = batch_len; + gso_skb->data_len = batch_len; + + /* take over the input's write ownership with its own destructor, as + * GSO segmentation does, so that freeing the aggregate releases the + * charge and, for TCP, runs tcp_wfree to wake TSQ once the batch has + * left the host + */ + if (first_segment->sk && is_skb_wmem(first_segment)) { + gso_skb->sk = first_segment->sk; + gso_skb->destructor = first_segment->destructor; + refcount_add(gso_skb->truesize, + &gso_skb->sk->sk_wmem_alloc); + } + + /* keep the metadata retained by the in-place path, which reuses the + * input skb + */ + gso_skb->priority = first_segment->priority; + skb_set_delivery_time(gso_skb, first_segment->tstamp, + first_segment->tstamp_type); + gso_skb->ooo_okay = first_segment->ooo_okay; + skb_set_dst_pending_confirm(gso_skb, + skb_get_dst_pending_confirm(first_segment)); + skb_copy_hash(gso_skb, first_segment); + skb_copy_secmark(gso_skb, first_segment); +#ifdef CONFIG_XPS + gso_skb->sender_cpu = first_segment->sender_cpu; +#endif + + skb_shinfo(gso_skb)->gso_type = SKB_GSO_UDP_L4; + skb_shinfo(gso_skb)->gso_size = first_segment->len + + OVPN_DATA_V2_OVERHEAD; + skb_shinfo(gso_skb)->gso_segs = segments; + + return gso_skb; +} + +/** + * ovpn_gso_send - encrypt materialized segments into UDP GSO aggregates + * @skbs: segments of one GSO skb, all but the last of the same length + * @peer: peer to send them to + * + * Consumes as many segments as fit into valid aggregates, each sent with its + * own references to @peer and its key. Segments left in @skbs, if any, are + * for the ordinary transmit path. Only for peers which pass + * ovpn_gso_supported. + */ +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; + + 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_supported - check whether a peer can send UDP GSO aggregates + * @peer: peer to check + * + * Return: true if the primary key of @peer is synchronous and its socket is a + * UDP socket which sends checksums + */ +bool ovpn_gso_supported(struct ovpn_peer *peer) +{ + struct ovpn_crypto_key_slot *ks; + struct ovpn_socket *sock; + bool udp_gso; + u8 idx; + + rcu_read_lock(); + idx = READ_ONCE(peer->crypto.primary_idx); + ks = rcu_dereference(peer->crypto.slots[idx]); + sock = rcu_dereference(peer->sock); + /* UDP GSO requires checksums. These socket settings can change after + * we decide to batch, but an already-built batch remains checksummed. + * Linux's ordinary UDP GSO path makes the same choice. + */ + udp_gso = ks && !ks->async && sock && + sock->sk->sk_protocol == IPPROTO_UDP && + !sock->sk->sk_no_check_tx && !udp_get_no_check6_tx(sock->sk); + rcu_read_unlock(); + + return udp_gso; +} diff --git a/drivers/net/ovpn/gso.h b/drivers/net/ovpn/gso.h new file mode 100644 index 000000000000..cc7b6b8ce314 --- /dev/null +++ b/drivers/net/ovpn/gso.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* OpenVPN data channel offload + * + * Copyright (C) 2026 OpenVPN, Inc. + * + * Author: Antonio Quartulli + * Ralf Lici + */ + +#ifndef _NET_OVPN_GSO_H_ +#define _NET_OVPN_GSO_H_ + +#include + +#include "peer.h" + +void ovpn_gso_send(struct sk_buff_head *skbs, struct ovpn_peer *peer); +bool ovpn_gso_supported(struct ovpn_peer *peer); + +#endif /* _NET_OVPN_GSO_H_ */ diff --git a/drivers/net/ovpn/io.c b/drivers/net/ovpn/io.c index cfdaad214bc1..358b2b9ebf36 100644 --- a/drivers/net/ovpn/io.c +++ b/drivers/net/ovpn/io.c @@ -19,6 +19,7 @@ #include "ovpnpriv.h" #include "peer.h" #include "io.h" +#include "gso.h" #include "bind.h" #include "crypto.h" #include "crypto_aead.h" @@ -34,14 +35,6 @@ const unsigned char ovpn_keepalive_message[OVPN_KEEPALIVE_SIZE] = { 0x07, 0xed, 0x2d, 0x0a, 0x98, 0x1f, 0xc7, 0x48 }; -/* gso_within_dev_limits() requires skb->len, which by then includes the - * link-layer and outer network headers, to stay below gso_max_size - */ -#define OVPN_UDP_GSO_MAX_PAYLOAD (GSO_LEGACY_MAX_SIZE - \ - LL_MAX_HEADER - \ - sizeof(struct ipv6hdr) - \ - sizeof(struct udphdr) - 1) - /** * ovpn_is_keepalive - check if skb contains a keepalive message * @skb: packet to check @@ -244,8 +237,8 @@ void ovpn_recv(struct ovpn_peer *peer, struct sk_buff *skb) ovpn_decrypt_post(skb, ovpn_aead_decrypt(peer, ks, skb)); } -static void ovpn_encrypt_key_exhausted(struct ovpn_peer *peer, - struct ovpn_crypto_key_slot *ks) +void ovpn_encrypt_key_exhausted(struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks) { netdev_warn(peer->ovpn->dev, "killing key %u for peer %u\n", ks->key_id, peer->id); @@ -254,9 +247,9 @@ static void ovpn_encrypt_key_exhausted(struct ovpn_peer *peer, ovpn_nl_key_swap_notify(peer, ks->key_id); } -static void ovpn_encrypt_send(struct ovpn_peer *peer, - struct ovpn_crypto_key_slot *ks, - struct sk_buff *skb, unsigned int packets) +void ovpn_encrypt_send(struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, + struct sk_buff *skb, unsigned int packets) { struct ovpn_socket *sock; unsigned int orig_len; @@ -334,7 +327,7 @@ void ovpn_encrypt_post(void *data, int ret) * The returned key and the peer each carry one reference which the caller must * release or pass to the completion path. */ -static struct ovpn_crypto_key_slot * +struct ovpn_crypto_key_slot * ovpn_encrypt_refs_get(struct ovpn_peer *peer) { struct ovpn_crypto_key_slot *ks; @@ -369,136 +362,6 @@ static bool ovpn_encrypt_one(struct ovpn_peer *peer, struct sk_buff *skb) return true; } -static bool ovpn_encrypt_gso_queue(struct sk_buff_head *skbs, - struct ovpn_peer *peer, - struct ovpn_crypto_key_slot *ks, - struct sk_buff *batch, - unsigned int segments) -{ - unsigned int offset = 0, moved = 0, i, len; - struct ovpn_aead_gso_ctx ctx = { }; - struct sk_buff *skb; - u32 first_pktid; - int ret; - - if (unlikely(ovpn_aead_gso_ctx_init(&ctx, ks, batch))) - goto err; - - /* reserve the complete range before dequeuing any input skb so that a - * failure leaves the ordinary transmit path available as a fallback - */ - if (unlikely(ovpn_pktid_xmit_range(&ks->pid_xmit, segments, - &first_pktid))) { - ovpn_encrypt_key_exhausted(peer, ks); - goto err; - } - - for (i = 0; i < segments; i++) { - skb = __skb_dequeue(skbs); - len = skb->len + OVPN_DATA_V2_OVERHEAD; - - ret = ovpn_aead_encrypt_gso(&ctx, peer, ks, skb, batch, offset, - first_pktid + i); - if (unlikely(ret < 0)) { - DEBUG_NET_WARN_ON_ONCE(ret == -EINPROGRESS || - ret == -EBUSY); - ovpn_dev_dstats_tx_dropped(peer->ovpn->dev, i + 1); - kfree_skb(skb); - break; - } - - /* pass on the TX timestamp request, which GSO segmentation - * attached to the segment holding the timestamped byte - */ - if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_ANY_TSTAMP)) { - skb_shinfo(batch)->tx_flags |= - skb_shinfo(skb)->tx_flags & SKBTX_ANY_TSTAMP; - skb_shinfo(batch)->tskey = skb_shinfo(skb)->tskey; - } - - /* the encrypted data now lives in the aggregate, which already - * carries the write charge, so free the segment without its - * destructor, which for TCP would wake TSQ before the batch has - * left the host - */ - if (batch->sk) { - moved += skb->truesize; - skb->destructor = NULL; - skb->sk = NULL; - } - consume_skb(skb); - offset += len; - } - - /* the aggregate's own charge keeps sk_wmem_alloc above zero */ - if (moved) - WARN_ON_ONCE(refcount_sub_and_test(moved, - &batch->sk->sk_wmem_alloc)); - if (unlikely(i < segments)) - goto err; - - ovpn_aead_gso_ctx_free(&ctx); - ovpn_encrypt_send(peer, ks, batch, segments); - return true; -err: - ovpn_aead_gso_ctx_free(&ctx); - ovpn_crypto_key_slot_put(ks); - ovpn_peer_put(peer); - return false; -} - -static struct sk_buff *ovpn_udp_gso_alloc(const struct sk_buff *first_segment, - unsigned int batch_len, - unsigned int segments) -{ - struct sk_buff *gso_skb; - int ret; - - gso_skb = alloc_skb_with_frags(OVPN_HEAD_ROOM, batch_len, - SKB_FRAG_PAGE_ORDER, &ret, GFP_ATOMIC); - if (unlikely(!gso_skb)) - return NULL; - - skb_reserve(gso_skb, OVPN_HEAD_ROOM); - skb_reset_inner_network_header(gso_skb); - gso_skb->len = batch_len; - gso_skb->data_len = batch_len; - - /* take over the input's write ownership with its own destructor, as - * GSO segmentation does, so that freeing the aggregate releases the - * charge and, for TCP, runs tcp_wfree to wake TSQ once the batch has - * left the host - */ - if (first_segment->sk && is_skb_wmem(first_segment)) { - gso_skb->sk = first_segment->sk; - gso_skb->destructor = first_segment->destructor; - refcount_add(gso_skb->truesize, - &gso_skb->sk->sk_wmem_alloc); - } - - /* keep the metadata retained by the in-place path, which reuses the - * input skb - */ - gso_skb->priority = first_segment->priority; - skb_set_delivery_time(gso_skb, first_segment->tstamp, - first_segment->tstamp_type); - gso_skb->ooo_okay = first_segment->ooo_okay; - skb_set_dst_pending_confirm(gso_skb, - skb_get_dst_pending_confirm(first_segment)); - skb_copy_hash(gso_skb, first_segment); - skb_copy_secmark(gso_skb, first_segment); -#ifdef CONFIG_XPS - gso_skb->sender_cpu = first_segment->sender_cpu; -#endif - - skb_shinfo(gso_skb)->gso_type = SKB_GSO_UDP_L4; - skb_shinfo(gso_skb)->gso_size = first_segment->len + - OVPN_DATA_V2_OVERHEAD; - skb_shinfo(gso_skb)->gso_segs = segments; - - return gso_skb; -} - /* send skb to connected peer, if any */ static void ovpn_send(struct ovpn_priv *ovpn, struct sk_buff *skb, struct ovpn_peer *peer) @@ -518,89 +381,6 @@ static void ovpn_send(struct ovpn_priv *ovpn, struct sk_buff *skb, ovpn_peer_put(peer); } -/* encrypt fixed-size input segments into one or more UDP GSO aggregates */ -static void ovpn_send_gso(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; - - seg_len = skb_peek(skbs)->len + OVPN_DATA_V2_OVERHEAD; - max_segs = min_t(unsigned int, UDP_MAX_SEGMENTS, - OVPN_UDP_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_udp_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_encrypt_gso_queue(skbs, peer, ks, - batch, segs))) { - kfree_skb(batch); - return; - } - } -} - -static bool ovpn_peer_supports_udp_gso(struct ovpn_peer *peer) -{ - struct ovpn_crypto_key_slot *ks; - struct ovpn_socket *sock; - bool udp_gso; - u8 idx; - - rcu_read_lock(); - idx = READ_ONCE(peer->crypto.primary_idx); - ks = rcu_dereference(peer->crypto.slots[idx]); - sock = rcu_dereference(peer->sock); - /* UDP GSO requires checksums. These socket settings can change after - * we decide to batch, but an already-built batch remains checksummed. - * Linux's ordinary UDP GSO path makes the same choice. - */ - udp_gso = ks && !ks->async && sock && - sock->sk->sk_protocol == IPPROTO_UDP && - !sock->sk->sk_no_check_tx && !udp_get_no_check6_tx(sock->sk); - rcu_read_unlock(); - - return udp_gso; -} - /* Send user data to the network */ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) @@ -722,8 +502,8 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) skb_queue_len(&skb_list)); if (gso_out && skb_queue_len(&skb_list) > 1 && - ovpn_peer_supports_udp_gso(peer)) - ovpn_send_gso(&skb_list, peer); + ovpn_gso_supported(peer)) + ovpn_gso_send(&skb_list, peer); skb_list.prev->next = NULL; ovpn_send(ovpn, skb_list.next, peer); diff --git a/drivers/net/ovpn/io.h b/drivers/net/ovpn/io.h index 1a94f0fda1d1..87a2b5a9e176 100644 --- a/drivers/net/ovpn/io.h +++ b/drivers/net/ovpn/io.h @@ -30,4 +30,10 @@ void ovpn_xmit_special(struct ovpn_peer *peer, const void *data, void ovpn_encrypt_post(void *data, int ret); void ovpn_decrypt_post(void *data, int ret); +struct ovpn_crypto_key_slot *ovpn_encrypt_refs_get(struct ovpn_peer *peer); +void ovpn_encrypt_key_exhausted(struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks); +void ovpn_encrypt_send(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, + struct sk_buff *skb, unsigned int packets); + #endif /* _NET_OVPN_OVPN_H_ */ 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); } /** From patchwork Fri Nov 13 15:51:09 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5689 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:18c:b0:11a:a05e:cb97 with SMTP id 12csp372175lag; Fri, 13 Nov 2026 07:52:11 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErE0VVggz8WVd3zsJJ5Rvi4knlGt42yvn6gtDzgoPcRUNTkL1LmqSL5Yv+OjYc8Pifxfc1z2RdQ6RRs=@openvpn.net X-Received: by 2002:a05:7022:3b84:b0:1b2:60ab:1e98 with SMTP id a92af1059eb24-1b5030f8824mr2968701c88.44.1794585130700; 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=CRXzO59/AaKUHI8+boLLztZC/EtMxa0f5l2qoCiob9+i7dP4G49opknwbDZZ/PaOl9 TaZTl6E2RiGMnubSKtGbHLMqgUe6sO7URPUvaSIljv9Fl2b7Be4FL2TL2X6iQtDaDKJj /83GsUTH1kqHl6ko9jOm0quNAajMr0E1uQSPXOFlYVl1sdLfg0Dfubd7BpxomEJsA29v B0AOOxoFK26xTDnyZtkY1GRCxpNSMuydItS8S5+KrddwF06EMKDbSkpO80cMTEClIXpH 4UOhx40uS+C+0V2ZTYdxwAcZ38RuZ3qgn7QTbXmbpK6JwS0A03Z9nMxGkbuR93CQXPvf CHNg== 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=qAY+3pERtdtJmK7IYm+IaYXqYbADioT4tatnHyr2Sfo=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=LIrmWqd41vV6SFfiW/HKz8IwxD6AJoiiJCa0eqtIacSIdStzFO1bCHakCF6qb4TVeS 44d5sRQVVYfO50tHzEVLSrx56UVfqLL9uknKYs56lhDQmZ2Bt2lPmiyk6OxvuEiF7w6z 70LjUntqNRZ0mlawqxBVyEHkCvNVYnjQGJ+7+xuVtjA8xI3t+gb1e4j+nBlR6LwlEMuY PLHgxjq1LfUFtNDLFMc1WcggPEACTdlhiZADPk3TfPCRYDDM+fIzL+sC197GcQfI/PID xxkfrawdnYnNvq7kA16PF/NWywDRMEBVBwK/0c8s6Qzwb/hybSn4qWiXRYlDTHZ2lBge zk9A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=AKwNJrEp; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=G7+orbdA; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Hx5WWtIv; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=ClQ+iR1X; 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-1b5031dc3e5si12460445c88.19.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=AKwNJrEp; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=G7+orbdA; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Hx5WWtIv; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=ClQ+iR1X; 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=qAY+3pERtdtJmK7IYm+IaYXqYbADioT4tatnHyr2Sfo=; b=AKwNJrEpnIdxr7 xpoRJUB40iyzcQ88jSkbnU7catnlbye88gplqZRAr3z8YJlcQWUR6OTw6qj09gmEWxwuXWC935smF GGnVNLjJwBL6LZUe8prqzyn2NhVm8btStrpbcghu1xNFQiA7n0jLA1zmY06XWG7ha+dYjHaIKg19E Ghw=; 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 1xRtZM-000000004Um-3lgB; Fri, 13 Nov 2026 15:52:04 +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 1xRtYr-000000004Su-49k9 for openvpn-devel@lists.sourceforge.net; Fri, 13 Nov 2026 15:51:35 +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=ao1IF2ret1qAavFUvs031nH9mRIkEF5MoLSTpvh17f0=; b=G7+orbdAuLZcEVjMLFSP32ADvR ZYJ4hFC7siJcuR1JKzCO8Kx7wQvX8OMs3HBtNlawhkTmbdpWzR9N0JKQIPjMIgbn1gafmF+khXQ1l xdY+/eWmZXmwNWohcWyviDHPUyKnjxp67PYHrirS2NG0DqwsYt0Rj6Egw9IRCNB2Ucn4=; 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=ao1IF2ret1qAavFUvs031nH9mRIkEF5MoLSTpvh17f0=; b=Hx5WWtIvbmeZ5ZDFI55/SezT5q WEo9f9LaUQlvErQjvXl2FxREP33/7Q5hKxQJRkw/kIlraVsj2vbHxlPYWDRWAe0Mr4kUP0NwKNzEs 7GNifUiNSqNUei4pCq7hPxjC5TMR2a772e1v/yPvIpMXTsaFSJnCUI0DfHMc+4jaWBE4=; Received: from mout-b-203.mailbox.org ([195.10.208.52]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xRtYp-000000005bU-0gLK 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 SHA512) (No client certificate requested) by mout-b-203.mailbox.org (Postfix) with ESMTPS id 4jR1vb5vsxzLlpk 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=ao1IF2ret1qAavFUvs031nH9mRIkEF5MoLSTpvh17f0=; b=ClQ+iR1XlG8rB3meyaRvlALxXXBh9eoY7Z6PDAiy188zzTvPCy5XppguE2YYuz3jMcfPK+ to/FkxPlKofwqonVl36YaBlAzhClcOwGdyDzajlMqTW4oR4LOWaazwPHjtWyJkdSRhuSq9 C72iSQ0cTpR2VJSjEZ0sX3vUgSsmaXMk9Ew7pE+3ILyAnzdbZh25gBcfU81oh0Pqf0OJpa v6uk/i6vFVQIo/YDpzSqBsYY1l9HxrfEL7feB9IW9uQ/iGzhZlXEc0wOA0OLMAp01J7QB7 jz8gV9Q1uVCU8j9NEwfDdjiVLrzbS/2R1AjMsAEPZXF+nDfDWZ7k5Dt/rzbVGw== 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:09 +0100 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jR1vb5vsxzLlpk 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: The segments of a GSO skb are encrypted out of place, from each segment into its range of the UDP GSO aggregate. Their L4 checksums are computed in software by the segmenter beforehand, which sums eac [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-Headers-End: 1xRtYp-000000005bU-0gLK Subject: [Openvpn-devel] [PATCH ovpn net-next 4/5] ovpn: encrypt GSO segments in place 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: 1881758898151453768 X-GMAIL-MSGID: 1881758898151453768 The segments of a GSO skb are encrypted out of place, from each segment into its range of the UDP GSO aggregate. Their L4 checksums are computed in software by the segmenter beforehand, which sums each segment's payload in a separate pass and, if its frags are shared as with sendfile, first copies it into a linear buffer. When the segments are going to be batched, leave their checksums partial instead. Copy each segment into its final position in the aggregate, summing it on the way, complete its checksum there as skb_checksum_help would and encrypt it in place. The checksums of packets left for the ordinary path are completed after batching. Segments with a frag_list are not batched, as the copy only walks the linear area and page frags. With one TCP flow over AES-128-GCM between two mlx5 ports connected back to back, with the sender, the receiver and their interrupts pinned to separate CPUs, the sender needs about 7% fewer CPU cycles per byte, and throughput rises from 27.5 to 29.2 Gbit/s, where the receiver becomes the bottleneck. With the aggregates segmented in software, where the sender is the bottleneck, throughput rises by 5%, from 17.1 to 18.0 Gbit/s. Signed-off-by: Ralf Lici --- drivers/net/ovpn/crypto_aead.c | 109 ++++++------------------ drivers/net/ovpn/crypto_aead.h | 12 +-- drivers/net/ovpn/gso.c | 147 ++++++++++++++++++++++++++++++++- drivers/net/ovpn/io.c | 53 +++++++----- 4 files changed, 209 insertions(+), 112 deletions(-) diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index e27b8c47c0fb..0a74cdf09e86 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -153,9 +153,9 @@ static struct aead_request *ovpn_aead_request_alloc(struct crypto_aead *aead, return req; } -static void ovpn_aead_encrypt_header(struct ovpn_peer *peer, - struct ovpn_crypto_key_slot *ks, - u32 pktid, u8 *iv, u8 *data) +void ovpn_aead_encrypt_header(struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, u32 pktid, + u8 *iv, u8 *data) { u32 op; @@ -171,39 +171,14 @@ static void ovpn_aead_encrypt_header(struct ovpn_peer *peer, 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_gso_ctx_init(struct ovpn_aead_gso_ctx *ctx, struct ovpn_crypto_key_slot *ks, struct sk_buff *gso_skb) { const unsigned int dst_nents = skb_shinfo(gso_skb)->nr_frags + 4; - const unsigned int src_nents = MAX_SKB_FRAGS + 2; unsigned int tmp_size; - tmp_size = ovpn_aead_crypto_tmp_size(ks->encrypt, - src_nents + dst_nents); + tmp_size = ovpn_aead_crypto_tmp_size(ks->encrypt, dst_nents); tmp_size += OVPN_AAD_SIZE; ctx->tmp = kmalloc(tmp_size, GFP_ATOMIC); if (unlikely(!ctx->tmp)) @@ -212,9 +187,8 @@ int ovpn_aead_gso_ctx_init(struct ovpn_aead_gso_ctx *ctx, ctx->dst_nents = dst_nents; ctx->iv = ovpn_aead_crypto_tmp_iv(ks->encrypt, ctx->tmp); ctx->req = ovpn_aead_crypto_tmp_req(ks->encrypt, ctx->iv); - ctx->src = ovpn_aead_crypto_req_sg(ks->encrypt, ctx->req); - ctx->dst = ctx->src + src_nents; - ctx->aad = (u8 *)(ctx->dst + dst_nents); + ctx->dst = ovpn_aead_crypto_req_sg(ks->encrypt, ctx->req); + ctx->head = (u8 *)(ctx->dst + dst_nents); aead_request_set_tfm(ctx->req, ks->encrypt); aead_request_set_callback(ctx->req, 0, NULL, NULL); aead_request_set_ad(ctx->req, OVPN_AAD_SIZE); @@ -227,72 +201,35 @@ void ovpn_aead_gso_ctx_free(struct ovpn_aead_gso_ctx *ctx) kfree(ctx->tmp); } -int ovpn_aead_encrypt_gso(struct ovpn_aead_gso_ctx *ctx, struct ovpn_peer *peer, - struct ovpn_crypto_key_slot *ks, struct sk_buff *skb, +int ovpn_aead_encrypt_gso(struct ovpn_aead_gso_ctx *ctx, struct sk_buff *gso_skb, unsigned int offset, - u32 pktid) + unsigned int crypt_len) { - unsigned int payload_off; - int dst_idx, mapped, ret; - bool direct_aad; + int nents, mapped; - /* encrypt out of place from the original segmented skb directly into - * its final range in the UDP GSO skb + /* The record at offset already holds its OpenVPN header, which is + * the AAD, room for the tag and the plaintext, and ctx->iv holds its + * nonce. Source and destination share one scatterlist, in which the + * tag follows the plaintext although it precedes it on the wire. */ - sg_init_table(ctx->src, skb_shinfo(skb)->nr_frags + 2); - /* 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, ctx->src, offset, - OVPN_AAD_SIZE); - if (unlikely(mapped < 0)) - return mapped; - direct_aad = mapped == 1 && - ovpn_aead_encrypt_header_direct(peer, ks, pktid, ctx->iv, - ctx->src); - if (unlikely(!direct_aad)) { - ovpn_aead_encrypt_header(peer, ks, pktid, ctx->iv, ctx->aad); - ret = skb_store_bits(gso_skb, offset, ctx->aad, - OVPN_AAD_SIZE); - if (unlikely(ret < 0)) - return ret; - sg_set_buf(ctx->src, ctx->aad, OVPN_AAD_SIZE); - } - - mapped = skb_to_sgvec_nomark(skb, ctx->src + 1, 0, skb->len); - if (unlikely(mapped < 0)) - return mapped; - sg_mark_end(&ctx->src[mapped]); - sg_init_table(ctx->dst, ctx->dst_nents); - if (likely(direct_aad)) { - /* destination AAD is not written and may alias source AAD */ - sg_set_page(ctx->dst, sg_page(ctx->src), ctx->src->length, - ctx->src->offset); - dst_idx = 1; - } else { - dst_idx = skb_to_sgvec_nomark(gso_skb, ctx->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, ctx->dst + dst_idx, - payload_off, skb->len); + nents = skb_to_sgvec_nomark(gso_skb, ctx->dst, offset, OVPN_AAD_SIZE); + if (unlikely(nents < 0)) + return nents; + mapped = skb_to_sgvec_nomark(gso_skb, ctx->dst + nents, + offset + OVPN_DATA_V2_OVERHEAD, crypt_len); if (unlikely(mapped < 0)) return mapped; - dst_idx += mapped; - - mapped = skb_to_sgvec_nomark(gso_skb, ctx->dst + dst_idx, + nents += mapped; + mapped = skb_to_sgvec_nomark(gso_skb, ctx->dst + nents, offset + OVPN_AAD_SIZE, OVPN_AUTH_TAG_SIZE); if (unlikely(mapped < 0)) return mapped; - dst_idx += mapped; - sg_mark_end(&ctx->dst[dst_idx - 1]); + nents += mapped; + sg_mark_end(&ctx->dst[nents - 1]); - aead_request_set_crypt(ctx->req, ctx->src, ctx->dst, skb->len, + aead_request_set_crypt(ctx->req, ctx->dst, ctx->dst, crypt_len, ctx->iv); return crypto_aead_encrypt(ctx->req); diff --git a/drivers/net/ovpn/crypto_aead.h b/drivers/net/ovpn/crypto_aead.h index c0c777410661..ae09d304c971 100644 --- a/drivers/net/ovpn/crypto_aead.h +++ b/drivers/net/ovpn/crypto_aead.h @@ -20,11 +20,11 @@ struct scatterlist; struct ovpn_aead_gso_ctx { struct aead_request *req; - struct scatterlist *src; struct scatterlist *dst; void *tmp; u8 *iv; - u8 *aad; + /* start of the record: its AAD */ + u8 *head; unsigned int dst_nents; }; @@ -34,10 +34,12 @@ int ovpn_aead_gso_ctx_init(struct ovpn_aead_gso_ctx *ctx, struct ovpn_crypto_key_slot *ks, struct sk_buff *gso_skb); void ovpn_aead_gso_ctx_free(struct ovpn_aead_gso_ctx *ctx); -int ovpn_aead_encrypt_gso(struct ovpn_aead_gso_ctx *ctx, struct ovpn_peer *peer, - struct ovpn_crypto_key_slot *ks, struct sk_buff *skb, +void ovpn_aead_encrypt_header(struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, u32 pktid, + u8 *iv, u8 *data); +int ovpn_aead_encrypt_gso(struct ovpn_aead_gso_ctx *ctx, struct sk_buff *gso_skb, unsigned int offset, - u32 pktid); + unsigned int crypt_len); int ovpn_aead_decrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb); diff --git a/drivers/net/ovpn/gso.c b/drivers/net/ovpn/gso.c index 432738812548..45933a39c9df 100644 --- a/drivers/net/ovpn/gso.c +++ b/drivers/net/ovpn/gso.c @@ -7,6 +7,7 @@ * Ralf Lici */ +#include #include #include #include @@ -32,6 +33,14 @@ sizeof(struct ipv6hdr) - \ sizeof(struct udphdr) - 1) +/* position in the linear area and page frags of an input skb */ +struct ovpn_gso_cursor { + const struct sk_buff *skb; + unsigned int head_off; + unsigned int frag_idx; + unsigned int frag_off; +}; + struct ovpn_gso_source { unsigned int segments; unsigned int next; @@ -40,6 +49,140 @@ struct ovpn_gso_source { struct sk_buff_head *skbs; }; +static bool ovpn_gso_copy_chunk(struct ovpn_gso_cursor *cur, u8 *to, + unsigned int len, unsigned int *pos, + __wsum *csum) +{ + unsigned int head_len = skb_headlen(cur->skb); + const struct sk_buff *skb = cur->skb; + __wsum part; + + /* Copy len bytes of the skb from the cursor position, first from the + * linear area if the cursor has not left it yet. Each copy also sums + * the copied bytes, and csum_block_add rotates that partial sum when + * it starts at an odd byte position of the copied range. + */ + if (cur->head_off < head_len) { + unsigned int size = min(len, head_len - cur->head_off); + + part = csum_partial_copy_nocheck(skb->data + cur->head_off, + to, size); + *csum = csum_block_add(*csum, part, *pos); + cur->head_off += size; + *pos += size; + to += size; + len -= size; + } + + /* then continue through the page frags */ + while (len && cur->frag_idx < skb_shinfo(skb)->nr_frags) { + const skb_frag_t *frag = &skb_shinfo(skb)->frags[cur->frag_idx]; + u32 p_off, p_len, copied; + unsigned int size; + struct page *p; + u8 *vaddr; + + /* map each page separately for highmem; elsewhere the whole + * range of the frag is one piece + */ + size = min(len, skb_frag_size(frag) - cur->frag_off); + skb_frag_foreach_page(frag, skb_frag_off(frag) + cur->frag_off, + size, p, p_off, p_len, copied) { + vaddr = kmap_local_page(p); + part = csum_partial_copy_nocheck(vaddr + p_off, + to + copied, p_len); + *csum = csum_block_add(*csum, part, *pos + copied); + kunmap_local(vaddr); + } + + /* move on to the next frag once this one is used up */ + cur->frag_off += size; + *pos += size; + to += size; + len -= size; + if (cur->frag_off == skb_frag_size(frag)) { + cur->frag_idx++; + cur->frag_off = 0; + } + } + + /* the skb ended before len bytes */ + return !len; +} + +static bool ovpn_gso_copy(struct ovpn_gso_cursor *cur, struct sk_buff *batch, + unsigned int offset, unsigned int len, __wsum *csum) +{ + unsigned int pos = 0, i; + + /* Copy len bytes of the skb at the cursor into the aggregate at offset + * and return their checksum in csum. The aggregate's frags come from + * ovpn_gso_alloc without __GFP_HIGHMEM, so each is directly mapped: + * skip those before offset, then copy into each one in turn, carrying + * the byte position for the checksum. + */ + *csum = 0; + for (i = 0; len && i < skb_shinfo(batch)->nr_frags; i++) { + skb_frag_t *frag = &skb_shinfo(batch)->frags[i]; + unsigned int size = skb_frag_size(frag), n; + + if (offset >= size) { + offset -= size; + continue; + } + + n = min(len, size - offset); + if (!ovpn_gso_copy_chunk(cur, skb_frag_address(frag) + offset, + n, &pos, csum)) + return false; + len -= n; + offset = 0; + } + + return !len; +} + +static int ovpn_gso_encrypt_segment(struct ovpn_aead_gso_ctx *ctx, + struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, + struct sk_buff *skb, struct sk_buff *batch, + unsigned int offset, u32 pktid) +{ + unsigned int data = offset + OVPN_DATA_V2_OVERHEAD; + struct ovpn_gso_cursor cur = { .skb = skb }; + unsigned int start = 0; + __sum16 check; + __wsum csum; + int ret; + + /* Copy the segment behind the OpenVPN header and the tag. Its L4 + * checksum is left partial for batching, so copy the headers in front + * of it, then the rest summing it on the way, and complete it in the + * aggregate as skb_checksum_help would in the segment. + */ + if (skb->ip_summed == CHECKSUM_PARTIAL) + start = skb_checksum_start_offset(skb); + if (unlikely(!ovpn_gso_copy(&cur, batch, data, start, &csum) || + !ovpn_gso_copy(&cur, batch, data + start, skb->len - start, + &csum))) + return -EMSGSIZE; + if (skb->ip_summed == CHECKSUM_PARTIAL) { + check = csum_fold(csum) ?: CSUM_MANGLED_0; + ret = skb_store_bits(batch, data + start + skb->csum_offset, + &check, sizeof(check)); + if (unlikely(ret < 0)) + return ret; + } + + /* store the OpenVPN header in front; encryption fills in the tag */ + ovpn_aead_encrypt_header(peer, ks, pktid, ctx->iv, ctx->head); + ret = skb_store_bits(batch, offset, ctx->head, OVPN_AAD_SIZE); + if (unlikely(ret < 0)) + return ret; + + return ovpn_aead_encrypt_gso(ctx, batch, offset, skb->len); +} + static bool ovpn_gso_encrypt_batch(struct ovpn_gso_source *src, struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, @@ -68,8 +211,8 @@ static bool ovpn_gso_encrypt_batch(struct ovpn_gso_source *src, src->next++; len = skb->len + OVPN_DATA_V2_OVERHEAD; - ret = ovpn_aead_encrypt_gso(&ctx, peer, ks, skb, batch, offset, - first_pktid + i); + ret = ovpn_gso_encrypt_segment(&ctx, peer, ks, skb, batch, + offset, first_pktid + i); if (unlikely(ret < 0)) { DEBUG_NET_WARN_ON_ONCE(ret == -EINPROGRESS || ret == -EBUSY); diff --git a/drivers/net/ovpn/io.c b/drivers/net/ovpn/io.c index 358b2b9ebf36..83cdd2acfce2 100644 --- a/drivers/net/ovpn/io.c +++ b/drivers/net/ovpn/io.c @@ -387,10 +387,10 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) { struct ovpn_priv *ovpn = netdev_priv(dev); struct sk_buff *segments, *curr, *next; + unsigned int tx_bytes = 0, tx_packets; const bool gso_in = skb_is_gso(skb); struct sk_buff_head skb_list; netdev_features_t features; - unsigned int tx_bytes = 0; struct ovpn_peer *peer; bool gso_out; __be16 proto; @@ -429,13 +429,18 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) /* dst was needed for peer selection - it can now be dropped */ skb_dst_drop(skb); + gso_out = gso_out && ovpn_gso_supported(peer); + if (gso_in) { - /* force software segmentation and calculate each checksum - * while allowing safe page-backed payload fragments to remain - * non-linear + /* force software segmentation while allowing safe page-backed + * payload fragments to remain non-linear. Batching completes + * the L4 checksums while copying the segments, so only + * calculate them here if the segments are not batched. */ features = netif_skb_features(skb); - features &= ~(NETIF_F_GSO_MASK | NETIF_F_CSUM_MASK); + features &= ~NETIF_F_GSO_MASK; + if (!gso_out) + features &= ~NETIF_F_CSUM_MASK; segments = skb_gso_segment(skb, features); if (IS_ERR_OR_NULL(segments)) { ret = PTR_ERR(segments); @@ -463,16 +468,9 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) continue; } - /* NETIF_F_HW_CSUM requires completing partial checksums */ - if (unlikely(curr->ip_summed == CHECKSUM_PARTIAL && - skb_checksum_help(curr) < 0)) { - net_err_ratelimited("%s: skb_checksum_help failed for payload packet\n", - netdev_name(dev)); - ovpn_dev_dstats_tx_dropped(ovpn->dev, 1); - kfree_skb(curr); + /* batching copies only the linear area and page frags */ + if (unlikely(skb_has_frag_list(curr))) gso_out = false; - continue; - } /* one aggregate can carry only one write owner, so batch only * segments that share it @@ -498,13 +496,30 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) return NETDEV_TX_OK; } - ovpn_peer_stats_add_tx(&peer->vpn_stats, tx_bytes, - skb_queue_len(&skb_list)); - - if (gso_out && skb_queue_len(&skb_list) > 1 && - ovpn_gso_supported(peer)) + tx_packets = skb_queue_len(&skb_list); + if (gso_out && tx_packets > 1) ovpn_gso_send(&skb_list, peer); + /* NETIF_F_HW_CSUM requires completing partial checksums, which + * batching does while copying, so complete those of the packets left + * for the ordinary path + */ + skb_queue_walk_safe(&skb_list, curr, next) { + if (curr->ip_summed != CHECKSUM_PARTIAL || + likely(skb_checksum_help(curr) >= 0)) + continue; + + net_err_ratelimited("%s: skb_checksum_help failed for payload packet\n", + netdev_name(dev)); + __skb_unlink(curr, &skb_list); + ovpn_dev_dstats_tx_dropped(ovpn->dev, 1); + tx_bytes -= curr->len; + tx_packets--; + kfree_skb(curr); + } + + ovpn_peer_stats_add_tx(&peer->vpn_stats, tx_bytes, tx_packets); + skb_list.prev->next = NULL; ovpn_send(ovpn, skb_list.next, peer); From patchwork Fri Nov 13 15:51:10 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5686 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:18c:b0:11a:a05e:cb97 with SMTP id 12csp372168lag; Fri, 13 Nov 2026 07:52:11 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFWD6pdt6l2jiEpE/Vu2oBT9KqInws6XFajR2sshTqpEG4Y9BKnVLHsKe5oogSweHqWI88eBmvvYHg=@openvpn.net X-Received: by 2002:a05:701b:4587:b0:1b2:6844:25c9 with SMTP id a92af1059eb24-1b5030613dbmr2476622c88.3.1794585130696; 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=TUHANOTEbrsceCGHLWSN6rMxsdO2X9MIil5L1Ro/vHMYdPx07F+QhvEidJRdh9gyAB t0zmflADkIfCm2N31sc4xf+fMgeqKWMgHNdta1966ydjtfzUaFZ2ExYIPZYvv+R6M/J+ fnChlEkaUr6TEL3WG2l1XDd3yzyVqmVDCpU9jQvTw+dGOMp8d7/n1E2rIIlHeteuui0K w1X8WGUzkeD+b777FjKMkSi0DyX8vKN/8ZAy0Z48NYKeKUj/OIngkimea+Kh0QnXhpOi Y2g+XMY6bHyQJYIA28zpichAlgF4PusabNKa0CBDhDXxCe62ekQ39mpRUhjyQR70HFjs kAJA== 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=VlbbfCKEmNjjs8pS3ud9zVKIl36T0GvfhG8k0pjN6c0=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=FRu9vJlShAXDYtZF62haVIGSfzujQVZl4tuyOpKee6wFThbotMh0neOrWZBoj92Pd8 zsO+pifT6EkxaP9BshjcWxw9NnlkaMKceB8EOWyapYbDCdCi9eJuavRje9VpM6u/Tv7S U3EnA+y2oLcwFyP50d0l/YBvQK8qUN46qSO22RyIszqiAMlRLq/ackuqtZYOBc6WoGqC 18FeYPC4OiQMLbkfjqMfGPp/Be+P87Bk1bQIEq6nInV72qV7i3qbzWTC1O+3ktROAjNX gUnolZkG1axz34HRXlaDYDTyOmeLfy44x83BSRJHGrTMMFgrO0d2I/D0ZCc85VkN33E3 M/Bg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=MLbHcjM8; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=KQ3nYK2l; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Kk9+d472; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b="WXZLB/DD"; 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-1b50323a443si7436875c88.60.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=MLbHcjM8; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=KQ3nYK2l; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Kk9+d472; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b="WXZLB/DD"; 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=VlbbfCKEmNjjs8pS3ud9zVKIl36T0GvfhG8k0pjN6c0=; b=MLbHcjM8UM0PlM C25x35htJI3q/YqNmFZIZBMQWKeQ0QbVmZ2rsZ9kJ5DlLKYuu0uGSrZZLeiA/H9VTom9U2kzM6AAy 1CAVlAEtX9W0E1qfqJ5wLiCAbAk486ghJ35r5SnIURc3bzJRy4cXAzbKD248pa8XMRO/OZNSffFNj 5YE=; Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xRtZQ-000000007AS-2yvc; Fri, 13 Nov 2026 15:52:08 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.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-0000000079t-1WMK 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=/w7XLqyyndvkFpV1Z1EOxvjEHIgiHQs3VxlUoyGPiWM=; b=KQ3nYK2l86c9sJTvLrVPwOrX0k e7jvEg0ytmiBCpbPCcertTL4BRniyYL4UR8S1qSj4ijxiKivvEPI5Va9Fj5Y7SHsw6YW4NnS6w1pW IbI8iv6AFdTfBTWtfCi17sYZMMlsih2ZBCI6f5zQU4jPZRfME+ATFpY53t8wdsHQ02jU=; 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=/w7XLqyyndvkFpV1Z1EOxvjEHIgiHQs3VxlUoyGPiWM=; b=Kk9+d4729B8osHPNIzkweeOs/r QO7vqP4md2bK1NHbYIDKIe8FO/7Oiln3Lkz4OC16W/MRCivR8u37QTN6OwRX1iQeV9bV4Z4pExzBf uLj7lSx3n/k5b/CNsoMbteqEUDKlD56az/UwAGSbD+ErLx2A73GLYd0EE8nM1psv07zs=; Received: from mout-b-112.mailbox.org ([195.10.208.42]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xRtYp-000000005bV-2X4x for openvpn-devel@lists.sourceforge.net; Fri, 13 Nov 2026 15:51:35 +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-112.mailbox.org (Postfix) with ESMTPS id 4jR1vc1CQ8z5vtq for ; Fri, 13 Nov 2026 16:51:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1794585084; 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=/w7XLqyyndvkFpV1Z1EOxvjEHIgiHQs3VxlUoyGPiWM=; b=WXZLB/DD4CoJ0kNzkS/MjkgLdXisFTtxkWkZUd59I//4FECdyDDf1wVuOPHRwHZSE1vQg3 ylIl1XJXFXgsI3DRzBZ0fkB6cUQcfcxnd9hQBXwC5rCe+vhptd/PYP+x48MnRFd06cjwx3 11QLJo7bAnIUtpOQijZ65zu8w69aN1CE2CtjDrkFLNixOYYoYEg40qynrIadeSgK9aIvXc tdoPwBAH49h7xy297BAbRJ7dlGu1G10wAwTQrXKAClGWz8JvRSfDoKNNnPetipMG8EfPNP J28VENTMXSrj5HznH5C5k0JtnEgEO9tOSbaJmGr41GPFeWI1wV+VYNp57EZveg== 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:10 +0100 Message-ID: <4b5efed85f76f63efe4d7e8f78be3e966a8b6939.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: 4jR1vc1CQ8z5vtq 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: Software segmentation materializes one child skb per inner packet even though UDP GSO output immediately copies each encrypted record into a new aggregate. The child skbs provide header storage, but t [...] 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-000000005bV-2X4x Subject: [Openvpn-devel] [PATCH ovpn net-next 5/5] ovpn: encrypt GSO input without child skbs 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: 1881758898098757984 X-GMAIL-MSGID: 1881758898098757984 Software segmentation materializes one child skb per inner packet even though UDP GSO output immediately copies each encrypted record into a new aggregate. The child skbs provide header storage, but their payload remains shared with the original GSO skb. For the IPv4 and IPv6 TCP and UDP GSO shapes which tso_build_hdr supports, add a record source which copies each record's payload from the original skb into its final position in the outer UDP GSO aggregate with the segment copy helpers, computing the inner L4 checksum on the way. Synthesize the record's network and transport headers behind its OpenVPN data header in the per-batch crypto buffer, complete their checksums, store them in front of the payload and encrypt the record in place. As with NETIF_F_TSO_MANGLEID, fixed-ID TCP aggregates get incrementing IPv4 IDs; gso_features_check already segments those without DF before they reach the driver. AccECN aggregates are accepted, as tso_build_hdr keeps CWR on every record just as their segmentation does. The aggregates take over the input's write ownership as for materialized segments, and the input's own charge is released without its destructor once the last aggregate is built, so TSQ is not woken before the aggregates are transmitted. Classic ECN aggregates, whose CWR belongs on the first segment only, frag_list input, IPv6 extension headers, headers outside the linear area, shared and TX-timestamped skbs and inputs whose records cannot all be batched stay on the software segmentation path. If an aggregate fails after earlier ones were sent, the remaining records are dropped, as they cannot fall back without resending the others. With one TCP flow over AES-128-GCM between two mlx5 ports connected back to back, with the sender, the receiver and their interrupts pinned to separate CPUs, the sender needs about 26% fewer CPU cycles per byte than with copied segments, while throughput only rises from 29.2 to 30.3 Gbit/s, as the receiver remains the bottleneck and hides most of the gain. With the aggregates segmented in software, where the sender is the bottleneck, throughput rises from 18.0 to 21.7 Gbit/s. Signed-off-by: Ralf Lici --- drivers/net/ovpn/crypto_aead.c | 8 +- drivers/net/ovpn/crypto_aead.h | 5 +- drivers/net/ovpn/gso.c | 275 ++++++++++++++++++++++++++++++--- drivers/net/ovpn/gso.h | 1 + drivers/net/ovpn/io.c | 2 + 5 files changed, 269 insertions(+), 22 deletions(-) diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index 0a74cdf09e86..427eecea6b04 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -173,13 +173,17 @@ void ovpn_aead_encrypt_header(struct ovpn_peer *peer, int ovpn_aead_gso_ctx_init(struct ovpn_aead_gso_ctx *ctx, struct ovpn_crypto_key_slot *ks, - struct sk_buff *gso_skb) + struct sk_buff *gso_skb, + unsigned int header_len) { const unsigned int dst_nents = skb_shinfo(gso_skb)->nr_frags + 4; unsigned int tmp_size; tmp_size = ovpn_aead_crypto_tmp_size(ks->encrypt, dst_nents); - tmp_size += OVPN_AAD_SIZE; + /* the head buffer stages the start of a record: its AAD and, for a + * TSO record, room for the tag and its synthesized headers + */ + tmp_size += OVPN_DATA_V2_OVERHEAD + header_len; ctx->tmp = kmalloc(tmp_size, GFP_ATOMIC); if (unlikely(!ctx->tmp)) return -ENOMEM; diff --git a/drivers/net/ovpn/crypto_aead.h b/drivers/net/ovpn/crypto_aead.h index ae09d304c971..f675995d9c64 100644 --- a/drivers/net/ovpn/crypto_aead.h +++ b/drivers/net/ovpn/crypto_aead.h @@ -23,7 +23,7 @@ struct ovpn_aead_gso_ctx { struct scatterlist *dst; void *tmp; u8 *iv; - /* start of the record: its AAD */ + /* start of the record: AAD, room for the tag, synthesized headers */ u8 *head; unsigned int dst_nents; }; @@ -32,7 +32,8 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct sk_buff *skb); int ovpn_aead_gso_ctx_init(struct ovpn_aead_gso_ctx *ctx, struct ovpn_crypto_key_slot *ks, - struct sk_buff *gso_skb); + struct sk_buff *gso_skb, + unsigned int header_len); void ovpn_aead_gso_ctx_free(struct ovpn_aead_gso_ctx *ctx); void ovpn_aead_encrypt_header(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, u32 pktid, diff --git a/drivers/net/ovpn/gso.c b/drivers/net/ovpn/gso.c index 45933a39c9df..c2c5e3b8e36e 100644 --- a/drivers/net/ovpn/gso.c +++ b/drivers/net/ovpn/gso.c @@ -10,7 +10,10 @@ #include #include #include +#include +#include #include +#include #include #include "ovpnpriv.h" @@ -33,6 +36,52 @@ sizeof(struct ipv6hdr) - \ sizeof(struct udphdr) - 1) +static void ovpn_gso_build_hdr(struct sk_buff *skb, struct tso_t *tso, + void *header, unsigned int payload_len, + __wsum payload_csum, bool is_last) +{ + u8 *transport_header = (u8 *)header + skb_transport_offset(skb); + unsigned int l4_len = tso->tlen + payload_len; + __sum16 *check; + __wsum csum; + u8 proto; + + /* copy the parent's headers and set this record's IP length and ID, + * TCP sequence number and flags or UDP length + */ + tso_build_hdr(skb, header, tso, payload_len, is_last); + + /* the L4 checksum covers the transport header and the payload, whose + * sum the caller computed while copying it + */ + if (skb_is_gso_tcp(skb)) { + check = &((struct tcphdr *)transport_header)->check; + proto = IPPROTO_TCP; + } else { + check = &((struct udphdr *)transport_header)->check; + proto = IPPROTO_UDP; + } + *check = 0; + csum = csum_partial(transport_header, tso->tlen, payload_csum); + + if (tso->ipv6) { + struct ipv6hdr *iph = header + skb_network_offset(skb); + + *check = csum_ipv6_magic(&iph->saddr, &iph->daddr, l4_len, + proto, csum); + } else { + struct iphdr *iph = header + skb_network_offset(skb); + + *check = csum_tcpudp_magic(iph->saddr, iph->daddr, l4_len, + proto, csum); + /* IPv4 also checksums its own header */ + ip_send_check(iph); + } + /* a zero UDP checksum would mean none */ + if (proto == IPPROTO_UDP && !*check) + *check = CSUM_MANGLED_0; +} + /* position in the linear area and page frags of an input skb */ struct ovpn_gso_cursor { const struct sk_buff *skb; @@ -47,6 +96,11 @@ struct ovpn_gso_source { unsigned int record_len; unsigned int last_record_len; struct sk_buff_head *skbs; + /* set if the records are ranges of a parent skb instead */ + struct sk_buff *parent; + struct tso_t tso; + struct ovpn_gso_cursor cursor; + unsigned int hdr_len; }; static bool ovpn_gso_copy_chunk(struct ovpn_gso_cursor *cur, u8 *to, @@ -183,18 +237,64 @@ static int ovpn_gso_encrypt_segment(struct ovpn_aead_gso_ctx *ctx, return ovpn_aead_encrypt_gso(ctx, batch, offset, skb->len); } +static int ovpn_gso_encrypt_record(struct ovpn_gso_source *src, + struct ovpn_aead_gso_ctx *ctx, + struct ovpn_peer *peer, + struct ovpn_crypto_key_slot *ks, + struct sk_buff *batch, unsigned int offset, + u32 pktid, unsigned int *len) +{ + unsigned int data = offset + OVPN_DATA_V2_OVERHEAD; + unsigned int hdr_len = src->hdr_len; + unsigned int index = src->next++; + unsigned int payload_len; + u8 *record = ctx->head; + __wsum csum; + bool last; + int ret; + + /* copy the record's payload into its final position in the aggregate, + * behind the OpenVPN header, the tag and the inner headers, and sum it + * on the way + */ + last = index + 1 == src->segments; + payload_len = (last ? src->last_record_len : src->record_len) - hdr_len; + if (unlikely(!ovpn_gso_copy(&src->cursor, batch, data + hdr_len, + payload_len, &csum))) + return -EMSGSIZE; + + /* stage the start of the record as it is laid out in the aggregate: + * the OpenVPN header, room for the tag and the synthesized inner + * headers, whose checksums cover the payload copied above + */ + ovpn_gso_build_hdr(src->parent, &src->tso, + record + OVPN_DATA_V2_OVERHEAD, payload_len, csum, + last); + tso_advance_hdr(&src->tso, payload_len); + ovpn_aead_encrypt_header(peer, ks, pktid, ctx->iv, record); + + /* store it in front of the payload; encryption overwrites the tag */ + ret = skb_store_bits(batch, offset, record, + OVPN_DATA_V2_OVERHEAD + hdr_len); + if (unlikely(ret < 0)) + return ret; + + *len = hdr_len + payload_len + OVPN_DATA_V2_OVERHEAD; + return ovpn_aead_encrypt_gso(ctx, batch, offset, hdr_len + payload_len); +} + 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) { - unsigned int offset = 0, moved = 0, i, len; + unsigned int offset = 0, moved = 0, i, len, batch_start = src->next; struct ovpn_aead_gso_ctx ctx = { }; struct sk_buff *skb; u32 first_pktid; int ret; - if (unlikely(ovpn_aead_gso_ctx_init(&ctx, ks, batch))) + if (unlikely(ovpn_aead_gso_ctx_init(&ctx, ks, batch, src->hdr_len))) goto err; /* reserve the complete range before dequeuing any input skb so that a @@ -207,20 +307,37 @@ static bool ovpn_gso_encrypt_batch(struct ovpn_gso_source *src, } for (i = 0; i < segments; i++) { - skb = __skb_dequeue(src->skbs); - src->next++; - len = skb->len + OVPN_DATA_V2_OVERHEAD; - - ret = ovpn_gso_encrypt_segment(&ctx, peer, ks, skb, batch, - offset, first_pktid + i); + if (src->parent) { + skb = NULL; + ret = ovpn_gso_encrypt_record(src, &ctx, peer, ks, + batch, offset, + first_pktid + i, &len); + } else { + skb = __skb_dequeue(src->skbs); + src->next++; + len = skb->len + OVPN_DATA_V2_OVERHEAD; + ret = ovpn_gso_encrypt_segment(&ctx, peer, ks, skb, + batch, offset, + first_pktid + i); + } if (unlikely(ret < 0)) { DEBUG_NET_WARN_ON_ONCE(ret == -EINPROGRESS || ret == -EBUSY); + /* report the whole batch as not handled */ + if (src->parent) { + src->next = batch_start; + break; + } ovpn_dev_dstats_tx_dropped(peer->ovpn->dev, i + 1); kfree_skb(skb); break; } + offset += len; + /* the caller releases the parent skb of TSO records */ + if (src->parent) + continue; + /* pass on the TX timestamp request, which GSO segmentation * attached to the segment holding the timestamped byte */ @@ -241,7 +358,17 @@ static bool ovpn_gso_encrypt_batch(struct ovpn_gso_source *src, skb->sk = NULL; } consume_skb(skb); - offset += len; + } + + /* once the last aggregate is built, the input's data lives in + * aggregates which carry their own write charge, so release the + * input's charge without waking TSQ before they are transmitted + */ + if (src->parent && batch->sk && i == segments && + src->next == src->segments) { + moved += src->parent->truesize; + src->parent->destructor = NULL; + src->parent->sk = NULL; } /* the aggregate's own charge keeps sk_wmem_alloc above zero */ @@ -263,6 +390,7 @@ static bool ovpn_gso_encrypt_batch(struct ovpn_gso_source *src, static struct sk_buff *ovpn_gso_alloc(const struct sk_buff *first_segment, unsigned int batch_len, + unsigned int record_len, unsigned int segments) { struct sk_buff *gso_skb; @@ -306,17 +434,16 @@ static struct sk_buff *ovpn_gso_alloc(const struct sk_buff *first_segment, #endif skb_shinfo(gso_skb)->gso_type = SKB_GSO_UDP_L4; - skb_shinfo(gso_skb)->gso_size = first_segment->len + - OVPN_DATA_V2_OVERHEAD; + skb_shinfo(gso_skb)->gso_size = record_len + OVPN_DATA_V2_OVERHEAD; skb_shinfo(gso_skb)->gso_segs = segments; return gso_skb; } -static void ovpn_gso_send_batch(struct ovpn_gso_source *src, - struct ovpn_peer *peer) +static unsigned int ovpn_gso_send_batch(struct ovpn_gso_source *src, + struct ovpn_peer *peer) { - unsigned int max_segs, batch_len, batch_segs, batch_start; + unsigned int max_segs, batch_len, batch_segs, batch_start, remaining; struct ovpn_crypto_key_slot *ks; struct sk_buff *batch; @@ -328,7 +455,14 @@ static void ovpn_gso_send_batch(struct ovpn_gso_source *src, * ordinary transmit path */ if (max_segs < 2) - return; + return 0; + + /* A parent skb cannot leave one record for the ordinary path. If a + * batch holds at most two records, an odd record count cannot be split + * entirely into valid UDP GSO aggregates, so fall back. + */ + if (src->parent && max_segs == 2 && (src->segments & 1)) + return 0; /* An input GSO skb might produce more than max_segs records, so * consume as many as can fit in each aggregate. A final materialized @@ -336,7 +470,11 @@ static void ovpn_gso_send_batch(struct ovpn_gso_source *src, */ while (src->segments - src->next > 1) { batch_start = src->next; - batch_segs = min(src->segments - src->next, max_segs); + remaining = src->segments - src->next; + batch_segs = min(remaining, max_segs); + /* a parent skb cannot leave one record behind */ + if (src->parent && remaining - batch_segs == 1) + batch_segs--; /* acquire shared state before allocating/consuming anything */ ks = ovpn_encrypt_refs_get(peer); @@ -358,13 +496,15 @@ static void ovpn_gso_send_batch(struct ovpn_gso_source *src, 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); + batch = ovpn_gso_alloc(src->parent ?: skb_peek(src->skbs), + batch_len, src->record_len, batch_segs); if (unlikely(!batch)) { ovpn_crypto_key_slot_put(ks); ovpn_peer_put(peer); break; } + if (src->parent && batch_start) + batch->ooo_okay = 0; if (unlikely(!ovpn_gso_encrypt_batch(src, peer, ks, batch, batch_segs))) { @@ -372,6 +512,8 @@ static void ovpn_gso_send_batch(struct ovpn_gso_source *src, break; } } + + return src->next; } /** @@ -396,6 +538,103 @@ void ovpn_gso_send(struct sk_buff_head *skbs, struct ovpn_peer *peer) ovpn_gso_send_batch(&src, peer); } +/** + * ovpn_gso_send_tso - encrypt a TCP or UDP GSO skb without segmenting it + * @skb: GSO skb to send + * @peer: peer to send it to + * + * Builds each record from a range of @skb instead of materializing its + * segments. Only for peers which pass ovpn_gso_supported. + * + * Return: true if @skb was consumed along with the caller's reference to + * @peer, false if it was left for the ordinary segmenter + */ +bool ovpn_gso_send_tso(struct sk_buff *skb, struct ovpn_peer *peer) +{ + const netdev_features_t features = NETIF_F_TSO | NETIF_F_TSO6 | + NETIF_F_TSO_MANGLEID | + NETIF_F_GSO_ACCECN | + NETIF_F_GSO_UDP_L4; + u8 proto = skb_is_gso_tcp(skb) ? IPPROTO_TCP : IPPROTO_UDP; + unsigned int hdr_len, payload_len, total_segs, handled; + unsigned int gso_size, last_payload_len, tx_bytes; + struct ovpn_gso_source src = { + .parent = skb, + .cursor.skb = skb, + }; + + if (!skb_gso_ok(skb, features)) + return false; + + /* the aggregates take over the parent's write charge, which requires + * owning it alone + */ + if (unlikely(skb_shared(skb))) + return false; + + /* let the protocol segmenter place a TX timestamp request on the + * appropriate child before batching those materialized segments + */ + if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_ANY_TSTAMP)) + return false; + + /* tso_build_hdr does not account for IPv6 extension headers. On a + * forwarded skb the transport header still points right behind the + * IPv6 header even when extension headers follow it, so check the next + * header too. + */ + if (skb->protocol == htons(ETH_P_IPV6) && + unlikely(ipv6_hdr(skb)->nexthdr != proto || + skb_network_header_len(skb) != sizeof(struct ipv6hdr))) + return false; + + /* tso_start reads the TCP header from the linear area */ + if (proto == IPPROTO_TCP && + unlikely(skb_headlen(skb) < + skb_transport_offset(skb) + sizeof(struct tcphdr))) + return false; + + /* tso_build_hdr copies the headers from the linear area */ + hdr_len = tso_start(skb, &src.tso); + if (unlikely(skb_headlen(skb) < hdr_len)) + return false; + + gso_size = skb_shinfo(skb)->gso_size; + payload_len = skb->len - hdr_len; + total_segs = DIV_ROUND_UP(payload_len, gso_size); + if (unlikely(total_segs < 2)) + return false; + + last_payload_len = payload_len - (total_segs - 1) * gso_size; + src.segments = total_segs; + src.record_len = hdr_len + gso_size; + src.last_record_len = hdr_len + last_payload_len; + src.cursor.head_off = hdr_len; + src.hdr_len = hdr_len; + + handled = ovpn_gso_send_batch(&src, peer); + /* if nothing was sent we can safely fall back to segmentation */ + if (!handled) + return false; + + tx_bytes = handled * src.record_len; + if (handled == total_segs) + tx_bytes -= src.record_len - src.last_record_len; + ovpn_peer_stats_add_tx(&peer->vpn_stats, tx_bytes, handled); + if (unlikely(handled < total_segs)) { + /* the remaining records cannot fall back to the segmenter + * without resending those already transmitted + */ + ovpn_dev_dstats_tx_dropped(peer->ovpn->dev, + total_segs - handled); + kfree_skb(skb); + } else { + consume_skb(skb); + } + ovpn_peer_put(peer); + return true; +} + /** * ovpn_gso_supported - check whether a peer can send UDP GSO aggregates * @peer: peer to check diff --git a/drivers/net/ovpn/gso.h b/drivers/net/ovpn/gso.h index cc7b6b8ce314..0b0cd83e7696 100644 --- a/drivers/net/ovpn/gso.h +++ b/drivers/net/ovpn/gso.h @@ -15,6 +15,7 @@ #include "peer.h" void ovpn_gso_send(struct sk_buff_head *skbs, struct ovpn_peer *peer); +bool ovpn_gso_send_tso(struct sk_buff *skb, struct ovpn_peer *peer); bool ovpn_gso_supported(struct ovpn_peer *peer); #endif /* _NET_OVPN_GSO_H_ */ diff --git a/drivers/net/ovpn/io.c b/drivers/net/ovpn/io.c index 83cdd2acfce2..884e19b87054 100644 --- a/drivers/net/ovpn/io.c +++ b/drivers/net/ovpn/io.c @@ -430,6 +430,8 @@ netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev) skb_dst_drop(skb); gso_out = gso_out && ovpn_gso_supported(peer); + if (gso_out && ovpn_gso_send_tso(skb, peer)) + return NETDEV_TX_OK; if (gso_in) { /* force software segmentation while allowing safe page-backed