Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1378770rdb; Mon, 2 Oct 2023 07:53:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEIe3cgK6xrz3GhA67520CqVqE8VOZN3QT8xA53U44uZeJT2M3jyFdr9LropveOo6NGZV5z X-Received: by 2002:a17:90a:5ae5:b0:273:e689:8dfc with SMTP id n92-20020a17090a5ae500b00273e6898dfcmr10162556pji.32.1696258423575; Mon, 02 Oct 2023 07:53:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696258423; cv=none; d=google.com; s=arc-20160816; b=AR+14O1lB9QYgbkkliQQxbkmIi49wt7+VvlITlPF/TtyzGS7ik4X6cxO81mc+Gd4Om 5Q6Rb+LACFUpWjoNoxbLAnoSJcyeiMvblwAmeanL2aGZO3Hqi/DNIHyc6LvksYoJWYBQ DABt2EkY6ih2L+c68oMhi7idAaDPckr/x8mfNq8qxTdvnEV7Vw2cUCoBO+3Xd8jO+0nb O4ZrZwFwWcaVLEz8hDt+0VPM3JVdRlVGVruFnPatHPCHJ2bxkeTm4krLNgqf0FoAl5Wz 6ZiO1Se6g7mdAgm+IM3OrRK5jueWKdQJfCMYZgg3yJiEBfc63OpAqGSv9KPQrB63htgH LsYg== 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=EXOQLlIMzonxFXeOhmeRsU+DrBEuhYU8tFZ284KP3Xg=; fh=05DobxX2JpcAgp2ZsQZ8xFHs0WsAJAN5I8bHUa82rls=; b=LbBt3tOLiaESDs4UZ7nk+1l546DL+qUZjxDPTojmoXPGazCwiOe3ypiBNVPkI3MoHf 6SR3NXY4pARxcECVR7wxGzl7d85d5CNaFlT/xRBW9zCLMrlxotlKx9UWm92w+H7ikvEa i63BoM69nF2VM2ub1Tayqm8VRDPEQKH1GeXqTtl+GLxh7jzHH9SD7sTSkTLkGUoO+4xn l0pi8R0xUg9RKcSLGRZpNUasRiKrV45cfpmQCn9NKjJ/jfxoxSsefDpI596vtar1o8FN UeoXXMEVmJ9Z4uynxNJHYId8zykjIPJtqMgnpLg2rlnlaaJg2lshpj0rKPLNGf2g84Ka QElg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id pg10-20020a17090b1e0a00b0026d0fa1c51esi8142803pjb.125.2023.10.02.07.53.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 07:53:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 2B1568022B28; Mon, 2 Oct 2023 07:32:30 -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 S237661AbjJBOcU (ORCPT + 99 others); Mon, 2 Oct 2023 10:32:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237474AbjJBOcS (ORCPT ); Mon, 2 Oct 2023 10:32:18 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 12BE0B4 for ; Mon, 2 Oct 2023 07:32:16 -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 43F0CC15; Mon, 2 Oct 2023 07:32:54 -0700 (PDT) Received: from [10.1.196.40] (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0FCAA3F762; Mon, 2 Oct 2023 07:32:14 -0700 (PDT) Message-ID: Date: Mon, 2 Oct 2023 15:32:10 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v4 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, baolu.lu@linux.intel.com, linux-kernel@vger.kernel.org References: <20231002141704.GG339126@nvidia.com> From: Robin Murphy In-Reply-To: <20231002141704.GG339126@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.1 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, 02 Oct 2023 07:32:30 -0700 (PDT) On 02/10/2023 3:17 pm, Jason Gunthorpe wrote: > On Mon, Oct 02, 2023 at 02:49:10PM +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. Since commit 57365a04c921 ("iommu: Move bus setup >> to IOMMU device registration"), any registered IOMMU instance is already >> considered "present" for every entry in iommu_buses, so it's simply a >> case of validating the bus and checking we have at least once IOMMU. >> >> Signed-off-by: Robin Murphy >> >> --- >> >> v3: Tweak to use the ops-based check rather than group-based, to >> properly match the existing behaviour >> v4: Just look for IOMMU instances instead of managed devices >> --- >> drivers/iommu/iommu.c | 21 ++++++++++++++++++++- >> 1 file changed, 20 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c >> index f7793d1b5c3e..ef7feb0acc34 100644 >> --- a/drivers/iommu/iommu.c >> +++ b/drivers/iommu/iommu.c >> @@ -1988,9 +1988,28 @@ int bus_iommu_probe(const struct bus_type *bus) >> return 0; >> } >> >> +/** >> + * 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 and aware of devices on the given bus; >> + * in general it may not be the only IOMMU, and it may not have anything to do >> + * with whatever device you are ultimately interested in. >> + */ >> bool iommu_present(const struct bus_type *bus) >> { >> - return bus->iommu_ops != NULL; >> + bool ret = false; >> + >> + for (int i = 0; i < ARRAY_SIZE(iommu_buses); i++) { >> + if (iommu_buses[i] == bus) { >> + spin_lock(&iommu_device_lock); >> + ret = !list_empty(&iommu_device_list); >> + spin_unlock(&iommu_device_lock); >> + } > > Add here: > > return ret; > >> + } >> + return ret; > > And this becomes > > return false > > ? My aim here was for the smallest, simplest code, given that what we still really want is no code, and this is basically only being retained to serve that one tricky Tegra callsite. I guess I could have also added "&& !ret" to the loop condition, but either way since this should never be on a hot path I figured it's not worth the bother just to save a handful of extra comparisons. > Regardless > > Reviewed-by: Jason Gunthorpe Thanks! Robin.