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=1796384689; b=g9NsC2YPDb3Z4L+M0uPOb9hFuuS9CLssOyl+zw5Jg3tRTjptFDTmssrjEITAmkYcxe9A a99bp6U8eVhup/RUaVgt4hlVchjB8kPET0U3uTOs3cuBOYXf0J6LH6a/lZPuuzLt5rafC EPpdLBY69NiGWNSc6N690q+jwtIWhtbdtBSN0TEyDEJL9MMkV9qrV3syus+0fOly57FYq fgj2/DMQsLTLFMRwc8hMW1vrNmm04uZITnYgg9mmQPfm+S/SJZK7CUv0eVmp2bL05zKDs PyY1zEOvwEtTmWTWGJa3UdvpXAbe5t5GvaR/qLAcGnqZrpk4B6jn9BQ4wly+VGTlHXA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384689; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=veFg3gu/wyEit/JJxvmVaQYxfgcrEf9WbdwUd8Ikk1E=; b=C5dPGFZO5knCIR7e/viakZjTTk0648N3uy29GCYksQaIBOzwEmBs/my/RmYHzoJNsJME oMW+0I5kJJEOI15fQFcXIcQzVHm7oBpCslBmNzdC7kyfHK/tPVz0UOsV0gT009UWLTUNn EABamTwYRkj1vPpIN0A7fkJsePeQefm/Jp1JVgX3w3iRxqSH9Nx/R5j9L8szXT9PfbDa7 B5v1XfgyVyj4Xua/pkjTt4oB95kXVcE7l9LuuBP4vhAlr/F+7S4XJXv7+hqgldDU77RsI yxrmZSejs0BuOFPbgBxpBX5XpzOh8B03LhQGHvZGfiYM+C+/KLX/jukihCwKAYGG52A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=hu+Wi374; 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 73750606A32C; Fri, 4 Dec 2026 11:44:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=hu+Wi374 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E14ED1F00931; Fri, 4 Dec 2026 11:44:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384689; bh=veFg3gu/wyEit/JJxvmVaQYxfgcrEf9WbdwUd8Ikk1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hu+Wi374OwwyNJzzYF+R1b5GyOR+dgci+MjB3wZOKREV00T2p2nauoqe7wN7MezM4 RZQCVfBseoByZuCGnrBEk6rCqzNYdNIjufgSsFmrrU6fu4/rG9y7TY/cX5vluvMwKi O7sGjGDmtuM4VX3SFZiPKcMn/cbt0diPoyG2Umcc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Omar Ramadan , Simon Horman , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6 0252/1167] amt: tear down every amt device on an unregistering lower Date: Fri, 4 Dec 2026 18:54:39 +0900 Message-ID: <20261204100708.629511464@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@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 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Omar Ramadan [ Upstream commit 7262e999ebec0a10ecc97ba4739f12255b7c6da8 ] amt_device_event() acts only on the amt device that amt_lookup_upper_dev() returns, which is the first amt device bound to the event's lower. Several amt devices can share one lower, for example two gateways. On NETDEV_UNREGISTER, only the first device is unlinked and unregistered. The others stay upper-linked to the lower, and unregister_netdevice_many_notify() warns, because the notifier chain must detach every upper device. They also still hold a reference on the lower, so each is torn down only when netdev_wait_allrefs_any(), called from netdev_run_todo(), rebroadcasts NETDEV_UNREGISTER. By then the lower's sysfs directory is gone, so unlinking it trips a kernfs WARN, and unregistering it from inside the rebroadcast trips the WARN in __rtnl_unlock(). On NETDEV_CHANGEMTU, only the first device is resized. Walk every amt device in the lower's netns and act on each one bound to the lower. On NETDEV_UNREGISTER, queue them all and unregister them in one batch. amt_dellink() unlinks each device but leaves it on the netns device list until unregister_netdevice_many(), so the walk stays valid under RTNL. To reproduce: ip link add lower0 type dummy ip link add amtg1 type amt mode gateway local 192.0.2.1 \ discovery 192.0.2.2 dev lower0 ip link add amtg2 type amt mode gateway local 192.0.2.1 \ discovery 192.0.2.2 dev lower0 ip link del lower0 Without this patch, the last command logs: WARNING: net/core/dev.c:12773 at unregister_netdevice_many_notify+0x13e5/0x1940, CPU#3: ip/216 kernfs: can not remove 'upper_amtg2', no directory WARNING: fs/kernfs/dir.c:1784 at kernfs_remove_by_name_ns+0xc9/0xd0, CPU#0: ip/216 WARNING: net/core/rtnetlink.c:141 at __rtnl_unlock+0xb2/0xf0, CPU#0: ip/216 WARNING: net/core/rtnetlink.c:141 at __rtnl_unlock+0xb2/0xf0, CPU#0: ip/216 With it, the commands log nothing and remove both amt devices, and tools/testing/selftests/net/amt.sh passes on a KASAN and lockdep kernel. Found by a selftest for our upcoming AMT offload RFC, which deletes a lower carrying two amt gateways, on our 6.18-based driver. The commands above reproduce it on net. Fixes: b9022b53adad ("amt: add control plane of amt interface") Signed-off-by: Omar Ramadan Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261105232302.494171-1-omar@blockcast.net Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/amt.c | 56 ++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index ad855130b4300..d318dd9bf7671 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -3377,22 +3377,6 @@ static struct rtnl_link_ops amt_link_ops __read_mostly = { .fill_info = amt_fill_info, }; -static struct net_device *amt_lookup_upper_dev(struct net_device *dev) -{ - struct net_device *upper_dev; - struct amt_dev *amt; - - for_each_netdev(dev_net(dev), upper_dev) { - if (netif_is_amt(upper_dev)) { - amt = netdev_priv(upper_dev); - if (amt->stream_dev == dev) - return upper_dev; - } - } - - return NULL; -} - static int amt_device_event(struct notifier_block *unused, unsigned long event, void *ptr) { @@ -3402,26 +3386,34 @@ static int amt_device_event(struct notifier_block *unused, LIST_HEAD(list); int new_mtu; - upper_dev = amt_lookup_upper_dev(dev); - if (!upper_dev) - return NOTIFY_DONE; - amt = netdev_priv(upper_dev); + /* amt_dellink() leaves each device on the netns device list until + * unregister_netdevice_many(), so the walk stays valid. + */ + for_each_netdev(dev_net(dev), upper_dev) { + if (!netif_is_amt(upper_dev)) + continue; + amt = netdev_priv(upper_dev); + if (amt->stream_dev != dev) + continue; - switch (event) { - case NETDEV_UNREGISTER: - amt_dellink(amt->dev, &list); - unregister_netdevice_many(&list); - break; - case NETDEV_CHANGEMTU: - if (amt->mode == AMT_MODE_RELAY) - new_mtu = dev->mtu - AMT_RELAY_HLEN; - else - new_mtu = dev->mtu - AMT_GW_HLEN; + switch (event) { + case NETDEV_UNREGISTER: + amt_dellink(amt->dev, &list); + break; + case NETDEV_CHANGEMTU: + if (amt->mode == AMT_MODE_RELAY) + new_mtu = dev->mtu - AMT_RELAY_HLEN; + else + new_mtu = dev->mtu - AMT_GW_HLEN; - dev_set_mtu(amt->dev, new_mtu); - break; + dev_set_mtu(amt->dev, new_mtu); + break; + } } + if (event == NETDEV_UNREGISTER) + unregister_netdevice_many(&list); + return NOTIFY_DONE; } -- 2.53.0