Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1342327rdb; Mon, 2 Oct 2023 06:55:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCso0tQSCohEaf3W7slsYKd19Y/XLEtLNzIsEwF8H/yp68GABJoRMnUa/ZxGmwmmxib7fd X-Received: by 2002:a05:6e02:1d19:b0:350:f51b:c32e with SMTP id i25-20020a056e021d1900b00350f51bc32emr16007399ila.16.1696254927400; Mon, 02 Oct 2023 06:55:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696254927; cv=none; d=google.com; s=arc-20160816; b=T9PrbM23ftzuQnA57fvuh1vTAAg183Q6ow0sF2UKGOG6tH+edvKYl+iLYJZPezMO1l /zGhpjwh+8BN6pa3HMB3n8N1ivSQuSKiqO868CKJqv6i0iIyCVrDpJdnRteV5sF7DWeT V51Uh+dRnMOupk7/VQk87YhAUqIEkuaCa5mrV3ALK6kJl9I+nYIo/c1QdIwZx4/v5vqM aB+AvWNRq9xI/jBNH4Vyma7KYh3e0/aGTEjGyoNimL4mFp8/Cqf5YhElfVV4wOge9r93 aBuT/F/Sk3lmjZQT1JjDV23OWrseQB6iOmiko+9Vr4uRFfN3SVJYVZ7LGvVaHKCnbP6e J7xQ== 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=dIJFFWvz6n7uUgCBmPfLiKIYdBFSOqRv1Zb0+myHU8Q=; fh=3nQM0QufZPSZ94JO+WDmHkrFziuG1/NJr0OD1jy0Wvc=; b=BvN3SVNOQusI9kx5oBC2xo2f4gbrGFUieF/yZ37IeAT3+hvkFLJ+zRcWdDTFC3qFmo Vv1egAVE+15aBOKLY2qgv2z2w/rIugzzq6qRKnSJnvAfJVAEgxyk1uQ+vnxnbi51SBEc sYwX7laCHKaZh23PNzSOyIMpIIVNZBSzSENJUef+evBAhjVwpXPlYvocLRWTm/Xs9PlL d/Ee2zRH8JMGd5hS/NR65Ia56o2T+RZIXbqBvEZwmAsz/XCnBfrucFf8RjhA6p8rPuxl 89boEXmZcIeWq4tAm0RwpnrELq8CitgNzgi8N2t8qMNPaTUpZha+yFVbxTd/ou0wXa1w Wy5Q== 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 f20-20020a637554000000b0057790a5a8e7si28140589pgn.190.2023.10.02.06.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 06:55:27 -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 DE1DB809BE63; Mon, 2 Oct 2023 06:50:09 -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 S237523AbjJBNt3 (ORCPT + 99 others); Mon, 2 Oct 2023 09:49:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237514AbjJBNt1 (ORCPT ); Mon, 2 Oct 2023 09:49:27 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8896FD7 for ; Mon, 2 Oct 2023 06:49:24 -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 BD10B143D; Mon, 2 Oct 2023 06:50:02 -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 7384A3F762; Mon, 2 Oct 2023 06:49:23 -0700 (PDT) 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 Subject: [PATCH v4 2/7] iommu: Decouple iommu_present() from bus ops Date: Mon, 2 Oct 2023 14:49:10 +0100 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 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 06:50:10 -0700 (PDT) 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); + } + } + return ret; } EXPORT_SYMBOL_GPL(iommu_present); -- 2.39.2.101.g768bb238c484.dirty