From patchwork Thu Oct 26 10:11:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shameer Kolothum X-Patchwork-Id: 10027939 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 A8AB36032C for ; Thu, 26 Oct 2017 10:13:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9729828D8A for ; Thu, 26 Oct 2017 10:13:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AF7628D90; Thu, 26 Oct 2017 10:13:08 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED 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 B8B8D28D8A for ; Thu, 26 Oct 2017 10:13:07 +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: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:In-Reply-To: List-Owner; bh=F8s1nL2cDvRYSKcwEy3xBa+9qF4/rGpcmlxkA64x0NA=; b=Gn09QPsSgoARpD sLz/xUMVKhOPJ95XEJxbVevLhXUSWgt8/6xV9lddx5rYEgbdWsDbjF8CELB+wJZEwzT1SZou3dLlD 2/mqBfUQccXEVjmNBp7ouDlveelEMLDB99EiW2Pos3DzOJIiFdaahV6VGFcTVJb2jrLu7+KredMvg vjcmdzRUCC8K8/0rnLqXg5WsmhnE5dRpiNyMg/13o9iSq3DuUZvbON1l8l00dlYuVE+rTy3TiHV2b 7+Q8B7rk2H4RP09ZyCFDmfOEKgcLDUAwzqn9nYOuVVpngXu41oDoxAEkzWkqkpXONQOggls4cyTyp FdZDO0/Kmrnl4rIUTq1A==; 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 1e7f9q-0005YE-6K; Thu, 26 Oct 2017 10:13:02 +0000 Received: from lhrrgout.huawei.com ([194.213.3.17]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e7f9k-0005Oi-2L for linux-arm-kernel@lists.infradead.org; Thu, 26 Oct 2017 10:12:59 +0000 Received: from 172.18.7.190 (EHLO LHREML712-CAH.china.huawei.com) ([172.18.7.190]) by lhrrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DRI97433; Thu, 26 Oct 2017 10:12:14 +0000 (GMT) Received: from FRAEML703-CAH.china.huawei.com (10.206.14.34) by LHREML712-CAH.china.huawei.com (10.201.108.35) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 26 Oct 2017 11:12:10 +0100 Received: from FRAEML521-MBX.china.huawei.com ([169.254.1.209]) by fraeml703-cah.china.huawei.com ([10.206.14.34]) with mapi id 14.03.0361.001; Thu, 26 Oct 2017 12:11:58 +0200 From: Shameerali Kolothum Thodi To: Robin Murphy , Will Deacon , "lorenzo.pieralisi@arm.com" Subject: RE: [PATCH v9 2/4] iommu/dma: Add a helper function to reserve HW MSI address regions for IOMMU drivers Thread-Topic: [PATCH v9 2/4] iommu/dma: Add a helper function to reserve HW MSI address regions for IOMMU drivers Thread-Index: AQHTPqx4nKCrhJeoMEGOMACd3y9xN6LiErgAgAShRACAAsgBgIAAO7awgAxPArA= Date: Thu, 26 Oct 2017 10:11:58 +0000 Message-ID: <5FC3163CFD30C246ABAA99954A238FA83844FE04@FRAEML521-MBX.china.huawei.com> References: <20171006140450.89652-1-shameerali.kolothum.thodi@huawei.com> <20171006140450.89652-3-shameerali.kolothum.thodi@huawei.com> <20171013192350.GA32130@arm.com> <5FC3163CFD30C246ABAA99954A238FA83844672A@FRAEML521-MBX.china.huawei.com> <1d49243a-4746-f189-7c5d-4b98937115fb@arm.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.202.227.237] MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A010205.59F1B501.0018, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=169.254.1.209, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: ce18925dd6d8647a9465f06fd9e1e0c4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171026_031256_860033_317194EC X-CRM114-Status: GOOD ( 37.21 ) 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: "sudeep.holla@arm.com" , Gabriele Paoloni , "marc.zyngier@arm.com" , "linux-pci@vger.kernel.org" , "joro@8bytes.org" , John Garry , Linuxarm , "linux-acpi@vger.kernel.org" , "iommu@lists.linux-foundation.org" , "Wangzhou \(B\)" , "Guohanjun \(Hanjun Guo\)" , "bhelgaas@google.com" , "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 Hi Lorenzo/Will, > -----Original Message----- > From: Shameerali Kolothum Thodi > Sent: Wednesday, October 18, 2017 3:24 PM > To: 'Robin Murphy' ; Will Deacon > > Cc: lorenzo.pieralisi@arm.com; Gabriele Paoloni > ; marc.zyngier@arm.com; linux- > pci@vger.kernel.org; joro@8bytes.org; John Garry ; > Guohanjun (Hanjun Guo) ; Linuxarm > ; linux-acpi@vger.kernel.org; iommu@lists.linux- > foundation.org; Wangzhou (B) ; > sudeep.holla@arm.com; bhelgaas@google.com; linux-arm- > kernel@lists.infradead.org; devel@acpica.org > Subject: RE: [PATCH v9 2/4] iommu/dma: Add a helper function to reserve HW > MSI address regions for IOMMU drivers > > > > > -----Original Message----- > > From: Robin Murphy [mailto:robin.murphy@arm.com] > > Sent: Wednesday, October 18, 2017 1:34 PM > > To: Shameerali Kolothum Thodi ; > > Will Deacon > > Cc: lorenzo.pieralisi@arm.com; Gabriele Paoloni > > ; marc.zyngier@arm.com; linux- > > pci@vger.kernel.org; joro@8bytes.org; John Garry > > ; Guohanjun (Hanjun Guo) > > ; Linuxarm ; > > linux-acpi@vger.kernel.org; iommu@lists.linux- foundation.org; > > Wangzhou (B) ; sudeep.holla@arm.com; > > bhelgaas@google.com; linux-arm- kernel@lists.infradead.org; > > devel@acpica.org > > Subject: Re: [PATCH v9 2/4] iommu/dma: Add a helper function to > > reserve HW MSI address regions for IOMMU drivers > > > > On 16/10/17 17:09, Shameerali Kolothum Thodi wrote: > > > Hi Robin, > > > > > >> -----Original Message----- > > >> From: Will Deacon [mailto:will.deacon@arm.com] > > >> Sent: Friday, October 13, 2017 8:24 PM > > >> To: Shameerali Kolothum Thodi > > >> > > >> Cc: lorenzo.pieralisi@arm.com; marc.zyngier@arm.com; > > >> sudeep.holla@arm.com; robin.murphy@arm.com; joro@8bytes.org; > > >> bhelgaas@google.com; Gabriele Paoloni > > >> ; John Garry ; > > >> iommu@lists.linux-foundation.org; > > >> linux-arm-kernel@lists.infradead.org; linux-acpi@vger.kernel.org; > > >> linux- pci@vger.kernel.org; devel@acpica.org; Linuxarm > > ; > > >> Wangzhou (B) ; Guohanjun (Hanjun Guo) > > >> > > >> Subject: Re: [PATCH v9 2/4] iommu/dma: Add a helper function to > > >> reserve > > HW > > >> MSI address regions for IOMMU drivers > > >> > > >> On Fri, Oct 06, 2017 at 03:04:48PM +0100, Shameer Kolothum wrote: > > >>> 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 | 20 ++++++++++++++++++++ > > >>> include/linux/dma-iommu.h | 7 +++++++ > > >>> 2 files changed, 27 insertions(+) > > >> > > >> I'd like to see Robin's Ack on this, because this is his code and > > >> he had ideas on ways to solve this problem properly. > > > > > > Please let us know if it is ok to go ahead with ACPI support for now. > > > It will help our customers to start using pass-through for PCIe. > > > > > > Thanks, > > > Shameer > > > > > >> > > >> Will > > >> > > >>> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > > >>> index 9d1cebe..bae677e 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 > > >>> @@ -27,6 +28,7 @@ > > >>> #include > > >>> #include > > >>> #include > > >>> +#include > > >>> #include > > >>> #include > > >>> #include > > >>> @@ -198,6 +200,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 > > > > This doesn't make an awful lot of sense - there's only one reserved > > region callback, so iommu-dma shouldn't be offering two separate and > > non-overlapping implementations. > > > > >>> + * 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_msi_get_resv_regions(dev, list); > > > > Either this call knows how to do the right thing for any platform and > > should be made from iommu_dma_get_reserved_regions() directly, or it's > > tightly coupled to the HiSilicon quirk in the SMMUv3 driver and > > iommu-dma doesn't need to know - the middle ground presented here is > > surely the worst of both worlds. > > Right. I think we have discussed this earlier[1] and had a v4 based on invoking > the iort_iommu_its_get_resv_regions() within the > iommu_dma_get_resv_regions(). > But later as you rightly pointed out, we were not checking for platforms which > requires this quirk inside the iort code and that will break the platforms which > are happy with MSI translations. Hence moved to the current implementation > in v6 after this discussion here[2] > > And earlier I think in the v3 version we had the function called from smmu > driver directly and the feedback was that it should be abstracted from the > driver. > > May be it is still possible to move the function call inside the > iommu_dma_get_resv_regions() and do the smmu model check inside the iort > helper function and selectively apply the HW MSI reservations. > > But I think it is much neater if we can invoke the iort_get_msi_regions() > directly from SMMUv3 based on the model. > > Thoughts? As we still don’t have a clear resolution on how to invoke the iort_iommu_msi_get_resv_regions(), I have gone back and attempted to move the smmu model check inside the iort code. This means the function will selectively apply HW MSI reservation based on the platform and also the function can be invoked from the iommu_dma_get_resv_regions() directly. Could you please take a look at the below snippet and let me know your feedback. Hope we can make some progress on this series. Thanks, Shameer -->8-- -->8-- diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index 876c0e1..a27233d 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -619,6 +619,39 @@ static int __maybe_unused __get_pci_rid(struct pci_dev *pdev, u16 alias, return 0; } +static bool __maybe_unused iort_hw_msi_resv_enable(struct device *dev, + struct acpi_iort_node *node) +{ + struct acpi_iort_node *iommu = NULL; + int i; + + if (dev_is_pci(dev)) { + u32 rid; + + pci_for_each_dma_alias(to_pci_dev(dev), __get_pci_rid, &rid); + iommu = iort_node_map_id(node, rid, NULL, IORT_IOMMU_TYPE); + } else { + for (i = 0; i < node->mapping_count; i++) { + iommu = iort_node_map_platform_id(node, NULL, + IORT_IOMMU_TYPE, i); + if (iommu) + break; + } + } + + if (iommu && (iommu->type == ACPI_IORT_NODE_SMMU_V3)) { + struct acpi_iort_smmu_v3 *smmu; + + smmu = (struct acpi_iort_smmu_v3 *)iommu->node_data; + if (smmu->model == ACPI_IORT_SMMU_V3_HISILICON_HI161X) { + dev_notice(dev, "Enabling HiSilicon erratum 161010801\n"); + return true; + } + } + + return false; +} + static int arm_smmu_iort_xlate(struct device *dev, u32 streamid, struct fwnode_handle *fwnode, const struct iommu_ops *ops) @@ -682,6 +715,9 @@ int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head) if (!node) return -ENODEV; + if (!iort_hw_msi_resv_enable(dev, node)) + return 0; + /* * Current logic to reserve ITS regions relies on HW topologies * where a given PCI or named component maps its IDs to only one diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 9d1cebe..67c6e30 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 @@ -174,6 +175,10 @@ void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list) struct pci_host_bridge *bridge; struct resource_entry *window; + if (!is_of_node(dev->iommu_fwspec->iommu_fwnode) && + iort_iommu_msi_get_resv_regions(dev, list) < 0) + return; + if (!dev_is_pci(dev)) return; diff --git a/include/linux/acpi_iort.h b/include/linux/acpi_iort.h index 182a577..88f17c9 100644 --- a/include/linux/acpi_iort.h +++ b/include/linux/acpi_iort.h @@ -56,7 +56,7 @@ const struct iommu_ops *iort_iommu_configure(struct device *dev) { return NULL; } static inline int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head) -{ return -ENODEV; } +{ return 0; } #endif #endif /* __ACPI_IORT_H__ */