From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796139720; b=Mcut4+gaqWxIwPtTnKgJxbhcLwLn1VUWCwAzegklPZ83rRcZRLnoqeTf6wK3AtuOwQXY Uo+4cQPZEVGGNVPsjAVHJT5nA6CT6AIeuLhCWbQvu0FA7wi6HzWXj9ct08XHMLl0A4McH mKREMpCTUuhnZ6Ymdee6b9QwBT8JJ4FlvIiZqgH2+FR8Yf/AjGiDeJPTVqMpICbNw9m9C uCh3dFgFwrVFpKv5qK330UHa64H7Iw2ddvQZUGaNElUM1rPNKtXxSubSDMqRVkpg0mcXu ajDL/uQ500ALqH3ymMD+qvGH7iJJx40UG1WbpHLV6VOSkF/SALI2wonfVEYmRmybxhw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796139720; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:Message-ID:Subject:From:To:Cc:Content-Type; bh=XvqYXIn86/jS2H6yoLH8z25d2mKS0HtPF3r1qMl7e5A=; b=TqL/uHCK4ivDD+U+QrNlr36aokH5i+OcoLgILbFrY+5rpvirjbDX6bV4AH+yo792z/gg 27KcmVLltAPxzaK4pUEgGmbsDd7Jk4d5vlB8CxrzYTuB6R4k9Oi1X/qmqez6y3FYV9wc/ nloEsyR9XQoHNl+fBcMRfN9/6lZoSvEpblruYG9E8guRZsLc3tvDbT+NoWo7keK9/AXXW 3aY1/Uz9HLbSPf33pfcfxSBt3NoOMHKMbQD4EbhZg/rOiiB1zb45UBQexYSZHdhlUWn6m sU64aPykJY0c13fhklkCd16c82YiUbMfh/YJCoYKupsCwmtqgDX4re5UevtF3aGyEDQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--willemb.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Iu8npcWo; arc=none smtp.remote-ip=209.85.219.70 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17BD3606A322 for ; Tue, 1 Dec 2026 15:41:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 17BD3606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--willemb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Iu8npcWo Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-92125693bc6so232145506d6.1 for ; Tue, 01 Dec 2026 07:41:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796139719; x=1796744519; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=XvqYXIn86/jS2H6yoLH8z25d2mKS0HtPF3r1qMl7e5A=; b=Iu8npcWoWKeaAiOLVEJ9V3SKA5nFReoIOYHOhmLdGZhqzFNO8ZwSkpS+CAE4Q4g+RP EKIVZLaOC/kRazN/WWp8TYRGrcMVwPSukY3qszGanLvjpFGlYkilOxPKqVPqzDk10/YH Fc6kDf50xdUyySSQ7am9No41V3PmEmMiKHJgZI4l+bZ8+hYruxQWDTKUex2R7WnI/Z/I ebXMMyTI/folop9W1f/ItsWZT+6wtPHT5CsDmcedrSSmHRvN7mVpAFD9y2Q11hicHfys qMQrxxi3HK+ItJv2+5eI22ao7SX8ijKdzHlJTDYgOEhvc8YzdfTkhtZDhrKWtGKeYOAY T2jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796139719; x=1796744519; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=XvqYXIn86/jS2H6yoLH8z25d2mKS0HtPF3r1qMl7e5A=; b=Q1wxmoyg+H52XZ5bX1xs99miitQK35L8PSDjlcpvAsQFvt02Rr4DT3DhjFgFol47mh w2pmIe+yDbxMABnZdsMuYlABcDhmsPiAbRDeZbwzzXpuR6H2AnPFrtnbzygeh03ylMRB 7gXaD3FPw8iV2TE6J5Tvwf+oEel8YTFSqS1RVDpi0B1a3v07wSjv88XNb59nwE89JaeS 4ZCtb0biSvKgvS1djenF4LnG+rb9yUCdazqx4JxMVzSO0OQ/zsUO8yNNPnT5hgatXKTS W/ifs5yxhl7vNNav1QFMAL2MrORVSKiPu5qqaYXGdzJcLfQPxWUDqOfWn2tQgrGD3wjH yjlw== X-Forwarded-Encrypted: i=1; AL+hErH4DMQ/B6fYxp7gZ23IBSfjTVLC+fKQ4/r3kZACjJRNFI8rQmIv5im10GoQcK1umFi+B7ymXMg=@vger.kernel.org X-Gm-Message-State: APuU4Z+WPagivKohCWhk9tHrdmyz7o2VHGM81fR7Y9qMLhXHytqoSwLh 3kM6NSYwv6a+uaFLgQdbJzHJbYUzmNv5RXxcNuJ/SsNivI60H1wDPYaPqDE9J758wIIfLz/7yc6 AZ1pJkwPaDw== X-Received: from qvoa16.prod.google.com ([2002:a0c:e910:0:b0:921:b816:cc0b]) (user=willemb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6214:c63:b0:921:4321:f5d6 with SMTP id 6a1803df08f44-9214321fbadmr588919456d6.34.1796139718522; Tue, 01 Dec 2026 07:41:58 -0800 (PST) Date: Tue, 01 Dec 2026 10:41:57 -0500 In-Reply-To: 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 References: <20261201015652.38202-1-willemb@google.com> Message-ID: Subject: Re: [PATCH net] ipv6: do not wait for a running gc in ip6_dst_gc() From: willemb@google.com To: David Ahern , 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 Content-Type: text/plain; charset="UTF-8"; format=flowed; delsp=yes David Ahern wrote: > 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. Are you suggesting that for stable? I would suggest that for net-next to indeed make the two stacks more alike. But for stable to avoid the behavioral change. Also, allegedly quite a few tunings set net.ipv6.route.gc_thresh explicitly, so those would still not be mitigated. > 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.