Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp575380rdf; Tue, 21 Nov 2023 10:06:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGr8x5JymYq4MrKSXerS3l6YjFfwMhJ8AP5Kv6UG60mL5ntxrOE6oTNnElfuIMqAhfxYG42 X-Received: by 2002:a05:6808:1688:b0:3b2:e77b:640d with SMTP id bb8-20020a056808168800b003b2e77b640dmr43678oib.31.1700589966766; Tue, 21 Nov 2023 10:06:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700589966; cv=none; d=google.com; s=arc-20160816; b=D5hkL7Gz7AlATB4/JAXpElre/HmftCU8kaTt6jO31DtHW/DS0fgRR38lbO5OR/4e1H Q1YT8w5OfN34w7V+4gmMgpVjdTalsYDUSEWrNyQ888GBKzQFUSt9oYDpDaNRlFtH51nE MfarphjOEx1qPg38T0iiVcYnkQI4Re2mFnuG58fwHNpqTNTultIrFrEb9ocECPMXo34b DxwTuoIdIRow/XTHaINgrNZ2qLMIs+R+ZY7SlFpRb31NaDWK+YI+jlDwEadBH7F6FotM DAwXNVTvf0svhKFk1tTEl7xFW19zNe4Tl2OeRlnXhDxuaeEKZ7DkJ4jKltH25l4A2CEy PkYg== 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=MaBEx2frbbgmL05L0+m4fhhXK4tTzeKPZfxvBUH/LGM=; fh=/LWf6GZq+5MWEfaJ8k2uZ3r5PX06byd5VRVQaY04470=; b=SD5S10UeyW0LLzkPjRBRDymWvYpKhlcr5L5+GPgPg/MYhPzrPGyB1Z2ViVQBZxthJh PNHGosmV5YLizp3vfoXSYWtoIB8M3Gx4xHMl4+6Yke3PX+VdSKCxetsKvMxhDIYdR7gK 1CzRj9mERGUuv2BV259BXnE2M1DPZGLXO9wNN8WJnh3eBs6HHv3nhmD5vxeBCpBeW/oj xa2hpu+dXOn/37iG+r1eEyVpIJjPc2NQIvSLOpjMCJn9GpQ8swMPHFiSfY55jkpMy9jl z+/YL02F/nx1M0EbZiUurmn0CGkTU8Nt4KmuKdFfcoKWec5HaluUNoVwNZX2B/7pNS4k SLyA== 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 Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id w13-20020a0568080d4d00b003a36350d056si3937150oik.57.2023.11.21.10.06.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 10:06:06 -0800 (PST) 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 2F41B809ECA3; Tue, 21 Nov 2023 10:05:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234515AbjKUSFC (ORCPT + 99 others); Tue, 21 Nov 2023 13:05:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234483AbjKUSEo (ORCPT ); Tue, 21 Nov 2023 13:04:44 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7336C170B for ; Tue, 21 Nov 2023 10:04:17 -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 F024F169C; Tue, 21 Nov 2023 10:05:03 -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 2D5763F6C4; Tue, 21 Nov 2023 10:04:16 -0800 (PST) From: Robin Murphy To: joro@8bytes.org, will@kernel.org Cc: iommu@lists.linux.dev, jgg@nvidia.com, baolu.lu@linux.intel.com, linux-kernel@vger.kernel.org, jsnitsel@redhat.com Subject: [PATCH v6 2/7] iommu: Decouple iommu_present() from bus ops Date: Tue, 21 Nov 2023 18:03:58 +0000 Message-Id: X-Mailer: git-send-email 2.39.2.101.g768bb238c484.dirty In-Reply-To: References: 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,T_SCC_BODY_TEXT_LINE 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: 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]); Tue, 21 Nov 2023 10:05:29 -0800 (PST) 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. Reviewed-by: Jason Gunthorpe Reviewed-by: Lu Baolu Reviewed-by: Jerry Snitselaar 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 5c555fc0d54c..7fafd073c33e 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2001,9 +2001,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); + } + } + return ret; } EXPORT_SYMBOL_GPL(iommu_present); -- 2.39.2.101.g768bb238c484.dirty