Message ID | b7cd933aa7774ad687c695ebe5e00c17178a7542.1694693889.git.robin.murphy@arm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1188998vqi; Fri, 15 Sep 2023 09:59:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+1Hp3CYo7P6zxlehXp0Dyv8Q534QP0ykGTWnu+0aiRgNpzzLHx79dkWerntmbw1f5kpFK X-Received: by 2002:a17:90b:ed7:b0:273:e0b6:661 with SMTP id gz23-20020a17090b0ed700b00273e0b60661mr1987616pjb.46.1694797157648; Fri, 15 Sep 2023 09:59:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694797157; cv=none; d=google.com; s=arc-20160816; b=yh4K8KrVpPi9ol359BXzoO0sk2WA78bWF3p7ORRfNYvSWHjaUn1NvfKUT6K7dDHY+z 6MwunR8AEqTlxgphX8ChF6155YVnVwt4TaYcFIPujTdnaMbRc1hXiE7KCLErNQXtcu0b XfgrTv8Z8YxxxZA9BIRFpXyo9BjywsZeyHX7c+uRsbt9axDK5PkusicGB78BAbqgimmI RJwMQyYSYdMDIAjw9/gO1TXYzrWNTJHJ1VTUcxsr6m4YZlfUAyp61UR06B82vfqO9TiV d12dNaft55t2c7IcQpsjReW5dQvBXcbPQG9b9vmCnf+HxevvoY3sC9csctGlhzBouj4i Kt2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=U1E2pjYwkQYyhMjbP9CzGox+91wcBiGJths0GMiXitI=; fh=3SO4sBNpOFNxfB4XNpCUWqe4lDXSOQ4O5f1XEPxUZRQ=; b=A4Q70a1/Yb2FChaoMwyCV4gDbqZFBt476QqSjFKnH4rfeo8HYk1hP3aIxBUSpXlLFo qqRFJrpLbnMgmBqZ4KFSkrE1c6qGNCgtPmfxtD3lO2xFhrfU8oTrt3yy+PIf0pLDe2Wm ZpLR7Lc/tQ4BLhPvwkCFdzj3DbPI1wOydavMaiJm6v9q6q70k6FoXzE7q3t+PTMCqrXF fcnJ20PHibc8gRhiJx494csgV4bDbhMxjil3rRizskvlAgYfl92MVskMbrlxxWbtPK+b qsQg92JMIcd5V+GdcddIhXT14ejO8ik/7zL5DddeDuMVbtoJFF0ZUyL8z7MywGbUNWud HHWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id z3-20020a633303000000b00573f9d916fbsi3543897pgz.784.2023.09.15.09.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 09:59:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id BD87082E555A; Fri, 15 Sep 2023 09:59:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234981AbjIOQ6n (ORCPT <rfc822;ruipengqi7@gmail.com> + 30 others); Fri, 15 Sep 2023 12:58:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234442AbjIOQ6b (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 15 Sep 2023 12:58:31 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5B73119BC for <linux-kernel@vger.kernel.org>; Fri, 15 Sep 2023 09:58:26 -0700 (PDT) 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 5C6AC12FC; Fri, 15 Sep 2023 09:59:03 -0700 (PDT) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0BB753F5A1; Fri, 15 Sep 2023 09:58:24 -0700 (PDT) From: Robin Murphy <robin.murphy@arm.com> To: joro@8bytes.org, will@kernel.org Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, jgg@nvidia.com, baolu.lu@linux.intel.com Subject: [PATCH v3 2/7] iommu: Decouple iommu_present() from bus ops Date: Fri, 15 Sep 2023 17:58:06 +0100 Message-Id: <b7cd933aa7774ad687c695ebe5e00c17178a7542.1694693889.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.39.2.101.g768bb238c484.dirty In-Reply-To: <cover.1694693889.git.robin.murphy@arm.com> References: <cover.1694693889.git.robin.murphy@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 15 Sep 2023 09:59:14 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777123624350528650 X-GMAIL-MSGID: 1777123624350528650 |
Series |
Iommu: Retire bus ops
|
|
Commit Message
Robin Murphy
Sept. 15, 2023, 4:58 p.m. UTC
Much as I'd like to remove iommu_present(), the final remaining users are proving stubbornly difficult to clean up, so kick that can down the road and just rework it to preserve the current behaviour without depending on bus ops. Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Robin Murphy <robin.murphy@arm.com> --- v3: Tweak to use the ops-based check rather than group-based, to properly match the existing behaviour --- drivers/iommu/iommu.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
Comments
On Fri, Sep 15, 2023 at 05:58:06PM +0100, Robin Murphy wrote: > Much as I'd like to remove iommu_present(), the final remaining users > are proving stubbornly difficult to clean up, so kick that can down > the road and just rework it to preserve the current behaviour without > depending on bus ops. > > Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> > Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> > Signed-off-by: Robin Murphy <robin.murphy@arm.com> > > --- > > v3: Tweak to use the ops-based check rather than group-based, to > properly match the existing behaviour > --- > drivers/iommu/iommu.c | 17 ++++++++++++++++- > 1 file changed, 16 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index 4566d0001cd3..2f29ee9dea64 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -1907,9 +1907,24 @@ int bus_iommu_probe(const struct bus_type *bus) > return 0; > } > > +static int __iommu_present(struct device *dev, void *unused) > +{ > + return dev_has_iommu(dev); > +} This is not locked right.. Rather than perpetuate that, can we fix the two callers instead? Maybe this for mtk: diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c index 93552d76b6e778..e7fe0e6f27de85 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c @@ -500,6 +500,8 @@ static int mtk_drm_kms_init(struct drm_device *drm) dev_err(drm->dev, "Need at least one OVL device\n"); goto err_component_unbind; } + if (!device_iommu_mapped(dma_dev)) + return -EPROBE_DEFER; for (i = 0; i < private->data->mmsys_dev_num; i++) private->all_drm_private[i]->dma_dev = dma_dev; @@ -583,9 +585,6 @@ static int mtk_drm_bind(struct device *dev) struct drm_device *drm; int ret, i; - if (!iommu_present(&platform_bus_type)) - return -EPROBE_DEFER; - pdev = of_find_device_by_node(private->mutex_node); if (!pdev) { dev_err(dev, "Waiting for disp-mutex device %pOF\n", ? It doesn't seem to use the iommu API so I guess all it is doing is trying to fix some kind of probe ordering issue? Maybe the probe ordering issue is already gone and we can just delete the check? And tegra: if (host1x_drm_wants_iommu(dev) && iommu_present(&platform_bus_type)) { tegra->domain = iommu_domain_alloc(&platform_bus_type); if (!tegra->domain) { Lets do the same: if (host1x_drm_wants_iommu(dev) && device_iommu_mapped(dev->dev.parent)) { ? Alternatively how about: bool iommu_present(void) { bool ret; spin_lock(&iommu_device_lock); ret = !list_empty(&iommu_device_list); spin_unlock(&iommu_device_lock); return ret; } EXPORT_SYMBOL_GPL(iommu_present); Since neither of the two users is really needing anything more than that? Jason
On 2023-09-18 18:12, Jason Gunthorpe wrote: > On Fri, Sep 15, 2023 at 05:58:06PM +0100, Robin Murphy wrote: >> Much as I'd like to remove iommu_present(), the final remaining users >> are proving stubbornly difficult to clean up, so kick that can down >> the road and just rework it to preserve the current behaviour without >> depending on bus ops. >> >> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> >> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> >> Signed-off-by: Robin Murphy <robin.murphy@arm.com> >> >> --- >> >> v3: Tweak to use the ops-based check rather than group-based, to >> properly match the existing behaviour >> --- >> drivers/iommu/iommu.c | 17 ++++++++++++++++- >> 1 file changed, 16 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c >> index 4566d0001cd3..2f29ee9dea64 100644 >> --- a/drivers/iommu/iommu.c >> +++ b/drivers/iommu/iommu.c >> @@ -1907,9 +1907,24 @@ int bus_iommu_probe(const struct bus_type *bus) >> return 0; >> } >> >> +static int __iommu_present(struct device *dev, void *unused) >> +{ >> + return dev_has_iommu(dev); >> +} > > This is not locked right.. Urgh, yes, I suppose technically this walk could run in parallel with the bus_iommu_probe() of another IOMMU instance that our caller here doesn't depend on. I agree that's suboptimal, even if it shouldn't happen in practice for the remaining in-tree callers. > Rather than perpetuate that, can we fix the two callers instead? > > Maybe this for mtk: > > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c > index 93552d76b6e778..e7fe0e6f27de85 100644 > --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c > +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c > @@ -500,6 +500,8 @@ static int mtk_drm_kms_init(struct drm_device *drm) > dev_err(drm->dev, "Need at least one OVL device\n"); > goto err_component_unbind; > } > + if (!device_iommu_mapped(dma_dev)) > + return -EPROBE_DEFER; > > for (i = 0; i < private->data->mmsys_dev_num; i++) > private->all_drm_private[i]->dma_dev = dma_dev; > @@ -583,9 +585,6 @@ static int mtk_drm_bind(struct device *dev) > struct drm_device *drm; > int ret, i; > > - if (!iommu_present(&platform_bus_type)) > - return -EPROBE_DEFER; > - > pdev = of_find_device_by_node(private->mutex_node); > if (!pdev) { > dev_err(dev, "Waiting for disp-mutex device %pOF\n", > > > ? It doesn't seem to use the iommu API so I guess all it is doing is > trying to fix some kind of probe ordering issue? Maybe the probe > ordering issue is already gone and we can just delete the check? As I've said before, the correct fix for this one is [1]. I've sent it twice now, it just gets ignored :( > And tegra: > > if (host1x_drm_wants_iommu(dev) && iommu_present(&platform_bus_type)) { > tegra->domain = iommu_domain_alloc(&platform_bus_type); > if (!tegra->domain) { > > Lets do the same: > > if (host1x_drm_wants_iommu(dev) && device_iommu_mapped(dev->dev.parent)) { > > ? IIRC the problem here is that the Host1x (or GPU?) wants to allocate a domain for the GPU (or Host1x) to use, even if the former isn't itself associated with the IOMMU, and at this point it doesn't actually have a suitable handle to the latter device. > Alternatively how about: > > bool iommu_present(void) > { > bool ret; > > spin_lock(&iommu_device_lock); > ret = !list_empty(&iommu_device_list); > spin_unlock(&iommu_device_lock); > return ret; > } > EXPORT_SYMBOL_GPL(iommu_present); > > Since neither of the two users is really needing anything more than that? Hmm, I guess maybe I did get a bit hung up on the bus notion... Indeed I think this wouldn't really be any more inaccurate than the current behaviour, and might be arguably truer to the intent of the function (whatever that is) since in the new design any instance is effectively present for all relevant buses anyway. I've respun along these lines (but retaining the argument with some token validation) and I don't hate it, so I'll send that as v4. Thanks, Robin. [1] https://lore.kernel.org/dri-devel/49bafdabd2263cfc543bb22fb7f1bf32ea6bfd22.1683735862.git.robin.murphy@arm.com/
On Mon, Sep 18, 2023 at 08:21:45PM +0100, Robin Murphy wrote: > > ? It doesn't seem to use the iommu API so I guess all it is doing is > > trying to fix some kind of probe ordering issue? Maybe the probe > > ordering issue is already gone and we can just delete the check? > > As I've said before, the correct fix for this one is [1]. I've sent it twice > now, it just gets ignored :( IMHO at this point just put it in this series and have Joerg take it :( > Hmm, I guess maybe I did get a bit hung up on the bus notion... Indeed I > think this wouldn't really be any more inaccurate than the current > behaviour, and might be arguably truer to the intent of the function > (whatever that is) since in the new design any instance is effectively > present for all relevant buses anyway. I've respun along these lines (but > retaining the argument with some token validation) and I don't hate it, so > I'll send that as v4. Eventually tegra is going to need to pass in a real struct device to get the domain, so at that moment we can switch it to use the device API on that real struct device. So this definately seems good enough for now. Jason
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 4566d0001cd3..2f29ee9dea64 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1907,9 +1907,24 @@ int bus_iommu_probe(const struct bus_type *bus) return 0; } +static int __iommu_present(struct device *dev, void *unused) +{ + return dev_has_iommu(dev); +} + +/** + * iommu_present() - make platform-specific assumptions about an IOMMU + * @bus: bus to check + * + * Do not use this function. You want device_iommu_mapped() instead. + * + * Return: true if some IOMMU is present for some device on the given bus. In + * general it may not be the only IOMMU, and it may not be for the device you + * are ultimately interested in. + */ bool iommu_present(const struct bus_type *bus) { - return bus->iommu_ops != NULL; + return bus_for_each_dev(bus, NULL, NULL, __iommu_present) > 0; } EXPORT_SYMBOL_GPL(iommu_present);