From nobody Fri Dec 19 01:38:57 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E09E8C6FA82 for ; Tue, 13 Sep 2022 14:24:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233585AbiIMOXl (ORCPT ); Tue, 13 Sep 2022 10:23:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233448AbiIMOXA (ORCPT ); Tue, 13 Sep 2022 10:23:00 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBCD765267; Tue, 13 Sep 2022 07:15:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 52F67CE1272; Tue, 13 Sep 2022 14:13:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DA99C433C1; Tue, 13 Sep 2022 14:13:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663078394; bh=4+LYtmP0CxGzLyk+tSZ/mf0FX8enKExZdAUzuzz+Om0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gaQbRnYHiOR9FCMt9aXiBICOc4IUGppHBsR6VdA5sZ2Y5QfPkWpyIVMrHCmMPTPzr 6+yOmgVBJa045WAB2WdK2SyzYeCNJdfKQ6aqRcyhYOtVH4snr2CvWtgOGGZvPk/1nX HFcwo6NooJnaQZg2QOl4eh9Fd5YRDtPxVSt053wc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jacob Keller , Patryk Piotrowski , SlawomirX Laba , Vitaly Grinberg , Ivan Vecera , Konrad Jankowski , Tony Nguyen , Sasha Levin Subject: [PATCH 5.19 122/192] iavf: Detach device during reset task Date: Tue, 13 Sep 2022 16:03:48 +0200 Message-Id: <20220913140416.072792672@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140410.043243217@linuxfoundation.org> References: <20220913140410.043243217@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Ivan Vecera [ Upstream commit aa626da947e9cd30c4cf727493903e1adbb2c0a0 ] iavf_reset_task() takes crit_lock at the beginning and holds it during whole call. The function subsequently calls iavf_init_interrupt_scheme() that grabs RTNL. Problem occurs when userspace initiates during the reset task any ndo callback that runs under RTNL like iavf_open() because some of that functions tries to take crit_lock. This leads to classic A-B B-A deadlock scenario. To resolve this situation the device should be detached in iavf_reset_task() prior taking crit_lock to avoid subsequent ndos running under RTNL and reattach the device at the end. Fixes: 62fe2a865e6d ("i40evf: add missing rtnl_lock() around i40evf_set_int= errupt_capability") Cc: Jacob Keller Cc: Patryk Piotrowski Cc: SlawomirX Laba Tested-by: Vitaly Grinberg Signed-off-by: Ivan Vecera Tested-by: Konrad Jankowski Signed-off-by: Tony Nguyen Signed-off-by: Sasha Levin --- drivers/net/ethernet/intel/iavf/iavf_main.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethe= rnet/intel/iavf/iavf_main.c index 6d159334da9ec..981c43b204ff4 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_main.c +++ b/drivers/net/ethernet/intel/iavf/iavf_main.c @@ -2789,6 +2789,11 @@ static void iavf_reset_task(struct work_struct *work) int i =3D 0, err; bool running; =20 + /* Detach interface to avoid subsequent NDO callbacks */ + rtnl_lock(); + netif_device_detach(netdev); + rtnl_unlock(); + /* When device is being removed it doesn't make sense to run the reset * task, just return in such a case. */ @@ -2796,7 +2801,7 @@ static void iavf_reset_task(struct work_struct *work) if (adapter->state !=3D __IAVF_REMOVE) queue_work(iavf_wq, &adapter->reset_task); =20 - return; + goto reset_finish; } =20 while (!mutex_trylock(&adapter->client_lock)) @@ -2866,7 +2871,6 @@ static void iavf_reset_task(struct work_struct *work) =20 if (running) { netif_carrier_off(netdev); - netif_tx_stop_all_queues(netdev); adapter->link_up =3D false; iavf_napi_disable_all(adapter); } @@ -2996,7 +3000,7 @@ static void iavf_reset_task(struct work_struct *work) mutex_unlock(&adapter->client_lock); mutex_unlock(&adapter->crit_lock); =20 - return; + goto reset_finish; reset_err: if (running) { set_bit(__IAVF_VSI_DOWN, adapter->vsi.state); @@ -3007,6 +3011,10 @@ static void iavf_reset_task(struct work_struct *work) mutex_unlock(&adapter->client_lock); mutex_unlock(&adapter->crit_lock); dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\= n"); +reset_finish: + rtnl_lock(); + netif_device_attach(netdev); + rtnl_unlock(); } =20 /** --=20 2.35.1