Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp629240ybz; Wed, 29 Apr 2020 06:40:11 -0700 (PDT) X-Google-Smtp-Source: APiQypIPXvJcfGaNWHoPAJRX8TUKoErhcsLHL2EQ1KJK4Ap7brRDU2TCGQLjP7PjYS5dodClBIyY X-Received: by 2002:a50:cb84:: with SMTP id k4mr2549738edi.89.1588167611765; Wed, 29 Apr 2020 06:40:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588167611; cv=none; d=google.com; s=arc-20160816; b=qr8qOViEm/hTDv0esnnsotRjubkbVSCMxY2yQCoWYAVTYaWh0afn+U3MvNHycW5vXv z80hik13f7sXYP49lDBA/3UrM3ig2+fSu5lII2cDAWwZ13WqSwmsc+xUagL+HWQnKqYQ LIUOxpxmq5c9heMaBhCqSP5JgJm0ev/LAbY+dE/q8jSEo9NHV4noStsmAyvy02milGMl I5GmlDFXL6KHSdD7go+ibO9jov3lkaxYdzj2PkK9BdXjNOJcfg7r7TkGr2rdS5osiOw1 sBM9EipbcBWeDPmnof6WBdL5kSCQCU1uNrgPekgbdbSPHJYDh9E03IUfUOfP5aGc/CBE s4Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=ALo4GUggUcM/NZfY4lN7aPZjFNAVUtBIEuw72LALTbA=; b=dQgPJLYqvTDw8EARH0n9MCaWieqFw4c0oQndnHCqZfwPnhAZscJRKwcmt62oPclutT fNOtc1MAAn4vw+O/1p54F1gVkPzsQtsNVDjUCBPKfm1kWXqJQy0vquPJqdB5XO4Z98mv KFj6iBDKTRyvcNZLHIQR2iD90jb6m4C24N/Qo0uy4KLmoHK6flzwjd4EB0UhTyPutZJM jCyQuxT2UypvRIcHjU29XxMUnhNzYorpzjujH2yaZD3r3hU9BNtmPHs+GxCK1Etn6EZ9 6bmCR+4Z9PSZiqnRh0YzIdiw0Kt/0z+fTa5BnnyxNRywVCKLmVsdZBAiQjubVjEpMR1S rOWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a3si3450054edv.206.2020.04.29.06.39.47; Wed, 29 Apr 2020 06:40:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728058AbgD2Nhx (ORCPT + 99 others); Wed, 29 Apr 2020 09:37:53 -0400 Received: from 8bytes.org ([81.169.241.247]:39788 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727944AbgD2Nhr (ORCPT ); Wed, 29 Apr 2020 09:37:47 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id BBE82BFC; Wed, 29 Apr 2020 15:37:37 +0200 (CEST) From: Joerg Roedel To: Joerg Roedel , Will Deacon , Robin Murphy , Marek Szyprowski , Kukjin Kim , Krzysztof Kozlowski , David Woodhouse , Lu Baolu , Andy Gross , Bjorn Andersson , Matthias Brugger , Rob Clark , Heiko Stuebner , Gerald Schaefer , Thierry Reding , Jonathan Hunter , Jean-Philippe Brucker Cc: Daniel Drake , jonathan.derrick@intel.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-tegra@vger.kernel.org, virtualization@lists.linux-foundation.org, Joerg Roedel Subject: [PATCH v3 13/34] iommu: Export bus_iommu_probe() and make is safe for re-probing Date: Wed, 29 Apr 2020 15:36:51 +0200 Message-Id: <20200429133712.31431-14-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200429133712.31431-1-joro@8bytes.org> References: <20200429133712.31431-1-joro@8bytes.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel Add a check to the bus_iommu_probe() call-path to make sure it ignores devices which have already been successfully probed. Then export the bus_iommu_probe() function so it can be used by IOMMU drivers. Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Signed-off-by: Joerg Roedel --- drivers/iommu/iommu.c | 10 +++++++++- include/linux/iommu.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 834a45da0ed0..397fd4fd0c32 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1610,11 +1610,19 @@ static int probe_iommu_group(struct device *dev, void *data) { const struct iommu_ops *ops = dev->bus->iommu_ops; struct list_head *group_list = data; + struct iommu_group *group; int ret; if (!dev_iommu_get(dev)) return -ENOMEM; + /* Device is probed already if in a group */ + group = iommu_group_get(dev); + if (group) { + iommu_group_put(group); + return 0; + } + if (!try_module_get(ops->owner)) { ret = -EINVAL; goto err_free_dev_iommu; @@ -1783,7 +1791,7 @@ static int iommu_group_create_direct_mappings(struct iommu_group *group) iommu_do_create_direct_mappings); } -static int bus_iommu_probe(struct bus_type *bus) +int bus_iommu_probe(struct bus_type *bus) { const struct iommu_ops *ops = bus->iommu_ops; int ret; diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 30170d191e5e..fea1622408ad 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -445,6 +445,7 @@ static inline void iommu_iotlb_gather_init(struct iommu_iotlb_gather *gather) #define IOMMU_GROUP_NOTIFY_UNBOUND_DRIVER 6 /* Post Driver unbind */ extern int bus_set_iommu(struct bus_type *bus, const struct iommu_ops *ops); +extern int bus_iommu_probe(struct bus_type *bus); extern bool iommu_present(struct bus_type *bus); extern bool iommu_capable(struct bus_type *bus, enum iommu_cap cap); extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus); -- 2.17.1