From nobody Sun Sep 14 06:38:06 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1086C05027 for ; Thu, 26 Jan 2023 18:26:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229889AbjAZS0e (ORCPT ); Thu, 26 Jan 2023 13:26:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229874AbjAZS0b (ORCPT ); Thu, 26 Jan 2023 13:26:31 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 19AAE599A8 for ; Thu, 26 Jan 2023 10:26:31 -0800 (PST) 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 B3B86C14; Thu, 26 Jan 2023 10:27:12 -0800 (PST) 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 C25DF3F71E; Thu, 26 Jan 2023 10:26:29 -0800 (PST) From: Robin Murphy To: joro@8bytes.org, will@kernel.org Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, hch@lst.de, jgg@nvidia.com, baolu.lu@linux.intel.com Subject: [PATCH v2 1/8] iommu: Decouple iommu_present() from bus ops Date: Thu, 26 Jan 2023 18:26:16 +0000 Message-Id: X-Mailer: git-send-email 2.36.1.dirty In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Robin Murphy Reviewed-by: Jason Gunthorpe Reviewed-by: Lu Baolu --- v2: No change 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 42591766266d..b27f5d3453bb 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1871,9 +1871,24 @@ int bus_iommu_probe(struct bus_type *bus) return ret; } =20 +static int __iommu_present(struct device *dev, void *unused) +{ + return device_iommu_mapped(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(struct bus_type *bus) { - return bus->iommu_ops !=3D NULL; + return bus_for_each_dev(bus, NULL, NULL, __iommu_present) > 0; } EXPORT_SYMBOL_GPL(iommu_present); =20 --=20 2.36.1.dirty