From patchwork Thu May 30 17:21:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Abeni X-Patchwork-Id: 13680633 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8FAA45BF0 for ; Thu, 30 May 2024 17:21:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717089682; cv=none; b=ViDoGkd8L/ycYYqPunlm61Olg8wciXbC7tKcm6uUIkZYRk42mem1fpn+ccOi3qzExzAuwZZBbZkPYHVKL5ISwPOYHG3t8tCBZP0ARMiFtEi4KhSeMVefaWqHhndMDuyTQIaPRHp6UQSXTJQYrlf5I5VjDDAtNpgwCxgmf4f3CPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717089682; c=relaxed/simple; bh=q7MD1ZITGxBpDMNdMo6pep4ioSjdd1BINvsplsHdRcQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ci2Dn1iwScEQv6+4Yr4V14c/fx8VxPlY3j/hePzl8lo/mvnr6L3DtK1V46cZrlHWvcCQ1uvKiD5BL81SgkpZjS7Un4hLCC9vHY4olLUDZnbzoiMD6vYVMpD9xrUJOsDdwRScT/TWoh6gYVQIatP3jurXvaQVDszZLvIhGizL1bU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=QzG0j/4f; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QzG0j/4f" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717089679; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BS30nG4qU9JzrpDo4ZZ7QONBVCca7tSabRhuQfFb0PI=; b=QzG0j/4fZQfATLDltX2VS+N0VnonAXZxPcx7fUDhlA56bOzshug/W4jHqShHXdhB0vMhiY WvhHI/XrJAaZo1xSW4Ol72cHZjHFr/4CHEWcvEyUynjHUXUhF4eZiDth0KWQfA9FFJBlYe aghNsx1D9CPusks98n1rVEcWrwII/4E= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-395-HNLyi8z8Ooyf1NB3id7wuA-1; Thu, 30 May 2024 13:21:16 -0400 X-MC-Unique: HNLyi8z8Ooyf1NB3id7wuA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8139329AA381; Thu, 30 May 2024 17:21:15 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.45.224.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67C6A4026B8; Thu, 30 May 2024 17:21:14 +0000 (UTC) From: Paolo Abeni To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , David Ahern , Jakub Kicinski Subject: [PATCH net-next 1/3] ipv6: use a new flag to indicate elevated refcount. Date: Thu, 30 May 2024 19:21:01 +0200 Message-ID: <7c3ec1f7c7e4098045d1e42961df8af11619089e.1717087015.git.pabeni@redhat.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Patchwork-Delegate: kuba@kernel.org ip6_pol_route() can return a dst entry with elevated reference count even when the caller ask for the RT6_LOOKUP_F_DST_NOREF flag. Currently the caller uses the rt_uncached list entry field to detect such scenario: the reference is elevated only for entry in the uncached list. Soon we are going to insert in the uncached list even entry held by the dst_cache(s), potentially fooling the above check and causing reference underflow. To avoid such issue, introduce and use a new field to mark the entries with refcount elevated. No functional change intended. Before: pahole -EC rt6_info /* size: 224, cachelines: 4, members: 9 */ /* sum members: 218, holes: 1, sum holes: 4 */ After: pahole: -EC rt6_info /* size: 224, cachelines: 4, members: 10 */ /* sum members: 219, holes: 1, sum holes: 4 */ Signed-off-by: Paolo Abeni --- include/net/ip6_fib.h | 3 +++ net/ipv6/route.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h index 6cb867ce4878..eb997af5523c 100644 --- a/include/net/ip6_fib.h +++ b/include/net/ip6_fib.h @@ -216,6 +216,9 @@ struct rt6_info { /* more non-fragment space at head required */ unsigned short rt6i_nfheader_len; + + /* route lookup always acquires a reference */ + bool rt6i_count_held; }; struct fib6_result { diff --git a/net/ipv6/route.c b/net/ipv6/route.c index bbc2a0dd9314..3b729ab86c55 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -2251,6 +2251,7 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, * this refcnt is always returned to the caller even * if caller sets RT6_LOOKUP_F_DST_NOREF flag. */ + rt->rt6i_count_held = true; rt6_uncached_list_add(rt); rcu_read_unlock(); @@ -2648,8 +2649,7 @@ struct dst_entry *ip6_route_output_flags(struct net *net, rcu_read_lock(); dst = ip6_route_output_flags_noref(net, sk, fl6, flags); rt6 = dst_rt6_info(dst); - /* For dst cached in uncached_list, refcnt is already taken. */ - if (list_empty(&rt6->dst.rt_uncached) && !dst_hold_safe(dst)) { + if (!rt6->rt6i_count_held && !dst_hold_safe(dst)) { dst = &net->ipv6.ip6_null_entry->dst; dst_hold(dst); } From patchwork Thu May 30 17:21:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Abeni X-Patchwork-Id: 13680634 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BE0746521 for ; Thu, 30 May 2024 17:21:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717089684; cv=none; b=QGYjH16dUZRcgCJt4RN0DsidCcULVw4uxRJoKiuMqCApIQ2JFUrNq5msN1uzrk9t/7kHy5Nt53vCz5sLrV6JV4/XlXLS1L0Y+X6Ng1bbgeNwFf4pEC1iXkV3ds1ne6nyf61nveFqaiQpDse4hxzS3EhWdN1Xg7gUUso+VCJ3a0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717089684; c=relaxed/simple; bh=82pkty1ED0gQueP3yMD4YElnZzpXECk/MJ4v+UBLHAs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MXvVY+Nb2ekvkmk0z2s/x4OUxV/WS5lBA2dkRLHJpba+1i9ZOYrUR+UheZWV/IWAK2eV91N2u8301Bd7OL2fRRPg6RaKIdzGI2M6FzNM0i9D++/t2qtQ5CdY/FzZIgP/PEzsjsU3zHU3FwsmuoAITl1JcMglE3g3cLrs8j7la+k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=M/ISREk0; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="M/ISREk0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717089682; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pU3iIHwv0Sd8cVDwSWtWQ4345lVcCCW8j/o0ndZ+2WE=; b=M/ISREk0prOaZ94ghcgQQjNsdGZE6LplwQIw6Oz09xFMtTkblhrekyHhAtd94V+JxHDr3I XgcVTXfRDElxG4nRlDVw7LQzukSJrrAnsjRy5zpuOyuQmtqU4MGfm12B8+Y/WZCH4+liYD +iZ04TUmxpCxcq6WJBwOc8Q80IotWdk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-377-6yo8pXZWNqymfwqo2jfpxA-1; Thu, 30 May 2024 13:21:17 -0400 X-MC-Unique: 6yo8pXZWNqymfwqo2jfpxA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E248C29AA386; Thu, 30 May 2024 17:21:16 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.45.224.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id C396340C5CB; Thu, 30 May 2024 17:21:15 +0000 (UTC) From: Paolo Abeni To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , David Ahern , Jakub Kicinski Subject: [PATCH net-next 2/3] ipv4: obsolete routes moved out of per cpu cache Date: Thu, 30 May 2024 19:21:02 +0200 Message-ID: <97703169844b3ae14e2e7623281546aa9533b48a.1717087015.git.pabeni@redhat.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Patchwork-Delegate: kuba@kernel.org When a new entry replaces an existing one in the next hop per cpu cache, the old entry is added to the uncached list. Soon we are going to insert in the uncached list even entries held by the dst_cache(s), the above could cause double add. Avoid the potential issue obsoleting the old entry instead. This additionally make the stack more consistent with ipv6, as the latter already calls dst_dev_put() when replacing per cpu cached entries. Signed-off-by: Paolo Abeni --- net/ipv4/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 5fd54103174f..506452f1395d 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -1473,7 +1473,7 @@ static bool rt_cache_route(struct fib_nh_common *nhc, struct rtable *rt) prev = cmpxchg(p, orig, rt); if (prev == orig) { if (orig) { - rt_add_uncached_list(orig); + dst_dev_put(&orig->dst); dst_release(&orig->dst); } } else { From patchwork Thu May 30 17:21:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Abeni X-Patchwork-Id: 13680635 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40D924655F for ; Thu, 30 May 2024 17:21:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717089686; cv=none; b=nCgOB7Q+LD2ZXq47D7gEaw067tln9sboHRgn9WFMnSEQXTqopUd3nZ+3ywEuS8j0KLONS2IUmGkeOdAidjCxrG4GYVA0E+gMyON76X9p0MwSrTvgj8eulGzSKP13n3sWcqX3yDk+9oj2iL5asBXFNCdcSGs5kZJo23QW9KWYItg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717089686; c=relaxed/simple; bh=ThNfK80vfaVwVlWDWyFllwp95oYfJ7BBClbIpG7UWR0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QumEVnnPAjwdh0zlS8qf8dO1BMWDH/eJhgWs9chjDOD1KATL31NqQxgtKeuFYnM8oH+jXOhgdQA+wqqLxv6pHpzx/5NG71cYxrXhX6yDTqPgxsrpO+BVtzEewQvYsnchShctcQzRhT7Q2ONZ9OeI/25bCgLGqufXej17AEixBJQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=SNTCkHfm; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SNTCkHfm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717089683; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TxbkADqPb1sAHUnDri1UMOEusAT7ldaPvVPWa4G6Nws=; b=SNTCkHfmIGu0rUy+l8DX8jV+EslXtTlPYVMRL0/cWi+fQgdyd1ovnaM93Q9+vUj4IR5Zzw EByJXZ6cloVlPW/wjRLdYFNJz0mf+aQC5VgVnUe+Py5fDw/Nwxa0U9kcWNnUzmIydczA0s NN6eb59GEWAzm2qjqlACSBVpmXqhNZw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-539-ZuFNwf0pMJKDu0ach7YyDQ-1; Thu, 30 May 2024 13:21:18 -0400 X-MC-Unique: ZuFNwf0pMJKDu0ach7YyDQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 58BFE101A525; Thu, 30 May 2024 17:21:18 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.45.224.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 386884026B8; Thu, 30 May 2024 17:21:17 +0000 (UTC) From: Paolo Abeni To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , David Ahern , Jakub Kicinski Subject: [PATCH net-next 3/3] dst_cache: let rt_uncached cope with dst_cache cleanup Date: Thu, 30 May 2024 19:21:03 +0200 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Patchwork-Delegate: kuba@kernel.org Eric reported that dst_cache don't cope correctly with device removal, keeping the cached dst unmodified even when the underlining device is deleted and the dst itself is not uncached. The above causes the infamous 'unregistering netdevice' hangup. Address the issue by adding each entry held by the dst_caches to the 'uncached' list, so that the dst core will cleanup the device reference at device removal time. Reported-by: Eric Dumazet Suggested-by: Eric Dumazet Fixes: 911362c70df5 ("net: add dst_cache support") Signed-off-by: Paolo Abeni --- net/core/dst_cache.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/core/dst_cache.c b/net/core/dst_cache.c index 6a0482e676d3..d1cb852d5748 100644 --- a/net/core/dst_cache.c +++ b/net/core/dst_cache.c @@ -11,6 +11,7 @@ #include #if IS_ENABLED(CONFIG_IPV6) #include +#include #endif #include @@ -28,6 +29,7 @@ static void dst_cache_per_cpu_dst_set(struct dst_cache_pcpu *dst_cache, struct dst_entry *dst, u32 cookie) { dst_release(dst_cache->dst); + if (dst) dst_hold(dst); @@ -98,6 +100,9 @@ void dst_cache_set_ip4(struct dst_cache *dst_cache, struct dst_entry *dst, idst = this_cpu_ptr(dst_cache->cache); dst_cache_per_cpu_dst_set(idst, dst, 0); + if (dst && list_empty(&dst->rt_uncached)) + rt_add_uncached_list(dst_rtable(dst)); + idst->in_saddr.s_addr = saddr; } EXPORT_SYMBOL_GPL(dst_cache_set_ip4); @@ -114,6 +119,9 @@ void dst_cache_set_ip6(struct dst_cache *dst_cache, struct dst_entry *dst, idst = this_cpu_ptr(dst_cache->cache); dst_cache_per_cpu_dst_set(idst, dst, rt6_get_cookie(dst_rt6_info(dst))); + if (dst && list_empty(&dst->rt_uncached)) + rt6_uncached_list_add(dst_rt6_info(dst)); + idst->in6_saddr = *saddr; } EXPORT_SYMBOL_GPL(dst_cache_set_ip6);