Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp410472imw; Wed, 13 Jul 2022 00:06:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sawp1TROv/O8hBV1l1hft46WEct4ij9ugf1D2MJENBDTlAt5bYUXCQW0gr0JRxCwtzW1nn X-Received: by 2002:a17:90a:b117:b0:1ef:958f:e5b7 with SMTP id z23-20020a17090ab11700b001ef958fe5b7mr8497667pjq.107.1657696002926; Wed, 13 Jul 2022 00:06:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657696002; cv=none; d=google.com; s=arc-20160816; b=nhETQx+4N1rDav86731NIE3z76HDLgNzqUAIs4UUwO78uACnuexAD/aNikdmlNsRIF mXP+bLk6TaLoVmeb6vdvs7HvlPfDSdFOAa6wGT+MR8nSXz1MrknF5rQ5pg2f5WBFoeGp jOil1V2b/k/mDJz8j3awDAJCnc34aNhtazhUEkG8I+o9T4X3N1V8SLQbrR/pPVBcFjB9 YRnY9hgtxNCig9uW/oZRIqyXqgqlq/i1aZQcMc6Z/E2IZ5v/frf+rG9pYA5km80yhxpN EgERV/nW/keD0JjIXFIZd5OPX1iP0xgZu0ZpZsRRFBmZTBRkGG2ljeLF91xuifQSKzU9 pi2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=LzDcCOyz/oL/Atfc+DxoSYENFDlt7iDBa7JxdWJN6Pg=; b=hK9l17eh1DZmiVPK7D0FjuCYHzmjcGukEI7QiNJO6ap0cCtFMNU3+f7FwuTb0y1Sqr bhtQQMntcNJw63ql+oaQvg/PBc6DRsA7MQvaV1PBFcKec1QnrT+R/vyOtbKG87etWKx9 jLuyjtGUtrINdJdnGtp9JiSnlgdh+aEoEvSMwiIAkDDJTYBQcJjEbiuqCJvjMBgC5nn+ yR8q96KUCLZ6q+LAqvqS258Mbe6me2fS9FTas5AJtqtdO8vipGAok7ZWUMJB6avTFN18 oClJ9Mfqys6ALjPnu8/u/+3KmRsPVFHh3npisyDaJ8AAMSA4wB+fR/wKTIqKa8wQxkAb TRzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zW3XIk4x; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d188-20020a6368c5000000b00412b40fe63esi15558162pgc.677.2022.07.13.00.06.30; Wed, 13 Jul 2022 00:06:42 -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=@linaro.org header.s=google header.b=zW3XIk4x; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232833AbiGMG5z (ORCPT + 99 others); Wed, 13 Jul 2022 02:57:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234322AbiGMG5x (ORCPT ); Wed, 13 Jul 2022 02:57:53 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FDBF18349 for ; Tue, 12 Jul 2022 23:57:52 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id u15so1515630lji.10 for ; Tue, 12 Jul 2022 23:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=LzDcCOyz/oL/Atfc+DxoSYENFDlt7iDBa7JxdWJN6Pg=; b=zW3XIk4xCAluS7YJYHCruLMdLmB3lr7SulMprALEQ/L7GCtEhiZ4Sttthk2ih5h1JY NKIkFLa6A9sPs81NC1QyKOBASgXOLdbVhcv9KTXY1kFVvCrt7htRkl8WwvnNxqFQ0im8 m25DR6KDePb8USlq+JdTV/5QQ8wsD11IDi1BBM7aDg/SUovyyoX3LiWYZy5fxB2S1/nQ cE4ws5g67LxE/58IfArGC5V8IOGQ0facYLF8IDaJyMesNBh++ztrTih/Vk6RHfzcwMH1 d/Z+rvE4SuV2lnfN+TO54XZh90iLUu/sZgMoBkBKx7YH+7k6CmvDfTpY7yWtj0tANXnX +JIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=LzDcCOyz/oL/Atfc+DxoSYENFDlt7iDBa7JxdWJN6Pg=; b=yb40k/Ub2xaZQF5RYwBR3akH78UDMXna+mGW07ngojgOIX4zvdH/koS6BC2cYasMwL Ddi28ufiqsmTqJC0XSh/Tr3CUe/OuTHov1ENaYkMYaaT2jbLNXQAE1v+ekH9BxSbuyYx SM/J1i8SmGgwIcu/A+UoO5DlKow1Y7R70+Z1h70GzyWRxM/fOaPvu6dvYF41RjDI5X4A 38unatkEzmGP/lf7PH72S3f4h3mOMrlH+OzIiFsfuRwLq5DtTO8F/fDfVIV8wUG3C8Ln rMArKFHoXwB62SS1va4gfK/K0lONCpAOkJ198MB+Xfxl02wMc5N9XSHb8EMC8HRgKRbY Preg== X-Gm-Message-State: AJIora9UozpGUzjDydWVkfUOe57yZ7HPPsSM6TMHZTSa6KpS2ykoK4r2 QqhYCQ/5SEf8Fm5pyoC3V45UyA== X-Received: by 2002:a2e:b538:0:b0:25d:881d:a10f with SMTP id z24-20020a2eb538000000b0025d881da10fmr734625ljm.65.1657695470468; Tue, 12 Jul 2022 23:57:50 -0700 (PDT) Received: from [10.0.0.8] (fwa5da9-171.bb.online.no. [88.93.169.171]) by smtp.gmail.com with ESMTPSA id be20-20020a05651c171400b0025d86b425e7sm300131ljb.89.2022.07.12.23.57.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Jul 2022 23:57:49 -0700 (PDT) Message-ID: Date: Wed, 13 Jul 2022 08:57:47 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] NFC: nxp-nci: fix deadlock during firmware update Content-Language: en-US To: Michael Walle Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jakub Kicinski References: <20220712152554.2909224-1-michael@walle.cc> From: Krzysztof Kozlowski In-Reply-To: <20220712152554.2909224-1-michael@walle.cc> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,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 On 12/07/2022 17:25, Michael Walle wrote: > During firmware update, both nxp_nci_i2c_irq_thread_fn() and > nxp_nci_fw_work() will hold the info_lock mutex and one will wait > for the other via a completion: > > nxp_nci_fw_work() > mutex_lock(info_lock) > nxp_nci_fw_send() > wait_for_completion(cmd_completion) > mutex_unlock(info_lock) > > nxp_nci_i2c_irq_thread_fn() > mutex_lock(info_lock) > nxp_nci_fw_recv_frame() > complete(cmd_completion) > mutex_unlock(info_lock) > > This will result in a -ETIMEDOUT error during firmware update (note > that the wait_for_completion() above is a variant with a timeout). > > Drop the lock in nxp_nci_fw_work() and instead take it after the > work is done in nxp_nci_fw_work_complete() when the NFC controller mode > is switched and the info structure is updated. > > Fixes: dece45855a8b ("NFC: nxp-nci: Add support for NXP NCI chips") > Signed-off-by: Michael Walle > --- > drivers/nfc/nxp-nci/firmware.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/nfc/nxp-nci/firmware.c b/drivers/nfc/nxp-nci/firmware.c > index 119bf305c642..6a4d4aa7239f 100644 > --- a/drivers/nfc/nxp-nci/firmware.c > +++ b/drivers/nfc/nxp-nci/firmware.c > @@ -54,6 +54,7 @@ void nxp_nci_fw_work_complete(struct nxp_nci_info *info, int result) > struct nxp_nci_fw_info *fw_info = &info->fw_info; > int r; > > + mutex_lock(&info->info_lock); > if (info->phy_ops->set_mode) { > r = info->phy_ops->set_mode(info->phy_id, NXP_NCI_MODE_COLD); > if (r < 0 && result == 0) > @@ -66,6 +67,7 @@ void nxp_nci_fw_work_complete(struct nxp_nci_info *info, int result) > release_firmware(fw_info->fw); > fw_info->fw = NULL; > } > + mutex_unlock(&info->info_lock); > > nfc_fw_download_done(info->ndev->nfc_dev, fw_info->name, (u32) -result); > } > @@ -172,8 +174,6 @@ void nxp_nci_fw_work(struct work_struct *work) > fw_info = container_of(work, struct nxp_nci_fw_info, work); > info = container_of(fw_info, struct nxp_nci_info, fw_info); > > - mutex_lock(&info->info_lock); > - I am not sure this is correct. info_lock should protect members of info thus also info->fw_info. By removing the mutex the protection is gone. Unless you are sure that fw_info cannot be modified concurrently? Best regards, Krzysztof