From nobody Sun Sep 14 22:55:27 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 0552DC54EE9 for ; Tue, 13 Sep 2022 14:40:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234438AbiIMOk2 (ORCPT ); Tue, 13 Sep 2022 10:40:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234362AbiIMOhk (ORCPT ); Tue, 13 Sep 2022 10:37:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 812BE6B66A; Tue, 13 Sep 2022 07:20:27 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 1C373614B4; Tue, 13 Sep 2022 14:19:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0DBBC433C1; Tue, 13 Sep 2022 14:19:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663078788; bh=n35/stZhqURexH/BuYeoGPgRqe6e21ZPM0ynenKxGXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=otGoylOh+VPlvDhjNzfqlFliG4muApEe2z3NjDa3E7qAu9kIrbtB3NVGgnM21MKHH 2i2Zt6Dpn+b0BMhGX0DQMqxau01zqnxttK5ia+kSkEfFmlyAZ5GsFtzz/qnps4RDUv UDPfFstzMMaCa2YapR/sXiox3mPfTZNkI1B2uCpQ= 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.15 083/121] iavf: Detach device during reset task Date: Tue, 13 Sep 2022 16:04:34 +0200 Message-Id: <20220913140400.938167651@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140357.323297659@linuxfoundation.org> References: <20220913140357.323297659@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 db95786c3419f..00b2ef01f4ea6 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_main.c +++ b/drivers/net/ethernet/intel/iavf/iavf_main.c @@ -2222,6 +2222,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. */ @@ -2229,7 +2234,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)) @@ -2299,7 +2304,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); } @@ -2412,7 +2416,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); @@ -2423,6 +2427,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