From patchwork Thu Mar 27 13:56:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14031161 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75B6B215799 for ; Thu, 27 Mar 2025 13:57:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083825; cv=none; b=T6gC8OelGNLI2CJbfp2PoPNKf3NsbECEwJQFYMWfP68GSgyTifkiokzhWRohB5UdhBFEF2ZVwd0uBvL/537v+ALYi5SCuxoN6xvtCUCYiHBEFMmj5SpqsINOhAE+LWbLnTcszQPBujvBwkIehImq91czQbmugt+wHwYeu6FO2II= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083825; c=relaxed/simple; bh=pPFaAHqfz6cidUBHyUpb67Pq1vZfAV2J6zGyohzFVqU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dYtCv0hO+bcp9/HdYbrRedjajhClXKbBImTOgbQlm8kSUdYwtmpbor9mpI6ig7QT7729yG4uCFVIEZUZKn+eVcpP5SPZf2oqUDuzjhXkrvsljL4hqtvoqVm9PLYObAZhm4iKdkDK5Hlio7SK4JMxn0bsvI90EdgekUaCeNY9xa4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-227cf12df27so15114045ad.0 for ; Thu, 27 Mar 2025 06:57:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743083822; x=1743688622; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b3B4DIcH2JGv8yKOtHByBvLXwJNtNg6sNAoCwNYSok4=; b=YNkzfUzJd6TfPCkbKLewp1jdL3cr8JXFSr54vonJzYD1f0Zc00BDNvJnB6QkxpkPFF dKD+zw2uTMCtc4HF4Mr78ZiqKXkOM6p0V2z0pwrJEwUdR6Y9UmxhYzAa7xIGwnsHhZ/x xkWC6zQS9GgX+YZ26Nf9oYISLKgTrILRDU21BHBNfk5ue9neOtoeagLhX2Q4S0DmJKWR aiIBvbFa8AQ9KMj+VUpt8Amka8fUauiFHQ6iU1AwLTPLFWmeso3vv/iiJ4UQj6G0LBzG JJ1ZFvxxCLgB2UOWe8d864z8rXx9l9iR6V4TN/r01Xg6izPDWLwm0EHbHdsq1Op4iju0 PeVA== X-Gm-Message-State: AOJu0YzyrysgulHdsn8SIu7et8NHYU/PBMlLoUuuW6SLxh+YEMoaoKqb GU/pmBMN/wSHKLd1ELzNPVKY35TlMWrzsYSktRgPvepgKnmJ+zo6UZGC+zx0cQ== X-Gm-Gg: ASbGncuJk49oBBCNG0eFNq3HqAa0J3q27ocjh91nnh9+t/Wn8QLRO3sRh0Z20u8BQrr TxfBpSHvSkL7GXuqk11zUOj/p+a/G7E25p2tWxpkJRaVODkEtscS/78lGwJ36if7XeYSkeOzIEt j0vc1bJIYLYEDVaRuxmB7tocpM//ASTN1ps3b/KdTnDhncDh5eSBtOUpBD6XJazsxHlmjAdadD0 VteO67lTcvXP1V6oi+29l+XOhF9FOvbj+ACZ9UtiF/g0rXzi2KwCKquEk7wm4F/rmH2U6h+Pd9I snkxFGCbZOIlUROUNmQ1xXY3I7mCP5GwZEWD2JaCIlmN X-Google-Smtp-Source: AGHT+IHt6DwK9WA7Xf9MIR4Nr+m82LBrzkCgO0ztOnf6ePj2X4cmQN3I/L9/km6eG8NUysSUXXEfDA== X-Received: by 2002:a17:902:ce08:b0:224:3d:2ffd with SMTP id d9443c01a7336-2291ddd8289mr3923185ad.17.1743083821986; Thu, 27 Mar 2025 06:57:01 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-22780f4a075sm127937855ad.100.2025.03.27.06.57.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Mar 2025 06:57:01 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Cosmin Ratiu Subject: [PATCH net v2 01/11] net: switch to netif_disable_lro in inetdev_init Date: Thu, 27 Mar 2025 06:56:49 -0700 Message-ID: <20250327135659.2057487-2-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250327135659.2057487-1-sdf@fomichev.me> References: <20250327135659.2057487-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Cosmin reports the following deadlock: dump_stack_lvl+0x62/0x90 print_deadlock_bug+0x274/0x3b0 __lock_acquire+0x1229/0x2470 lock_acquire+0xb7/0x2b0 __mutex_lock+0xa6/0xd20 dev_disable_lro+0x20/0x80 inetdev_init+0x12f/0x1f0 inetdev_event+0x48b/0x870 notifier_call_chain+0x38/0xf0 netif_change_net_namespace+0x72e/0x9f0 do_setlink.isra.0+0xd5/0x1220 rtnl_newlink+0x7ea/0xb50 rtnetlink_rcv_msg+0x459/0x5e0 netlink_rcv_skb+0x54/0x100 netlink_unicast+0x193/0x270 netlink_sendmsg+0x204/0x450 Switch to netif_disable_lro which assumes the caller holds the instance lock. inetdev_init is called for blackhole device (which sw device and doesn't grab instance lock) and from REGISTER/UNREGISTER notifiers. We already hold the instance lock for REGISTER notifier during netns change and we'll soon hold the lock during other paths. Reported-by: Cosmin Ratiu Fixes: ad7c7b2172c3 ("net: hold netdev instance lock during sysfs operations") Signed-off-by: Stanislav Fomichev Reviewed-by: Jakub Kicinski --- net/core/dev.c | 1 + net/ipv4/devinet.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/net/core/dev.c b/net/core/dev.c index be17e0660144..80523f75ee6b 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1771,6 +1771,7 @@ void netif_disable_lro(struct net_device *dev) netdev_unlock_ops(lower_dev); } } +EXPORT_SYMBOL(netif_disable_lro); /** * dev_disable_gro_hw - disable HW Generic Receive Offload on a device diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 754f60fb6e25..77e5705ac799 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -281,7 +281,7 @@ static struct in_device *inetdev_init(struct net_device *dev) if (!in_dev->arp_parms) goto out_kfree; if (IPV4_DEVCONF(in_dev->cnf, FORWARDING)) - dev_disable_lro(dev); + netif_disable_lro(dev); /* Reference in_dev->dev */ netdev_hold(dev, &in_dev->dev_tracker, GFP_KERNEL); /* Account for reference dev->ip_ptr (below) */ From patchwork Thu Mar 27 13:56:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14031162 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A367F215F6C for ; Thu, 27 Mar 2025 13:57:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083826; cv=none; b=ezstQOtXgnkyzcAZUfVrIRqbn0NaP4uj4sjuaOi07gJQzk6ZWK5gRZFstRQHcYk3sAXU0X6Gq7lEfywvb2WoQcnvuHV45NzA7Q16AH2A5c4fqGSuYbc/bXsuRCHp/lDjbr8B3NVYfIs+UNFqD/wKQr8KpQ2bZPRy0mKPssX5isk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083826; c=relaxed/simple; bh=tm6o/3FxEt4Z+I9o21RZnbS58EvBomkNpdhEpNPWSUI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hZB/YqNIhWuwiGZb/ECaA4WM+K5BlCCmsAiToYEAFezQWXEqsjXqktOa8J7Caeon/nMsctSKJub820q3lGJVc0xBY6EbnEoQ6IM6Z/6s3e2FUq8/s6YtBpcMiqDZp/SQc+iI44l6rStubRjcN4VBrMuSE0KHop3/c/lDukenG44= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-227b650504fso22015785ad.0 for ; Thu, 27 Mar 2025 06:57:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743083823; x=1743688623; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rTKaip8E4PutjEdyQWuPX2ECkZPWrWyOQOPPOifxHHw=; b=A6H0pGLY7TI8jeiaWaWSO38MIuqZigdPcNe3Qaeuhx40xzrbsrbzNMX7/xeX8dwm+M OlxgxphmWO9R69Qgl3xKzvet7588snN1YWgFTwyvZQR2enlvafO+qcmNg0WzmMZ14CSb //2JFn5d1I+OewVh9fStyghSHjWl6oQlupo78ACrJfZ+L0a0B+KtCUyWamODNtZ0Zlpj zUzVRT9rL4ZcHADL/0NLh/Oh74p4L/2aMUnvp/33AZEf6qk/pKdehqct6RHGT0x4LAD9 VZPO6uBLXkU1ZPXl8zPdrrGJ0OnJFzOZLgckzwScGAD/tLrWYxj5SYWEITLh4txCcnkg cfLA== X-Gm-Message-State: AOJu0YycMWKllMEgRSkmwUMWW633djewEJ/A2Tml1Y0sGh7GC19+izzf T/md4BtizBaZ9vOTIVjJyixe/ENTv71uMGXFtDn0D2vSn5U2mjBQ5HTwApRWAw== X-Gm-Gg: ASbGncsZNOu4ETRSyMpTkS9bwjo053bjrq+8Pv+6IrLJf7GYYQtuDx2hkIUODlkDynb BRXRL3xiJ93wDgh2EGLm7+nHsOu5UQ5DGX/7p78w+W/iXv+tBEPo1MQ/TEnglphmi1nHmFOm49t QkiN91LhyKjHkWtfxlg6iS1i7/2yZ9jcdhg+JybZnLulmhzm6oJGTmFC0tidCStrI4DTox7bKmz CGL80PNfICvd+TL2DMRO3HvjuLmI9MdhYqFuXJxn6iK0Y2zTSt4RhEAiWk4q/fQLS4lsViQ5kI9 Xf+8eDG214CEPUO4TnpPeyy0x/Ye1YX6fBxf2IW6lKV8 X-Google-Smtp-Source: AGHT+IG/+S0nX8H4zC9wGq/aebxmJAwNASqowSKOmkxT9NnSzbbU8FFXdyUOy8/LMLPNo+wDyFCpiQ== X-Received: by 2002:a17:902:d511:b0:223:47e4:d288 with SMTP id d9443c01a7336-2280493bf03mr44140515ad.47.1743083823445; Thu, 27 Mar 2025 06:57:03 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-227811c0cb8sm128128565ad.122.2025.03.27.06.57.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Mar 2025 06:57:03 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Cosmin Ratiu Subject: [PATCH net v2 02/11] net: hold instance lock during NETDEV_REGISTER/UP/UNREGISTER Date: Thu, 27 Mar 2025 06:56:50 -0700 Message-ID: <20250327135659.2057487-3-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250327135659.2057487-1-sdf@fomichev.me> References: <20250327135659.2057487-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Callers of inetdev_init can come from several places with inconsistent expectation about netdev instance lock. Grab instance lock during REGISTER (plus UP) and UNREGISTER netdev notifiers. Take extra care in the path that re-registers the notifiers during net namespace move (all the dance with extra 'lock' argument). WARNING: CPU: 10 PID: 1479 at ./include/net/netdev_lock.h:54 __netdev_update_features+0x65f/0xca0 __warn+0x81/0x180 __netdev_update_features+0x65f/0xca0 report_bug+0x156/0x180 handle_bug+0x4f/0x90 exc_invalid_op+0x13/0x60 asm_exc_invalid_op+0x16/0x20 __netdev_update_features+0x65f/0xca0 netif_disable_lro+0x30/0x1d0 inetdev_init+0x12f/0x1f0 inetdev_event+0x48b/0x870 notifier_call_chain+0x38/0xf0 register_netdevice+0x741/0x8b0 register_netdev+0x1f/0x40 mlx5e_probe+0x4e3/0x8e0 [mlx5_core] auxiliary_bus_probe+0x3f/0x90 really_probe+0xc3/0x3a0 __driver_probe_device+0x80/0x150 driver_probe_device+0x1f/0x90 __device_attach_driver+0x7d/0x100 bus_for_each_drv+0x80/0xd0 __device_attach+0xb4/0x1c0 bus_probe_device+0x91/0xa0 device_add+0x657/0x870 Reported-by: Cosmin Ratiu Fixes: ad7c7b2172c3 ("net: hold netdev instance lock during sysfs operations") Signed-off-by: Stanislav Fomichev --- net/core/dev.c | 66 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 80523f75ee6b..019f838f94d8 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1829,6 +1829,8 @@ static int call_netdevice_register_notifiers(struct notifier_block *nb, { int err; + netdev_ops_assert_locked(dev); + err = call_netdevice_notifier(nb, NETDEV_REGISTER, dev); err = notifier_to_errno(err); if (err) @@ -1842,24 +1844,34 @@ static int call_netdevice_register_notifiers(struct notifier_block *nb, } static void call_netdevice_unregister_notifiers(struct notifier_block *nb, - struct net_device *dev) + struct net_device *dev, + struct net_device *locked) { if (dev->flags & IFF_UP) { call_netdevice_notifier(nb, NETDEV_GOING_DOWN, dev); call_netdevice_notifier(nb, NETDEV_DOWN, dev); } + if (dev != locked) + netdev_lock_ops(dev); call_netdevice_notifier(nb, NETDEV_UNREGISTER, dev); + if (dev != locked) + netdev_unlock_ops(dev); } static int call_netdevice_register_net_notifiers(struct notifier_block *nb, - struct net *net) + struct net *net, + struct net_device *locked) { struct net_device *dev; int err; for_each_netdev(net, dev) { + if (locked != dev) + netdev_lock_ops(dev); err = call_netdevice_register_notifiers(nb, dev); + if (locked != dev) + netdev_unlock_ops(dev); if (err) goto rollback; } @@ -1867,17 +1879,18 @@ static int call_netdevice_register_net_notifiers(struct notifier_block *nb, rollback: for_each_netdev_continue_reverse(net, dev) - call_netdevice_unregister_notifiers(nb, dev); + call_netdevice_unregister_notifiers(nb, dev, locked); return err; } static void call_netdevice_unregister_net_notifiers(struct notifier_block *nb, - struct net *net) + struct net *net, + struct net_device *locked) { struct net_device *dev; for_each_netdev(net, dev) - call_netdevice_unregister_notifiers(nb, dev); + call_netdevice_unregister_notifiers(nb, dev, locked); } static int dev_boot_phase = 1; @@ -1914,7 +1927,7 @@ int register_netdevice_notifier(struct notifier_block *nb) goto unlock; for_each_net(net) { __rtnl_net_lock(net); - err = call_netdevice_register_net_notifiers(nb, net); + err = call_netdevice_register_net_notifiers(nb, net, NULL); __rtnl_net_unlock(net); if (err) goto rollback; @@ -1928,7 +1941,7 @@ int register_netdevice_notifier(struct notifier_block *nb) rollback: for_each_net_continue_reverse(net) { __rtnl_net_lock(net); - call_netdevice_unregister_net_notifiers(nb, net); + call_netdevice_unregister_net_notifiers(nb, net, NULL); __rtnl_net_unlock(net); } @@ -1965,7 +1978,7 @@ int unregister_netdevice_notifier(struct notifier_block *nb) for_each_net(net) { __rtnl_net_lock(net); - call_netdevice_unregister_net_notifiers(nb, net); + call_netdevice_unregister_net_notifiers(nb, net, NULL); __rtnl_net_unlock(net); } @@ -1978,7 +1991,8 @@ EXPORT_SYMBOL(unregister_netdevice_notifier); static int __register_netdevice_notifier_net(struct net *net, struct notifier_block *nb, - bool ignore_call_fail) + bool ignore_call_fail, + struct net_device *locked) { int err; @@ -1988,7 +2002,7 @@ static int __register_netdevice_notifier_net(struct net *net, if (dev_boot_phase) return 0; - err = call_netdevice_register_net_notifiers(nb, net); + err = call_netdevice_register_net_notifiers(nb, net, locked); if (err && !ignore_call_fail) goto chain_unregister; @@ -2000,7 +2014,8 @@ static int __register_netdevice_notifier_net(struct net *net, } static int __unregister_netdevice_notifier_net(struct net *net, - struct notifier_block *nb) + struct notifier_block *nb, + struct net_device *locked) { int err; @@ -2008,7 +2023,7 @@ static int __unregister_netdevice_notifier_net(struct net *net, if (err) return err; - call_netdevice_unregister_net_notifiers(nb, net); + call_netdevice_unregister_net_notifiers(nb, net, locked); return 0; } @@ -2032,7 +2047,7 @@ int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb) int err; rtnl_net_lock(net); - err = __register_netdevice_notifier_net(net, nb, false); + err = __register_netdevice_notifier_net(net, nb, false, NULL); rtnl_net_unlock(net); return err; @@ -2061,7 +2076,7 @@ int unregister_netdevice_notifier_net(struct net *net, int err; rtnl_net_lock(net); - err = __unregister_netdevice_notifier_net(net, nb); + err = __unregister_netdevice_notifier_net(net, nb, NULL); rtnl_net_unlock(net); return err; @@ -2070,10 +2085,11 @@ EXPORT_SYMBOL(unregister_netdevice_notifier_net); static void __move_netdevice_notifier_net(struct net *src_net, struct net *dst_net, - struct notifier_block *nb) + struct notifier_block *nb, + struct net_device *locked) { - __unregister_netdevice_notifier_net(src_net, nb); - __register_netdevice_notifier_net(dst_net, nb, true); + __unregister_netdevice_notifier_net(src_net, nb, locked); + __register_netdevice_notifier_net(dst_net, nb, true, locked); } static void rtnl_net_dev_lock(struct net_device *dev) @@ -2119,7 +2135,7 @@ int register_netdevice_notifier_dev_net(struct net_device *dev, int err; rtnl_net_dev_lock(dev); - err = __register_netdevice_notifier_net(dev_net(dev), nb, false); + err = __register_netdevice_notifier_net(dev_net(dev), nb, false, NULL); if (!err) { nn->nb = nb; list_add(&nn->list, &dev->net_notifier_list); @@ -2138,7 +2154,7 @@ int unregister_netdevice_notifier_dev_net(struct net_device *dev, rtnl_net_dev_lock(dev); list_del(&nn->list); - err = __unregister_netdevice_notifier_net(dev_net(dev), nb); + err = __unregister_netdevice_notifier_net(dev_net(dev), nb, NULL); rtnl_net_dev_unlock(dev); return err; @@ -2151,7 +2167,7 @@ static void move_netdevice_notifiers_dev_net(struct net_device *dev, struct netdev_net_notifier *nn; list_for_each_entry(nn, &dev->net_notifier_list, list) - __move_netdevice_notifier_net(dev_net(dev), net, nn->nb); + __move_netdevice_notifier_net(dev_net(dev), net, nn->nb, dev); } /** @@ -11046,7 +11062,9 @@ int register_netdevice(struct net_device *dev) memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); /* Notify protocols, that a new device appeared. */ + netdev_lock_ops(dev); ret = call_netdevice_notifiers(NETDEV_REGISTER, dev); + netdev_unlock_ops(dev); ret = notifier_to_errno(ret); if (ret) { /* Expect explicit free_netdev() on failure */ @@ -11179,8 +11197,11 @@ static struct net_device *netdev_wait_allrefs_any(struct list_head *list) rtnl_lock(); /* Rebroadcast unregister notification */ - list_for_each_entry(dev, list, todo_list) + list_for_each_entry(dev, list, todo_list) { + netdev_lock_ops(dev); call_netdevice_notifiers(NETDEV_UNREGISTER, dev); + netdev_unlock_ops(dev); + } __rtnl_unlock(); rcu_barrier(); @@ -11971,7 +11992,9 @@ void unregister_netdevice_many_notify(struct list_head *head, /* Notify protocols, that we are about to destroy * this device. They should clean all the things. */ + netdev_lock_ops(dev); call_netdevice_notifiers(NETDEV_UNREGISTER, dev); + netdev_unlock_ops(dev); if (!dev->rtnl_link_ops || dev->rtnl_link_state == RTNL_LINK_INITIALIZED) @@ -12068,6 +12091,7 @@ int netif_change_net_namespace(struct net_device *dev, struct net *net, int err, new_nsid; ASSERT_RTNL(); + netdev_ops_assert_locked(dev); /* Don't allow namespace local devices to be moved. */ err = -EINVAL; From patchwork Thu Mar 27 13:56:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14031163 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FA712163B6 for ; Thu, 27 Mar 2025 13:57:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083827; cv=none; b=R31BkYV3y9L0RxWpViilOHlBVfyUzj4dAWCXl8Rwb+bidnRyvosVlHolS5Za9ygp1kC4mSQQ3CGKNuWXFTsSnWeq/8/nrvi93XSeMdMGZL9qvhbHPjjAhZ4izZGe/usLjwG9hHzDdqxrRYK0kv32eeuKjKGOzFMjajVGzH6ruLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083827; c=relaxed/simple; bh=0B8gE5WxJ2eK5JUTJQLSFNicfC7EMq7CXfO9wLvrYqY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=abC33ix6TGnV9X+1B8i1rvAGkXmJRO+t4D2AI9di63VaASabXTZfX6uPO+Dax+R6YFk2NqnwBpbli4mSBSMvSSnhykUAzh0w4FuepCMA29OtEuskuBwrqXQ60BifINLnYBiMi7Xu2QhFYKhzi9MH9DiDyMYwj6fxsIWFUtIrDpI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-22435603572so19876435ad.1 for ; Thu, 27 Mar 2025 06:57:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743083825; x=1743688625; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qHS6fZkp/GtrmnJnMfY3SsVjRf/F72aaiS8iWCsHSUA=; b=ezkQtAsHZLrHAUrmvRrzuNt+jjyxVncR70TNy69q1tLVDwYi+F+GuXRwjEX1BJ1iaF nlcMIXlwvE0ORnxpB3VVVmPG5I51AuYpQlkb/6WUsfhyqf8n6vZKZOp67dK6HCRnGZpf K1eSn+d3F4f4RXLQThS82IAKSinkKBqK6EIGoVbDoay/kyl1UY/aE+PYu68PeoxNeyLU hkhe8GdZOPSlORewa/pwu1XK6GCfxanHVIvqL3oFiKkxL9lUiMBvoE3knKAERAQKjmK3 ZMtiI9N3zr8SuDVJS/oj/KPPwCW60jP3M8XSPNrOPW4GXwiDlAuoqbESRcnrlZRw/Xls tncQ== X-Gm-Message-State: AOJu0YyGR/5gFh6mJTszG4W1PMYUESHV85NppnHKenz8gWejmygddedC 0X4sCOiVOQueq2HUKbk01GcvVIaEBz/WT8V5saAN2nUfYx3B1mYjkIiTBsX+gQ== X-Gm-Gg: ASbGnctNuEkMaY7gEt1XW3gD+cERSMhDczC2KgfaoQIi5O6SpSdiwQwGHvOdThnFYMh T0+6XsLQwqt6JEBNIj9CAKeTacJCeEktrn4r0NoQVrtgYyx60lAXqOISP5A9DUrMYXZFVX2j2yR Ay033T0/qWuaZBbpwB59Oe5arAr3MJkWBqBNYs7PNLpVeSCqYTvcV30FMAWloh+Q04ZDFjJCXL5 fvO6O4WiH8tBmILFbmDkS8wCMia+jepJdgHjqHA+ycSz6cB/vhLJJqr4HO13tzYKVy9wu7TKdc6 UQXrNNaJMsbybaJcXhAhM3ok9+VyNXqXfGsVjvXaqNri X-Google-Smtp-Source: AGHT+IEI+KhOkmMLJDfTKu6L7nu19EgXloYBTTqCAplhEmNsvWTRxFN7xLYxYzmp1vbYxqEp6clt4A== X-Received: by 2002:a17:903:2f85:b0:220:d601:a704 with SMTP id d9443c01a7336-22804858faamr36300475ad.18.1743083824798; Thu, 27 Mar 2025 06:57:04 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-22780f45e9esm128666965ad.88.2025.03.27.06.57.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Mar 2025 06:57:04 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Cosmin Ratiu Subject: [PATCH net v2 03/11] net: use netif_disable_lro in ipv6_add_dev Date: Thu, 27 Mar 2025 06:56:51 -0700 Message-ID: <20250327135659.2057487-4-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250327135659.2057487-1-sdf@fomichev.me> References: <20250327135659.2057487-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org ipv6_add_dev might call dev_disable_lro which unconditionally grabs instance lock, so it will deadlock during NETDEV_REGISTER. Switch to netif_disable_lro. Make sure all callers hold the instance lock as well. Cc: Cosmin Ratiu Fixes: ad7c7b2172c3 ("net: hold netdev instance lock during sysfs operations") Signed-off-by: Stanislav Fomichev --- include/linux/netdevice.h | 1 + net/core/dev.c | 1 + net/core/dev.h | 1 - net/ipv6/addrconf.c | 17 +++++++++++++---- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index fa79145518d1..b2b4e31806d5 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3386,6 +3386,7 @@ struct net_device *dev_get_by_index(struct net *net, int ifindex); struct net_device *__dev_get_by_index(struct net *net, int ifindex); struct net_device *netdev_get_by_index(struct net *net, int ifindex, netdevice_tracker *tracker, gfp_t gfp); +struct net_device *netdev_get_by_index_lock(struct net *net, int ifindex); struct net_device *netdev_get_by_name(struct net *net, const char *name, netdevice_tracker *tracker, gfp_t gfp); struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex); diff --git a/net/core/dev.c b/net/core/dev.c index 019f838f94d8..bb4a135b1569 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1072,6 +1072,7 @@ struct net_device *netdev_get_by_index_lock(struct net *net, int ifindex) return __netdev_put_lock(dev); } +EXPORT_SYMBOL(netdev_get_by_index_lock); struct net_device * netdev_xa_find_lock(struct net *net, struct net_device *dev, diff --git a/net/core/dev.h b/net/core/dev.h index 7ee203395d8e..8d35860f2e89 100644 --- a/net/core/dev.h +++ b/net/core/dev.h @@ -28,7 +28,6 @@ struct napi_struct * netdev_napi_by_id_lock(struct net *net, unsigned int napi_id); struct net_device *dev_get_by_napi_id(unsigned int napi_id); -struct net_device *netdev_get_by_index_lock(struct net *net, int ifindex); struct net_device *__netdev_put_lock(struct net_device *dev); struct net_device * netdev_xa_find_lock(struct net *net, struct net_device *dev, diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index ac8cc1076536..665184d2adce 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -80,6 +80,7 @@ #include #include #include +#include #include #include #include @@ -377,6 +378,7 @@ static struct inet6_dev *ipv6_add_dev(struct net_device *dev) int err = -ENOMEM; ASSERT_RTNL(); + netdev_ops_assert_locked(dev); if (dev->mtu < IPV6_MIN_MTU && dev != blackhole_netdev) return ERR_PTR(-EINVAL); @@ -402,7 +404,7 @@ static struct inet6_dev *ipv6_add_dev(struct net_device *dev) return ERR_PTR(err); } if (ndev->cnf.forwarding) - dev_disable_lro(dev); + netif_disable_lro(dev); /* We refer to the device */ netdev_hold(dev, &ndev->dev_tracker, GFP_KERNEL); @@ -3151,11 +3153,12 @@ int addrconf_add_ifaddr(struct net *net, void __user *arg) cfg.plen = ireq.ifr6_prefixlen; rtnl_net_lock(net); - dev = __dev_get_by_index(net, ireq.ifr6_ifindex); + dev = netdev_get_by_index_lock(net, ireq.ifr6_ifindex); if (dev) err = inet6_addr_add(net, dev, &cfg, 0, 0, NULL); else err = -ENODEV; + netdev_unlock(dev); rtnl_net_unlock(net); return err; } @@ -5022,11 +5025,11 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, rtnl_net_lock(net); - dev = __dev_get_by_index(net, ifm->ifa_index); + dev = netdev_get_by_index_lock(net, ifm->ifa_index); if (!dev) { NL_SET_ERR_MSG_MOD(extack, "Unable to find the interface"); err = -ENODEV; - goto unlock; + goto unlock_rtnl; } idev = ipv6_find_idev(dev); @@ -5065,6 +5068,8 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, in6_ifa_put(ifa); unlock: + netdev_unlock(dev); +unlock_rtnl: rtnl_net_unlock(net); return err; @@ -6503,7 +6508,9 @@ static int addrconf_sysctl_addr_gen_mode(const struct ctl_table *ctl, int write, if (idev->cnf.addr_gen_mode != new_val) { WRITE_ONCE(idev->cnf.addr_gen_mode, new_val); + netdev_lock_ops(idev->dev); addrconf_init_auto_addrs(idev->dev); + netdev_unlock_ops(idev->dev); } } else if (&net->ipv6.devconf_all->addr_gen_mode == ctl->data) { struct net_device *dev; @@ -6515,7 +6522,9 @@ static int addrconf_sysctl_addr_gen_mode(const struct ctl_table *ctl, int write, idev->cnf.addr_gen_mode != new_val) { WRITE_ONCE(idev->cnf.addr_gen_mode, new_val); + netdev_lock_ops(idev->dev); addrconf_init_auto_addrs(idev->dev); + netdev_unlock_ops(idev->dev); } } } From patchwork Thu Mar 27 13:56:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14031164 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 933E7215F6C for ; Thu, 27 Mar 2025 13:57:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083829; cv=none; b=X1dLQL5RWLr80JV/IlfLAYRqXZW0O9bIlHo/tyWeIVSWHkiWm9bo1yBu7X0bswGHujSElv8tb+DMeoiOrQ/eg/8F9FMGx9zO+HqoxaI4a2pnxui1HFMw+yp/sa6mO3L63SU5NN5CognihXvQN2br+ZMO5FU+QW9WPILg1MOPcJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083829; c=relaxed/simple; bh=ULYcjFcYN8Ek24nx7HnK26yS90k5oRG32V8suQnV9aA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qBeSD2w8XDAcy/Y5d4n473J+TR44Bz2iEoaSr8frotEZa8DpqYqsX0EEIAojRQJzPPoIvJSq3GjwrTHV0K4nqcDOutFhiVjWDPCCF9U7TAPdPgKsWwyq77zTGmVapJruMUw+xvnHjdVhGtj2Gi+aiRVH09xZz0D6JHP7u5TAqvA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.216.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2ff6cf448b8so2209312a91.3 for ; Thu, 27 Mar 2025 06:57:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743083826; x=1743688626; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5vtkERddGy3ubQOVBjaWiY4FjSm3HKUTtr8vteqq4d8=; b=X1Gxlyw3wHENS7wYiOmYx+Dua21P8njNxVdshQCepM4YMBGpEpTFcX4zFgSMXdmquc 2jEQ1/HbDodyRWO3/nvHQAbqq5omy5IkQw3NM3GzFpb3bYVMAcAxmX+Rq3y6RXmraCTy Vj7QWA/yGu+nPaAMhfdfTh12p5zZBashykwRKF+HfkHyoQXqs49JP0u6+3ahKEfSaMZh FdVfuVyJ4laejNSl5mvbqI9y0YTYhcTDmWUZ+Qi/YSHgkX1INL7w9p7JNmoGDIrOoKvo v966CXtM5JQljHEuowHgS+UFBywz/JQusRH3hidf7t4Df9iSij95ZlgOJ71X/rM3ysDL lijg== X-Gm-Message-State: AOJu0YwyqfKmsQEtDv3g7VrdKWcpTSG0hFDRur9B1A6tCz8ji9WS/o1r PQVwftTUySkMisQeQnqrnlJENWf+bOtWyCBTh4HrZubPLRgyFKEt3iBhDp2Lhg== X-Gm-Gg: ASbGnctkWNCPb3CRZSTivhtgmqCLY7wRozDR164lLDMzc2Yk2Rv58BDpJ7GcLQv4Apb fFFlCKfTABP/UkEHMGoEY05kHsc6GgmhTrPZv8hNYYwjfUu3HP1eIzjARTlE+BNP2fFnXZg0HhD YAUgItYaG3ZnVk+4LWs2SbbZM6zaJxDvSU4vJafUT5EwqubHfN98U+X5/+DjufJPZ71bIgkY8fd /VPSiP1KtF3z6T65CDrewClUd7PCP+SVKhT3EC3GfajDlm0iNb+5Os00Jpzb/UYEh8fjNnndnOD g5wrrktMR7bM25z6gPi3mA4KtOM3JkPO79q2CqfU7+8c X-Google-Smtp-Source: AGHT+IFjWQdzWValeKzE46rdldVNCBkXUWUdaAhvYnjoPtVt7aVK7Ix5j6E9PWYQMJbPonnFTz1uNA== X-Received: by 2002:a17:90b:5344:b0:2ee:5958:828 with SMTP id 98e67ed59e1d1-303a7d64072mr5468601a91.9.1743083826297; Thu, 27 Mar 2025 06:57:06 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-3039dfd48e2sm2229046a91.9.2025.03.27.06.57.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Mar 2025 06:57:05 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Taehee Yoo Subject: [PATCH net v2 04/11] net: release instance lock during NETDEV_UNREGISTER for bond/team Date: Thu, 27 Mar 2025 06:56:52 -0700 Message-ID: <20250327135659.2057487-5-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250327135659.2057487-1-sdf@fomichev.me> References: <20250327135659.2057487-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Running NETDEV_UNREGISTER under instance lock might be problematic for teaming/bonding [0] because they take their own lock and the ordering is reverse in the notifiers path. Release the instance lock in the notifiers and let the existing code paths take the lock in the correct order. 0: https://lore.kernel.org/netdev/CAMArcTW+5Lk0EWCaHOsUhf+p31S8yAZyQvi3C8zeRF3TxnC9Fg@mail.gmail.com/ Reported-by: Taehee Yoo Signed-off-by: Stanislav Fomichev --- drivers/net/bonding/bond_main.c | 2 ++ drivers/net/team/team_core.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 950d8e4d86f8..82f887adb33b 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -4022,10 +4022,12 @@ static int bond_slave_netdev_event(unsigned long event, switch (event) { case NETDEV_UNREGISTER: + netdev_unlock_ops(slave_dev); if (bond_dev->type != ARPHRD_ETHER) bond_release_and_destroy(bond_dev, slave_dev); else __bond_release_one(bond_dev, slave_dev, false, true); + netdev_lock_ops(slave_dev); break; case NETDEV_UP: case NETDEV_CHANGE: diff --git a/drivers/net/team/team_core.c b/drivers/net/team/team_core.c index d8fc0c79745d..4a1815f50015 100644 --- a/drivers/net/team/team_core.c +++ b/drivers/net/team/team_core.c @@ -2997,7 +2997,9 @@ static int team_device_event(struct notifier_block *unused, !!netif_oper_up(port->dev)); break; case NETDEV_UNREGISTER: + netdev_unlock_ops(dev); team_del_slave(port->team->dev, dev); + netdev_lock_ops(dev); break; case NETDEV_FEAT_CHANGE: if (!port->team->notifier_ctx) { From patchwork Thu Mar 27 13:56:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14031165 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF4D8217668 for ; Thu, 27 Mar 2025 13:57:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083830; cv=none; b=CgqGjyLTvkzvTq5BdhlfXW1kbZd7kMxyIRt187moai5VrC0xRkYsSyKsehe4AFaPh8tdxrQsxLasYgBK6KMrRRv3P7MR2uz1A89dh1Kn0ao/yFDcufVTKQWhfUy4u/0YTGtGoMeIKdR6P9OIFKN4QElKgkAXL6hXPhaVSFC6uL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083830; c=relaxed/simple; bh=YEDPaib1in0t3FNqP8CqzxLx2cZwNmmLwkBr5DAIR2A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iJYsW0ExHcC4F0rTztEdOCWN50A9blI4w6ipcvmbsQf9NacNPicFxvFT9jOXhuUgmIl47OhBrqyCnzGI9jTNztZF8g9X+aI9Avjy+Y7nphiOARp3tvTLKnhJ9z35q3ZXfwk+y2YdttoCXwQ0Iiawv8jv0yoRJJuuv8m+Scoa5P4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-224191d92e4so19773535ad.3 for ; Thu, 27 Mar 2025 06:57:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743083828; x=1743688628; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=64yh+WmiMEv8Bz4J35cqLkuK/gFRr8aAu8X3M/MtTfA=; b=m5DRPhFGexa1IkNNHtXrdsaKIVFQOXwK0fIh0umwCO87xmv+bwtBffV8OijiDN0r/S ilQVH0E/hxRoKZ3AXrZyLAzB1H6y2ODDAS9BC2Wt7UlYN7x568hpr6+fi6MBAzMa/tM7 RZ7k90qP7UTDSFTJqbYhij9qei6E7rgpGlKSorlhzPk0MrZIMd6Syz33suQd9RFvVKID vw9nURuFZcxM5WwFGSATpsOXr6NvSYJCdnBgqbP8xsTmXlE/LGx3qLq5v5ZX6g0XC/1E UzwUfujwKKzCpBP13Olm8mE/EXd9pxpw29zJFMiaSUs0QaU1Ly+K2zv2ny3PYqpso9b4 s+8Q== X-Gm-Message-State: AOJu0Yz1KV1rgfQv7tauin96KhUI3scpX26Phl4fBooKkTgsQrnPO/oo wznW8dfzfhE4udePCpOnhbS/I5RGjXxmBQ1q8EqW9YaISkpLgb22NmqrtfmTDQ== X-Gm-Gg: ASbGncv4BqbtMvNOBkqMUcyxwJLKj7+zNCrXnm1KrRp6e/r93XA9RLB0xIq7Xhg6Xnh tFNDXcf53dyXSlZChO1JdOqzSaTadWuEwRpYK2STJErk2xIvL3Nz54XR0aAVScZNeEcqC4OkERT AHtpIx/HmhZGDLgzjrS6j0OgGCX+5SFiDmOhZErWrsOjOjMIKcYovywRzYHS5SUyAbybKQUnJbL AEZEabafs37rEhfUmtipa7bVihras+lT3E0ccjubc5A4zg0UjQnNYcO73KZqcWr55MPyD36ZOPs Bj/O7Wi78A4HlLUKm6Hq626LIWPb8UtMwlNLrVydcoYx X-Google-Smtp-Source: AGHT+IG9WmumP6ZIjvTkJj4yAAC9p4DnlK4weyAEqrrkAYlkhQL5AvCgsqTkpiaDIV4kDPOyuGWWmA== X-Received: by 2002:a17:902:d551:b0:216:794f:6d7d with SMTP id d9443c01a7336-2280495aa5bmr64331865ad.48.1743083827666; Thu, 27 Mar 2025 06:57:07 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-7390618f080sm14774159b3a.176.2025.03.27.06.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Mar 2025 06:57:07 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, Cosmin Ratiu Subject: [PATCH net v2 05/11] net/mlx5e: use netdev_lockdep_set_classes Date: Thu, 27 Mar 2025 06:56:53 -0700 Message-ID: <20250327135659.2057487-6-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250327135659.2057487-1-sdf@fomichev.me> References: <20250327135659.2057487-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Cosmin reports a potential recursive lock warning in [0]. mlx5 is using register_netdevice_notifier_dev_net which might result in iteration over entire netns which triggers lock ordering issues. We know that lower devices are independent, so it's save to suppress the lockdep. 0: https://lore.kernel.org/netdev/672305efd02d3d29520f49a1c18e2f4da6e90902.camel@nvidia.com/ Reported-by: Cosmin Ratiu Signed-off-by: Stanislav Fomichev --- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index 3506024c2453..e3d8d6c9bf03 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -5454,6 +5455,7 @@ static void mlx5e_build_nic_netdev(struct net_device *netdev) netdev->netdev_ops = &mlx5e_netdev_ops; netdev->xdp_metadata_ops = &mlx5e_xdp_metadata_ops; netdev->xsk_tx_metadata_ops = &mlx5e_xsk_tx_metadata_ops; + netdev_lockdep_set_classes(netdev); mlx5e_dcbnl_build_netdev(netdev); From patchwork Thu Mar 27 13:56:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14031166 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 260EF215F56 for ; Thu, 27 Mar 2025 13:57:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083831; cv=none; b=SoEHNVouji9wZNOIXmr0qyjAnv8ZIgC/A3wKF5Qk/c6T/dOalSIT1mhHtURPEGNPBc3BWSbbhKXLn+lFFZrkt1Nno+0aFA5tRw+H74Wxj8p5NPewXaEWK+mfjInNVUvyfB3gtw2Q/Q2vJdo8PalEx3pQ7LQOBvCeLcFyTExo8FE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083831; c=relaxed/simple; bh=2Y4VDEvLrJrpUhn3IQbN6tNLk+RPoWOZNBq3c0J6REQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nz/7I3WR/w+fkEXBqblpQbvhWFkDKOFGnqUxqAlH2S6oeAktJ8bTC1hcq1UqYI5WuuwCZHSGqlRaH3o7aoYKiGo/LQrYD+ENQ1Sq97pnYv/RJAwluN1S+0miNazvecOpMCPjKPNux3zqPN92WibglgC50nwuungqQYMnuhxADAM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-227b828de00so18194915ad.1 for ; Thu, 27 Mar 2025 06:57:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743083829; x=1743688629; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KFWCB/uYzwGS8vFF1zUzuiF948URPxY9n2dU+3UkGgA=; b=KXVVYPC9GX1IF8r57bQhyEYtyC6PnD2pSq6dXeJdhz8tCNujH5UASkK2scjawIzLUB Ez7sdwev72AZ8aH9N8MVFgOKUJNfaI2y2BkR9YTlBVeO27ZCHhL+hrIlG8DSVopyshze 3Nniik3X3KCI+cH7bUqE7qKyVJ4PJkpuimBZ8Kgq4zv/zQb+S9vZnUo7wgkFjznw8ZTk sXWbcCCNzd14QZ4Mmuyr1NmnaGXz4nJ9KOFajxxFd+ymMmFSSY+VUGNj8g+HVaNo6lKV FwoNLN0IyzxJUkN3sgmi08/ZBapmNLIB/ils3HfI5gtnE8BTXoxdDgNw8Spz2xeFwB4Q X8mQ== X-Gm-Message-State: AOJu0Ywsf9C+UltNSNG95YBNPg9mkzUr+R5yP/NtU1VEnQTUQTHOBsg+ VBji8vJxmzI0CEa7IgAy19/pZNitU5rhTmN5m5bwtne/qEFU5nuAE1gAy/NgPA== X-Gm-Gg: ASbGnctZkuI+73qQI+h7XCOTqJQ7/SRHfa5FeYziI+HCHy0U+Qs73BMckpoHKa3juFq A9+Cmac52Lgf+4lxLdls5GQWEmp5MULnZaalIJHxnDi5gcWxLI0y4FKN0+hTEv6oxEGZxDCIxcT TcWEIWuOB4wVS3J//sJWirL8195mxgVX+K1BszY1EYm6xuWu+1B6G3CeEVZ/THrkCMgM+YLjera ZuRVFpR7UORiG+WnnsLyDjxb1XRLcp42go8kuCaUM8na7BQU1bj7Z7xc3ZmaB9ZDxrY/y5QwcrH hk8UzaH8kdOuqsftHwfVjudQsFimzlVDiSpv8EVngnHmFK/ePPx6MfU= X-Google-Smtp-Source: AGHT+IF/eRAw1z1ob6fpH6jusap991A0tUQr8p80+IeiFRFomCYm8/dvFfUgoja9z7CHT6zDRJstOA== X-Received: by 2002:a05:6a20:3d12:b0:1f5:9961:c40 with SMTP id adf61e73a8af0-1fea2d37505mr6956785637.8.1743083829000; Thu, 27 Mar 2025 06:57:09 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-af8a2803dd2sm12865129a12.19.2025.03.27.06.57.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Mar 2025 06:57:08 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Subject: [PATCH net v2 06/11] netdevsim: add dummy device notifiers Date: Thu, 27 Mar 2025 06:56:54 -0700 Message-ID: <20250327135659.2057487-7-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250327135659.2057487-1-sdf@fomichev.me> References: <20250327135659.2057487-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org In order to exercise and verify notifiers' locking assumptions, register dummy notifiers and assert that netdev is ops locked for REGISTER/UNREGISTER/UP. Signed-off-by: Stanislav Fomichev --- drivers/net/netdevsim/netdev.c | 58 +++++++++++++++++++++++++++++++ drivers/net/netdevsim/netdevsim.h | 3 ++ 2 files changed, 61 insertions(+) diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index b67af4651185..fdf10dd3df0b 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -926,6 +926,24 @@ static void nsim_queue_uninit(struct netdevsim *ns) ns->rq = NULL; } +static int nsim_net_event(struct notifier_block *this, unsigned long event, + void *ptr) +{ + struct net_device *dev = netdev_notifier_info_to_dev(ptr); + + switch (event) { + case NETDEV_REGISTER: + case NETDEV_UNREGISTER: + case NETDEV_UP: + netdev_ops_assert_locked(dev); + break; + default: + break; + } + + return NOTIFY_DONE; +} + static int nsim_init_netdevsim(struct netdevsim *ns) { struct mock_phc *phc; @@ -939,6 +957,7 @@ static int nsim_init_netdevsim(struct netdevsim *ns) ns->netdev->netdev_ops = &nsim_netdev_ops; ns->netdev->stat_ops = &nsim_stat_ops; ns->netdev->queue_mgmt_ops = &nsim_queue_mgmt_ops; + netdev_lockdep_set_classes(ns->netdev); err = nsim_udp_tunnels_info_create(ns->nsim_dev, ns->netdev); if (err) @@ -959,7 +978,13 @@ static int nsim_init_netdevsim(struct netdevsim *ns) err = register_netdevice(ns->netdev); if (err) goto err_ipsec_teardown; + rtnl_unlock(); + + ns->nb.notifier_call = nsim_net_event; + if (register_netdevice_notifier_dev_net(ns->netdev, &ns->nb, &ns->nn)) + ns->nb.notifier_call = NULL; + return 0; err_ipsec_teardown: @@ -1043,6 +1068,10 @@ void nsim_destroy(struct netdevsim *ns) debugfs_remove(ns->qr_dfs); debugfs_remove(ns->pp_dfs); + if (ns->nb.notifier_call) + unregister_netdevice_notifier_dev_net(ns->netdev, &ns->nb, + &ns->nn); + rtnl_lock(); peer = rtnl_dereference(ns->peer); if (peer) @@ -1086,6 +1115,28 @@ static struct rtnl_link_ops nsim_link_ops __read_mostly = { .validate = nsim_validate, }; +static int nsim_device_event(struct notifier_block *this, unsigned long event, + void *ptr) +{ + struct net_device *dev = netdev_notifier_info_to_dev(ptr); + + switch (event) { + case NETDEV_REGISTER: + case NETDEV_UNREGISTER: + case NETDEV_UP: + netdev_ops_assert_locked(dev); + break; + default: + break; + } + + return NOTIFY_DONE; +} + +static struct notifier_block nsim_notifier = { + .notifier_call = nsim_device_event, +}; + static int __init nsim_module_init(void) { int err; @@ -1102,8 +1153,14 @@ static int __init nsim_module_init(void) if (err) goto err_bus_exit; + err = register_netdevice_notifier(&nsim_notifier); + if (err) + goto err_notifier_exit; + return 0; +err_notifier_exit: + rtnl_link_unregister(&nsim_link_ops); err_bus_exit: nsim_bus_exit(); err_dev_exit: @@ -1113,6 +1170,7 @@ static int __init nsim_module_init(void) static void __exit nsim_module_exit(void) { + unregister_netdevice_notifier(&nsim_notifier); rtnl_link_unregister(&nsim_link_ops); nsim_bus_exit(); nsim_dev_exit(); diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 665020d18f29..d04401f0bdf7 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -144,6 +144,9 @@ struct netdevsim { struct nsim_ethtool ethtool; struct netdevsim __rcu *peer; + + struct notifier_block nb; + struct netdev_net_notifier nn; }; struct netdevsim * From patchwork Thu Mar 27 13:56:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14031167 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90C4C217668 for ; Thu, 27 Mar 2025 13:57:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083832; cv=none; b=RxuBIjZqMMdrEpt/D0kjyopUSrdbsvnrEFAYi7IuOf2KKmwRemGVGNNm1REu0dxG2DLFEow/af20H10FJy+hgk2t23iaijf1ZHcCCNu1OgnlLmfz330buz+Wi0QY1ync/1XuGKSdtgkkXLeJbJTsv/UkYQEkFQaWHKFC+BCzqUc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083832; c=relaxed/simple; bh=No/0VfPK7pHniKtbbaQJ0cyWQL9HoLVC3b3WbWBLe4o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bKIyR54dPiXKqXkGPTMI7vszbQs6c7y09Nzxta1acqHx4xGzUBrkawVyvabKlKo/6TtMRUMHEF2Rct3GK2dV9Bho6rhqbgwdM7r+HdnaEVK2Jbh0eyhUK0q2e+NMjnTkO00MnVdE4nJ3JmwM5+bnd9oZQODMOsLbzyEtyKypG5I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2240b4de12bso28235395ad.2 for ; Thu, 27 Mar 2025 06:57:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743083830; x=1743688630; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QOUxfu91P1ktbOKHx7UEPpGlhg2bkdrt6E9z1Gl/UMk=; b=SDd9j1gP6KQe/oR4HDrqJOWNHthAbmpo2iAF6qyHStgIthNzhlzl5plVYd6Bnl9Az7 8QEpfXYWGgjNiMOKMowOfunbzL6vbmPUEF+gR7yNgUt6N/Sk0PpT780r8Y/K4ayHqHqv eobVgC35d5Jr53DvGiBAdd4hx/TOMwdsEJAgj+ctfy1wPe/J+UCtOni0+uDn+PI7IgaS Xqwjegdw9QU6dBtnMf/Ll8b93wHACACaQSuryPWbl1JleYF3F/B/loIoXXW2IpFATNe3 U651ob6AiLj9eWYZb3rXCNIpq+O630s3XnLDdowQBE93g2sowyctQT5MfQVYFunyykMx /OLg== X-Gm-Message-State: AOJu0YxiF69bKFMqFdQGolHRMM5zhxYtqTRu+I5XqQaszDuyxpRdB7ex N5qAfq+WA8gH8s4pPl4x2Pf4ZRgQc/wFB6tdtgwW5hKyIRM3yfY0AlnbbuPvpA== X-Gm-Gg: ASbGncvIGos5YcR7amPPlUgx5Stfpv6jTv8y8Fk42GNlFvcLVu0DxO6CurWt8WRLylj 2BQPBJ8xtolZz5piDnJ/0Wy6QkMstNiI4S2zjbYfxt5K54ijxAxwVGUr2iCmdYeFmvPVvEKIe+1 YWHAJbTDj+GBZydN29Lm5QqTvejVfMDGFFGOtNAE7cVtonTA7MNtvv7eBLnQ+ayMEYu1O2MN8wr zp4bPiQoAw04/knabid98vMbKDs4Log4GigofFtNG0NTK8M5X8fvVB/oxJYSME3MRY9A9Msc7wK YSZrcIQAgPIRhWeAVgorFjAVWRIq3XGXLz6JbrEIcpC1 X-Google-Smtp-Source: AGHT+IFhaZ5omOvrymxczUb2jY7DRa8o2W1EmyQ75/nAyCPU9ZXj47wTKGPIpOgHFSbI+3eC+d3DAg== X-Received: by 2002:a17:903:2acb:b0:216:2bd7:1c4a with SMTP id d9443c01a7336-22804877939mr58510925ad.26.1743083830392; Thu, 27 Mar 2025 06:57:10 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-227811dcd47sm128490395ad.178.2025.03.27.06.57.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Mar 2025 06:57:10 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Subject: [PATCH net v2 07/11] net: dummy: request ops lock Date: Thu, 27 Mar 2025 06:56:55 -0700 Message-ID: <20250327135659.2057487-8-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250327135659.2057487-1-sdf@fomichev.me> References: <20250327135659.2057487-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Even though dummy device doesn't really need an instance lock, a lot of selftests use dummy so it's useful to have extra expose to the instance lock on NIPA. Request the instance/ops locking. Signed-off-by: Stanislav Fomichev --- drivers/net/dummy.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c index a4938c6a5ebb..d6bdad4baadd 100644 --- a/drivers/net/dummy.c +++ b/drivers/net/dummy.c @@ -105,6 +105,7 @@ static void dummy_setup(struct net_device *dev) dev->netdev_ops = &dummy_netdev_ops; dev->ethtool_ops = &dummy_ethtool_ops; dev->needs_free_netdev = true; + dev->request_ops_lock = true; /* Fill in device structure with ethernet-generic values. */ dev->flags |= IFF_NOARP; From patchwork Thu Mar 27 13:56:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14031168 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68EBE217F30 for ; Thu, 27 Mar 2025 13:57:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083834; cv=none; b=uC95rdW52Eh8hZWYWddmwl88TmxF3IZ42B1plYi+ndc2zxCwo68SryZjnpmpYTwXN776BkUTLYkiV082G4mWboobzpiaNntSxuQpN0BGBtdPJy9FsTb9PUH1NiBNQPvkZzwEDTU3b8L0vf9igfu1CiPig9a9ID7+l27zK04UmpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083834; c=relaxed/simple; bh=n97bsKeGNxiCQENyEnu04SJHTKTffra3u3PkxcA2ORQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YWEfkn45QcHnIwChoVYQShNQtCegh8IJZS/gfhCSzDs0iKAZaNa+ROc2z6CV7t5dp+uPNM/lKYdxxL8NRo5xui4MH97yqrKRFJ3leU9rkWwGKqD9/Re3cCJYO/zQrxwsSflkEk5W0slhYjuKgMlSVyN0PywWW9VGspg0lwQJYLI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-22435603572so19880645ad.1 for ; Thu, 27 Mar 2025 06:57:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743083832; x=1743688632; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SR4152Dd3dI58fOWxtoFrARZtfVG4WmmakmPAvGHxzY=; b=UDthSmOJmQ72WKi3N0ituJ+LFjBsVej2ZQ1PnKJlFK2U0iq7vTfb0yTr7XxOoswmRi piq9TIkSNSaqZfX/lMwtule59agIap0VcLoTUYot3kSpe/oHuA1Aj8r0D1aurT3o8UTV sPVbde+MbwdVvtc5B5IcAzcadK8yubZLjD1IU1j7lrzRJgVFDqdK2gac59j2e7gxHhwk 7jVO5pmHLJSbr/pZ1PLZ02CMZiCpAVBZktVodnwfokmOSynoB8Au916yzIllCjJhUgz8 W437QvPcr/XHVt4ObvH6l+Xe5QztXnAe09pzF+IdiARl/yk2sIUinD5UXYSZfJXyQbdK W1WQ== X-Gm-Message-State: AOJu0YzxW6PYg9Uueh1H4W4VFQFnYnkc3V6LibPPZh/PSKnH8CzxTMSs JBP/tzQJGQDYLAduPhZHVLNNIUKNwhNsyHmfMd0szXRHx3gaUX7jYv9XMaX82A== X-Gm-Gg: ASbGnctS/JtESR9wyTmSEet98HzUu8TZLalAOQ5iFJJ8slk+NOGjh7Evbe1HaHUs1Ax Ah5FEi7unN8TBWXO0N2YYVSS6UxOZnwW8UcSg53u/tTfWny9qK3OwjdVKYz/RsBmQtV7LoPKIBw y7xjf6zqQR/LswaSTJ1H55OP/Rg0ktqb+GvNUORJ+wvjz7mLm1ZXjoyT6eg5bsL/IdlCktTV6Ff dnzmkI+M6nk5W1YbCxz2N68qPY1l6KAtdfAGVZNlDIs9gNgxGtVwODd2GK7LDfKLkU9QSrAEnFl EkF0Fy/00SxsfgP8z4npE4I5qdsZ9CVoQ1kuV9n6fIfC X-Google-Smtp-Source: AGHT+IEc4iHqjhlpsfsAK2GfYFZHsozW5jHK4BjiKatEntZDGla8YLkUWqH2xgDMq2WsMXwyxBPDDw== X-Received: by 2002:a17:90b:2643:b0:2ee:c04a:4276 with SMTP id 98e67ed59e1d1-303a7c5e6efmr5252573a91.5.1743083831712; Thu, 27 Mar 2025 06:57:11 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-3039f6b31fbsm2202933a91.40.2025.03.27.06.57.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Mar 2025 06:57:11 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Subject: [PATCH net v2 08/11] docs: net: document netdev notifier expectations Date: Thu, 27 Mar 2025 06:56:56 -0700 Message-ID: <20250327135659.2057487-9-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250327135659.2057487-1-sdf@fomichev.me> References: <20250327135659.2057487-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org We don't have a consistent state yet, but document where we think we are and where we wanna be. Signed-off-by: Stanislav Fomichev --- Documentation/networking/netdevices.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Documentation/networking/netdevices.rst b/Documentation/networking/netdevices.rst index ebb868f50ac2..89337cfec36e 100644 --- a/Documentation/networking/netdevices.rst +++ b/Documentation/networking/netdevices.rst @@ -343,6 +343,24 @@ there are two sets of interfaces: ``dev_xxx`` and ``netif_xxx`` (e.g., acquiring the instance lock themselves, while the ``netif_xxx`` functions assume that the driver has already acquired the instance lock. +Notifiers and netdev instance lock +================================== + +For device drivers that implement shaping or queue management APIs, +some of the notifiers (``enum netdev_cmd``) are running under the netdev +instance lock. + +Currently only the following notifiers are running under the instance lock: +* ``NETDEV_REGISTER`` +* ``NETDEV_UP`` +* ``NETDEV_UNREGISTER`` + +There are no clear expectations for the remaining notifiers. Notifiers not on +the list may run with or without the instance lock, potentially even invoking +the same notifier type with and without the lock from different code paths. +The goal is to eventually ensure that all (or most, with a few documented +exceptions) notifiers run under the instance lock. + NETDEV_INTERNAL symbol namespace ================================ From patchwork Thu Mar 27 13:56:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14031169 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97AF8217F56 for ; Thu, 27 Mar 2025 13:57:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083836; cv=none; b=fLrzBdt1xGmEW6FU7FHMCirfzMK6z8ssMokszwpOFkGU2OfGSoOtFCrd1/cYFJmN5OgorZSI40WIklnQJuPw4p58/PVtuVlxsf0twrV6EjktVzC5gseCm6RWhwnZeDDvgnWPf+7wDYXC+PMtZAlv1EGI6HLJKTXz7osey82lBMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083836; c=relaxed/simple; bh=rycKGXFoqAeC5tPx/73rvy9De8EwBoLt/+IT2SfEVXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZLEUwB/b6RUTAamDKQ/xD4cSlHcjPCSLESHOlygHc+g1NBUkOKL6m9MLwoizlCkL+L3G9103InWlvKKbP5O0sa8IflgVGDyLafiic3ekWDhcbdYnLsBEk4QwvnKPwcZiWk69yHyKKXHmYxG8Aa1qJ2aFe0afxFLIsD5AqvNkTdo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.216.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2ff615a114bso3276423a91.0 for ; Thu, 27 Mar 2025 06:57:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743083833; x=1743688633; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aE5CppWR6I6v1fz3Mt2HH1HdiF5SrnQoNwkZhPjynWg=; b=YAn3Lwrh6A1Ut22innZeyYuegERvBBtBTA4jYKPsjvz2TViKgLSeMGkgKBfEp0ddua TiNlRC7ruN+nS49dWwjqE8zP7U3pC9FAJxAkn3oPwT0fEF2LobQAhroU7nbq3EQtfh1C A/a4SdPqv7ar24CeEVBP/SPxYdeOM2TdPFH4yv0N8z2ljdmSppbguZJ14yWKp+vCO/MF WiabjPlZJBLUcE2gVLcOx7aCXrN0Gb2cT6VU7GE+QYJIXhrhwyM5Obp7Lwl0lvCcvwZ9 9tCrm/8TOlIEAQ9YSX1k5BqX0elNDuMM4Xy58vFz88osl4fojB4YVpRHXiP+0hr+6Bi4 LyaA== X-Gm-Message-State: AOJu0Yx4V1V9t85+rnQeXDFjL1PV0Ax4p192l8/AH8DP9l8lrYyN5hlK aWLK/5ObfBwP7f/Tt8D/kLK1QrbvbDHAW6l9dYU6J3mGkvA9qJgz190yAae6HQ== X-Gm-Gg: ASbGncukWFf+wqgy8cmajoIRXkPEWAdj1+4Ucr66cpdZXAVCTsc5fCTuEw0TBNgKk/z oUHkDMDOaTETnKVXdVCt0b7nTVlO44Hmoq0lUskavCmuOWehitI3+c6WtZRq+lCOJymitwaWpDk XIx83s9bR82oQ3N7h+EAHRBGdqX6zFzmS+sjFtCHacgNe10SdlISL2AImPF6Q4Vjr21bTSd0hUu pSTTp/fg8CcqN89xSSNxWoPsSu6gbGZk5pzz0TucewJ4R2MMJxXMZN9THfxElE87qnEbInGt0Hu vkxk5NPAHT3XY3Dkb+YITRakkpGBeRGPEEAaES0Wo9dQ X-Google-Smtp-Source: AGHT+IFptf22dZ+GwYUqkOeig0NbyZF2M1/LTtyae6cL703lhQmHjSqNbQZEofmIi5vZCinZlcKGjQ== X-Received: by 2002:a17:90b:3bc4:b0:2fa:603e:905c with SMTP id 98e67ed59e1d1-3050bcdab54mr376346a91.2.1743083833174; Thu, 27 Mar 2025 06:57:13 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-3039e60bfd6sm2197782a91.41.2025.03.27.06.57.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Mar 2025 06:57:12 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Subject: [PATCH net v2 09/11] net: designate XSK pool pointers in queues as "ops protected" Date: Thu, 27 Mar 2025 06:56:57 -0700 Message-ID: <20250327135659.2057487-10-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250327135659.2057487-1-sdf@fomichev.me> References: <20250327135659.2057487-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jakub Kicinski Read accesses go via xsk_get_pool_from_qid(), the call coming from the core and gve look safe (other "ops locked" drivers don't support XSK). Write accesses go via xsk_reg_pool_at_qid() and xsk_clear_pool_at_qid(). Former is already under the ops lock, latter needs to be locked when coming from the workqueue via xp_clear_dev(). Acked-by: Stanislav Fomichev Signed-off-by: Jakub Kicinski Signed-off-by: Stanislav Fomichev --- include/linux/netdevice.h | 1 + include/net/netdev_rx_queue.h | 6 +++--- net/xdp/xsk_buff_pool.c | 7 ++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index b2b4e31806d5..b3d1c1922ec0 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -688,6 +688,7 @@ struct netdev_queue { /* Subordinate device that the queue has been assigned to */ struct net_device *sb_dev; #ifdef CONFIG_XDP_SOCKETS + /* "ops protected", see comment about net_device::lock */ struct xsk_buff_pool *pool; #endif diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h index b2238b551dce..8cdcd138b33f 100644 --- a/include/net/netdev_rx_queue.h +++ b/include/net/netdev_rx_queue.h @@ -20,12 +20,12 @@ struct netdev_rx_queue { struct net_device *dev; netdevice_tracker dev_tracker; + /* All fields below are "ops protected", + * see comment about net_device::lock + */ #ifdef CONFIG_XDP_SOCKETS struct xsk_buff_pool *pool; #endif - /* NAPI instance for the queue - * "ops protected", see comment about net_device::lock - */ struct napi_struct *napi; struct pp_memory_provider_params mp_params; } ____cacheline_aligned_in_smp; diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c index 25a76c5ce0f1..c7e50fd86c6a 100644 --- a/net/xdp/xsk_buff_pool.c +++ b/net/xdp/xsk_buff_pool.c @@ -279,9 +279,14 @@ static void xp_release_deferred(struct work_struct *work) { struct xsk_buff_pool *pool = container_of(work, struct xsk_buff_pool, work); + struct net_device *netdev = pool->netdev; rtnl_lock(); - xp_clear_dev(pool); + if (netdev) { + netdev_lock_ops(netdev); + xp_clear_dev(pool); + netdev_unlock_ops(netdev); + } rtnl_unlock(); if (pool->fq) { From patchwork Thu Mar 27 13:56:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14031170 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC56421422C for ; Thu, 27 Mar 2025 13:57:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083837; cv=none; b=MC6iRHv5ck9zHey2PcR885x8XNHOdiW9Mae+giIS5iuBl7uSHolt2iCv8FmiTEa5RXPvAJIOvW4aoY40QQk0lh0AO83sP4Xs0nnBgsQZUa638GrmOaH6oPbGxOCC9kC7rRzVWAC02HGc6rEMhq4/UA8V81GpsamjGm8Ua7INo0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083837; c=relaxed/simple; bh=of2BHr0ODb2uStHV41mgqAmOSbSLGSoE+Pr7pCR6LSQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ApQCqpNHN1wS6s6zSiag1/FM6VEFuiexP/+hoB2Y04wRIYi+iFjGXBrHgKKRDJBwfDPlS3brNSop7mDWydFMZRz8XYEYNLcFT8Ol7wL3Ezw2bOdQ5wSQjZ4DvSvW0zBxiuMaAFdg0GzXumn6xdtOU2ar4Mj0yLSvkD9IPB/kATM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-224191d92e4so19777575ad.3 for ; Thu, 27 Mar 2025 06:57:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743083835; x=1743688635; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=41eutsHNNUgp/YLlU9qv9rjhqH3AWJ6Bj/6el16QKro=; b=h+s3Ib36M0uxhAoQQ1Jswy7zT1rvaBzn48NVyCOifK0we1URlGYt1whZDM+d2Z4gAc Yp0x1sK/0lfD+RiKupJ1fcfc93FWoE3WfVB4/2/4xsCoYs/OfnT6NXXYKVtcW59nx+Rc TtLP4JOT9lTlZO/2HmWeXPDmBpZHRwwAnhSrLj9vuiuTa4vZB3oeXu/+55tJYPJ8kKU0 fI39/fysLCrgLinvT62efYao4LwMGQHrGdweXri579L/klKP8lr/bBgMHHE1mFEcJljB GyXZt4Z4ww6xvm/vx+jwQBMT1XYBmQomUcNJ3Oas8upejivne76HzIKOJINbf4zeVRSt lt6Q== X-Gm-Message-State: AOJu0Yz8zFaAPUfWqGthaSiqwWRC3rTLCnxtnlFljq7R+AJYR/motVXa SCRMHLxl8z+3CR+zugpKbSK3eFqLFGUqI7tqlxfY351vqY2UeRSEif6s9cfQZQ== X-Gm-Gg: ASbGncvfw7TVEEUjGZd5MDAZd7w6GV8ncPkDKqiYsCRb9vMLOgNoB9dqU9RB/C/Fvpb JTshh/eVD6f9zut6mzG/4SwPWLFCqwzTBRct9+51mll9o6trjS31rR57Z3mIk+UxR+eoFBl4uDD xvgE5UsFLXRAHylSDEIXmUzra4JcgY0wgvPQFQbFEFVWjpUikboWfq+C4G7RXsd0C/f79DzsgUh ZfJkwX1cic5RLeIvjTy/uIpsnJQKvOo5iGR/HVHCd+BQZcObXMW3159YYBTb+aOlfxu16LCeloX CVIsxCrlNoI4KsGRWJeItZhmvFWGe2njSxYMkjqBEWtC X-Google-Smtp-Source: AGHT+IHESlvLw+d/BF9Ru55e4YB+Dzgp51+JEFes9+XLZ340jqxTIQaoNlewillDkf+fea7VnSsqmg== X-Received: by 2002:a17:902:f644:b0:216:6901:d588 with SMTP id d9443c01a7336-228048ac56amr51471015ad.15.1743083834669; Thu, 27 Mar 2025 06:57:14 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-227811e3132sm129034435ad.200.2025.03.27.06.57.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Mar 2025 06:57:14 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Subject: [PATCH net v2 10/11] netdev: add "ops compat locking" helpers Date: Thu, 27 Mar 2025 06:56:58 -0700 Message-ID: <20250327135659.2057487-11-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250327135659.2057487-1-sdf@fomichev.me> References: <20250327135659.2057487-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jakub Kicinski Add helpers to "lock a netdev in a backward-compatible way", which for ops-locked netdevs will mean take the instance lock. For drivers which haven't opted into the ops locking we'll take rtnl_lock. The scoped foreach is dropping and re-taking the lock for each device, even if prev and next are both under rtnl_lock. I hope that's fine since we expect that netdev nl to be mostly supported by modern drivers, and modern drivers should also opt into the instance locking. Note that these helpers are mostly needed for queue related state, because drivers modify queue config in their ops in a non-atomic way. Or differently put, queue changes don't have a clear-cut API like NAPI configuration. Any state that can should just use the instance lock directly, not the "compat" hacks. Acked-by: Stanislav Fomichev Signed-off-by: Jakub Kicinski Signed-off-by: Stanislav Fomichev --- include/net/netdev_lock.h | 16 +++++++++++++ net/core/dev.c | 49 +++++++++++++++++++++++++++++++++++++++ net/core/dev.h | 15 ++++++++++++ 3 files changed, 80 insertions(+) diff --git a/include/net/netdev_lock.h b/include/net/netdev_lock.h index 1c0c9a94cc22..76cbf5a449b6 100644 --- a/include/net/netdev_lock.h +++ b/include/net/netdev_lock.h @@ -64,6 +64,22 @@ netdev_ops_assert_locked_or_invisible(const struct net_device *dev) netdev_ops_assert_locked(dev); } +static inline void netdev_lock_ops_compat(struct net_device *dev) +{ + if (netdev_need_ops_lock(dev)) + netdev_lock(dev); + else + rtnl_lock(); +} + +static inline void netdev_unlock_ops_compat(struct net_device *dev) +{ + if (netdev_need_ops_lock(dev)) + netdev_unlock(dev); + else + rtnl_unlock(); +} + static inline int netdev_lock_cmp_fn(const struct lockdep_map *a, const struct lockdep_map *b) { diff --git a/net/core/dev.c b/net/core/dev.c index bb4a135b1569..20ae7cb79163 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1051,6 +1051,18 @@ struct net_device *__netdev_put_lock(struct net_device *dev) return dev; } +static struct net_device *__netdev_put_lock_ops_compat(struct net_device *dev) +{ + netdev_lock_ops_compat(dev); + if (dev->reg_state > NETREG_REGISTERED) { + netdev_unlock_ops_compat(dev); + dev_put(dev); + return NULL; + } + dev_put(dev); + return dev; +} + /** * netdev_get_by_index_lock() - find a device by its ifindex * @net: the applicable net namespace @@ -1074,6 +1086,18 @@ struct net_device *netdev_get_by_index_lock(struct net *net, int ifindex) } EXPORT_SYMBOL(netdev_get_by_index_lock); +struct net_device * +netdev_get_by_index_lock_ops_compat(struct net *net, int ifindex) +{ + struct net_device *dev; + + dev = dev_get_by_index(net, ifindex); + if (!dev) + return NULL; + + return __netdev_put_lock_ops_compat(dev); +} + struct net_device * netdev_xa_find_lock(struct net *net, struct net_device *dev, unsigned long *index) @@ -1099,6 +1123,31 @@ netdev_xa_find_lock(struct net *net, struct net_device *dev, } while (true); } +struct net_device * +netdev_xa_find_lock_ops_compat(struct net *net, struct net_device *dev, + unsigned long *index) +{ + if (dev) + netdev_unlock_ops_compat(dev); + + do { + rcu_read_lock(); + dev = xa_find(&net->dev_by_index, index, ULONG_MAX, XA_PRESENT); + if (!dev) { + rcu_read_unlock(); + return NULL; + } + dev_hold(dev); + rcu_read_unlock(); + + dev = __netdev_put_lock_ops_compat(dev); + if (dev) + return dev; + + (*index)++; + } while (true); +} + static DEFINE_SEQLOCK(netdev_rename_lock); void netdev_copy_name(struct net_device *dev, char *name) diff --git a/net/core/dev.h b/net/core/dev.h index 8d35860f2e89..e7446b25bcde 100644 --- a/net/core/dev.h +++ b/net/core/dev.h @@ -40,6 +40,21 @@ DEFINE_FREE(netdev_unlock, struct net_device *, if (_T) netdev_unlock(_T)); (var_name = netdev_xa_find_lock(net, var_name, &ifindex)); \ ifindex++) +struct net_device * +netdev_get_by_index_lock_ops_compat(struct net *net, int ifindex); +struct net_device * +netdev_xa_find_lock_ops_compat(struct net *net, struct net_device *dev, + unsigned long *index); + +DEFINE_FREE(netdev_unlock_ops_compat, struct net_device *, + if (_T) netdev_unlock_ops_compat(_T)); + +#define for_each_netdev_lock_ops_compat_scoped(net, var_name, ifindex) \ + for (struct net_device *var_name __free(netdev_unlock_ops_compat) = NULL; \ + (var_name = netdev_xa_find_lock_ops_compat(net, var_name, \ + &ifindex)); \ + ifindex++) + #ifdef CONFIG_PROC_FS int __init dev_proc_init(void); #else From patchwork Thu Mar 27 13:56:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14031171 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 301F2218823 for ; Thu, 27 Mar 2025 13:57:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083838; cv=none; b=udDx8tEhWbMMQI2KVJQO24lSAYVpON2lSHgToxT9VsC9I4IZW6PHkpwSqRHV+iWDlg818ldrwHCx9ozFIXwnXQ6Eu3kZYJM5Aux/TDuT/ojBqA292RwMF6TuQjeTvdylSDnGI31LlzO90wZPpaJSVrZGoHiQSj+sZh1AfiFw+vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743083838; c=relaxed/simple; bh=CUR5I3UpwjbNO0hNnmCCSuAoAxW+HdofdbYjgHwMqZw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JAhufHTAfSJUkJWNVUoW35hl1sSaTtDGBygXvBFBImLxpHBn5iahSOF1qj3y58E9XYHIOllQywND2szHocq2dEbiRpsdL00T9xTPOjA99iqdWLVzIEbTcs6s4SL1+3U12PJ2idiv5au72v6Gf3wg60hZrDujaAHeo0P0c6VG5wE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fomichev.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-22401f4d35aso22773075ad.2 for ; Thu, 27 Mar 2025 06:57:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743083836; x=1743688636; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=knTGk9lxkObf5m8zJBEYc+FoI0axfDUQp9+wJSH7C6k=; b=BnJzk/3patT4i3Z+XGB5vRhselNe2YihUBF7fyKUUYVpX6+AMf33Mmv/Q/l4in19HX Kql/qD0gU1VntKBWjxZH3sbdR4Ni8SoyugdPUNEv5XBNz+7R/nRWoZ79bNB/CoxelpOV x+0kOFF2uUn+fF3B+vP8dXfHVhEPDRu2eJ+o/aV+f6TY1MH4anwQAPCbsxERlUWYIlFQ JK91gBd969ePZLt548cB5q1wadnFHPmcW51k6EY9onm33gJ2teC7p/cVTZS8dOTd54rY 47gfzuF1aeoFghiJTwUFAnw+BNgOsox3fVDxlRAmzGd8Y5JtL1lh9pOtLI0/KxGq+99+ L4oA== X-Gm-Message-State: AOJu0YxMz5vjpl+fzI2L+141XbhIr7+8/3YH1zaYzxryU6pcEl/z1Zaz 50fWGrapDZBrmpeco8jSHL0yShNNZ8Bp4z/wGEG5/lO4YlUcRdGXktGyv5ho8A== X-Gm-Gg: ASbGncuWYGfOmCjGodtO6xXlZtENolKos7uF1Pcsl0wlAWnKxR4J9pt+p21lIIovP12 YAGuNVyO0FGnNbUnSWmhDw3qe+TMwaPWEA/9HRxt2RPfuKQ/wa6R1kJiT2lia/iy3GRrLcG3BkR mKWum2sBTjcGapRaX+/5XAp6QD86nL4w9dQ8W9sYVD4l/LCF7Jlg2cYfkUmYZeuW6BjYZSpG+qZ a3baIfMn84ctcrOSKY4CEfoGaIzX0MllkbqJcto6RnrnY9b5LZlG4SqD3rvukHYJcRjO3JT0na6 XkgdN9ICy7Ic07vPEkj1JIK2VkGsGePXPYwNfhXnBvUr X-Google-Smtp-Source: AGHT+IF0peGQVF7L4jTD8/d4Sadc653SulLHWWDndc7X5zqxyggPMPOgIs7sa8KrcOZurBIkzifbYA== X-Received: by 2002:a05:6a21:618f:b0:1f5:59e5:8ad2 with SMTP id adf61e73a8af0-1fea2e9f4aamr7367098637.24.1743083836053; Thu, 27 Mar 2025 06:57:16 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-af8a2a23634sm12786656a12.60.2025.03.27.06.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Mar 2025 06:57:15 -0700 (PDT) From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Subject: [PATCH net v2 11/11] netdev: don't hold rtnl_lock over nl queue info get when possible Date: Thu, 27 Mar 2025 06:56:59 -0700 Message-ID: <20250327135659.2057487-12-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250327135659.2057487-1-sdf@fomichev.me> References: <20250327135659.2057487-1-sdf@fomichev.me> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jakub Kicinski Netdev queue dump accesses: NAPI, memory providers, XSk pointers. All three are "ops protected" now, switch to the op compat locking. rtnl lock does not have to be taken for "ops locked" devices. Acked-by: Stanislav Fomichev Signed-off-by: Jakub Kicinski Signed-off-by: Stanislav Fomichev --- net/core/netdev-genl.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index fd1cfa9707dc..39f52a311f07 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -481,18 +481,15 @@ int netdev_nl_queue_get_doit(struct sk_buff *skb, struct genl_info *info) if (!rsp) return -ENOMEM; - rtnl_lock(); - - netdev = netdev_get_by_index_lock(genl_info_net(info), ifindex); + netdev = netdev_get_by_index_lock_ops_compat(genl_info_net(info), + ifindex); if (netdev) { err = netdev_nl_queue_fill(rsp, netdev, q_id, q_type, info); - netdev_unlock(netdev); + netdev_unlock_ops_compat(netdev); } else { err = -ENODEV; } - rtnl_unlock(); - if (err) goto err_free_msg; @@ -541,17 +538,17 @@ int netdev_nl_queue_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) if (info->attrs[NETDEV_A_QUEUE_IFINDEX]) ifindex = nla_get_u32(info->attrs[NETDEV_A_QUEUE_IFINDEX]); - rtnl_lock(); if (ifindex) { - netdev = netdev_get_by_index_lock(net, ifindex); + netdev = netdev_get_by_index_lock_ops_compat(net, ifindex); if (netdev) { err = netdev_nl_queue_dump_one(netdev, skb, info, ctx); - netdev_unlock(netdev); + netdev_unlock_ops_compat(netdev); } else { err = -ENODEV; } } else { - for_each_netdev_lock_scoped(net, netdev, ctx->ifindex) { + for_each_netdev_lock_ops_compat_scoped(net, netdev, + ctx->ifindex) { err = netdev_nl_queue_dump_one(netdev, skb, info, ctx); if (err < 0) break; @@ -559,7 +556,6 @@ int netdev_nl_queue_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) ctx->txq_idx = 0; } } - rtnl_unlock(); return err; }