From patchwork Wed Mar 12 22:34:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 14014007 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6C2B1DFD95 for ; Wed, 12 Mar 2025 22:35:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818920; cv=none; b=oFCrfNsVyVrFNNeeKW8a7QjmzZeNHQcDO3JgswnowSbEauGqG2K33Nl9EHDAGoXPscryccdHGFvSV2lSF6wXsEbxB6LqCuouGsMEIguwIMiBxPDRPyBuiv3koe93JHg84VCTXTbaHTzbrJpw/H5DwOGgd/fAkTwPG/q1D4JHVZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818920; c=relaxed/simple; bh=mUMfc61+oHRmSbEZXt/K/mgy4oEcVaPT6Jl9gBK4+NY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lDVfUaVRZ7288VRxOCTrN5bn/4lyszdovo9ZIoXnWeeHL/5lmoHvY9EX1fo1uMZRNUj17QE7knaQ5oyIO444Cyrh1NAQiauSaXl1zrhqf7TMYwQ/kDmBfZd74OH44+ckXwZcpolB8K7l5a81XANQFn4xnHek8fytUZxdjDlWjVo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O3fRef9I; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="O3fRef9I" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34BF0C4CEE3; Wed, 12 Mar 2025 22:35:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741818920; bh=mUMfc61+oHRmSbEZXt/K/mgy4oEcVaPT6Jl9gBK4+NY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O3fRef9IUqpCL3bpPuUWSNsdyA9H7lgML1frSadcazZgzXflnFHDESDz0Dwh+0YmT MEdzcjMYZGfbC/Ebp7rQwxjl2K4Z20tkYdm/reV6inrCv0AKbLy+OdoxKjukeR+NcQ YoaC+rLj4yr/TXbv827zOzVDP517pxgMPACyZlOkR2fwVfe68BTDyHGOVyhKMwcEwA ShFQ/gDl3oLZuzOzJ1vOH75SM3/qHyCASmvK1jFlTDeOUSI/cHcuMBJYdcpVcrpapF vS79+MGDQth1wJIrR6JhF3TItaKMJJauHQHPPdtigHS5VU+7h3VUnIYwGE6dpyP5dg R5fdezIJj8cRA== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org, sdf@fomichev.me, Jakub Kicinski Subject: [PATCH net-next 01/11] net: bubble up taking netdev instance lock to callers of net_devmem_unbind_dmabuf() Date: Wed, 12 Mar 2025 23:34:57 +0100 Message-ID: <20250312223507.805719-2-kuba@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250312223507.805719-1-kuba@kernel.org> References: <20250312223507.805719-1-kuba@kernel.org> 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 A recent commit added taking the netdev instance lock in netdev_nl_bind_rx_doit(), but didn't remove it in net_devmem_unbind_dmabuf() which it calls from an error path. Always expect the callers of net_devmem_unbind_dmabuf() to hold the lock. This is consistent with net_devmem_bind_dmabuf(). (Not so) coincidentally this also protects mp_param with the instance lock, which the rest of this series needs. Fixes: 1d22d3060b9b ("net: drop rtnl_lock for queue_mgmt operations") Signed-off-by: Jakub Kicinski --- net/core/devmem.c | 2 -- net/core/netdev-genl.c | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/core/devmem.c b/net/core/devmem.c index 5c4d79a1bcd8..9e9db6de8631 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -127,10 +127,8 @@ void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding) rxq->mp_params.mp_priv = NULL; rxq->mp_params.mp_ops = NULL; - netdev_lock(binding->dev); rxq_idx = get_netdev_rx_queue_index(rxq); WARN_ON(netdev_rx_queue_restart(binding->dev, rxq_idx)); - netdev_unlock(binding->dev); } xa_erase(&net_devmem_dmabuf_bindings, binding->id); diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index a186fea63c09..9e4882a22407 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -947,7 +947,9 @@ void netdev_nl_sock_priv_destroy(struct netdev_nl_sock *priv) mutex_lock(&priv->lock); list_for_each_entry_safe(binding, temp, &priv->bindings, list) { + netdev_lock(binding->dev); net_devmem_unbind_dmabuf(binding); + netdev_unlock(binding->dev); } mutex_unlock(&priv->lock); } From patchwork Wed Mar 12 22:34:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 14014008 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E01FC1DFD95 for ; Wed, 12 Mar 2025 22:35:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818923; cv=none; b=B3YK295BhYJ1LFYaCfYay9T2L0ocyrHuv+dZE0kJzHErnuqMam7I6oa96QMOYOV4DJeqnx0lBIcMvon+WraaRyCLCwuJGw78yzrOxR/A8u7rNI9w4qzUqaBUGcyEVwpWT6jP0ya4liGmQu4+G/DBczFuCHaEi7cSQl7RYN9ithw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818923; c=relaxed/simple; bh=fU29yfcICr0i7WPZOez/rsw4Cxi+HOfiazZsiZQuRe4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LlBfyGGwb5w+UrsA0Vb1FcFkU9EC0qMzlmRXV407bZeCMJyuIdSefJuJonvk5IaK8+2f4h1ivCyTXTvOye9wfN1qm/MKBZmvhJhXtE45Xfk6kiiAyUWIrDsTdFb76gIWQI1vcElqgOlb4hr3jjSilu2xFpzzeqRyDZEX1nkKlCI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JeG+WeJN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JeG+WeJN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAEFBC4CEDD; Wed, 12 Mar 2025 22:35:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741818922; bh=fU29yfcICr0i7WPZOez/rsw4Cxi+HOfiazZsiZQuRe4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JeG+WeJNa9W4ttPuvMwzY7jBKFJG7zL2QhWFbd/fWSArttAKdrObRasZc4PT9Jp6V 3Knld+EQ2gVW49QgiUdSZO/24AIjeKfxpApHCoOHKzTq58AG6V+akp9xB9hzzTSu1F +5eLjjvStZnIMuOPGGjNUQLy4FfZPBLBUP/IOf1nsJ5j4ETkuezSjwdEiggcsJ8k7U POfgt7Sf55I/A0e2aKh8w267LljW2WjAITk+m8SXfR3zCn2yzuhEay93BWVc3GcYiT S5gBhEyiFDdH26xt2gc6z63Vt9LWImFYfwrqCJJy5oMyczktB2fvsCrPquvdOcoxKv v9tXtblXFueNw== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org, sdf@fomichev.me, Jakub Kicinski Subject: [PATCH net-next 02/11] net: remove netif_set_real_num_rx_queues() helper for when SYSFS=n Date: Wed, 12 Mar 2025 23:34:58 +0100 Message-ID: <20250312223507.805719-3-kuba@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250312223507.805719-1-kuba@kernel.org> References: <20250312223507.805719-1-kuba@kernel.org> 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 Since commit a953be53ce40 ("net-sysfs: add support for device-specific rx queue sysfs attributes"), so for at least a decade now it is safe to call net_rx_queue_update_kobjects() when SYSFS=n. That function does its own ifdef-inery and will return 0. Remove the unnecessary stub for netif_set_real_num_rx_queues(). Signed-off-by: Jakub Kicinski --- include/linux/netdevice.h | 10 ---------- net/core/dev.c | 2 -- 2 files changed, 12 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 0dbfe069a6e3..2f344d5ad953 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -4062,17 +4062,7 @@ static inline bool netif_is_multiqueue(const struct net_device *dev) } int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq); - -#ifdef CONFIG_SYSFS int netif_set_real_num_rx_queues(struct net_device *dev, unsigned int rxq); -#else -static inline int netif_set_real_num_rx_queues(struct net_device *dev, - unsigned int rxqs) -{ - dev->real_num_rx_queues = rxqs; - return 0; -} -#endif int netif_set_real_num_queues(struct net_device *dev, unsigned int txq, unsigned int rxq); diff --git a/net/core/dev.c b/net/core/dev.c index 0bf5af9706b1..3f35f3f8b2f1 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3162,7 +3162,6 @@ int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq) } EXPORT_SYMBOL(netif_set_real_num_tx_queues); -#ifdef CONFIG_SYSFS /** * netif_set_real_num_rx_queues - set actual number of RX queues used * @dev: Network device @@ -3193,7 +3192,6 @@ int netif_set_real_num_rx_queues(struct net_device *dev, unsigned int rxq) return 0; } EXPORT_SYMBOL(netif_set_real_num_rx_queues); -#endif /** * netif_set_real_num_queues - set actual number of RX and TX queues used From patchwork Wed Mar 12 22:34:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 14014009 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7B501DFD95 for ; Wed, 12 Mar 2025 22:35:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818925; cv=none; b=GeZjbOuL3O5WNilS2dPEtNS5VPE1XWWEr3kwxIMMtklXL58etChatJW8QzOIzL0xTxnnQWAhbSYnpirzTamiAIr0fFFsFrkw0NOycMUa+TmZjaIz4ii/Qki1AFkUeUoaFRC6XNPwrY0w8lGThgB6dhwhmKnywfOV8bJySl8JpWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818925; c=relaxed/simple; bh=CfUwrM2V/e72+UB4UGgtb91j5B0Cx+t37H2hoW+n3II=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OP8SMWCmzuZh7ZnL0MX2OEKKdYw9ZsH1csm1sBLeyuCMSsIVvffawdEoVCf+48sRmXZefUAhdD3P/dDOsH16HXOX0zgelzBIcYiiGUiz+qFXcZuOuO2JHhFSoxiLJ8PibtKVhsF5y5VxmvzY6ieL/QVSjjj4g5A/O2yKtaA6KZk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MNPZ7OHa; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MNPZ7OHa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3901CC4CEED; Wed, 12 Mar 2025 22:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741818925; bh=CfUwrM2V/e72+UB4UGgtb91j5B0Cx+t37H2hoW+n3II=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MNPZ7OHa1rmHNi1DmCsWSzMkTKRF6wSsgH4Jo2TLsGMcyfq2SXS1Kq64s6qUVc0R0 EumJCi2UWjgY4tnrz7B7eLixMplnszJuTIyuDsuNnVWIjP1dxw1u/zoPdGpCIcFvUD g/7WM0aO7eAKXNNFzL0OY0fr+NGl0rukyH+zZh5TgLTRlDs4PoNrAyAQ6BRJF56ltm 0gHqwahrXOdFPlKn7lZLML92XFeh6NPpAuzRsiBVhJLvpkZiZMPnWTlaplzfSHWVXi EEEbZV/6M43PH6TmHWcbfjVXjoI7iHymgW+TSLoHhgXFqEM+SD1kD44H5MziRdKpyT hg7WpY36rWlFg== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org, sdf@fomichev.me, Jakub Kicinski Subject: [PATCH net-next 03/11] net: constify dev pointer in misc instance lock helpers Date: Wed, 12 Mar 2025 23:34:59 +0100 Message-ID: <20250312223507.805719-4-kuba@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250312223507.805719-1-kuba@kernel.org> References: <20250312223507.805719-1-kuba@kernel.org> 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 lockdep asserts and predicates can operate on const pointers. In the future this will let us add asserts in functions which operate on const pointers like dev_get_min_mp_channel_count(). Signed-off-by: Jakub Kicinski --- include/net/netdev_lock.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/net/netdev_lock.h b/include/net/netdev_lock.h index 99631fbd7f54..689ffdfae50d 100644 --- a/include/net/netdev_lock.h +++ b/include/net/netdev_lock.h @@ -11,19 +11,20 @@ static inline bool netdev_trylock(struct net_device *dev) return mutex_trylock(&dev->lock); } -static inline void netdev_assert_locked(struct net_device *dev) +static inline void netdev_assert_locked(const struct net_device *dev) { lockdep_assert_held(&dev->lock); } -static inline void netdev_assert_locked_or_invisible(struct net_device *dev) +static inline void +netdev_assert_locked_or_invisible(const struct net_device *dev) { if (dev->reg_state == NETREG_REGISTERED || dev->reg_state == NETREG_UNREGISTERING) netdev_assert_locked(dev); } -static inline bool netdev_need_ops_lock(struct net_device *dev) +static inline bool netdev_need_ops_lock(const struct net_device *dev) { bool ret = dev->request_ops_lock || !!dev->queue_mgmt_ops; @@ -46,7 +47,7 @@ static inline void netdev_unlock_ops(struct net_device *dev) netdev_unlock(dev); } -static inline void netdev_ops_assert_locked(struct net_device *dev) +static inline void netdev_ops_assert_locked(const struct net_device *dev) { if (netdev_need_ops_lock(dev)) lockdep_assert_held(&dev->lock); From patchwork Wed Mar 12 22:35:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 14014010 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 640201F0E26 for ; Wed, 12 Mar 2025 22:35:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818928; cv=none; b=ZXDlh4axUq5VJY6ogZesUpULwnP+HwFoSAYTRrspAmEqe1vfuNbhb5AQWAsLr/e9yVPAfPUIFAjualnS0GCupjz3979N+O1s+Z7oifNU2LESKKgKbRsrbS0noxamp0RZRUvcH3CbUs+/SAXerk+ylyKAkhc9F64w7UaCPdwUJLM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818928; c=relaxed/simple; bh=ju48Qgbreq1JnAKm3gumpOguqdUyJKjT2HnadJSjg1w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RnqY3Iv3j4R8gm03WbvGe/Utw1eFb4q3+bcRXsynwx9IySUIoaYOnZV40sk9fZ1ILQDTZjT6uSLDuxH1vhs1785psGuILMKCuadvN86F63uCRubx8bAJuJWk3Oua3fSOHCYus+uaRap7VhQtzoR+jx6ytZBilr0LFj/pNOgS1fc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=beB8sxUb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="beB8sxUb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEFA7C4CEDD; Wed, 12 Mar 2025 22:35:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741818927; bh=ju48Qgbreq1JnAKm3gumpOguqdUyJKjT2HnadJSjg1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=beB8sxUb2FIV7+41YPGZvMRvOtG7pFxX/MFxoen2BHVFK4CpdAVhG7mJz7LxAMHWL tpca0q0vLrMp2clw46NFBLtOIs8d0nC1JvgUrsHaVNSJjIpXninmRPiq4TtrtuWmlz lDL8TmPbWTcaXjj/i/gph0YMoK+JruTWHYln8Fmx+KAuj+R5V4Rwco3crE3kew9LFS ZPXeqvNdRRrwRAlNg4taiBUaCkvtvrDWVcw4FaWUk+/5lpdeWJEhadm5+kjaq25R1s 8f1SASVrXMQQmMsGXjrqPubR/OuEDjuCofvCAvidtg1Eidg28kkZegg3FUAb7wNsOW rnElBjiNawLVQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org, sdf@fomichev.me, Jakub Kicinski Subject: [PATCH net-next 04/11] net: explain "protection types" for the instance lock Date: Wed, 12 Mar 2025 23:35:00 +0100 Message-ID: <20250312223507.805719-5-kuba@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250312223507.805719-1-kuba@kernel.org> References: <20250312223507.805719-1-kuba@kernel.org> 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 Try to define some terminology for which fields are protected by which lock and how. Some fields are protected by both rtnl_lock and instance lock which is hard to talk about without having a "key phrase" to refer to a particular protection scheme. "ops protected" fields are defined later in the series, one by one. Add ASSERT_RTNL() to netdev_ops_assert_locked() for drivers not other instance protection of ops. Hopefully it's not too confusion that netdev_lock_ops() does not match the lock which netdev_ops_assert_locked() will assert, exactly. The noun "ops" is in a different place in the name, so I think it's acceptable... Signed-off-by: Jakub Kicinski --- include/linux/netdevice.h | 24 ++++++++++++++++++------ include/net/netdev_lock.h | 3 +++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 2f344d5ad953..e8e4e6fbcef4 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2496,19 +2496,31 @@ struct net_device { * Should always be taken using netdev_lock() / netdev_unlock() helpers. * Drivers are free to use it for other protection. * - * Protects: + * For the drivers that implement shaper or queue API, the scope + * of this lock is expanded to cover most ndo/queue/ethtool/sysfs + * operations. Drivers may opt-in to this behavior by setting + * @request_ops_lock. + * + * @lock protection mixes with rtnl_lock in multiple ways, fields are + * either: + * - simply protected by the instance @lock; + * - double protected - writers hold both locks, readers hold either; + * - ops protected - protected by the lock held around the NDOs + * and other callbacks, that is the instance lock on devices for + * which netdev_need_ops_lock() returns true, otherwise by rtnl_lock; + * - double ops protected - always protected by rtnl_lock but for + * devices for which netdev_need_ops_lock() returns true - also + * the instance lock. + * + * Simply protects: * @gro_flush_timeout, @napi_defer_hard_irqs, @napi_list, * @net_shaper_hierarchy, @reg_state, @threaded, @dev_addr * - * Partially protects (writers must hold both @lock and rtnl_lock): + * Double protects: * @up * * Also protects some fields in struct napi_struct. * - * For the drivers that implement shaper or queue API, the scope - * of this lock is expanded to cover most ndo/queue/ethtool/sysfs - * operations. - * * Ordering: take after rtnl_lock. */ struct mutex lock; diff --git a/include/net/netdev_lock.h b/include/net/netdev_lock.h index 689ffdfae50d..efd302375ef2 100644 --- a/include/net/netdev_lock.h +++ b/include/net/netdev_lock.h @@ -5,6 +5,7 @@ #include #include +#include static inline bool netdev_trylock(struct net_device *dev) { @@ -51,6 +52,8 @@ static inline void netdev_ops_assert_locked(const struct net_device *dev) { if (netdev_need_ops_lock(dev)) lockdep_assert_held(&dev->lock); + else + ASSERT_RTNL(); } static inline int netdev_lock_cmp_fn(const struct lockdep_map *a, From patchwork Wed Mar 12 22:35:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 14014011 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBAAE1EFFBA for ; Wed, 12 Mar 2025 22:35:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818931; cv=none; b=kNDPWr4bfMDKbtp3VezvpRXVSQ/GrjtrFtPN7IiL5ZuVH0Ljq0G9dgEuqtQClkvcIZpPA9ws800vDejcE0VKXw0Wpk8LaM68b8t5olVw7h671292KJffd1lMG23bIPkGYM17zahWbiaNw70l107cwYeSzQYHBE3Zoh6PEdoIj6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818931; c=relaxed/simple; bh=IwfCs1DnF0SiqPf/BkI1aSOJGuYCy0ETeAjtkyZv1FY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IurryJuLmn8lmJUqjJsW3q6/yBvWMNg1Ri3VMXGpfTGBQqjYnwxdLD8gbteEFOcRdc7htvC6aK2IvDlOvwHOZcQkroecVcFEpKMJuJWgo6huCfSOjS/SVJb0qOwDHRmto+Yg1kEkgyatgGIbqaGSadDQflWbEvAZKE1vdT+f0hc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SnWYRd/8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SnWYRd/8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F609C4CEED; Wed, 12 Mar 2025 22:35:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741818930; bh=IwfCs1DnF0SiqPf/BkI1aSOJGuYCy0ETeAjtkyZv1FY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SnWYRd/8LyaK4CwyTCy0OUuI+dguEvj2ARtZgoo/QNTNx/XzDJLNjdCs83jZ7e+xr P7YZIacBNU+gHYSMUe+x8oa1W1S9VkaKi4ncZhqdBD9PjOVvklsN5mmRdilsvtgrP+ 67lLew208Hij2d72xLWr9aUASgvryDlr3NOKbNIkq6AKOpezsREmSmHYDUKqdXwtbh +tMxmygOsgj9iMeAPE89rI2zUnVN7a6qqePlkDOQsoNFU2XwcTPPqtG2jrBd1FaDc4 zwlb9MguNpijvLS/JXzGDYCCGEbETkJp21jh/FFObUaeVrvUcReCuTGNrCQgR5+5AG hWBtb1BYo+ImQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org, sdf@fomichev.me, Jakub Kicinski Subject: [PATCH net-next 05/11] net: designate queue counts as "double ops protected" by instance lock Date: Wed, 12 Mar 2025 23:35:01 +0100 Message-ID: <20250312223507.805719-6-kuba@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250312223507.805719-1-kuba@kernel.org> References: <20250312223507.805719-1-kuba@kernel.org> 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 Drivers which opt into instance lock protection of ops should only call set_real_num_*_queues() under the instance lock. This means that queue counts are double protected (writes are under both rtnl_lock and instance lock, readers under either). Some readers may still be under the rtnl_lock, however, so for now we need double protection of writers. OTOH queue API paths are only under the protection of the instance lock, so we need to validate that the instance is actually locking ops, otherwise the input checks we do against queue count are racy. Signed-off-by: Jakub Kicinski --- include/linux/netdevice.h | 3 +++ net/core/dev.c | 2 ++ net/core/net-sysfs.c | 2 ++ net/core/netdev-genl.c | 7 +++++++ net/core/netdev_rx_queue.c | 3 +++ 5 files changed, 17 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index e8e4e6fbcef4..0e2fa80a556d 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2519,6 +2519,9 @@ struct net_device { * Double protects: * @up * + * Double ops protects: + * @real_num_rx_queues, @real_num_tx_queues + * * Also protects some fields in struct napi_struct. * * Ordering: take after rtnl_lock. diff --git a/net/core/dev.c b/net/core/dev.c index 3f35f3f8b2f1..8ae4f56169fe 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3132,6 +3132,7 @@ int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq) if (dev->reg_state == NETREG_REGISTERED || dev->reg_state == NETREG_UNREGISTERING) { ASSERT_RTNL(); + netdev_ops_assert_locked(dev); rc = netdev_queue_update_kobjects(dev, dev->real_num_tx_queues, txq); @@ -3181,6 +3182,7 @@ int netif_set_real_num_rx_queues(struct net_device *dev, unsigned int rxq) if (dev->reg_state == NETREG_REGISTERED) { ASSERT_RTNL(); + netdev_ops_assert_locked(dev); rc = net_rx_queue_update_kobjects(dev, dev->real_num_rx_queues, rxq); diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 529a0f721268..6776b1080864 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -2145,8 +2145,10 @@ static void remove_queue_kobjects(struct net_device *dev) net_rx_queue_update_kobjects(dev, real_rx, 0); netdev_queue_update_kobjects(dev, real_tx, 0); + netdev_lock_ops(dev); dev->real_num_rx_queues = 0; dev->real_num_tx_queues = 0; + netdev_unlock_ops(dev); #ifdef CONFIG_SYSFS kset_unregister(dev->queues_kset); #endif diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index 9e4882a22407..fd1cfa9707dc 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -867,6 +867,13 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info) goto err_unlock_sock; } + if (!netdev_need_ops_lock(netdev)) { + err = -EOPNOTSUPP; + NL_SET_BAD_ATTR(info->extack, + info->attrs[NETDEV_A_DEV_IFINDEX]); + goto err_unlock; + } + if (dev_xdp_prog_count(netdev)) { NL_SET_ERR_MSG(info->extack, "unable to bind dmabuf to device with XDP program attached"); err = -EEXIST; diff --git a/net/core/netdev_rx_queue.c b/net/core/netdev_rx_queue.c index a5b234b33cd5..3af716f77a13 100644 --- a/net/core/netdev_rx_queue.c +++ b/net/core/netdev_rx_queue.c @@ -92,6 +92,9 @@ static int __net_mp_open_rxq(struct net_device *dev, unsigned ifq_idx, struct netdev_rx_queue *rxq; int ret; + if (!netdev_need_ops_lock(dev)) + return -EOPNOTSUPP; + if (ifq_idx >= dev->real_num_rx_queues) return -EINVAL; ifq_idx = array_index_nospec(ifq_idx, dev->real_num_rx_queues); From patchwork Wed Mar 12 22:35:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 14014012 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 650761EFFBA for ; Wed, 12 Mar 2025 22:35:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818933; cv=none; b=ido1c93KQ6LThVc/Nj97hCGJf6l4XlLI602HMZC0jAxrDxEX+cm6C1y/o/Oql3KMuU2QCC6WArgEwWQG7eviv2UIIj3nUwmTuRS7xb5/qiyY7uF8Lffl2HPvmvbAZ/hPRwqRGw94HKU8vTtoZUYRPZopnEpB3CDa2hCtZbwUpaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818933; c=relaxed/simple; bh=m94RWl7vU9oHuhve8G/1ka9IbsK+2DTHzEc60QzSUWU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f7szl1i8bZwMnSEJGhC8sUKHug0Sg1MgW5IdeuGjF9G+kz9qKmOkGjQx4MYDZMpL+FpmpyXpIskL3YXMA3yPMNl6EpG4YZ3vBlRl7EC4E7VT+llyp+DJ52F34P2SkPYrswPsl177POwB7IZmM9CxH5A/dv34nvxDMdELvcIGXNs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iWthig+e; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iWthig+e" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8010C4CEE3; Wed, 12 Mar 2025 22:35:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741818932; bh=m94RWl7vU9oHuhve8G/1ka9IbsK+2DTHzEc60QzSUWU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iWthig+eWjigUtVEaa6Erm5ePiUSNsZsc7EYCW0XNF60yZoiheBcuNMb8c1OY2xiZ N1r9hXTT+OYQYWxV45+tUnVQghz+tJt80jLnbk8ZrQ5doox9Gfg/1yqpvwHT1Qsey3 +e0prnDCRRSm6Z+QL/nq6XA24AHiKcF9Yf0mX8lNzS+XwQowWJqx8gY/guSypM0dGm 8by7TgKQhObjFED9HePVXHInYevGh+xAHrBwxDjPFSazySO9DoLYRwkZEweguqP0P/ qoU6RRhAV1+CBW/dSRmryT9hM5sbkT9R0q/SMv/rpRj9bBnIkUSHYPMFxJIG6UpW64 HeRoN6CFLgkuQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org, sdf@fomichev.me, Jakub Kicinski Subject: [PATCH net-next 06/11] net: designate queue -> napi linking as "ops protected" Date: Wed, 12 Mar 2025 23:35:02 +0100 Message-ID: <20250312223507.805719-7-kuba@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250312223507.805719-1-kuba@kernel.org> References: <20250312223507.805719-1-kuba@kernel.org> 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 netdev netlink is the only reader of netdev_{,rx_}queue->napi, and it already holds netdev->lock. Switch protection of the writes to netdev->lock to "ops protected". The expectation will be now that accessing queue->napi will require netdev->lock for "ops locked" drivers, and rtnl_lock for all other drivers. Current "ops locked" drivers don't require any changes. gve and netdevsim use _locked() helpers right next to netif_queue_set_napi() so they must be holding the instance lock. iavf doesn't call it. bnxt is a bit messy but all paths seem locked. Signed-off-by: Jakub Kicinski --- include/linux/netdevice.h | 5 +++-- include/net/netdev_lock.h | 8 ++++++++ include/net/netdev_rx_queue.h | 2 +- net/core/dev.c | 3 +-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 0e2fa80a556d..0fc79ae60ff5 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -710,7 +710,7 @@ struct netdev_queue { * slow- / control-path part */ /* NAPI instance for the queue - * Readers and writers must hold RTNL + * "ops protected", see comment about net_device::lock */ struct napi_struct *napi; @@ -2522,7 +2522,8 @@ struct net_device { * Double ops protects: * @real_num_rx_queues, @real_num_tx_queues * - * Also protects some fields in struct napi_struct. + * Also protects some fields in: + * struct napi_struct, struct netdev_queue, struct netdev_rx_queue * * Ordering: take after rtnl_lock. */ diff --git a/include/net/netdev_lock.h b/include/net/netdev_lock.h index efd302375ef2..1c0c9a94cc22 100644 --- a/include/net/netdev_lock.h +++ b/include/net/netdev_lock.h @@ -56,6 +56,14 @@ static inline void netdev_ops_assert_locked(const struct net_device *dev) ASSERT_RTNL(); } +static inline void +netdev_ops_assert_locked_or_invisible(const struct net_device *dev) +{ + if (dev->reg_state == NETREG_REGISTERED || + dev->reg_state == NETREG_UNREGISTERING) + netdev_ops_assert_locked(dev); +} + static inline int netdev_lock_cmp_fn(const struct lockdep_map *a, const struct lockdep_map *b) { diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h index af40842f229d..b2238b551dce 100644 --- a/include/net/netdev_rx_queue.h +++ b/include/net/netdev_rx_queue.h @@ -24,7 +24,7 @@ struct netdev_rx_queue { struct xsk_buff_pool *pool; #endif /* NAPI instance for the queue - * Readers and writers must hold RTNL + * "ops protected", see comment about net_device::lock */ struct napi_struct *napi; struct pp_memory_provider_params mp_params; diff --git a/net/core/dev.c b/net/core/dev.c index 8ae4f56169fe..8f30938ed402 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6886,8 +6886,7 @@ void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index, if (WARN_ON_ONCE(napi && !napi->dev)) return; - if (dev->reg_state >= NETREG_REGISTERED) - ASSERT_RTNL(); + netdev_ops_assert_locked_or_invisible(dev); switch (type) { case NETDEV_QUEUE_TYPE_RX: From patchwork Wed Mar 12 22:35:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 14014013 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDFD71F0E51 for ; Wed, 12 Mar 2025 22:35:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818935; cv=none; b=sNX6v432E4e0XJ4JMXATwRZLO2gAJc9ZbcuqUsbmWRiuQRZdue/XF9xEncBoIpokLNFXdhODLol1PmC690/aopj9J5WT+yV6OUgdOdATA3Wpoz4ZzVRfmTFnKPrHQnI9nOl/1K9glHbHPZf+EfbefDegjtYmQnQt+vkQ3mLJC8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818935; c=relaxed/simple; bh=l07BTBACX/w8O/b9xOZb3065+hBiDYS2A4dopmh/V48=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j6GF3QSlFkQ0w11b88wuRtFS7JgqMvHOqITDXvHfxqIovQAqOHU5hpUnNct0gDpE8I4iz7+H1uLjpOOO2cu+NALcH3oPbRYzTH4jmYlJWwijit02Oa/F9eEolVvqzagnRRmHbDgnixQSFjuitRd4EKwvwCAJNMaK/FsG+GLt4a4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pRdpt3mt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pRdpt3mt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 599C9C4CEDD; Wed, 12 Mar 2025 22:35:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741818935; bh=l07BTBACX/w8O/b9xOZb3065+hBiDYS2A4dopmh/V48=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pRdpt3mtW8VabyM51wM91PkyFJ693JJFG5/cY0voV+vwWE1CfcXw0+c5G4Bm8ydg8 mpGigKvFN3wq+3GPU5K7CVmivafAvI22QP4p2NZoWB/MMGZwWS2yuiDJBtok6ZIxPe omCD7YmpNFIDX/lUkHw0TKBCKl0ZkyfZRCnjF8AEobe45lreCSk8zqctaeAxwDiv3n QYci0cdZo7+lOrrKUBkwKnMblgo83SfIEo1J2iMPfvkHM0Ff+yhBJOspT8PXYUel+7 tpLXYUf4HfxilRche1u08/URX3sXLeqPepoTuQEKKLS5ModRnoc8jYsTNrf6YAtCpj fSND8WF+xZzKQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org, sdf@fomichev.me, Jakub Kicinski Subject: [PATCH net-next 07/11] net: protect rxq->mp_params with the instance lock Date: Wed, 12 Mar 2025 23:35:03 +0100 Message-ID: <20250312223507.805719-8-kuba@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250312223507.805719-1-kuba@kernel.org> References: <20250312223507.805719-1-kuba@kernel.org> 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 Ensure that all accesses to mp_params are under the netdev instance lock. The only change we need is to move dev_memory_provider_uninstall() under the lock. Appropriately swap the asserts. Signed-off-by: Jakub Kicinski --- net/core/dev.c | 4 ++-- net/core/page_pool.c | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 8f30938ed402..ded6ffbda965 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10334,7 +10334,7 @@ u32 dev_get_min_mp_channel_count(const struct net_device *dev) { int i; - ASSERT_RTNL(); + netdev_ops_assert_locked(dev); for (i = dev->real_num_rx_queues - 1; i >= 0; i--) if (dev->_rx[i].mp_params.mp_priv) @@ -11938,9 +11938,9 @@ void unregister_netdevice_many_notify(struct list_head *head, dev_tcx_uninstall(dev); netdev_lock_ops(dev); dev_xdp_uninstall(dev); + dev_memory_provider_uninstall(dev); netdev_unlock_ops(dev); bpf_dev_bound_netdev_unregister(dev); - dev_memory_provider_uninstall(dev); netdev_offload_xstats_disable_all(dev); diff --git a/net/core/page_pool.c b/net/core/page_pool.c index acef1fcd8ddc..7745ad924ae2 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -279,11 +280,7 @@ static int page_pool_init(struct page_pool *pool, get_device(pool->p.dev); if (pool->slow.flags & PP_FLAG_ALLOW_UNREADABLE_NETMEM) { - /* We rely on rtnl_lock()ing to make sure netdev_rx_queue - * configuration doesn't change while we're initializing - * the page_pool. - */ - ASSERT_RTNL(); + netdev_assert_locked(pool->slow.netdev); rxq = __netif_get_rx_queue(pool->slow.netdev, pool->slow.queue_idx); pool->mp_priv = rxq->mp_params.mp_priv; From patchwork Wed Mar 12 22:35:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 14014014 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E411D1F03E4 for ; Wed, 12 Mar 2025 22:35:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818938; cv=none; b=qG6VCNICFTlCP1xNZOc8SwPsEWiPhcmLNpX6Bczhzb2fAoOfPHYiaUBCAkikpJwCKyVFfNhYBGiRBVBEY3hGEHxOMRxKcVPFhXb1XV6gkCjqogYhNkGkSYVWb7oLFvyVhW1N2dRmdL/Ssdy8uU8MFkYpa5cC467QoSphQZFMLWk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818938; c=relaxed/simple; bh=AfbgA0hnPzi8/W4YlY1M32nuTyl1QpocHbaVMT0a0rU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ojqEujScGokkW295gnDOycrFQyRQ7bPL+FtFe0YD96QddQNZau7E8li4WOK2LlhazffQ/WLn2OBjQY3JA5lIG19bQFmu5NfQvbngOan1h00+pQ1ykDNynWAP4fl4e5GnXxZKkhHb5T2FK8gBFdIYqLNrHDsPxhH0Zoexm38w8zE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Rco06rUi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Rco06rUi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFFDEC4CEEB; Wed, 12 Mar 2025 22:35:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741818937; bh=AfbgA0hnPzi8/W4YlY1M32nuTyl1QpocHbaVMT0a0rU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rco06rUid5bhG2UC2mwOEdwfNnWZeJh4fZDz3swYxcTkzDFAJzNsGveyecrBaSDxa L/abYeh6l1MFvZ+PyKmcyprp+AzQVzpfs/yVlOCHAqEaIK42i94mKYgGyv4Pgwy0Hm /tgZT5qQp1J1LHgXIFPsCHsJq0WUKDl24fDPYv8aZqihc3zJhxhKkeFvwSWACxT+Gx L9y02gvRvdhj6krq6BDqyjGDTe2+tV2ysLwFHbEmR2dnBbwb8Fcl0Ng7D/9ZvCSxy4 6JdXJVJR/WoApZ/n+3vn6sQRzrwHziVxdOQsFVVlSPqOAWyPOtHryeFvePFv8SIxrY ze0IIn4Wubyiw== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org, sdf@fomichev.me, Jakub Kicinski Subject: [PATCH net-next 08/11] net: make NETDEV_UNREGISTER and instance lock more consistent Date: Wed, 12 Mar 2025 23:35:04 +0100 Message-ID: <20250312223507.805719-9-kuba@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250312223507.805719-1-kuba@kernel.org> References: <20250312223507.805719-1-kuba@kernel.org> 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 The NETDEV_UNREGISTER notifier gets called under the ops lock when device changes namespace but not during real unregistration. Take it consistently, XSK tries to poke at netdev queue state from this notifier. Signed-off-by: Jakub Kicinski --- net/core/dev.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net/core/dev.c b/net/core/dev.c index ded6ffbda965..8296b4c159fe 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1856,7 +1856,9 @@ static void call_netdevice_unregister_notifiers(struct notifier_block *nb, dev); call_netdevice_notifier(nb, NETDEV_DOWN, dev); } + netdev_lock_ops(dev); call_netdevice_notifier(nb, NETDEV_UNREGISTER, dev); + netdev_unlock_ops(dev); } static int call_netdevice_register_net_notifiers(struct notifier_block *nb, @@ -11155,8 +11157,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(); @@ -11947,7 +11952,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) From patchwork Wed Mar 12 22:35:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 14014015 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2BD31F03DE for ; Wed, 12 Mar 2025 22:35:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818940; cv=none; b=qHSxcw82AOtNUAY/Z7B19e0GxfesZBm09qgoVlaRYUgyv09qeO+eu67yxzPButkSn0/uQpGYVBA4veyjTE1iv7fQb1Kpl5lygq0JjsaWF3cXXg9OiKgrK5d4L5svQdjkX25J5k7zQzDa2DS/2jTiaOWYKx95oMW5OMzVgCW/IKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818940; c=relaxed/simple; bh=PjuiaYD06gAwzkwu3j5pZ5a8JqKZBfknOwKtVNJjoYs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P+7E11dNnJVhZwy+tMvXfokdyBA5KbytdjxviEIqoCibutMAZvh8nDp5pkAVaHBN2x7FsS+oSqKftK+sGe0Jdfqk0IeJvmDnRVvymwh5etNmi7qlCe3Sxgewt+EnGxkru6sLpJ1MrgY4mKdF0cIgBemqr26GmakYG4IVt7zu5+o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Sk8Ikopj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Sk8Ikopj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EDB1C4CEDD; Wed, 12 Mar 2025 22:35:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741818940; bh=PjuiaYD06gAwzkwu3j5pZ5a8JqKZBfknOwKtVNJjoYs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sk8Ikopj2ZjF0hFxhqFP/m8zWJ3psAe9lRveJ8840hJT+GrHyOZoPBsRj8K643JGN cQfKHMuI2JKvywYQLb0vxZvTjM29x5aOctTAeBKAPU5Q2qdjXaRetZ6atQZtm2wuDr uw5cYc+RkAWkm0O2nxi1ePorodr/w5bHGXKalXCRGsBjHAioMMd/TYigFVDh2HQb6V lDzKezW2dNsX6dvssuyi1rQQDe93G7xA3wg1ChWCzWVlLHC7x5PJQlbkjCQDVtd8D8 l4+tybrpdn64jDL/fsLb/nAJ+mjJBMifIMxVETlZUWy2uKfrn9lUbFTDelhSm+0bBu 7BkhCFBbLwnnQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org, sdf@fomichev.me, Jakub Kicinski Subject: [PATCH net-next 09/11] net: designate XSK pool pointers in queues as "ops protected" Date: Wed, 12 Mar 2025 23:35:05 +0100 Message-ID: <20250312223507.805719-10-kuba@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250312223507.805719-1-kuba@kernel.org> References: <20250312223507.805719-1-kuba@kernel.org> 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 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(). Signed-off-by: Jakub Kicinski --- include/linux/netdevice.h | 1 + include/net/netdev_rx_queue.h | 6 +++--- net/xdp/xsk_buff_pool.c | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 0fc79ae60ff5..7d802ef1c864 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 14716ad3d7bc..60b3adb7b2d7 100644 --- a/net/xdp/xsk_buff_pool.c +++ b/net/xdp/xsk_buff_pool.c @@ -279,9 +279,12 @@ 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(); + netdev_lock_ops(netdev); xp_clear_dev(pool); + netdev_unlock_ops(netdev); rtnl_unlock(); if (pool->fq) { From patchwork Wed Mar 12 22:35:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 14014016 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E906E1F03DE for ; Wed, 12 Mar 2025 22:35:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818943; cv=none; b=DiNu+1vrQziIGAceTGPLw0EzjWLAywgR7QfPm4XIFtP9XCL8jOFO0vSC+LW4sN2w1ni2gIlHuFlS9D1kSLZT5UtSd5yhHrp7ZlyyZtMdx2S7PUbcwQ1weevSdLeFAJD6HJh9LHOmG0joYqTMqFE+eO7jW8jPNcLbvazJ16FQ40w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818943; c=relaxed/simple; bh=7fX/ZtP8jrUk1NoUgi1jNBTjW7S9t+rPPz3YeCB9bHc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RuDb43yH8TtWfCHY5LDP++yFw9DRGs2jhKfVxJx+fMImh3uTgtXuIl/C8xzpfgP8IBlIaEVhYmM/LOzdn1katCcCAOOWbGRiAogUCyMYLhDK9M8TyVYoCSJcv4FuZhlZOoA7iwrR/OPXHbecPVlCRI7clQkJFyySw6y2gtt86gQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GZ+XI4UW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GZ+XI4UW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C38C2C4CEEE; Wed, 12 Mar 2025 22:35:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741818942; bh=7fX/ZtP8jrUk1NoUgi1jNBTjW7S9t+rPPz3YeCB9bHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GZ+XI4UWZ66MuBIlSYgAQrcyNAxhJlYW+QV4PiDJPPbGPbyfzPzTyI2i5c/4zw+YJ g/HUu/YGgOm4QsDikt/qYgUwuYXeKGJvlHxgGp+sPDf2XcAQp20a8gKaLis/qoQXSU TYAjyOxyXUYFHZeJOZZKIViurgxYUpA0YMAlwGcvqPSxjguI/wBL+DQJz74Es8Qap7 DA+ikdlNq5aO9It1rGkrpH17lYhHGjUFGMlpowxNcjwdn47Zr7D9wl2dxjE54TQMav aXKCUU1RUwa8S9cccVx37fmXgzlH8QW4xD++EuwWDkaTz/4RY4USjNQB/i/nf2pOqq 8gF8fvQfbP03A== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org, sdf@fomichev.me, Jakub Kicinski Subject: [PATCH net-next 10/11] netdev: add "ops compat locking" helpers Date: Wed, 12 Mar 2025 23:35:06 +0100 Message-ID: <20250312223507.805719-11-kuba@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250312223507.805719-1-kuba@kernel.org> References: <20250312223507.805719-1-kuba@kernel.org> 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 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. Signed-off-by: Jakub Kicinski --- include/net/netdev_lock.h | 16 +++++++++++++ net/core/dev.h | 15 ++++++++++++ net/core/dev.c | 49 +++++++++++++++++++++++++++++++++++++++ 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.h b/net/core/dev.h index 0ddd3631acb0..f1e9f51f36d4 100644 --- a/net/core/dev.h +++ b/net/core/dev.h @@ -42,6 +42,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 diff --git a/net/core/dev.c b/net/core/dev.c index 8296b4c159fe..1477bbae0ee0 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1037,6 +1037,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 @@ -1059,6 +1071,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); +} + /** * netdev_get_by_name_lock() - find a device by its name * @net: the applicable net namespace @@ -1106,6 +1130,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) From patchwork Wed Mar 12 22:35:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 14014017 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7BDD1EF08D for ; Wed, 12 Mar 2025 22:35:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818945; cv=none; b=aGdFmMCztnvc/wApx6sX4eRx2fqcleF8hbZdrM1mjqYp7Hrvm6REc1+P0+EicI99iihrrSYV947ZcQs3PKrAMUmyeCFfgChSO/qtqW6wvKqirfaitmsaXTvYwe4rm3dCLI8HJDx3sK6IFtdLtUT4a7eY+aG0N+TI+ORQdCshWEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741818945; c=relaxed/simple; bh=2S2WwdPjGT5zN3uPH471LFBIxVSY2S0i+aOU5q/QtTA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eDsaGbvqbNBqWEmTwvLvJHWS7dVmYT5V5AJ6dQkGz0JBT03mkSwLmgPiNRcNR1j3RJq0wsh9D6uJXpYrSAantzwlZaae8jgiifGaZjDXNt/VJ8YTC/BgZ3Q/7dYvqifCSyDxl4Qq8mKrGrqnd1XzKlCHp/lXa6rX1yYXR7ZzTgI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FgU5c496; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FgU5c496" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A71AC4CEDD; Wed, 12 Mar 2025 22:35:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741818945; bh=2S2WwdPjGT5zN3uPH471LFBIxVSY2S0i+aOU5q/QtTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FgU5c496ttFBT3N167Vayygu+h/p3HkTFEeaDoAX9JcQpq344bZ+U7QsS8ADNgdxU vtkadDo5g+Zl4X9tJsZneCpohkELZnrqXjg3MK7bogd6LrXE0lEvZfCcUMba1oiTjU H7Km1XKGmTbxV8zaWuHBxYE9rlPt74CtRTpaIQI4+evaCmQOt55d18c9RY49FJQMv4 081gcpqgkpLso0MPmrmeqF6+kv3Fc+iwWcXz/s4QPLrv+I2RzGsiWbLak+1d+vW03o pSaVgo0L9gg3qTOuLnCumchS8OpSeJBjgnU0qW88RYPPruY0oim8iJp83B4G5/gHQa fRnVig6qTKlpA== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org, sdf@fomichev.me, Jakub Kicinski Subject: [PATCH net-next 11/11] netdev: don't hold rtnl_lock over nl queue info get when possible Date: Wed, 12 Mar 2025 23:35:07 +0100 Message-ID: <20250312223507.805719-12-kuba@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250312223507.805719-1-kuba@kernel.org> References: <20250312223507.805719-1-kuba@kernel.org> 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 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. Signed-off-by: Jakub Kicinski --- 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; }