Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5548699iob; Mon, 9 May 2022 20:18:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5qcx1GRHgp1e6XnlfBEOW7MPcU2CuU5pErpVNKcWwSqKJbjMirKUuB8cT6x1NUBTo0+KS X-Received: by 2002:a63:90c7:0:b0:3c6:2bba:a5c0 with SMTP id a190-20020a6390c7000000b003c62bbaa5c0mr15652999pge.3.1652152697047; Mon, 09 May 2022 20:18:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652152697; cv=none; d=google.com; s=arc-20160816; b=h5GolQRv0zrEi59y3W6CH92zlqaXx6Zjy0P9npzlFGNErbCk7SVANtDkOwjwpQfkmg 4WRC+aaFVKY0blohLIHWt8a+6vDtxAn9kqOHUz00yALLARM2kADR96fBdd1HYKMI02Vl SvzId7G+x6tJNsgzuk1chJZeIt64oUY71AAPHMA7a9BLAJGxb0C8eEnUc5Fkto8uz9O7 3djayV7UFRNZ53I5ef+B4Lmg8MbcHu9qQ06gGGSdH8NaMXeDVK8DN/+6Z8lr1xd5tXW0 gmXP2ItHcLyX4T4nY7lbBr5YtsghW1li7MWET9a8R6rfntP9CdezQn7uXfsCcRFr6UYM 2Wzw== 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 :mime-version:user-agent:date:message-id:from:references:to:subject :cc; bh=BovlRV4I6lJf+JKY3biFtf9Op2tns3eDwfxG73t8dCk=; b=0+u7gJJy9d+TleEjQwZspaVh3oxuT3zApfd8VvcLB6XE2ti3iVQLXclZ5W+EsckQ+O uYEgE36Z8qY2LCyfDouwdAqK7PRP2lPEmTma4NZUZ+hdCUPyGyWwEa3eGeXUHpheg6/Q MKftHMVJ4cw/PjdHrEDTvTo8BKU2tljS2l7wqmHgCqxMlLJuUCxkwpfB+WXwEvewPbGs ozqjPkfc+BHnKbS029hLD2QsizmZDUFQP8Bwk/+4jCwPjR1B9qHK+1ElxNbtETCmg1U4 iXUbqhYLBwGD+/5VcOGmeR5Vm+5xlz0YsbHuKmm5uWOpmU0xCX+axS5qdYx8YehG9lRp Uy6Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n4-20020a170902d2c400b00158d0436f45si2167703plc.76.2022.05.09.20.18.00; Mon, 09 May 2022 20:18:17 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234489AbiEJCHp (ORCPT + 99 others); Mon, 9 May 2022 22:07:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230437AbiEJCHo (ORCPT ); Mon, 9 May 2022 22:07:44 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB4BA210B94; Mon, 9 May 2022 19:03:48 -0700 (PDT) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Ky1V31sFpzGpdn; Tue, 10 May 2022 10:00:59 +0800 (CST) Received: from [10.67.102.169] (10.67.102.169) by canpemm500009.china.huawei.com (7.192.105.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 10 May 2022 10:03:46 +0800 CC: , Subject: Re: [PATCH] pci: avoid dead lock between device reset and sriov disable To: Jay Zhou , , , , References: <20220404062539.1710-1-jianjay.zhou@huawei.com> From: Yicong Yang Message-ID: <0b146b52-054d-4f89-961a-65f29037e172@huawei.com> Date: Tue, 10 May 2022 10:03:46 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: <20220404062539.1710-1-jianjay.zhou@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.102.169] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,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 On 2022/4/4 14:25, Jay Zhou wrote: > Call trace of PF SRIOV disable: > sriov_numvfs_store > device_lock <----------------- (1) get the device lock > ->sriov_configure # e.g. vfio_pci_sriov_configure > sriov_disable > pci_cfg_access_lock <--- (4) wait dev->block_cfg_access to be 0 > > Call trace of PF reset: > reset_store > pci_reset_function > pci_dev_lock > pci_cfg_access_lock <----- (2) set dev->block_cfg_access = 1 > device_lock <------------- (3) want to get the device lock > > These two oprations would wait for each other forever if the > code execution sequence is (1)(2)(3)(4). > > Let's get the device lock and then the config access lock in > pci_dev_lock(). > > Signed-off-by: Jay Zhou The patch looks good to me, Reviewed-by: Yicong Yang I met the same problem and tried to fix it in the same way. It's worth to be merged if somebody meets the same problem again. https://lore.kernel.org/linux-pci/1583489997-17156-1-git-send-email-yangyicong@hisilicon.com/ > --- > drivers/pci/pci.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index 9ecce435fb3f..61a6db1d21f6 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -5103,19 +5103,19 @@ static int pci_reset_bus_function(struct pci_dev *dev, bool probe) > > void pci_dev_lock(struct pci_dev *dev) > { > - pci_cfg_access_lock(dev); > /* block PM suspend, driver probe, etc. */ > device_lock(&dev->dev); > + pci_cfg_access_lock(dev); > } > EXPORT_SYMBOL_GPL(pci_dev_lock); > > /* Return 1 on successful lock, 0 on contention */ > int pci_dev_trylock(struct pci_dev *dev) > { > - if (pci_cfg_access_trylock(dev)) { > - if (device_trylock(&dev->dev)) > + if (device_trylock(&dev->dev)) { > + if (pci_cfg_access_trylock(dev)) > return 1; > - pci_cfg_access_unlock(dev); > + device_unlock(&dev->dev); > } > > return 0; > @@ -5124,8 +5124,8 @@ EXPORT_SYMBOL_GPL(pci_dev_trylock); > > void pci_dev_unlock(struct pci_dev *dev) > { > - device_unlock(&dev->dev); > pci_cfg_access_unlock(dev); > + device_unlock(&dev->dev); > } > EXPORT_SYMBOL_GPL(pci_dev_unlock); > >