From patchwork Tue Mar 25 21:30:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14029518 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 B0CF0265CC8 for ; Tue, 25 Mar 2025 21:31:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742938262; cv=none; b=upv5BSiBkMFOIDGHupjBPfHrvPPA/zH8mttGsEpIBIQvRCZ9Gx+rodb0ClCVZEglHeRbbtczv2QmHXx9bBcrN2drDj5OdnrwjWhjCKAPNdGc5ZwATayb8yhh5M9ecpNtocI8EJ3TE5T+KIoE1xW7DOgPnmIkbUzGnQaiOP+t3rI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742938262; c=relaxed/simple; bh=ubvtV00usCUlu4B15x0IskAav2vYjGL/C0e+ijFYpXE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X/w3HgFPDXn1BMOvJAiiKnIy0U3WFgXPpDH2wkCgBvtSb3q3Rfgwvtk+Gc4WUDg3BVrZAQgqLfA732/2GXVoYwGnfMwOKrc7D0DOtCVl5KsptH3h+x1kMLksXBtarEzW3znfqymXhJDo2FXYyEEHqa9+W5WnsFDK1ScfpL8rxTQ= 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.179 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-f179.google.com with SMTP id d9443c01a7336-22409077c06so134701915ad.1 for ; Tue, 25 Mar 2025 14:31:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742938259; x=1743543059; 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=xFPA1zqSSDNpg8Ij+teJMS0m0J223HfVwa79DP8ntPA=; b=Ltl/Y838UaOq+NWQoKRjzWZuJo8fKN/TmHfkclSStgsVMRZZM17i9/yalk2n7SKHhn tMAkD3l880Omb4C66y93tv7NSZeUaEqMdWOvUvYEGkakUwp0iqYuW6FTSjbua1AQVDcH Ieh0UrXveG70+9Crzg8cX37NPBnpy7VUvVZv47xUaB+27QPLKbKgqAWa0BFrPZr0erld JU7hwtnE/O4oGbM7zepoY8Re9ye/BIS74/JNbqJMmX7/qGhWJvPqRJR4TIdJ1lKIaPA4 mP62UoOfXz8INgH6FH14QwKaNPcKHqp3nE9C54zPpnWlP3t7wvxkYe3fmoDBY89coOR/ DT0w== X-Gm-Message-State: AOJu0YxqufZIFymODX7Z5RPY9e9G0PAotQnAXG9xcwjEXYhzqYk98KUT nJT3rdAxK2Rd15FnIUOo1K0GEnamAe9FtnEs8HH43gSayFo5TqM0ufBVp8y9RA== X-Gm-Gg: ASbGncsc6t//gzdLV+VEVhcyreWOjXNeql2HpFfi3mNiefjl6+BBdLUgSj+1QsVVKBw uGZaMLPJOAw1BhXB3mqC9Ic7NTTxUqpEevp+RsYNLyVio3hBbYwChnEqur+MATPjop2l9twF9m+ U0OZiAKqIYBg/6mCwIr+fodzXxDAcj/RQ7H/pU5pMMm6f7pKIdFwFMcwW3Iyw+9x1RNvDirY/GX 2Tnhhn4k/GBkpt/5XAJrtrsrx9RRkqFrBZCBFZm6y2JEBSsXxI7SpEsrX5aA46NSFeO45R2Q3Sq BR6IVQuEHAbIIkdcYvmncu3jQQM07NkJXT+k62/80/EJ X-Google-Smtp-Source: AGHT+IHBdyaN3xPMkmk9cPzSbNW3vmvw++RyLMVuv4hgv1uTh9fMo0g7x/GCAJX4BGDvdyEr0DpczA== X-Received: by 2002:a17:903:166d:b0:224:584:6f05 with SMTP id d9443c01a7336-22780e09d81mr283233815ad.41.1742938259024; Tue, 25 Mar 2025 14:30:59 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-73905fd57casm11055546b3a.65.2025.03.25.14.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Mar 2025 14:30:58 -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-next 1/9] net: switch to netif_disable_lro in inetdev_init Date: Tue, 25 Mar 2025 14:30:48 -0700 Message-ID: <20250325213056.332902-2-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250325213056.332902-1-sdf@fomichev.me> References: <20250325213056.332902-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 --- 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 b597cc27a115..8df428fc6924 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 Tue Mar 25 21:30: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: 14029519 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 D592A165F16 for ; Tue, 25 Mar 2025 21:31:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742938263; cv=none; b=O3YKvD7UtuefXkNhIOZVKuat7pnZcWFFZfFVbajwGjHSg76hF4P98MnJceiqSpYBwyb6otJBhiY4lvWFRo5W7sjo7PMAEYg1Dn78+9YGdUr4xPj9lKYXFKvLIufFge4Ud/VPdVPvaE/U95ZZhf1osUYy1yNCRhqPRWH22oO/4fE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742938263; c=relaxed/simple; bh=9cN1mnZYPdbTuLyPYME9DwUnMLCMZGu7wMN0yGCWtMg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HoIP52d4/a7ZOXrMvgZa3IlYQsh3Hv/eGMW1FqRW0Iwt6nZ5dGe+MhhHVGx8TjwqksKaSTBrfNco1+INR+KVMeoL7ZG2IX87mZcU0AaBA01Nz1ryI0WV2lVk4Bogjzxbe2c+2feACwf5xgw36JT/JmPPVWBjTP0X7DRHPOkQcgY= 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.182 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-f182.google.com with SMTP id d9443c01a7336-2241053582dso51203265ad.1 for ; Tue, 25 Mar 2025 14:31:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742938261; x=1743543061; 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=Qbc9SPvdUhMYEZgc4W/JfKQwvmAd91zf6wDNocXeRcU=; b=Ht8bPJdwkWiYa4S9zVhz6bDEYS1NQ4sha8QJHJzUr7EVGRm+Nr7btfrX22YmcJDSIZ 9ECdSKjPoCNChAtiPqHOlpd39O3nmMw1bkMmxj//zzteksIg8xhDW/8NkrIdtMufd4x3 a+BPmmUHw8S+13EvZX5E8QWivFRy5AtrFso/WuOE/BL31YBLr1NNBOlXlc7J4vieujKd 8xDExhr0eTaaweU8EKlx/PHhnC983vPNxX/2YswX1h25Snm4zF96sgqRu4ggUVbVVcGW SLVWIGC5EnEuqxbEN1mD/N0f/2RWNQOU8Wuw66NYeXTujeTwZtint/gK8lghnc2QKu8f iZfw== X-Gm-Message-State: AOJu0YxztNE97C/HdrgswU1Bn462GS3MJa3U/BJOjXUJjFc5UaXRSIIP E/JmUrQ5JXN3FCtNwkwkEhigyjjCUpkr0sez8QXQR5O8zPPar72tsdPYi98Wew== X-Gm-Gg: ASbGncuAsLJFHJLfS/KRyl4wD+ym6Ow0pUiY3f1lEZsdgk2MYygufzxIDYQC8Osie5N vqUluZXYkboQY7y1e6wyRkA+p7zwAZShb/Q6UALk/DuCExNRSshoLBdy40sCqNW3ZeLUC+uZNMW BLlYMMFqA8cPMYNB+F03LSpuzSyn91iO+hiMmLQZBboTD605Z/awHPt6skb8Hc+DSA/wVkC1RrY znuu9Ouh44DKETEeTmZga+7UuRWVpt5aMdFcErbPK4E4EjIZn+s/6KEJnDmdmsnnjLtSHHiVonk ez5mqXsW8djNQZVKL4XCIlV0HH/vxDmiMYNoqzO3jeJe X-Google-Smtp-Source: AGHT+IGScIDpf3rIgwEJGKwR8xzuyYdaS4Y7ob6UkPfqZlpFd0FdSRzeJat3aXiuUkX+7CSwPvtplQ== X-Received: by 2002:a17:903:2350:b0:21f:74ec:1ff0 with SMTP id d9443c01a7336-22780e14e77mr301886455ad.32.1742938260531; Tue, 25 Mar 2025 14:31:00 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-22780f3b7c2sm95689735ad.8.2025.03.25.14.30.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Mar 2025 14:30:59 -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-next 2/9] net: hold instance lock during NETDEV_REGISTER/UP/UNREGISTER Date: Tue, 25 Mar 2025 14:30:49 -0700 Message-ID: <20250325213056.332902-3-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250325213056.332902-1-sdf@fomichev.me> References: <20250325213056.332902-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 | 61 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 8df428fc6924..bbcf302b53a8 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, + bool lock) { if (dev->flags & IFF_UP) { call_netdevice_notifier(nb, NETDEV_GOING_DOWN, dev); call_netdevice_notifier(nb, NETDEV_DOWN, dev); } + if (lock) + netdev_lock_ops(dev); call_netdevice_notifier(nb, NETDEV_UNREGISTER, dev); + if (lock) + netdev_unlock_ops(dev); } static int call_netdevice_register_net_notifiers(struct notifier_block *nb, - struct net *net) + struct net *net, + bool lock) { struct net_device *dev; int err; for_each_netdev(net, dev) { + if (lock) + netdev_lock_ops(dev); err = call_netdevice_register_notifiers(nb, dev); + if (lock) + 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, lock); return err; } static void call_netdevice_unregister_net_notifiers(struct notifier_block *nb, - struct net *net) + struct net *net, + bool lock) { struct net_device *dev; for_each_netdev(net, dev) - call_netdevice_unregister_notifiers(nb, dev); + call_netdevice_unregister_notifiers(nb, dev, lock); } 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, true); __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, true); __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, true); __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, + bool lock) { 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, lock); 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, + bool lock) { 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, lock); 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, true); 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, true); rtnl_net_unlock(net); return err; @@ -2072,8 +2087,8 @@ static void __move_netdevice_notifier_net(struct net *src_net, struct net *dst_net, struct notifier_block *nb) { - __unregister_netdevice_notifier_net(src_net, nb); - __register_netdevice_notifier_net(dst_net, nb, true); + __unregister_netdevice_notifier_net(src_net, nb, false); + __register_netdevice_notifier_net(dst_net, nb, true, false); } static void rtnl_net_dev_lock(struct net_device *dev) @@ -2119,7 +2134,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, true); if (!err) { nn->nb = nb; list_add(&nn->list, &dev->net_notifier_list); @@ -2138,7 +2153,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, true); rtnl_net_dev_unlock(dev); return err; @@ -11047,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 */ @@ -11180,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(); @@ -11972,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) @@ -12069,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 Tue Mar 25 21:30: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: 14029520 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 149BF267B9D for ; Tue, 25 Mar 2025 21:31:02 +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=1742938264; cv=none; b=dps3DXMuDfzXFY3vJw/uZnxU+7YVkkeGqVaF08yuOaYyzUVbnmsUKtTBLEbjZRvmYr/0ek196XJudE4qgEy0IcHDI74PqwEaT9M0zDjVhTkfN/P3MEXUJWpNLm9a8STd+d8QWfaYYUjUzvA7xZTQ6zBDifWo7aWAy7CLmPdjptg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742938264; c=relaxed/simple; bh=1i0zmyNtMUhAKyD1bOggzZ5GfnWc/xFKCOrXOfl2ao0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bzQ0AVr+SRicQHZKSyYqe2WFmaQAQJNHy5cIl+4BdVLAcVp7pbp5kLqMKHWHhkWdDjhAo0L6YfEM3dgLpv/Xs5iT3B7apqLqLVTVSwve18HzU20HqQOCHiDmKrRNucvjR0N3aP/0vHjNokMO1vWslHGALcdyFEyCeT5DIal3NrA= 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-22438c356c8so126233045ad.1 for ; Tue, 25 Mar 2025 14:31:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742938262; x=1743543062; 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=C1FwfdhYfIumAe5mcpaiBwsps/nbgCpH3Gm/8KLhBBc=; b=oMdgp2slZMjxuNCTH+HfPObrldfBohAdjydTLY/XCBEwNikrC+gLybIICoIMxKMe1a ArRIkCv2JVVMMjXtS9Yx5ZhJNdbREc7LFj7OrcuNJ72jvdVW6CWwBJk/AruBDSCMOLxl v3KjTskx28Lj8TMY5Cbrs8TOSAIHGX1OMMMuPZMssyzZrSmpQVVJvb9cFS3xp49TmePS hkIhw739yZHoAr+pwtVInMpUVNn6PnNlHqCy5axd9kt96VczRKzyUOkxPBS1CpeSU4+i rypkPLgJrfFNb0NTjlk443D0qeDonFwaaI5eTg6k7U2ICl8kN82FR1w8gQ1Tx9EamUqA KOvg== X-Gm-Message-State: AOJu0YyQnVrzS7czaEovSm6qOvZOKLyV5WILKwhuqqiVAaQmpQgIhBc1 EE+gfoDly6lI34vYEinm/iFeJBAaSFc5yEsIc3pj+S7MK5Fe8m493LtR+pr1nA== X-Gm-Gg: ASbGncuzIGrsywuLbYyp44G5YBe38oHm8u47F3jxHLEBXbX6yzptLEi9GVqgoqxaPmS 8+Rbu7UQrBWtLsLDrodnQuuuiCNeQM162kMBML3TpsaUT18kW9RTTAzJHaFQe8tjIa+IyeuFVtJ BTA5Mq72/u9SziTmATW2559iCrtS0NPsA2tUEa9AU2KfO/pq9LWtXZx0HV/IKXtEi+mzJy6kofw k/kv4ZuOTfLxOqgGx/uWku22DRHd4wL2VmWrj8rde++dmbWlrDMUqeZqx87/2bQbyrwP9iqV+Xr RPPNibcfOQD7FXSftUTne4mlKAqacCdjpHu28wWplUjk X-Google-Smtp-Source: AGHT+IEt7+vGxDfOI1I34fPHYDHi7JB84IYxolT3rUnfX1XV8SxCrkuV3A8VgZhYTbZKWaP9S3mmCQ== X-Received: by 2002:a17:90a:e70d:b0:2ff:5ed8:83d0 with SMTP id 98e67ed59e1d1-3030fe94191mr33755400a91.16.1742938261920; Tue, 25 Mar 2025 14:31:01 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-301bf576d1csm14904123a91.8.2025.03.25.14.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Mar 2025 14:31: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-next 3/9] net: use netif_disable_lro in ipv6_add_dev Date: Tue, 25 Mar 2025 14:30:50 -0700 Message-ID: <20250325213056.332902-4-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250325213056.332902-1-sdf@fomichev.me> References: <20250325213056.332902-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.h | 1 - net/ipv6/addrconf.c | 17 +++++++++++++---- 3 files changed, 14 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.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 Tue Mar 25 21:30: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: 14029521 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 90632269820 for ; Tue, 25 Mar 2025 21:31:04 +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=1742938266; cv=none; b=TE5nYdtTEECkF0l9KGeQ/zAA1k6ioH/vIbNNyxZkE6RsWse76/A8yK5sKPe9o1f7lnOwGzONI6EcHXLHIQQWbD2Evz1wCKI5QsjXuuuC5VJgE+lej4f9d8rPmARWPsz4eeTFLfVaPRw6vpxD84JQv6JZrSInB5kruezB3MQ10+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742938266; c=relaxed/simple; bh=No/0VfPK7pHniKtbbaQJ0cyWQL9HoLVC3b3WbWBLe4o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gSgUcmNCiGVInV8uz70IArkItZTCmZT6bc++r6e5nTDkIWf9OSP3coqYHDVmL+ArrNd268VtWTbIZbwzdh2KEyOMea6qus0qExC9RTmvE/M1Fzvn4W4dP3dVvfNEZG8xHckp+cJJ1q5ACwxeZ30BcjcPQnYjM9RC2xM1UQ9wUKk= 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-224191d92e4so120824535ad.3 for ; Tue, 25 Mar 2025 14:31:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742938263; x=1743543063; 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=N7nUwE7gDDB+Yhu0LCZ9OCLZj6cuse6T81g17adUbcdjoiCAOlYIg4dG2y+MtH1aMs /oeWqDY2/FAhEHmwrJq1y6dBpz2e2hskBS3K1vpjUwnFbjm6WUJ8LkcXWJZWiUWPBwcn pGU/B308e4scy3dYm81gviQP9kikfRBkiwpGam8241/nRj112ZmW9HbTWt4WZPI99cp5 yB98OHlP/MYF3EMRv9Om1bZLCaTt8qxOuRIrGHTbxOFvS9aZsjje/I/5Fe2w7+mbXfRI AFvHADHWevREzUsRMrgPt07dEKhinrRXfQiezwTdFb6Fn8JO4bkCLAxCRdEKVT993L4G YH+A== X-Gm-Message-State: AOJu0Yzp2F4HYBMT3fpwTmj1MXPur5yjl62Cagbhn63hqfiFLU5g8qKN J9RZoyQPVoReWxYqOc5FYXAXhlYS3O6Kp0KVr2Akb2Z4LoPWkL2xDMCRTBIvIA== X-Gm-Gg: ASbGncsnzLYrgm50zU8T3daWXJfEcZIe5NaQ88/dnyUBpigyBzgdXLIdZ4+Mgyasjrj AD5DBqI5ZDs00rzzyhNWm40C964H1svuE0qxbrE1RdXp1a2Yzwanc7lk0wFJ90akuPYSEANjGZ/ b8Kzmm1p2ebVKhchTbAbVZGseuAe3WtXd9F/5PbPMMidKa9jK3bfbaMoTauyLPtrzIlAZ/T4o3X LZoiB7BBW/UKo9xRMiETttphEuvj7vCgvdqldGHTJx48ebFd+/T62u2Pnz/RJbXefGvv8ThzH22 TLKbDaVEXfu9ccwmdgUth00nI07uZzgoWdOzWi7si0tN X-Google-Smtp-Source: AGHT+IFaTFXA4c18TXOPsCkqdzuAjLzJMdJ36/UE6qKMgOWlpKRRDkXbBhWA5/eqY04gB9GIZ8gzNw== X-Received: by 2002:a05:6a00:14c6:b0:737:5edd:9805 with SMTP id d2e1a72fcca58-739059f802amr28215118b3a.19.1742938263303; Tue, 25 Mar 2025 14:31:03 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-73905fd564fsm11077708b3a.52.2025.03.25.14.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Mar 2025 14:31:02 -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-next 4/9] net: dummy: request ops lock Date: Tue, 25 Mar 2025 14:30:51 -0700 Message-ID: <20250325213056.332902-5-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250325213056.332902-1-sdf@fomichev.me> References: <20250325213056.332902-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 Tue Mar 25 21:30: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: 14029522 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 DD5C2261581 for ; Tue, 25 Mar 2025 21:31:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742938267; cv=none; b=s63WCx4NeT2PgKiq74Nljc8SXtbSQcxubwX3pf/Ioqb/MlmKndiTJo2mM5dpPWuqFSnzvq1pnNCPX2A5Qoyg4NkjDAmezuGOAYjJlwB32EFDjg9NaKLOfqP5Fx4Qh7YZ8LtJeDsQCfdSncqZW+O+1CZkD/Qt63iD1cRbzEJqLqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742938267; c=relaxed/simple; bh=3hKDtQW7nguGUkP5QSgPQw+SY81a3nOos9zYGryXqG0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NXTtS/83lHKvBeynX6okfTyQUla9CwyjRjTmrehAxjU2u/zBXon2pmz8jkA4PEga70tAyiKeiBp6a6+5NFxNMPbbSiCV6AqZ1UGU1KVWs5doRWzecMCkXYgDSzafKsMoB+dnY/yWGTaHNWS991JGa3W0Rx93s9EzhqSYs/0G+kQ= 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.46 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-f46.google.com with SMTP id 98e67ed59e1d1-2ff784dc055so10314061a91.1 for ; Tue, 25 Mar 2025 14:31:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742938265; x=1743543065; 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=OpWV28lY7+LV+jqD0cQnrZVOXDsPx+xK/tnI27PxWX4=; b=dVUHs42Y8cuZRE70F+kWA9xZjsj+ofI4ojIsFzfrcatZ8OjyWzZf40Jbrz9pQRELbs Suco79LJewIZxVhMNtMlIDLqSSBvFohIpbMzu0L2+1q6KBPa9Ji2nortgMGQkmtH8fCU gPxFIx6giTXzOOQ0zxiHnXtOnfph0Tix/sdTQVQj9rNOETagPNeQTZ/ZGODyGUIOND2q fwVsUVjikFxlo+W+FDvIrzbom+MV4N1+y5tyfUudM1ejjv607gJdl2PAQxUiOF/8kFEU KabxpKiiEUtIpw17ZEiCOyI45D6RoZAoKMl9Yq6//YiqPn4VJyN7WFiLXyfps7NKevyK fTZw== X-Gm-Message-State: AOJu0YwF98BtrQmhUVLIPwwvfgRmWOX6wRbcUFPAXzW4knEzFSy17W6h lVXUlWzDsNJmaU0HajB5POTuxy0HnrmOW/pOBhxqsNAjGXMStBqV/MqF73zpSg== X-Gm-Gg: ASbGncvhiYIJWw9BZbNHT+xG3bLCjeRgIKgm7UMfa9xaysUGHR7VgsFn0gdSo3yHXVU aSeB1aZH9zH9Dcw70XlUc93ht/JUMo977IradjF5aXTD+iKBWURmfpaRKhNn/51vxqOA+K7VBxi Rh5at9WbcmHhG6PZSJ62fe52uw7vpUTZmy4Z3Bd4YybvPnqCxfe4/RWgk060Rw1u1GqH49mV6eU K4YrHak9kicYNbmaWXHX95SkmTgtzSkzGz7iiIzHQWYYgVfmfgb+Qq+8CRdHmLK1AFnz/+sc19M KPGPzhOYzO9X6PSRNtKlJOPyuuwNXD7VYAAX0NlKc4i6 X-Google-Smtp-Source: AGHT+IHD7y8DyJwwKJUrU/beMMyQQP279Umly0jZ34acnXzak34t+byLkvAMFJgSQxQDWKv39It1ng== X-Received: by 2002:a17:90b:48ca:b0:2fc:a3b7:108e with SMTP id 98e67ed59e1d1-3030fe726f2mr27907263a91.4.1742938264552; Tue, 25 Mar 2025 14:31:04 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-227811fa212sm95407405ad.242.2025.03.25.14.31.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Mar 2025 14:31:04 -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-next 5/9] net: release instance lock during NETDEV_UNREGISTER for bond/team Date: Tue, 25 Mar 2025 14:30:52 -0700 Message-ID: <20250325213056.332902-6-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250325213056.332902-1-sdf@fomichev.me> References: <20250325213056.332902-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 e7f576d52311..7a1b160c5f23 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 Tue Mar 25 21:30: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: 14029523 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 33B4325EFB9 for ; Tue, 25 Mar 2025 21:31:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742938268; cv=none; b=LuQ4xYG/f58atHDHdkqon8dEk9UjUjsASbzzNMAXTQlJsZXfx3rlGsCd9sHC3NQP4xhIaKe89U5u9DX9SFlVGzck8PjWz8PWHbUcPhFZFg1ZojOF1Inl/yNmgCSJcUE/R4PybdK2K89EvJNNQ+Pc32YaMvMTlYdkpHIpZKqCtsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742938268; c=relaxed/simple; bh=n97bsKeGNxiCQENyEnu04SJHTKTffra3u3PkxcA2ORQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jLer7bpebVzuxSWmlJqzKOpFMarZnDk2vMDnRLlrgxiUsglwPzaeAvFpRiff06ViqMjhtCvoYloykZzQEADfrfhsoDA/GYoISmHDyYyF+p8gLObcGeseHqyC/kAAYqm4+gCZOz//EECdV7ltwWEzC7tHlflhyDnEnzk/mIlOMp4= 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.53 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-f53.google.com with SMTP id 98e67ed59e1d1-301cda78d48so11696306a91.0 for ; Tue, 25 Mar 2025 14:31:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742938266; x=1743543066; 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=wzrYYpYH9Lh+By3wnhkOCr0i1MdATP4svlLPkFKjiYNiCzqOFM1gvTj4M+Wx3tC+L3 pJIp+//YGHYFa6M5ph7aeNi3M02vws8A5Vj095lRnGvNENRepYCIhikazvb4wDyNBGA5 3QnNgyKld3V/y2Z/znChqXeoQOSaxAZ473Nf6l8LYetSut0eKLn0++svbVSgBMbLKjm1 BTigX4qNHuTAyHvRC4v38xxm/EwLTpwheR+VuWmiXM3dM8daMmcxK72V5S7hBvbVi6zQ Onn05aQ3KqIwwJ5Fawv1km/lgCCLvST0B3OiEhis0IJYBRkTZFbPOmglBVYqkJRXRtbt JVUQ== X-Gm-Message-State: AOJu0YxHTV8s+e/QOVn2XuiSG4thIs4eLSfQnS/UqkIafInkmuJW5wvx olw6FFrq+T02z3T2/AdLcAorJxTMTx5Wqm8qm6mVHK/X+EJgrcgCdK1IUFCE8A== X-Gm-Gg: ASbGncuHfKnbEtPN5SNspG+y0lax5pM/1rLAbrbWwp/HP5AuWMaYkBlU1qf5RWp2hT4 T+zjEHTyc+f8TuvhgNNTHZKhh2xMpSFyfS7N4Dk4abZU++M9pQfbLLGmMtOW4HCsk68ZEOoe+0P IfqbzHZuCMd9sHlQkg+3OxChGHr8Iz7PvWEo2KFqYAvO2Xb91ULDBMoUNIkZ/HoKPTjw47nOY+P HSNUq1jxXtOf6vTwoaepQoJ1/AGbezTDbYX/ntuZC6G84R0fONr5dqBOSrXXNiZcY58LcZoHfLS gvlCW+w9cRHLU2YVtL5/tz4NxuX3+M50D9Slevvlvnci X-Google-Smtp-Source: AGHT+IEJRO8qGZLVcBLFShtZDMdmOIGOp0JTzA9EUpr3eXlJBWjPtXrpQuUF+Fx0IEiyH0aui9flxg== X-Received: by 2002:a17:90b:314c:b0:2ee:53b3:3f1c with SMTP id 98e67ed59e1d1-3030fe59853mr28286864a91.5.1742938265969; Tue, 25 Mar 2025 14:31:05 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-af8a2a4747bsm9550172a12.68.2025.03.25.14.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Mar 2025 14:31:05 -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-next 6/9] docs: net: document netdev notifier expectations Date: Tue, 25 Mar 2025 14:30:53 -0700 Message-ID: <20250325213056.332902-7-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250325213056.332902-1-sdf@fomichev.me> References: <20250325213056.332902-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 Tue Mar 25 21:30: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: 14029524 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 D18E9269CE5 for ; Tue, 25 Mar 2025 21:31:08 +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=1742938270; cv=none; b=GEW1Ivm8E1FAHupK7LxtYpfPZGNB+pJwyL7F899UL0q+6IhjZcQmBsyHpE8ltdc3rYjOH19jGoXUV5bWgm8l3qEkV3Wzb/nqOiyW7V6fpNsQlRRpzQRdrRFwKRR1OLb2nQTMDwd/wFltLMLOODWT2GIZ4KB+EI+wgd4ozhS7HYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742938270; c=relaxed/simple; bh=rycKGXFoqAeC5tPx/73rvy9De8EwBoLt/+IT2SfEVXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WcMuFNdw0/2dixNfd7meWtqM8nIVMRufAjUXNSBqopA/IKLtlTJJK1zHrxzfKV9CDhN78bRRn3tj4L44BF1ZhZ7OMn3amUoYSh2fXuBMGsgrn5fGjDNG5CsqMXLUP2uaiUaHd/DO9hA3vVC8RbXhzhNdsXnFwewhKgFIoZMouEg= 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-2240b4de12bso58100395ad.2 for ; Tue, 25 Mar 2025 14:31:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742938267; x=1743543067; 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=BaIahJ/OHkL8cpXSmzaWHswKP7Zmr5DMtULZ/oR7kyfmPZ7dx0Tnti0KzsTSsr09Vu 7Q3+MqNoo+VFLEHyku05+MsK1RRsu08zSvRAbECE2VyCs8TzgE5xcbuHBZVh5m93Apyh NWkNevXb7CvKwMMaC1LBqDlxAGTYaSKHa4Gc0tJJwO0nfyiMVJoLH5EZgvmmnVcsYT9c BSv3QBfrrMfW6HbPTQgyUzrbzYNqmTvdk05yuZQxjghI9iJawyPm9cWJT4RDM6wg91di DjK+TsadsUvzkNOxrO+QGv2Ia5lsBqiv3SiLShbcW5DE15U2kNqNHF6ogJEVDgTOtxJs 8KLA== X-Gm-Message-State: AOJu0Yy3dnoxofEVgIR9j8F7207w6xjuwRzg2rXyUXYagtsZeFQVWCEg WHez7zc6Qgk0fn6Ba8ld8Lnj3jt0mdtZtPhRW5s+5CfPTTjo182IDgFHxcOpqg== X-Gm-Gg: ASbGncvDlIV7J9kwh+YfUBny94d8xt0ULIlUNwVk4X5ghTBwojAT1cKmxeSgPJx4Mw6 Alq/sLSa3OeTol2RaktaJ88wNIDfy5q3Dh28GauuoGpsMfw4ZSFsnKxqb7Vw4LXguXpGu4dMhmb eA1bdZuCtCGP6djgLCOq+/90OvspEaU5A45H0FjFCTq+TStSabXG8+Iv+rHjCwAoIzGBgAGH7Rr 7hvD4Gk9FnO+40rWdsy6S7udrwGLNrPhp3+Mc4Hy/Iej1yR9LqUFV2NE/57NtW9pihj3MzTdKDP NQNiFJSndlvpYbZPLPF2Uk7mGK+PnrLpePlMosy2eGyn X-Google-Smtp-Source: AGHT+IHZf3Mp0naRThMQomdyYw1aEdk1eMLcZBPlOtxqcR801njRpKTtZkAbuqRTPWLShDqy+LhXHA== X-Received: by 2002:a17:902:e54a:b0:21f:85ee:f2df with SMTP id d9443c01a7336-22780c79888mr270957775ad.15.1742938267261; Tue, 25 Mar 2025 14:31:07 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-227811da2eesm95631605ad.172.2025.03.25.14.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Mar 2025 14:31:06 -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-next 7/9] net: designate XSK pool pointers in queues as "ops protected" Date: Tue, 25 Mar 2025 14:30:54 -0700 Message-ID: <20250325213056.332902-8-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250325213056.332902-1-sdf@fomichev.me> References: <20250325213056.332902-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 Tue Mar 25 21:30: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: 14029525 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 F2BE71EA7D3 for ; Tue, 25 Mar 2025 21:31:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742938271; cv=none; b=ECCPBkrs06Oq7RlAuyACEscFIoFE5A9du3T4Xc6Ou+tvOjKv03KvQLrEenbxaKp+saQMkEbemN8/+Xb/6fOCcGZ2LE/tpQ2RjHyc8tD9ykmQl62OisYa0V4z3lCwnOaqipqiKdCx4/4B4Yy6/en/ip2nPv4ZBNg+TmuaLn5q3TA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742938271; c=relaxed/simple; bh=u0NFjKidKiCCC5Zpktj60hLTvahC55mnRL3QytGn26w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U6G78F2dnXONr1se8AZT8kxb2JHaB07RlqQTbFwEIBwtkr4Jdxbo021cFdP7DH/rIN/JyAb3VlO9Fu0uiLUth600DLNiWxsM5eDj4k9cTihZTaBV558/ERtC1v4ffbRDy+gLWbEeRYlgDAUpyAo6g79yCOGXTkDOlSUMto4wiTY= 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.172 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-f172.google.com with SMTP id d9443c01a7336-2260c91576aso103744175ad.3 for ; Tue, 25 Mar 2025 14:31:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742938269; x=1743543069; 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=OpxWmB0uAND3cvwNO+EN3BRKNqzAQc/XiisPNxzPy+o=; b=FV2YMdt4Trnt41SToofO0W8hW6hR/RZfgpbWkCl12fsNzJAwwzbH7eiy8TdSkWFICp /ATetmlMUHRQONr5vHVpFywZksRoPhX56mu2yZucPiuKnzO7b7rf6gj8j3mtdd7bwxXI yOELFAsRn3usHsaARJBGo+ki4OZzHKtGl2G8qWO01nThmFSE+8G0R96eeCmzXj54H00f O430WXowYuLhajtG8+VMFUq8oop+Jq/f28oE+zpS3WHPxcgkVwI08g/DaVLp4ZE6lDQo 2w2emO+VQb7yMbyqKUod0dJn8y2oTpz2+ndMz2VAYNmYdUM7NquYzPMLgaWNk+AT9XaC h0hA== X-Gm-Message-State: AOJu0Yy2aa2/tzPvWJmY/l543rhPk9MTIp6BVlMlV/+jdfvlFP3H5+xn 13RL3KncOlUyvkN6AmmaGgx4nn3COQbO+RvBIGhlIwqxO6O9urXOCgnJ9qPCTw== X-Gm-Gg: ASbGncsul/yvZCdzqf15G9MT76L6hOJttlFwszpcyCKWqMKCD+X9jhcyu6qNs0Q+NtW IMe7r/IEuvlr6uKZoNeXul06BRUlVnRvgU4r14XuGqyJPpbm1OmF9/eibz+hopyRcfLUp6C4Db/ ck0L5b1+lDVqKcC1P1TTrzuBAJHHUcEQjHa4lvlM3i9qb8hNgAPCq0MPWvEsYOTcdkkTBB0FS0p s3flTsDfrJ1JkjPz/k6I61i/xr4DZFIMZj8WyWsUJwy6MD5JynOrKg97e4Bz7Evi4Mj/L6grxIg 320WjRpBPjqG5tcG+4/qvDcXTHcYLtGQbzhDffVMGad1qa7/AT7ro7w= X-Google-Smtp-Source: AGHT+IE1kCjIGhTZzWTzQxtjK+v0B9Pg5luT1quOviI9496U8IpaRYj6jq/AwBSjw/2asXiifOa+lw== X-Received: by 2002:a17:902:ea07:b0:220:ca08:8986 with SMTP id d9443c01a7336-22780d828c4mr292248765ad.22.1742938268622; Tue, 25 Mar 2025 14:31:08 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-3030f806f1csm10850235a91.46.2025.03.25.14.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Mar 2025 14:31: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-next 8/9] netdev: add "ops compat locking" helpers Date: Tue, 25 Mar 2025 14:30:55 -0700 Message-ID: <20250325213056.332902-9-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250325213056.332902-1-sdf@fomichev.me> References: <20250325213056.332902-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 bbcf302b53a8..3589cd4471c8 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 @@ -1073,6 +1085,18 @@ struct net_device *netdev_get_by_index_lock(struct net *net, int ifindex) return __netdev_put_lock(dev); } +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) @@ -1098,6 +1122,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 Tue Mar 25 21:30: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: 14029526 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 5A53A266B55 for ; Tue, 25 Mar 2025 21:31:11 +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=1742938272; cv=none; b=F1agEXx7ECaz2tSQHE8s1Khm51tx3DbrlZxacpCqYtOQ3HXx1r4AsJyGqRZmT2S72H4B38B3aWK9vodWdxR7l+OENQKaqJCykMeWHBl8FWlyZmUUUwLGulE6M8Ei+4o6MStr74pKGHllK4hLu+njOuj4BPu+COmTimQvyn98oGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742938272; c=relaxed/simple; bh=CUR5I3UpwjbNO0hNnmCCSuAoAxW+HdofdbYjgHwMqZw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qHs3T+SF8TjStFcPuu8Af02o7gpO5BoW0jmvcnbmGx7i3sllnFvUC+rGlkfAaQzjkJTsjvyruUcqGjptT30bZdoyYwEv8Jkrn9sbQAc5dRMwE4JI7e4z4CP/I8vaUBUhvAd7PvylMmcSC43wd4brcxC+OsaWMFPCIup3aIhic6U= 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-227cf12df27so3945595ad.0 for ; Tue, 25 Mar 2025 14:31:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742938270; x=1743543070; 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=U7PDakPclO3JNXcHdq7UwAyXbGp5zp8H/tjCaEb0xubS2LzXQlq9FCKH4LRrvYmryQ BRX0u5zoRUth2rlEHmu+YNJ16dW0yYS6BqYdWSQ6TKhiYKGpC+YTOi3yLbkP++Y1JEcN psG7pQp66W+x7HfrLOWpU29L58a1icWBM25vMK97nVZhjk43jG4IDZxjdlh4JAPsxIVm GflcqYy82FkpNzFZVc1zt5fpfGMueYHZzEgS+fFYQVO3VtYGjFTgC5W9gxOiwLZLoWw9 yEPwXxno5NWaFR/OPnHMcdtRlYYyTMY20hJzour3kJ+jJUrvOxoJdeO7kOz2HW3Jovqy uSSw== X-Gm-Message-State: AOJu0YxTkXFCnnxyshtpL1nAIxyR+kmCUwH9rEZC5fOLuvCrw5E/4SY7 yDwqyLGpkkbirsvsHSATzGoL49yJJmTkjWokBgNU0O7wmyNQCZEPNtFsThQwzA== X-Gm-Gg: ASbGncuJWMAy+NwtVoIiLS6PeH+cGUda5mf8dGK1mn0oU0ljiFcpfLiKOYIt0IxMevD WG/gTW15SToljSUiR1wBQhR77oFj26860ViW8sm6zJ78JZFSgx4g/s5e7WoanP8QUmH1ih42Ova fzi4K1YQCgxCtJnoMJBlcJDSv+PJb5yF1CB+Fw5XXT/dHRK3XNVS47lgFkIICOGQz7wPTrZGLC4 VyBUxfFQRLmmzfNDjyWabD4g5X0y9pGGSXPJG33/4r8KsRfzVcRBRnI9rKF5OViLTe4NAkIQgwK M2CX22smwB0N4yGD6ZC0qJ03ZMGGDD+ICrS1bL52UIu6Cn1jb2kFrRk= X-Google-Smtp-Source: AGHT+IE6OI7ZYUB+RyRqNOSHa6dcIorzBveqcHsTle4MLuY7jT5AFxe0+OyjKOH7Fp1j3gwplFjLUQ== X-Received: by 2002:a17:903:1cb:b0:215:6c5f:d142 with SMTP id d9443c01a7336-227efb875admr16785655ad.20.1742938270019; Tue, 25 Mar 2025 14:31:10 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-227811da369sm95585925ad.170.2025.03.25.14.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Mar 2025 14:31:09 -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-next 9/9] netdev: don't hold rtnl_lock over nl queue info get when possible Date: Tue, 25 Mar 2025 14:30:56 -0700 Message-ID: <20250325213056.332902-10-sdf@fomichev.me> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250325213056.332902-1-sdf@fomichev.me> References: <20250325213056.332902-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; }