Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1001795rdg; Wed, 11 Oct 2023 11:15:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlTTdUAWKKax2EoeYF82RkhXyufVC6JSsQVLvd9J0cjdBEEVB4KAMCjSxXFA9txlbkpVWj X-Received: by 2002:a05:6a20:4405:b0:16b:9f9b:5764 with SMTP id ce5-20020a056a20440500b0016b9f9b5764mr19126632pzb.54.1697048155231; Wed, 11 Oct 2023 11:15:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697048155; cv=none; d=google.com; s=arc-20160816; b=shZCVlNG4jvrh2J+Pb+lmHa66VZq7yYgMfhMEF/3F2bbnLXjE2JkKQlRepl5FHmwxM BIqvQhfM7rjHCzgu5yDVKnEAn+B2jj2LRdO/T1z6PmZw6LYTNx1vMzbIhcNS0ToGuSJU PfrpYqRUA0aLoWs2TzAemhWoq8HsIB96LaHD0CNliAHN6sgv7zvLB9JjD5Nn4NwJU2Hn 5gPQsRbfDlTIMmtEu0HCwIJpjom+31wX1LXxMZ8D/hgtAa1eZFMBM9+1o04ZxeWoazB1 7yGAbT5XcTQvP5lVRFJJZZzc6eNRr3uq8O1ActKZMkk61+X8Gx4P5tp+VLdAzCb95tZX adcw== 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=SVWW+PORY5YiJ+bRKWKrhoVDO8SWZF4Qve4vBzHSfVI=; fh=3nQM0QufZPSZ94JO+WDmHkrFziuG1/NJr0OD1jy0Wvc=; b=dkUYVxfmLUYO8K9nmDu72aGukKtcEu4EGm2/o0DHaC2JXd4YSkUGmLq9F4JM1RlgAu SN7nBpI9VULa0al68ozOu7pUMri/Xj6VnvzC+qawoZrjgyD3qAVpNs50F+tWsJxc27Xp qSS9CHFGwCOXOyMl8D3yzZ6tlyVXi4FFc4IBZYVYXuht//uTnreMCUVcLHC8WAKQn4zL /sJC8xPNSxSEvBgqAbZs/CxG9SdoLDxk828wFjj99PftVGjv+gh1vOHjUnkv+ItLS+fI 6yT9nT4jUlCrts3JoEC8hbEUikaGHLshA9TYR6nEqwu92H0BzHlEt8P5yweinWoM7qAu NwHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id 5-20020a630c45000000b00578b9d1d118si307254pgm.219.2023.10.11.11.15.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 11:15:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 65E728074CD5; Wed, 11 Oct 2023 11:15:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235052AbjJKSPN (ORCPT + 99 others); Wed, 11 Oct 2023 14:15:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233215AbjJKSPF (ORCPT ); Wed, 11 Oct 2023 14:15:05 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2544193 for ; Wed, 11 Oct 2023 11:15:04 -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 A58CD14BF; Wed, 11 Oct 2023 11:15:44 -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 129F93F5A1; Wed, 11 Oct 2023 11:15:02 -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 v5 2/7] iommu: Decouple iommu_present() from bus ops Date: Wed, 11 Oct 2023 19:14:49 +0100 Message-Id: <6711338e24dd1edfd02187f25cf40d8622cefdb2.1697047261.git.robin.murphy@arm.com> 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=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Wed, 11 Oct 2023 11:15:50 -0700 (PDT) X-Spam-Level: ** 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 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 5a3ce293a5de..7bb92e8b7a49 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2000,9 +2000,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