From patchwork Wed Nov 18 17:30:35 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5741 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:b1c3:10b0:11b:d6c:f273 with SMTP id i3-n1csp477918laq; Wed, 18 Nov 2026 09:31:04 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErGW6pfRBNJ9xtuogNXRHcHNgjoCmGbMsUfTTms1mXCMpk3+P9gBEa5x8Sa3ATV77eWCHPnnHok9kyE=@openvpn.net X-Received: by 2002:a05:6820:a504:20b0:71a:de33:9236 with SMTP id 006d021491bc7-71b1878713cmr1801701eaf.87.1795023064096; Wed, 18 Nov 2026 09:31:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795023064; cv=none; d=google.com; s=arc-20260327; b=a8kDHIg0oyWDiOzgpXSxLmqHY0j6v7V7q6/PMgNSyjkH8InPFJZ6IuD08yhoX9pm8+ JMzoGD9B2fD81Eq+xAejQ7MK30QUNh8NPdy07lNLOg3+Co4W3uPAR9rIZOyML5kFkYhX p4j6BaeuFmzly6Gi/G/YjME/2PizmbJR3K0T2RkdHyMvMRn7ZFPOgDV+DnCdg6nd8rdu 8itoP2yjR8eh7wx+dp0qGF3uwlA2/bjIRbqF+rn7Gkc1WdPGDtdoeMUzG07VPNi94659 mTKO3TVVtjWAFZhWpBl1XGB+PC5YS/VWfwT0u8PPDBiWrPK97lOclUMjmvvtvokCg7cp yIoQ== 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:message-id:date:to:from:dkim-signature:dkim-signature :dkim-signature:dkim-signature; bh=8clUQSg44KDaFQaJVlTZ8iOYP7MVaOY9XT6kIlO+zyM=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=okdg4txaofuFnk+VkBHItyRcsDGODxZKQ5hDVKPo7omUW1jlV8pj08SEzwXrBJDF3O TiXW1cZxT907N7YXlBW3izYAgCJxEH4lb0QeizxNSRTKocpyTPNqyYXxVXsORvNWdWzD HVYsbjtsRy/BenZsb3eNiZjqBnWl7sVqhwR7VQmGaYSwQHIM5xfWnJgRJwo4nod4nY5g kWZqIqaqk8oGtk8qkBHn8Aseaf+YiiFiBoUYqE+Cl67Z0cgu2mDxtctJruxofRNZxehF hvVzl+73LFZ4YvYcTHWPbjgZ+xx72NgMIq+7RGcj2CLk0wY+6dOBmQ2h3ToWclrCaCZk 1rKQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b="CPoF/E78"; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=FJHvK5hB; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=mY2sCwkv; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=pN7wDLqe; 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 006d021491bc7-71b1971233dsi4145024eaf.72.2026.11.18.09.31.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Nov 2026 09:31:04 -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="CPoF/E78"; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=FJHvK5hB; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=mY2sCwkv; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=pN7wDLqe; 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: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:In-Reply-To:References:List-Unsubscribe-Post:List-Owner; bh=8clUQSg44KDaFQaJVlTZ8iOYP7MVaOY9XT6kIlO+zyM=; b=CPoF/E78L94LJ4cRZc8C8rX5MJ VpJcEiLumDvPZTCAb02HfR1RF6WOUThw8BjDzoAbB5SMB392KknApjkAUQ72ceFkGpm0MxuITa6e5 vt43qqO4h/WTOSgnlRmAx+MktJFxByi9zvOirXWTyJGH1W+NKVTAsA3uBrln59F1+UlA=; 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 1xTjUs-000000008JU-2n4z; Wed, 18 Nov 2026 17:31:02 +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 1xTjUq-000000008JE-1HMP for openvpn-devel@lists.sourceforge.net; Wed, 18 Nov 2026 17:31:01 +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: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:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZuRQj2rWA8S1uP/+eJUqX0cLvA0GHyR6Y2SXilkbGnU=; b=FJHvK5hBxpeXHSvcORcQOdoyk0 RSJzpHGJocE2XeeXPYxDux/TvaiFvF4FUejhk3upNm1adfIeVM72OWVDGHawa5j7CHe1KI2xKYdrg 12a8ZzmcbZwqCiQfvSmbw5kEwIboqY0xxyU1e45EicUOLsuX39CMBVk/AsMtScMgLs0I=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version: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:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZuRQj2rWA8S1uP/+eJUqX0cLvA0GHyR6Y2SXilkbGnU=; b=mY2sCwkv7CEA6AVtFPysUpPHbd iKyUQJh+u54+qONlj4PC+dw9Uyc07Ht6GGi9EDKDxrks+NRgOgk2LbWUQttWQ4W5/khMS6YGOr+MP 8UbkplW5cIrZCSlZaFOQUjiwmo2XzGmAUw05eEI7KYqzy1CPcSZx2g5Ni2V0mCFHHQzs=; Received: from mout-b-112.mailbox.org ([195.10.208.42]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xTjUl-000000007PK-490Y for openvpn-devel@lists.sourceforge.net; Wed, 18 Nov 2026 17:31:00 +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 4jV7sy3fT1z5xCw for ; Wed, 18 Nov 2026 18:30:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1795023046; 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; bh=ZuRQj2rWA8S1uP/+eJUqX0cLvA0GHyR6Y2SXilkbGnU=; b=pN7wDLqeRBv7qWDvsIW8NsqxpdvwWQox8qXoik4rj22ce/K6ycKYClZ3GG+zR/Wc+bYYqs 4AhsKwyC5PHxHOQZMM4rEJMrORoNJEL8Q5r56vBvXiWc1ddUHsu30zhWcTaHZSO3Lmf0uX 5i3wjNbEd14yML4OsuURin0oqS+02uEDMVurhoHx4VQTGWMkJxbPFxPF9FYqHJGIed0NSr nY1p7HamZ0Yqa04KU7hfyxEN06khuT0Y4NKxYQTJDNkjxbduLCILJW5jXeYfTFEOUGPHh/ 63egaj488pwwedZ6zGCt6CipgPJOyXb4T8gNT/iONHF68a6s8P7E850w6Mceow== 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: Wed, 18 Nov 2026 18:30:35 +0100 Message-ID: X-Mailer: git-send-email 2.56.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jV7sy3fT1z5xCw 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: ovpn_peer_endpoints_update runs for every authenticated UDP data packet and takes peer->lock just to compare the packet addresses with the peer's bind, although they almost always match. Bind objects are immutable and replaced under RCU, so check for a match under RCU first and take the lock only when the remote or local endpoint has changed. The locked path rereads the current bind, [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-Headers-End: 1xTjUl-000000007PK-490Y Subject: [Openvpn-devel] [PATCH ovpn net-next] ovpn: avoid endpoint lock when the bind matches 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: 1882218104791751754 X-GMAIL-MSGID: 1882218104791751754 ovpn_peer_endpoints_update runs for every authenticated UDP data packet and takes peer->lock just to compare the packet addresses with the peer's bind, although they almost always match. Bind objects are immutable and replaced under RCU, so check for a match under RCU first and take the lock only when the remote or local endpoint has changed. The locked path rereads the current bind, so concurrent updates are still handled there. Signed-off-by: Ralf Lici --- drivers/net/ovpn/peer.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) base-commit: 7ccc5e05043b1bb84326b19a2b05938d8f7a2ae6 diff --git a/drivers/net/ovpn/peer.c b/drivers/net/ovpn/peer.c index 2067825bb5b6..972ee4ba0aec 100644 --- a/drivers/net/ovpn/peer.c +++ b/drivers/net/ovpn/peer.c @@ -193,10 +193,29 @@ int ovpn_peer_reset_sockaddr(struct ovpn_peer *peer, static void __ovpn_peer_hash_transp_addr(struct ovpn_peer *peer, const struct ovpn_bind *bind); +static bool ovpn_peer_endpoints_match(const struct ovpn_bind *bind, + const struct sk_buff *skb) +{ + if (!bind || !ovpn_bind_skb_src_match(bind, skb)) + return false; + + switch (skb->protocol) { + case htons(ETH_P_IP): + return bind->local.ipv4.s_addr == ip_hdr(skb)->daddr; + case htons(ETH_P_IPV6): + return ipv6_addr_equal(&bind->local.ipv6, + &ipv6_hdr(skb)->daddr); + default: + return true; + } +} + /** * ovpn_peer_endpoints_update - update remote or local endpoint for peer * @peer: peer to update the remote endpoint for * @skb: incoming packet to retrieve the source/destination address from + * + * Context: called with rcu_read_lock held. */ void ovpn_peer_endpoints_update(struct ovpn_peer *peer, struct sk_buff *skb) { @@ -207,6 +226,13 @@ void ovpn_peer_endpoints_update(struct ovpn_peer *peer, struct sk_buff *skb) struct ovpn_bind *bind; bool floated = false; + /* bind objects are immutable and replaced under RCU and the locked + * path rechecks the current object before changing an endpoint + */ + bind = rcu_dereference(peer->bind); + if (likely(ovpn_peer_endpoints_match(bind, skb))) + return; + spin_lock_bh(&peer->lock); bind = rcu_dereference_protected(peer->bind, lockdep_is_held(&peer->lock));