From patchwork Fri Jan 13 18:09:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodong Wang X-Patchwork-Id: 1726323 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=iLxXtiS+; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NtqFM5WSCz23dq for ; Sat, 14 Jan 2023 05:09:43 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pGOUg-0002L5-Un; Fri, 13 Jan 2023 18:09:34 +0000 Received: from mail-dm6nam12on2053.outbound.protection.outlook.com ([40.107.243.53] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pGOUd-0002Ic-Bg for kernel-team@lists.ubuntu.com; Fri, 13 Jan 2023 18:09:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DffE0Pmpoay7QiBfl2Xdzi11UXR/+N/0mNx55waVfct1gOA87a35+CImao53+EPg7oA4O3WSXbz8oCHuotKTY4wR0cU2ZpVNBa6olZGCQCQdYNVY5mnandHau4gg+i6PKj1AnRadZ2Ygi3zkIVQg8mlTbeE1vQTfMT10HM4bFfxVper87B/0t3p7xNUl2DV5HZcDcb81SUiC1Uco0hpPA3eWPSrKQBw5QloJAhjS0vX/kqDid+bGXU7AjiI+1EvTR/fzqseGG10udtDznkZ7c1fBjKG4PFUOh4JXpRp7aQJfQJWhhhq25vhcS4fKhNwJisVRANdIjzkwpOumLp0maw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=a915KRGRwTmuzI8+MKjKsi31mD4N8CI2NHNjBcgUN/A=; b=jTurpsbHUXjPoW7T1ipka5bSN5e1G38tiuM9hEs3rIR697GgMfsRxczUxayDvI8FDQdurZgAsjAtW2kQCZGZ1dKpvCKfb+Wxs7DeL6C6VhjxPrzqChflMP3YTw5mJnRtyeN7UH6QDtg4LemTCsrQjjrOllCf+WBhL5rQe8CJHi4BNqchISSme5oZpHT+wNl/RfkZhfWG8XdeIdm0T8MEgD6pARdrA286Qk7ShGgok27bdLfBQrz5V5z50ORNX6r0Q6hsNzmCzgGUme0Cz/+Jgszee+KphdLBUQNWk77DNLRPR7VCnfQe3eDwCo6M373T3XYATsLvEaJOlnalH2wMEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=a915KRGRwTmuzI8+MKjKsi31mD4N8CI2NHNjBcgUN/A=; b=iLxXtiS+00tAGvRAro6rIWxL4e1aqt6Ta3VxnHunIga2wx/xgr9arny6n/r1UoKcE+s6LBJe8bcE3KHC4pzfQ+xSLtE4Rs8ximXEKaT35flBljcefp1qgo8DPaMEN9yi0Dma9qHK5NmlTOcs0TUtPsZo9x3mY8N2epiy7KcoVR8n0DSgigVsVHrXxkKteo3/Q442jGnnlER6eOknF0DiTeZG91lZRq13fs483u5e9KkPZr2RnXGBEWVXF82FWrCh8f3p15eG5TDcSArqKFLDzhvNRgyrTBhK7bF+fFGLs5PEkW4iA5gmBuFpO+BU4CP52POoNtZYVlevbc2pkzJwvg== Received: from CY5PR17CA0049.namprd17.prod.outlook.com (2603:10b6:930:12::33) by PH7PR12MB7209.namprd12.prod.outlook.com (2603:10b6:510:204::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.12; Fri, 13 Jan 2023 18:09:28 +0000 Received: from CY4PEPF0000C980.namprd02.prod.outlook.com (2603:10b6:930:12:cafe::8f) by CY5PR17CA0049.outlook.office365.com (2603:10b6:930:12::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.16 via Frontend Transport; Fri, 13 Jan 2023 18:09:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000C980.mail.protection.outlook.com (10.167.241.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.11 via Frontend Transport; Fri, 13 Jan 2023 18:09:28 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Fri, 13 Jan 2023 10:09:20 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Fri, 13 Jan 2023 10:09:20 -0800 Received: from mtl123.mtl.labs.mlnx (10.127.8.10) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36 via Frontend Transport; Fri, 13 Jan 2023 10:09:19 -0800 Received: from sw-mtx-061.mtx.labs.mlnx (sw-mtx-061.mtx.labs.mlnx [10.9.153.25]) by mtl123.mtl.labs.mlnx (8.14.4/8.14.4) with ESMTP id 30DI9FcR032345; Fri, 13 Jan 2023 20:09:17 +0200 From: Bodong Wang To: Subject: [SRU][F:linux-bluefield][PATCH 1/4] net: push loops and nb calls into helper functions Date: Fri, 13 Jan 2023 20:09:12 +0200 Message-ID: <20230113180915.426904-2-bodong@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230113180915.426904-1-bodong@nvidia.com> References: <20230113180915.426904-1-bodong@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000C980:EE_|PH7PR12MB7209:EE_ X-MS-Office365-Filtering-Correlation-Id: f05d9c80-8753-4b22-f539-08daf5914ffa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OxULPQ0l1Nh/pP/Rk1a6VnU3QN3mt69OD8Yjj8lCO63764eRHUShEdZUyqKjD1iZctZZh+6vXd2gKHljS0b4ZgkG+7JoBOa2VdPeV322V4bq5zIPSMqd/LKvlCp+KfEJDc57MiXzYdOpj0HiSATF6twW8jOSDZhe/nL9ipj+g7hKpYheRgPccRIF0F0D0HdbXmBEoS6/uN2CUkGYRFszzmqWcJyzjXcDdiM/f/HXfyqa7OtLoIMIBg+Kai1jadYMs6PFl1pf7NH9kFI3ce1R/VYM+R9l76KTjzAYMqGLOVKWiQbJ+WwZIIRcflorFX5CzPAykqr0DQCARhG0w+q2dTu16wjr/VkV9n8AW0HlRVWtnOAmAAbo8cPjurrscOztVEYQ3SpGB21V20sQUoYgreFbYXdKhM2suhNd8hP0H+YbZzdcEra0VxTizaismHIWvZE/6jzx9j1UqCBPF56+GDHNfnwPKSeiaUOn7QbLHJsjQajYr0+m1+RiegVX5a6V1UiVPlk9fAIIZoeuFwtxfDYHeK4MECvJTjps6T9jsYmdFleMvn4XAQc8f+mnm4CMBCuNJllKK2C8LpT1qG7WmDJiLhx/3ZOOSTfpCbCX+k9mXvaYQ0s7Ng9wJ4Ly/lz8xkC0Nv+GtZyP2pkHgtjNVVrbkqJR5pxgEsmvEdpKiyakFk7nkVygE1BLfF6deBfzSXBxL5DrCGF+3eePm9u0aobSFdNe7ENdXptpEI5lKVHyMmXdLP36xQ+T+T4aN76Jbmnwi0aGbmEvtMz6L08jbv3+8C34lfVqToYVG9Lv+KA= X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230022)(4636009)(136003)(39860400002)(376002)(396003)(346002)(451199015)(36840700001)(46966006)(40470700004)(6666004)(107886003)(316002)(966005)(186003)(1076003)(26005)(478600001)(336012)(83380400001)(4326008)(41300700001)(6916009)(5660300002)(8936002)(70586007)(8676002)(70206006)(47076005)(2906002)(36860700001)(356005)(82740400003)(7636003)(40480700001)(86362001)(54906003)(2616005)(36756003)(40460700003)(82310400005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jan 2023 18:09:28.6162 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f05d9c80-8753-4b22-f539-08daf5914ffa X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000C980.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7209 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad@nvidia.com, bodong@nvidia.com, feliu@nvidia.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jiri Pirko BugLink: https://bugs.launchpad.net/bugs/2002361 Push iterations over net namespaces and netdevices from register_netdevice_notifier() and unregister_netdevice_notifier() into helper functions. Along with that introduce continue_reverse macros to make the code a bit nicer allowing to get rid of "last" marks. Signed-off-by: Jiri Pirko Signed-off-by: David S. Miller (cherry picked from commit afa0df5998131153ec3036f41e76ece33bf1334f) Signed-off-by: Bodong Wang --- include/linux/netdevice.h | 3 ++ include/net/net_namespace.h | 3 +- net/core/dev.c | 89 +++++++++++++++++++++++++------------ 3 files changed, 66 insertions(+), 29 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index de4cbae880fb..9936a946d6e8 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2610,6 +2610,9 @@ extern rwlock_t dev_base_lock; /* Device list lock */ list_for_each_entry_safe(d, n, &(net)->dev_base_head, dev_list) #define for_each_netdev_continue(net, d) \ list_for_each_entry_continue(d, &(net)->dev_base_head, dev_list) +#define for_each_netdev_continue_reverse(net, d) \ + list_for_each_entry_continue_reverse(d, &(net)->dev_base_head, \ + dev_list) #define for_each_netdev_continue_rcu(net, d) \ list_for_each_entry_continue_rcu(d, &(net)->dev_base_head, dev_list) #define for_each_netdev_in_bond_rcu(bond, slave) \ diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index 167e390ac9d4..444af82e46da 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -333,7 +333,8 @@ static inline struct net *read_pnet(const possible_net_t *pnet) /* Protected by net_rwsem */ #define for_each_net(VAR) \ list_for_each_entry(VAR, &net_namespace_list, list) - +#define for_each_net_continue_reverse(VAR) \ + list_for_each_entry_continue_reverse(VAR, &net_namespace_list, list) #define for_each_net_rcu(VAR) \ list_for_each_entry_rcu(VAR, &net_namespace_list, list) diff --git a/net/core/dev.c b/net/core/dev.c index 3cb38d0b0a46..9e7ef73679b7 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1531,6 +1531,62 @@ static int call_netdevice_notifier(struct notifier_block *nb, unsigned long val, return nb->notifier_call(nb, val, &info); } +static int call_netdevice_register_notifiers(struct notifier_block *nb, + struct net_device *dev) +{ + int err; + + err = call_netdevice_notifier(nb, NETDEV_REGISTER, dev); + err = notifier_to_errno(err); + if (err) + return err; + + if (!(dev->flags & IFF_UP)) + return 0; + + call_netdevice_notifier(nb, NETDEV_UP, dev); + return 0; +} + +static void call_netdevice_unregister_notifiers(struct notifier_block *nb, + struct net_device *dev) +{ + if (dev->flags & IFF_UP) { + call_netdevice_notifier(nb, NETDEV_GOING_DOWN, + dev); + call_netdevice_notifier(nb, NETDEV_DOWN, dev); + } + call_netdevice_notifier(nb, NETDEV_UNREGISTER, dev); +} + +static int call_netdevice_register_net_notifiers(struct notifier_block *nb, + struct net *net) +{ + struct net_device *dev; + int err; + + for_each_netdev(net, dev) { + err = call_netdevice_register_notifiers(nb, dev); + if (err) + goto rollback; + } + return 0; + +rollback: + for_each_netdev_continue_reverse(net, dev) + call_netdevice_unregister_notifiers(nb, dev); + return err; +} + +static void call_netdevice_unregister_net_notifiers(struct notifier_block *nb, + struct net *net) +{ + struct net_device *dev; + + for_each_netdev(net, dev) + call_netdevice_unregister_notifiers(nb, dev); +} + static int dev_boot_phase = 1; /** @@ -1549,8 +1605,6 @@ static int dev_boot_phase = 1; int register_netdevice_notifier(struct notifier_block *nb) { - struct net_device *dev; - struct net_device *last; struct net *net; int err; @@ -1563,17 +1617,9 @@ int register_netdevice_notifier(struct notifier_block *nb) if (dev_boot_phase) goto unlock; for_each_net(net) { - for_each_netdev(net, dev) { - err = call_netdevice_notifier(nb, NETDEV_REGISTER, dev); - err = notifier_to_errno(err); - if (err) - goto rollback; - - if (!(dev->flags & IFF_UP)) - continue; - - call_netdevice_notifier(nb, NETDEV_UP, dev); - } + err = call_netdevice_register_net_notifiers(nb, net); + if (err) + goto rollback; } unlock: @@ -1582,22 +1628,9 @@ int register_netdevice_notifier(struct notifier_block *nb) return err; rollback: - last = dev; - for_each_net(net) { - for_each_netdev(net, dev) { - if (dev == last) - goto outroll; - - if (dev->flags & IFF_UP) { - call_netdevice_notifier(nb, NETDEV_GOING_DOWN, - dev); - call_netdevice_notifier(nb, NETDEV_DOWN, dev); - } - call_netdevice_notifier(nb, NETDEV_UNREGISTER, dev); - } - } + for_each_net_continue_reverse(net) + call_netdevice_unregister_net_notifiers(nb, net); -outroll: raw_notifier_chain_unregister(&netdev_chain, nb); goto unlock; } From patchwork Fri Jan 13 18:09:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodong Wang X-Patchwork-Id: 1726324 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=sd9tx0OF; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NtqFM6FQ4z23g9 for ; Sat, 14 Jan 2023 05:09:43 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pGOUg-0002KE-Ma; Fri, 13 Jan 2023 18:09:34 +0000 Received: from mail-dm6nam10on2062.outbound.protection.outlook.com ([40.107.93.62] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pGOUc-0002IQ-E9 for kernel-team@lists.ubuntu.com; Fri, 13 Jan 2023 18:09:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zc9s7xBZ/xSqVGdaqo8L7nOIKhk2GKrJV2kD6nj50oYGimsNyVNihJ0GbkJx0IrKGgNHj5oW9qxdBNkC4iWxYu6IwidO3Y+2vt3ky/OTicJC1218eJMDSb6J+GfRwTFygw0vLgEd3AYamuUfdzwTBn/sIvVv21wg+Z3/hI++TUubIB41XmqCIfG8YjQ1+hUJe6g2jGJSAW/BA5AIQcmC4v2EwZpSW71/KzBTHJ02FzQVooMYyONEKydQw1aiQQQZSWe2Ku+4uK4OO63WlYXAzv127AeqcQUnm15Qgb+ABHp4l5o06L8RPinQqyI909xzJUzjec1nYf9H1DtZK+SX6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=EwuP+OHfZjnAxuCn+SgCUVV6GnSaNw3pMjM3CRtk37Q=; b=a+kK2zK9rdUWRn07uHleTS6yoL5b3FDn8Oi2HJr42/TnVLju9MDDCGCYXrDb/0MBksdiUuxY99hMHiAUUEVDEFuHNqlrkiaSAFnNdCkIYMa+zxkDhdeScpdKpeMMGi3XxCMJyxOvtMI4XSCIg3Cpr0C12WQsSxd/CUfDPveMACawJajFX7J2AExsutddlwoVtIH4vOFIs1R88W5zQ3LYkjUOig6yvufccGNxB8+CNLaFrOT54nO3bDbuS4BbLyA5WmosfVZxGu8IoAuKrlWtu/SubnEVWLD5iebGuYZRPxZuBNfG6VS2/4NMi8E++hUXNGZHNSf4Hc+mhC6GYmRqoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EwuP+OHfZjnAxuCn+SgCUVV6GnSaNw3pMjM3CRtk37Q=; b=sd9tx0OFedDBROMO1gBeLXO+bokP/KeCwbCaDwUN3HfwcvgKpgJ36KsXnfwIS6ghFRjdgr7Mv+4Xajh/Sqo/S9C/mPG699a/NM+4RjABuWkJTC4P4B1dNkr0gN93J1cLX4Cc1BNFf/27Ri5/aPLWH3Ir/bunnRoO+EEoaMixoyuxFgCARc0uANxiuXkqsGNZkebJKe5UESJ10nlFwfBerA+C6CqJc6bsfTxzTCtrum2s+Yhse7tyikz2STd2xGDGtQWv7/5qC5d1XAH0jVhVUV6lBWC/5u5FzcNzAp4LtmoUIEcImJPhNA0MgYiKsN/p41/kI0Y3ahcs0+g7B5U5ow== Received: from MW4PR04CA0077.namprd04.prod.outlook.com (2603:10b6:303:6b::22) by DS0PR12MB7747.namprd12.prod.outlook.com (2603:10b6:8:138::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.19; Fri, 13 Jan 2023 18:09:27 +0000 Received: from CO1NAM11FT057.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6b:cafe::44) by MW4PR04CA0077.outlook.office365.com (2603:10b6:303:6b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.14 via Frontend Transport; Fri, 13 Jan 2023 18:09:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by CO1NAM11FT057.mail.protection.outlook.com (10.13.174.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.13 via Frontend Transport; Fri, 13 Jan 2023 18:09:27 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Fri, 13 Jan 2023 10:09:22 -0800 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Fri, 13 Jan 2023 10:09:21 -0800 Received: from mtl123.mtl.labs.mlnx (10.127.8.10) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36 via Frontend Transport; Fri, 13 Jan 2023 10:09:21 -0800 Received: from sw-mtx-061.mtx.labs.mlnx (sw-mtx-061.mtx.labs.mlnx [10.9.153.25]) by mtl123.mtl.labs.mlnx (8.14.4/8.14.4) with ESMTP id 30DI9FcS032345; Fri, 13 Jan 2023 20:09:18 +0200 From: Bodong Wang To: Subject: [SRU][F:linux-bluefield][PATCH 2/4] net: introduce per-netns netdevice notifiers Date: Fri, 13 Jan 2023 20:09:13 +0200 Message-ID: <20230113180915.426904-3-bodong@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230113180915.426904-1-bodong@nvidia.com> References: <20230113180915.426904-1-bodong@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT057:EE_|DS0PR12MB7747:EE_ X-MS-Office365-Filtering-Correlation-Id: 22626583-747a-433a-069f-08daf5914f74 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bq6siOwaOEatDkzU+fyjmRdXTIITI2Ejavmog1OoudEtlGiPmtR8vUrbjlIlepefrNNLGLNLlTU7qOHvHM8ioPXT04NEmcx1zOvBB4buQ1WP44WolmC9U/6gysjSsRsa+g4XpGbZSe8asQkP0X/BnjHUoHtKRXM5lgBP3JWMayIOrZDZTXEX9WrEeGyAjonInApVTv9QYwkOIisNoYLl5mIVz++snhyhl4lu9dEkkEtDklqO6UTBOjK6/UpGcK+7VH+qO36mSMscaABsPJWLPHEqS1yMpkXADbavDsIb1XBEfW2qxiLoBXevu0t62G5LmIfh8ieh2OdQLhuoik+uv9gQ2CvEi2kZIV3nCAomGi0ANY/AGlqJT6sX7/uGHEeIhdJiIm1J1txNZqcr4PdEZbS+8ao4pz9fvTqnAMmaXZFL2fr3075vmcuc0ZkWUfNJYFVxt5uhjsJxbFwbkxQPZ1AaX5eLp4E08xtJzpeZ/UKmbxjMgGEUXFmqVGzgIK6cT/njBgzGR1cKMADAVbyupv9615eHhmaGIxV2qeRJ4HBlu0mly30hO0jfqdpcRCnkEVkSTDJDUabuxjdm2jNji0dYblja6YoeOhSMhH8gjrGFBRuukbSAymm6QkkpwEblaFKBGa0YBtOEiJFK3O7R5U+ax7HgN6J9z5B6C+G7+tPh0kYdyLSPosoCClWT8IviiFfD/4bjwKBTpFO70zYLj0gwoi9BjRT73A91KI9ehT+W43xSAgBZrVcVhU687tp8+kTxPBA07KQohJfqtU14WGu1Bce1C+nBBYzkmd6+Sk8= X-Forefront-Antispam-Report: CIP:216.228.118.232; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge1.nvidia.com; CAT:NONE; SFS:(13230022)(4636009)(346002)(376002)(39860400002)(136003)(396003)(451199015)(46966006)(40470700004)(36840700001)(2906002)(40460700003)(5660300002)(316002)(54906003)(36756003)(2616005)(1076003)(82310400005)(336012)(36860700001)(83380400001)(47076005)(966005)(26005)(86362001)(40480700001)(356005)(186003)(7636003)(82740400003)(478600001)(107886003)(6666004)(8936002)(4326008)(6916009)(8676002)(70586007)(41300700001)(70206006); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jan 2023 18:09:27.7319 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22626583-747a-433a-069f-08daf5914f74 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.232]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT057.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7747 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad@nvidia.com, bodong@nvidia.com, feliu@nvidia.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jiri Pirko BugLink: https://bugs.launchpad.net/bugs/2002361 Often the code for example in drivers is interested in getting notifier call only from certain network namespace. In addition to the existing global netdevice notifier chain introduce per-netns chains and allow users to register to that. Eventually this would eliminate unnecessary overhead in case there are many netdevices in many network namespaces. Signed-off-by: Jiri Pirko Signed-off-by: David S. Miller (Backported from commit a30c7b429f2dd980202c912fcb76442364937b4d) Signed-off-by: Bodong Wang [Bodong: ignore dev_base_seq/ifindex/dev_unreg_count] --- include/linux/netdevice.h | 3 ++ include/net/net_namespace.h | 2 + net/core/dev.c | 87 +++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 9936a946d6e8..73a0c82a2621 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2540,6 +2540,9 @@ const char *netdev_cmd_to_name(enum netdev_cmd cmd); int register_netdevice_notifier(struct notifier_block *nb); int unregister_netdevice_notifier(struct notifier_block *nb); +int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb); +int unregister_netdevice_notifier_net(struct net *net, + struct notifier_block *nb); struct netdev_notifier_info { struct net_device *dev; diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index 444af82e46da..cc20e2e14940 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -36,6 +36,7 @@ #include #include #include +#include struct user_namespace; struct proc_dir_entry; @@ -110,6 +111,7 @@ struct net { u32 hash_mix; struct net_device *loopback_dev; /* The loopback */ + struct raw_notifier_head netdev_chain; /* core fib_rules */ struct list_head rules_ops; diff --git a/net/core/dev.c b/net/core/dev.c index 9e7ef73679b7..58cf313c6bea 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1680,6 +1680,80 @@ int unregister_netdevice_notifier(struct notifier_block *nb) } EXPORT_SYMBOL(unregister_netdevice_notifier); +/** + * register_netdevice_notifier_net - register a per-netns network notifier block + * @net: network namespace + * @nb: notifier + * + * Register a notifier to be called when network device events occur. + * The notifier passed is linked into the kernel structures and must + * not be reused until it has been unregistered. A negative errno code + * is returned on a failure. + * + * When registered all registration and up events are replayed + * to the new notifier to allow device to have a race free + * view of the network device list. + */ + +int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb) +{ + int err; + + rtnl_lock(); + err = raw_notifier_chain_register(&net->netdev_chain, nb); + if (err) + goto unlock; + if (dev_boot_phase) + goto unlock; + + err = call_netdevice_register_net_notifiers(nb, net); + if (err) + goto chain_unregister; + +unlock: + rtnl_unlock(); + return err; + +chain_unregister: + raw_notifier_chain_unregister(&netdev_chain, nb); + goto unlock; +} +EXPORT_SYMBOL(register_netdevice_notifier_net); + +/** + * unregister_netdevice_notifier_net - unregister a per-netns + * network notifier block + * @net: network namespace + * @nb: notifier + * + * Unregister a notifier previously registered by + * register_netdevice_notifier(). The notifier is unlinked into the + * kernel structures and may then be reused. A negative errno code + * is returned on a failure. + * + * After unregistering unregister and down device events are synthesized + * for all devices on the device list to the removed notifier to remove + * the need for special case cleanup code. + */ + +int unregister_netdevice_notifier_net(struct net *net, + struct notifier_block *nb) +{ + int err; + + rtnl_lock(); + err = raw_notifier_chain_unregister(&net->netdev_chain, nb); + if (err) + goto unlock; + + call_netdevice_unregister_net_notifiers(nb, net); + +unlock: + rtnl_unlock(); + return err; +} +EXPORT_SYMBOL(unregister_netdevice_notifier_net); + /** * call_netdevice_notifiers_info - call all network notifier blocks * @val: value passed unmodified to notifier function @@ -1692,7 +1766,18 @@ EXPORT_SYMBOL(unregister_netdevice_notifier); static int call_netdevice_notifiers_info(unsigned long val, struct netdev_notifier_info *info) { + struct net *net = dev_net(info->dev); + int ret; + ASSERT_RTNL(); + + /* Run per-netns notifier block chain first, then run the global one. + * Hopefully, one day, the global one is going to be removed after + * all notifier block registrators get converted to be per-netns. + */ + 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); } @@ -10149,6 +10234,8 @@ static int __net_init netdev_init(struct net *net) if (net->dev_index_head == NULL) goto err_idx; + RAW_INIT_NOTIFIER_HEAD(&net->netdev_chain); + return 0; err_idx: From patchwork Fri Jan 13 18:09:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodong Wang X-Patchwork-Id: 1726325 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=LzGeI9km; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NtqFQ5gPQz23dq for ; Sat, 14 Jan 2023 05:09:46 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pGOUj-0002Oc-HO; Fri, 13 Jan 2023 18:09:37 +0000 Received: from mail-co1nam11on2043.outbound.protection.outlook.com ([40.107.220.43] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pGOUf-0002Jb-UN for kernel-team@lists.ubuntu.com; Fri, 13 Jan 2023 18:09:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BoXyplJRx5rKeezKmbs95S/8qwhwzA3W6ULE3pcXSCe46ayp0tNSJ6rMReMJvGbx5FOKEEJgP+Gg5SeKD5utwhKPUIo99o4JLirMhTUjE+MzAC8d+g5UDy1gYx8FXYr/0hTH7nT4fbUEp8OeJ0KCMDTOd5Irs23xqSK9R1ERP2Va7DqfgdZJCJ74rmYHgqxTU87KUFdqMgXFSBG7pYlTIQ5X0vdFettmP4DjSVLbSa2fzUZi83o84BvXRKbd/5G89s1LdJUVLaUQaZV3LSJCPGug+kXMdGSAAllv07/RnBYjR42usHH6TtxWbH5z5uGgIWUNbnaXKWxZhUBgD4mgFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LxfpmDlmboWjiVB5zRVIQwJokWhCM4I8spHORGeD0qY=; b=MPnj50sSF5bczIZ2xgzMLzVPBcURHY4DpU2LGi+4nVPur4QeP8Ahb6LzOvaFFEGLv3Uyz8mO8JtfKk+fl3YKHPhByEmAGEq0g6Uk9wCV2uEvCnKQtH3F0IOCnB8TbfkdGT+A2pEmLIsI4BnSVa0CLOqCyPvylY8Cq9N7NSDpjhrDuwjhpY007hxqe0peAMB/or8pm9g1Agr0rSuVyOfR/n+VlZP37OjPBOMtGYi03H4q5+j87F4d0eJ5LLp9Gq3oMiSzMaosdMoozyv1P50tvjwTgTDYGeDhPT4FywNM300yoAK/KlRIn/LfJ0sCg/imei0lsKlBxAmvjiQqs3rhmw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LxfpmDlmboWjiVB5zRVIQwJokWhCM4I8spHORGeD0qY=; b=LzGeI9km4zQLOhtbApvKO878FVNhWb7twoCW7w2c5zJ+M9YcFriaiZ+Ts1AxQpG8wZasUCU5qdy09uLcVKhOCj04h7qxBNth2yeG8HXakpxcSuGKTp38axJL2UgLSW5ngfniCzpbKgW0yPpCyN/hQhtsfL5XQ5TFiiIfUqxrvxOz9JK2sTymnGLj4+pVadWLF2bEepq1lisy/mwVIgamyWxRxENZmmEnWgeV+uJ8NM9LBy/NDu73deWR9L8uaVOwGqp7UNhlEpLRfbLeINSDqGlUXye0p6pNM8GQyk/tuOxop+XBANe2WXPKdxF/aldkS+0qtMtpsOapbeXNbR4kkw== Received: from CY8PR22CA0014.namprd22.prod.outlook.com (2603:10b6:930:45::23) by SJ0PR12MB6879.namprd12.prod.outlook.com (2603:10b6:a03:484::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Fri, 13 Jan 2023 18:09:31 +0000 Received: from CY4PEPF0000C985.namprd02.prod.outlook.com (2603:10b6:930:45:cafe::b) by CY8PR22CA0014.outlook.office365.com (2603:10b6:930:45::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.16 via Frontend Transport; Fri, 13 Jan 2023 18:09:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000C985.mail.protection.outlook.com (10.167.241.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.11 via Frontend Transport; Fri, 13 Jan 2023 18:09:31 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Fri, 13 Jan 2023 10:09:23 -0800 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Fri, 13 Jan 2023 10:09:23 -0800 Received: from mtl123.mtl.labs.mlnx (10.127.8.10) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36 via Frontend Transport; Fri, 13 Jan 2023 10:09:22 -0800 Received: from sw-mtx-061.mtx.labs.mlnx (sw-mtx-061.mtx.labs.mlnx [10.9.153.25]) by mtl123.mtl.labs.mlnx (8.14.4/8.14.4) with ESMTP id 30DI9FcT032345; Fri, 13 Jan 2023 20:09:20 +0200 From: Bodong Wang To: Subject: [SRU][F:linux-bluefield][PATCH 3/4] net: push code from net notifier reg/unreg into helpers Date: Fri, 13 Jan 2023 20:09:14 +0200 Message-ID: <20230113180915.426904-4-bodong@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230113180915.426904-1-bodong@nvidia.com> References: <20230113180915.426904-1-bodong@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000C985:EE_|SJ0PR12MB6879:EE_ X-MS-Office365-Filtering-Correlation-Id: b65d87f0-8601-4a88-9690-08daf591517f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RBfHRfu6cQuvsR7rNGrIXHw/zi6Lbdiq5E0ZFJpAnz21egz0FKSqhyE1AfgosA9YpkJe4qzzDeAo3P18r0dhC5Wk01HoVJSAyyzuafTn0VjCL3vhDs4Oe0LPw5sE79t989YOJIVygs8tNLm3KKYC9ZJqviJuJEjh3CxmIxuIurn5PzeoHaWHGpT6ufBGpKE7ictq9QwH1qfQ9lTXbFsobBj6U3hgOGL2x54F1ARucsbYcx0zvdp3C3pOBdA+CbBJ3oE3DWxqL1fom3ALuOaPE8/3eI4sKIgoPJRiY24Z+ciJtOkrszPVMmmujm/sIaPmMfxkmgx5wRcXump/81fFvxbwGhvhhKl3JyqI9UMUUpst8NPaErafs2KLVlJtKoEZxBRAb7iKfMpRZU2E2MnnTeY9AuAv7+fJZ/dSfpvIUUwiboECWijrKYC+SAXNhpMBTNsQqT+pRhtKBeYPus2uwOyKdMtKzbTC8KextgY/ikaS4idvQ5IKURK4/8Pr79s0ZC/FDOZeoCnO0Xzpda5sJRTBwmxG8bwHCUZPp0DD/uVgDSPmAuG3pAMq55qIXjGyf+8bKyZltH41xuisy8MPzBui11knXwTWdDl3aFJozGZcrQ6vlNZKP6DHOJH8+y+vVy9jIN1kSfmXuhTe++dbwyGwGRN9LIoLah6KWFxUjenTK95K/MnFG9Qx0giuO7ThvgvlpWYUu6h+DQOdFbFNhE7/gYFabZjxEUXEqF+OBrHb1opypib/aAgV8kGEc/9If8N35ZpYfwCxDzV8VqJmGEC8RtX6bAEDW/30wH3bE8I= X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230022)(4636009)(376002)(136003)(39860400002)(396003)(346002)(451199015)(36840700001)(46966006)(40470700004)(2906002)(966005)(107886003)(26005)(6666004)(186003)(478600001)(8676002)(40480700001)(83380400001)(2616005)(70586007)(36756003)(1076003)(316002)(6916009)(54906003)(336012)(47076005)(70206006)(40460700003)(4326008)(41300700001)(82740400003)(7636003)(86362001)(36860700001)(82310400005)(8936002)(5660300002)(356005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jan 2023 18:09:31.1788 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b65d87f0-8601-4a88-9690-08daf591517f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000C985.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6879 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad@nvidia.com, bodong@nvidia.com, feliu@nvidia.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jiri Pirko BugLink: https://bugs.launchpad.net/bugs/2002361 Push the code which is done under rtnl lock in net notifier register and unregister function into separate helpers. Signed-off-by: Jiri Pirko Signed-off-by: David S. Miller (cherry picked from commit 1f637703d8b63f1ba411b4c798e998e3f828b6cb) Signed-off-by: Bodong Wang --- net/core/dev.c | 60 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 58cf313c6bea..9916229aec71 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1680,6 +1680,42 @@ int unregister_netdevice_notifier(struct notifier_block *nb) } EXPORT_SYMBOL(unregister_netdevice_notifier); +static int __register_netdevice_notifier_net(struct net *net, + struct notifier_block *nb, + bool ignore_call_fail) +{ + int err; + + err = raw_notifier_chain_register(&net->netdev_chain, nb); + if (err) + return err; + if (dev_boot_phase) + return 0; + + err = call_netdevice_register_net_notifiers(nb, net); + if (err && !ignore_call_fail) + goto chain_unregister; + + return 0; + +chain_unregister: + raw_notifier_chain_unregister(&net->netdev_chain, nb); + return err; +} + +static int __unregister_netdevice_notifier_net(struct net *net, + struct notifier_block *nb) +{ + int err; + + err = raw_notifier_chain_unregister(&net->netdev_chain, nb); + if (err) + return err; + + call_netdevice_unregister_net_notifiers(nb, net); + return 0; +} + /** * register_netdevice_notifier_net - register a per-netns network notifier block * @net: network namespace @@ -1700,23 +1736,9 @@ int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb) int err; rtnl_lock(); - err = raw_notifier_chain_register(&net->netdev_chain, nb); - if (err) - goto unlock; - if (dev_boot_phase) - goto unlock; - - err = call_netdevice_register_net_notifiers(nb, net); - if (err) - goto chain_unregister; - -unlock: + err = __register_netdevice_notifier_net(net, nb, false); rtnl_unlock(); return err; - -chain_unregister: - raw_notifier_chain_unregister(&netdev_chain, nb); - goto unlock; } EXPORT_SYMBOL(register_netdevice_notifier_net); @@ -1742,13 +1764,7 @@ int unregister_netdevice_notifier_net(struct net *net, int err; rtnl_lock(); - err = raw_notifier_chain_unregister(&net->netdev_chain, nb); - if (err) - goto unlock; - - call_netdevice_unregister_net_notifiers(nb, net); - -unlock: + err = __unregister_netdevice_notifier_net(net, nb); rtnl_unlock(); return err; } From patchwork Fri Jan 13 18:09:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodong Wang X-Patchwork-Id: 1726326 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=VZlELvaH; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NtqFV5q4Tz23dq for ; Sat, 14 Jan 2023 05:09:50 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pGOUo-0002Wz-03; Fri, 13 Jan 2023 18:09:42 +0000 Received: from mail-dm6nam04on2048.outbound.protection.outlook.com ([40.107.102.48] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pGOUl-0002R0-SS for kernel-team@lists.ubuntu.com; Fri, 13 Jan 2023 18:09:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cR6QnwyOWO/vm1c+l7ITpi1UqsaRqjejUw6R3KD7jaEz/0a1QlnCiVkP5wyu2/M7LjxoS4AJeQH9rXgCgjpDBWFRrX5kTPbicq/Z5+GqJbFaQjwRNgYldTpxR4XD9atmMlsCfTx+jH+fazYRyeANRRsErTvlPuKUEo5Tqjfi3wqCl2XK+YsruFUv/Z+qQtLE39Z708QDfra7eUyjC2C9VIRGOObNixrD5fcQ4ad3uh/DKvFtzomLGHwrWlCjfgrTpRkPEAYTXJvon9tw9HbFrRvNSDOqdlRztY8jiucVUFQ89X+ev9VV7RQ03lFjSkwd3kgV8wwRfltOEmbTXRz6Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=A/C46PJ7pMBtkKo0U/9IZbsqUZHyQ6OmDCeGwylcis8=; b=d1OPmxWd+mFeybQaa3z+TCVGm9p8mGvriXMgEP3bdIVS9WM85HDBWnUU135VERfnfD3+/88rStt6cPZJ/l2Nt7MImGu8tjIn72lQ5vXFvwW/MKB4BHiE6XMWW+Buedbe3R1Si8Aq47QsHEMOQz2goSXs9f1tGZFFCRZf5tnRT+qQcXkJDpfXjDCLg/2HVYxOqmaKYPL6wLBdyaSRrX+hmgiTzARQnzRO40pHAy8UFfS7Fnun8fJS6p1wkX8WcB++kl4HMKUk6ZqScibOAm9nefaMNRCqulq04xrbwXzELVUibusZCTzBP0oG1NA7YpJaEbo307KsrAXybb25gm67hw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=A/C46PJ7pMBtkKo0U/9IZbsqUZHyQ6OmDCeGwylcis8=; b=VZlELvaHmRM+1ztN3yjyVfM/ftnFSbln8oQf1+NJcozIRjsMkcWKIgAF82URXI16s7IRloAfdOB/pH3MEEmxGJ42YycFFyO4qo4SXbug8VWLY4UrRrV9FbIAom5Mt0m1MFi/9bg1JJ7frAXVjwxHfDuHzDgCjfr8f5PtfakHDWsLZwK52svW1EloeNIpxzneOX5SdrerqeWr8K1HBUHsfndlbSd3FHG6t+97GtEMxpLI3qygdOFTmPYXYG+Gm5zYn2ey2ksOFWMLZ1HylcoP057yBml5YE7bo0qpdKvyHlMBfVHt20VFnwg3v7ObvaVOsgP12AIkSQP7ibqS+t0Fag== Received: from MW4PR03CA0010.namprd03.prod.outlook.com (2603:10b6:303:8f::15) by BL1PR12MB5126.namprd12.prod.outlook.com (2603:10b6:208:312::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.13; Fri, 13 Jan 2023 18:09:37 +0000 Received: from CO1NAM11FT091.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8f:cafe::ba) by MW4PR03CA0010.outlook.office365.com (2603:10b6:303:8f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.16 via Frontend Transport; Fri, 13 Jan 2023 18:09:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CO1NAM11FT091.mail.protection.outlook.com (10.13.175.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.13 via Frontend Transport; Fri, 13 Jan 2023 18:09:36 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Fri, 13 Jan 2023 10:09:24 -0800 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Fri, 13 Jan 2023 10:09:24 -0800 Received: from mtl123.mtl.labs.mlnx (10.127.8.10) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36 via Frontend Transport; Fri, 13 Jan 2023 10:09:23 -0800 Received: from sw-mtx-061.mtx.labs.mlnx (sw-mtx-061.mtx.labs.mlnx [10.9.153.25]) by mtl123.mtl.labs.mlnx (8.14.4/8.14.4) with ESMTP id 30DI9FcU032345; Fri, 13 Jan 2023 20:09:21 +0200 From: Bodong Wang To: Subject: [SRU][F:linux-bluefield][PATCH 4/4] net: introduce dev_net notifier register/unregister variants Date: Fri, 13 Jan 2023 20:09:15 +0200 Message-ID: <20230113180915.426904-5-bodong@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230113180915.426904-1-bodong@nvidia.com> References: <20230113180915.426904-1-bodong@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT091:EE_|BL1PR12MB5126:EE_ X-MS-Office365-Filtering-Correlation-Id: 9e33777b-0720-46fe-82cd-08daf59154e6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7gTKal51MduZXdBJaNHcT4t4emSQkIpLkQP5PQ/aytqi4m2+p7HsuapCSML23EhFdx2KZghKTg2RKUcq08qzQCcxE8G38PfrKawHfVRdqTKWIevL7n17xufSEDj4FMbBZLhsH9ILDL/Irhl32Z3uiL7zl2uzgWLCuacO0iAl/LstbdbmSZqQdCvjxcq26Yzs9rWuRApKR5dGbYFdETrMk0TiDaA11Y8yNmbgNgqSUpVsn7P7DKvW7mxgohY7tj3Nwb8+zLDtG0ULFAYk7++FzJlW9dhLSejGUtBKlqb+ogsqMzBSvdsgGIC/rpkzrl/TliuCLr0asb9/PmN3fIMqJMFhs21/yI0gdFSxYpmtCRf6rGS/mS9EABrimRVGDfI0ID8ue1xVrWkX6Bmk1VBNbiOzVXikMj52bB+s23NpCXNNSTkz0v2Y5OK4HtNOtaIDyMRko+RWVnM3SmshmPPb5P3DUg8A5cwYPITj8UMtADtbLcg8MRlwF+jB0/VqSUxLCOo6Elz2yHzSRk1htrJx055MGbnoxz2aARq0zyGf+9GtlSCNXvWu0NgAxtF+0yVOEQxuqnOkCd59BItX7HgGMtI0QkqO5eR0PWx/W4lgSFtJ+ZVeOqg+H8VD5ZlvM7LWFq+JI3m+KOMemTK3KGeo2EBheLNwR3hbtTT+1r2HpSP2WPwTIG58v6gsEkxH8ia+46GBi+Wu/Dn1RjmT7Iahx4przESzgoNHX2f727GZ8spDPLReKu+IBZ37AApC4XwoPgx3bKOlQLsDLVuBToj8y9dBxCDM6Uy59ozeNyhKWQc= X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230022)(4636009)(396003)(136003)(346002)(39860400002)(376002)(451199015)(36840700001)(46966006)(40470700004)(36860700001)(6666004)(107886003)(36756003)(2906002)(70206006)(5660300002)(8936002)(4326008)(83380400001)(6916009)(8676002)(478600001)(82740400003)(47076005)(966005)(41300700001)(356005)(7636003)(26005)(336012)(70586007)(82310400005)(186003)(40480700001)(1076003)(54906003)(40460700003)(2616005)(86362001)(316002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jan 2023 18:09:36.8083 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9e33777b-0720-46fe-82cd-08daf59154e6 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT091.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5126 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad@nvidia.com, bodong@nvidia.com, feliu@nvidia.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jiri Pirko BugLink: https://bugs.launchpad.net/bugs/2002361 Introduce dev_net variants of netdev notifier register/unregister functions and allow per-net notifier to follow the netdevice into the namespace it is moved to. Signed-off-by: Jiri Pirko Signed-off-by: David S. Miller (cherry picked from commit 93642e14bd50e59b11cf6389ce3fc243e932777a) Signed-off-by: Bodong Wang --- include/linux/netdevice.h | 17 +++++++++++++++ net/core/dev.c | 46 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 73a0c82a2621..6d3c8e9361c0 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -929,6 +929,11 @@ struct devlink; struct tlsdev_ops; +struct netdev_net_notifier { + struct list_head list; + struct notifier_block *nb; +}; + /* * This structure defines the management hooks for network devices. * The following hooks can be defined; unless noted otherwise, they are @@ -1796,6 +1801,10 @@ enum netdev_ml_priv_type { * * @wol_enabled: Wake-on-LAN is enabled * + * @net_notifier_list: List of per-net netdev notifier block + * that follow this device when it is moved + * to another network namespace. + * * FIXME: cleanup struct net_device such that network protocol info * moves out. */ @@ -2088,6 +2097,8 @@ struct net_device { struct lock_class_key addr_list_lock_key; bool proto_down; unsigned wol_enabled:1; + + struct list_head net_notifier_list; }; #define to_net_dev(d) container_of(d, struct net_device, dev) @@ -2543,6 +2554,12 @@ int unregister_netdevice_notifier(struct notifier_block *nb); int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb); int unregister_netdevice_notifier_net(struct net *net, struct notifier_block *nb); +int register_netdevice_notifier_dev_net(struct net_device *dev, + struct notifier_block *nb, + struct netdev_net_notifier *nn); +int unregister_netdevice_notifier_dev_net(struct net_device *dev, + struct notifier_block *nb, + struct netdev_net_notifier *nn); struct netdev_notifier_info { struct net_device *dev; diff --git a/net/core/dev.c b/net/core/dev.c index 9916229aec71..e7c0f35fd5e1 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1770,6 +1770,48 @@ int unregister_netdevice_notifier_net(struct net *net, } EXPORT_SYMBOL(unregister_netdevice_notifier_net); +int register_netdevice_notifier_dev_net(struct net_device *dev, + struct notifier_block *nb, + struct netdev_net_notifier *nn) +{ + int err; + + rtnl_lock(); + err = __register_netdevice_notifier_net(dev_net(dev), nb, false); + if (!err) { + nn->nb = nb; + list_add(&nn->list, &dev->net_notifier_list); + } + rtnl_unlock(); + return err; +} +EXPORT_SYMBOL(register_netdevice_notifier_dev_net); + +int unregister_netdevice_notifier_dev_net(struct net_device *dev, + struct notifier_block *nb, + struct netdev_net_notifier *nn) +{ + int err; + + rtnl_lock(); + list_del(&nn->list); + err = __unregister_netdevice_notifier_net(dev_net(dev), nb); + rtnl_unlock(); + return err; +} +EXPORT_SYMBOL(unregister_netdevice_notifier_dev_net); + +static void move_netdevice_notifiers_dev_net(struct net_device *dev, + struct net *net) +{ + struct netdev_net_notifier *nn; + + list_for_each_entry(nn, &dev->net_notifier_list, list) { + __unregister_netdevice_notifier_net(dev_net(dev), nn->nb); + __register_netdevice_notifier_net(net, nn->nb, true); + } +} + /** * call_netdevice_notifiers_info - call all network notifier blocks * @val: value passed unmodified to notifier function @@ -9827,6 +9869,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, INIT_LIST_HEAD(&dev->adj_list.lower); INIT_LIST_HEAD(&dev->ptype_all); INIT_LIST_HEAD(&dev->ptype_specific); + INIT_LIST_HEAD(&dev->net_notifier_list); #ifdef CONFIG_NET_SCHED hash_init(dev->qdisc_hash); #endif @@ -10089,6 +10132,9 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char kobject_uevent(&dev->dev.kobj, KOBJ_REMOVE); netdev_adjacent_del_links(dev); + /* Move per-net netdevice notifiers that are following the netdevice */ + move_netdevice_notifiers_dev_net(dev, net); + /* Actually switch the network namespace */ dev_net_set(dev, net); dev->ifindex = new_ifindex;