From patchwork Mon Jun 10 15:37:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Larysa Zaremba X-Patchwork-Id: 13692243 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 2CBEA1422DF; Mon, 10 Jun 2024 15:45:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718034307; cv=none; b=CuJtSMFfbTkZvz8oHA93eqZHxtL6+pyxwFUd4IJ+Cb0j/Vn+pqJdXYe4XTBT+qVCtw7FwK2nXUimaSl5bHY8x396Fn84xCx/2CQcZ0TtkdTHaPBjtcZVJLRhJeN0yeOAkDtawG0je/c8LEaXcNSxkIz2LGuF0JnlLCbFz1dUlYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718034307; c=relaxed/simple; bh=Y7N7MUsfJCWKfw1oZc9U8+5XiTJyZC934D1IerD9Trs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C4BHX7vBDDGPeyEihXhz6ger5CP+MK03uFqp/lAxh9mndKo+9efWNv6RaSVhKzq9XeqOQUAehkpWooUZoVpCaZ0aV3HWGO8CA/Box9i153vFlFA2+ZgvozEnKAtVr02+Gbv5EyXHJG3vJ97D/VxF/Urc7rbwa7tcG9FZuA1V74U= 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=I38wnLkY; arc=none smtp.client-ip=198.175.65.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="I38wnLkY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718034305; x=1749570305; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Y7N7MUsfJCWKfw1oZc9U8+5XiTJyZC934D1IerD9Trs=; b=I38wnLkYj0m9b/zi4jPw8WFQCEBh7OO/Q1/Sft9g3qYm+ky8fZcKKSP8 m4r5f81E3/jFwJulZhnSn0+VLL3bnFcpLVrkinEeuBl1ezzgQJuj9FNAV vk0bJBEPxYLcpl+zcfxvhmD5BavjiVpUVDa5h7QO6wKOmYKwmprOjRbM+ +0uHKulNIyAlGw3Bv1KhO0VSk4hda6uOJ/ratoG6TGwaX5tW0iuWdLupp oEk7BKJSNeYFCudJs+1fFdhbYXVoSOmA6MVsSzeX2X7/DaCx+fegxNkUI r1Agfciy4GFtL+X7gLgd0w72Ld95jg0exnxli6wussYWDm/oaXAPU+wP8 w==; X-CSE-ConnectionGUID: NicJpdcCRZWaZFrEFkXExg== X-CSE-MsgGUID: VK17jSdEQDm9VDr4xMO1NA== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="26119844" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="26119844" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:45:04 -0700 X-CSE-ConnectionGUID: X0M0ga2rRSGJ8vbzfj7bqQ== X-CSE-MsgGUID: RU2UScXASu2GRT/Ob6yPIw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="43679761" Received: from irvmail002.ir.intel.com ([10.43.11.120]) by fmviesa004.fm.intel.com with ESMTP; 10 Jun 2024 08:44:59 -0700 Received: from lincoln.igk.intel.com (lincoln.igk.intel.com [10.102.21.235]) by irvmail002.ir.intel.com (Postfix) with ESMTP id CDE2D312D5; Mon, 10 Jun 2024 16:44:48 +0100 (IST) From: Larysa Zaremba To: intel-wired-lan@lists.osuosl.org Cc: Larysa Zaremba , Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Maciej Fijalkowski , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, magnus.karlsson@intel.com, Michal Kubiak , Igor Bagnucki Subject: [PATCH iwl-net 1/3] ice: synchronize XDP setup with reset Date: Mon, 10 Jun 2024 17:37:13 +0200 Message-ID: <20240610153716.31493-2-larysa.zaremba@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240610153716.31493-1-larysa.zaremba@intel.com> References: <20240610153716.31493-1-larysa.zaremba@intel.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org XDP setup and PF reset code access the same resources in the following sections: * ice_vsi_close() in ice_prepare_for_reset() - already rtnl-locked * ice_vsi_rebuild() for the PF VSI - not protected With an unfortunate timing, such accesses can result in a crash such as the one below: [ +1.999878] ice 0000:b1:00.0: Registered XDP mem model MEM_TYPE_XSK_BUFF_POOL on Rx ring 14 [ +2.002992] ice 0000:b1:00.0: Registered XDP mem model MEM_TYPE_XSK_BUFF_POOL on Rx ring 18 [Mar15 18:17] ice 0000:b1:00.0 ens801f0np0: NETDEV WATCHDOG: CPU: 38: transmit queue 14 timed out 80692736 ms [ +0.000093] ice 0000:b1:00.0 ens801f0np0: tx_timeout: VSI_num: 6, Q 14, NTC: 0x0, HW_HEAD: 0x0, NTU: 0x0, INT: 0x4000001 [ +0.000012] ice 0000:b1:00.0 ens801f0np0: tx_timeout recovery level 1, txqueue 14 [ +0.394718] ice 0000:b1:00.0: PTP reset successful [ +0.006184] BUG: kernel NULL pointer dereference, address: 0000000000000098 [ +0.000045] #PF: supervisor read access in kernel mode [ +0.000023] #PF: error_code(0x0000) - not-present page [ +0.000023] PGD 0 P4D 0 [ +0.000018] Oops: 0000 [#1] PREEMPT SMP NOPTI [ +0.000023] CPU: 38 PID: 7540 Comm: kworker/38:1 Not tainted 6.8.0-rc7 #1 [ +0.000031] Hardware name: Intel Corporation S2600WFT/S2600WFT, BIOS SE5C620.86B.02.01.0014.082620210524 08/26/2021 [ +0.000036] Workqueue: ice ice_service_task [ice] [ +0.000183] RIP: 0010:ice_clean_tx_ring+0xa/0xd0 [ice] [...] [ +0.000013] Call Trace: [ +0.000016] [ +0.000014] ? __die+0x1f/0x70 [ +0.000029] ? page_fault_oops+0x171/0x4f0 [ +0.000029] ? schedule+0x3b/0xd0 [ +0.000027] ? exc_page_fault+0x7b/0x180 [ +0.000022] ? asm_exc_page_fault+0x22/0x30 [ +0.000031] ? ice_clean_tx_ring+0xa/0xd0 [ice] [ +0.000194] ice_free_tx_ring+0xe/0x60 [ice] [ +0.000186] ice_destroy_xdp_rings+0x157/0x310 [ice] [ +0.000151] ice_vsi_decfg+0x53/0xe0 [ice] [ +0.000180] ice_vsi_rebuild+0x239/0x540 [ice] [ +0.000186] ice_vsi_rebuild_by_type+0x76/0x180 [ice] [ +0.000145] ice_rebuild+0x18c/0x840 [ice] [ +0.000145] ? delay_tsc+0x4a/0xc0 [ +0.000022] ? delay_tsc+0x92/0xc0 [ +0.000020] ice_do_reset+0x140/0x180 [ice] [ +0.000886] ice_service_task+0x404/0x1030 [ice] [ +0.000824] process_one_work+0x171/0x340 [ +0.000685] worker_thread+0x277/0x3a0 [ +0.000675] ? preempt_count_add+0x6a/0xa0 [ +0.000677] ? _raw_spin_lock_irqsave+0x23/0x50 [ +0.000679] ? __pfx_worker_thread+0x10/0x10 [ +0.000653] kthread+0xf0/0x120 [ +0.000635] ? __pfx_kthread+0x10/0x10 [ +0.000616] ret_from_fork+0x2d/0x50 [ +0.000612] ? __pfx_kthread+0x10/0x10 [ +0.000604] ret_from_fork_asm+0x1b/0x30 [ +0.000604] The previous way of handling this through returning -EBUSY is not viable, particularly when destroying AF_XDP socket, because the kernel proceeds with removal anyway. There is plenty of code between those calls and there is no need to create a large critical section that covers them both, same as there is no need to protect ice_vsi_rebuild() with rtnl_lock(). Leaving an unprotexted section in between would result in a state, when the VSI is closed, but not yet rebuild, such situation can be handled pretty easily. Lock ice_vsi_rebuild() with ICE_CFG_BUSY flag. Particularly, to prevent system crash, when tx_timeout and .ndo_bpf() happen at the same time. Also, handle the state between critical sections by skipping XDP ring configuration. Fixes: efc2214b6047 ("ice: Add support for XDP") Reviewed-by: Igor Bagnucki Signed-off-by: Larysa Zaremba --- drivers/net/ethernet/intel/ice/ice_lib.c | 5 +++- drivers/net/ethernet/intel/ice/ice_main.c | 36 +++++++++++++++++++---- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index 7629b0190578..4774bcc4d5a8 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -2426,7 +2426,10 @@ void ice_vsi_decfg(struct ice_vsi *vsi) dev_err(ice_pf_to_dev(pf), "Failed to remove RDMA scheduler config for VSI %u, err %d\n", vsi->vsi_num, err); - if (ice_is_xdp_ena_vsi(vsi)) + /* xdp_rings can be absent, if program was attached amid reset, + * VSI rebuild is supposed to create them later + */ + if (ice_is_xdp_ena_vsi(vsi) && vsi->xdp_rings) /* return value check can be skipped here, it always returns * 0 if reset is in progress */ diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index 15a6805ac2a1..dc60d816a345 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -2986,6 +2986,20 @@ static int ice_max_xdp_frame_size(struct ice_vsi *vsi) return ICE_RXBUF_3072; } +/** + * ice_rebuild_pending - ice_vsi_rebuild will be performed, when locks are released + * @vsi: VSI to setup XDP for + * + * ice_vsi_close() in the reset path is called under rtnl_lock(), + * so it happens strictly before or after .ndo_bpf(). + * In case it has happened before, we do not have anything attached to rings + */ +static bool ice_rebuild_pending(struct ice_vsi *vsi) +{ + return ice_is_reset_in_progress(vsi->back->state) && + !vsi->rx_rings[0]->desc; +} + /** * ice_xdp_setup_prog - Add or remove XDP eBPF program * @vsi: VSI to setup XDP for @@ -3009,7 +3023,7 @@ ice_xdp_setup_prog(struct ice_vsi *vsi, struct bpf_prog *prog, } /* hot swap progs and avoid toggling link */ - if (ice_is_xdp_ena_vsi(vsi) == !!prog) { + if (ice_is_xdp_ena_vsi(vsi) == !!prog || ice_rebuild_pending(vsi)) { ice_vsi_assign_bpf_prog(vsi, prog); return 0; } @@ -3081,21 +3095,30 @@ static int ice_xdp(struct net_device *dev, struct netdev_bpf *xdp) { struct ice_netdev_priv *np = netdev_priv(dev); struct ice_vsi *vsi = np->vsi; + struct ice_pf *pf = vsi->back; + int ret; if (vsi->type != ICE_VSI_PF) { NL_SET_ERR_MSG_MOD(xdp->extack, "XDP can be loaded only on PF VSI"); return -EINVAL; } + while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) + usleep_range(1000, 2000); + switch (xdp->command) { case XDP_SETUP_PROG: - return ice_xdp_setup_prog(vsi, xdp->prog, xdp->extack); + ret = ice_xdp_setup_prog(vsi, xdp->prog, xdp->extack); + break; case XDP_SETUP_XSK_POOL: - return ice_xsk_pool_setup(vsi, xdp->xsk.pool, - xdp->xsk.queue_id); + ret = ice_xsk_pool_setup(vsi, xdp->xsk.pool, xdp->xsk.queue_id); + break; default: - return -EINVAL; + ret = -EINVAL; } + + clear_bit(ICE_CFG_BUSY, pf->state); + return ret; } /** @@ -7672,7 +7695,10 @@ static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type) ice_gnss_init(pf); /* rebuild PF VSI */ + while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) + usleep_range(1000, 2000); err = ice_vsi_rebuild_by_type(pf, ICE_VSI_PF); + clear_bit(ICE_CFG_BUSY, pf->state); if (err) { dev_err(dev, "PF VSI rebuild failed: %d\n", err); goto err_vsi_rebuild; From patchwork Mon Jun 10 15:37:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Larysa Zaremba X-Patchwork-Id: 13692244 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 822D11422D5; Mon, 10 Jun 2024 15:45:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718034312; cv=none; b=CAzh0576/cTK/XrqX82InxtXzuH/Pvo2XMOMx6kMAd0W83cmI5eE4YGMH8fveERZgBHb35MAqPySAdEAUV+j/BkToHW1YG8esOJ0Vw+ZlTEf6eA1oX5wwCs2h0EozyfamkT/jM5F726QOddpHntCvyOwdIeGWggqd/tifM241tg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718034312; c=relaxed/simple; bh=1CJQhgdeQheVVIX/aqzTWo34167G3W6siXPTBXQpy9A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GSz1Z8NIJJAyZtuyHRTrCmk+VI2u1gSqyUfLVEwiKbfP/qkdSQNQJJIa4oC/tZWM9kxGn+kj/xsmlJnhFd9yKEIihwg2Fdvim5zWDtBBITZxbOCzXp8iAl8hTPeQv6HXcRaVUZ6PAv3fXnB1lzNkcxXfM/tOTByMn+1F6M5hyFM= 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=VKAB8jIh; arc=none smtp.client-ip=198.175.65.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="VKAB8jIh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718034310; x=1749570310; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1CJQhgdeQheVVIX/aqzTWo34167G3W6siXPTBXQpy9A=; b=VKAB8jIh8ycwOMgVFjKzHRRV7WPkLYAXdeFIlGsCd0TTi+Sb3UbKQbF3 tGFku7G+kVwTVjrP+jI74P3Z4ajiSzyLiHGuWEnDg507JsFF3bpAo144h gy0hSStBeq30jEKfzgQYet0XCrRC55sn9uwLPshrc09plBpcPRFzCr6jQ izXXsRmTEcvsI2gSEgLTerwwuPLmaODge17rzvUEH2s1D7CCdnQpK17so cTQU10zvatgwklqKo2RlLuuU4rxmc65hdZy8kPr6v/wQLlq2JXU3oAAPh 5TEy224sTvfIFXO7TWTF5a9O6GwO1phk/SiyEC4yn1NaGXbTB86RIeNJB Q==; X-CSE-ConnectionGUID: oRuzBhYmTBaCxQXchtgREQ== X-CSE-MsgGUID: fNFSYBdHS5yzjjTJ1RZH9w== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="26119868" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="26119868" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:45:10 -0700 X-CSE-ConnectionGUID: 6R3brtywTb2VXCSyRA/AmA== X-CSE-MsgGUID: JvFWDt5rTDmrEJjMGy02Uw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="43679776" Received: from irvmail002.ir.intel.com ([10.43.11.120]) by fmviesa004.fm.intel.com with ESMTP; 10 Jun 2024 08:45:05 -0700 Received: from lincoln.igk.intel.com (lincoln.igk.intel.com [10.102.21.235]) by irvmail002.ir.intel.com (Postfix) with ESMTP id BB4B1312D7; Mon, 10 Jun 2024 16:44:50 +0100 (IST) From: Larysa Zaremba To: intel-wired-lan@lists.osuosl.org Cc: Larysa Zaremba , Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Maciej Fijalkowski , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, magnus.karlsson@intel.com, Michal Kubiak , Igor Bagnucki Subject: [PATCH iwl-net 2/3] ice: fix locking in ice_xsk_pool_setup() Date: Mon, 10 Jun 2024 17:37:14 +0200 Message-ID: <20240610153716.31493-3-larysa.zaremba@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240610153716.31493-1-larysa.zaremba@intel.com> References: <20240610153716.31493-1-larysa.zaremba@intel.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org With ICE_CFG_BUSY PF state flag locking used in ice_xdp(), there is no need to lock with VSI state inside ice_xsk_pool_setup(). For robust synchronization the state between reset preparation and PF VSI rebuild has to be handled, in the same way as in ice_xdp_setup_prog(). Remove locking logic from ice_qp_dis() and ice_qp_ena() and skip those functions, if rebuild is pending. Fixes: 2d4238f55697 ("ice: Add support for AF_XDP") Reviewed-by: Igor Bagnucki Signed-off-by: Larysa Zaremba --- drivers/net/ethernet/intel/ice/ice.h | 1 + drivers/net/ethernet/intel/ice/ice_main.c | 2 +- drivers/net/ethernet/intel/ice/ice_xsk.c | 12 ++---------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice.h b/drivers/net/ethernet/intel/ice/ice.h index 701a61d791dd..76590cfcaf68 100644 --- a/drivers/net/ethernet/intel/ice/ice.h +++ b/drivers/net/ethernet/intel/ice/ice.h @@ -941,6 +941,7 @@ int ice_prepare_xdp_rings(struct ice_vsi *vsi, struct bpf_prog *prog, enum ice_xdp_cfg cfg_type); int ice_destroy_xdp_rings(struct ice_vsi *vsi, enum ice_xdp_cfg cfg_type); void ice_map_xdp_rings(struct ice_vsi *vsi); +bool ice_rebuild_pending(struct ice_vsi *vsi); int ice_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames, u32 flags); diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index dc60d816a345..cd8be3c3b956 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -2994,7 +2994,7 @@ static int ice_max_xdp_frame_size(struct ice_vsi *vsi) * so it happens strictly before or after .ndo_bpf(). * In case it has happened before, we do not have anything attached to rings */ -static bool ice_rebuild_pending(struct ice_vsi *vsi) +bool ice_rebuild_pending(struct ice_vsi *vsi) { return ice_is_reset_in_progress(vsi->back->state) && !vsi->rx_rings[0]->desc; diff --git a/drivers/net/ethernet/intel/ice/ice_xsk.c b/drivers/net/ethernet/intel/ice/ice_xsk.c index 4e2020ab0825..6c95bebd7777 100644 --- a/drivers/net/ethernet/intel/ice/ice_xsk.c +++ b/drivers/net/ethernet/intel/ice/ice_xsk.c @@ -163,7 +163,6 @@ static int ice_qp_dis(struct ice_vsi *vsi, u16 q_idx) struct ice_tx_ring *xdp_ring; struct ice_tx_ring *tx_ring; struct ice_rx_ring *rx_ring; - int timeout = 50; int fail = 0; int err; @@ -175,13 +174,6 @@ static int ice_qp_dis(struct ice_vsi *vsi, u16 q_idx) xdp_ring = vsi->xdp_rings[q_idx]; q_vector = rx_ring->q_vector; - while (test_and_set_bit(ICE_CFG_BUSY, vsi->state)) { - timeout--; - if (!timeout) - return -EBUSY; - usleep_range(1000, 2000); - } - synchronize_net(); netif_trans_update(vsi->netdev); netif_carrier_off(vsi->netdev); @@ -251,7 +243,6 @@ static int ice_qp_ena(struct ice_vsi *vsi, u16 q_idx) synchronize_net(); netif_tx_start_queue(netdev_get_tx_queue(vsi->netdev, q_idx)); netif_carrier_on(vsi->netdev); - clear_bit(ICE_CFG_BUSY, vsi->state); return fail; } @@ -379,7 +370,8 @@ int ice_xsk_pool_setup(struct ice_vsi *vsi, struct xsk_buff_pool *pool, u16 qid) return -EINVAL; } - if_running = netif_running(vsi->netdev) && ice_is_xdp_ena_vsi(vsi); + if_running = !ice_rebuild_pending(vsi) && + netif_running(vsi->netdev) && ice_is_xdp_ena_vsi(vsi); if (if_running) { struct ice_rx_ring *rx_ring = vsi->rx_rings[qid]; From patchwork Mon Jun 10 15:37:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Larysa Zaremba X-Patchwork-Id: 13692245 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 3CFD914387E; Mon, 10 Jun 2024 15:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718034312; cv=none; b=cqOYAtRED0db3O+1Wp0g4SA5Zh5y6mH1AlGVBAXjvxkdrhCRWqcLGQI3hNdVjRYYDn5YXnRs/W1+RJMwkpLK7asbNGO/m+SZUrhq+xrdfrA/ecQoPnJKoFsOY9RuHiImxtTNHbPq97j1+bXjb88gQZcaQ4ytxshyt3o+jdbTIfY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718034312; c=relaxed/simple; bh=77taguqMlOk9palmEIZHwzEPuGl4cXRwnQzwDICfdrM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CW2gOfReW99FyEn2P0H1C5F03DjpShkAxLkWcVceXsqmGfz1EOQD8CqqDCEcIvx9+W7wpdzOA9hfhFssrrsAajYmjEUVDWF9C7KbCavCZ216a4bwFFQ99h9/0mEYcpSDkyAQI5joQ4ITdOknY3c6prUcefJEBggLK8hpWWSK4Uk= 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=ktG1mqw5; arc=none smtp.client-ip=198.175.65.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="ktG1mqw5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718034311; x=1749570311; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=77taguqMlOk9palmEIZHwzEPuGl4cXRwnQzwDICfdrM=; b=ktG1mqw5L1iYa4cKb9v7KEp82MHmR59PjwKhxKr1PUZ1gpR/kWNnwhJ7 GkMUNX5HomyEtbb4IzrfOf1gFIsJH3GOi1W4reSRj5BaTMJNgHk9g0Rs7 G9IyW4HplM+0O9/kamMhCmRbKr2WLXC1DK5uy9K7QpUTxHeSEkMGLZ+RZ zPOXbuN54gTFv/Mst6Xx5hgCVzGf6hZFobjr7rNCBlmxPnOXl2ypBTyB1 Z20q4b1Fd1LDrgyMMjLGTIo0TPjZFyZQlVxARZRC9ZPD8f/rKg2aeF7DP 4uXyy6/grI9/qBaVLJWU3YOKt5+4sZh9tCFX2ofSC/XerBI/T1oz1EK48 w==; X-CSE-ConnectionGUID: Xg8+b+XOQJyhftiEc0YARw== X-CSE-MsgGUID: TgZBS62HT7mM4Ywd/ByQ3A== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="26119872" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="26119872" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:45:10 -0700 X-CSE-ConnectionGUID: uVaJisceRt+8/TSVPvmkGA== X-CSE-MsgGUID: vCchazQYRsOqkyP5o3Padg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="43679782" Received: from irvmail002.ir.intel.com ([10.43.11.120]) by fmviesa004.fm.intel.com with ESMTP; 10 Jun 2024 08:45:05 -0700 Received: from lincoln.igk.intel.com (lincoln.igk.intel.com [10.102.21.235]) by irvmail002.ir.intel.com (Postfix) with ESMTP id 0CFDD312D8; Mon, 10 Jun 2024 16:44:52 +0100 (IST) From: Larysa Zaremba To: intel-wired-lan@lists.osuosl.org Cc: Larysa Zaremba , Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Maciej Fijalkowski , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, magnus.karlsson@intel.com, Michal Kubiak , Igor Bagnucki Subject: [PATCH iwl-net 3/3] ice: make NAPI setting code aware that rtnl-locked request is waiting Date: Mon, 10 Jun 2024 17:37:15 +0200 Message-ID: <20240610153716.31493-4-larysa.zaremba@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240610153716.31493-1-larysa.zaremba@intel.com> References: <20240610153716.31493-1-larysa.zaremba@intel.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org ice_vsi_rebuild() is a critical section in the reset path. Sometimes, rtnl-locked callbacks have to wait for it to finish. However, it is possible they will wait for an eternity, because the critical section contains calls to ice_queue_set_napi() that try to take rtnl_lock. Make ice_queue_set_napi() aware that some rtnl-locked code is waiting and skip taking the lock, if this is the case. Fixes: 080b0c8d6d26 ("ice: Fix ASSERT_RTNL() warning during certain scenarios") Reviewed-by: Igor Bagnucki Signed-off-by: Larysa Zaremba --- drivers/net/ethernet/intel/ice/ice.h | 1 + drivers/net/ethernet/intel/ice/ice_lib.c | 18 +++++++++++++++--- drivers/net/ethernet/intel/ice/ice_main.c | 5 ++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice.h b/drivers/net/ethernet/intel/ice/ice.h index 76590cfcaf68..7c1e24afa34b 100644 --- a/drivers/net/ethernet/intel/ice/ice.h +++ b/drivers/net/ethernet/intel/ice/ice.h @@ -307,6 +307,7 @@ enum ice_pf_state { ICE_PHY_INIT_COMPLETE, ICE_FD_VF_FLUSH_CTX, /* set at FD Rx IRQ or timeout */ ICE_AUX_ERR_PENDING, + ICE_RTNL_WAITS_FOR_RESET, ICE_STATE_NBITS /* must be last */ }; diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index 4774bcc4d5a8..a5dc6fc6e63d 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -2740,12 +2740,24 @@ ice_queue_set_napi(struct ice_vsi *vsi, unsigned int queue_index, if (current_work() == &pf->serv_task || test_bit(ICE_PREPARED_FOR_RESET, pf->state) || test_bit(ICE_DOWN, pf->state) || - test_bit(ICE_SUSPENDED, pf->state)) + test_bit(ICE_SUSPENDED, pf->state)) { + bool rtnl_held_here = true; + + while (!rtnl_trylock()) { + if (test_bit(ICE_RTNL_WAITS_FOR_RESET, pf->state)) { + rtnl_held_here = false; + break; + } + usleep_range(1000, 2000); + } __ice_queue_set_napi(vsi->netdev, queue_index, type, napi, - false); - else + true); + if (rtnl_held_here) + rtnl_unlock(); + } else { __ice_queue_set_napi(vsi->netdev, queue_index, type, napi, true); + } } /** diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index cd8be3c3b956..37b3dd22cdc2 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -3103,8 +3103,11 @@ static int ice_xdp(struct net_device *dev, struct netdev_bpf *xdp) return -EINVAL; } - while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) + while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) { + set_bit(ICE_RTNL_WAITS_FOR_RESET, pf->state); usleep_range(1000, 2000); + } + clear_bit(ICE_RTNL_WAITS_FOR_RESET, pf->state); switch (xdp->command) { case XDP_SETUP_PROG: