From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796092468; b=yMpA06AurobvjBhHicpqsZEbqAK+cG0LJROWP8HfTgYOBmqAcQF+TiDiqXTMX1bCGzXd mPk2TIBn+XD6xwDYY+Tc8XTTZNNp1LamAHkz/V0XUIe0ohRHbx/zeYUfY9bJYljDUznYv 4APZw3BhcumhRpmRAHxvXrOlKFPEhQ2lsBemRqNf93v7Hvw4RBKha1C8vwXDBxkflOxbM qrIFg3zA/3lMjRxkOhIWunTNrHXpc8nM95oGdEnf6wx9/I17JYOl2rDAWxhCU7ccdyWy/ q1+Tnw6882XBJyDZ4n8HelVqdqQeZEMMF0/xVflt1OLMSSxLzvF4vgrZxAFj7/5NWOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796092468; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent: Subject:Content-Language:To:Cc:References:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=k2MG6X9JN2t0GIFfz+bPz0ObWjkJP75ts/6FLNUVBEg=; b=muwPjaG2i1gVmpTycOVXH1z+Gmo9r88Eqe3zHNXTyxoLATHtc9Q6QauSEPl1JA9J+AjC 6fZBrRlJ45y5RClRlbAbfNspzftxT18p+GGZBQLcMD/feE/seJrWNxXDONdprvoYPOutQ M4fMDpq/uRM4P9xdgs5YgwRzhL6bNqerW6bdW4/yGsOKc74eJ6rwCZUcUVsLGa+5xinKx Gt4TFWJ5PEH7XLxHIK44JJS22fDmW4hFikowlGyy+k9AnCk/JpyVh01HS4mTAcd0OYIw/ IrwVpdUKgXLua6jLtd+MUd6BgVWfvP+9S+pwl3dW/yiX0+MPxI7Qz1Ve/vzhk5d/Wuw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=nIBS8wbO; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DAC8606A31A; Tue, 1 Dec 2026 02:34:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=nIBS8wbO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AFC91F000C1; Tue, 1 Dec 2026 02:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796092467; bh=k2MG6X9JN2t0GIFfz+bPz0ObWjkJP75ts/6FLNUVBEg=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=nIBS8wbO0XIEgGHMfYxepubQNirlwptLlK2xnIV/hx/WOJItRY+zmRJBXwDB1VT6R tMOjA3c/rZ7Np+D9qMbeO0KHtcFt0wkTZzkcPfzvJyBlYJNsT3WD1nbrZCvkHqmFBK uqNSX+/Mk9HGqOf5Uj7qbJ4b29LQyJ+dTEgXAb2ndX1M/SM8Xe+Nmwy/DuJkx0Ssbr vUEf8Zw6/x1fUTIaU5EWPXUmpMeNbZn0Nn7wyn6ibJgucje27t/HNeBwzOwaf/SIkp l8ash0VlzG2xL3PcwxHA+wE3nOecntW5x/DtirXbkVPVvP3QzpBnOljCoHr0BY8K6P lwc8qeiKRU5bQ== Message-ID: Date: Mon, 30 Nov 2026 19:34:26 -0700 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net] ipv6: do not wait for a running gc in ip6_dst_gc() Content-Language: en-US To: Willem de Bruijn , netdev@vger.kernel.org Cc: Ido Schimmel , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Chris Mason , stable@vger.kernel.org References: <20261201015652.38202-1-willemb@google.com> From: David Ahern In-Reply-To: <20261201015652.38202-1-willemb@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 11/30/26 6:55 PM, Willem de Bruijn wrote: > From: Chris Mason > > With more than net.ipv6.route.gc_thresh cached routes, CPUs that > allocate an IPv6 route while the route garbage collector runs can stall > for as many gc runs as there are CPUs waiting, with bottom halves > disabled. > > While more than net.ipv6.route.gc_thresh cached routes exist, > dst_alloc() calls ip6_dst_gc(), which starts a gc run, fib6_run_gc(), > unless the last one ended less than gc_min_interval ago. A gc run holds > fib6_gc_lock with bottom halves disabled, and sets ip6_rt_last_gc, the > time at which the last gc run ended, only at its end. But ip6_dst_gc() > tests ip6_rt_last_gc before it takes the lock, so each CPU that passes > the test during a gc run spins for the lock and then starts a gc run of > its own. > > Commit 2ac3ac8f86f2 ("ipv6: prevent fib6_run_gc() contention") in v3.11 > fixed this contention, which it reported as soft lockups on a > high-traffic router with many processors, by having ip6_dst_gc() only > try the lock unless the number of entries exceeded max_size. Commit > 14956643550f ("ipv6: slight optimization in ip6_dst_gc") in v3.16 made > ip6_dst_gc() wait for the lock again in all cases, on the premise that > the number of entries always exceeds max_size at that point. That does > not hold once gc_min_interval has passed since the last gc run. > > The fix used here is to give ip6_dst_gc() a variant of fib6_run_gc(), > fib6_try_run_gc(), which returns at once if another CPU holds > fib6_gc_lock, and repeats the test of ip6_rt_last_gc under the lock. > > Found and fixed with an LLM; reproduced on an unmodified kernel with an > LLM-generated reproducer in a 16-CPU KVM guest. Verified with the > reproducer and IPv6 route selftests (fib_tests.sh, fib_nexthops.sh). > > Fixes: 14956643550f ("ipv6: slight optimization in ip6_dst_gc") > Cc: # 6.18.x: 12eddc685744: ipv6: annotate data-races around sysctl.ip6_rt_gc_interval > Cc: # 6.18.x > Signed-off-by: Chris Mason > [willemb: add lockdep_assert_held() and WRITE_ONCE() on ip6_rt_last_gc, > expand commit message] > Signed-off-by: Willem de Bruijn > --- > include/net/ip6_fib.h | 1 + > net/ipv6/ip6_fib.c | 44 +++++++++++++++++++++++++++++++++++-------- > net/ipv6/route.c | 4 +++- > 3 files changed, 40 insertions(+), 9 deletions(-) > ipv4 has gc_thresh set to ~0 in its dst_ops. At this point seems like ipv6 should be able to move in that direction. Double checking my thinking with claude (sonnet-5.5): IPv6 already bounds its dst cache the way IPv4 does, so the only code change is setting the gc_thresh default to ~0 (like IPv4 does). How IPv4 limits growth (net/ipv4/route.c) - There is no .gc callback and ipv4_dst_ops.gc_thresh = ~0, so nothing is enforced by dst count. - Cached exceptions (fnhe) sit in hash buckets. On insert, fnhe_remove_oldest() evicts entries once a bucket's depth passes a randomized FNHE_RECLAIM_DEPTH. - Everything else is bounded by the number of nexthops. IPv6 already does the same - __rt6_insert_exception() caps each bucket at a randomized FIB6_MAX_DEPTH and evicts with rt6_exception_remove_oldest(). - Per-cpu routes are allocated DST_NOCOUNT and are bounded by nexthops. - max_size is already INT_MAX. The exception count per FIB entry is bounded by bucket depth times FIB6_GC_BUCKET_SIZE, which I didn't check. The bound could still be large with many nexthops, and the same is true for IPv4. ### IPv6 has a timer that calls fib6_run_gc every gc_interval seconds to control for example the RAs.