Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3774597imm; Tue, 11 Sep 2018 01:43:38 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb20+lJDTjldi2paOduMgvfPvheH/OQDvhJjHFI55t3Rri6BBjIE9V4+6TF30iho7OPfcpO X-Received: by 2002:a62:3ac8:: with SMTP id v69-v6mr28111343pfj.164.1536655418173; Tue, 11 Sep 2018 01:43:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536655418; cv=none; d=google.com; s=arc-20160816; b=PSnxXgyz9dHMgwxaHH13dUiv+elIRD7hQhesm2w2aNM3WVHk/Q1mcaM/s3cEhos6dJ jhKD3LhiRLhdYr01131RIFwtCz3ba5XLTfVPl7sJeXVMXTl3qejKSPG8s+Ew1x2kNfS4 7fUX7X6CT1bcgwHFNUCBnLuwCvbXqoRRp713HLMi5Wbbw3Nrb3O+xV5JM3BG8mDINh99 gMGS5oDsohgVcBt7Cq1DJBTdN3bLGuKZjEE21scO9u3h+CgiPLQeIlhf3YWrfeDWDu9T UexEf7M5OhhymXBDTyadEH9UDtrnBmuFHHu7JedBMCyiUiythMgC1dirNoxa+NoENGq2 hXvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=wJGRwCTJt+e6C0TaDJkGyfIdIrsDXviI3msLqj5X4Po=; b=C2eYes0dcN8/jkxqub+UzVdXFbINjFjGeXKX18X9+fpphPrR8miwlTwVLugd7obmJl oMN98DaK/EvuDpwXmd4F+/OryOEawSTQQvP8dGQbXCdhs5Uy6kNH1TQWzPM3TjxzypyP NHl58yTx/8ZwouyTvdhHKjF+w3YtidxqsHQPFLkQlJrWvVl1EoLBRiKpEpHZ/4nIp9Pb ougsG2M3W8A6uVNDudOJL+aFtH2mkF3kmQ0nDKh5TtT1PTzoFGzmKP2HP0hqNH4R+DIq MoBPE4lv7j5Q2RNZEsyIsDG+C+nIqIYpRfrBsKeYR82VHZVDN/n/Eh6z9DGrwiPRGyxN BQew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=kuYQF8V5; 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=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 14-v6si18844029pgc.179.2018.09.11.01.43.22; Tue, 11 Sep 2018 01:43:38 -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=@synopsys.com header.s=mail header.b=kuYQF8V5; 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=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726569AbeIKNld (ORCPT + 99 others); Tue, 11 Sep 2018 09:41:33 -0400 Received: from us01smtprelay-2.synopsys.com ([198.182.47.9]:43872 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726488AbeIKNlc (ORCPT ); Tue, 11 Sep 2018 09:41:32 -0400 Received: from mailhost.synopsys.com (mailhost3.synopsys.com [10.12.238.238]) by smtprelay.synopsys.com (Postfix) with ESMTP id 9257C24E204C; Tue, 11 Sep 2018 01:43:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1536655396; bh=ZuGLnWRSGnnMXa7CuOJXAWAylDoIpxdIpDx4Q6Ehztc=; h=Subject:To:CC:References:From:Date:In-Reply-To:From; b=kuYQF8V5M7tEy+tEB9fq1PFqv6xO+orSYjIzs/5Sjm5tbfid5rtU4016JLeklSDbc 8Hb9pqTXkBWEEswSkwgKqs0v2hrWLt58hdA8NOtaPEBBNFkJW5591tFatCbGQpJT0H ystVHj63CQN2vt/bp8hqCQdbRNfZSSF0jMeDqp0rXl9sv/qIYTcwHd0x86uCoaLNGn pt7p51XuWsmoAKDR/ZLzIzucHDDoWGLCZj8sDmCY/L1G5p66zJtEeKMz2E8+7agHj9 7tJQ6dQWfHJL3ux5wAXgTz0eBDeIwJrksoIV3nPKt39wYclGFM8R7wQ9TZci1LTH08 0+QEDaWnzmCrw== Received: from US01WEHTC3.internal.synopsys.com (us01wehtc3.internal.synopsys.com [10.15.84.232]) by mailhost.synopsys.com (Postfix) with ESMTP id 6838A3262; Tue, 11 Sep 2018 01:43:16 -0700 (PDT) Received: from DE02WEHTCA.internal.synopsys.com (10.225.19.92) by US01WEHTC3.internal.synopsys.com (10.15.84.232) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 11 Sep 2018 01:43:16 -0700 Received: from DE02WEHTCB.internal.synopsys.com (10.225.19.94) by DE02WEHTCA.internal.synopsys.com (10.225.19.92) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 11 Sep 2018 10:43:14 +0200 Received: from [10.107.25.102] (10.107.25.102) by DE02WEHTCB.internal.synopsys.com (10.225.19.80) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 11 Sep 2018 10:43:13 +0200 Subject: Re: [PATCH] pci: dwc: pcie_designware: Fix a sleep-in-atomic-context bug in dw_pcie_prog_outbound_atu To: 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: Gustavo Pimentel Message-ID: Date: Tue, 11 Sep 2018 09:40:12 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180902033811.26858-1-baijiaju1990@gmail.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.107.25.102] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Regards, Gustavo > } > dev_err(pci->dev, "Outbound iATU is not being enabled\n"); > } >