Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3969959rwe; Tue, 30 Aug 2022 02:05:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR7vVY1vr6XOxonxe791wX12qHC8xOp7bfmdUpx3JppD5t3XaQwj2PYaUL3dBgCW/7blMfNV X-Received: by 2002:a05:6402:2789:b0:440:44b6:849b with SMTP id b9-20020a056402278900b0044044b6849bmr20267516ede.387.1661850327722; Tue, 30 Aug 2022 02:05:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661850327; cv=none; d=google.com; s=arc-20160816; b=gkUCpsx3p05wzXJP8K03x2ayocnby8Ii37H6caq0Sn6xgWieHGTjbS65pg7wE7XMJo ZOLpkF5HN5yph0Npu1UprtqmkeVijJ8j1XkONQtNj8yoLvSUErbCDhe7V55Kxgfgn6XS xXTGyVzxFi7F4byBTbA3D4KlEyDXwnWUS4WMMppxRN5YqJOKSZCzYv6yVSkRVaEnMRpz LBSdgrE6JO8/eX0KoElOayoafUdL1Mjx3aolOrboelrHDVZqU15xZTAMqNAT7Aam8xCS 9443auEprwu9hwa9GFu3tjEgs3NPVPcoDq1qswFScCAtojGDRFhGN7Io9nW3QhAhEE7z EHDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=/zPHAN3qGo7NVF2OTVY04vNzvTw3myDXxymM/1eiXU4=; b=NUsnQmwlYTwwyEqjrtkoGRhTRSBSOfLyYeMwh2JuTPvY7WIHdQ8GBpxWQibkxPGYlN T4i9CGcMfXzSQ0lro1f3hYq0aSXdv9naCKG2IKJp0tXl/TyAgfvGyHTWGxWeUbOMQo2Z cPbRDtuiNJOF4cx4fB1w2WN9KP1XhgM2tnRbOwjat93XrWdzcqBcqqvJWZFPv5rLHpwn 2YOUEAnp0r/lu8sH+gQnc+nHbTfoFHTm5ZiokzFzyEK/3V4Gel0T8RcpWExuyDtdJIIf YuuisRwxGeiAK2O0rLSqGHszGwVlzSXeICRumsZExPOYd+kBdiHYUiwbl9nvUgtovleN GnQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XfRa5WIm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hs7-20020a1709073e8700b007317756bc04si699358ejc.1006.2022.08.30.02.05.01; Tue, 30 Aug 2022 02:05:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XfRa5WIm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231406AbiH3IQx (ORCPT + 99 others); Tue, 30 Aug 2022 04:16:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229729AbiH3IQu (ORCPT ); Tue, 30 Aug 2022 04:16:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DCD39AF8C for ; Tue, 30 Aug 2022 01:16:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661847407; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=/zPHAN3qGo7NVF2OTVY04vNzvTw3myDXxymM/1eiXU4=; b=XfRa5WImGppjIdA4RZP+PFHSohf+h4LSS3MZbO3GMplXRvWzBPH7NtVKSJUomo9YaPRdq4 rpzn2R9EEbh5FFYNWxazD+rmhraWvnQoz6I83IqJuOTfVfoKqOL9kODQ20g4CI1xrzx2De i8oh6/Bce9pBJPv6PXHzTcmYsME86os= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-310-Qkp0WAYFPiuLdQuBOBf5yA-1; Tue, 30 Aug 2022 04:16:31 -0400 X-MC-Unique: Qkp0WAYFPiuLdQuBOBf5yA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BB66D101AA47; Tue, 30 Aug 2022 08:16:30 +0000 (UTC) Received: from p1.luc.com (unknown [10.40.195.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7965C909FF; Tue, 30 Aug 2022 08:16:28 +0000 (UTC) From: Ivan Vecera To: netdev@vger.kernel.org Cc: Jacob Keller , Patryk Piotrowski , SlawomirX Laba , Vitaly Grinberg , Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jeff Kirsher , intel-wired-lan@lists.osuosl.org (moderated list:INTEL ETHERNET DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH net v2] iavf: Detach device during reset task Date: Tue, 30 Aug 2022 10:16:27 +0200 Message-Id: <20220830081627.1205872-1-ivecera@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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_interrupt_capability") Cc: Jacob Keller Cc: Patryk Piotrowski Cc: SlawomirX Laba Tested-by: Vitaly Grinberg Signed-off-by: Ivan Vecera --- 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/ethernet/intel/iavf/iavf_main.c index f39440ad5c50..10aa99dfdcdb 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_main.c +++ b/drivers/net/ethernet/intel/iavf/iavf_main.c @@ -2877,6 +2877,11 @@ static void iavf_reset_task(struct work_struct *work) int i = 0, err; bool running; + /* 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. */ @@ -2884,7 +2889,7 @@ static void iavf_reset_task(struct work_struct *work) if (adapter->state != __IAVF_REMOVE) queue_work(iavf_wq, &adapter->reset_task); - return; + goto reset_finish; } while (!mutex_trylock(&adapter->client_lock)) @@ -2954,7 +2959,6 @@ static void iavf_reset_task(struct work_struct *work) if (running) { netif_carrier_off(netdev); - netif_tx_stop_all_queues(netdev); adapter->link_up = false; iavf_napi_disable_all(adapter); } @@ -3084,7 +3088,7 @@ static void iavf_reset_task(struct work_struct *work) mutex_unlock(&adapter->client_lock); mutex_unlock(&adapter->crit_lock); - return; + goto reset_finish; reset_err: if (running) { set_bit(__IAVF_VSI_DOWN, adapter->vsi.state); @@ -3095,6 +3099,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(); } /** -- 2.35.1