From patchwork Fri Sep 15 16:58:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 13387257 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 19175EED61A for ; Fri, 15 Sep 2023 16:58:58 +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-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/NNY07GAfF02rEAARL4UUl7VqXYWES31gcascKoNQSA=; b=ltUU5yBNo+ohi3 g6T0vJiYtZaXm9DrJ4gwlPJAoN8Mp9mZKWyOvhsyy3fAjJhx3OFPzx4J+uZu4pQzGJFjSYd22CshG Y+KQlfnkP6At451+X+POg0PhPheextqU2wQIwrHvrOp87Tkuv/zGLyxgCwdseeVckHZE/KV3gc9LH HaigzcuXuOwxd9KUSQ6nXZ1ZpDZpNF56Al9jXF7wZ98dRFkMhak/KrVfH7fG+vlVHzFY6uuk2a7+x jA0apXQpjGvdecrJup/ZIr2MQsc2Rqe8PuoN+sTlHVCxpRm+IE39RR6X39BJk4p+TikJYj9YSh4VA APn19LvQs8ST+jq4T8Pg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qhC9J-00B5Rs-28; Fri, 15 Sep 2023 16:58:33 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qhC9F-00B5Q9-1a for linux-arm-kernel@lists.infradead.org; Fri, 15 Sep 2023 16:58:31 +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 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 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: X-Mailer: git-send-email 2.39.2.101.g768bb238c484.dirty In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230915_095829_614046_E03E0F0F X-CRM114-Status: GOOD ( 12.70 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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); +} + +/** + * 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);