From patchwork Tue Aug 8 09:49:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 9887299 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F120360384 for ; Tue, 8 Aug 2017 09:51:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E232328776 for ; Tue, 8 Aug 2017 09:51:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6CC028794; Tue, 8 Aug 2017 09:51:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3BC2C28776 for ; Tue, 8 Aug 2017 09:51:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EDQ7z795yj6uR42MBMJPd7aznnhLBIGG0hj6M4cfdv0=; b=QaEH+dSPbbIP9F Ol+ZyPF1zGgsMrvBzrSd1MonOQ27WXus0ZMDxWBxgEsILM3YvhHGl7scLq8FXSiwnxojqdjNMLvW7 HNLFGQBGi6OTo/ED1IQ7bvpOzOpwbisXR58xaJZM7+KsIdAw2ZOBDsSajSPa5GjKJpXLriCn8ZfsR 3FMMBH7w2f7uWhccRh17H2mhaTH9E6DBcyeMh9TVENPXDfRyRqh81wpu+1560JZ5KiAaZA84jfxZp wEx1H+cwf62P9F9pG1a8idGXSIktjT2cmjNVNnkfNCLpEJ+OJlF6B+MCav7fKqHKu2b5IvCxkuhwX AQjzAScm1N5VcUyWOrIQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1df1AM-0006vq-G9; Tue, 08 Aug 2017 09:51:10 +0000 Received: from lhrrgout.huawei.com ([194.213.3.17]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1df1AH-0006tj-LE for linux-arm-kernel@lists.infradead.org; Tue, 08 Aug 2017 09:51:08 +0000 Received: from 172.18.7.190 (EHLO lhreml708-cah.china.huawei.com) ([172.18.7.190]) by lhrrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DME46863; Tue, 08 Aug 2017 09:50:00 +0000 (GMT) Received: from FRAEML702-CAH.china.huawei.com (10.206.14.33) by lhreml708-cah.china.huawei.com (10.201.108.49) with Microsoft SMTP Server (TLS) id 14.3.301.0; Tue, 8 Aug 2017 10:49:57 +0100 Received: from FRAEML521-MBX.china.huawei.com ([169.254.1.170]) by fraeml702-cah.china.huawei.com ([10.206.14.33]) with mapi id 14.03.0301.000; Tue, 8 Aug 2017 11:49:51 +0200 From: Shameerali Kolothum Thodi To: Lorenzo Pieralisi Subject: RE: [PATCH v5 1/2] ACPI/IORT: Add ITS address regions reservation helper Thread-Topic: [PATCH v5 1/2] ACPI/IORT: Add ITS address regions reservation helper Thread-Index: AQHTCrQr2b2WEE81GUGLjjJZ701LDaJ0Tn8AgARDhkCAAHbdgIABNPzQ Date: Tue, 8 Aug 2017 09:49:51 +0000 Message-ID: <5FC3163CFD30C246ABAA99954A238FA8383C8FED@FRAEML521-MBX.china.huawei.com> References: <20170801104913.71912-1-shameerali.kolothum.thodi@huawei.com> <20170801104913.71912-2-shameerali.kolothum.thodi@huawei.com> <5FC3163CFD30C246ABAA99954A238FA8383C7EF8@FRAEML521-MBX.china.huawei.com> <20170807170921.GB27830@red-moon> In-Reply-To: <20170807170921.GB27830@red-moon> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.203.177.212] MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090202.59898949.006B, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=169.254.1.170, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 4d4b8ee981c3733da498a3faba3ff687 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170808_025106_212251_E9463A6B X-CRM114-Status: GOOD ( 32.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Guohanjun \(Hanjun Guo\)" , Gabriele Paoloni , "marc.zyngier@arm.com" , John Garry , "will.deacon@arm.com" , Linuxarm , "linux-acpi@vger.kernel.org" , "iommu@lists.linux-foundation.org" , "hanjun.guo@linaro.org" , "Wangzhou \(B\)" , "sudeep.holla@arm.com" , Robin Murphy , "linux-arm-kernel@lists.infradead.org" , "devel@acpica.org" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP > -----Original Message----- > From: Lorenzo Pieralisi [mailto:lorenzo.pieralisi@arm.com] > Sent: Monday, August 07, 2017 6:09 PM > To: Shameerali Kolothum Thodi > Cc: Robin Murphy; marc.zyngier@arm.com; sudeep.holla@arm.com; > will.deacon@arm.com; hanjun.guo@linaro.org; Gabriele Paoloni; John Garry; > Linuxarm; linux-acpi@vger.kernel.org; iommu@lists.linux-foundation.org; > Wangzhou (B); Guohanjun (Hanjun Guo); linux-arm- > kernel@lists.infradead.org; devel@acpica.org > Subject: Re: [PATCH v5 1/2] ACPI/IORT: Add ITS address regions reservation > helper > > On Mon, Aug 07, 2017 at 08:21:40AM +0000, Shameerali Kolothum Thodi > wrote: > > > > > > > -----Original Message----- > > > From: Robin Murphy [mailto:robin.murphy@arm.com] > > > Sent: Friday, August 04, 2017 5:57 PM > > > To: Shameerali Kolothum Thodi; lorenzo.pieralisi@arm.com; > > > marc.zyngier@arm.com; sudeep.holla@arm.com; will.deacon@arm.com; > > > hanjun.guo@linaro.org > > > Cc: Gabriele Paoloni; John Garry; iommu@lists.linux-foundation.org; > linux- > > > arm-kernel@lists.infradead.org; linux-acpi@vger.kernel.org; > > > devel@acpica.org; Linuxarm; Wangzhou (B); Guohanjun (Hanjun Guo) > > > Subject: Re: [PATCH v5 1/2] ACPI/IORT: Add ITS address regions > reservation > > > helper > > > > > > On 01/08/17 11:49, Shameer Kolothum wrote: > > > > On some platforms ITS address regions have to be excluded from > normal > > > > IOVA allocation in that they are detected and decoded in a HW specific > > > > way by system components and so they cannot be considered normal > > > IOVA > > > > address space. > > > > > > > > Add an helper function that retrieves ITS address regions through IORT > > > > device <-> ITS mappings and reserves it so that these regions will not > > > > be translated by IOMMU and will be excluded from IOVA allocations. > > > > > > I've just realised that we no longer seem to have a check that ensures > > > the regions are only reserved on platforms that need it - if not, then > > > we're going to break everything else that does have an ITS behind SMMU > > > translation as expected. > > > > Right. I had this doubt, but then my thinking was that we will have the > SW_MSI > > regions for those and will end up using that. But that doesn’t seems > > to be the case now. > > > > > It feels like IORT should know enough to be able to make that decision > > > internally, but if not (or if it would be hideous to do so), then I > > > guess my idea for patch #2 was a bust and we probably do need to go > back > > > to calling directly from the SMMU driver based on the SMMU model. > > > > It might be possible to do that check inside iort code, but then we have to > find > > the smmu node first and check the model number. I think it will be more > > cleaner if SMMU driver makes that check and call the > > iommu_dma_get_msi_resv_regions(). > > +1 on this one - we can do it in IORT but I think it is more logical > to have a flag in the SMMU driver (keeping the DT/ACPI fwnode switch in > generic IOMMU layer though). Please find [1] for the generic iommu helper function which will be called from SMMU driver based on the model. > Side note I: AFAICS iommu_dma_get_resv_regions() is only used on ARM, if > it is not patch 2 would break miserably on arches that do not select > IORT - you should rework the return code on !CONFIG_ACPI_IORT configs. Yes. But so far it is only used on ARM. In any way this function is not going to be changed and will introduce a new iommu_dma_get_msi_resv_regions() fn as proposed in [1]. Please take a look and let me know. I will submit the series again if this is fine. Thanks, Shameer [1] This will replace patch 2 and will be followed by smmu driver patch to invoke iommu_dma_get_msi_resv_regions() based on SMMU model. -->8-- Subject: [PATCH] iommu/dma: Add a helper function to reserve HW MSI address regions for IOMMU drivers IOMMU drivers can use this to implement their .get_resv_regions callback for HW MSI specific reservations(e.g. ARM GICv3 ITS MSI region). Signed-off-by: Shameer Kolothum --- drivers/iommu/dma-iommu.c | 19 +++++++++++++++++++ include/linux/dma-iommu.h | 7 +++++++ 2 files changed, 26 insertions(+) -- 1.9.1 diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 9d1cebe..952ecdd 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -19,6 +19,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -198,6 +199,24 @@ void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list) } EXPORT_SYMBOL(iommu_dma_get_resv_regions); +/** + * iommu_dma_get_msi_resv_regions - Reserved region driver helper + * @dev: Device from iommu_get_resv_regions() + * @list: Reserved region list from iommu_get_resv_regions() + * + * IOMMU drivers can use this to implement their .get_resv_regions + * callback for HW MSI specific reservations. For now, this only + * covers ITS MSI region reservation using ACPI IORT helper function. + */ +int iommu_dma_get_msi_resv_regions(struct device *dev, struct list_head *list) +{ + if (!is_of_node(dev->iommu_fwspec->iommu_fwnode)) + return iort_iommu_its_get_resv_regions(dev, list); + + return -ENODEV; +} +EXPORT_SYMBOL(iommu_dma_get_msi_resv_regions); + static int cookie_init_hw_msi_region(struct iommu_dma_cookie *cookie, phys_addr_t start, phys_addr_t end) { diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h index 92f2083..6062ef0 100644 --- a/include/linux/dma-iommu.h +++ b/include/linux/dma-iommu.h @@ -74,6 +74,8 @@ void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle, void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg); void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list); +int iommu_dma_get_msi_resv_regions(struct device *dev, struct list_head *list); + #else struct iommu_domain; @@ -107,6 +109,11 @@ static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_he { } +static inline int iommu_dma_get_msi_resv_regions(struct device *dev, struct list_head *list) +{ + return -ENODEV; +} + #endif /* CONFIG_IOMMU_DMA */ #endif /* __KERNEL__ */ #endif /* __DMA_IOMMU_H */