From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE979C77B7F for ; Wed, 3 May 2023 10:59:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=011Bmv7SVdanmvOzCMsCI7NSLQTB0J3BFxucb3LKq+M=; b=Ni/nhSgnokdzrA JqNGNfFJ0Z5tZMeG/qqzRKM2Q+Q0PeXvoEf+tQ/I/jKXJS/tZbc55nDBiYMuBE/ozy7tXPDpF0to/ bkcHhjqsemvT5C/wVoBwIOtouXWofYyLPOAP4abbtEcfMuguHXArTM60fINs0BEQAFLS+94+JBAig hC+1Iu+Cc7gfe4fCOrh+vTnvkrJJD81Ci6ySZnRSvR8MZUb7Bbe/yTyZ6D8137CmCpAj0pSBNzE/r MTgrf+abrV3rRpMphJ99cOh3ai+OP0m0TNXeFA/zCEUatQDjYrE78SaRWpnygxN/K7GwIV7bW4juF eyVVsMUCGuFzj0830iKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1puABg-004KAx-2R; Wed, 03 May 2023 10:58:20 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1puABc-004K9Z-2h; Wed, 03 May 2023 10:58:18 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E71872F4; Wed, 3 May 2023 03:58:53 -0700 (PDT) Received: from [10.57.82.232] (unknown [10.57.82.232]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 499853F67D; Wed, 3 May 2023 03:58:04 -0700 (PDT) Message-ID: <32aa1228-3eb9-340a-41e7-88fdd7c0a5ac@arm.com> Date: Wed, 3 May 2023 11:57:59 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: [PATCH 04/20] iommu/fsl_pamu: Replace set_platform_dma_ops() with IOMMU_DOMAIN_PLATFORM Content-Language: en-GB To: Jason Gunthorpe , Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Marek Szyprowski , Matthias Brugger , Matthew Rosato , Orson Zhai , Rob Clark , Samuel Holland , Niklas Schnelle , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Kevin Tian , Nicolin Chen , Steven Price References: <4-v1-21cc72fcfb22+a7a-iommu_all_defdom_jgg@nvidia.com> From: Robin Murphy In-Reply-To: <4-v1-21cc72fcfb22+a7a-iommu_all_defdom_jgg@nvidia.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230503_035816_972503_2775F561 X-CRM114-Status: GOOD ( 28.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2023-05-01 19:02, Jason Gunthorpe wrote: > It is not clear what this is actually doing, most likely this is IDENTITY > behavior, but I think there is a chance it is BLOCKING given how the PAMU > stuff is oddly used. Logically it has to be identity, since there are no DMA ops interacting with this driver (it's not the TCE IOMMU of arch/powerpc/kernel/iommu.c), so any device using a kernel driver rather than VFIO must be using dma-direct and thus require an identity mapping. At this point I finally got sufficiently fed up of this driver always being the mystery weirdo and tracked down an old QorIQ reference manual, and now I have about half an hours' worth of understanding of how the PAMU actually works. Based on that, what setup_liodns() is doing is indeed setting up identity for everything initially. It also becomes apparent that it's never supported giving a PCI device back to its regular driver after using vfio-pci, since an attach/detach cycle will then leave the PPAACE invalid and thus DMA blocked. Oh well, that's been broken for 10 years; nobody cares. Call it an identity domain and move on. Thanks, Robin. > Signed-off-by: Jason Gunthorpe > --- > drivers/iommu/fsl_pamu_domain.c | 29 ++++++++++++++++++++++++++--- > 1 file changed, 26 insertions(+), 3 deletions(-) > > diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c > index bce37229709965..4c65f1adfe7511 100644 > --- a/drivers/iommu/fsl_pamu_domain.c > +++ b/drivers/iommu/fsl_pamu_domain.c > @@ -283,15 +283,28 @@ static int fsl_pamu_attach_device(struct iommu_domain *domain, > return ret; > } > > -static void fsl_pamu_set_platform_dma(struct device *dev) > +/* > + * FIXME: This seems to turn off the iommu HW but it is not obvious what state > + * it leaves the HW in. This is probably really a BLOCKING or IDENTITY domain. > + * For now this ensures that the old detach_dev behavior functions about the > + * same as it always did, and we turn off the IOMMU whenever the UNMANAGED > + * domain is detached. > + */ > +static int fsl_pamu_platform_attach(struct iommu_domain *platform_domain, > + struct device *dev) > { > struct iommu_domain *domain = iommu_get_domain_for_dev(dev); > - struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain); > + struct fsl_dma_domain *dma_domain; > const u32 *prop; > int len; > struct pci_dev *pdev = NULL; > struct pci_controller *pci_ctl; > > + if (domain == platform_domain || !domain) > + return 0; > + > + dma_domain = to_fsl_dma_domain(domain); > + > /* > * Use LIODN of the PCI controller while detaching a > * PCI device. > @@ -312,8 +325,18 @@ static void fsl_pamu_set_platform_dma(struct device *dev) > detach_device(dev, dma_domain); > else > pr_debug("missing fsl,liodn property at %pOF\n", dev->of_node); > + return 0; > } > > +static struct iommu_domain_ops fsl_pamu_platform_ops = { > + .attach_dev = fsl_pamu_platform_attach, > +}; > + > +static struct iommu_domain fsl_pamu_platform_domain = { > + .type = IOMMU_DOMAIN_PLATFORM, > + .ops = &fsl_pamu_platform_ops, > +}; > + > /* Set the domain stash attribute */ > int fsl_pamu_configure_l1_stash(struct iommu_domain *domain, u32 cpu) > { > @@ -448,11 +471,11 @@ static struct iommu_device *fsl_pamu_probe_device(struct device *dev) > } > > static const struct iommu_ops fsl_pamu_ops = { > + .default_domain = &fsl_pamu_platform_domain, > .capable = fsl_pamu_capable, > .domain_alloc = fsl_pamu_domain_alloc, > .probe_device = fsl_pamu_probe_device, > .device_group = fsl_pamu_device_group, > - .set_platform_dma_ops = fsl_pamu_set_platform_dma, > .default_domain_ops = &(const struct iommu_domain_ops) { > .attach_dev = fsl_pamu_attach_device, > .iova_to_phys = fsl_pamu_iova_to_phys, _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel