Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp207776rdb; Mon, 18 Sep 2023 12:28:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGPaPajuPVBqwFu5OjVV4lVblRO5m9mkOygvWE827GI9ovySYfF4zhyo1T13Z+7MIZojrev X-Received: by 2002:a05:6a00:4a03:b0:68a:4102:e483 with SMTP id do3-20020a056a004a0300b0068a4102e483mr538709pfb.14.1695065314456; Mon, 18 Sep 2023 12:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695065314; cv=none; d=google.com; s=arc-20160816; b=Q65g7WfdTNtAG5u32rtY6VgwjW1DUabkCA9iiK2TzG1iHyadj/EG3saGa9BG4YoI3w bQKJbiG+ZOeWVytdl2wz3qSxSgU1mho12A0m+ndvW7KaYMtOXgcHvcy/RUQTY4pzUdKI 4nNcYOZKNzCgqnO74GO6MWzmWyR2CwAycVoyMDQeOe2xPEqQzUQPMc8jaAg9MtVSuRlW 3rYlzqbfoVvZS6vuS1t/AB3FfbXU2xlvijBchfR/b6S/+7HMlHN+yUL7C0rXX2Ms139d dBHtDKk6NjBT9YpD1R2FPUruUh7EZ3Fm0zzl8Qbx/u/FXP5Vflio/UBXqXW5gH6ELj/c DoEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=KXGXOYQXB7oocV8xXZAJiooCnJtdooGhFaw1vRbwByg=; fh=FUZcHxDrb6O5ZcPi8ta9biMJts6OgiRw8sXC6AR8MmM=; b=ayEf7qsk8OsRQvhoLl9/6waafSwjcoSrkUvDj++eqaLalR/zBQ7RvuQrYgVbmg/dEJ A9K0sL5f9MTDe/53F/X04B8UiwljLGcQ4NTlzNjHQT0VirxzmFExLBFP+wIOwcgIX+rw CDNtiHxmm6p8f3jcwqq8XuOnlCbzJiOZnXZ2FXac3vJ1PeLgPh8ypchXBGcSdWdgXcaN GPDJYsqLezMhHzfY3hx1bHubfwj7HI0WrLATIFFaoLT0gs0fcl68WEFpHfIva2O62LP1 dJK4ltznNXiRTDFhYHZR+YmjqqHhkpNeT/GUCrqGd0593QCRNSMRNj8W9Q7zlRRy+Zyd IDBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id cd22-20020a056a00421600b00690c0051dcdsi165118pfb.143.2023.09.18.12.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 12:28:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 8616781F35B3; Mon, 18 Sep 2023 12:22:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229483AbjIRTWD (ORCPT + 99 others); Mon, 18 Sep 2023 15:22:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229379AbjIRTWC (ORCPT ); Mon, 18 Sep 2023 15:22:02 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 150D210E for ; Mon, 18 Sep 2023 12:21:52 -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 DA14A1FB; Mon, 18 Sep 2023 12:22:28 -0700 (PDT) Received: from [10.57.94.165] (unknown [10.57.94.165]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 526413F5A1; Mon, 18 Sep 2023 12:21:50 -0700 (PDT) Message-ID: <982143de-ec1e-aff4-e65f-77a38e48cf20@arm.com> Date: Mon, 18 Sep 2023 20:21:45 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v3 2/7] iommu: Decouple iommu_present() from bus ops Content-Language: en-GB To: Jason Gunthorpe Cc: joro@8bytes.org, will@kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, baolu.lu@linux.intel.com References: <20230918171216.GK13733@nvidia.com> From: Robin Murphy In-Reply-To: <20230918171216.GK13733@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,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 pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 18 Sep 2023 12:22:15 -0700 (PDT) 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 >> Reviewed-by: Jason Gunthorpe >> Signed-off-by: Robin Murphy >> >> --- >> >> 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/