From patchwork Tue May 26 13:01:35 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: 1298045 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 49WZ1l4gC4z9sTP; Tue, 26 May 2020 23:04:59 +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 1jdZGI-000713-17; Tue, 26 May 2020 13:04:54 +0000 Received: from mail-pj1-f67.google.com ([209.85.216.67]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jdZEw-0005yW-RS for kernel-team@lists.ubuntu.com; Tue, 26 May 2020 13:03:31 +0000 Received: by mail-pj1-f67.google.com with SMTP id nu7so1405986pjb.0 for ; Tue, 26 May 2020 06:03:30 -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=iKX32KrHAjuBo4IZxyt5FQngiDOiMvFMQpmHEGnPyrU=; b=omT25HdTQsY5vkL6uEXW//TuLk5d0fEr2AH1LjnbDdpw+MUFvUj7aEEGWuaEJGEHnW ZTJzlYioIhmp4s7UeQkg8bD/VbuJEVfNHx2TsbO6wufi7Qd49fj27j5VFa9nEjtqYxLE vcssb5HrIisOQaNc+Sx5x60KhznUBih5R55bbysJnCYSVb8PfltiyNVGyyNjzchMqlDb FgF7Jm4CQMv4R+a/AiwWfNvL0/5PzrIkZAoHHAMxIpJSCYLBPi617CcwnXj1VCMJfFi3 hbWPFx6bfXBdHgZ3QZqTRjtbPHcNXQ4wlAK466iGrdR6n9SHObsxkLRspmq3XT1EeSj5 p8vQ== X-Gm-Message-State: AOAM532CPQiJ/Ho0y0Gdra0PM9iOK4sWhwRGb12hjFX/D+llOPovrSQg n/FnF6mGn1nzFMrminDOHlg/hjEHc2g= X-Google-Smtp-Source: ABdhPJya+u3qpw7hq+74pmhWQB51eKD3n6NHuSxsuvhgO4wZC+GZScjIv8ZUDolMMuejzPJ1ytl7jw== X-Received: by 2002:a17:90a:4b47:: with SMTP id o7mr23826839pjl.205.1590498206873; Tue, 26 May 2020 06:03:26 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id y138sm6653686pfb.33.2020.05.26.06.03.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2020 06:03:26 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 31/60][SRU][OEM-5.6] UBUNTU: SAUCE: iommu: Export bus_iommu_probe() and make is safe for re-probing Date: Tue, 26 May 2020 21:01:35 +0800 Message-Id: <20200526130204.238445-32-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200526130204.238445-1-vicamo.yang@canonical.com> References: <20200526130204.238445-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 iommu/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 874bd6e72f29..517faae131aa 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1611,11 +1611,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; @@ -1784,7 +1792,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);