Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3922287imm; Tue, 11 Sep 2018 04:20:16 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaRW94rIs6MttVS3cVzBMgO0dBTnJJ0egsPCiURZJZwhGT8aFtQQt6CxEHXwVqD7+ITmiP/ X-Received: by 2002:a62:41d6:: with SMTP id g83-v6mr28921723pfd.219.1536664816054; Tue, 11 Sep 2018 04:20:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536664816; cv=none; d=google.com; s=arc-20160816; b=WoIp4KtuAsA9ZjjT6u6y/fGWrtlRwhXzqDpnMGHUr3zFiGWP9QhBH8+WctR7eWLvaZ /ydDcQX/Pw8ghCk7FlM98uVSmlAlvklA5/SjpxSc2rFgphIXRZS2ZOpWKThlm/emd4oG XkOo/2/Ee/r1xrZ6VGWFweZAKd1xGIGHmNxVp4MV96+s08zYlETwM4K8vm9hzp4FfWqX vlkjMyFczEvkv1d2dKxgdDCsRkrMWRkdqn9D2dacJmk0QTFwwpQzcjWZ/AgxZbg5sZU/ VxOZevbuEGLq+7ZxOmpIdhNI6kO/ApPs1DNUqiIyNl9jO1FsHNwCw0asoYuAfoIDjwog KWaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=5l4q6dytCDXg8DgZ90+MSZBX3Wn4E5laJqCvUaIeMQI=; b=CNh7uvZS5INmjAofimkvZG6Xk2CBWs3jZuXY6YafHHsC9jOms+k6Oq/G77uei2DZMR bYms7Nk4RYg/ghOAkGDLXS5u0nZN6HN2/YYbS/yz7UGiaKnjlKxcbcG6icXo2voFstai bfe80vuUrJInZiZf3U0GDOG/mr/f/JciUgghl7ZVpjxi7smTs3Pdn4P5zxKYO08caZd+ TXvzuDoaAa/gBLj0HKLISZSdeVVRr8jCZKvjHKUdj7cW28u2KoTG6jk35HQgrsaZY+YY nds+/Y5MxHAI4UhKJvhOdYVN007mQZd6PLCAO8L/3W61yFv3pAupoGn8eBH4TV4bMOyy 720g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=j18luMTy; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z12-v6si20872702pgz.665.2018.09.11.04.19.59; Tue, 11 Sep 2018 04:20:16 -0700 (PDT) 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=@163.com header.s=s110527 header.b=j18luMTy; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727006AbeIKQSM (ORCPT + 99 others); Tue, 11 Sep 2018 12:18:12 -0400 Received: from m12-18.163.com ([220.181.12.18]:60846 "EHLO m12-18.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726601AbeIKQSL (ORCPT ); Tue, 11 Sep 2018 12:18:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Subject:From:Message-ID:Date:MIME-Version; bh=5l4q6 dytCDXg8DgZ90+MSZBX3Wn4E5laJqCvUaIeMQI=; b=j18luMTy+hg/hyqDuJWTH neMZg5xEOyDhI7ejJha1NfM5wQp1BhKa6H4oCLzALwEXFIlcZavZskx2fou2L++w hdNl+ux+W1ek/4f8gA+E15wvaz4e2V7ZLf7Vl49VzazlVsQZoJTzq37gvl9bXex+ q5bCXm91t91tx+BJsH/7cc= Received: from [166.111.71.58] (unknown [166.111.71.58]) by smtp14 (Coremail) with SMTP id EsCowAAncCCOpJdbZRitSw--.10141S2; Tue, 11 Sep 2018 19:18:38 +0800 (CST) Subject: Re: [PATCH] pci: dwc: pcie_designware: Fix a sleep-in-atomic-context bug in dw_pcie_prog_outbound_atu To: Gustavo Pimentel , Jia-Ju Bai , "jingoohan1@gmail.com" , "Joao.Pinto@synopsys.com" , "lorenzo.pieralisi@arm.com" , "bhelgaas@google.com" Cc: "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" References: <20180902033811.26858-1-baijiaju1990@gmail.com> From: Jia-Ju Bai Message-ID: Date: Tue, 11 Sep 2018 19:18:38 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-CM-TRANSID: EsCowAAncCCOpJdbZRitSw--.10141S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxKF4rCryUJw1xuw43GrW3KFg_yoW7XryrpF W5JFWSya48JFs0vayava4rZry5JanrAFWUGr4Sgas7WF17ZFy7K3WkJay3tr12qr4jqr12 krWrt3Z3GF15A3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07beyCXUUUUU= X-Originating-IP: [166.111.71.58] X-CM-SenderInfo: xedlyx5dmximizq6il2tof0z/1tbiYw6+elaD0mCpBAAAsj Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018/9/11 16:40, Gustavo Pimentel wrote: > Hi Jia, > > On 02/09/2018 04:38, Jia-Ju Bai wrote: >> The driver may sleep with holding a spinlock and in an interupt handler. >> >> The function call paths (from bottom to top) in Linux-4.16 are: >> >> [FUNC] usleep_range >> drivers/pci/dwc/pcie-designware.c, 181: >> usleep_range in dw_pcie_prog_outbound_atu >> drivers/pci/dwc/pcie-designware-host.c, 479: >> dw_pcie_prog_outbound_atu in dw_pcie_rd_other_conf >> drivers/pci/dwc/pcie-designware-host.c, 561: >> dw_pcie_rd_other_conf in dw_pcie_rd_conf >> drivers/pci/access.c, 66: >> [FUNC_PTR]dw_pcie_rd_conf in pci_bus_read_config_word >> drivers/pci/access.c, 918: >> pci_bus_read_config_word in pci_read_config_word >> drivers/block/umem.c, 630: >> pci_read_config_word in mm_interrupt (interrupt handler) >> >> [FUNC] usleep_range >> drivers/pci/dwc/pcie-designware.c, 181: >> usleep_range in dw_pcie_prog_outbound_atu >> drivers/pci/dwc/pcie-designware-host.c, 479: >> dw_pcie_prog_outbound_atu in dw_pcie_rd_other_conf >> drivers/pci/dwc/pcie-designware-host.c, 561: >> dw_pcie_rd_other_conf in dw_pcie_rd_conf >> drivers/pci/access.c, 66: >> [FUNC_PTR]dw_pcie_rd_conf in pci_bus_read_config_word >> drivers/pci/access.c, 918: >> pci_bus_read_config_word in pci_read_config_word >> drivers/ata/pata_efar.c, 115: >> pci_read_config_word in efar_set_piomode >> drivers/ata/pata_efar.c, 113: >> _raw_spin_lock_irqsave in efar_set_piomod >> >> [FUNC] usleep_range >> drivers/pci/dwc/pcie-designware.c, 181: >> usleep_range in dw_pcie_prog_outbound_atu >> drivers/pci/dwc/pcie-designware-host.c, 479: >> dw_pcie_prog_outbound_atu in dw_pcie_rd_other_conf >> drivers/pci/dwc/pcie-designware-host.c, 561: >> dw_pcie_rd_other_conf in dw_pcie_rd_conf >> drivers/pci/access.c, 66: >> [FUNC_PTR]dw_pcie_rd_conf in pci_bus_read_config_word >> drivers/pci/access.c, 918: >> pci_bus_read_config_word in pci_read_config_word >> drivers/block/mtip32xx/mtip32xx.c, 158: >> pci_read_config_word in mtip_check_surprise_removal >> drivers/block/mtip32xx/mtip32xx.c, 843: >> mtip_check_surprise_removal in mtip_handle_irq >> drivers/block/mtip32xx/mtip32xx.c, 879: >> mtip_handle_irq in mtip_irq_handler (interrupt handler) >> >> [FUNC] usleep_range >> drivers/pci/dwc/pcie-designware.c, 181: >> usleep_range in dw_pcie_prog_outbound_atu >> drivers/pci/dwc/pcie-designware-host.c, 479: >> dw_pcie_prog_outbound_atu in dw_pcie_rd_other_conf >> drivers/pci/dwc/pcie-designware-host.c, 561: >> dw_pcie_rd_other_conf in dw_pcie_rd_conf >> drivers/pci/access.c, 66: >> [FUNC_PTR]dw_pcie_rd_conf in pci_bus_read_config_word >> drivers/pci/access.c, 918: >> pci_bus_read_config_word in pci_read_config_word >> drivers/gpu/vga/vgaarb.c, 645: >> pci_read_config_word in vga_arbiter_add_pci_device >> drivers/gpu/vga/vgaarb.c, 629: >> _raw_spin_lock_irqsave in vga_arbiter_add_pci_device >> >> [FUNC] usleep_range >> drivers/pci/dwc/pcie-designware.c, 181: >> usleep_range in dw_pcie_prog_outbound_atu >> drivers/pci/dwc/pcie-designware-host.c, 479: >> dw_pcie_prog_outbound_atu in dw_pcie_rd_other_conf >> drivers/pci/dwc/pcie-designware-host.c, 561: >> dw_pcie_rd_other_conf in dw_pcie_rd_conf >> drivers/pci/access.c, 66: >> [FUNC_PTR]dw_pcie_rd_conf in pci_bus_read_config_word >> drivers/pci/access.c, 918: >> pci_bus_read_config_word in pci_read_config_word >> drivers/pci/ats.c, 139: >> pci_read_config_word in pci_ats_queue_depth >> drivers/iommu/intel-iommu.c, 1519: >> pci_ats_queue_depth in iommu_enable_dev_iotlb >> drivers/iommu/intel-iommu.c, 5295: >> iommu_enable_dev_iotlb in intel_iommu_enable_pasid >> drivers/iommu/intel-iommu.c, 5241: >> _raw_spin_lock_irqsave in intel_iommu_enable_pasid >> >> To fix this bug, usleep_range() is replaced with udelay(). >> >> This bug is found by my static analysis tool DSAC. >> >> Signed-off-by: Jia-Ju Bai >> --- >> drivers/pci/controller/dwc/pcie-designware.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c >> index 778c4f76a884..7f50f7e51543 100644 >> --- a/drivers/pci/controller/dwc/pcie-designware.c >> +++ b/drivers/pci/controller/dwc/pcie-designware.c >> @@ -135,7 +135,7 @@ static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index, >> if (val & PCIE_ATU_ENABLE) >> return; >> >> - usleep_range(LINK_WAIT_IATU_MIN, LINK_WAIT_IATU_MAX); >> + udelay(LINK_WAIT_IATU_MAX); > You might use the mdelay instead of udelay, however this fix and others were > already made on patch on [1] > > [1] https://lkml.org/lkml/2018/9/10/284 > Okay, that is good. Best wishes, Jia-Ju Bai