From patchwork Fri Sep 12 11:24:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Mietus X-Patchwork-Id: 4405 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:b149:b0:671:5a2c:6455 with SMTP id s9csp3741623maw; Fri, 12 Sep 2025 04:45:24 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXOpIeiqPnEjMoZVZM0NBKB0M90j0ZNAT/tdBo2rFgXg7tR0MjxAt2BRf/Adc8eKrzyWd7WsA4Hpek=@openvpn.net X-Google-Smtp-Source: AGHT+IGZUpLYIwJ7iPfp5NNBP8z9HgpeMoGb5GnKTyYdLZojJreBhUWASs5fZDBJesx6zd7xtDt2 X-Received: by 2002:a05:6830:6686:b0:746:d50f:f9c7 with SMTP id 46e09a7af769-7535269824cmr1688317a34.4.1757677524435; Fri, 12 Sep 2025 04:45:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1757677524; cv=none; d=google.com; s=arc-20240605; b=E4EYJXn+vc7IJUnDHgZ+q0HEubmtcEdc+zb/g9vwb6W5xC14xF17MzKn1voOFAAGAF juBgk5OOGlh0CxXeFvd8RVIolwnPtWvUR/EMlrNgx0I0kisnQJaGq1zCcixtb3+wyOum q/ee32SjNnoHRf+oX55NG5ImXiwpLkdIqDu8S1LoQSe8RAibXU6ENOC5wyjZ/KH6a4Sf /F0cEnqLVEtW8QBVJZhIO3Ne7eF5DtgE/ojqpr9Z0xCP8tECFzCGvdQO3GV98qabBq6F maI5GhBe/SSAlSl+NzU0nusHvz+MF9BpHvz2gG29MRqa+YN6yPdDJ7fzhjpofSYhe9Hz QeUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:cc:reply-to:from:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=tbn6gT8KVa8R5aR6/KEgtyfv849HKlYSDapYim46ulI=; fh=Nld6ED5MA/hilqlwqNF+z3bWNSgobxU8XeD15u7QoP0=; b=DiVad0KfPum8E92P5cZicHqHWQS8atPckpTX08yap067fTIMPkAB+yUvXBltifkOmm 72BL3UkO9kPQ2dGknoLdog5gWfwMkvGWpR9D4vqkBV594c+0LmAavhh9dfr1Y67fJlIW djJauP5pxctwgsf1dnL+/GILIreI1dvzQ/yrRHJUqy/a3VVZhs7ARl9sRtoiVGFSQsOP fcja8OhNI/GywyCGYPkZfuIrIFdal+IXf7ESEJL2x0Pr0j9A+jzVPNitQ+FNuaGffGlr 4jyQeZ+HIV9cofuSzPaHe4LfwbhSd6Xei8AfrSnltwP5OyZVb6aXVEkAPgO4CKIXIBWm 0faQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=PDR3miQH; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=eVZpcTST; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="i8w/9C6u"; dkim=neutral (body hash did not verify) header.i=@yahoo.com header.s=s2048 header.b="FPR/2d+a"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lists.sourceforge.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 46e09a7af769-7524b7a91dfsi950110a34.442.2025.09.12.04.45.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Sep 2025 04:45:24 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=PDR3miQH; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=eVZpcTST; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="i8w/9C6u"; dkim=neutral (body hash did not verify) header.i=@yahoo.com header.s=s2048 header.b="FPR/2d+a"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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:Cc: Reply-To:From:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Subject:MIME-Version:References:In-Reply-To: Message-ID:Date:To:Sender:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=tbn6gT8KVa8R5aR6/KEgtyfv849HKlYSDapYim46ulI=; b=PDR3miQHy1qnpJPjf/tPo1GYb5 LmAR9EMPmBkoKY9S2gBkiwgk0m/nwfK8ZJ0Kp1XRlncnJa7rVfxDGvySwhPvAnLr9p9CNeQ+khrak tMl7popGiTwCLoR7sTDncmYy31pjRY0wGTSbMLzASPvLlgjG8GxXVgBGKhekSdaTuHo4=; 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.95) (envelope-from ) id 1ux2DR-0002dU-9K; Fri, 12 Sep 2025 11:45:21 +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.95) (envelope-from ) id 1ux2DQ-0002dO-Ff for openvpn-devel@lists.sourceforge.net; Fri, 12 Sep 2025 11:45:20 +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:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=kQN6ns9dR4cKsHVgmniWSuQnXl22gTgXJWUVwRX4GN8=; b=eVZpcTST1PFrtvTl3XJMmEbrpQ zwv0jPLEOCnZCDHAdmwd3qvpcmv6AxUMeQzYml8dkd/Y79cD1/tAfDcO+8rQ5XSbzx0M+hd5juDrT RslhA96IdzVr8XgG5K7KVNGI98JUv9jZt5FQMGJnZDS8hQXyRJwKehfvzfwNKdKDA0no=; 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:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=kQN6ns9dR4cKsHVgmniWSuQnXl22gTgXJWUVwRX4GN8=; b=i8w/9C6uOdz7mCv3UVUPRUC21M 0NlZ9+CqEZythcIul1q7WxEs5IxPYnOD8IblbIKWklbFXm9S6T0HHnt6T89OGddOgwKz2FfTi/c0m HlDP1iovSas+wZhVF6gCBinZWjFeDbJfFOxgkqLJjFhVdgq+M84DEGSXdgZvl6lHYj4s=; Received: from sonic310-23.consmr.mail.ne1.yahoo.com ([66.163.186.204]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1ux2DP-0004Gf-TE for openvpn-devel@lists.sourceforge.net; Fri, 12 Sep 2025 11:45:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1757677514; bh=kQN6ns9dR4cKsHVgmniWSuQnXl22gTgXJWUVwRX4GN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=FPR/2d+ad/xs9IuTXCLBap9vzKH3vEWBZUZZ8qH/201JLrkmHzsAsI+4FLSkLuTRJLQFYlK+GyWgKM10uID8cppUrCIn9ycMASzCNn43+HLFctdaBkDf090BqrIzA/vDvbL4PfGyplCKtoUHL6efnzMOJlo4p0PT1VtHkCR+aY3R8gW6E2+MrfronLv9tSx6/PptJc7qRYyRRg4T2Bl8zXAiIvx/uZjpic1gLYRHduC+lENe2/Mz5GgPIEiZ89bZnyVl0Ji+Cu/cMRD3ZixZS/bpAv4CqgPtqpfU/Yz3YzwPDCx0iKvqOtU90kVi3UVTMNPHUx18e5lMd9w7c7G5bg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1757677514; bh=zxnBuYPZa9+/hd5HznF31Ffq8AD/IJjZPsOjr7aV6jG=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=ESH40R3xzO/QBRfaU8jE91/LF69a8IRXtMeRm7D1g8SE7tF4a0Tj5rPIic6c4T+4abQ/x8eFHJqEewtLAvsEPMjqy1CPItb9Ag2ZCCzE3BfPoz2+NzLbRhEKO0soKHuV4ZJzWR5f6tEhgNhj3N9pVOC3No+lUF3xHhuMBkoHKh73nGSyvny6Ajnef1hiWUciyZuraT+aAhEVKICpwUnMbPQ8G2XXmPth4kiIctavVIlqfqzUrrfz6A2jH/mN/eHZ0OBz4PWsrzfL/KXq8xJoxuMEJA1nsOUmEIV2LYOo0hrs52Oeqyf3SVr+zApIRVH3ePw/fbgqAZYCzW8dTe3+3g== X-YMail-OSG: nIivqLoVM1lOivMbtDPvp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9cK bTGrrC3Cl0PugKox0niQQ8FA5Sg9qsx8p7N1VZ12HOXNjVw-- X-Sonic-MF: X-Sonic-ID: c405784a-adb1-4de2-9ec4-31216b83b70e Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.ne1.yahoo.com with HTTP; Fri, 12 Sep 2025 11:45:14 +0000 Received: by hermes--production-ir2-7d8c9489f-pnggd (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 93cda13a9625b3ea865113cded111022; Fri, 12 Sep 2025 11:24:49 +0000 (UTC) To: netdev@vger.kernel.org, antonio@openvpn.net, kuba@kernel.org Date: Fri, 12 Sep 2025 13:24:18 +0200 Message-ID: <20250912112420.4394-2-mmietus97@yahoo.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250912112420.4394-1-mmietus97@yahoo.com> References: <20250912112420.4394-1-mmietus97@yahoo.com> MIME-Version: 1.0 Content-Length: 5830 X-Spam-Score: 0.1 (/) 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: Implement RCU variants for existing dst_cache helpers interacting with dst_entry. The new helpers avoid referencing the dst_entry, sparing some unnecessary atomic operations. They should only be used in flows that are already guaranteed to be inside a RCU read-side critical context [...] Content analysis details: (0.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_DNSWL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to DNSWL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#DnsBlocklists-dnsbl-block for more information. [66.163.186.204 listed in list.dnswl.org] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [mmietus97(at)yahoo.com] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [mmietus97(at)yahoo.com] 0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [66.163.186.204 listed in wl.mailspike.net] X-Headers-End: 1ux2DP-0004Gf-TE Subject: [Openvpn-devel] [PATCH net-next v2 1/3] net: dst_cache: implement RCU variants for dst_cache helpers 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: , X-Patchwork-Original-From: Marek Mietus via Openvpn-devel From: Marek Mietus Reply-To: Marek Mietus Cc: openvpn-devel@lists.sourceforge.net Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1843058467904819874?= X-GMAIL-MSGID: =?utf-8?q?1843058467904819874?= Implement RCU variants for existing dst_cache helpers interacting with dst_entry. The new helpers avoid referencing the dst_entry, sparing some unnecessary atomic operations. They should only be used in flows that are already guaranteed to be inside a RCU read-side critical context. Signed-off-by: Marek Mietus --- include/net/dst_cache.h | 26 ++++++++++++++ net/core/dst_cache.c | 78 +++++++++++++++++++++++++++++++++++------ 2 files changed, 94 insertions(+), 10 deletions(-) diff --git a/include/net/dst_cache.h b/include/net/dst_cache.h index 1961699598e2..d3bf616a6e6f 100644 --- a/include/net/dst_cache.h +++ b/include/net/dst_cache.h @@ -32,6 +32,21 @@ struct dst_entry *dst_cache_get(struct dst_cache *dst_cache); */ struct rtable *dst_cache_get_ip4(struct dst_cache *dst_cache, __be32 *saddr); +/** + * dst_cache_get_ip4_rcu - lookup cache and ipv4 source under RCU + * @dst_cache: the cache + * @saddr: return value for the retrieved source address + * + * Perform cache lookup and fetch ipv4 source without taking a + * reference on the dst. + * Must be called with local BH disabled, and within an rcu read side + * critical section. + * + * Return: Pointer to retrieved rtable if cache is initialized and + * cached dst is valid, NULL otherwise. + */ +struct rtable *dst_cache_get_ip4_rcu(struct dst_cache *dst_cache, __be32 *saddr); + /** * dst_cache_set_ip4 - store the ipv4 dst into the cache * @dst_cache: the cache @@ -43,6 +58,17 @@ struct rtable *dst_cache_get_ip4(struct dst_cache *dst_cache, __be32 *saddr); void dst_cache_set_ip4(struct dst_cache *dst_cache, struct dst_entry *dst, __be32 saddr); +/** + * dst_cache_steal_ip4 - store the ipv4 dst into the cache and steal its + * reference + * @dst_cache: the cache + * @dst: the entry to be cached whose reference will be stolen + * @saddr: the source address to be stored inside the cache + * + * local BH must be disabled + */ +void dst_cache_steal_ip4(struct dst_cache *dst_cache, struct dst_entry *dst, + __be32 saddr); #if IS_ENABLED(CONFIG_IPV6) /** diff --git a/net/core/dst_cache.c b/net/core/dst_cache.c index 9ab4902324e1..f1e3992d8171 100644 --- a/net/core/dst_cache.c +++ b/net/core/dst_cache.c @@ -25,20 +25,30 @@ struct dst_cache_pcpu { }; }; -static void dst_cache_per_cpu_dst_set(struct dst_cache_pcpu *dst_cache, - struct dst_entry *dst, u32 cookie) +static void __dst_cache_per_cpu_dst_set(struct dst_cache_pcpu *dst_cache, + struct dst_entry *dst, u32 cookie) { DEBUG_NET_WARN_ON_ONCE(!in_softirq()); dst_release(dst_cache->dst); - if (dst) - dst_hold(dst); dst_cache->cookie = cookie; dst_cache->dst = dst; } -static struct dst_entry *dst_cache_per_cpu_get(struct dst_cache *dst_cache, - struct dst_cache_pcpu *idst) +static void dst_cache_per_cpu_dst_set(struct dst_cache_pcpu *dst_cache, + struct dst_entry *dst, u32 cookie) +{ + if (dst == dst_cache->dst && cookie == dst_cache->cookie) + return; + + if (dst) + dst_hold(dst); + + __dst_cache_per_cpu_dst_set(dst_cache, dst, cookie); +} + +static struct dst_entry *__dst_cache_per_cpu_get(struct dst_cache *dst_cache, + struct dst_cache_pcpu *idst) { struct dst_entry *dst; @@ -47,14 +57,10 @@ static struct dst_entry *dst_cache_per_cpu_get(struct dst_cache *dst_cache, if (!dst) goto fail; - /* the cache already hold a dst reference; it can't go away */ - dst_hold(dst); - if (unlikely(!time_after(idst->refresh_ts, READ_ONCE(dst_cache->reset_ts)) || (READ_ONCE(dst->obsolete) && !dst->ops->check(dst, idst->cookie)))) { dst_cache_per_cpu_dst_set(idst, NULL, 0); - dst_release(dst); goto fail; } return dst; @@ -64,6 +70,18 @@ static struct dst_entry *dst_cache_per_cpu_get(struct dst_cache *dst_cache, return NULL; } +static struct dst_entry *dst_cache_per_cpu_get(struct dst_cache *dst_cache, + struct dst_cache_pcpu *idst) +{ + struct dst_entry *dst; + + dst = __dst_cache_per_cpu_get(dst_cache, idst); + if (dst) + /* the cache already hold a dst reference; it can't go away */ + dst_hold(dst); + return dst; +} + struct dst_entry *dst_cache_get(struct dst_cache *dst_cache) { struct dst_entry *dst; @@ -100,6 +118,28 @@ struct rtable *dst_cache_get_ip4(struct dst_cache *dst_cache, __be32 *saddr) } EXPORT_SYMBOL_GPL(dst_cache_get_ip4); +struct rtable *dst_cache_get_ip4_rcu(struct dst_cache *dst_cache, __be32 *saddr) +{ + struct dst_cache_pcpu *idst; + struct dst_entry *dst; + + if (!dst_cache->cache) + return NULL; + + local_lock_nested_bh(&dst_cache->cache->bh_lock); + idst = this_cpu_ptr(dst_cache->cache); + dst = __dst_cache_per_cpu_get(dst_cache, idst); + if (!dst) { + local_unlock_nested_bh(&dst_cache->cache->bh_lock); + return NULL; + } + + *saddr = idst->in_saddr.s_addr; + local_unlock_nested_bh(&dst_cache->cache->bh_lock); + return dst_rtable(dst); +} +EXPORT_SYMBOL_GPL(dst_cache_get_ip4_rcu); + void dst_cache_set_ip4(struct dst_cache *dst_cache, struct dst_entry *dst, __be32 saddr) { @@ -116,6 +156,24 @@ void dst_cache_set_ip4(struct dst_cache *dst_cache, struct dst_entry *dst, } EXPORT_SYMBOL_GPL(dst_cache_set_ip4); +void dst_cache_steal_ip4(struct dst_cache *dst_cache, struct dst_entry *dst, + __be32 saddr) +{ + struct dst_cache_pcpu *idst; + + if (!dst_cache->cache) { + dst_release(dst); + return; + } + + local_lock_nested_bh(&dst_cache->cache->bh_lock); + idst = this_cpu_ptr(dst_cache->cache); + __dst_cache_per_cpu_dst_set(idst, dst, 0); + idst->in_saddr.s_addr = saddr; + local_unlock_nested_bh(&dst_cache->cache->bh_lock); +} +EXPORT_SYMBOL_GPL(dst_cache_steal_ip4); + #if IS_ENABLED(CONFIG_IPV6) void dst_cache_set_ip6(struct dst_cache *dst_cache, struct dst_entry *dst, const struct in6_addr *saddr)