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=1796146858; b=l9GuAmBMzEzpmgL/Ojk55RHbMDgzKj9WQVRlWTJ8BzGbej+W+B/Ed7D1NNp5xB7tbzkd wo8Exo9+iUY8thQ4VvQcEsNBwM/ni5NS3VKgMkCortDC2zwi5GC26Gd27ErffziH1alMi xfz8db4WMKxQF8BAiJQL0jOyirhOUeR5Jd6nGAZkCDceVyhFRiQLosEAqVu7H65ZCAk/1 XAYmXUeygyFvoUFrB7tPrMstLfTGkRoCrwed3FwS9TdLZtOtUW6Ic4XRKVQv1Ylx4XuQD omL90h2n4Ko3AU/2IALRHNzCMhcZgSb58XjMaLKt1bBQU9x/LJfFUSaoPz+M8162lZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796146858; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=tmgJbiib1733cChyg+mnRX5/0bst+si1D86Nhl6hA/Q=; b=TopiO8xYDlKJS3ff1KNhBa0LXvD4YTuV/nxYiyg+lQ5XnO0ghTVFqMwvF7+QB/uIpks5 Pmp8XvhAfZ/Th6B30zuIT8zmeDmwnxpC5xeDcg5aywtm1UQVX+IPnlTDuMNnodDz0vTuI Y9hMRDAUqyfHFTkIAtTCh/5FHzryvkjDvsrH5GNEFGM7x4Jis4xCHrkJ19j55r9U4R6rZ RnQCdEkd1r2u/SdW5VQglxUEuLOr30u92oMqfbwsgoHxvInLapIThDyGClawpN7lVD0u0 H16r/FF3hiARJS0vhZQqbLMMZYWpSCgyVxAhL6pKU/6pvxGam9kUkM94FVIXDFhHe3g== 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=bR6U3KAL; 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 4C6E7606A329 for ; Tue, 1 Dec 2026 17:40:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bR6U3KAL Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E7171F0089A; Tue, 1 Dec 2026 17:40:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796146858; bh=tmgJbiib1733cChyg+mnRX5/0bst+si1D86Nhl6hA/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bR6U3KALNxyzb9IMbL0d6Jg1yKVymrtd4S31jHzy+2wMuAa119fUmaw7Mrff5aeuU JN2NuWKDlpLbzmOoHgY2fNOu33pH8YeiIwFsmv1v8cEiZEJUesIFWcE9J/0s0JVYbN N6b6q/A2XMweds6aXIJMFrIBfagMLnl/A7/GIvz+T5PcZd0RFquKYf7TC0x8Dws6Y1 LlpbfkzE0jEoMnF+7Sah/njGuqq0hO/+KT7gpfzn5gdDhF4nMKHEVMPfqpsYU4rX40 VajgmTCsX7NVyXhbbG9XZ71M1/lCDdZngv7lUaAWN6JjycFueu/FqaJz8jS/OzaGN3 HHFYNLF/SUx/g== From: David Ahern To: netdev@vger.kernel.org Cc: dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, ralf@mandelbit.com, ja@ssi.bg, David Ahern Subject: [PATCH net-next v3 01/13] ipv6: allocate the exception entry before removing the one it replaces Date: Tue, 1 Dec 2026 10:40:02 -0700 Message-ID: <20261201174021.7211-2-dsahern@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261201174021.7211-1-dsahern@kernel.org> References: <20261201174021.7211-1-dsahern@kernel.org> 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 Content-Transfer-Encoding: 8bit From: David Ahern rt6_insert_exception() unlinks the existing exception for a destination before it allocates, with GFP_ATOMIC, the table entry for its replacement. If that allocation fails, what was learned (a reduced PMTU or a redirect gateway) is already gone and the caller gets -ENOMEM, so traffic falls back to the route's own MTU and gateway. Allocate the entry first. If that fails nothing has been touched and the exception stays as it was. Fixes: 35732d01fe31 ("ipv6: introduce a hash table to store dst cache") Signed-off-by: David Ahern --- net/ipv6/route.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index df843178e5ec..c41c5ca23fe1 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -1721,8 +1721,8 @@ static int rt6_insert_exception(struct rt6_info *nrt, struct net *net = dev_net(nrt->dst.dev); struct rt6_exception_bucket *bucket; struct fib6_info *f6i = res->f6i; + struct rt6_exception *rt6_ex, *new_ex; struct in6_addr *src_key = NULL; - struct rt6_exception *rt6_ex; struct fib6_nh *nh = res->nh; int max_depth; int err = 0; @@ -1765,19 +1765,24 @@ static int rt6_insert_exception(struct rt6_info *nrt, goto out; } + /* Allocate the new entry before the one it replaces is touched, so + * that running out of memory leaves what was learned in place. + */ + new_ex = kzalloc_obj(*new_ex, GFP_ATOMIC); + if (!new_ex) { + err = -ENOMEM; + goto out; + } + + new_ex->rt6i = nrt; + new_ex->stamp = jiffies; + rt6_ex = __rt6_find_exception_spinlock(&bucket, &nrt->rt6i_dst.addr, src_key); if (rt6_ex) rt6_remove_exception(bucket, rt6_ex); - rt6_ex = kzalloc_obj(*rt6_ex, GFP_ATOMIC); - if (!rt6_ex) { - err = -ENOMEM; - goto out; - } - rt6_ex->rt6i = nrt; - rt6_ex->stamp = jiffies; - hlist_add_head_rcu(&rt6_ex->hlist, &bucket->chain); + hlist_add_head_rcu(&new_ex->hlist, &bucket->chain); bucket->depth++; rt6_exception_net(nrt)->ipv6.rt6_stats->fib_rt_cache++; -- 2.54.0 (Apple Git-157)