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: 140543 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1188998vqi; Fri, 15 Sep 2023 09:59:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+1Hp3CYo7P6zxlehXp0Dyv8Q534QP0ykGTWnu+0aiRgNpzzLHx79dkWerntmbw1f5kpFK X-Received: by 2002:a17:90b:ed7:b0:273:e0b6:661 with SMTP id gz23-20020a17090b0ed700b00273e0b60661mr1987616pjb.46.1694797157648; Fri, 15 Sep 2023 09:59:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694797157; cv=none; d=google.com; s=arc-20160816; b=yh4K8KrVpPi9ol359BXzoO0sk2WA78bWF3p7ORRfNYvSWHjaUn1NvfKUT6K7dDHY+z 6MwunR8AEqTlxgphX8ChF6155YVnVwt4TaYcFIPujTdnaMbRc1hXiE7KCLErNQXtcu0b XfgrTv8Z8YxxxZA9BIRFpXyo9BjywsZeyHX7c+uRsbt9axDK5PkusicGB78BAbqgimmI RJwMQyYSYdMDIAjw9/gO1TXYzrWNTJHJ1VTUcxsr6m4YZlfUAyp61UR06B82vfqO9TiV d12dNaft55t2c7IcQpsjReW5dQvBXcbPQG9b9vmCnf+HxevvoY3sC9csctGlhzBouj4i Kt2g== 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=U1E2pjYwkQYyhMjbP9CzGox+91wcBiGJths0GMiXitI=; fh=3SO4sBNpOFNxfB4XNpCUWqe4lDXSOQ4O5f1XEPxUZRQ=; b=A4Q70a1/Yb2FChaoMwyCV4gDbqZFBt476QqSjFKnH4rfeo8HYk1hP3aIxBUSpXlLFo qqRFJrpLbnMgmBqZ4KFSkrE1c6qGNCgtPmfxtD3lO2xFhrfU8oTrt3yy+PIf0pLDe2Wm ZpLR7Lc/tQ4BLhPvwkCFdzj3DbPI1wOydavMaiJm6v9q6q70k6FoXzE7q3t+PTMCqrXF fcnJ20PHibc8gRhiJx494csgV4bDbhMxjil3rRizskvlAgYfl92MVskMbrlxxWbtPK+b qsQg92JMIcd5V+GdcddIhXT14ejO8ik/7zL5DddeDuMVbtoJFF0ZUyL8z7MywGbUNWud HHWg== 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 Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id z3-20020a633303000000b00573f9d916fbsi3543897pgz.784.2023.09.15.09.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 09:59:17 -0700 (PDT) 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 BD87082E555A; Fri, 15 Sep 2023 09:59:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234981AbjIOQ6n (ORCPT + 30 others); Fri, 15 Sep 2023 12:58:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234442AbjIOQ6b (ORCPT ); Fri, 15 Sep 2023 12:58:31 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5B73119BC for ; Fri, 15 Sep 2023 09:58:26 -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 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-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 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]); Fri, 15 Sep 2023 09:59:14 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777123624350528650 X-GMAIL-MSGID: 1777123624350528650 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);