Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp309336pxb; Thu, 14 Apr 2022 23:28:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqmtxmDIoAa2aCYUQ1Xl/4dhJK5GuM9gBwuJ7dWT91UTLjh8JgMDaCkD7uHCmjlLodgS6V X-Received: by 2002:a17:906:9746:b0:6e0:5c9a:1a20 with SMTP id o6-20020a170906974600b006e05c9a1a20mr5320583ejy.714.1650004103392; Thu, 14 Apr 2022 23:28:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650004103; cv=none; d=google.com; s=arc-20160816; b=oJZkf/aJTgeaeaJaFe+PAUb0t1qR90hw0s76AafBvIKKOacjI+BcM2ggKWdnVues2R 38mPcnGWiQZ+sT3HQSgi2i5jhS03GEVAdLMWtnFk2V3gEbTJPifDo8662gIHQA5VhQkp dt53e65bc9fMl1CJ53iyEUGFE9nbN10wo7/D0HqCJXk+v/k8P+cS1+p/tT1ArirKLpsf +Y12Nf+Md3IkJprcmEsBYEFc9mOppkxcyPDUgter6f/Lb1ZPMyYI0CkhTn/YjJnQ+DST Ra04QiQHzDcwhERDHfywPsMk6aPGckc5YoAVqnUmqt5W2xKLLfgvXyt5ka1Thqc9R+6R 6RzA== 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=lffeO+mExD+NjQXiy9/PuEgPB1A/WdRO+aWILPJqnn8=; b=lwH4HOyYkWWnuTgRGS92hKBcATSR6byw3gFM4JHLp+iBKGf6dPXNn/I8rmZlX1LYxu +Xc4+ZXmK3FP7KuOdOxEG5vPz7I7m3TdxvWTlCAzfObVp3U1h1dvqLTKYSnfnt3N/ET9 uiBtr7AcojGFrQDsmWc6zRDrBF1L7RFJ5XwpFM5+GJDpGpRrDy6CRI30UlUvs1CySEFX A1+xbRN6yfavR328VmarN6jaeb1hQr7rR6tQvY8JbUc5z/d0cuj74FuKzGBVA+GHU1Gl 5cxcMfxUaN0Gsxuy+tZw3eA/PFDLpbOhG92s8n7fWdrKoX0bjfYThkif2C9Tnpp5Zc6z nPhw== 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 jz11-20020a17090775eb00b006e106ad0114si420473ejc.900.2022.04.14.23.27.57; Thu, 14 Apr 2022 23:28:23 -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 S243480AbiDNMpX (ORCPT + 99 others); Thu, 14 Apr 2022 08:45:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243472AbiDNMpR (ORCPT ); Thu, 14 Apr 2022 08:45:17 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 622DC85666 for ; Thu, 14 Apr 2022 05:42:52 -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 25A44139F; Thu, 14 Apr 2022 05:42:52 -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 2B9943F70D; Thu, 14 Apr 2022 05:42:50 -0700 (PDT) From: Robin Murphy To: joro@8bytes.org, will@kernel.org Cc: iommu@lists.linux-foundation.org, sven@svenpeter.dev, robdclark@gmail.com, m.szyprowski@samsung.com, baolu.lu@linux.intel.com, yong.wu@mediatek.com, mjrosato@linux.ibm.com, gerald.schaefer@linux.ibm.com, zhang.lyra@gmail.com, thierry.reding@gmail.com, vdumpa@nvidia.com, jean-philippe@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/13] iommu: Move bus setup to IOMMU device registration Date: Thu, 14 Apr 2022 13:42:31 +0100 Message-Id: X-Mailer: git-send-email 2.28.0.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_PASS,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 Move the bus setup to iommu_device_register(). This should allow bus_iommu_probe() to be correctly replayed for multiple IOMMU instances, and leaves bus_set_iommu() as a glorfied no-op to be cleaned up next. Note that although the handling of errors from bus_iommu_probe() looks inadequate, it is merely preserving the well-established existing behaviour. This could be improved in future - probably combined with equivalent cleanup for iommu_device_unregister() - but that isn't a priority right now. Signed-off-by: Robin Murphy --- drivers/iommu/iommu.c | 50 ++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 13e1a8bd5435..51205c33c426 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -175,6 +175,14 @@ static int __init iommu_subsys_init(void) } subsys_initcall(iommu_subsys_init); +static int remove_iommu_group(struct device *dev, void *data) +{ + if (dev->iommu && dev->iommu->iommu_dev == data) + iommu_release_device(dev); + + return 0; +} + /** * iommu_device_register() - Register an IOMMU hardware instance * @iommu: IOMMU handle for the instance @@ -197,6 +205,22 @@ int iommu_device_register(struct iommu_device *iommu, spin_lock(&iommu_device_lock); list_add_tail(&iommu->list, &iommu_device_list); spin_unlock(&iommu_device_lock); + + for (int i = 0; i < ARRAY_SIZE(iommu_buses); i++) { + struct bus_type *bus = iommu_buses[i]; + const struct iommu_ops *bus_ops = bus->iommu_ops; + int err; + + WARN_ON(bus_ops && bus_ops != ops); + bus->iommu_ops = ops; + err = bus_iommu_probe(bus); + if (err) { + bus_for_each_dev(bus, NULL, iommu, remove_iommu_group); + bus->iommu_ops = bus_ops; + return err; + } + } + return 0; } EXPORT_SYMBOL_GPL(iommu_device_register); @@ -1654,13 +1678,6 @@ static int probe_iommu_group(struct device *dev, void *data) return ret; } -static int remove_iommu_group(struct device *dev, void *data) -{ - iommu_release_device(dev); - - return 0; -} - static int iommu_bus_notifier(struct notifier_block *nb, unsigned long action, void *data) { @@ -1883,27 +1900,12 @@ static int iommu_bus_init(struct bus_type *bus) */ int bus_set_iommu(struct bus_type *bus, const struct iommu_ops *ops) { - int err; - - if (ops == NULL) { - bus->iommu_ops = NULL; - return 0; - } - - if (bus->iommu_ops != NULL) + if (bus->iommu_ops && ops && bus->iommu_ops != ops) return -EBUSY; bus->iommu_ops = ops; - /* Do IOMMU specific setup for this bus-type */ - 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; + return 0; } EXPORT_SYMBOL_GPL(bus_set_iommu); -- 2.28.0.dirty