Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp982733ybc; Tue, 19 Nov 2019 12:26:55 -0800 (PST) X-Google-Smtp-Source: APXvYqzonk7r6RCmgLXUSvvkgELUMuotKyOauIdFTEjnNM8wa3eyOFcvIZbaAHAU2T4yVMuzf9U+ X-Received: by 2002:a17:906:fac7:: with SMTP id lu7mr37955808ejb.5.1574195215243; Tue, 19 Nov 2019 12:26:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574195215; cv=none; d=google.com; s=arc-20160816; b=p+Jaf992QREilvMg3GEsxK6xgtcAfgBbGsRoyJDJTaR0AD2n4RwGypgdT5SVAxCtSn qzuCFuovBjUyPWWoLR/zrE3wZx7NAkpjEuN3awitn/+4Xd5uAaI83a+1DqYR1ZIzehgi nXYqBeU8kb4CyYpJnlLvZtHrp32GCqgMx7Lg+l0UzDgdq73n8M8i8zf/SEhJF5djuwku tfnrNtEVC4P6PajE8AgEiXfkMZVi7M8NsfIncpQ1P4XoXv/I8kD06QTA8YIWtBQ56nOM IFflOiwIoQhHHQYvoK+VxF32WUk/wLqvDpG1GDWtb5ZzZyDPLfuWKDf+7j4IW8+khtnz PriA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:message-id:subject:cc:to:from:date :dkim-signature; bh=7feoM/6zkZTAoIJGLG8Lq4iB9O2klrttv2oo+oQAHqE=; b=xkrB8c0GPfzstd8I79IPmc11hGzQhfZF3Rj5wCe+PzWsM/DH8Birzv66ys++RmQ75O DRY4U8ZYx6squ3OAr0/zh5CFbo5Ul7hnmw7XU8nC1Exi7rGgw07eGucc0JuaXQ0kOwnR WAe1gjeiSKQDv0gwRJ4BOUvyh1upOI3clrmCCM6/faIIVIjgnusRlggneaqM5vhqCp3H sIa8ZZsgMVUPMpRv1L0/cZjZT0SMMRiIyuMhZLOnZNzwGI7o/51hLYWqoX87frebZ+wR raKES523tBMoBa3ydrV2pttFMT+YGTmD71OOnJzytRkNgOq1/jJJVSbVCW9eLXm+ZHNG LkPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qrsJKda4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cb6si14339061ejb.359.2019.11.19.12.26.25; Tue, 19 Nov 2019 12:26:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qrsJKda4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727316AbfKSUXI (ORCPT + 99 others); Tue, 19 Nov 2019 15:23:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:50094 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726711AbfKSUXI (ORCPT ); Tue, 19 Nov 2019 15:23:08 -0500 Received: from localhost (unknown [69.71.4.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9FBCD2235D; Tue, 19 Nov 2019 20:23:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574194988; bh=gGqBvXglDEzCSK8thnzKNOyVmnBORJCnCuazwZu8Wmo=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=qrsJKda4M4ryOc9ETyXtnEeKouT6QOkDTRulbKdjk20avj2s4UH5QDkaoX2uJX/Ma n5V457p79EcIba3noyQ3FLcAQBBxUy9i1KvyDfxpnx8id3VHLuTBxvcXyJoKeWQblT cckiTKZsqFMWpLv633GqE8wUA9KNg896rOnsGE2w= Date: Tue, 19 Nov 2019 14:23:05 -0600 From: Bjorn Helgaas To: Xiang Zheng Cc: willy@infradead.org, wangxiongfeng2@huawei.com, wanghaibin.wang@huawei.com, guoheyi@huawei.com, yebiaoxiang@huawei.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, rjw@rjwysocki.net, tglx@linutronix.de, guohanjun@huawei.com, yangyingliang@huawei.com Subject: Re: [PATCH v2] pci: lock the pci_cfg_wait queue for the consistency of data Message-ID: <20191119202305.GA214858@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191119011545.15408-1-zhengxiang9@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 19, 2019 at 09:15:45AM +0800, Xiang Zheng wrote: > Commit "7ea7e98fd8d0" suggests that the "pci_lock" is sufficient, > and all the callers of pci_wait_cfg() are wrapped with the "pci_lock". > > However, since the commit "cdcb33f98244" merged, the accesses to > the pci_cfg_wait queue are not safe anymore. A "pci_lock" is > insufficient and we need to hold an additional queue lock while > read/write the wait queue. > > So let's use the add_wait_queue()/remove_wait_queue() instead of > __add_wait_queue()/__remove_wait_queue(). Also move the wait queue > functionality around the "schedule()" function to avoid reintroducing > the deadlock addressed by "cdcb33f98244". Procedural nits: - Run "git log --oneline drivers/pci/access.c" and follow the convention, e.g., starts with "PCI: " and first subsequent word is capitalized. - Use conventional commit references, e.g., 7ea7e98fd8d0 ("PCI: Block on access to temporarily unavailable pci device") and cdcb33f98244 ("PCI: Avoid possible deadlock on pci_lock and p->pi_lock") - IIRC you found that this actually caused a panic; please include the lore.kernel.org URL to that report. You can wait for a while to see if there are more substantive comments to address before posting a v3. > Signed-off-by: Xiang Zheng > Cc: Heyi Guo > Cc: Biaoxiang Ye > --- > > v2: > - Move the wait queue functionality around the "schedule()" function to > avoid reintroducing the deadlock addressed by "cdcb33f98244" > > --- > > drivers/pci/access.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/pci/access.c b/drivers/pci/access.c > index 2fccb5762c76..09342a74e5ea 100644 > --- a/drivers/pci/access.c > +++ b/drivers/pci/access.c > @@ -207,14 +207,14 @@ static noinline void pci_wait_cfg(struct pci_dev *dev) > { > DECLARE_WAITQUEUE(wait, current); > > - __add_wait_queue(&pci_cfg_wait, &wait); > do { > set_current_state(TASK_UNINTERRUPTIBLE); > raw_spin_unlock_irq(&pci_lock); > + add_wait_queue(&pci_cfg_wait, &wait); > schedule(); > + remove_wait_queue(&pci_cfg_wait, &wait); > raw_spin_lock_irq(&pci_lock); > } while (dev->block_cfg_access); > - __remove_wait_queue(&pci_cfg_wait, &wait); > } > > /* Returns 0 on success, negative values indicate error. */ > -- > 2.19.1 > >