Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp5044253rwb; Mon, 8 Aug 2022 11:06:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR6+uuXPJU7b7QGmnOnjhOnGWu6WfR6hNSHE8YtPMOpROGxY3c7G3u9ktx3mnYZ6IMj8TSqL X-Received: by 2002:a17:907:2724:b0:730:da23:5b60 with SMTP id d4-20020a170907272400b00730da235b60mr13611171ejl.43.1659982006793; Mon, 08 Aug 2022 11:06:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659982006; cv=none; d=google.com; s=arc-20160816; b=tRTZt8kFB1yhWApSRLIUvNdRbO1tkDVAEhd0dfYBb+TBXKh/6Be6diWzfYscsFOPrS ppQJNY2vT4InQUrXFjUkEXntq0qO5Jl/LxTQ0FDyk6Ry8kj3uY4UDtm4GpUCNZ6QubMh 7fCgqCVZTFmWQMOIWJCy5oer3sYerTV61ufBgRL431RGLEzkOv3GOCTOnEjPy/dnDs2I ETdxOXc98PSfgZ4wGLfwWGm5SKwoFeZqV3J66FNOGJZjGPvqKJs4ERs3pYQNfjkvx/Wo SqQdExjjdRWAOI2tkc/RKfYL3q8oVb3sFYhMhs03+MCOeAZxm9wRrkxKcvMY0v17gfB5 wKMg== 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=rKD32BoUZtJVmXJMy5BhMXR7sCS+Ype3RSG55JgauC4=; b=hlMZhk9uGFzYLg8SDUVEebfHNuLPUBCGJb+5aEvHIZw0/e/knt3KVqK0VqmR2pP+TH 5DXni/ipDAWew7N2CtGkHwMJP05CW/qb0/xjd1yEUPPuEiz3B0/f/GtWyNkacqogMyy/ D7wbr0vdiL5dfFJE61+fIa5KXq+iD1zyaQjo9TAPNlKfZHpLoeij5yvOAoOMFLJvMmi4 /CfED8sWW+/4huGbSPumhNGzIeW7+xlLp0V8NF3n2d9jrFFGc5NnQ+AbP6RcChx4Gyy5 3kTwZdCw7Nnj3t1bex6va6cSuyhSuH8Gs4EhnwrdfGN7SpvXvkTPd35ns9zZ5fHNrDsS htQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ItO1Agfg; 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 g1-20020a50d0c1000000b0043d67a7dd61si7147923edf.179.2022.08.08.11.06.20; Mon, 08 Aug 2022 11:06:46 -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=ItO1Agfg; 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 S243914AbiHHR64 (ORCPT + 99 others); Mon, 8 Aug 2022 13:58:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235853AbiHHR6y (ORCPT ); Mon, 8 Aug 2022 13:58:54 -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 ESMTP id 4EB0217A93 for ; Mon, 8 Aug 2022 10:58:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659981532; 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=rKD32BoUZtJVmXJMy5BhMXR7sCS+Ype3RSG55JgauC4=; b=ItO1Agfgd78BC7dyOVYHHj/aR0RSN4iARfV9yEEgRHCsH3KFXEubdGtyloOln5cvW3fQ2u NyBY43TQI61T4/KBywlDL74CG7kzAmlaoyGaDyxJuiku4bH5sZjNqyAlffV+MV4aWJZmjZ 1L6OpCkIv7FwDOenIWp+qgWEfsBpEFQ= 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-418-R9LkVXhoN4url2WW2DAw_A-1; Mon, 08 Aug 2022 13:58:49 -0400 X-MC-Unique: R9LkVXhoN4url2WW2DAw_A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B4311019DE1; Mon, 8 Aug 2022 17:58:48 +0000 (UTC) Received: from p1.luc.com (unknown [10.40.194.142]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4410C15BA1; Mon, 8 Aug 2022 17:58:46 +0000 (UTC) From: Ivan Vecera To: netdev@vger.kernel.org Cc: Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Stefan Assmann , intel-wired-lan@lists.osuosl.org (moderated list:INTEL ETHERNET DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH net] iavf: Fix deadlock in initialization Date: Mon, 8 Aug 2022 19:58:45 +0200 Message-Id: <20220808175845.484968-1-ivecera@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Spam-Status: No, score=-2.7 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=ham 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 Fix deadlock that occurs when iavf interface is a part of failover configuration. 1. Mutex crit_lock is taken at the beginning of iavf_watchdog_task() 2. Function iavf_init_config_adapter() is called when adapter state is __IAVF_INIT_CONFIG_ADAPTER 3. iavf_init_config_adapter() calls register_netdevice() that emits NETDEV_REGISTER event 4. Notifier function failover_event() then calls net_failover_slave_register() that calls dev_open() 5. dev_open() calls iavf_open() that tries to take crit_lock in end-less loop Stack trace: ... [ 790.251876] usleep_range_state+0x5b/0x80 [ 790.252547] iavf_open+0x37/0x1d0 [iavf] [ 790.253139] __dev_open+0xcd/0x160 [ 790.253699] dev_open+0x47/0x90 [ 790.254323] net_failover_slave_register+0x122/0x220 [net_failover] [ 790.255213] failover_slave_register.part.7+0xd2/0x180 [failover] [ 790.256050] failover_event+0x122/0x1ab [failover] [ 790.256821] notifier_call_chain+0x47/0x70 [ 790.257510] register_netdevice+0x20f/0x550 [ 790.258263] iavf_watchdog_task+0x7c8/0xea0 [iavf] [ 790.259009] process_one_work+0x1a7/0x360 [ 790.259705] worker_thread+0x30/0x390 To fix the situation we should check the current adapter state after first unsuccessful mutex_trylock() and return with -EBUSY if it is __IAVF_INIT_CONFIG_ADAPTER. Fixes: 226d528512cf ("iavf: fix locking of critical sections") Signed-off-by: Ivan Vecera --- drivers/net/ethernet/intel/iavf/iavf_main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c index 45d097a164ad..f9dcaadc7ea0 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_main.c +++ b/drivers/net/ethernet/intel/iavf/iavf_main.c @@ -4085,8 +4085,17 @@ static int iavf_open(struct net_device *netdev) return -EIO; } - while (!mutex_trylock(&adapter->crit_lock)) + while (!mutex_trylock(&adapter->crit_lock)) { + /* If we are in __IAVF_INIT_CONFIG_ADAPTER state the crit_lock + * is already taken and iavf_open is called from an upper + * device's notifier reacting on NETDEV_REGISTER event. + * We have to leave here to avoid dead lock. + */ + if (adapter->state == __IAVF_INIT_CONFIG_ADAPTER) + return -EBUSY; + usleep_range(500, 1000); + } if (adapter->state != __IAVF_DOWN) { err = -EBUSY; -- 2.35.1