From patchwork Tue Sep 28 12:54:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 12522477 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED7A8C433EF for ; Tue, 28 Sep 2021 12:55:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D086A610FC for ; Tue, 28 Sep 2021 12:55:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240824AbhI1M45 (ORCPT ); Tue, 28 Sep 2021 08:56:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:47592 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240731AbhI1M4z (ORCPT ); Tue, 28 Sep 2021 08:56:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A6CAC610CC; Tue, 28 Sep 2021 12:55:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632833716; bh=MYyuK2Oibf/hpzECOqohcD7fpK/taUOqcg37M8ZQG6c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PCmcw80kihK7PbWq72ZjqNf2Yorh5OmG8UZfW4UPAozrQDjRKDXe9/sbQid8eRnOJ OMeDWsOxOdwfZ76PbXwTSFqthnS4cuaxBjl0elvmJoRIbDolPej5ioCRGYgDyjCJp7 1NOtQIse+9nbAxbIeclYwjX1NtvRp5tBx0ZhTMtaKYcmtAb9doPrcRXs+qmOzwCUJ1 5OQj+7/40nXPXQMCMJRH01hbohl9ovFB6k9saEW6BBL4WFuSdAd275dH+4JaaxVOoP KDLTRPQSSKJFR6PrTlWdFVWtILipMdYaHYqGz1ItrlnVo/H4OJuHEyl5ZhGQ0eXF+P +7RfCheNugCOQ== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org Cc: Antoine Tenart , pabeni@redhat.com, gregkh@linuxfoundation.org, ebiederm@xmission.com, stephen@networkplumber.org, herbert@gondor.apana.org.au, juri.lelli@redhat.com, netdev@vger.kernel.org Subject: [RFC PATCH net-next 1/9] net-sysfs: try not to restart the syscall if it will fail eventually Date: Tue, 28 Sep 2021 14:54:52 +0200 Message-Id: <20210928125500.167943-2-atenart@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210928125500.167943-1-atenart@kernel.org> References: <20210928125500.167943-1-atenart@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Due to deadlocks in the networking subsystem spotted 12 years ago[1], a workaround was put in place[2] to avoid taking the rtnl lock when it was not available and restarting the syscall (back to VFS, letting userspace spin). The following construction is found a lot in the net sysfs and sysctl code: if (!rtnl_trylock()) return restart_syscall(); This can be problematic when multiple userspace threads use such interfaces in a short period, making them to spin a lot. This happens for example when adding and moving virtual interfaces: userspace programs listening on events, such as systemd-udevd and NetworkManager, do trigger actions reading files in sysfs. It gets worse when a lot of virtual interfaces are created concurrently, say when creating containers at boot time. Returning early without hitting the above pattern when the syscall will fail eventually does make things better. While it is not a fix for the issue, it does ease things. [1] https://lore.kernel.org/netdev/49A4D5D5.5090602@trash.net/ https://lore.kernel.org/netdev/m14oyhis31.fsf@fess.ebiederm.org/ and https://lore.kernel.org/netdev/20090226084924.16cb3e08@nehalam/ [2] Rightfully, those deadlocks are *hard* to solve. Signed-off-by: Antoine Tenart --- net/core/net-sysfs.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index f6197774048b..21c3fdeccf20 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -196,6 +196,12 @@ static ssize_t speed_show(struct device *dev, struct net_device *netdev = to_net_dev(dev); int ret = -EINVAL; + /* The check is also done in __ethtool_get_link_ksettings; this helps + * returning early without hitting the trylock/restart below. + */ + if (!netdev->ethtool_ops->get_link_ksettings) + return -EOPNOTSUPP; + if (!rtnl_trylock()) return restart_syscall(); @@ -216,6 +222,12 @@ static ssize_t duplex_show(struct device *dev, struct net_device *netdev = to_net_dev(dev); int ret = -EINVAL; + /* The check is also done in __ethtool_get_link_ksettings; this helps + * returning early without hitting the trylock/restart below. + */ + if (!netdev->ethtool_ops->get_link_ksettings) + return -EOPNOTSUPP; + if (!rtnl_trylock()) return restart_syscall(); @@ -478,6 +490,12 @@ static ssize_t phys_port_id_show(struct device *dev, struct net_device *netdev = to_net_dev(dev); ssize_t ret = -EINVAL; + /* The check is also done in dev_get_phys_port_id; this helps returning + * early without hitting the trylock/restart below. + */ + if (!netdev->netdev_ops->ndo_get_phys_port_id) + return -EOPNOTSUPP; + if (!rtnl_trylock()) return restart_syscall(); @@ -500,6 +518,13 @@ static ssize_t phys_port_name_show(struct device *dev, struct net_device *netdev = to_net_dev(dev); ssize_t ret = -EINVAL; + /* The checks are also done in dev_get_phys_port_name; this helps + * returning early without hitting the trylock/restart below. + */ + if (!netdev->netdev_ops->ndo_get_phys_port_name && + !netdev->netdev_ops->ndo_get_devlink_port) + return -EOPNOTSUPP; + if (!rtnl_trylock()) return restart_syscall(); @@ -522,6 +547,13 @@ static ssize_t phys_switch_id_show(struct device *dev, struct net_device *netdev = to_net_dev(dev); ssize_t ret = -EINVAL; + /* The checks are also done in dev_get_phys_port_name; this helps + * returning early without hitting the trylock/restart below. + */ + if (!netdev->netdev_ops->ndo_get_port_parent_id && + !netdev->netdev_ops->ndo_get_devlink_port) + return -EOPNOTSUPP; + if (!rtnl_trylock()) return restart_syscall(); @@ -1226,6 +1258,12 @@ static ssize_t tx_maxrate_store(struct netdev_queue *queue, if (!capable(CAP_NET_ADMIN)) return -EPERM; + /* The check is also done later; this helps returning early without + * hitting the trylock/restart below. + */ + if (!dev->netdev_ops->ndo_set_tx_maxrate) + return -EOPNOTSUPP; + err = kstrtou32(buf, 10, &rate); if (err < 0) return err; From patchwork Tue Sep 28 12:54:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 12522479 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7FA9C433F5 for ; Tue, 28 Sep 2021 12:55:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A16BF611CC for ; Tue, 28 Sep 2021 12:55:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240839AbhI1M47 (ORCPT ); Tue, 28 Sep 2021 08:56:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:47642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240731AbhI1M46 (ORCPT ); Tue, 28 Sep 2021 08:56:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8689A611BD; Tue, 28 Sep 2021 12:55:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632833719; bh=8cLfolrANnusajxe/rQ7Xw6RsowFwoRI5G/COp4LbYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UpLWhZgE34MhcFNjfzcoavbIOF/5gZsjyLM9fdeJSZUzSjCN1HApRbc18meFQNS2W K2PUbLVxlmuQrIe9tWbCkWhMMKgm+w+2Z/DwzPYPW9ZM7Gu8wHcKyuwhPXNHPzarmS Kzn5TVIsUdrGTP72X6He5bFMuW9jSu4rNXSVhd0hHOakVEO3ELaAGWUxgdwiZitXho oY0ylbuFgiyxaFzxhQGhFD5sIz/Lzk9Fi5Q3jOm5ayFUZ4Dgc7sbuLGhKeJ/2txvir ctdPD72X0JbDYHb3RskuRou1BZtNloISICD9GOxfqf1RrlCVc9scCJNBwCgCp7UqIe J2roJtXM4XjNg== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org Cc: Antoine Tenart , pabeni@redhat.com, gregkh@linuxfoundation.org, ebiederm@xmission.com, stephen@networkplumber.org, herbert@gondor.apana.org.au, juri.lelli@redhat.com, netdev@vger.kernel.org Subject: [RFC PATCH net-next 2/9] net: split unlisting the net device from unlisting its node name Date: Tue, 28 Sep 2021 14:54:53 +0200 Message-Id: <20210928125500.167943-3-atenart@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210928125500.167943-1-atenart@kernel.org> References: <20210928125500.167943-1-atenart@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This (mostly [*]) cosmetic patch spits the unlisting of the net device from the unlisting of its node name. The two unlisting are still done for now at the same places in the code, keeping the logic. [*] The two removals are now not done in a single dev_base_lock locking section. That is not an issue as insertion/deletion from both lists doesn't have to be atomic from the dev_base_lock point of view. Signed-off-by: Antoine Tenart --- net/core/dev.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/core/dev.c b/net/core/dev.c index fa989ab63f29..2f28b70e5244 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -385,13 +385,21 @@ static void unlist_netdevice(struct net_device *dev) /* Unlink dev from the device chain */ write_lock_bh(&dev_base_lock); list_del_rcu(&dev->dev_list); - netdev_name_node_del(dev->name_node); hlist_del_rcu(&dev->index_hlist); write_unlock_bh(&dev_base_lock); dev_base_seq_inc(dev_net(dev)); } +static void unlist_netdevice_name(struct net_device *dev) +{ + ASSERT_RTNL(); + + write_lock_bh(&dev_base_lock); + netdev_name_node_del(dev->name_node); + write_unlock_bh(&dev_base_lock); +} + /* * Our notifier list */ @@ -11030,6 +11038,7 @@ void unregister_netdevice_many(struct list_head *head) list_for_each_entry(dev, head, unreg_list) { /* And unlink it from device chain. */ unlist_netdevice(dev); + unlist_netdevice_name(dev); dev->reg_state = NETREG_UNREGISTERING; } @@ -11177,6 +11186,7 @@ int __dev_change_net_namespace(struct net_device *dev, struct net *net, /* And unlink it from device chain */ unlist_netdevice(dev); + unlist_netdevice_name(dev); synchronize_net(); From patchwork Tue Sep 28 12:54:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 12522481 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01B19C433F5 for ; Tue, 28 Sep 2021 12:55:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5EE5611EF for ; Tue, 28 Sep 2021 12:55:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240848AbhI1M5C (ORCPT ); Tue, 28 Sep 2021 08:57:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:47708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240833AbhI1M5B (ORCPT ); Tue, 28 Sep 2021 08:57:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4CB98611CA; Tue, 28 Sep 2021 12:55:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632833721; bh=Bs156pJycha/DaevpmnOzmirXa2QBzO5NvHuZENnSDM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=icH0aIFynQNIB0b4pC7X/A/hG6WHQfevSUvodBgQTTOIyzoYDWYE4Y8hACe6iATJ1 yxlRgsVUmLgZxbOEEZJNMR3IBYZQo5zdICaTWt19YdOsLf7zjjtaJqHvIhbhqpw28H eSIam78Mi0PMJpsCShULcVfJQ059kj9vHqdgsPkjKmil5fAl68rVIhqWxthyXhETmi 4u0meEuEN/jYgv4cKPQ+ukqz5WbCk6rE0oB2r1AG3JTvHRjFSLbSy0FfVJced5K139 vjUZXirP35KmVaY1UW9kE2WB09Dj2LMttpE6RpCZFruEvGKJuPv0R1CdEQPJkBfdTU hPYwvGzxxMXtw== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org Cc: Antoine Tenart , pabeni@redhat.com, gregkh@linuxfoundation.org, ebiederm@xmission.com, stephen@networkplumber.org, herbert@gondor.apana.org.au, juri.lelli@redhat.com, netdev@vger.kernel.org Subject: [RFC PATCH net-next 3/9] net: export netdev_name_node_lookup Date: Tue, 28 Sep 2021 14:54:54 +0200 Message-Id: <20210928125500.167943-4-atenart@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210928125500.167943-1-atenart@kernel.org> References: <20210928125500.167943-1-atenart@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Export netdev_name_node_lookup for use outside of net/core/dev.c. Prior to this __dev_get_by_name was used for both name collision detection and to retrieve a net device reference. We now want to allow a difference in behaviour between the two, hence exporting netdev_name_node_lookup. (It will be used in the next commits). Signed-off-by: Antoine Tenart --- include/linux/netdevice.h | 2 ++ net/core/dev.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index d79163208dfd..f8dae47b9aa8 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2955,6 +2955,8 @@ struct net_device *__dev_get_by_flags(struct net *net, unsigned short flags, struct net_device *dev_get_by_name(struct net *net, const char *name); struct net_device *dev_get_by_name_rcu(struct net *net, const char *name); struct net_device *__dev_get_by_name(struct net *net, const char *name); +struct netdev_name_node *netdev_name_node_lookup(struct net *net, + const char *name); int dev_alloc_name(struct net_device *dev, const char *name); int dev_open(struct net_device *dev, struct netlink_ext_ack *extack); void dev_close(struct net_device *dev); diff --git a/net/core/dev.c b/net/core/dev.c index 2f28b70e5244..bfe17a264d6c 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -279,8 +279,8 @@ static void netdev_name_node_del(struct netdev_name_node *name_node) hlist_del_rcu(&name_node->hlist); } -static struct netdev_name_node *netdev_name_node_lookup(struct net *net, - const char *name) +struct netdev_name_node *netdev_name_node_lookup(struct net *net, + const char *name) { struct hlist_head *head = dev_name_hash(net, name); struct netdev_name_node *name_node; @@ -290,6 +290,7 @@ static struct netdev_name_node *netdev_name_node_lookup(struct net *net, return name_node; return NULL; } +EXPORT_SYMBOL(netdev_name_node_lookup); static struct netdev_name_node *netdev_name_node_lookup_rcu(struct net *net, const char *name) From patchwork Tue Sep 28 12:54:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 12522483 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C33D7C433FE for ; Tue, 28 Sep 2021 12:55:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A78F7611CC for ; Tue, 28 Sep 2021 12:55:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240849AbhI1M5H (ORCPT ); Tue, 28 Sep 2021 08:57:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:47782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240841AbhI1M5E (ORCPT ); Tue, 28 Sep 2021 08:57:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 45413611C3; Tue, 28 Sep 2021 12:55:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632833724; bh=KsFqiEy9aWDPlVhl7llh9H8jF/gcHv/Mi5pL+JtQQnY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lg5qsnJdNLMqmtb5fWCRVp8GRseKQH6j8nrPWXiVfTcBEd9aPFjZ474/2ICkA1+kY QCiV68D1p4pMisFOtjj+5v+ydT5drPtQN++5bTHnUe4wPH1Q1nPEoLzpXul6cVD4zH ob1LoorVsQnbOm3Q0OIUXZzoaBc/HtNJzAEc24Owy1KAoEUMgsdUOng86dCpBYNVs8 Bna66B5eeMd25FfbEBxTJGcQ4y5p/OXq4Y2qZr6XWmEzGK0RMco/Jwrv7eRsLGgAiu gNMrubuGuQrLWPvz6vjuehgp5+qWJReT39srTcpj51IxSicQsA3cYD/f+fDH41GFui f/t6UTnomRRkQ== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org Cc: Antoine Tenart , pabeni@redhat.com, gregkh@linuxfoundation.org, ebiederm@xmission.com, stephen@networkplumber.org, herbert@gondor.apana.org.au, juri.lelli@redhat.com, netdev@vger.kernel.org Subject: [RFC PATCH net-next 4/9] bonding: use the correct function to check for netdev name collision Date: Tue, 28 Sep 2021 14:54:55 +0200 Message-Id: <20210928125500.167943-5-atenart@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210928125500.167943-1-atenart@kernel.org> References: <20210928125500.167943-1-atenart@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC netdev_name_node_lookup and __dev_get_by_name have two distinct aims, one helps in name collision detection, while the other is used to retrieve a reference to a net device from its name. Here in bond_create_sysfs we want to check for a name collision, hence use the correct function. (The behaviour of the two functions was similar but will change in the next commits). Signed-off-by: Antoine Tenart --- drivers/net/bonding/bond_sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c index b9e9842fed94..8260bf941ca3 100644 --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c @@ -811,8 +811,8 @@ int bond_create_sysfs(struct bond_net *bn) */ if (ret == -EEXIST) { /* Is someone being kinky and naming a device bonding_master? */ - if (__dev_get_by_name(bn->net, - class_attr_bonding_masters.attr.name)) + if (netdev_name_node_lookup(bn->net, + class_attr_bonding_masters.attr.name)) pr_err("network device named %s already exists in sysfs\n", class_attr_bonding_masters.attr.name); ret = 0; From patchwork Tue Sep 28 12:54:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 12522485 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5629C433EF for ; Tue, 28 Sep 2021 12:55:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B941061209 for ; Tue, 28 Sep 2021 12:55:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240855AbhI1M5I (ORCPT ); Tue, 28 Sep 2021 08:57:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:47842 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240852AbhI1M5H (ORCPT ); Tue, 28 Sep 2021 08:57:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 257C8611F2; Tue, 28 Sep 2021 12:55:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632833727; bh=fM6tqvUHtXgbjxtWtxna9zDvOYzYTwynikJGkmmVJ20=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AcTL0vOcGNB4uKcnoWA0fO869N76RZyCb5/N2GidT88pnhbsMutwDG5vxglWObpOb LX9fE/Kh5Krcb1PtPYBeZHqoHF8euJznrkilnZdNY3M3PFPs2+r7H2Q46pFjnB5/ET yrSVu8zsc/iQiA9F860obr3nx5FZdbrx1IDHMXCejhosFeNyHHq6oT0HoV0//yBONR tb4q3O/RP4k13yjYRaA+tWDkCEE5ypqGG/Y0l0vjVYoUi5Pq8eIdqKlMowHsAUF22/ EpNlrpJdxLd57WLmGz5Di//EYiAV7GLLmPAsJIwxgW9sQZikCmvt3epSCvmW2/8Q6P zVHRIM4NGMTnw== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org Cc: Antoine Tenart , pabeni@redhat.com, gregkh@linuxfoundation.org, ebiederm@xmission.com, stephen@networkplumber.org, herbert@gondor.apana.org.au, juri.lelli@redhat.com, netdev@vger.kernel.org Subject: [RFC PATCH net-next 5/9] ppp: use the correct function to check for netdev name collision Date: Tue, 28 Sep 2021 14:54:56 +0200 Message-Id: <20210928125500.167943-6-atenart@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210928125500.167943-1-atenart@kernel.org> References: <20210928125500.167943-1-atenart@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC netdev_name_node_lookup and __dev_get_by_name have two distinct aims, one helps in name collision detection, while the other is used to retrieve a reference to a net device from its name. Here in ppp_unit_register we want to check for a name collision, hence use the correct function. (The behaviour of the two functions was similar but will change in the next commits). Signed-off-by: Antoine Tenart --- drivers/net/ppp/ppp_generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c index fb52cd175b45..c3e2f4da9949 100644 --- a/drivers/net/ppp/ppp_generic.c +++ b/drivers/net/ppp/ppp_generic.c @@ -1161,7 +1161,7 @@ static int ppp_unit_register(struct ppp *ppp, int unit, bool ifname_is_set) if (!ifname_is_set) { while (1) { snprintf(ppp->dev->name, IFNAMSIZ, "ppp%i", ret); - if (!__dev_get_by_name(ppp->ppp_net, ppp->dev->name)) + if (!netdev_name_node_lookup(ppp->ppp_net, ppp->dev->name)) break; unit_put(&pn->units_idr, ret); ret = unit_get(&pn->units_idr, ppp, ret + 1); From patchwork Tue Sep 28 12:54:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 12522487 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41872C433F5 for ; Tue, 28 Sep 2021 12:55:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2A18961246 for ; Tue, 28 Sep 2021 12:55:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240860AbhI1M5M (ORCPT ); Tue, 28 Sep 2021 08:57:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:47924 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240858AbhI1M5J (ORCPT ); Tue, 28 Sep 2021 08:57:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 04D2561206; Tue, 28 Sep 2021 12:55:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632833730; bh=Ag2p0eQmaQKoD0RHMA3spX+uYqTTNv/FMT+QUF+zdoQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oP4Yn7ao/g3qLtDa5Y4cXNU5oGaAqfbRb17buGT+jT3vmI8sY6FXrIyEz8GKTOZG3 wLlWQU7TMOH47JxzP6ZNN8O31djVpmbLqVU8RoIG5W5mymOlcyfDOiDldiPqZLkUNn H1+uGYuZIeJ9R6KD0fpVQY6tiM9/NANkD5KlobwwayxNxo2gDmEf8TsHZECruNVnVf FZD6hYXHkrbWNgaS9D5r4yYImJu34uwGb0ck4GaRNmfdLxnTs7/OZbXj7MiP9tNGnA ddgLtf50csf7WYrKzISq8zYr+jWRCkGMDpZHt1gFr1MntN4Eni77qDUVqIe2dcF+84 6dN5D5bBwbvnw== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org Cc: Antoine Tenart , pabeni@redhat.com, gregkh@linuxfoundation.org, ebiederm@xmission.com, stephen@networkplumber.org, herbert@gondor.apana.org.au, juri.lelli@redhat.com, netdev@vger.kernel.org Subject: [RFC PATCH net-next 6/9] net: use the correct function to check for netdev name collision Date: Tue, 28 Sep 2021 14:54:57 +0200 Message-Id: <20210928125500.167943-7-atenart@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210928125500.167943-1-atenart@kernel.org> References: <20210928125500.167943-1-atenart@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC netdev_name_node_lookup and __dev_get_by_name have two distinct aims, one helps in name collision detection, while the other is used to retrieve a reference to a net device from its name. Fix the callers checking for a name collision. (The behaviour of the two functions was similar but will change in the next commits). Signed-off-by: Antoine Tenart --- net/core/dev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index bfe17a264d6c..02f9d505dbe2 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1142,7 +1142,7 @@ static int __dev_alloc_name(struct net *net, const char *name, char *buf) } snprintf(buf, IFNAMSIZ, name, i); - if (!__dev_get_by_name(net, buf)) + if (!netdev_name_node_lookup(net, buf)) return i; /* It is possible to run out of possible slots @@ -1196,7 +1196,7 @@ static int dev_get_valid_name(struct net *net, struct net_device *dev, if (strchr(name, '%')) return dev_alloc_name_ns(net, dev, name); - else if (__dev_get_by_name(net, name)) + else if (netdev_name_node_lookup(net, name)) return -EEXIST; else if (dev->name != name) strlcpy(dev->name, name, IFNAMSIZ); @@ -11164,7 +11164,7 @@ int __dev_change_net_namespace(struct net_device *dev, struct net *net, * we can use it in the destination network namespace. */ err = -EEXIST; - if (__dev_get_by_name(net, dev->name)) { + if (netdev_name_node_lookup(net, dev->name)) { /* We get here if we can't use the current device name */ if (!pat) goto out; @@ -11518,7 +11518,7 @@ static void __net_exit default_device_exit(struct net *net) /* Push remaining network devices to init_net */ snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex); - if (__dev_get_by_name(&init_net, fb_name)) + if (netdev_name_node_lookup(&init_net, fb_name)) snprintf(fb_name, IFNAMSIZ, "dev%%d"); err = dev_change_net_namespace(dev, &init_net, fb_name); if (err) { From patchwork Tue Sep 28 12:54:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 12522489 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C887C433FE for ; Tue, 28 Sep 2021 12:55:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0466561215 for ; Tue, 28 Sep 2021 12:55:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240858AbhI1M5N (ORCPT ); Tue, 28 Sep 2021 08:57:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:47968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240852AbhI1M5M (ORCPT ); Tue, 28 Sep 2021 08:57:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D820961209; Tue, 28 Sep 2021 12:55:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632833733; bh=Fs3VNYn5umW+YMZuXLhjRbr7s55rOpQRQOxWbxeldn8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GIc7SzL/bSu4rmJn5/M5u0rCdv5W5jE5ko4AB4ACZI95zdiE0oCaHd4kHwoY6eoe/ HViPGT+maGAj93oPnKpnTgmnjzcN1pGZkh06XdBA87uSqgcXRGMli7Ds3NhDhOah8g AJ98WQzTRRGLDzPu+g/MbFKso5Uw6RqB6Kgt7cQMbBsZrGNNAbtRGvr6Ymphr7F61R gTWRUHxYHQ5xiKnIf3hGcEGYOA6tfxzPc7w+ohURrw7lTNjc2tMS4JnNd38cKUbetu RRcgKPy9b+aneFHa2uBCxMZo6+9aujEGzcbz3MjWSp3h9OOlLHLh/2py0IPfJZK/Wt Iij2D0+j5B2cw== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org Cc: Antoine Tenart , pabeni@redhat.com, gregkh@linuxfoundation.org, ebiederm@xmission.com, stephen@networkplumber.org, herbert@gondor.apana.org.au, juri.lelli@redhat.com, netdev@vger.kernel.org Subject: [RFC PATCH net-next 7/9] net: delay the removal of the name nodes until run_todo Date: Tue, 28 Sep 2021 14:54:58 +0200 Message-Id: <20210928125500.167943-8-atenart@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210928125500.167943-1-atenart@kernel.org> References: <20210928125500.167943-1-atenart@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Keep the node name collision detection working until the last registration stage, by delaying the removal of the name nodes in run_todo. This allows to perform unregistration operations being sensitive to name collisions, in run_todo. As run_todo has sections of code running without the rtnl lock taken, this will allow to perform some of those operations not under this lock (when possible). While we move the removal of the name node until a late unregistration stage, we still want to avoid returning a net device reference when it's being unregistered (calling __dev_get_by_name for example). We keep this logic by setting the node name dev reference to NULL. This follows the logic of __dev_get_by_name. Altnames are in the same list, they are not special here. From now on we have to be strict on the use of __dev_get_by_name vs netdev_name_node_lookup. One is designed to get the device, the other one to lookup in the list of currently reserved names. Current users should have been fixed by previous patches. One side effect is there is now a window between unregistering the netdevice and running the todo where names are still reserved and can't be used for new device creation. Signed-off-by: Antoine Tenart --- net/core/dev.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 02f9d505dbe2..a1eab120bb50 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10611,10 +10611,15 @@ void netdev_run_todo(void) if (dev->needs_free_netdev) free_netdev(dev); - /* Report a network device has been unregistered */ rtnl_lock(); + unlist_netdevice_name(dev); + synchronize_net(); + netdev_name_node_free(dev->name_node); + dev_net(dev)->dev_unreg_count--; __rtnl_unlock(); + + /* Report a network device has been unregistered */ wake_up(&netdev_unregistering_wq); /* Free network device */ @@ -11039,7 +11044,12 @@ void unregister_netdevice_many(struct list_head *head) list_for_each_entry(dev, head, unreg_list) { /* And unlink it from device chain. */ unlist_netdevice(dev); - unlist_netdevice_name(dev); + + /* Unreference the net device from the node name. From this + * point on the node name is only used for naming collision + * detection. + */ + dev->name_node->dev = NULL; dev->reg_state = NETREG_UNREGISTERING; } @@ -11072,7 +11082,6 @@ void unregister_netdevice_many(struct list_head *head) dev_mc_flush(dev); netdev_name_node_alt_flush(dev); - netdev_name_node_free(dev->name_node); if (dev->netdev_ops->ndo_uninit) dev->netdev_ops->ndo_uninit(dev); From patchwork Tue Sep 28 12:54:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 12522491 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37D53C433F5 for ; Tue, 28 Sep 2021 12:55:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 223B86124B for ; Tue, 28 Sep 2021 12:55:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240868AbhI1M5Q (ORCPT ); Tue, 28 Sep 2021 08:57:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:48046 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240852AbhI1M5P (ORCPT ); Tue, 28 Sep 2021 08:57:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B83EB6120D; Tue, 28 Sep 2021 12:55:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632833736; bh=jB/QpcfxY9y6Dmusvk7HAqbu8vgl9cqrzA7TMCLGhHI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t66YjspOHwZxtfV15xwYG188/MswDWJTGbmujXPE7G7/2TiSL5P0kWn7vdR3VD1s1 99kyrBeEqMhUrQjp+YBpgMRbJKaQTOUMbTbSdtRbUtkkFWtH80vWcT7bV9s1OL8e5C bzo5vlqtX3jR9isUK//AWIWPZMaEFyQPvwqha+twVRbGdLPfVZuU3rlYwAd9Hh0Tuz 6PJEw5cm+qmpNhRKwqEhwysXDQM9INrtfWWC3qaXeTaKLQfwEehcGnVbeX+PnKsYF0 UCVsIm40zGPk/QGIvScFrESer5sNCjDMVYhopgkxF48AJVUValAYd4UVGNDe3tgEDv sPBNoejNwJRUg== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org Cc: Antoine Tenart , pabeni@redhat.com, gregkh@linuxfoundation.org, ebiederm@xmission.com, stephen@networkplumber.org, herbert@gondor.apana.org.au, juri.lelli@redhat.com, netdev@vger.kernel.org Subject: [RFC PATCH net-next 8/9] net: delay device_del until run_todo Date: Tue, 28 Sep 2021 14:54:59 +0200 Message-Id: <20210928125500.167943-9-atenart@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210928125500.167943-1-atenart@kernel.org> References: <20210928125500.167943-1-atenart@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Move the deletion of the device from unregister_netdevice_many to netdev_run_todo and move it outside the rtnl lock. 12 years ago was reported an ABBA deadlock between net-sysfs and the netdevice unregistration[1]. The issue was the following: A B unregister_netdevice_many sysfs access rtnl_lock sysfs refcount rtnl_lock drain sysfs files => waits for B => waits for A This was avoided thanks to two patches[2][3], which used rtnl_trylock in net-sysfs and restarted the syscall when the rtnl lock was already taken. This way kernfs nodes were not blocking the netdevice unregistration anymore. This was fine at the time but is now causing some issues: creating and moving interfaces makes userspace (systemd, NetworkManager or others) to spin a lot as syscalls are restarted, which has an impact on performance. This happens for example when creating pods. While userspace applications could be improved, fixing this in-kernel has the benefit of fixing the root cause of the issue. The sysfs removal is done in device_del, and moving it outside of the rtnl lock does fix the initial deadlock. With that the trylock/restart logic can be removed in a following-up patch. [1] https://lore.kernel.org/netdev/49A4D5D5.5090602@trash.net/ (I'm referencing the full thread but the sysfs issue was discussed later in the thread). [2] 336ca57c3b4e ("net-sysfs: Use rtnl_trylock in sysfs methods.") [3] 5a5990d3090b ("net: Avoid race between network down and sysfs") Co-developed-by: Paolo Abeni Signed-off-by: Antoine Tenart --- net/core/dev.c | 2 ++ net/core/net-sysfs.c | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index a1eab120bb50..d774fbec5d63 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10593,6 +10593,8 @@ void netdev_run_todo(void) continue; } + device_del(&dev->dev); + dev->reg_state = NETREG_UNREGISTERED; netdev_wait_allrefs(dev); diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 21c3fdeccf20..e754f00c117b 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -1955,8 +1955,6 @@ void netdev_unregister_kobject(struct net_device *ndev) remove_queue_kobjects(ndev); pm_runtime_set_memalloc_noio(dev, false); - - device_del(dev); } /* Create sysfs entries for network device. */ From patchwork Tue Sep 28 12:55:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 12522493 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C06D5C433EF for ; Tue, 28 Sep 2021 12:55:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A9C2161266 for ; Tue, 28 Sep 2021 12:55:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240870AbhI1M5U (ORCPT ); Tue, 28 Sep 2021 08:57:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:48096 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240852AbhI1M5S (ORCPT ); Tue, 28 Sep 2021 08:57:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7E07661215; Tue, 28 Sep 2021 12:55:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632833739; bh=f4TymLIZGiKc1reyB92dlJpF9pGSgYjD+LZcAT8XLPM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RLd+ejQEnFRgzT3DvmkVixtjjPAWZxE1S1hJ5i3G6uW/7/J5C70fkLRlyFRwqKiTV AFbo3Mv6zIAQ6IzYENvTG+pkpJhSoEgwcHMVpHobdN/Smz9LVsR6z3KJkTn9UuYHCm haV3ZN31l1IXuDmlNYh/gcRWr1qajII5fzBEZr31ufTE7qmekZkVTKGSo57KUp2Ak6 ShUbkkV1/ZJBB93qkDuR2PDC6uSl9EXlMuPgvgkGqB+LjRT7DJ07954pNw9tEOAF6S e8Yuway5ehzMXYL5rWdzkTuMawBNzppX55ikM0d8z+W12K56l4hW9dDPlW1DvJrRO4 Ty0NnpHMJTi6g== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org Cc: Antoine Tenart , pabeni@redhat.com, gregkh@linuxfoundation.org, ebiederm@xmission.com, stephen@networkplumber.org, herbert@gondor.apana.org.au, juri.lelli@redhat.com, netdev@vger.kernel.org Subject: [RFC PATCH net-next 9/9] net-sysfs: remove the use of rtnl_trylock/restart_syscall Date: Tue, 28 Sep 2021 14:55:00 +0200 Message-Id: <20210928125500.167943-10-atenart@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210928125500.167943-1-atenart@kernel.org> References: <20210928125500.167943-1-atenart@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The ABBA deadlock avoided by using rtnl_trylock and restart_syscall was fixed in previous commits, we can now remove the use of this trylock/restart logic and have net-sysfs operations not spinning when rtnl is already taken. Signed-off-by: Antoine Tenart --- net/core/net-sysfs.c | 95 +++++++------------------------------------- 1 file changed, 14 insertions(+), 81 deletions(-) diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index e754f00c117b..987b32fd8604 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -90,9 +90,7 @@ static ssize_t netdev_store(struct device *dev, struct device_attribute *attr, if (ret) goto err; - if (!rtnl_trylock()) - return restart_syscall(); - + rtnl_lock(); if (dev_isalive(netdev)) { ret = (*set)(netdev, new); if (ret == 0) @@ -196,15 +194,7 @@ static ssize_t speed_show(struct device *dev, struct net_device *netdev = to_net_dev(dev); int ret = -EINVAL; - /* The check is also done in __ethtool_get_link_ksettings; this helps - * returning early without hitting the trylock/restart below. - */ - if (!netdev->ethtool_ops->get_link_ksettings) - return -EOPNOTSUPP; - - if (!rtnl_trylock()) - return restart_syscall(); - + rtnl_lock(); if (netif_running(netdev)) { struct ethtool_link_ksettings cmd; @@ -222,15 +212,7 @@ static ssize_t duplex_show(struct device *dev, struct net_device *netdev = to_net_dev(dev); int ret = -EINVAL; - /* The check is also done in __ethtool_get_link_ksettings; this helps - * returning early without hitting the trylock/restart below. - */ - if (!netdev->ethtool_ops->get_link_ksettings) - return -EOPNOTSUPP; - - if (!rtnl_trylock()) - return restart_syscall(); - + rtnl_lock(); if (netif_running(netdev)) { struct ethtool_link_ksettings cmd; @@ -427,9 +409,7 @@ static ssize_t ifalias_store(struct device *dev, struct device_attribute *attr, if (len > 0 && buf[len - 1] == '\n') --count; - if (!rtnl_trylock()) - return restart_syscall(); - + rtnl_lock(); if (dev_isalive(netdev)) { ret = dev_set_alias(netdev, buf, count); if (ret < 0) @@ -490,15 +470,7 @@ static ssize_t phys_port_id_show(struct device *dev, struct net_device *netdev = to_net_dev(dev); ssize_t ret = -EINVAL; - /* The check is also done in dev_get_phys_port_id; this helps returning - * early without hitting the trylock/restart below. - */ - if (!netdev->netdev_ops->ndo_get_phys_port_id) - return -EOPNOTSUPP; - - if (!rtnl_trylock()) - return restart_syscall(); - + rtnl_lock(); if (dev_isalive(netdev)) { struct netdev_phys_item_id ppid; @@ -518,16 +490,7 @@ static ssize_t phys_port_name_show(struct device *dev, struct net_device *netdev = to_net_dev(dev); ssize_t ret = -EINVAL; - /* The checks are also done in dev_get_phys_port_name; this helps - * returning early without hitting the trylock/restart below. - */ - if (!netdev->netdev_ops->ndo_get_phys_port_name && - !netdev->netdev_ops->ndo_get_devlink_port) - return -EOPNOTSUPP; - - if (!rtnl_trylock()) - return restart_syscall(); - + rtnl_lock(); if (dev_isalive(netdev)) { char name[IFNAMSIZ]; @@ -547,16 +510,7 @@ static ssize_t phys_switch_id_show(struct device *dev, struct net_device *netdev = to_net_dev(dev); ssize_t ret = -EINVAL; - /* The checks are also done in dev_get_phys_port_name; this helps - * returning early without hitting the trylock/restart below. - */ - if (!netdev->netdev_ops->ndo_get_port_parent_id && - !netdev->netdev_ops->ndo_get_devlink_port) - return -EOPNOTSUPP; - - if (!rtnl_trylock()) - return restart_syscall(); - + rtnl_lock(); if (dev_isalive(netdev)) { struct netdev_phys_item_id ppid = { }; @@ -576,9 +530,7 @@ static ssize_t threaded_show(struct device *dev, struct net_device *netdev = to_net_dev(dev); ssize_t ret = -EINVAL; - if (!rtnl_trylock()) - return restart_syscall(); - + rtnl_lock(); if (dev_isalive(netdev)) ret = sprintf(buf, fmt_dec, netdev->threaded); @@ -1214,9 +1166,7 @@ static ssize_t traffic_class_show(struct netdev_queue *queue, if (!netif_is_multiqueue(dev)) return -ENOENT; - if (!rtnl_trylock()) - return restart_syscall(); - + rtnl_lock(); index = get_netdev_queue_index(queue); /* If queue belongs to subordinate dev use its TC mapping */ @@ -1258,18 +1208,11 @@ static ssize_t tx_maxrate_store(struct netdev_queue *queue, if (!capable(CAP_NET_ADMIN)) return -EPERM; - /* The check is also done later; this helps returning early without - * hitting the trylock/restart below. - */ - if (!dev->netdev_ops->ndo_set_tx_maxrate) - return -EOPNOTSUPP; - err = kstrtou32(buf, 10, &rate); if (err < 0) return err; - if (!rtnl_trylock()) - return restart_syscall(); + rtnl_lock(); err = -EOPNOTSUPP; if (dev->netdev_ops->ndo_set_tx_maxrate) @@ -1460,8 +1403,7 @@ static ssize_t xps_cpus_show(struct netdev_queue *queue, char *buf) index = get_netdev_queue_index(queue); - if (!rtnl_trylock()) - return restart_syscall(); + rtnl_lock(); /* If queue belongs to subordinate dev use its map */ dev = netdev_get_tx_queue(dev, index)->sb_dev ? : dev; @@ -1507,11 +1449,7 @@ static ssize_t xps_cpus_store(struct netdev_queue *queue, return err; } - if (!rtnl_trylock()) { - free_cpumask_var(mask); - return restart_syscall(); - } - + rtnl_lock(); err = netif_set_xps_queue(dev, mask, index); rtnl_unlock(); @@ -1531,9 +1469,7 @@ static ssize_t xps_rxqs_show(struct netdev_queue *queue, char *buf) index = get_netdev_queue_index(queue); - if (!rtnl_trylock()) - return restart_syscall(); - + rtnl_lock(); tc = netdev_txq_to_tc(dev, index); rtnl_unlock(); if (tc < 0) @@ -1566,10 +1502,7 @@ static ssize_t xps_rxqs_store(struct netdev_queue *queue, const char *buf, return err; } - if (!rtnl_trylock()) { - bitmap_free(mask); - return restart_syscall(); - } + rtnl_lock(); cpus_read_lock(); err = __netif_set_xps_queue(dev, mask, index, XPS_RXQS);