Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp100860rdg; Wed, 11 Oct 2023 23:09:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHesUUQvIaFUBR12LzFXuwEUgrCROOwyxhhOpj7l9w1iUf1V4TH5nA8fAD+fimXmisEnFC4 X-Received: by 2002:a05:6e02:1090:b0:34c:f2cb:b2c with SMTP id r16-20020a056e02109000b0034cf2cb0b2cmr22158898ilj.19.1697090947496; Wed, 11 Oct 2023 23:09:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697090947; cv=none; d=google.com; s=arc-20160816; b=hooXABOQxs3UUkuFnb9SHYXj0OBULiOCe8PoEvsn/7g0m4GX+T844D3bowiPBgWuTj HJmSQ4fWmDiTkyVFb3jepE9v4w7Gkkhy2HCjESkEdfPQNsZs/I27Z8rOnEXj3ceUzpyS YiNPrY1OZMt8ahPToj3x/IZFoWQgUNE5YEWZZPuuQWqe+F+K62SjTOcaTSUGdUuOyd93 pJGkiUBSOhA4F4taE3/QgmL/7y37BlBjto/pN0oXBeaoYQms4kkcKtH3V23rsWrplYsy B/VBbz3vXR7hLN7aMwJq9Yl7VvwMwc4XX0KtH+Co/7sX5S3Tn30n05ubnlpzXcSbGv7m ZvEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=6L/LZjqaswZTsBU/KPCif0pcUUeb/u9+ujQlGx49w20=; fh=Jtbq2SGmld3DVmnHO87icIF4HdB4zzzXf+HKPrDalnk=; b=kO7PDlitA/B1biUOQ7g/HyHKt2lAOrgrzf8/eJurO57uNpmoJtCE5vcugypIfNLIl1 hXvGs09H+qfEssqE9wNBY5oCJeFjA15SFvJux0t4Hvcn2rRPVxOjGUvfbMmXpNHgAD+o oaKY3A1vvnD+YtToT8RLzb3zvtoIAPWWFqwds/YJ6XNhld6RTsY0OcZHy69vTZUtLJIT IGkcFcHg4lrJXNJG9M+3POEMHDeiMVd4S0JmcSsjQIE6KaNo79cZL0uftuKPH9toWqD2 Zx3p+gMva+E6/CoxytpLXYoPIl1ozvkWv64ODSr+h4PGGqSGI1EVW9Z1bTKbSB3kT+/2 WkPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="TtU/Aday"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id u6-20020a634706000000b00578a084850dsi1469194pga.720.2023.10.11.23.09.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 23:09:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="TtU/Aday"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id B000E802B141; Wed, 11 Oct 2023 23:09:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376631AbjJLGIw (ORCPT + 99 others); Thu, 12 Oct 2023 02:08:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232786AbjJLGIv (ORCPT ); Thu, 12 Oct 2023 02:08:51 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED82CA9 for ; Wed, 11 Oct 2023 23:08:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697090929; x=1728626929; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=vnvBwkspZUy3N5RRakd9NDz8RSPL4W2JB+T3C/ANT28=; b=TtU/Aday6waleFCLs6Lh4WT7VKJejGAgxLASlghF28PdcL75gYcKQtoR tCi2Uk/4tVvhlLo2tS3jteNld5p7H1mD0XVwNs/kpZVCV/KmnKRyrgA2y 0xJ/pjLVnMGfs+SMYB7lbtN7bnworui6nKz4B5zfVXQq7/A0/Y7ax4xBr b4UYOg3Yx+hI4pquytV4USq5wYro0sMdLIUNtm/I2gEcgAL3b3B796LjZ gAylKhFwysZcZ9nuUQAqQti7zld2dIU7/3h9Wu5Uz6Cjq0c/yuj5ikT2E O3HM+Oc8UPRMXqaxMru+u/uBrH/+6W3oWlm5m+YV1STdi+dWdDRe+ytCB Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="375194946" X-IronPort-AV: E=Sophos;i="6.03,218,1694761200"; d="scan'208";a="375194946" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 23:08:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="789259868" X-IronPort-AV: E=Sophos;i="6.03,218,1694761200"; d="scan'208";a="789259868" Received: from allen-box.sh.intel.com (HELO [10.239.159.127]) ([10.239.159.127]) by orsmga001.jf.intel.com with ESMTP; 11 Oct 2023 23:08:46 -0700 Message-ID: <43ca2a88-942e-4d65-87f1-30a7cf537edd@linux.intel.com> Date: Thu, 12 Oct 2023 14:05:14 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: baolu.lu@linux.intel.com, iommu@lists.linux.dev, jgg@nvidia.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 2/7] iommu: Decouple iommu_present() from bus ops Content-Language: en-US To: Robin Murphy , joro@8bytes.org, will@kernel.org References: <6711338e24dd1edfd02187f25cf40d8622cefdb2.1697047261.git.robin.murphy@arm.com> From: Baolu Lu In-Reply-To: <6711338e24dd1edfd02187f25cf40d8622cefdb2.1697047261.git.robin.murphy@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,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 groat.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 (groat.vger.email [0.0.0.0]); Wed, 11 Oct 2023 23:09:04 -0700 (PDT) On 10/12/23 2:14 AM, Robin Murphy wrote: > 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 The iommu_present() is only used in below two drivers. $ git grep iommu_present drivers/gpu/drm/mediatek/mtk_drm_drv.c: if (!iommu_present(&platform_bus_type)) drivers/gpu/drm/tegra/drm.c: if (host1x_drm_wants_iommu(dev) && iommu_present(&platform_bus_type)) { Both are platform drivers and have the device pointer passed in. Just out of curiosity, why not replacing them with device_iommu_mapped() instead? Sorry if I overlooked previous discussion. Best regards, baolu > 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); >