From nobody Tue Dec 2 00:44:39 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 29D4832AADD; Tue, 25 Nov 2025 17:36:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764092207; cv=none; b=m8cRUiLmxFiBePp4M9EpRlHNKq/QNsiydUIfSypNXF5YtbtsJujogngCAv1C4sKeLNxdeGbTzhhrh9XLauAHvcinax8S7DnsHiPUSl0zVRsm2yjA8lEi2sWhj6rmmjK3GqJCG+NenslyfJPoCc8t4Vhk4NX3/BLyoptxLVaZvMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764092207; c=relaxed/simple; bh=hiQCTOP4/S5xPr0kEs71P8ohuU8clI3OaBh/kWSlaPc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V0ZqLADu49X5GHPPUFlOeSpJ5gJ3o9UKnIyfq5pzP2RlIggxLlpSAJl4XSr68l7Jb6+vjotFy2IoNaRfIFuLrkNe0SVEi1bWyjVc/BavrqMZ4cBrnLTTTY2NbNMEJymEZqnNSY5PNs4tqBJ6Ryvntgr99qp9cdmFmOntEA65w6U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=dHegYmI9; arc=none smtp.client-ip=192.198.163.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dHegYmI9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1764092206; x=1795628206; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hiQCTOP4/S5xPr0kEs71P8ohuU8clI3OaBh/kWSlaPc=; b=dHegYmI9Z4Uv80w3IuIMGf0nCBCLHFHWTDkiPNNzwV0sZNbTcBi7TVwV mLdGapSbE/vG603Yzpn7Pwyj9FWVniwe482L2oycPXx0ABvO3wLLu0Kbj s9xL6DpEW9u7Cdzn0wZSTR+OSkJXXAeby/RQJdfMceTGq1XBf67kNuaJR z+vavBdtIbi//qfOWGx62AzUHmPkm93FmtRmvnXKBZqc26Dn38541U9a3 R/Eo07M8yaUzU5AkT6fMVi9uAUBcZH1y8kISXtWqoReHCDNUiE07wKTQi 0+vTBVTT6ukxlfAUYf0j4Aop9GJcZqdflbBI2uyvLFJjzGoUJaZFc5lyx A==; X-CSE-ConnectionGUID: nWdpxwfXSrSZ/sMIgaXkYw== X-CSE-MsgGUID: DxiZoV7vQ9CRa6YGzSmRFA== X-IronPort-AV: E=McAfee;i="6800,10657,11624"; a="69979903" X-IronPort-AV: E=Sophos;i="6.20,226,1758610800"; d="scan'208";a="69979903" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2025 09:36:44 -0800 X-CSE-ConnectionGUID: 83E69N6LRfueqL1R3ySKew== X-CSE-MsgGUID: bf3w1m7bTKqmPJ2OYgTqdA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,226,1758610800"; d="scan'208";a="216040404" Received: from newjersey.igk.intel.com ([10.102.20.203]) by fmviesa002.fm.intel.com with ESMTP; 25 Nov 2025 09:36:41 -0800 From: Alexander Lobakin To: intel-wired-lan@lists.osuosl.org Cc: Alexander Lobakin , Tony Nguyen , Przemek Kitszel , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jacob Keller , Aleksandr Loktionov , nxne.cnse.osdt.itp.upstreaming@intel.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH iwl-next 3/5] ice: migrate to netdev ops lock Date: Tue, 25 Nov 2025 18:36:01 +0100 Message-ID: <20251125173603.3834486-4-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251125173603.3834486-1-aleksander.lobakin@intel.com> References: <20251125173603.3834486-1-aleksander.lobakin@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Queue management ops unconditionally enable netdev locking. The same lock is taken by default by several NAPI configuration functions, such as napi_enable() and netif_napi_set_irq(). Request ops locking in advance and make sure we use the _locked counterparts of those functions to avoid deadlocks, taking the lock manually where needed (suspend/resume, queue rebuild and resets). Reviewed-by: Jacob Keller Reviewed-by: Aleksandr Loktionov Signed-off-by: Alexander Lobakin --- drivers/net/ethernet/intel/ice/ice_lib.h | 6 ++- drivers/net/ethernet/intel/ice/ice_lib.c | 56 +++++++++++++++++---- drivers/net/ethernet/intel/ice/ice_main.c | 49 ++++++++++-------- drivers/net/ethernet/intel/ice/ice_sf_eth.c | 1 + drivers/net/ethernet/intel/ice/ice_xsk.c | 4 +- 5 files changed, 82 insertions(+), 34 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_lib.h b/drivers/net/etherne= t/intel/ice/ice_lib.h index 2cb1eb98b9da..d9c94c06c657 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.h +++ b/drivers/net/ethernet/intel/ice/ice_lib.h @@ -53,9 +53,11 @@ struct ice_vsi * ice_vsi_setup(struct ice_pf *pf, struct ice_vsi_cfg_params *params); =20 void ice_vsi_set_napi_queues(struct ice_vsi *vsi); -void ice_napi_add(struct ice_vsi *vsi); - +void ice_vsi_set_napi_queues_locked(struct ice_vsi *vsi); void ice_vsi_clear_napi_queues(struct ice_vsi *vsi); +void ice_vsi_clear_napi_queues_locked(struct ice_vsi *vsi); + +void ice_napi_add(struct ice_vsi *vsi); =20 int ice_vsi_release(struct ice_vsi *vsi); =20 diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/etherne= t/intel/ice/ice_lib.c index 15621707fbf8..8f79dd022e91 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -2695,7 +2695,7 @@ void ice_vsi_close(struct ice_vsi *vsi) if (!test_and_set_bit(ICE_VSI_DOWN, vsi->state)) ice_down(vsi); =20 - ice_vsi_clear_napi_queues(vsi); + ice_vsi_clear_napi_queues_locked(vsi); ice_vsi_free_irq(vsi); ice_vsi_free_tx_rings(vsi); ice_vsi_free_rx_rings(vsi); @@ -2764,12 +2764,13 @@ void ice_dis_vsi(struct ice_vsi *vsi, bool locked) } =20 /** - * ice_vsi_set_napi_queues - associate netdev queues with napi + * ice_vsi_set_napi_queues_locked - associate netdev queues with napi * @vsi: VSI pointer * * Associate queue[s] with napi for all vectors. + * Must be called only with the netdev_lock taken. */ -void ice_vsi_set_napi_queues(struct ice_vsi *vsi) +void ice_vsi_set_napi_queues_locked(struct ice_vsi *vsi) { struct net_device *netdev =3D vsi->netdev; int q_idx, v_idx; @@ -2777,7 +2778,6 @@ void ice_vsi_set_napi_queues(struct ice_vsi *vsi) if (!netdev) return; =20 - ASSERT_RTNL(); ice_for_each_rxq(vsi, q_idx) netif_queue_set_napi(netdev, q_idx, NETDEV_QUEUE_TYPE_RX, &vsi->rx_rings[q_idx]->q_vector->napi); @@ -2789,17 +2789,37 @@ void ice_vsi_set_napi_queues(struct ice_vsi *vsi) ice_for_each_q_vector(vsi, v_idx) { struct ice_q_vector *q_vector =3D vsi->q_vectors[v_idx]; =20 - netif_napi_set_irq(&q_vector->napi, q_vector->irq.virq); + netif_napi_set_irq_locked(&q_vector->napi, q_vector->irq.virq); } } =20 /** - * ice_vsi_clear_napi_queues - dissociate netdev queues from napi + * ice_vsi_set_napi_queues - associate VSI queues with NAPIs * @vsi: VSI pointer * + * Version of ice_vsi_set_napi_queues_locked() that takes the netdev_lock, + * to use it outside of the net_device_ops context. + */ +void ice_vsi_set_napi_queues(struct ice_vsi *vsi) +{ + struct net_device *netdev =3D vsi->netdev; + + if (!netdev) + return; + + netdev_lock(netdev); + ice_vsi_set_napi_queues_locked(vsi); + netdev_unlock(netdev); +} + +/** + * ice_vsi_clear_napi_queues_locked - dissociate netdev queues from napi + * @vsi: VSI to process + * * Clear the association between all VSI queues queue[s] and napi. + * Must be called only with the netdev_lock taken. */ -void ice_vsi_clear_napi_queues(struct ice_vsi *vsi) +void ice_vsi_clear_napi_queues_locked(struct ice_vsi *vsi) { struct net_device *netdev =3D vsi->netdev; int q_idx, v_idx; @@ -2807,12 +2827,11 @@ void ice_vsi_clear_napi_queues(struct ice_vsi *vsi) if (!netdev) return; =20 - ASSERT_RTNL(); /* Clear the NAPI's interrupt number */ ice_for_each_q_vector(vsi, v_idx) { struct ice_q_vector *q_vector =3D vsi->q_vectors[v_idx]; =20 - netif_napi_set_irq(&q_vector->napi, -1); + netif_napi_set_irq_locked(&q_vector->napi, -1); } =20 ice_for_each_txq(vsi, q_idx) @@ -2822,6 +2841,25 @@ void ice_vsi_clear_napi_queues(struct ice_vsi *vsi) netif_queue_set_napi(netdev, q_idx, NETDEV_QUEUE_TYPE_RX, NULL); } =20 +/** + * ice_vsi_clear_napi_queues - dissociate VSI queues from NAPIs + * @vsi: VSI to process + * + * Version of ice_vsi_clear_napi_queues_locked() that takes the netdev loc= k, + * to use it outside of the net_device_ops context. + */ +void ice_vsi_clear_napi_queues(struct ice_vsi *vsi) +{ + struct net_device *netdev =3D vsi->netdev; + + if (!netdev) + return; + + netdev_lock(netdev); + ice_vsi_clear_napi_queues_locked(vsi); + netdev_unlock(netdev); +} + /** * ice_napi_add - register NAPI handler for the VSI * @vsi: VSI for which NAPI handler is to be registered diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethern= et/intel/ice/ice_main.c index 2533876f1a2f..c0432182b482 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -3523,6 +3523,7 @@ static void ice_set_ops(struct ice_vsi *vsi) } =20 netdev->netdev_ops =3D &ice_netdev_ops; + netdev->request_ops_lock =3D true; netdev->udp_tunnel_nic_info =3D &pf->hw.udp_tunnel_nic; netdev->xdp_metadata_ops =3D &ice_xdp_md_ops; ice_set_ethtool_ops(netdev); @@ -5533,16 +5534,17 @@ static int ice_reinit_interrupt_scheme(struct ice_p= f *pf) =20 /* Remap vectors and rings, after successful re-init interrupts */ ice_for_each_vsi(pf, v) { - if (!pf->vsi[v]) + struct ice_vsi *vsi =3D pf->vsi[v]; + + if (!vsi) continue; =20 - ret =3D ice_vsi_alloc_q_vectors(pf->vsi[v]); + ret =3D ice_vsi_alloc_q_vectors(vsi); if (ret) goto err_reinit; - ice_vsi_map_rings_to_vectors(pf->vsi[v]); - rtnl_lock(); - ice_vsi_set_napi_queues(pf->vsi[v]); - rtnl_unlock(); + + ice_vsi_map_rings_to_vectors(vsi); + ice_vsi_set_napi_queues(vsi); } =20 ret =3D ice_req_irq_msix_misc(pf); @@ -5555,13 +5557,15 @@ static int ice_reinit_interrupt_scheme(struct ice_p= f *pf) return 0; =20 err_reinit: - while (v--) - if (pf->vsi[v]) { - rtnl_lock(); - ice_vsi_clear_napi_queues(pf->vsi[v]); - rtnl_unlock(); - ice_vsi_free_q_vectors(pf->vsi[v]); - } + while (v--) { + struct ice_vsi *vsi =3D pf->vsi[v]; + + if (!vsi) + continue; + + ice_vsi_clear_napi_queues(vsi); + ice_vsi_free_q_vectors(vsi); + } =20 return ret; } @@ -5623,14 +5627,17 @@ static int ice_suspend(struct device *dev) * to CPU0. */ ice_free_irq_msix_misc(pf); + ice_for_each_vsi(pf, v) { - if (!pf->vsi[v]) + struct ice_vsi *vsi =3D pf->vsi[v]; + + if (!vsi) continue; - rtnl_lock(); - ice_vsi_clear_napi_queues(pf->vsi[v]); - rtnl_unlock(); - ice_vsi_free_q_vectors(pf->vsi[v]); + + ice_vsi_clear_napi_queues(vsi); + ice_vsi_free_q_vectors(vsi); } + ice_clear_interrupt_scheme(pf); =20 pci_save_state(pdev); @@ -6760,7 +6767,7 @@ static void ice_napi_enable_all(struct ice_vsi *vsi) ice_init_moderation(q_vector); =20 if (q_vector->rx.rx_ring || q_vector->tx.tx_ring) - napi_enable(&q_vector->napi); + napi_enable_locked(&q_vector->napi); } } =20 @@ -7204,7 +7211,7 @@ static void ice_napi_disable_all(struct ice_vsi *vsi) struct ice_q_vector *q_vector =3D vsi->q_vectors[q_idx]; =20 if (q_vector->rx.rx_ring || q_vector->tx.tx_ring) - napi_disable(&q_vector->napi); + napi_disable_locked(&q_vector->napi); =20 cancel_work_sync(&q_vector->tx.dim.work); cancel_work_sync(&q_vector->rx.dim.work); @@ -7504,7 +7511,7 @@ int ice_vsi_open(struct ice_vsi *vsi) if (err) goto err_set_qs; =20 - ice_vsi_set_napi_queues(vsi); + ice_vsi_set_napi_queues_locked(vsi); } =20 err =3D ice_up_complete(vsi); diff --git a/drivers/net/ethernet/intel/ice/ice_sf_eth.c b/drivers/net/ethe= rnet/intel/ice/ice_sf_eth.c index 1a2c94375ca7..2c3db1b03055 100644 --- a/drivers/net/ethernet/intel/ice/ice_sf_eth.c +++ b/drivers/net/ethernet/intel/ice/ice_sf_eth.c @@ -58,6 +58,7 @@ static int ice_sf_cfg_netdev(struct ice_dynamic_port *dyn= _port, eth_hw_addr_set(netdev, dyn_port->hw_addr); ether_addr_copy(netdev->perm_addr, dyn_port->hw_addr); netdev->netdev_ops =3D &ice_sf_netdev_ops; + netdev->request_ops_lock =3D true; SET_NETDEV_DEVLINK_PORT(netdev, devlink_port); =20 err =3D register_netdev(netdev); diff --git a/drivers/net/ethernet/intel/ice/ice_xsk.c b/drivers/net/etherne= t/intel/ice/ice_xsk.c index 989ff1fd9110..4168cd58d4d8 100644 --- a/drivers/net/ethernet/intel/ice/ice_xsk.c +++ b/drivers/net/ethernet/intel/ice/ice_xsk.c @@ -33,9 +33,9 @@ ice_qvec_toggle_napi(struct ice_vsi *vsi, struct ice_q_ve= ctor *q_vector, return; =20 if (enable) - napi_enable(&q_vector->napi); + napi_enable_locked(&q_vector->napi); else - napi_disable(&q_vector->napi); + napi_disable_locked(&q_vector->napi); } =20 /** --=20 2.51.1