Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1536822imw; Tue, 5 Jul 2022 11:07:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1umpCR1neG80Q4lPTv/1FdTxryg/kECCIP+0acnhk+0w/eGaoC5ewTIleS5v25hwUzIL7H3 X-Received: by 2002:a63:f959:0:b0:412:4bf5:e846 with SMTP id q25-20020a63f959000000b004124bf5e846mr9963014pgk.217.1657044437822; Tue, 05 Jul 2022 11:07:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657044437; cv=none; d=google.com; s=arc-20160816; b=qQP+8HQTUunHLkx7JQI1ArnYuBrp/prv6mF9gMkflUcaNiuXW67QmPqf6DQDTFhiiB BiSm84z/PuI6yDLe6zgh6j81uh9Y4Kd94JtoYyF+xj5tUQ7EMJ2Djs5Msemo3S+S9ZZ2 Kh2PRo2usF491tCbHK92mpyGz7aztLdXi4g1K9aUXqdvmQPePQcF5ShO66tcM1+zssRD /DGcJS7tYjPK70GLR0f49WHnHJRvfXs2IN6sT1cWw+qYHpDm3NHMC2W+CsavpuC2oQkW OhTvk7uiaxiCo6+X0MQ82PUzpYKbiqgam/MsttZwKCqKc/muBDV9iON9XRaxyt3tZoAR 69wg== 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=Y2R/WbA8ZsGlLe9PvLrY3aLKS3BV2x5XBbIy3yzH2HM=; b=lcazUy73KRi22zFcfaLM2pRP7KuM8sowuXX1nVRgyEqiI0E4P3eB6lTSnZOe58HXAX N2t9q2pRkid8FJV06CMrZuVtGn4aE6FjHtQ5sm4VSa+GtNG//o2CkDH5VmCM3mp3rwGz SI8+4+NdygaOg2KbEp64oxrzCRsoOUdKQWhQYmb2Sn2Rw/9fNvBHZAYOO5vDF8YRLHW2 /4ob7ZODsZOMbRAgEL/U3oTADCW6foyDbTGprDk5Gj95rAgkAwKngqL/EXx19SczvShk 62vK2Sq2Q8GTfrOIR1M+rNndVRWkpvtniY8qar9WsyN82ZvTDJ7CZJ+QL8dZie+YnDlE xYdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m21-20020a63f615000000b003fbd7285a83si43193137pgh.817.2022.07.05.11.07.04; Tue, 05 Jul 2022 11:07:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233163AbiGERI5 (ORCPT + 99 others); Tue, 5 Jul 2022 13:08:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232917AbiGERIu (ORCPT ); Tue, 5 Jul 2022 13:08:50 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1C6F01CB14; Tue, 5 Jul 2022 10:08:49 -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 2566A1595; Tue, 5 Jul 2022 10:08:49 -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 446FE3F66F; Tue, 5 Jul 2022 10:08:47 -0700 (PDT) From: Robin Murphy To: joro@8bytes.org Cc: will@kernel.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, baolu.lu@linux.intel.com, suravee.suthikulpanit@amd.com, vasant.hegde@amd.com, mjrosato@linux.ibm.com, gerald.schaefer@linux.ibm.com, schnelle@linux.ibm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 03/15] iommu: Always register bus notifiers Date: Tue, 5 Jul 2022 18:08:26 +0100 Message-Id: <8c380309f264cd0dfc73ba2ec060adc9515af2f2.1657034828.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.36.1.dirty In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The number of bus types that the IOMMU subsystem deals with is small and manageable, so pull that list into core code as a first step towards cleaning up all the boilerplate bus-awareness from drivers. Calling iommu_probe_device() before bus->iommu_ops is set will simply return -ENODEV and not break the notifier call chain, so there should be no harm in proactively registering all our bus notifiers at init time. Tested-by: Marek Szyprowski Signed-off-by: Robin Murphy --- v3: Add host1x_context_bus drivers/iommu/iommu.c | 53 ++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 847ad47a2dfd..514edc0eaa94 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -6,6 +6,7 @@ #define pr_fmt(fmt) "iommu: " fmt +#include #include #include #include @@ -16,11 +17,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -75,6 +78,7 @@ static const char * const iommu_group_resv_type_string[] = { #define IOMMU_CMD_LINE_DMA_API BIT(0) #define IOMMU_CMD_LINE_STRICT BIT(1) +static int iommu_bus_init(struct bus_type *bus); static int iommu_alloc_default_domain(struct iommu_group *group, struct device *dev); static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus, @@ -103,6 +107,22 @@ struct iommu_group_attribute iommu_group_attr_##_name = \ static LIST_HEAD(iommu_device_list); static DEFINE_SPINLOCK(iommu_device_lock); +static struct bus_type * const iommu_buses[] = { + &platform_bus_type, +#ifdef CONFIG_PCI + &pci_bus_type, +#endif +#ifdef CONFIG_ARM_AMBA + &amba_bustype, +#endif +#ifdef CONFIG_FSL_MC_BUS + &fsl_mc_bus_type, +#endif +#ifdef CONFIG_TEGRA_HOST1X_CONTEXT_BUS + &host1x_context_device_bus_type, +#endif +}; + /* * Use a function instead of an array here because the domain-type is a * bit-field, so an array would waste memory. @@ -152,6 +172,10 @@ static int __init iommu_subsys_init(void) (iommu_cmd_line & IOMMU_CMD_LINE_STRICT) ? "(set via kernel command line)" : ""); + /* If the system is so broken that this fails, it will WARN anyway */ + for (int i = 0; i < ARRAY_SIZE(iommu_buses); i++) + iommu_bus_init(iommu_buses[i]); + return 0; } subsys_initcall(iommu_subsys_init); @@ -1772,35 +1796,19 @@ int bus_iommu_probe(struct bus_type *bus) return ret; } -static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops) +static int iommu_bus_init(struct bus_type *bus) { struct notifier_block *nb; int err; - nb = kzalloc(sizeof(struct notifier_block), GFP_KERNEL); + nb = kzalloc(sizeof(*nb), GFP_KERNEL); if (!nb) return -ENOMEM; nb->notifier_call = iommu_bus_notifier; - err = bus_register_notifier(bus, nb); if (err) - goto out_free; - - err = bus_iommu_probe(bus); - if (err) - goto out_err; - - - return 0; - -out_err: - /* Clean up */ - bus_for_each_dev(bus, NULL, NULL, remove_iommu_group); - bus_unregister_notifier(bus, nb); - -out_free: - kfree(nb); + kfree(nb); return err; } @@ -1833,9 +1841,12 @@ int bus_set_iommu(struct bus_type *bus, const struct iommu_ops *ops) bus->iommu_ops = ops; /* Do IOMMU specific setup for this bus-type */ - err = iommu_bus_init(bus, ops); - if (err) + err = bus_iommu_probe(bus); + if (err) { + /* Clean up */ + bus_for_each_dev(bus, NULL, NULL, remove_iommu_group); bus->iommu_ops = NULL; + } return err; } -- 2.36.1.dirty