From patchwork Sat Jan 4 06:37:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13926109 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-80009.amazon.com (smtp-fw-80009.amazon.com [99.78.197.220]) (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 E161235959 for ; Sat, 4 Jan 2025 06:38:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.220 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735972712; cv=none; b=IMXcpmV/qgVZzaS2GeAxIRXlDX1K5EO8ret13c+B5r+MXPyEGEhw2RriH3qt7c9l5KF4ac+7kOTtTwYcF0HH7c1S2snmZhJhGWkq957l3hHmbUYfNQEaNCFvzxrFkrYLdZA2MZLRocSSJuycJ7HZiK0e+EY5QR7Su8njmhgZmF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735972712; c=relaxed/simple; bh=1KY2nW7mCAO/gQN6+vP4tuWBqSrq7KK/sYxEW/qt3T0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LJjwqPAWpHsfbIXZ2oQzBdCo25o8hZaMv1/JC2jpbLgkTxjE//g4U8jiVat30v/ZwznjcTZdjIU5SSe1PELvRU1ch5xW04hlJilMlO1hm7Ry5FXBX+cfMUxdC960v+Jdm5DkHqDiZ0Vmp3rzx5IBc+kbAlWfNqJKCFTKuLLRoEQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=THaVfdeN; arc=none smtp.client-ip=99.78.197.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="THaVfdeN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1735972711; x=1767508711; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=63C6D2JvOmHN8gsZTjW8wLqNNd5ilwpwls75PuN1uI4=; b=THaVfdeN0Ut3F032jteop/B4TqBnphYJMPS2JhwdiWnV9+sXrvTsTC4T RgAoIHn5rbX5p7T91IOGq027JtWUbuTLWe6hkwVVW8mlE47Xohc9w6nQ3 6TWH2S8pLqJTk9/PvGZrURrOJnCwxv5M7lBj/CNqys641MFfArROmtxUi 0=; X-IronPort-AV: E=Sophos;i="6.12,288,1728950400"; d="scan'208";a="161619420" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-80009.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jan 2025 06:38:30 +0000 Received: from EX19MTAUWB002.ant.amazon.com [10.0.21.151:35266] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.24.171:2525] with esmtp (Farcaster) id 2deb9544-7295-49c3-89e4-8eaaf5a1c18a; Sat, 4 Jan 2025 06:38:30 +0000 (UTC) X-Farcaster-Flow-ID: 2deb9544-7295-49c3-89e4-8eaaf5a1c18a Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWB002.ant.amazon.com (10.250.64.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Sat, 4 Jan 2025 06:38:29 +0000 Received: from 6c7e67c6786f.amazon.com (10.119.9.250) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Sat, 4 Jan 2025 06:38:26 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 1/4] net: Convert netdev_chain to blocking_notifier. Date: Sat, 4 Jan 2025 15:37:32 +0900 Message-ID: <20250104063735.36945-2-kuniyu@amazon.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250104063735.36945-1-kuniyu@amazon.com> References: <20250104063735.36945-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D031UWA003.ant.amazon.com (10.13.139.47) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org Once RTNL is converted to per-netns, nothing protects netdev_chain. A netdev notifier might disappear while being used by raw_notifier_call_chain(). Let's convert netdev_chain to blocking_notifier to add its dedicated rwsem. Given netdev_chain is touched under RTNL by only one user at the same time, adding rwsem is unlikely to cause regression. Signed-off-by: Kuniyuki Iwashima --- net/core/dev.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index e7223972b9aa..404f5bda821b 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -444,7 +444,7 @@ static void unlist_netdevice(struct net_device *dev) * Our notifier list */ -static RAW_NOTIFIER_HEAD(netdev_chain); +static BLOCKING_NOTIFIER_HEAD(netdev_chain); /* * Device drivers call our routines to queue packets here. We empty the @@ -1770,7 +1770,7 @@ int register_netdevice_notifier(struct notifier_block *nb) /* Close race with setup_net() and cleanup_net() */ down_write(&pernet_ops_rwsem); rtnl_lock(); - err = raw_notifier_chain_register(&netdev_chain, nb); + err = blocking_notifier_chain_register(&netdev_chain, nb); if (err) goto unlock; if (dev_boot_phase) @@ -1790,7 +1790,7 @@ int register_netdevice_notifier(struct notifier_block *nb) for_each_net_continue_reverse(net) call_netdevice_unregister_net_notifiers(nb, net); - raw_notifier_chain_unregister(&netdev_chain, nb); + blocking_notifier_chain_unregister(&netdev_chain, nb); goto unlock; } EXPORT_SYMBOL(register_netdevice_notifier); @@ -1817,7 +1817,7 @@ int unregister_netdevice_notifier(struct notifier_block *nb) /* Close race with setup_net() and cleanup_net() */ down_write(&pernet_ops_rwsem); rtnl_lock(); - err = raw_notifier_chain_unregister(&netdev_chain, nb); + err = blocking_notifier_chain_unregister(&netdev_chain, nb); if (err) goto unlock; @@ -1993,7 +1993,7 @@ int call_netdevice_notifiers_info(unsigned long val, ret = raw_notifier_call_chain(&net->netdev_chain, val, info); if (ret & NOTIFY_STOP_MASK) return ret; - return raw_notifier_call_chain(&netdev_chain, val, info); + return blocking_notifier_call_chain(&netdev_chain, val, info); } /** From patchwork Sat Jan 4 06:37:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13926112 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-52003.amazon.com (smtp-fw-52003.amazon.com [52.119.213.152]) (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 7BD03335C7 for ; Sat, 4 Jan 2025 06:39:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735972747; cv=none; b=Ne/ZHtlErIG7d3VDwPmq1wCqUuMEkywpyhAA7Clw/uiVDzZcXqvcwjzUzCnhgvxTyWJqjo0qGqy2atSI8kQOggGTj9FHV9Clmv33tZURPHvGBp2L6s+bfXqzLfM3a8luGgOn3neR/HO0BCHJH6B4LWaxS+pBTa0CfX1qWzSmd/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735972747; c=relaxed/simple; bh=nxcYv7+HPYrA7xR12uVMxbYYYWiutXB7MEe7rNyBU3g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kbuQ26kuTv0aU1BACaXZz0RmZNt/aggPnz0EL/bhn0LyR6BkYvzBtzdPcuOnIv0XUSrMg/h8u/DV30mmvbHKfzpBa7eD1UgD84vZLHC0YFeGCfHzt3wuF/jEV7Od51AjW4iH/07z1Xh7extcrq8HmqBQOC2Rw3pfP/v8FKy6jyU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=uTZjadFa; arc=none smtp.client-ip=52.119.213.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="uTZjadFa" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1735972744; x=1767508744; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XztmMcqAI8ex1hkvxRrFtklHKPIS2b40cwt6x2scGDw=; b=uTZjadFaLcJXldukmEE8pYX5f3Rz86/pSxsksW8nq40LIgNFsytObohD 5/DqB6DNbJMBGUOOgK6Ed9o6rOf/tn2BJuE409opxUIXZ7bTmMQnYsaHe lG40BTSR4XyFXckh2MTwpb8Dp0mE70e2wcOmCaFhsHlUX4x7/hnw6p9Is A=; X-IronPort-AV: E=Sophos;i="6.12,288,1728950400"; d="scan'208";a="55146370" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-52003.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jan 2025 06:39:01 +0000 Received: from EX19MTAUWA002.ant.amazon.com [10.0.21.151:29757] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.39.3:2525] with esmtp (Farcaster) id 68129ada-0799-4f83-94cc-df88ec5492a5; Sat, 4 Jan 2025 06:39:02 +0000 (UTC) X-Farcaster-Flow-ID: 68129ada-0799-4f83-94cc-df88ec5492a5 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Sat, 4 Jan 2025 06:38:57 +0000 Received: from 6c7e67c6786f.amazon.com (10.119.9.250) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Sat, 4 Jan 2025 06:38:53 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 2/4] net: Hold __rtnl_net_lock() in (un)?register_netdevice_notifier(). Date: Sat, 4 Jan 2025 15:37:33 +0900 Message-ID: <20250104063735.36945-3-kuniyu@amazon.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250104063735.36945-1-kuniyu@amazon.com> References: <20250104063735.36945-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D043UWA004.ant.amazon.com (10.13.139.41) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org (un)?register_netdevice_notifier() hold pernet_ops_rwsem and RTNL, iterate all netns, and trigger the notifier for all netdev. Let's hold __rtnl_net_lock() before triggering the notifier. Signed-off-by: Kuniyuki Iwashima --- net/core/dev.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 404f5bda821b..7d49b4018ea2 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1776,7 +1776,9 @@ int register_netdevice_notifier(struct notifier_block *nb) if (dev_boot_phase) goto unlock; for_each_net(net) { + __rtnl_net_lock(net); err = call_netdevice_register_net_notifiers(nb, net); + __rtnl_net_unlock(net); if (err) goto rollback; } @@ -1787,8 +1789,11 @@ int register_netdevice_notifier(struct notifier_block *nb) return err; rollback: - for_each_net_continue_reverse(net) + for_each_net_continue_reverse(net) { + __rtnl_net_lock(net); call_netdevice_unregister_net_notifiers(nb, net); + __rtnl_net_unlock(net); + } blocking_notifier_chain_unregister(&netdev_chain, nb); goto unlock; @@ -1821,8 +1826,11 @@ int unregister_netdevice_notifier(struct notifier_block *nb) if (err) goto unlock; - for_each_net(net) + for_each_net(net) { + __rtnl_net_lock(net); call_netdevice_unregister_net_notifiers(nb, net); + __rtnl_net_unlock(net); + } unlock: rtnl_unlock(); From patchwork Sat Jan 4 06:37:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13926113 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-80009.amazon.com (smtp-fw-80009.amazon.com [99.78.197.220]) (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 BFC8122EE4 for ; Sat, 4 Jan 2025 06:39:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.220 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735972767; cv=none; b=WfE8/0lKETWmh1eLspK2Piz8r2vXI0JAd1hIQrj+bKSYw+5u2RJTlMA0E5r8a63zdaGqQa2A1TAiiq3oYCApqXD4ifa6/kb9jfhDCginLIaZ7fRxYJgA/uz43dqOZcmzCiQD4aRToQVjZC4dWAq8q9PkIlBn8nS76mi1uo9f3gM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735972767; c=relaxed/simple; bh=tzCjE1R1GTyzWt93KxYexCgmIKYA9H5amU9Xl9R0W/o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YZaTtianWg5wDFowfY3noAPYP8wjl1vrgLmp6Z0HTfeSR5X60zz4gzrMXRtSHx3A1iFK6ziCWouzm6vFUJUi2cgqTwqQgWpX0zsCwOGZeGxnXlmQIiAcgwdhdiI1h1xhAWcvR+pENq20N7mE7b6FUkolRB3b28WCxZA8uYJX53E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=Adr/zQiZ; arc=none smtp.client-ip=99.78.197.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="Adr/zQiZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1735972765; x=1767508765; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UQ9zjD/oUxFFpuVZdjUC++H44Nw4zgl4PXMZVNNqHoA=; b=Adr/zQiZ/rM1bjaEe0EzW6wdwC8ibJ40L70R55J5HqA+3IWVllu+RCbE DFHEwlIctPnVIHVOABNzJgb1dr9OrMWmw0WK6Oy0m6UHGq8Kt+drE6efP pKRqUOR/9Vmdz/ePr+CQU22nhr7t7W5OgZVDUh0x6/x2Xrnb5jUnXbegL A=; X-IronPort-AV: E=Sophos;i="6.12,288,1728950400"; d="scan'208";a="161619543" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-80009.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jan 2025 06:39:25 +0000 Received: from EX19MTAUWB001.ant.amazon.com [10.0.21.151:29566] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.2.75:2525] with esmtp (Farcaster) id c2cc0949-9bd6-4f5c-8d74-9f566a3f55fa; Sat, 4 Jan 2025 06:39:25 +0000 (UTC) X-Farcaster-Flow-ID: c2cc0949-9bd6-4f5c-8d74-9f566a3f55fa Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWB001.ant.amazon.com (10.250.64.248) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Sat, 4 Jan 2025 06:39:24 +0000 Received: from 6c7e67c6786f.amazon.com (10.119.9.250) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Sat, 4 Jan 2025 06:39:21 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 3/4] net: Hold rtnl_net_lock() in (un)?register_netdevice_notifier_net(). Date: Sat, 4 Jan 2025 15:37:34 +0900 Message-ID: <20250104063735.36945-4-kuniyu@amazon.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250104063735.36945-1-kuniyu@amazon.com> References: <20250104063735.36945-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D042UWA001.ant.amazon.com (10.13.139.92) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org (un)?register_netdevice_notifier_net() hold RTNL before triggering the notifier for all netdev in the netns. Let's convert the RTNL to rtnl_net_lock(). Note that the per-netns netdev notifier is protected by per-netns RTNL, so we do not need to convert it to blocking_notifier. Signed-off-by: Kuniyuki Iwashima --- net/core/dev.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 7d49b4018ea2..f6c6559e2548 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1894,9 +1894,10 @@ int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb) { int err; - rtnl_lock(); + rtnl_net_lock(net); err = __register_netdevice_notifier_net(net, nb, false); - rtnl_unlock(); + rtnl_net_unlock(net); + return err; } EXPORT_SYMBOL(register_netdevice_notifier_net); @@ -1922,9 +1923,10 @@ int unregister_netdevice_notifier_net(struct net *net, { int err; - rtnl_lock(); + rtnl_net_lock(net); err = __unregister_netdevice_notifier_net(net, nb); - rtnl_unlock(); + rtnl_net_unlock(net); + return err; } EXPORT_SYMBOL(unregister_netdevice_notifier_net); From patchwork Sat Jan 4 06:37:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13926114 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-52002.amazon.com (smtp-fw-52002.amazon.com [52.119.213.150]) (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 286221A29A for ; Sat, 4 Jan 2025 06:39:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735972796; cv=none; b=ny+W8ftDbyHXxn/+bw5LxenG726u4IaYALoghL3j0ITqE240to5GX1S4kBdVo+lzW1jxQQUvnA8N6yGBDVCvg0MLxFQDkp6vwesJScrHlcsb44bnNoL0tStPJb0cE739aWwkaHGfVtdzic6gFIxXjxQBYzAgbIiv3m5BsvcJ3ok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735972796; c=relaxed/simple; bh=6WENTeKSDRdyEm+fSrgDwuHbeUXmzeZher9/QMzN2wk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eoXq3vAMpov+R2bjkPjnJTJk9LU1cK0n1PlQs+eA93segzga/FR1jdPOy7TCO5JMruoZveDxOHDKkEIEfRu8oNw0fx6KENV+J974bAvFDKLx1qrCRzVjDPPkw/dQgvxmqZMDOozZvzPrfAVzkmVUE/EQVkN6pOQr5o7DwxVeVlo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=Zbs6DPkT; arc=none smtp.client-ip=52.119.213.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="Zbs6DPkT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1735972795; x=1767508795; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=I1Z7phS8bZxHyqTW+DXtuHuNTdjBFWacRFAxiPyGEIQ=; b=Zbs6DPkTreUV3HZDHkMKxDtJQBdDYjIYEqEQ+DeSHplKpEjavOQGaoPx JG/vIDzd/CINKP3vEo/C1VsK+u9+R22P4A3/WYUW0jCh7ilYMcxyA4tqT my7cXTvNhLBEFp1NbN1zfBJbWajRq3OlDrakOE1sgf18TM37TnB6gNJQX 8=; X-IronPort-AV: E=Sophos;i="6.12,288,1728950400"; d="scan'208";a="686778619" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-52002.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jan 2025 06:39:51 +0000 Received: from EX19MTAUWC002.ant.amazon.com [10.0.21.151:21143] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.39.3:2525] with esmtp (Farcaster) id d2f1c624-3f0b-4cbc-a323-b8e41a55cbf4; Sat, 4 Jan 2025 06:39:51 +0000 (UTC) X-Farcaster-Flow-ID: d2f1c624-3f0b-4cbc-a323-b8e41a55cbf4 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC002.ant.amazon.com (10.250.64.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Sat, 4 Jan 2025 06:39:50 +0000 Received: from 6c7e67c6786f.amazon.com (10.119.9.250) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.39; Sat, 4 Jan 2025 06:39:47 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 4/4] net: Hold rtnl_net_lock() in (un)?register_netdevice_notifier_dev_net(). Date: Sat, 4 Jan 2025 15:37:35 +0900 Message-ID: <20250104063735.36945-5-kuniyu@amazon.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250104063735.36945-1-kuniyu@amazon.com> References: <20250104063735.36945-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D033UWA002.ant.amazon.com (10.13.139.10) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org (un)?register_netdevice_notifier_dev_net() hold RTNL before triggering the notifier for all netdev in the netns. Let's convert the RTNL to rtnl_net_lock(). Note that move_netdevice_notifiers_dev_net() is assumed to be (but not yet) protected by per-netns RTNL of both src and dst netns; we need to convert wireless and hyperv drivers that call dev_change_net_namespace(). Signed-off-by: Kuniyuki Iwashima --- net/core/dev.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index f6c6559e2548..a0dd34463901 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1943,15 +1943,17 @@ int register_netdevice_notifier_dev_net(struct net_device *dev, struct notifier_block *nb, struct netdev_net_notifier *nn) { + struct net *net = dev_net(dev); int err; - rtnl_lock(); - err = __register_netdevice_notifier_net(dev_net(dev), nb, false); + rtnl_net_lock(net); + err = __register_netdevice_notifier_net(net, nb, false); if (!err) { nn->nb = nb; list_add(&nn->list, &dev->net_notifier_list); } - rtnl_unlock(); + rtnl_net_unlock(net); + return err; } EXPORT_SYMBOL(register_netdevice_notifier_dev_net); @@ -1960,12 +1962,14 @@ int unregister_netdevice_notifier_dev_net(struct net_device *dev, struct notifier_block *nb, struct netdev_net_notifier *nn) { + struct net *net = dev_net(dev); int err; - rtnl_lock(); + rtnl_net_lock(net); list_del(&nn->list); - err = __unregister_netdevice_notifier_net(dev_net(dev), nb); - rtnl_unlock(); + err = __unregister_netdevice_notifier_net(net, nb); + rtnl_net_unlock(net); + return err; } EXPORT_SYMBOL(unregister_netdevice_notifier_dev_net);