From patchwork Tue Jun 2 07:48:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1302207 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49bkhT0PPJz9sSn; Tue, 2 Jun 2020 17:49:29 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jg1fp-0005RR-AH; Tue, 02 Jun 2020 07:49:25 +0000 Received: from mail-pl1-f196.google.com ([209.85.214.196]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1fm-0005Oo-V1 for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:23 +0000 Received: by mail-pl1-f196.google.com with SMTP id x11so1014685plv.9 for ; Tue, 02 Jun 2020 00:49:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g+iS2TZBfMHSMOSLhCIvEriNa52KXAilbk3SSaCFwv4=; b=agORUWE5WL6L+XnHN/msxwgu8vzUaEC2v12ngqAlyMLOh9Xxwbtd8VRz4EE8ftPSqR H8pO08U5wdwIJaydnNZhg81GpIiWAUkgHgT6CfKWLnLa38HjHFhuxiFPIptUWELClK1a rKQOqNhgoZ/1NHB0sgeWSGPNYTiF8qUdZ88LlCR0RhT87r6XTpD0KS7kNr9odhK/RQJp h1rkVJ1KD9obnNpiYUxqpCSRNLdNRMiVZRLmbVTQBGaiwC5VzK8YoovH7is2pfYi0+Cm brXt3GtJ5SgNB2DngfE4zAZjhNi/4lWNav90FdLTgN70jEKo04AMSVW7Uh9E3bnwSoeB dttA== X-Gm-Message-State: AOAM530Q7UaKd2M5hqADf160ESCgEJhjknagVGJY5W7moAxONBw7nJhj +2NtAw8EQlb54JqcDoE1fxX4kLvcuyI= X-Google-Smtp-Source: ABdhPJwWBHkF3lsveWMecP/3HuqsbSDPF9sg93lCUAvvNd4B74vDelk1dg9WPvDTi59Nt3nZUIH3iQ== X-Received: by 2002:a17:90a:7401:: with SMTP id a1mr3766000pjg.218.1591084160659; Tue, 02 Jun 2020 00:49:20 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id s36sm1508968pgl.35.2020.06.02.00.49.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:19 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 13/42][SRU][U] iommu: Export bus_iommu_probe() and make is safe for re-probing Date: Tue, 2 Jun 2020 15:48:14 +0800 Message-Id: <20200602074843.1743493-14-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200602074843.1743493-1-vicamo.yang@canonical.com> References: <20200602074843.1743493-1-vicamo.yang@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Joerg Roedel BugLink: https://bugs.launchpad.net/bugs/1876707 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. Signed-off-by: Joerg Roedel Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200429133712.31431-14-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 5012c3968537e2ffecbdb2eba3479bf9fb9e5597 linux-next) Signed-off-by: You-Sheng Yang --- 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 5c2a32d5935c..95b8701e191c 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1620,11 +1620,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; @@ -1793,7 +1801,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);