From patchwork Tue Apr 1 16:34:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14035148 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 D6E1E207A23 for ; Tue, 1 Apr 2025 16:34:56 +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=1743525299; cv=none; b=C6akVpRKjSUVyic3TvG98NkHEcUUXoncSDSTvNwz+UizvRDuHzBjTrTxGmpxEtnwjYorhnhSerynzsOuWgY491FLrSKvuGGDlhrlXiNuouGh/BHgkVYmUahuF+iNlbJYrWQnS1LEGTE1ExPBWTeUSWG5JBIpsnhEBkmRpH/n5g8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743525299; c=relaxed/simple; bh=lVli2XcpkFVkj2pcszPjwXfUE4AKc4A82mHJobVKVs0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JxItCEo5fsV1mJTA5QSKMHFboyhOvwU2S6rZgZOd6mru60ubBxQ1Tz8z79htqmAr9cz52UtQsnQ5Winoi2K7wjy45G+J2PJq/EMBqQLf8zlEdOXlzMHzdQDFj8hZvIvXtqan1fTVcA89ccCG3h+5ZKTfeoTAFVD8SheG1Hcf4JQ= 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-2260c915749so81436395ad.3 for ; Tue, 01 Apr 2025 09:34:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743525296; x=1744130096; 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=8GUgZG5VvzNgh+1mfB+3OA3fyiAKrjf6aeYdbDZGI6c=; b=IbjsZLGrnK1F3+kt7y8iNTw/zPTN5ew6zx4FmUuzLWvelZvvlh1uSNNHrUezg7DWjw f8ApwnPQznNIhVLlv1gjNirkkuW1y/4e2xOfXZwEopb8dg0qU8fBg93Wft4aaSdIQS07 C7cUdVJc09iWVeP35d9z9FtvQtUkCLSRDjkcVjYfmyi/9PLUnuaWutl9dCtOV1yVEblN nI3mTNp7lROF1cIwr/qiPrPE7Nj1RsZSuCT+LlxkxDJdstJq6pSHkjUhfjRWkApkmbcS v7Fc34XsoARVsXEll7OfFA3oorWrtusJ90Hsx6TqXfxUQ5zYRJyFr3dqp/znEaGrPYkI 3SOg== X-Gm-Message-State: AOJu0YwQ8CpOQn/nZzxYKRSLaYuE5zXSJZ0x0XftpW2hamqVXO7Y3Q1J BHoYpoMKc9PUdwRWexYOFOpMqwtfUHuW+cJplSdf7DX2LcMtAly/p3PC+BuEtQ== X-Gm-Gg: ASbGncv8uRS33B3xhzT10ifisjSNc4PuKKPckZK9KMbG+AvTdmLil6aumsfuScb2Okx 4Rw2AZ8djLlIP+cMoHG+pN8yH30Re5Nvm/RlKiOUzKdmRGlQzF6t8MAfpkYW1BAsVLmr5xFZtca vO6bSIWr1392wcd+T1p+XyKkXnCb1IeE+GDXGr3jsBO2n+mVS7t6M6Oz1jkyd5LKHm3dmHJPe1N 2osaJyAyWtxNWwIQnef18Ol7qWyECUym9bO9xzqCePmyMDkkW3XUEAVkXmhh8WU2Jp4QnkWRs4d chs82ERv4fRSsBMlGXnemohvkP8ZMQdDPx8sLIqgJkws X-Google-Smtp-Source: AGHT+IFpxZZiMKAj7OlrMAo62Gmsef1aRBG8SEzKtVE7wjd+zfG1dVDB0uepw3vsimVEWR1d5BYuiQ== X-Received: by 2002:a17:902:d50a:b0:220:e392:c73 with SMTP id d9443c01a7336-2292f95f2d2mr238151375ad.22.1743525295586; Tue, 01 Apr 2025 09:34:55 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-73970deefe4sm9097734b3a.30.2025.04.01.09.34.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Apr 2025 09:34:55 -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 v5 01/11] net: switch to netif_disable_lro in inetdev_init Date: Tue, 1 Apr 2025 09:34:42 -0700 Message-ID: <20250401163452.622454-2-sdf@fomichev.me> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250401163452.622454-1-sdf@fomichev.me> References: <20250401163452.622454-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. Reviewed-by: Jakub Kicinski Reported-by: Cosmin Ratiu Fixes: ad7c7b2172c3 ("net: hold netdev instance lock during sysfs operations") Signed-off-by: Stanislav Fomichev --- net/ipv4/devinet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 Apr 1 16:34:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14035149 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 46F9A20D4F7 for ; Tue, 1 Apr 2025 16:34:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743525299; cv=none; b=ekBkj8JUzWMxRSq4p5SbFckjfvSXDHS4Bs9akZMOGLLGzx05xZfoQnxJzlxfZ42BTDqUHvDQ5LsXFr8IInnpH7x4V4GZwPcrzhkCguEgqn/ZrEQaVNJNnSueG2neqt7Pv7nyFxLkDHctAEvKFl3z1EvToqtx9lj8i8DZCLhhyDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743525299; c=relaxed/simple; bh=NCJWGxBSpQ5TCQWjoI6vVXAt0Odv6zejZA4HfO9GObw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B5z8DRo6Ar8cCludg4O/oJijpMHCAmzZHTz0wxjn+U/PNiH6cRlJod76FL+tkezCcPd2SniIX562qBdW9evVTpIQcNziR3BuMRlNB5fDqewgdedblS/GZ+G/iS3z5/ZEGZZ246e4nZ7RwmzLULJTHMuYeIydYocFswB/hikGmko= 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.49 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-f49.google.com with SMTP id 98e67ed59e1d1-2ff615a114bso21983a91.0 for ; Tue, 01 Apr 2025 09:34:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743525297; x=1744130097; 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=M6vlPCUZHkjrtvyT/1+ymW/z2m3BuDKhtRHAQhec/o8=; b=PWHJRFnV3UGaILdXGXGrtyMmUF13ltk/ACvXrxdS2MyP0krwxdJxVmyR0t3rmIBHVT Er9CBg9uKcWCmoTbOGJPTtjPDMvoNiYY9hpBVOnEwvKV5vB2qbCZ8efvid54iOA8VfRK U5mVUQiYexXQSz6SjdcHJwbMj8FE6h14K2QUY1OVQDhL0v5/Pu07wK6c10aB/e9Htr2q syl0zDkNEifY0g0ukbEkiKuX/fXArjBZg3j/j43YwxqGTJueK1izCOTiBwpgqxR+zxd3 K4pzEwqPfQydcfKsF3mAFE1fK3pSrtffEgQTy+r2eX1V2u4Jzv2C/1UJ2dPTaGjQhTn7 jDIA== X-Gm-Message-State: AOJu0YwWsNd1nE87DYnBDryCFzARuEjY/q1T0JgbJO70O+UEF8/rWWBY dK+Mu1FIm7YAfnGR2P/p7o4VmZTa8NYihD4ArqZhhAPPBxAXUHdnUQrvC41SoQ== X-Gm-Gg: ASbGncucqwF3TM+zyCnqUAB08AOTzrUPj/GKQfVAdZcJJDYE9J7jVKkgQe6pp8j0NUC o13ZNTGwZSEAp5EPFHpPHmFdwAxtLCXfDjnbT6EteSPBw/Qq+n28l77cZIOaGg46DVqCtDxZyJ9 2pJKvOoSwsj43gXqBA+ma57pyJnkWwHFRqHQ15VI7+4v8IJCHGe/Vvc8/fq3Qz5/ZmOC1/g5tUQ zcRlenZvv8v8DI/Eli/JwJL0/cGjz9ijragVZ51vFiDXkSpjbUgej8+GWeiQ9/XcDRT3wR32cJO 6o0J5ZI5nZrBmYNt77u4rTdk8I7yh907Lkr76SWIWePL X-Google-Smtp-Source: AGHT+IGO9IxGvKS6j0PpKgBt6rYY7VeUbvWWePJHFog8JiXlaYqW4MwEZmxkSX0P8UqqMt54MgAsOw== X-Received: by 2002:a17:90b:5750:b0:2fb:fe21:4841 with SMTP id 98e67ed59e1d1-3056b70940fmr1015529a91.8.1743525297001; Tue, 01 Apr 2025 09:34:57 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-30516fed6f4sm9500406a91.32.2025.04.01.09.34.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Apr 2025 09:34:56 -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 v5 02/11] net: hold instance lock during NETDEV_REGISTER/UP Date: Tue, 1 Apr 2025 09:34:43 -0700 Message-ID: <20250401163452.622454-3-sdf@fomichev.me> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250401163452.622454-1-sdf@fomichev.me> References: <20250401163452.622454-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). Also solve the inconsistency with UNREGISTER where it was locked only during move netns path. 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 Reviewed-by: Jakub Kicinski Reported-by: Cosmin Ratiu Fixes: ad7c7b2172c3 ("net: hold netdev instance lock during sysfs operations") Signed-off-by: Stanislav Fomichev --- include/linux/netdevice.h | 2 +- net/core/dev.c | 12 +++++++++--- net/core/dev_api.c | 8 +------- net/core/rtnetlink.c | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index fa79145518d1..cf3b6445817b 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -4192,7 +4192,7 @@ int dev_change_flags(struct net_device *dev, unsigned int flags, int netif_set_alias(struct net_device *dev, const char *alias, size_t len); int dev_set_alias(struct net_device *, const char *, size_t); int dev_get_alias(const struct net_device *, char *, size_t); -int netif_change_net_namespace(struct net_device *dev, struct net *net, +int __dev_change_net_namespace(struct net_device *dev, struct net *net, const char *pat, int new_ifindex, struct netlink_ext_ack *extack); int dev_change_net_namespace(struct net_device *dev, struct net *net, diff --git a/net/core/dev.c b/net/core/dev.c index be17e0660144..0ebe8d6597f2 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1858,7 +1858,9 @@ static int call_netdevice_register_net_notifiers(struct notifier_block *nb, int err; for_each_netdev(net, dev) { + netdev_lock_ops(dev); err = call_netdevice_register_notifiers(nb, dev); + netdev_unlock_ops(dev); if (err) goto rollback; } @@ -11045,7 +11047,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 */ @@ -12057,7 +12061,7 @@ void unregister_netdev(struct net_device *dev) } EXPORT_SYMBOL(unregister_netdev); -int netif_change_net_namespace(struct net_device *dev, struct net *net, +int __dev_change_net_namespace(struct net_device *dev, struct net *net, const char *pat, int new_ifindex, struct netlink_ext_ack *extack) { @@ -12142,11 +12146,12 @@ int netif_change_net_namespace(struct net_device *dev, struct net *net, * And now a mini version of register_netdevice unregister_netdevice. */ + netdev_lock_ops(dev); /* If device is running close it first. */ netif_close(dev); - /* And unlink it from device chain */ unlist_netdevice(dev); + netdev_unlock_ops(dev); synchronize_net(); @@ -12208,11 +12213,12 @@ int netif_change_net_namespace(struct net_device *dev, struct net *net, err = netdev_change_owner(dev, net_old, net); WARN_ON(err); + netdev_lock_ops(dev); /* Add the device back in the hashes */ list_netdevice(dev); - /* Notify protocols, that a new device appeared. */ call_netdevice_notifiers(NETDEV_REGISTER, dev); + netdev_unlock_ops(dev); /* * Prevent userspace races by waiting until the network diff --git a/net/core/dev_api.c b/net/core/dev_api.c index 8dbc60612100..90bafb0b1b8c 100644 --- a/net/core/dev_api.c +++ b/net/core/dev_api.c @@ -117,13 +117,7 @@ EXPORT_SYMBOL(dev_set_mac_address_user); int dev_change_net_namespace(struct net_device *dev, struct net *net, const char *pat) { - int ret; - - netdev_lock_ops(dev); - ret = netif_change_net_namespace(dev, net, pat, 0, NULL); - netdev_unlock_ops(dev); - - return ret; + return __dev_change_net_namespace(dev, net, pat, 0, NULL); } EXPORT_SYMBOL_GPL(dev_change_net_namespace); diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 334db17be37d..c23852835050 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -3025,8 +3025,6 @@ static int do_setlink(const struct sk_buff *skb, struct net_device *dev, char ifname[IFNAMSIZ]; int err; - netdev_lock_ops(dev); - err = validate_linkmsg(dev, tb, extack); if (err < 0) goto errout; @@ -3042,14 +3040,16 @@ static int do_setlink(const struct sk_buff *skb, struct net_device *dev, new_ifindex = nla_get_s32_default(tb[IFLA_NEW_IFINDEX], 0); - err = netif_change_net_namespace(dev, tgt_net, pat, + err = __dev_change_net_namespace(dev, tgt_net, pat, new_ifindex, extack); if (err) - goto errout; + return err; status |= DO_SETLINK_MODIFIED; } + netdev_lock_ops(dev); + if (tb[IFLA_MAP]) { struct rtnl_link_ifmap *u_map; struct ifmap k_map; From patchwork Tue Apr 1 16:34:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14035150 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 C06BD20D51D for ; Tue, 1 Apr 2025 16:34:59 +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=1743525301; cv=none; b=mRJxB4SGOJdgRf4IZKXvqNPBhmioRWfg2z53bkpdusXl4aqrzW6vT0VJm9LQb4cyDjpeGi0L2MLFOgQJQwqyR7XbW7SbXEjLmnvI4BqraRASeyKDXnjGgKptCutUGCrA75oXif7Lct9QWp8e30AzR0ii8NCvdCZ3SOPxi2mPf+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743525301; c=relaxed/simple; bh=LITO/GEar54V17mAAupd9TzAHAWqOewaekZQUdLCRy0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ER9nBAXfIFGTY1W2nDVPNTXHkAOnLfb/FtrxXh7EhBCmHyQZW4W5YkfylsxaMtg53yL2y8Tf5abSk3d+uIGqgjqcvLovi14IBOyhfkxRVkOq3JtI145YFel/Js9witx4whabJROQYORT8+2MuWOTx0ApEjVNJm7xg2hZ3Xtt7hY= 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-22548a28d0cso155918975ad.3 for ; Tue, 01 Apr 2025 09:34:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743525298; x=1744130098; 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=RlQr57FXa2KFohs3JTa1N4rbU/iSP3wM0AqQfwH4+j0=; b=tijZ7jcQnTRAMpTjUy5RttzbpnZBA1MuQsIKp7FVLICXJhkZ8bUd1ER3VKaW8PxpsM YrH7ZeIAF/vtCDBlOk6VIw/gaPIV+YXyhJ1EBgV48hF2OXzOYIikCt9DtEvy7lil4Wrr T9WfW7evtOW9xPsySJBzWbyAoJWfHMab+mla6QNCmYOlkroqMad1NvGg7kJhs5iVkPBs 0kn0+sLduaBq+RG5egWGHMNWmctjvrmwYKxrX9o8v1YMugC2vUcvzZcARw/N82LuWt8q /izbsOfrwRyIdRQhuUKYNxymHBqUCanxRU9FNrYN1BIsnkR3aesfNkOqOqkG786S3cmS o0Nw== X-Gm-Message-State: AOJu0YzoCu6wuNngNdevVI7zhmQbxeUFNZiv475KWUUfn6nKKptjfgbj W+S3K9UEgZopBEdxUgMmhryt7fv3ZDuP6ll/pTcrw85Zas43EOTXANPvi+N5QQ== X-Gm-Gg: ASbGncv+2PWQx7LXzmol2KkiJBiYcE0J46VdSYWsay736p1TtEcb//5w6dt2YSlIWT2 UWIKpROsKBuX8Wk4kEDUpaHWw5unC6UBPWM87Jwy+0hoC5vB0LkawqtlhQIhDdg7vSp+Dd41OwU J5XXIkp69kobmyN9Z3TpGcZDZr9/oXTXkQTzErsXJ8C9LGNIEgJLUZ1dnUqUXUtysfboInDkkpj xVfMEvYY6aQtc3ZNeZafweqVo8N8MMgR8K9l4ts/rU3IlCUMsLy+jQNvRsTlTM8rxEZkpb3ONKP nJqXnrf9jnG7Eht8s848pa1fX0UwuTxelQUZcLcwW6Gg X-Google-Smtp-Source: AGHT+IH7uWGjeVBZWAqEfP+/U/Nt/AKQ5WNL/GEfAPzCZ2nkM126f8yRD3xJO4Af8mE46JXTlKwmdA== X-Received: by 2002:a05:6a00:2da1:b0:736:4b85:ee05 with SMTP id d2e1a72fcca58-739803c5d57mr20633411b3a.11.1743525298458; Tue, 01 Apr 2025 09:34:58 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-7398cd1cc3dsm5866122b3a.80.2025.04.01.09.34.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Apr 2025 09:34: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 v5 03/11] net: use netif_disable_lro in ipv6_add_dev Date: Tue, 1 Apr 2025 09:34:44 -0700 Message-ID: <20250401163452.622454-4-sdf@fomichev.me> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250401163452.622454-1-sdf@fomichev.me> References: <20250401163452.622454-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/net/ip.h | 16 ++++++++-------- net/core/dev.c | 1 + net/ipv6/addrconf.c | 15 +++++++++++++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/net/ip.h b/include/net/ip.h index 8a48ade24620..47ed6d23853d 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -667,14 +667,6 @@ static inline void ip_ipgre_mc_map(__be32 naddr, const unsigned char *broadcast, memcpy(buf, &naddr, sizeof(naddr)); } -#if IS_MODULE(CONFIG_IPV6) -#define EXPORT_IPV6_MOD(X) EXPORT_SYMBOL(X) -#define EXPORT_IPV6_MOD_GPL(X) EXPORT_SYMBOL_GPL(X) -#else -#define EXPORT_IPV6_MOD(X) -#define EXPORT_IPV6_MOD_GPL(X) -#endif - #if IS_ENABLED(CONFIG_IPV6) #include #endif @@ -694,6 +686,14 @@ static __inline__ void inet_reset_saddr(struct sock *sk) #endif +#if IS_MODULE(CONFIG_IPV6) +#define EXPORT_IPV6_MOD(X) EXPORT_SYMBOL(X) +#define EXPORT_IPV6_MOD_GPL(X) EXPORT_SYMBOL_GPL(X) +#else +#define EXPORT_IPV6_MOD(X) +#define EXPORT_IPV6_MOD_GPL(X) +#endif + static inline unsigned int ipv4_addr_hash(__be32 ip) { return (__force unsigned int) ip; diff --git a/net/core/dev.c b/net/core/dev.c index 0ebe8d6597f2..e59eb173900d 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_IPV6_MOD(netif_disable_lro); /** * dev_disable_gro_hw - disable HW Generic Receive Offload on a device diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index ac8cc1076536..35477d494573 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); @@ -3152,10 +3154,12 @@ int addrconf_add_ifaddr(struct net *net, void __user *arg) rtnl_net_lock(net); dev = __dev_get_by_index(net, ireq.ifr6_ifindex); + netdev_lock_ops(dev); if (dev) err = inet6_addr_add(net, dev, &cfg, 0, 0, NULL); else err = -ENODEV; + netdev_unlock_ops(dev); rtnl_net_unlock(net); return err; } @@ -5026,9 +5030,10 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, if (!dev) { NL_SET_ERR_MSG_MOD(extack, "Unable to find the interface"); err = -ENODEV; - goto unlock; + goto unlock_rtnl; } + netdev_lock_ops(dev); idev = ipv6_find_idev(dev); if (IS_ERR(idev)) { err = PTR_ERR(idev); @@ -5065,6 +5070,8 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, in6_ifa_put(ifa); unlock: + netdev_unlock_ops(dev); +unlock_rtnl: rtnl_net_unlock(net); return err; @@ -6503,7 +6510,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 +6524,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 Apr 1 16:34:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14035151 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 0B64820D4F7 for ; Tue, 1 Apr 2025 16:35:00 +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=1743525302; cv=none; b=LHG7AZNugxpkchbBwJxYfohCW3hJdd8DQhll/+KCDmTr5v8eRDrXaLlJ7U1QwwJGABMykZTXU8PPHX9io4ICRZ87GzGGTvRkz6kiYtda5E9YOwfQ11WJnBW2WgtLr1ycBnjwE12ejB6tfrmtkNI+ddspbibewMKI0fafgJQwkc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743525302; c=relaxed/simple; bh=V52ogIerz3pWrsOVtz2HNfeJC3T1ZLd6RIDKy5JCA10=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rCWvP0TIS7ihjvHfLAhFhPb8H/oVZgBuvQAbiyHEVVzQjGCeQb5Vnx4rd63bYP9ZOwuzxRj1hQXxpNzpCr7uM1+yWgbjPaSBU4sIA9NpVXR8iGwdZkOrwRBPuCfE5vlI1ZzgavCal5UrBm+Y0TQ2qToYdi67l/HQBqe97GkUybQ= 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-22435603572so108880745ad.1 for ; Tue, 01 Apr 2025 09:35:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743525300; x=1744130100; 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=QqW4GjRTu/v0EzDHaXQV7WFvqxG263JPBR8ADF6KpwE=; b=O8FRzwqw9F6IMs6qN7nLQ2J+p5+ELs/DdNBXPpePbhC2NCVqOufULIzd+Irj1APbIr nytZCXaiLh/SrV9gr82oRskreoLmyDlKIMQDQVLHrQcyVrA3l2W20CPSXH2u3Y553bZz V2Wu5r1iLjw0jKjWbiZ2N3zNiVXXa6EUSEBx+OhuQr3DTZi2QTxtfZ+eJ+I6ess4CPbw 44WXE2lXkBGeAd6Xx41f8OpyIjP0OzXdESOEB2NWlzFHP7R9Xyg5IM24PM2zBus7ekqF rfPxhTvLZGYQR8nsl/1bzvsSNKZ1fOpXqTmPasSPPVw8ATlnkkEHONc6VXE1H+6VOh5l bcsQ== X-Gm-Message-State: AOJu0Yww+JYH3Foq0b7Zbximxv9+YESUyMrwR3jS2KdQJ0C9Bvc4/RmI EROs6t+Vh5F5hyC2mgQL634cieiqNDvTqNCmhry7hKnNUya3/Uz+Az9YRueXOw== X-Gm-Gg: ASbGnctJIB3A5NryV59zZT4HwuP3ru1j2it65qqbnBnu8/0h/WylEB4jN3PAgo9LCmZ A+pqCDGWi0VV7DLia519bRvSe8AsHzl4GJczBRqK3Ka+VMV7HZMfSBvMNnpmE2DjZaD1Hs4FIL7 OiTDvWRFs95nUieZVulXijPddAQline7hq26hvqm/+dWcZxtADHDG19OOmV2DVM1yQ/Ea/Afxxs vtidtXG2WDJ5TFGczBxMLRB1y5V484ZaA/kv9CGrLvGguIZ5Ms2iUOPzP53OfjHxE955Q0uztr1 z6Vm9ShM890QsiLLifgfRA5C4rJ4W/2+uiYjyszHle3H X-Google-Smtp-Source: AGHT+IF4T6jmB2z2n9PHadBfxpjeLuK3A1AU8GVUIt9fw/PANgQSkHTea+AbaGmRTKn59laZq5DbGA== X-Received: by 2002:a17:902:cece:b0:220:cb1a:da5 with SMTP id d9443c01a7336-2292f9f2ee6mr230756585ad.40.1743525299840; Tue, 01 Apr 2025 09:34:59 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-2291f1cde7bsm91060475ad.149.2025.04.01.09.34.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Apr 2025 09:34:59 -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 v5 04/11] net: rename rtnl_net_debug to lock_debug Date: Tue, 1 Apr 2025 09:34:45 -0700 Message-ID: <20250401163452.622454-5-sdf@fomichev.me> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250401163452.622454-1-sdf@fomichev.me> References: <20250401163452.622454-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 And make it selected by CONFIG_DEBUG_NET. Don't rename any of the structs/functions. Next patch will use rtnl_net_debug_event in netdevsim. Reviewed-by: Jakub Kicinski Signed-off-by: Stanislav Fomichev --- net/core/Makefile | 2 +- net/core/{rtnl_net_debug.c => lock_debug.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename net/core/{rtnl_net_debug.c => lock_debug.c} (100%) diff --git a/net/core/Makefile b/net/core/Makefile index a10c3bd96798..b2a76ce33932 100644 --- a/net/core/Makefile +++ b/net/core/Makefile @@ -45,5 +45,5 @@ obj-$(CONFIG_BPF_SYSCALL) += bpf_sk_storage.o obj-$(CONFIG_OF) += of_net.o obj-$(CONFIG_NET_TEST) += net_test.o obj-$(CONFIG_NET_DEVMEM) += devmem.o -obj-$(CONFIG_DEBUG_NET_SMALL_RTNL) += rtnl_net_debug.o +obj-$(CONFIG_DEBUG_NET) += lock_debug.o obj-$(CONFIG_FAIL_SKB_REALLOC) += skb_fault_injection.o diff --git a/net/core/rtnl_net_debug.c b/net/core/lock_debug.c similarity index 100% rename from net/core/rtnl_net_debug.c rename to net/core/lock_debug.c From patchwork Tue Apr 1 16:34:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14035152 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 48D5720E313 for ; Tue, 1 Apr 2025 16:35:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743525304; cv=none; b=gPNVElpuSEahclovjO4gQSYyjNLdYxYZnHe7jinWWDF/4zuUwAVPFoS0uY5gc3ls5YLjPz+TAK3K52wkZGpw+IxxONbWmUhc0ufCY2gAZL1VeLLC8wlVI7+rW2OMu8R7w9Wlq1DixIqtxKVq6/ZrVmC4lY86GvW8EzINAvjhd5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743525304; c=relaxed/simple; bh=37DPlTB1m+vNulI3hmYc3tDyAAJiHuA+wLkwQsf3Un8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LED/RJtHLW9eyn8MLjP6BJQhOyS9zYIkzywX5en0UNANpRJK3pCNKFkUawAPx6rq5rQyh69tFKqfUxnyohokbw0xR6R00HTM0sirFtFzxzr0/6I0oy1aV66IKjGc0/95GklT4JbuG9gfZXV2UHQqnfAyowUkmSrT8UI7ocU31K0= 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.175 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-f175.google.com with SMTP id d9443c01a7336-2260c91576aso92327295ad.3 for ; Tue, 01 Apr 2025 09:35:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743525301; x=1744130101; 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=QtrkWp/IUEbfiPxi5ET2roEwQfuYzRFO4zkGAj8DquA=; b=SZeC8YhOM44NAPdBJ4zyiLeoOsMwIunYBxyHnLiMN8dSAgmR2cgMSw1UBcLUCMnQCl oWkNDzYvznEuZUkERKCRaUfSrT6ejOVKWO4Jk9Wjn8Vk4Yu4407qZUQpJ7KfAZcHsE0C /Hb8PXzmrszEqrUaMEMm4x4vXBWDVls0qhxJ1oGwx4SymY8ucXALJWCBFZWVS+xJw5/s sTbjZuIvrS8/MGFVrz1lrJI/+v1ZNHJh3lFnJqM/CvGNOiFLQur2pOsy+3P/f6xmLpB1 uLCUVvSvPbcNU4gkV9obqR7lgJ9Bk6kPDD8VqHD8hGNsItJ6NZoLDTQxkF7miggE9zwd xrtw== X-Gm-Message-State: AOJu0YzHWg4BuM+1ytOltxbOuQZS47CfCwSxlYPv/FZc9aZTq+gPYFtZ 6rH4MzSQLGR0EGO3Wt5dhYtaoVhmpyyJ+CLssGsGFnYtLzD5TOn4ANs2+8H3nw== X-Gm-Gg: ASbGncvQn6UtJ100tku9avgLcGSkhRhfUdGWst7BC8dOpBOU81rB+blYlj+Q9BCxpy9 MbwsBH9Es/RuhczaD4jQqgdjhwn+d2/XDAsgiL68WQFqJMYOslT/cDJfPhhCAczJvz+UAZeGh+l 2sn23iL1wwicJFvi4TzFaRvARWD7j2L/a5AGpM8bFYYOdmv6P63PfkGv7qRIO7ka4APLjGvLTl5 mHVXw4tOVwWxay6StLToh7bvT+oMf9+WRwjrp5Qv3wqpALgBBu76DtOuQo4d0A7o4CxnLNKKmcE QBxi5KisIKY1lXDv2P32siohLZNWg/wro9zVydoxia9nTR05o9vG4jI= X-Google-Smtp-Source: AGHT+IE7QtvIM/kCpjnL0I+6bU7HziVdI2MSwS7kXtHjLp24ijHW5tP/29JZGijVvCfUuKSxM1osSQ== X-Received: by 2002:a17:902:da83:b0:227:e7c7:d451 with SMTP id d9443c01a7336-2292f974b3emr226446835ad.29.1743525301231; Tue, 01 Apr 2025 09:35:01 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-2291eee03f5sm91135375ad.99.2025.04.01.09.35.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Apr 2025 09:35:00 -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 v5 05/11] netdevsim: add dummy device notifiers Date: Tue, 1 Apr 2025 09:34:46 -0700 Message-ID: <20250401163452.622454-6-sdf@fomichev.me> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250401163452.622454-1-sdf@fomichev.me> References: <20250401163452.622454-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 (via register_netdevice_notifier_dev_net). Share notifier event handler that enforces the assumptions with lock_debug.c (rename and export rtnl_net_debug_event as netdev_debug_event). Add ops lock asserts to netdev_debug_event. Signed-off-by: Stanislav Fomichev --- drivers/net/netdevsim/netdev.c | 13 +++++++++++++ drivers/net/netdevsim/netdevsim.h | 3 +++ include/net/netdev_lock.h | 3 +++ net/core/lock_debug.c | 14 +++++++++----- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index b67af4651185..ddda0c1e7a6d 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -939,6 +939,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) @@ -960,6 +961,14 @@ static int nsim_init_netdevsim(struct netdevsim *ns) if (err) goto err_ipsec_teardown; rtnl_unlock(); + + if (IS_ENABLED(CONFIG_DEBUG_NET)) { + ns->nb.notifier_call = netdev_debug_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 +1052,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) 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 * diff --git a/include/net/netdev_lock.h b/include/net/netdev_lock.h index 1c0c9a94cc22..c316b551df8d 100644 --- a/include/net/netdev_lock.h +++ b/include/net/netdev_lock.h @@ -98,4 +98,7 @@ static inline int netdev_lock_cmp_fn(const struct lockdep_map *a, &qdisc_xmit_lock_key); \ } +int netdev_debug_event(struct notifier_block *nb, unsigned long event, + void *ptr); + #endif diff --git a/net/core/lock_debug.c b/net/core/lock_debug.c index 7ecd28cc1c22..72e522a68775 100644 --- a/net/core/lock_debug.c +++ b/net/core/lock_debug.c @@ -6,10 +6,11 @@ #include #include #include +#include #include -static int rtnl_net_debug_event(struct notifier_block *nb, - unsigned long event, void *ptr) +int netdev_debug_event(struct notifier_block *nb, unsigned long event, + void *ptr) { struct net_device *dev = netdev_notifier_info_to_dev(ptr); struct net *net = dev_net(dev); @@ -17,11 +18,13 @@ static int rtnl_net_debug_event(struct notifier_block *nb, /* Keep enum and don't add default to trigger -Werror=switch */ switch (cmd) { + case NETDEV_REGISTER: case NETDEV_UP: + netdev_ops_assert_locked(dev); + fallthrough; case NETDEV_DOWN: case NETDEV_REBOOT: case NETDEV_CHANGE: - case NETDEV_REGISTER: case NETDEV_UNREGISTER: case NETDEV_CHANGEMTU: case NETDEV_CHANGEADDR: @@ -66,6 +69,7 @@ static int rtnl_net_debug_event(struct notifier_block *nb, return NOTIFY_DONE; } +EXPORT_SYMBOL_NS_GPL(netdev_debug_event, "NETDEV_INTERNAL"); static int rtnl_net_debug_net_id; @@ -74,7 +78,7 @@ static int __net_init rtnl_net_debug_net_init(struct net *net) struct notifier_block *nb; nb = net_generic(net, rtnl_net_debug_net_id); - nb->notifier_call = rtnl_net_debug_event; + nb->notifier_call = netdev_debug_event; return register_netdevice_notifier_net(net, nb); } @@ -95,7 +99,7 @@ static struct pernet_operations rtnl_net_debug_net_ops __net_initdata = { }; static struct notifier_block rtnl_net_debug_block = { - .notifier_call = rtnl_net_debug_event, + .notifier_call = netdev_debug_event, }; static int __init rtnl_net_debug_init(void) From patchwork Tue Apr 1 16:34:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 14035153 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 AB0F520D4F7 for ; Tue, 1 Apr 2025 16:35:03 +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=1743525305; cv=none; b=r3dYB0fOYqMFH22DBjqzp5z0b4gq6H8QGOlzNzQpFDT6W1S9jW0vK5ctwyXBLc6aLiuKPoftBCfwOpfTLFirPCQ9pBs5EnOelCRd+qRDRuuGUKaf/Ysp8nqKHZBIu84ad/FPdhfvxhmsdFKFuSw6BZMWFcYBHwATOepIGShNrnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743525305; c=relaxed/simple; bh=vZn7yO2iCnAMEvEz7u+7h64+lzs6SGdVKJy6rnV3No4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q2FlwWdkYn33xT1cwzBJPCP/+hybAb5H5JAu7C1m0XA7lMJtKs1gQOjFVehKRXKG2kNdqjO5O/P4MsJu/W95qp2x+uxfvbPwX+iOU0HCFRe3HDyoWeIobyxYlbDCoYgZ3h5QtoJ4oJC9c3gR1bE7ae+wloLPD0NW6qxRsELG/3Q= 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-2260c91576aso92327915ad.3 for ; Tue, 01 Apr 2025 09:35:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743525303; x=1744130103; 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=mkASRlWWPss/UGLbr7z0MSMnXM0Kc2QVcSHO644ngfQ=; b=LfDnErgMQPo++M/7cTSu4hQrPSxA4fwsnC+qQvQJg9pVqBalR6ZsdtgM82NNKRSwRY tgRUIY3Xci0/irC6RO3QzALEcNWnmMcq4Qj9BHf+3WI9R/i/qWqB8L4088hsgB6yW22J Amwvm7KQ84fKZCYscPzHmAkl5icrXyHUGqvUJJIvkGVDJBavw4qwAzKS0vNZKFsZ3lbL qPJmrtzIe6fUxu1YJvZLsbAcCIJnqpuysHOsiFtllzGxMJUKNEqTVNT7fdsnRPwZquiq YeuBCgiL9XQQlL2Cyodx/6YgLv+BquQJoNEhf3+gEvy5U5YhrnTjsgfZ4wwe4+FkeFuB GyMQ== X-Gm-Message-State: AOJu0Yxk8RwzsO0Fm/qgQRGsPbObc+xIIaHtsbhhzZ52Uj8CbIflTVdC j3cZxqBcENH8+o1wC+oaq6h92jGpvst7RP2e1KHL9XqkoD/IU3pSJ1FyamK9Qw== X-Gm-Gg: ASbGncuhSlv7pPOVWtFeF+MzXeDmFx6Ad8OS+NNit085r07J5p+9YdkwFVG+HUHHWHP GX57awZ+OtaC3CknugnlBKb4HkzHeiXK+jie403dfdWPrHipjWJXEVkDjr5zNPVoF64f+Pn6z+W m0u5pSiQ1p2Y1XJaelSORYZ0zoBtN2lU18BxHqne2SH8L4POJ3obrisgFBARnh4y611lv7aABT8 BeZzYe+aBx9xaaSOvimmBfuU97HcFUAeiR/XpwA5JP6x2lD5rL/MolylwKUJLvQX9B+kpleujBa 9/XwhxtAmD7G60bGoRgAM7+hkY4o9i03ikFIm+5gp0Bt X-Google-Smtp-Source: AGHT+IH7J7wiRIEToxRj4jgL8qJPqEQjqFLcG+qPId7lOhSKlEHcA255N4J3SPQv+ZIjTMabv+mxnA== X-Received: by 2002:a05:6a00:3288:b0:736:57cb:f2b6 with SMTP id d2e1a72fcca58-739803aa740mr23163487b3a.12.1743525302598; Tue, 01 Apr 2025 09:35:02 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-73970e2aed9sm9130010b3a.72.2025.04.01.09.35.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Apr 2025 09:35: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 v5 06/11] net: dummy: request ops lock Date: Tue, 1 Apr 2025 09:34:47 -0700 Message-ID: <20250401163452.622454-7-sdf@fomichev.me> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250401163452.622454-1-sdf@fomichev.me> References: <20250401163452.622454-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 Apr 1 16:34: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: 14035154 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 144EB20E313 for ; Tue, 1 Apr 2025 16:35:04 +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=1743525306; cv=none; b=b1vIuUMWHJVT6HDgoHaWCwMxo/Ri8gdotYPAZ8YwdQfqBO7w9oqeq4O+hxleVRXNh8kH1ZJCFd8hoCSeHxOuBTD9S+fAsaO6ZnAUi8SbwWBvJQvS0L1gHU6+RVlH74mJf6jMkjYdqe1WYdgy4IoMblGO4iByxpHdRbnUiscU/vI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743525306; c=relaxed/simple; bh=brNcDKtIpW55d45qQoDg2xLCrtCFSoB36qUcpPmbkBc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Yzr710LcjuPsIqR0ClG1p52IzWGHxfWO5iK/Dd34MUj+wYX4MxfxOpSPnizlqlOB0YQW5Jpdvg1BPgmuGM9M6er7uYxQZlOz9Hd4NK8lRij8hck1FoETgtLXrazr1TpJvYJQeQ0dW5KY0NkNz9YAVsHj+QCbooXZnUD4tnI5Hvc= 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-2254e0b4b79so149100405ad.2 for ; Tue, 01 Apr 2025 09:35:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743525304; x=1744130104; 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=hV36hiRVRFzZxgV3bV0iMgv0RNkvHa9U+49mMjCNugs=; b=ROIr1bSkTEXFvI9YOI3WuXa++fd7El7TVxNI0kK8wnJmXAQEJ0K6Hg19+5dmhBe1r7 LA1K8wNYm+oMHJlOSdtbL4Huc/vB+u7/MG+Hu9d6PJepiSwjec3bFO3D0GO3BwUvdV4u S8SlGxL1toe0FPmZpgpF+wIYsqaowUoAeqzdZNbziZNvcm4k7IT/ixFi3dXQiOyM7xcl Po+nGZa9wu3vA573+ELvyuqfWAv9hKpoJHav1d+shvF3Sp1Q9U3TnnV9XLS1XRvWNAgl KNXk64L4rtUGBGxdLvzjtBKd7XC45B10Kwoy3ktbaVeyw8rYNdGr+AcQsMPt1UfoLxHQ u1Lw== X-Gm-Message-State: AOJu0Yw3nCxc87KM9x24EApfC89qv6rw6lU3bD0qS/yl8OHix1dFbA+D cYrcjhPojUGPCq4v+Q+YoitMm0RPGzxi/RmxH+A771HdBVihN6kY/17NW8CN3A== X-Gm-Gg: ASbGncv6mH8GlqkuEbRLDMYN95G6ClubcRxizLMJvlyZBQjrSZBYTqjnKzT3+rmT45M QDCaQkTkIkD0TZYOOl0JweVfsw5xYH2U+ponDbJxKtYX3XUh0gvA6SdRWKGqNYj9/DV4lxP6oVm BrW3prVLS5AT4IKqzMTnDPshi8CwS8igfd019OmwypG/VsM42py/uJpRnKHwy7aln72b58Nlyup oUIZasml4+y6MGW+2ILEZE3PMWikB4GiE9CMbMyxU49/OAAM32hAbzAecjme+g4zo5eoWgtl1xd h8Nyv41rwYjtdjsW/9QRPzplm9kV4L1d7lEKWuFDkHs0 X-Google-Smtp-Source: AGHT+IHaNwjfE4BiooRO5RnZVihY9wkl7m5eA/Z9iDsnLl7cFIPdfIwFpOCtzDMH0cs1yNd2KapSmg== X-Received: by 2002:a05:6a00:180b:b0:736:baa0:2acd with SMTP id d2e1a72fcca58-73980487652mr23308076b3a.20.1743525303969; Tue, 01 Apr 2025 09:35:03 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-73970def69dsm9391964b3a.14.2025.04.01.09.35.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Apr 2025 09:35:03 -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 v5 07/11] docs: net: document netdev notifier expectations Date: Tue, 1 Apr 2025 09:34:48 -0700 Message-ID: <20250401163452.622454-8-sdf@fomichev.me> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250401163452.622454-1-sdf@fomichev.me> References: <20250401163452.622454-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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Documentation/networking/netdevices.rst b/Documentation/networking/netdevices.rst index ebb868f50ac2..6c2d8945f597 100644 --- a/Documentation/networking/netdevices.rst +++ b/Documentation/networking/netdevices.rst @@ -343,6 +343,29 @@ 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. + +For devices with locked ops, currently only the following notifiers are +running under the lock: +* ``NETDEV_REGISTER`` +* ``NETDEV_UP`` + +The following notifiers are running without the lock: +* ``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. Please extend this +documentation whenever you make explicit assumption about lock being held +from a notifier. + NETDEV_INTERNAL symbol namespace ================================ From patchwork Tue Apr 1 16:34: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: 14035155 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 9C70820E70E for ; Tue, 1 Apr 2025 16:35:06 +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=1743525308; cv=none; b=KViqTCVCY+zEozXXy9z/aWgq7foVs/fgSxMpQr4E5+AeHDSV42qLEyoHmvRJSmgTVSWHxZAklVcHMZouUXhHMCT19XdQTG+k6J1NDqs+nBnTGBmohzmI7OPxAh+bLmxaAYvIxI0cd/2ARThE9rc2TAv/uwVmBoANrgIDjqZmBHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743525308; c=relaxed/simple; bh=d7JvG3+7EDCHito5Pw1XyustXPnDzUgGCpwAMdHun1U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uZimsA8kXmDsoJSW9nWrZsmvWtYbyZVy7f+ks4lWQ1bgZDlm9IoEi2V/cMI5cczTGMNQ+1apR/QHqRLQAAYC7UPvUE66ggo684YzRTOX+dFtkI1rZEBoT5USNQHPjtQzYY3lXlnsXILfLpHmVqKRHhn3PIr04tQZXBGfUAYlDIc= 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-223f4c06e9fso107469285ad.1 for ; Tue, 01 Apr 2025 09:35:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743525305; x=1744130105; 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=hiPqGUN65xqmstpHwHf6M/veERZEgyfwG65731/G/BY=; b=M+bKIzDC+YuGtvg3QuEhhu9y9T8h44ArfOPMTDsX8AznsjnNBOjv7qdjgvAklMH3dR Cw5ZA6E4bTjfxA1W6KLo1gu+MiC54peCtiV3pIf15buMNpg0IM0l1OXYCQJOE1lxBasc p8+tklbdKuSEgLgh4b56wH+UV2nAlvZsOrZyEzrugcaRMj06CBElyU/1mCMsNmAUV1eY YpTQEVlqE3LSUXdLEL5gNvzGt2wJGxrg9/8jcuRjKNRSNg1qR6o3GMbWj8emwdrIeghc f9go1R2bVbfEf8eFGhmE08Boa4QBF9m/fWJim0N6SGFFcfXP1zmV41LKeTcG3yVFz16W VYTQ== X-Gm-Message-State: AOJu0Yx0I7mV12oQGEVRxnaddFi1jSWPsWtLREWQigRGC5GmLMAOpVvn wizrO0R4WnOr6tW4cI2Me9KiUNS3B96y2hwH8Kp4CjrsdcJimPb19cBeII753Q== X-Gm-Gg: ASbGncsf9Kn9pp4dflCEaUQzoEDwsA2FHUH9jNR/kC9K7gdPjrThqiZcXyy/37SlqEh WQuWpYcDECwHWTi0apiCLQ0NGMQKyUk6TtryL+bGFCDJdGF26HqJx5Fdz03k+g5IUJ1YR1eku/V fwwIUG8GYbjfUCv8zXycc7cEHlkDLlSiyw7JYTxqww1HplOM4xfA7D08XjcSG0xfd0rUtpex+7k N57asodUc1cg4tqLYc7hGceenyRQP9saD2EVfhlR5o5ROm+HlirgnXw+o/d+ljbSWxfEFRv9Rti R9hJN6mrnp4sD+fkwvnkfNiKMHMmZ01iQE8S6aJ62gUN X-Google-Smtp-Source: AGHT+IFM3+SrbXG6XEfuI1EjqDuyDuQPpR8R+/0lKIAqsZuUi++maDKuKcOXzI1oQUUqod4Td6+Aug== X-Received: by 2002:a17:903:2c8:b0:224:3610:bef4 with SMTP id d9443c01a7336-2296834c024mr8384025ad.25.1743525305490; Tue, 01 Apr 2025 09:35:05 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-2291f1f9240sm90412855ad.236.2025.04.01.09.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Apr 2025 09:35: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 v5 08/11] selftests: net: use netdevsim in netns test Date: Tue, 1 Apr 2025 09:34:49 -0700 Message-ID: <20250401163452.622454-9-sdf@fomichev.me> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250401163452.622454-1-sdf@fomichev.me> References: <20250401163452.622454-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 Netdevsim has extra register_netdevice_notifier_dev_net notifiers, use netdevim instead of dummy device to test them out. Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/net/lib.sh | 25 +++++++++++++++++++++++ tools/testing/selftests/net/netns-name.sh | 13 ++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/net/lib.sh b/tools/testing/selftests/net/lib.sh index 975be4fdbcdb..701905eeff66 100644 --- a/tools/testing/selftests/net/lib.sh +++ b/tools/testing/selftests/net/lib.sh @@ -222,6 +222,31 @@ setup_ns() NS_LIST+=("${ns_list[@]}") } +# Create netdevsim with given id and net namespace. +create_netdevsim() { + local id="$1" + local ns="$2" + + modprobe netdevsim &> /dev/null + udevadm settle + + echo "$id 1" | ip netns exec $ns tee /sys/bus/netdevsim/new_device >/dev/null + local dev=$(ip netns exec $ns ls /sys/bus/netdevsim/devices/netdevsim$id/net) + ip -netns $ns link set dev $dev name nsim$id + ip -netns $ns link set dev nsim$id up + + echo nsim$id +} + +# Remove netdevsim with given id. +cleanup_netdevsim() { + local id="$1" + + if [ -d "/sys/bus/netdevsim/devices/netdevsim$id/net" ]; then + echo "$id" > /sys/bus/netdevsim/del_device + fi +} + tc_rule_stats_get() { local dev=$1; shift diff --git a/tools/testing/selftests/net/netns-name.sh b/tools/testing/selftests/net/netns-name.sh index 0be1905d1f2f..38871bdef67f 100755 --- a/tools/testing/selftests/net/netns-name.sh +++ b/tools/testing/selftests/net/netns-name.sh @@ -7,10 +7,12 @@ set -o pipefail DEV=dummy-dev0 DEV2=dummy-dev1 ALT_NAME=some-alt-name +NSIM_ADDR=2025 RET_CODE=0 cleanup() { + cleanup_netdevsim $NSIM_ADDR cleanup_ns $NS $test_ns } @@ -25,12 +27,15 @@ setup_ns NS test_ns # # Test basic move without a rename +# Use netdevsim because it has extra asserts for notifiers. # -ip -netns $NS link add name $DEV type dummy || fail -ip -netns $NS link set dev $DEV netns $test_ns || + +nsim=$(create_netdevsim $NSIM_ADDR $NS) +ip -netns $NS link set dev $nsim netns $test_ns || fail "Can't perform a netns move" -ip -netns $test_ns link show dev $DEV >> /dev/null || fail "Device not found after move" -ip -netns $test_ns link del $DEV || fail +ip -netns $test_ns link show dev $nsim >> /dev/null || + fail "Device not found after move" +cleanup_netdevsim $NSIM_ADDR # # Test move with a conflict From patchwork Tue Apr 1 16:34: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: 14035156 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 DA52720F063 for ; Tue, 1 Apr 2025 16:35: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=1743525309; cv=none; b=RjXvlswti3Qc5ytdH8mk/xKY5t1L3GSmoFgjoPaQHSblicLXc8HY5e4cGF1TvILO5/suftlbgoSnvrC7qQrPSnGCue5lANW3J1cKNaQu1F/rPx5k/xazrq9o+HKSBbpKNIh0xT03py36tFQ3RjiZDgkgjxeibH2j34Qcw7eNo/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743525309; c=relaxed/simple; bh=tf/CChIRlAkfC+Vo8oKSHhJyTpfdaovsvldGu0jbXEc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XQUynFhUsYRNu9ZgZrZGZAVcpo0ge86Srn3qQpWpCrofE9qXMreDoRfxznBPMSpy5i+wi3lYr1i+nCz8ZqWPomSKyjwJ7zn9AqDqbAjKIMFr+D81L+6iEvmfc/ovelwpA91wPp0Y9K0F8ClWIPtl5rTpKwu5GFS4L24C4MCT7x8= 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-301c4850194so8064791a91.2 for ; Tue, 01 Apr 2025 09:35:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743525307; x=1744130107; 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=6p3CjK1FzhuhSc0mPtP8gefXfwAJuXaqGhkba69pwL0=; b=Cl/wSChZ1Xrlt86ANjRvigxDPM/Tg4LPdOvBNUT0mLBHch37Qb1rKOfk21lfjA5KOs UWiaS+6JNT1hETTmDLC0MsW0kvykbmtauNkPem7avlg5LpvYvGr7+ZXUTmytVvGFhSJH 35TVFom9/HvBVCj33vfiL+rcmQNzk1qzEnNV/6TAeLSTigBJNC6OygaXXiMQo6jsWxDs XxM1PM6osL8HBTyPA9EXH/U5sAstiUj5rUBnKsOVtkG55oFAukRbpw2p8AE77T7ezaVY oBiWcCfxcQfPbE6z/3ZhzvJc3aX6ilMQXz/U8BjSZiayloDgJsCGBC3/XaQlc1gGhscm bbCA== X-Gm-Message-State: AOJu0Yw8l1lyEIh3W6iEKnPJpTweeIUCxO4zECLazTWLWLThbdTjgNHu VlaqT5NWVh3LEYpHi0/BSMfVONGSTZUhQSNY84aP6QWfxQFitXkKuT59T60jMw== X-Gm-Gg: ASbGncsIMXkpBesZaKOuBcG/nZBaO6cjp+JdKtjx8AL70bxZdMumVxm8tWAfwIOojn5 dWjVnb57J0AuLfqAfmoe32YWjCZxqyttg14YI0n+PYx36BzvmppCGbVywr95MvbezSiRxeSmxo0 ZrNHg0R2E5UwMwewWsMgqoln64NgNNU8XQg5ungbfmDDknWjc33ve7uYG9GG09R3fGN9Z12q6jD wjeyECzKgFNgD2dUebUVYOrEPS3f4tllhXCjSw+W5fp213THoQIVA9tReVcSiTRDZVT3qtJ9Qlp 11eiiqAtoLLRuUHFSKsrqXSchgZCtOIM6FnUzz88OM9y X-Google-Smtp-Source: AGHT+IHkb6fll9FtZ8OBF2fS7+hDr23ynKzxNGZCtKyjfTv9c8AzQNFIiT6EKC0qn7NXB/tZTP/Vbw== X-Received: by 2002:a17:90a:c88c:b0:2ee:8e75:4aeb with SMTP id 98e67ed59e1d1-305320af2b4mr24545193a91.17.1743525306885; Tue, 01 Apr 2025 09:35:06 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-305175c99a6sm9543642a91.40.2025.04.01.09.35.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Apr 2025 09:35: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 v5 09/11] net: designate XSK pool pointers in queues as "ops protected" Date: Tue, 1 Apr 2025 09:34:50 -0700 Message-ID: <20250401163452.622454-10-sdf@fomichev.me> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250401163452.622454-1-sdf@fomichev.me> References: <20250401163452.622454-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.c | 2 ++ net/xdp/xsk_buff_pool.c | 7 ++++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index cf3b6445817b..9fb03a292817 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.c b/net/xdp/xsk.c index e5d104ce7b82..98a38d21b9b7 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c @@ -1651,7 +1651,9 @@ static int xsk_notifier(struct notifier_block *this, xsk_unbind_dev(xs); /* Clear device references. */ + netdev_lock_ops(dev); xp_clear_dev(xs->pool); + netdev_unlock_ops(dev); } mutex_unlock(&xs->mutex); } 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 Apr 1 16:34: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: 14035157 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 3936320D51F for ; Tue, 1 Apr 2025 16:35:09 +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=1743525310; cv=none; b=uqGXWuaF2TKjy6jSotXG285EGds5HGMlaAI7bVSPOOW7zq0MWXpG90BCDGEcM9/DizveTBY+GVmtzotFgsopI6heiQlShO/GbYBxzDUh1q1LSiJZSGTiUfUHd78v+HxWpyXz8sY54T9nm7D+XPavtRkTxHTnXPtxWkul0LwmM18= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743525310; c=relaxed/simple; bh=jtIpRcdfbZGr8j8HnOORbFj33P6heMMjUX2ftdMNEdA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QDlfGQ+QOifgD7KjG20YkiQnkut5RlnAfYIfRNQnHn6uYuC2iHYOs49IMCV168FtVOEb9giR4Sp+cj/qfhlWnLKIgokcx5OLVIl6CBISVBMEX0gjiEcFQjhDQsW6X/1ime08GpT99UBXGmPxhUH1eqJMUz48IeaKe14AvD0TM2g= 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-227b650504fso116541595ad.0 for ; Tue, 01 Apr 2025 09:35:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743525308; x=1744130108; 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=a7aDtDjy3ey4QTIdSAIPP/aWvltr5sAHTnuDp8R+rVI=; b=fcvHJramCk5SW1O/kjB9Gc8Z77fzNQZI7HOfMRRdhrxehqEZ1kFO4kxwUcfjl7VNk4 +HYExusEMr1FshNKIqi24HRt9Exc7mu/ocEvCZt+boBXR2sYBbuy3Nesn2deurvrfFgU ONQ2b23cc1I/mRQ7RA/fr+ybQ3dhWmYn17JOwPU/57qApVzHtQRIsFxKHAezotjQ4hsH 6OCUqlHsxTd9mqQ8YwTgsRUTyRGVYjcCj0gmn/fUgagvhZ26uYqhTAftypAOGQ5ZO5d6 lu0guxlAKVb6JC0lhmvprvcVuK5fGzomcSvdHAN8xc9C1WQrCN16N/4Y8i7pcnrPiyn+ Ms/g== X-Gm-Message-State: AOJu0YyRwkAL5TtroqgE/M0T9Aum7c3r2hT4Z5SDvBGjMowrx678uTR+ K3YtuZK+pcRLQdW3w5DfcdNhr+0uOp91cdRrPEHObDkW1h2AJukGUJ6AxPZo/Q== X-Gm-Gg: ASbGncuk3+oyjMlJFSKoTJQI5lLkZjlk7AhpwxprwyIX3B/c9kQ0KZ9uUVqt70tqVvu 39QEXqwxNEFekrNO+2+fpcm9KppYLblbG4YWUQUKgNX3gOjdbA/RG612fA++o1PBg68cs2Xp6Bu EigVeJVhxveILdOyqnuw8+oA0S1CBEOf7M0uhkLYGZ8KdM7Nen11zJ3gpkXurHI+jVREtkhWz54 6bE8bMZN2Sh71NFT7djISvB9L+0/cD3t5w6+ARQDmqB2QQ83lcPcIRJhUtHfXNgAANeC8X354x+ w+l24OyLeBHl+Ruj4pOOiBiGLj3Vk/lAe20OKk5DGvXu X-Google-Smtp-Source: AGHT+IHlvRCiCm8u1+6Cks1GmVtmsBIZ3y5TKSKXxi/FwbarPEI34ziVQxGe/IpUyIdrcaHNKrGX+w== X-Received: by 2002:a17:903:2408:b0:224:1157:6d26 with SMTP id d9443c01a7336-2292f942a8fmr226841365ad.4.1743525308241; Tue, 01 Apr 2025 09:35:08 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-2291eeca0e2sm90953075ad.34.2025.04.01.09.35.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Apr 2025 09:35:07 -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 v5 10/11] netdev: add "ops compat locking" helpers Date: Tue, 1 Apr 2025 09:34:51 -0700 Message-ID: <20250401163452.622454-11-sdf@fomichev.me> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250401163452.622454-1-sdf@fomichev.me> References: <20250401163452.622454-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 c316b551df8d..5706835a660c 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 e59eb173900d..87cba93fa59f 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 7ee203395d8e..c4b645120d72 100644 --- a/net/core/dev.h +++ b/net/core/dev.h @@ -41,6 +41,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 Apr 1 16:34: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: 14035158 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 1C00820FA96 for ; Tue, 1 Apr 2025 16:35:10 +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=1743525312; cv=none; b=g1ONBMzXYvI1/pnl6suCsaZEnVtXoWFHJrtR4Kpxzf0xokJfqVbsXpt6gIwL0QgxTUyGJTNuYX/cgdVEjw33AQduaXoVI/vJLxxrtHDpbWh/JD04g4aZVb7GVH6qCCusPFDpFoh/fABnnxrwjurLtd6Vii/ZZbKtV3aCyX5C28M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743525312; c=relaxed/simple; bh=Kt1WIg4lIHQ0tNTX8utGNk0WuyC4wNiPq7D7wY3RHmw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G/EgN5sVFFYmgNOpwdSTTIvkGxyAZl4tp9DmWsV1FWebAQbahN+FlEBdnL2ibSSKRneaCLdI7N04PJ++jAX1c1OpMW5ftjR5Fq8hYJYxOFWsuEZlO77YBXUgnbt6TnUZ+7dU6MJoT3f25+4dXTh+GDRngPLtm6xMve7wM9cGYDE= 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-30362ee1312so10169166a91.0 for ; Tue, 01 Apr 2025 09:35:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743525310; x=1744130110; 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=N5haY6mKBf1kNjqdrh+owzCUwoLwuFf5utGl4xuJ7TU=; b=V7tdhZCZqFeLx7twQKpkruS5Qs3VjWkw/zYF6tBg4Xc5SGGgz58HxbmV71zbWWs1wD Ml3ua6SsVWZbyvaY/OEJYJe4ya/YkSPEN2ufrYCkqcP0fcCpNknMexmIF6tb6IrwJ+1O 7bWKw6/GGmAe3xsnH2jjDv7u5eqrpdvPZ0tt2FaTkulJ6Up207QTp4pEyBBdyeDl0GQX tymv/qXOlaikIgvbuaZ9lin974WUQTRQAnXHgGBcBoLfS4i2IaJzsl3AunP9c0DvVEKv +dGqqOz/9OFQwd+nxK9JyU1KMp/r3SMvwhkUUwus2C4j0e5ifAzfXNLlc1oMd9i3ly0Q ipeg== X-Gm-Message-State: AOJu0YzMKlZ8TmIHTtGVr9BOChMAqq1D2siZetXpyJpzXCfAuCuK0nz1 z9Q6WB96nz9JANqZy0sq7DvO9zP8/lI8OUl1N3rpNE85Gj08axLa95SvZrFiaA== X-Gm-Gg: ASbGncsADG9OCy8NCTXjT8NBx/Zewpyq4esZzXAo3agu61gRl/r3w1FiWu60/mPYuF8 82w4LiluWRpEqTn33livE3p2R26kGwxr7KPLJB30136Fur+UUIR6US2sS9KVN950JurQ2urvNCO +ptg5zet8+0ikVDk07y3znQBJTdBUR60tgMx/9afCDiWefnJ24wPVeTGyaULjLfn6ye7O7u6ikQ +aOxQeGCzcm+oQbnWnjA6GkeKyHv0cjyJPevsgqVyXUv0D2iCPUkxPiC9DNNVZzJh8swC/DcA9O 7Dzih1T2t5Wb5oI/BbpxGYLFio/V2qHj4aMfLEmbOJtv X-Google-Smtp-Source: AGHT+IEZBf4fKopGb+2H9NDULNg/MAMle5uTLdonr5HuauraSJ7D9psKEifdmrjcsmAZwm4vkHhvBg== X-Received: by 2002:a17:90b:3b8a:b0:2ee:e945:5355 with SMTP id 98e67ed59e1d1-305320b1043mr18395665a91.19.1743525309600; Tue, 01 Apr 2025 09:35:09 -0700 (PDT) Received: from localhost ([2601:646:9e00:f56e:123b:cea3:439a:b3e3]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-30561cac698sm1163482a91.0.2025.04.01.09.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Apr 2025 09:35: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 v5 11/11] netdev: don't hold rtnl_lock over nl queue info get when possible Date: Tue, 1 Apr 2025 09:34:52 -0700 Message-ID: <20250401163452.622454-12-sdf@fomichev.me> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250401163452.622454-1-sdf@fomichev.me> References: <20250401163452.622454-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 3afeaa8c5dc5..f9d7fe89644f 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; }