From patchwork Tue May 26 12:59:25 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: 1297984 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 49WYwv6mh8z9sRW; Tue, 26 May 2020 23:00:47 +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 1jdZCE-000429-GW; Tue, 26 May 2020 13:00:42 +0000 Received: from mail-pj1-f65.google.com ([209.85.216.65]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jdZC7-0003uv-Ds for kernel-team@lists.ubuntu.com; Tue, 26 May 2020 13:00:35 +0000 Received: by mail-pj1-f65.google.com with SMTP id fs4so1395822pjb.5 for ; Tue, 26 May 2020 06:00:35 -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=m4zT5erv4bS7O4xlXePJfR0u8zfvHQhjAPjMql6QgbYmuUQm5lB7VQqmPrno5mGDp2 fbABK5PXVUQtUpQzi4F581UGzFiMCt+jW51KNUsPEOssHyD9ckRb2TsqOqNyaYcg/jWu 5tF96ulw2nPMtH6pWIqgyJAg1PVYKyI9XSitGnaU66jrp7nlW8jtQYtvzn/8dFjpJH3M 2DsIKRTvNUNVZ68/S2AQ/KbNg0LelNWtXIAYTjpPuCOgs3BWxQn9ESQvOos6dtVNac7b p79eJ7QF2x50GgfxVEe+RQVXwzG+kCfcXF8hgaV4HsSC8NLiueL+ZidZ5zNHD5CLctDr PijA== X-Gm-Message-State: AOAM533tGk75c+mZqmzwsOVdknVw78slCDZwHvX5aulzUwbH/yyru2q7 KCszuI0dcAvIAkk0E00XWjYu19Tr1V8= X-Google-Smtp-Source: ABdhPJxDKaDRYq6RDpethOeIuTI5P7/YA2STrjDUx65HYzVbOGH0f7c5v10FLWCDO5T6bi39dGvRAg== X-Received: by 2002:a17:902:fe8d:: with SMTP id x13mr1019808plm.198.1590498032431; Tue, 26 May 2020 06:00:32 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id t12sm12523589pjf.3.2020.05.26.06.00.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2020 06:00:31 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 13/42][SRU][U] UBUNTU: SAUCE: iommu: Export bus_iommu_probe() and make is safe for re-probing Date: Tue, 26 May 2020 20:59:25 +0800 Message-Id: <20200526125954.237403-14-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200526125954.237403-1-vicamo.yang@canonical.com> References: <20200526125954.237403-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);