From patchwork Tue Jun 2 07:48:02 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: 1302195 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 49bkgr1kMGz9sSy; Tue, 2 Jun 2020 17:48:56 +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 1jg1fJ-00050Z-9m; Tue, 02 Jun 2020 07:48:53 +0000 Received: from mail-pf1-f196.google.com ([209.85.210.196]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1fH-0004zO-5A for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:48:51 +0000 Received: by mail-pf1-f196.google.com with SMTP id a4so4682029pfo.4 for ; Tue, 02 Jun 2020 00:48:51 -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=TwSO0oD5f2JKRCwgYKM4hoJ4i6sh4v36OkCdXmb+ojg=; b=TKXvSjmdEHexYK5AjUKpG0AFgBLIDOZ92H5Y4NXKLdS8RbRqZLFN8YOI996ck/N7sZ yIK4H2ifsF3IPHv/YRguyXGDY/Qz7laENes10ZFHvfHEHNvUlwe3e82zR6O7o4oUJ0u3 Ldew8IdC09T6/76be8XzmG1iAoHt98DrR8J6YFHTR17hdB7z1FELi9rXvPO7RYRq/J2O 8S42GqpOJQANPR4oIxHBpwkO8lIM1BQmEEioz8psRNsTKNZqssGBvBIsylVarVwILn+6 8EZ9PYOUBM9Tw3t/AbtQnWE45nn8/Hq7bJMnVPOLhLjnNYkLTX+Uho36SPQb1bj0zmFr ldWg== X-Gm-Message-State: AOAM533e+ciFb2S1U8CKxJdz5/FjATwlH2SeVqdGx5/fwCUdrdRk1neU Lr3VWaaXDVYCNRrs0OauaE02rEph4HY= X-Google-Smtp-Source: ABdhPJxbkWRT0Clgvqql14I8X+MSm3f6zM0v4+ZVgC8/LXlT30/yDBqgkgz6BsxImMO10XdIth8lwA== X-Received: by 2002:a62:ee02:: with SMTP id e2mr23416844pfi.161.1591084129247; Tue, 02 Jun 2020 00:48:49 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id 25sm1397358pjk.50.2020.06.02.00.48.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:48:48 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 01/42][SRU][U] iommu: Move default domain allocation to separate function Date: Tue, 2 Jun 2020 15:48:02 +0800 Message-Id: <20200602074843.1743493-2-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 Move the code out of iommu_group_get_for_dev() into a separate function. Signed-off-by: Joerg Roedel Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200429133712.31431-2-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit ff2a08b39bcede1b08d84d8b5c8ee1336a39c5df linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/iommu.c | 74 ++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 03d6a26687bc..207e67652992 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1371,6 +1371,41 @@ struct iommu_group *fsl_mc_device_group(struct device *dev) } EXPORT_SYMBOL_GPL(fsl_mc_device_group); +static int iommu_alloc_default_domain(struct device *dev, + struct iommu_group *group) +{ + struct iommu_domain *dom; + + if (group->default_domain) + return 0; + + dom = __iommu_domain_alloc(dev->bus, iommu_def_domain_type); + if (!dom && iommu_def_domain_type != IOMMU_DOMAIN_DMA) { + dom = __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_DMA); + if (dom) { + dev_warn(dev, + "failed to allocate default IOMMU domain of type %u; falling back to IOMMU_DOMAIN_DMA", + iommu_def_domain_type); + } + } + + if (!dom) + return -ENOMEM; + + group->default_domain = dom; + if (!group->domain) + group->domain = dom; + + if (!iommu_dma_strict) { + int attr = 1; + iommu_domain_set_attr(dom, + DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE, + &attr); + } + + return 0; +} + /** * iommu_group_get_for_dev - Find or create the IOMMU group for a device * @dev: target device @@ -1403,40 +1438,21 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev) /* * Try to allocate a default domain - needs support from the - * IOMMU driver. + * IOMMU driver. There are still some drivers which don't support + * default domains, so the return value is not yet checked. */ - if (!group->default_domain) { - struct iommu_domain *dom; - - dom = __iommu_domain_alloc(dev->bus, iommu_def_domain_type); - if (!dom && iommu_def_domain_type != IOMMU_DOMAIN_DMA) { - dom = __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_DMA); - if (dom) { - dev_warn(dev, - "failed to allocate default IOMMU domain of type %u; falling back to IOMMU_DOMAIN_DMA", - iommu_def_domain_type); - } - } - - group->default_domain = dom; - if (!group->domain) - group->domain = dom; - - if (dom && !iommu_dma_strict) { - int attr = 1; - iommu_domain_set_attr(dom, - DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE, - &attr); - } - } + iommu_alloc_default_domain(dev, group); ret = iommu_group_add_device(group, dev); - if (ret) { - iommu_group_put(group); - return ERR_PTR(ret); - } + if (ret) + goto out_put_group; return group; + +out_put_group: + iommu_group_put(group); + + return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(iommu_group_get_for_dev); From patchwork Tue Jun 2 07:48:03 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: 1302196 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 49bkgt4VjHz9sSn; Tue, 2 Jun 2020 17:48:58 +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 1jg1fL-00051s-Eo; Tue, 02 Jun 2020 07:48:55 +0000 Received: from mail-pg1-f194.google.com ([209.85.215.194]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1fJ-00050S-JS for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:48:53 +0000 Received: by mail-pg1-f194.google.com with SMTP id j21so4715394pgb.7 for ; Tue, 02 Jun 2020 00:48:53 -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=XbH59jNF/vCOChzXOmZYUineHEQ7t7+YePGASW+MlUg=; b=noeIgtd/U769Y3KPicLXydM2UzsCMk4tmgMJP8tworqQ6DoVw8oZoxszIyxez8O//L WxsdhyiFxPHjahoR5+9/jOWkczJy0YClaxVQnLoqtCC+gDqGT0kvHn2QQ00Yxk3mC0Zr 1fN6WWUwl7YijcFASyr63aWc85AbTwGOiyRpzRibRu6cdIECWMBKYDk2rLEM24bslMP9 mvkoKiKNFj9RZrgI1yupqQ0txzxUSP0YAiH7EaC65crICZRfXuvipn1lyjKonMH9R7T6 GbGFl4XZ1jO7oXj6qtW7uZ8apfAuwpxYpybxskD0EnIm0Vz0LMEenUJZdDAbh1se13om rroA== X-Gm-Message-State: AOAM5338maig6uh2PZ3yon12fzF28D+6r83voM4A1MC1A59v3N0dmKiE 2IgstgyLZPs74t74YGQzqz7bgx3VF74= X-Google-Smtp-Source: ABdhPJxUKnAR+KMzbzgZudav9adg+8HXqxb+OnOgqRWM7ngzEFusvlDJcPEKPozRZBIJuz7MnGJ2ZQ== X-Received: by 2002:a63:9258:: with SMTP id s24mr22966376pgn.362.1591084131654; Tue, 02 Jun 2020 00:48:51 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id n19sm1483271pfu.194.2020.06.02.00.48.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:48:50 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 02/42][SRU][U] iommu: Add def_domain_type() callback in iommu_ops Date: Tue, 2 Jun 2020 15:48:03 +0800 Message-Id: <20200602074843.1743493-3-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: Sai Praneeth Prakhya BugLink: https://bugs.launchpad.net/bugs/1876707 Some devices are reqired to use a specific type (identity or dma) of default domain when they are used with a vendor iommu. When the system level default domain type is different from it, the vendor iommu driver has to request a new default domain with iommu_request_dma_domain_for_dev() and iommu_request_dm_for_dev() in the add_dev() callback. Unfortunately, these two helpers only work when the group hasn't been assigned to any other devices, hence, some vendor iommu driver has to use a private domain if it fails to request a new default one. This adds def_domain_type() callback in the iommu_ops, so that any special requirement of default domain for a device could be aware by the iommu generic layer. Signed-off-by: Sai Praneeth Prakhya Signed-off-by: Lu Baolu [ jroedel@suse.de: Added iommu_get_def_domain_type() function and use it to allocate the default domain ] Co-developed-by: Joerg Roedel Signed-off-by: Joerg Roedel Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200429133712.31431-3-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 4cbf38511a007867def958872203ae8adb8e2351 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/iommu.c | 20 +++++++++++++++++--- include/linux/iommu.h | 6 ++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 207e67652992..cff8d1ac0961 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1371,21 +1371,35 @@ struct iommu_group *fsl_mc_device_group(struct device *dev) } EXPORT_SYMBOL_GPL(fsl_mc_device_group); +static int iommu_get_def_domain_type(struct device *dev) +{ + const struct iommu_ops *ops = dev->bus->iommu_ops; + unsigned int type = 0; + + if (ops->def_domain_type) + type = ops->def_domain_type(dev); + + return (type == 0) ? iommu_def_domain_type : type; +} + static int iommu_alloc_default_domain(struct device *dev, struct iommu_group *group) { struct iommu_domain *dom; + unsigned int type; if (group->default_domain) return 0; - dom = __iommu_domain_alloc(dev->bus, iommu_def_domain_type); - if (!dom && iommu_def_domain_type != IOMMU_DOMAIN_DMA) { + type = iommu_get_def_domain_type(dev); + + dom = __iommu_domain_alloc(dev->bus, type); + if (!dom && type != IOMMU_DOMAIN_DMA) { dom = __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_DMA); if (dom) { dev_warn(dev, "failed to allocate default IOMMU domain of type %u; falling back to IOMMU_DOMAIN_DMA", - iommu_def_domain_type); + type); } } diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 7ef8b0bda695..1f027b07e499 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -248,6 +248,10 @@ struct iommu_iotlb_gather { * @cache_invalidate: invalidate translation caches * @sva_bind_gpasid: bind guest pasid and mm * @sva_unbind_gpasid: unbind guest pasid and mm + * @def_domain_type: device default domain type, return value: + * - IOMMU_DOMAIN_IDENTITY: must use an identity domain + * - IOMMU_DOMAIN_DMA: must use a dma domain + * - 0: use the default setting * @pgsize_bitmap: bitmap of all possible supported page sizes * @owner: Driver module providing these ops */ @@ -318,6 +322,8 @@ struct iommu_ops { int (*sva_unbind_gpasid)(struct device *dev, int pasid); + int (*def_domain_type)(struct device *dev); + unsigned long pgsize_bitmap; struct module *owner; }; From patchwork Tue Jun 2 07:48:04 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: 1302197 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 49bkgx67Dqz9sSg; Tue, 2 Jun 2020 17:49:01 +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 1jg1fO-00053q-NA; Tue, 02 Jun 2020 07:48:58 +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 1jg1fM-00052D-HF for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:48:56 +0000 Received: by mail-pj1-f67.google.com with SMTP id s88so1047408pjb.5 for ; Tue, 02 Jun 2020 00:48:56 -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=vozkoBQ9ZhSFG4iWGNvhEN6Nnuq3ZGnfXjLp+I50iHc=; b=iPItVYRJdhwel9oHU5wH4NtjC8Nm6jdoIMzpmPXBU2TkhWW5cb4yb3DySbASh9dykr K3T4RVj3LDFA+HeoCE4eUXegCwMin3K8deAl+8MqDcRrU/5m4AYm+Rw7j7mpAdOTRfEf Hb2PRMHc+la1S4i+G1YfMiBHCyAq+XeD234nQCbpLUyVTZQGXkmd1+3PEVtEcxWI1Bmg JxfP2ugchUEtLxAFBHUh8l/U5ZfJ9+pNz4Er3f5pDus2TZFCh8LaY9Rwccch8Q2AcpKx T/GsbXloXdP5lTfRse+Rb7qrIsQfYSocxGQRLPHRM7jxxWhD5K/yP1tVYvBiG42/Qf8/ PZvg== X-Gm-Message-State: AOAM532pEGmTpUo9KFC2TwUa2lNtJ9DqdgBAZ9aRqWmNvQqWO5bx6M4r g4nIjVCMPhYsLaA+Hir/IUFMYlkDD0g= X-Google-Smtp-Source: ABdhPJzStPu4iWm7+7FZtvyJgKhomJ+iK8VpLq+U61LPt//kkjRmsK0R7ShtaBQw9WOQas3zBF863w== X-Received: by 2002:a17:902:7897:: with SMTP id q23mr7857871pll.5.1591084134626; Tue, 02 Jun 2020 00:48:54 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id y23sm1562195pje.3.2020.06.02.00.48.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:48:53 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 03/42][SRU][U] iommu/amd: Implement iommu_ops->def_domain_type call-back Date: Tue, 2 Jun 2020 15:48:04 +0800 Message-Id: <20200602074843.1743493-4-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 Implement the new def_domain_type call-back for the AMD IOMMU driver. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-4-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit bdf4a7c4c77dcb91bd64b53b70d9faf3184e88d8 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/amd_iommu.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 2883ac389abb..02e80a55b177 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -2758,6 +2758,20 @@ static void amd_iommu_iotlb_sync(struct iommu_domain *domain, amd_iommu_flush_iotlb_all(domain); } +static int amd_iommu_def_domain_type(struct device *dev) +{ + struct iommu_dev_data *dev_data; + + dev_data = get_dev_data(dev); + if (!dev_data) + return 0; + + if (dev_data->iommu_v2) + return IOMMU_DOMAIN_IDENTITY; + + return 0; +} + const struct iommu_ops amd_iommu_ops = { .capable = amd_iommu_capable, .domain_alloc = amd_iommu_domain_alloc, @@ -2777,6 +2791,7 @@ const struct iommu_ops amd_iommu_ops = { .pgsize_bitmap = AMD_IOMMU_PGSIZES, .flush_iotlb_all = amd_iommu_flush_iotlb_all, .iotlb_sync = amd_iommu_iotlb_sync, + .def_domain_type = amd_iommu_def_domain_type, }; /***************************************************************************** From patchwork Tue Jun 2 07:48:05 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: 1302198 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 49bkh10BLbz9sSd; Tue, 2 Jun 2020 17:49:05 +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 1jg1fR-00055f-5L; Tue, 02 Jun 2020 07:49:01 +0000 Received: from mail-pg1-f196.google.com ([209.85.215.196]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1fO-00053b-Vv for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:48:59 +0000 Received: by mail-pg1-f196.google.com with SMTP id o6so4727123pgh.2 for ; Tue, 02 Jun 2020 00:48:58 -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=1z3BocyLQku44B1f97dcLwTasmlnjYUwTzMAC9w7lTQ=; b=Dt1J7eyNGPhvgpBkXS8ufWHJni/UWzVWy+kSMkgOjjUxtA/Wz+ie0OFeddn9e/rXE/ GYgi9gKQTd68UlQil7iKrXDnOLbAet5d3barwshejQFVvzQKXr1SPloyjpHlqCjPSlwa tiyJiDjfjv+tehPtY2eQKLefErZOYXMUIyJ0ayFXXK/xeLJFxRjOXtSfmae8dGKBU4MJ tdk8r/PkAQIJATUJS1MhjVRmoVRQUCAr6pvBcgo/gRn0dAJvlTNnvJz2i9h8qsXGk5Z0 QV5mbDSdsj1z11orwAAwupAzY32FiFZOs0Yq6UEunnaFesb6THoPXIpV/CLWp0cRMmJC EICg== X-Gm-Message-State: AOAM532C8vSmh1SWqpKSveZawy0NUrhwwMFJrAShPGxDpyExLdIQZov0 KMDjIUHMX+I65XsR5RqyiWEPnaaEOPk= X-Google-Smtp-Source: ABdhPJwvTAqQl+/9pZawCQ4cHMeUU7R0QKy4iygfruRFiU00RTz0MO2d/yNV4gQjj2gOdG4BECpk/Q== X-Received: by 2002:aa7:850f:: with SMTP id v15mr24871064pfn.277.1591084137070; Tue, 02 Jun 2020 00:48:57 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id i21sm1482967pgn.20.2020.06.02.00.48.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:48:56 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 04/42][SRU][U] iommu/vt-d: Wire up iommu_ops->def_domain_type Date: Tue, 2 Jun 2020 15:48:05 +0800 Message-Id: <20200602074843.1743493-5-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 The Intel VT-d driver already has a matching function to determine the default domain type for a device. Wire it up in intel_iommu_ops. Signed-off-by: Joerg Roedel Reviewed-by: Lu Baolu Link: https://lore.kernel.org/r/20200429133712.31431-5-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 7039d11b3e4af77cf5ac1f689ae395b2a183bd25 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/intel-iommu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 0182cff2c7ac..c9e11964fed3 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -6209,6 +6209,7 @@ const struct iommu_ops intel_iommu_ops = { .dev_enable_feat = intel_iommu_dev_enable_feat, .dev_disable_feat = intel_iommu_dev_disable_feat, .is_attach_deferred = intel_iommu_is_attach_deferred, + .def_domain_type = device_def_domain_type, .pgsize_bitmap = INTEL_IOMMU_PGSIZES, }; From patchwork Tue Jun 2 07:48:06 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: 1302199 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 49bkh16yhmz9sSy; Tue, 2 Jun 2020 17:49:05 +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 1jg1fS-00057Q-QK; Tue, 02 Jun 2020 07:49:02 +0000 Received: from mail-pf1-f193.google.com ([209.85.210.193]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1fR-00055S-Mz for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:01 +0000 Received: by mail-pf1-f193.google.com with SMTP id f3so4669601pfd.11 for ; Tue, 02 Jun 2020 00:49:01 -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=0vkCbB51acvLInlBqLAhB5QstEwbs6IoQK2eKSGo/Vk=; b=O/U+4ZDDM3rgGFCvthtidVXltQ+FX/GQUFqN5oy65GnLw6LPuPHnu+XF5DgkiUzCCU /h4Ktg331+W/1KKdMF9FqaEu8Lx1eg4jDRqJbxkbLOLVFsugpBsH7n8wWrn9s7ziM9Lx bbI0mGEMEzMAvt5Zx5WKZ1Xbhl22SA/FTm91NvmWgkz/lZ6527FM2gJbW2BdExNfbb+B HS8UvC3hOGNSBMDi/d0PPeUn2OvowNqPKTttcGK4fNnq/4XAoKzH8rnImUxBwjbey5rP fQfuq4GTuwwLifaRFu5ve7mlLHyVcBjE3HvuPfEALfBUmVhhBRuO1NnoSdlv04jLweRb H9SA== X-Gm-Message-State: AOAM533iIbMA+F9NlkrtoYUvGS7hbB62piD3NHzlJVr95/6VHTkLGiAI FnSetLCSVpaAykOh9/4/CJpYDDYttJU= X-Google-Smtp-Source: ABdhPJy2s9Rm4Y44yr2p5AcYSRU87fLu7X/XzsnhMWfSz4WcdExGIqHicMoLAyXht3LtCtpeN2suGw== X-Received: by 2002:aa7:9aca:: with SMTP id x10mr5224204pfp.146.1591084139637; Tue, 02 Jun 2020 00:48:59 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id f11sm1538971pfk.58.2020.06.02.00.48.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:48:58 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 05/42][SRU][U] iommu/amd: Remove dma_mask check from check_device() Date: Tue, 2 Jun 2020 15:48:06 +0800 Message-Id: <20200602074843.1743493-6-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 The check was only needed for the DMA-API implementation in the AMD IOMMU driver, which no longer exists. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-6-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit c0da9b9f5afdb56ae2aaccf79f36a358ac8454c8 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/amd_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 02e80a55b177..524e71ccd5a1 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -349,7 +349,7 @@ static bool check_device(struct device *dev) { int devid; - if (!dev || !dev->dma_mask) + if (!dev) return false; devid = get_device_id(dev); From patchwork Tue Jun 2 07:48:07 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: 1302200 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 49bkh54lL0z9sSg; Tue, 2 Jun 2020 17:49:09 +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 1jg1fW-0005Au-6i; Tue, 02 Jun 2020 07:49:06 +0000 Received: from mail-pl1-f193.google.com ([209.85.214.193]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1fU-000585-DU for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:04 +0000 Received: by mail-pl1-f193.google.com with SMTP id q16so1029689plr.2 for ; Tue, 02 Jun 2020 00:49:04 -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=07UJQ4UXc8TYteoMmBMXwhhDm9h/2VvTAn37WUCvxHg=; b=i25js87TlRYNB1YiGvpW2gz5GZnpqaJr27r/sxZ05CDj1H6AK/YVUryyeP0ls+u0zk chQS8T6Vr4D7RzeT9LLTTO0FxoTj8FPB9qV0LB6M4SrmrvhZqXNxFNsoPg+pZJKY2Ott TWFkIJLkyPrvFZL0WINRQCRMnRshmoP7AdeJOfGJimGcwaccbbHtnaKarwTbCqZ9z5LG qkpiaqszt9ArtUOkPEf3VEQw9d/W7djUQwXwchnY/TFDZrMLyZtvvdAhSAiEx/R5GS52 ZfBVWCLTlKoFxOOFWsIVxiEpcjoRlbslurxMdE6TwCh1eMj9zKWtBG8+LDRB7HGPYUZB B57Q== X-Gm-Message-State: AOAM531J230BU9fK+KuBUEx+h4yo1YOgmNet0q4LrBisy9zsGsStVPx1 +XQS5ADsKMWhtxwfy4B3p4t5Ux7w0Fs= X-Google-Smtp-Source: ABdhPJxbACrRnFIaK8ErHRAabu3do5VwXePq1HXkwowd97ejQQCu3yLmpZif6GAIqAhlAQU5AYHRyg== X-Received: by 2002:a17:90a:c588:: with SMTP id l8mr4131123pjt.178.1591084141997; Tue, 02 Jun 2020 00:49:01 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id 25sm1397954pjk.50.2020.06.02.00.49.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:01 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 06/42][SRU][U] iommu/amd: Return -ENODEV in add_device when device is not handled by IOMMU Date: Tue, 2 Jun 2020 15:48:07 +0800 Message-Id: <20200602074843.1743493-7-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 When check_device() fails on the device, it is not handled by the IOMMU and amd_iommu_add_device() needs to return -ENODEV. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-7-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 57bd2c24ba1673bd47828f6ac5eaaa6292a03582 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/amd_iommu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 524e71ccd5a1..39c68487f67b 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -2229,9 +2229,12 @@ static int amd_iommu_add_device(struct device *dev) struct amd_iommu *iommu; int ret, devid; - if (!check_device(dev) || get_dev_data(dev)) + if (get_dev_data(dev)) return 0; + if (!check_device(dev)) + return -ENODEV; + devid = get_device_id(dev); if (devid < 0) return devid; From patchwork Tue Jun 2 07:48:08 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: 1302201 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 49bkhB0Mm6z9sSg; Tue, 2 Jun 2020 17:49:14 +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 1jg1fa-0005Ei-EW; Tue, 02 Jun 2020 07:49:10 +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 1jg1fW-0005Ad-NO for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:06 +0000 Received: by mail-pj1-f67.google.com with SMTP id nu7so993011pjb.0 for ; Tue, 02 Jun 2020 00:49:06 -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=DE+ED7pXpVb07sESz1ek9DquHSPsQ+OfhAjWilpGi+8=; b=tQQUXsDRzPrRGQdH1k90lcuBL0JetIqljifsDRX2jzJq06/iASYyIoC/D7onkt+i/X IEmUtGFfrrsg/5p84YHQqtxvto7mZ3snIo1a6l79sWNs2cVd2Fn4zzomm0rFqEbFx3X1 IC7rmMhTJYFom0CI3soygpIHyWMFT1sCm1gf70C+TorvpgOivFMza8hc07+nuJIDCRsl qj0AKeCHbehi4e7TaHfozb0jABQZMWrCYCVahnsh91WndJ6wPYZPHBT2z7xg3sZ5EkWV i/CiwnXZXeELgUd3dJV/MNZJPBhiulZX+g1YOlvOwtYdduP7aWnMu1ClUZBiPRRCNMHH A2bw== X-Gm-Message-State: AOAM532JLk5nDKr3CTZMwg7OQ/7QuXbikF3+RQNPGi9B1giRr+EnztJ9 eXnUXEQTwgTFNl+/xfo6xAn1usMG9kU= X-Google-Smtp-Source: ABdhPJxQn9gJeEyufENKsftiSjqITR3p4SLA+cUlNigsLK1ICvYl2ZdHHGN6ykj2f8mLV6bcbEWE1A== X-Received: by 2002:a17:90a:b384:: with SMTP id e4mr3809963pjr.1.1591084144800; Tue, 02 Jun 2020 00:49:04 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id j6sm1503262pfi.183.2020.06.02.00.49.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:04 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 07/42][SRU][U] iommu: Add probe_device() and release_device() call-backs Date: Tue, 2 Jun 2020 15:48:08 +0800 Message-Id: <20200602074843.1743493-8-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 call-backs to 'struct iommu_ops' as an alternative to the add_device() and remove_device() call-backs, which will be removed when all drivers are converted. The new call-backs will not setup IOMMU groups and domains anymore, so also add a probe_finalize() call-back where the IOMMU driver can do per-device setup work which require the device to be set up with a group and a domain. Signed-off-by: Joerg Roedel Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200429133712.31431-8-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit a6a4c7e2c5b8b981d1c546a393ff21f2112468c3 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/iommu.c | 63 ++++++++++++++++++++++++++++++++++++++----- include/linux/iommu.h | 9 +++++++ 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index cff8d1ac0961..3ae0b9a85d80 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -175,6 +175,36 @@ static void dev_iommu_free(struct device *dev) dev->iommu = NULL; } +static int __iommu_probe_device(struct device *dev) +{ + const struct iommu_ops *ops = dev->bus->iommu_ops; + struct iommu_device *iommu_dev; + struct iommu_group *group; + int ret; + + iommu_dev = ops->probe_device(dev); + if (IS_ERR(iommu_dev)) + return PTR_ERR(iommu_dev); + + dev->iommu->iommu_dev = iommu_dev; + + group = iommu_group_get_for_dev(dev); + if (!IS_ERR(group)) { + ret = PTR_ERR(group); + goto out_release; + } + iommu_group_put(group); + + iommu_device_link(iommu_dev, dev); + + return 0; + +out_release: + ops->release_device(dev); + + return ret; +} + int iommu_probe_device(struct device *dev) { const struct iommu_ops *ops = dev->bus->iommu_ops; @@ -192,10 +222,17 @@ int iommu_probe_device(struct device *dev) goto err_free_dev_param; } - ret = ops->add_device(dev); + if (ops->probe_device) + ret = __iommu_probe_device(dev); + else + ret = ops->add_device(dev); + if (ret) goto err_module_put; + if (ops->probe_finalize) + ops->probe_finalize(dev); + return 0; err_module_put: @@ -205,17 +242,31 @@ int iommu_probe_device(struct device *dev) return ret; } +static void __iommu_release_device(struct device *dev) +{ + const struct iommu_ops *ops = dev->bus->iommu_ops; + + iommu_device_unlink(dev->iommu->iommu_dev, dev); + + iommu_group_remove_device(dev); + + ops->release_device(dev); +} + void iommu_release_device(struct device *dev) { const struct iommu_ops *ops = dev->bus->iommu_ops; - if (dev->iommu_group) + if (!dev->iommu) + return; + + if (ops->release_device) + __iommu_release_device(dev); + else if (dev->iommu_group) ops->remove_device(dev); - if (dev->iommu) { - module_put(ops->owner); - dev_iommu_free(dev); - } + module_put(ops->owner); + dev_iommu_free(dev); } static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus, diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 1f027b07e499..30170d191e5e 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -225,6 +225,10 @@ struct iommu_iotlb_gather { * @iova_to_phys: translate iova to physical address * @add_device: add device to iommu grouping * @remove_device: remove device from iommu grouping + * @probe_device: Add device to iommu driver handling + * @release_device: Remove device from iommu driver handling + * @probe_finalize: Do final setup work after the device is added to an IOMMU + * group and attached to the groups domain * @device_group: find iommu group for a particular device * @domain_get_attr: Query domain attributes * @domain_set_attr: Change domain attributes @@ -275,6 +279,9 @@ struct iommu_ops { phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova); int (*add_device)(struct device *dev); void (*remove_device)(struct device *dev); + struct iommu_device *(*probe_device)(struct device *dev); + void (*release_device)(struct device *dev); + void (*probe_finalize)(struct device *dev); struct iommu_group *(*device_group)(struct device *dev); int (*domain_get_attr)(struct iommu_domain *domain, enum iommu_attr attr, void *data); @@ -375,6 +382,7 @@ struct iommu_fault_param { * * @fault_param: IOMMU detected device fault reporting data * @fwspec: IOMMU fwspec data + * @iommu_dev: IOMMU device this device is linked to * @priv: IOMMU Driver private data * * TODO: migrate other per device data pointers under iommu_dev_data, e.g. @@ -384,6 +392,7 @@ struct dev_iommu { struct mutex lock; struct iommu_fault_param *fault_param; struct iommu_fwspec *fwspec; + struct iommu_device *iommu_dev; void *priv; }; From patchwork Tue Jun 2 07:48:09 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: 1302202 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 49bkhF1PgGz9sSy; Tue, 2 Jun 2020 17:49:17 +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 1jg1fd-0005Gr-4e; Tue, 02 Jun 2020 07:49:13 +0000 Received: from mail-pg1-f194.google.com ([209.85.215.194]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1fZ-0005Cv-5k for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:09 +0000 Received: by mail-pg1-f194.google.com with SMTP id u5so4725298pgn.5 for ; Tue, 02 Jun 2020 00:49:09 -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=N4l7ChSkQbfRAC+LLIYsN/yC+vriEEfRk+y1L/urXDw=; b=SJ0BIBHaPtCMOautu6cCano586qvyVBPK/+ex9lL9vwUEPtuunzIdCcDjtZpEOhtRa N4a5Q+Wwtax0e3vSFu6Kblb3jht6kR8Y29xCpHb6mwJDCrlfnqJFR7gYW8mUex1qHPDv usKSOwWyT8KbPx+5wZeIUCqutbEyelUMWJMY5DqtwBteX8ma46uZyVlCCC6552MI6dtY VMshvS08rnA0blLAYjgbrTDc0AxZcc0mqI+poKvBxkY7efqxq1Hc9qnCrktZe0xKPZGi 0pMSqOzuwJqSBlDxHjMGKMclCjo5EG1LukdF2TnKVLeTMd/8hKEISV/YCSaBjnRgtU3c swBg== X-Gm-Message-State: AOAM531i/gcmvJe26uEEGih9D+gjLhfcaUO0DMA46ph9yySzQc+wCgd9 GSFwgUvUz/WtBgusWz7Ct0q/YOIyEoY= X-Google-Smtp-Source: ABdhPJyYE0pnUMGJUqKayq89B8Uwv/qXaz6CXfyEUMryzWgzSH/MSQseolwERm5C08QlEn4y46sT/A== X-Received: by 2002:a62:e801:: with SMTP id c1mr24215259pfi.217.1591084147140; Tue, 02 Jun 2020 00:49:07 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id m2sm1529397pjf.34.2020.06.02.00.49.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:06 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 08/42][SRU][U] iommu: Move default domain allocation to iommu_probe_device() Date: Tue, 2 Jun 2020 15:48:09 +0800 Message-Id: <20200602074843.1743493-9-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 Well, not really. The call to iommu_alloc_default_domain() in iommu_group_get_for_dev() has to stay around as long as there are IOMMU drivers using the add/remove_device() call-backs instead of probe/release_device(). Those drivers expect that iommu_group_get_for_dev() returns the device attached to a group and the group set up with a default domain (and the device attached to the groups current domain). But when all drivers are converted this compatability mess can be removed. Signed-off-by: Joerg Roedel Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200429133712.31431-9-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 6e1aa2049154d7462968c968b20f985859308267 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/iommu.c | 102 +++++++++++++++++++++++++++++------------- 1 file changed, 71 insertions(+), 31 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 3ae0b9a85d80..fa5c8c737fe9 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -79,6 +79,16 @@ static bool iommu_cmd_line_dma_api(void) return !!(iommu_cmd_line & IOMMU_CMD_LINE_DMA_API); } +static int iommu_alloc_default_domain(struct device *dev); +static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus, + unsigned type); +static int __iommu_attach_device(struct iommu_domain *domain, + struct device *dev); +static int __iommu_attach_group(struct iommu_domain *domain, + struct iommu_group *group); +static void __iommu_detach_group(struct iommu_domain *domain, + struct iommu_group *group); + #define IOMMU_GROUP_ATTR(_name, _mode, _show, _store) \ struct iommu_group_attribute iommu_group_attr_##_name = \ __ATTR(_name, _mode, _show, _store) @@ -222,10 +232,29 @@ int iommu_probe_device(struct device *dev) goto err_free_dev_param; } - if (ops->probe_device) + if (ops->probe_device) { + struct iommu_group *group; + ret = __iommu_probe_device(dev); - else + + /* + * Try to allocate a default domain - needs support from the + * IOMMU driver. There are still some drivers which don't + * support default domains, so the return value is not yet + * checked. + */ + if (!ret) + iommu_alloc_default_domain(dev); + + group = iommu_group_get(dev); + if (group && group->default_domain) { + ret = __iommu_attach_device(group->default_domain, dev); + iommu_group_put(group); + } + + } else { ret = ops->add_device(dev); + } if (ret) goto err_module_put; @@ -269,15 +298,6 @@ void iommu_release_device(struct device *dev) dev_iommu_free(dev); } -static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus, - unsigned type); -static int __iommu_attach_device(struct iommu_domain *domain, - struct device *dev); -static int __iommu_attach_group(struct iommu_domain *domain, - struct iommu_group *group); -static void __iommu_detach_group(struct iommu_domain *domain, - struct iommu_group *group); - static int __init iommu_set_def_domain_type(char *str) { bool pt; @@ -1433,25 +1453,18 @@ static int iommu_get_def_domain_type(struct device *dev) return (type == 0) ? iommu_def_domain_type : type; } -static int iommu_alloc_default_domain(struct device *dev, - struct iommu_group *group) +static int iommu_group_alloc_default_domain(struct bus_type *bus, + struct iommu_group *group, + unsigned int type) { struct iommu_domain *dom; - unsigned int type; - - if (group->default_domain) - return 0; - type = iommu_get_def_domain_type(dev); - - dom = __iommu_domain_alloc(dev->bus, type); + dom = __iommu_domain_alloc(bus, type); if (!dom && type != IOMMU_DOMAIN_DMA) { - dom = __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_DMA); - if (dom) { - dev_warn(dev, - "failed to allocate default IOMMU domain of type %u; falling back to IOMMU_DOMAIN_DMA", - type); - } + dom = __iommu_domain_alloc(bus, IOMMU_DOMAIN_DMA); + if (dom) + pr_warn("Failed to allocate default IOMMU domain of type %u for group %s - Falling back to IOMMU_DOMAIN_DMA", + type, group->name); } if (!dom) @@ -1471,6 +1484,23 @@ static int iommu_alloc_default_domain(struct device *dev, return 0; } +static int iommu_alloc_default_domain(struct device *dev) +{ + struct iommu_group *group; + unsigned int type; + + group = iommu_group_get(dev); + if (!group) + return -ENODEV; + + if (group->default_domain) + return 0; + + type = iommu_get_def_domain_type(dev); + + return iommu_group_alloc_default_domain(dev->bus, group, type); +} + /** * iommu_group_get_for_dev - Find or create the IOMMU group for a device * @dev: target device @@ -1501,16 +1531,26 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev) if (IS_ERR(group)) return group; + ret = iommu_group_add_device(group, dev); + if (ret) + goto out_put_group; + /* * Try to allocate a default domain - needs support from the * IOMMU driver. There are still some drivers which don't support - * default domains, so the return value is not yet checked. + * default domains, so the return value is not yet checked. Only + * allocate the domain here when the driver still has the + * add_device/remove_device call-backs implemented. */ - iommu_alloc_default_domain(dev, group); + if (!ops->probe_device) { + iommu_alloc_default_domain(dev); - ret = iommu_group_add_device(group, dev); - if (ret) - goto out_put_group; + if (group->default_domain) + ret = __iommu_attach_device(group->default_domain, dev); + + if (ret) + goto out_put_group; + } return group; From patchwork Tue Jun 2 07:48:10 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: 1302203 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 49bkhG0D1Kz9sSd; Tue, 2 Jun 2020 17:49:18 +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 1jg1fd-0005Hd-Vn; Tue, 02 Jun 2020 07:49:13 +0000 Received: from mail-pl1-f194.google.com ([209.85.214.194]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1fb-0005Er-Rw for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:12 +0000 Received: by mail-pl1-f194.google.com with SMTP id g12so1010645pll.10 for ; Tue, 02 Jun 2020 00:49:11 -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=QavVStEtdJ2qnNCyT6p3/I1MBn6QnIt0NqbW0OEUXWo=; b=g4uj6NxgUZE3yE4tD7Fw+nKMXNPqmiAgXp5y9ssg9L/iz76HqCij1Y6vdwrUqajqur dmCdrSa1p6RojWIJSmUZbSxOcYtMDkmD1YG98icwY0yvYLKdAUJZhBnf3A96yk2sPu8s 8S/jW5NWGTBcQHuR9jRrcGHGE19dksm1EfHxDaDvlM5uVoYVCAVXWbsEEKKJtWZihqjr y9ucOn538+sRpbmwiB8pqzwvttfQaY4a4fqz3lZGTqiH9hXsVN3meK+Aw44gq8MdkNCd ZQJOhLLGy5RIEZodjUmNiUoiU5hxOg+8FmP2cX0fJ8ldiMn4wgx8BF3jEUiByokHFDVr mbIA== X-Gm-Message-State: AOAM532zla+AG3ccn9HLZbtdOjVKUZPf6piRVxc3Bzpo+vCH2/3H/kTr bi8fe+/2KPcGQzGJv43SS3OP6YRgD6E= X-Google-Smtp-Source: ABdhPJwduc4RxMB8oZAadzzlOVBgp0HBcfeRRnZnt/6JAd0fqDVWfJLpnAL5p9hlKhl6E4os7UXb/g== X-Received: by 2002:a17:90a:de95:: with SMTP id n21mr4023049pjv.100.1591084149515; Tue, 02 Jun 2020 00:49:09 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id c138sm1483389pfc.97.2020.06.02.00.49.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:08 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 09/42][SRU][U] iommu: Keep a list of allocated groups in __iommu_probe_device() Date: Tue, 2 Jun 2020 15:48:10 +0800 Message-Id: <20200602074843.1743493-10-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 This is needed to defer default_domain allocation for new IOMMU groups until all devices have been added to the group. Signed-off-by: Joerg Roedel Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200429133712.31431-10-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 41df6dcc0a3ff4fb654c3d969ab96ba9c4f0e796 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/iommu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index fa5c8c737fe9..87706d225dba 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -44,6 +44,7 @@ struct iommu_group { int id; struct iommu_domain *default_domain; struct iommu_domain *domain; + struct list_head entry; }; struct group_device { @@ -185,7 +186,7 @@ static void dev_iommu_free(struct device *dev) dev->iommu = NULL; } -static int __iommu_probe_device(struct device *dev) +static int __iommu_probe_device(struct device *dev, struct list_head *group_list) { const struct iommu_ops *ops = dev->bus->iommu_ops; struct iommu_device *iommu_dev; @@ -205,6 +206,9 @@ static int __iommu_probe_device(struct device *dev) } iommu_group_put(group); + if (group_list && !group->default_domain && list_empty(&group->entry)) + list_add_tail(&group->entry, group_list); + iommu_device_link(iommu_dev, dev); return 0; @@ -235,7 +239,7 @@ int iommu_probe_device(struct device *dev) if (ops->probe_device) { struct iommu_group *group; - ret = __iommu_probe_device(dev); + ret = __iommu_probe_device(dev, NULL); /* * Try to allocate a default domain - needs support from the @@ -568,6 +572,7 @@ struct iommu_group *iommu_group_alloc(void) group->kobj.kset = iommu_group_kset; mutex_init(&group->mutex); INIT_LIST_HEAD(&group->devices); + INIT_LIST_HEAD(&group->entry); BLOCKING_INIT_NOTIFIER_HEAD(&group->notifier); ret = ida_simple_get(&iommu_group_ida, 0, 0, GFP_KERNEL); From patchwork Tue Jun 2 07:48:11 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: 1302204 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 49bkhK15hrz9sSn; Tue, 2 Jun 2020 17:49:21 +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 1jg1fh-0005Kx-Lx; Tue, 02 Jun 2020 07:49:17 +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 1jg1fe-0005Hb-SO for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:15 +0000 Received: by mail-pj1-f65.google.com with SMTP id d6so1056000pjs.3 for ; Tue, 02 Jun 2020 00:49:14 -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=ZDdYH4EU19FWka6N/vAt/zgFFsdpvA7xc3kS5TDgO0I=; b=Yg8+6PnweHvav+u2Io+tI+aZxaOjChEnHNHOAVvqwSHZkr3WJQo8H/T6aXFRoDQUd7 bTrxB7hJSFNbnYordvTyhueM287c2iVYmXw8wpnwxD16tBkuYOo8+nEJAWib7bJ7Nab9 lBzztdgOIKgBmAzUl/OUfHRJlCRSEWrlVq1Yp2bJt/QZy3sgiOhHSb9xyjZJlUIyUDbG 00qaHWjvrg2Yt9rqTVg12cU4CveXJtsRyzLdf9wKDRXoW78tbju95zwdhw5xrjxu9R4K 66EZcITrhzlRkXGS3uRHA6Lc/gI28K7gOpriiyxQ/2zFppKTCSD5ntsvoYX0OBxjVUHb 893A== X-Gm-Message-State: AOAM530m3QTyPChxSp/b36ZpRM6zX5belcoviHDWXrnMgFTybL/cqx1v xYAlpjehC7fuPwa34d6Mhfom9LDkpL8= X-Google-Smtp-Source: ABdhPJwuLpgLjPC6YXTdAu4hOgeoOfB6k9v7e2pGxvhu9Yn845cMZuDGbiYYdzTkUQ0PtRSe1ZHU1w== X-Received: by 2002:a17:902:e788:: with SMTP id cp8mr10458007plb.34.1591084152330; Tue, 02 Jun 2020 00:49:12 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id y10sm1617307pfq.34.2020.06.02.00.49.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:11 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 10/42][SRU][U] iommu: Move new probe_device path to separate function Date: Tue, 2 Jun 2020 15:48:11 +0800 Message-Id: <20200602074843.1743493-11-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 This makes it easier to remove to old code-path when all drivers are converted. As a side effect that it also fixes the error cleanup path. Signed-off-by: Joerg Roedel Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200429133712.31431-11-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit cf193888bfbd3d57e03a511e49d26f7d9c6f76df linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/iommu.c | 69 ++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 87706d225dba..428ba12c338c 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -219,12 +219,55 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list return ret; } +static int __iommu_probe_device_helper(struct device *dev) +{ + const struct iommu_ops *ops = dev->bus->iommu_ops; + struct iommu_group *group; + int ret; + + ret = __iommu_probe_device(dev, NULL); + if (ret) + goto err_out; + + /* + * Try to allocate a default domain - needs support from the + * IOMMU driver. There are still some drivers which don't + * support default domains, so the return value is not yet + * checked. + */ + iommu_alloc_default_domain(dev); + + group = iommu_group_get(dev); + if (!group) + goto err_release; + + if (group->default_domain) + ret = __iommu_attach_device(group->default_domain, dev); + + iommu_group_put(group); + + if (ret) + goto err_release; + + if (ops->probe_finalize) + ops->probe_finalize(dev); + + return 0; + +err_release: + iommu_release_device(dev); +err_out: + return ret; + +} + int iommu_probe_device(struct device *dev) { const struct iommu_ops *ops = dev->bus->iommu_ops; int ret; WARN_ON(dev->iommu_group); + if (!ops) return -EINVAL; @@ -236,30 +279,10 @@ int iommu_probe_device(struct device *dev) goto err_free_dev_param; } - if (ops->probe_device) { - struct iommu_group *group; - - ret = __iommu_probe_device(dev, NULL); - - /* - * Try to allocate a default domain - needs support from the - * IOMMU driver. There are still some drivers which don't - * support default domains, so the return value is not yet - * checked. - */ - if (!ret) - iommu_alloc_default_domain(dev); - - group = iommu_group_get(dev); - if (group && group->default_domain) { - ret = __iommu_attach_device(group->default_domain, dev); - iommu_group_put(group); - } - - } else { - ret = ops->add_device(dev); - } + if (ops->probe_device) + return __iommu_probe_device_helper(dev); + ret = ops->add_device(dev); if (ret) goto err_module_put; From patchwork Tue Jun 2 07:48:12 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: 1302205 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 49bkhM3n6Nz9sSn; Tue, 2 Jun 2020 17:49:23 +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 1jg1fk-0005NH-1o; Tue, 02 Jun 2020 07:49:20 +0000 Received: from mail-pl1-f194.google.com ([209.85.214.194]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1fh-0005K2-FN for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:17 +0000 Received: by mail-pl1-f194.google.com with SMTP id g12so1010718pll.10 for ; Tue, 02 Jun 2020 00:49:17 -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=pxZHRpIKDczJAVecENIwndjE7Hqpddh35lZSufc7XA8=; b=lWFDXDvRyI2qExbjU1vu9nWj1CTbdVs47Tu2RXew8zLZkoeM1Akma9ZE5gJncFF8ny TIOchvBWmmeBn2fGIkOUiiKDo6v1iPRv38HmBJeiaW49amkFHAC6VO4sXO8L7f52KN+U N89c7dJEBpNhqkacLCyPtii/u1z8i/bFNUlw8e3vFgH9m7HqfF2fPmKWteQTr6K9bsVN K0s5xb1jFiXEfMx72D7kMu70N5do8Fzy/x39udDpQJWBrrpzL33baxj96Ucc6vdT8gwG r5dt2C2BpLXjJjCCvKqUjXT7em37mDJZmdzjehqW5N4eRrLF5T3vUtb8GV72kCbOpGRT Cu5Q== X-Gm-Message-State: AOAM531LQGMH1Fl4oTYnzswaNE2zYF0k5S7UKRYMbBMgPfCnPne+5Q8u xJBGymjys05x4X/Q+OQdDk5u2NMKB18= X-Google-Smtp-Source: ABdhPJxImUACdOP70TWxCcyZ+2Afk7fNYn/VdcRtmr0zNRCwFt1YjL9yvIvKc3NV+9HOM03FEUSwew== X-Received: by 2002:a17:90a:b013:: with SMTP id x19mr847759pjq.229.1591084155074; Tue, 02 Jun 2020 00:49:15 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id 12sm1672300pfb.3.2020.06.02.00.49.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:14 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 11/42][SRU][U] iommu: Split off default domain allocation from group assignment Date: Tue, 2 Jun 2020 15:48:12 +0800 Message-Id: <20200602074843.1743493-12-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 When a bus is initialized with iommu-ops, all devices on the bus are scanned and iommu-groups are allocated for them, and each groups will also get a default domain allocated. Until now this happened as soon as the group was created and the first device added to it. When other devices with different default domain requirements were added to the group later on, the default domain was re-allocated, if possible. This resulted in some back and forth and unnecessary allocations, so change the flow to defer default domain allocation until all devices have been added to their respective IOMMU groups. The default domains are allocated for newly allocated groups after each device on the bus is handled and was probed by the IOMMU driver. Signed-off-by: Joerg Roedel Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200429133712.31431-12-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit deac0b3bed26bb5d04486696b1071d8ec3851100 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/iommu.c | 154 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 428ba12c338c..b02f212acaee 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -200,7 +200,7 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list dev->iommu->iommu_dev = iommu_dev; group = iommu_group_get_for_dev(dev); - if (!IS_ERR(group)) { + if (IS_ERR(group)) { ret = PTR_ERR(group); goto out_release; } @@ -1609,6 +1609,37 @@ static int add_iommu_group(struct device *dev, void *data) return ret; } +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; + int ret; + + if (!dev_iommu_get(dev)) + return -ENOMEM; + + if (!try_module_get(ops->owner)) { + ret = -EINVAL; + goto err_free_dev_iommu; + } + + ret = __iommu_probe_device(dev, group_list); + if (ret) + goto err_module_put; + + return 0; + +err_module_put: + module_put(ops->owner); +err_free_dev_iommu: + dev_iommu_free(dev); + + if (ret == -ENODEV) + ret = 0; + + return ret; +} + static int remove_iommu_group(struct device *dev, void *data) { iommu_release_device(dev); @@ -1668,10 +1699,127 @@ static int iommu_bus_notifier(struct notifier_block *nb, return 0; } +struct __group_domain_type { + struct device *dev; + unsigned int type; +}; + +static int probe_get_default_domain_type(struct device *dev, void *data) +{ + const struct iommu_ops *ops = dev->bus->iommu_ops; + struct __group_domain_type *gtype = data; + unsigned int type = 0; + + if (ops->def_domain_type) + type = ops->def_domain_type(dev); + + if (type) { + if (gtype->type && gtype->type != type) { + dev_warn(dev, "Device needs domain type %s, but device %s in the same iommu group requires type %s - using default\n", + iommu_domain_type_str(type), + dev_name(gtype->dev), + iommu_domain_type_str(gtype->type)); + gtype->type = 0; + } + + if (!gtype->dev) { + gtype->dev = dev; + gtype->type = type; + } + } + + return 0; +} + +static void probe_alloc_default_domain(struct bus_type *bus, + struct iommu_group *group) +{ + struct __group_domain_type gtype; + + memset(>ype, 0, sizeof(gtype)); + + /* Ask for default domain requirements of all devices in the group */ + __iommu_group_for_each_dev(group, >ype, + probe_get_default_domain_type); + + if (!gtype.type) + gtype.type = iommu_def_domain_type; + + iommu_group_alloc_default_domain(bus, group, gtype.type); +} + +static int iommu_group_do_dma_attach(struct device *dev, void *data) +{ + struct iommu_domain *domain = data; + const struct iommu_ops *ops; + int ret; + + ret = __iommu_attach_device(domain, dev); + + ops = domain->ops; + + if (ret == 0 && ops->probe_finalize) + ops->probe_finalize(dev); + + return ret; +} + +static int __iommu_group_dma_attach(struct iommu_group *group) +{ + return __iommu_group_for_each_dev(group, group->default_domain, + iommu_group_do_dma_attach); +} + +static int bus_iommu_probe(struct bus_type *bus) +{ + const struct iommu_ops *ops = bus->iommu_ops; + int ret; + + if (ops->probe_device) { + struct iommu_group *group, *next; + LIST_HEAD(group_list); + + /* + * This code-path does not allocate the default domain when + * creating the iommu group, so do it after the groups are + * created. + */ + ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group); + if (ret) + return ret; + + list_for_each_entry_safe(group, next, &group_list, entry) { + /* Remove item from the list */ + list_del_init(&group->entry); + + mutex_lock(&group->mutex); + + /* Try to allocate default domain */ + probe_alloc_default_domain(bus, group); + + if (!group->default_domain) { + mutex_unlock(&group->mutex); + continue; + } + + ret = __iommu_group_dma_attach(group); + + mutex_unlock(&group->mutex); + + if (ret) + break; + } + } else { + ret = bus_for_each_dev(bus, NULL, NULL, add_iommu_group); + } + + return ret; +} + static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops) { - int err; struct notifier_block *nb; + int err; nb = kzalloc(sizeof(struct notifier_block), GFP_KERNEL); if (!nb) @@ -1683,7 +1831,7 @@ static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops) if (err) goto out_free; - err = bus_for_each_dev(bus, NULL, NULL, add_iommu_group); + err = bus_iommu_probe(bus); if (err) goto out_err; From patchwork Tue Jun 2 07:48:13 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: 1302206 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 49bkhQ3L8Wz9sSd; Tue, 2 Jun 2020 17:49:26 +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 1jg1fm-0005P5-EV; Tue, 02 Jun 2020 07:49:22 +0000 Received: from mail-pj1-f66.google.com ([209.85.216.66]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1fj-0005M5-GY for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:19 +0000 Received: by mail-pj1-f66.google.com with SMTP id s88so1047796pjb.5 for ; Tue, 02 Jun 2020 00:49:19 -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=MoUJb36B2X1wqvRgI/T6SsCDxs2+L8ju2SWfLAmLmJU=; b=F4QcVVSPaR3HRePzShxypyZwsG850L4BHPB/KJZ7eJIa/+znclgwHxsZoSzbJuB17C rWPwimaHdi5S9fL7jpOsGhL/qVTKuZGhyL2dHb3E9N9E7QYtkwvVxiLHpuYY4AcV2j5C 1+tcQW577K5vqz076dvlP5KaO7CDoQ6Q4PPzMLAxQwYIcQzsQGhCQ5s19w9JK3VYJwQG Lf4ChSky6ASAIoxxLdsQpXqyHnsjA/5me+VW7nqWOADLbr2V8TH8wWrAsJAjRV3GVuCU PVI1Ru+A3txHC+7QDGgpywOzczms4Z1H4JJp4Qt+ZdVhmWM+ngWk/ngnZddgBbPF/jcB CH0Q== X-Gm-Message-State: AOAM533T5WQEoZC2YTQa7v34VGUYoamOi53Xz+ON2fdYKmhl5zN/dChi aU8r1eYfgOXFgc3ZqE+RHoBo9X3WoT8= X-Google-Smtp-Source: ABdhPJzL5T8GDgAklCoQQ4oI5cCaHSr7ijWiRNHLdr0NvLvVhNUTv/r112gwxYUrfYAcypXoZrxFPQ== X-Received: by 2002:a17:90b:30d8:: with SMTP id hi24mr4083441pjb.78.1591084157513; Tue, 02 Jun 2020 00:49:17 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id n38sm1505140pgm.1.2020.06.02.00.49.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:16 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 12/42][SRU][U] iommu: Move iommu_group_create_direct_mappings() out of iommu_group_add_device() Date: Tue, 2 Jun 2020 15:48:13 +0800 Message-Id: <20200602074843.1743493-13-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 After the previous changes the iommu group may not have a default domain when iommu_group_add_device() is called. With no default domain iommu_group_create_direct_mappings() will do nothing and no direct mappings will be created. Rename iommu_group_create_direct_mappings() to iommu_create_device_direct_mappings() to better reflect that the function creates direct mappings only for one device and not for all devices in the group. Then move the call to the places where a default domain actually exists. Signed-off-by: Joerg Roedel Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200429133712.31431-13-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit ce574c27ae275bc51b6437883fc9cd1c46b498e5 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/iommu.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index b02f212acaee..5c2a32d5935c 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -89,6 +89,8 @@ static int __iommu_attach_group(struct iommu_domain *domain, struct iommu_group *group); static void __iommu_detach_group(struct iommu_domain *domain, struct iommu_group *group); +static int iommu_create_device_direct_mappings(struct iommu_group *group, + struct device *dev); #define IOMMU_GROUP_ATTR(_name, _mode, _show, _store) \ struct iommu_group_attribute iommu_group_attr_##_name = \ @@ -244,6 +246,8 @@ static int __iommu_probe_device_helper(struct device *dev) if (group->default_domain) ret = __iommu_attach_device(group->default_domain, dev); + iommu_create_device_direct_mappings(group, dev); + iommu_group_put(group); if (ret) @@ -264,6 +268,7 @@ static int __iommu_probe_device_helper(struct device *dev) int iommu_probe_device(struct device *dev) { const struct iommu_ops *ops = dev->bus->iommu_ops; + struct iommu_group *group; int ret; WARN_ON(dev->iommu_group); @@ -286,6 +291,10 @@ int iommu_probe_device(struct device *dev) if (ret) goto err_module_put; + group = iommu_group_get(dev); + iommu_create_device_direct_mappings(group, dev); + iommu_group_put(group); + if (ops->probe_finalize) ops->probe_finalize(dev); @@ -737,8 +746,8 @@ int iommu_group_set_name(struct iommu_group *group, const char *name) } EXPORT_SYMBOL_GPL(iommu_group_set_name); -static int iommu_group_create_direct_mappings(struct iommu_group *group, - struct device *dev) +static int iommu_create_device_direct_mappings(struct iommu_group *group, + struct device *dev) { struct iommu_domain *domain = group->default_domain; struct iommu_resv_region *entry; @@ -851,8 +860,6 @@ int iommu_group_add_device(struct iommu_group *group, struct device *dev) dev->iommu_group = group; - iommu_group_create_direct_mappings(group, dev); - mutex_lock(&group->mutex); list_add_tail(&device->list, &group->devices); if (group->domain && !iommu_is_attach_deferred(group->domain, dev)) @@ -1746,6 +1753,7 @@ static void probe_alloc_default_domain(struct bus_type *bus, gtype.type = iommu_def_domain_type; iommu_group_alloc_default_domain(bus, group, gtype.type); + } static int iommu_group_do_dma_attach(struct device *dev, void *data) @@ -1770,6 +1778,21 @@ static int __iommu_group_dma_attach(struct iommu_group *group) iommu_group_do_dma_attach); } +static int iommu_do_create_direct_mappings(struct device *dev, void *data) +{ + struct iommu_group *group = data; + + iommu_create_device_direct_mappings(group, dev); + + return 0; +} + +static int iommu_group_create_direct_mappings(struct iommu_group *group) +{ + return __iommu_group_for_each_dev(group, group, + iommu_do_create_direct_mappings); +} + static int bus_iommu_probe(struct bus_type *bus) { const struct iommu_ops *ops = bus->iommu_ops; @@ -1802,6 +1825,8 @@ static int bus_iommu_probe(struct bus_type *bus) continue; } + iommu_group_create_direct_mappings(group); + ret = __iommu_group_dma_attach(group); mutex_unlock(&group->mutex); @@ -2638,7 +2663,7 @@ request_default_domain_for_dev(struct device *dev, unsigned long type) iommu_domain_free(group->default_domain); group->default_domain = domain; - iommu_group_create_direct_mappings(group, dev); + iommu_create_device_direct_mappings(group, dev); dev_info(dev, "Using iommu %s mapping\n", type == IOMMU_DOMAIN_DMA ? "dma" : "direct"); 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); From patchwork Tue Jun 2 07:48:15 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: 1302208 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 49bkhX28v2z9sSn; Tue, 2 Jun 2020 17:49:32 +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 1jg1fs-0005Tx-1O; Tue, 02 Jun 2020 07:49:28 +0000 Received: from mail-pg1-f196.google.com ([209.85.215.196]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1fp-0005Qo-K0 for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:25 +0000 Received: by mail-pg1-f196.google.com with SMTP id f21so4706700pgg.12 for ; Tue, 02 Jun 2020 00:49:25 -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=YD5J4CF6UsGQP6PD0XBe0pOU17XReZtCRi+QlGOvKmk=; b=hpAaBpu2Itd78pQ+eGY3Dl2ZJXtAcTaoAmQ4Yu0ngsc5CFBVlzwNei3SX+wIeJtSWu 1TXzUF4WhRrLNvm4TgRewWFWsmQNHwd7NIlR2qZxvqu+CydAdy79Zcv9q5oInSp7NSFR 1RAv7yJ5N6l4zjZW2NANAKe8LdihYzcw2r3HgTZoLgBNxaFRlLup0o+64EIHs4oT5vMt g+uzDUtt3YKT9uR8XqM3GQutlTlvLH9g+gBhWI6trK6RMu7y7DwHyGGzHpJzKsybHZav eJfSQG6QAIu9BTHgyEsADyIwnACAdoG44v/+dbLdqaR7KM+RMLY2pLViuNdH/Li8yK1a MzTg== X-Gm-Message-State: AOAM532b7OhOgrgY54fS+9XVxcQsbXfHxjBaJrp4moux4jMYvlD+OGdy 4scmGylPKUK+MbL+wkYTReA6uRVG5OM= X-Google-Smtp-Source: ABdhPJxkvGhPTXQQVjKKiH5BLqC0VicWoHbjdBo7Sl4WVdoCzWY0uUwyNI5S5rwgZc7pWNdOFrE3AQ== X-Received: by 2002:a62:25c2:: with SMTP id l185mr6864679pfl.58.1591084163110; Tue, 02 Jun 2020 00:49:23 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id c195sm1436057pfc.203.2020.06.02.00.49.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:22 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 14/42][SRU][U] iommu/amd: Remove dev_data->passthrough Date: Tue, 2 Jun 2020 15:48:15 +0800 Message-Id: <20200602074843.1743493-15-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 Make use of generic IOMMU infrastructure to gather the same information carried in dev_data->passthrough and remove the struct member. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-15-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 57f9842e48840684f596db1de936d7c6d44cd087 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/amd_iommu.c | 10 +++++----- drivers/iommu/amd_iommu_types.h | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 39c68487f67b..3fd474f9136c 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -2119,8 +2119,8 @@ static int pdev_iommuv2_enable(struct pci_dev *pdev) static int attach_device(struct device *dev, struct protection_domain *domain) { - struct pci_dev *pdev; struct iommu_dev_data *dev_data; + struct pci_dev *pdev; unsigned long flags; int ret; @@ -2139,8 +2139,10 @@ static int attach_device(struct device *dev, pdev = to_pci_dev(dev); if (domain->flags & PD_IOMMUV2_MASK) { + struct iommu_domain *def_domain = iommu_get_dma_domain(dev); + ret = -EINVAL; - if (!dev_data->passthrough) + if (def_domain->type != IOMMU_DOMAIN_IDENTITY) goto out; if (dev_data->iommu_v2) { @@ -2261,9 +2263,7 @@ static int amd_iommu_add_device(struct device *dev) /* Domains are initialized for this device - have a look what we ended up with */ domain = iommu_get_domain_for_dev(dev); - if (domain->type == IOMMU_DOMAIN_IDENTITY) - dev_data->passthrough = true; - else if (domain->type == IOMMU_DOMAIN_DMA) + if (domain->type == IOMMU_DOMAIN_DMA) iommu_setup_dma_ops(dev, IOVA_START_PFN << PAGE_SHIFT, 0); out: diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h index 7a8fdec138bd..f7e7c96bc298 100644 --- a/drivers/iommu/amd_iommu_types.h +++ b/drivers/iommu/amd_iommu_types.h @@ -645,7 +645,6 @@ struct iommu_dev_data { struct pci_dev *pdev; u16 devid; /* PCI Device ID */ bool iommu_v2; /* Device can make use of IOMMUv2 */ - bool passthrough; /* Device is identity mapped */ struct { bool enabled; int qdep; From patchwork Tue Jun 2 07:48:16 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: 1302209 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 49bkhd29lfz9sSn; Tue, 2 Jun 2020 17:49:37 +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 1jg1fx-0005Yy-FZ; Tue, 02 Jun 2020 07:49:33 +0000 Received: from mail-pg1-f195.google.com ([209.85.215.195]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1ft-0005Ue-Gb for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:29 +0000 Received: by mail-pg1-f195.google.com with SMTP id t7so3878364pgt.3 for ; Tue, 02 Jun 2020 00:49:29 -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=jYeT8qaCRluTu5dwa+YB8Dt9NJyKTnZH0GAaXRh5JtU=; b=Ua1J5ADGnX0uQQrMQAj3hmRqs1mzagLMdebeHAZEg445Wyc49smCYwDKXRcrrx8no3 vvfr46FtivCFRLg0m0B8pUQRKYuo2aUpvBlUl9n4Y11Q49DkwIHJLzoDuqgktK5FkZsM j8lKJLpdM6QeiF+D2G5Cy/w4ckucbr9nKW33c4NXYi6g94BXjMu75BnpOQIUvnhOnctV TKXSUQ9dJmO8VeSsPL4PoiHX2vCWg6KZgJU/JxzZd05S4a23fLD5s2UQj0XFseXonnM7 b4s+huQJPb6dij9kHi+rWwF6QB6b/QX/ufWhs0M+a/gPwJhMcRoErWGb8hLl7BNc8Zbv 7acQ== X-Gm-Message-State: AOAM530MwidRgaMSJkDmZzkRH3aqjm8ApbJyaJd5f+TOdq90HNrdazJ6 HRVHGjP1tKUxQd7HGnNAqZv0K/KU5Ic= X-Google-Smtp-Source: ABdhPJyfx9Qs3lo4VUa+zkZXBYvfvlQWgcRMNX2qnA3a1RUB5lERFe6O46qFgEZIH8opUFuAWkh7tw== X-Received: by 2002:a62:1c46:: with SMTP id c67mr17793720pfc.170.1591084165462; Tue, 02 Jun 2020 00:49:25 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id a14sm1431321pfc.133.2020.06.02.00.49.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:24 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 15/42][SRU][U] iommu/amd: Convert to probe/release_device() call-backs Date: Tue, 2 Jun 2020 15:48:16 +0800 Message-Id: <20200602074843.1743493-16-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 Convert the AMD IOMMU Driver to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-16-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit dce8d6964ebdb333383bacf5e7ab8c27df151218 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/amd_iommu.c | 71 ++++++++++++--------------------------- 1 file changed, 22 insertions(+), 49 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 3fd474f9136c..3d158239bb67 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -366,21 +366,9 @@ static bool check_device(struct device *dev) return true; } -static void init_iommu_group(struct device *dev) -{ - struct iommu_group *group; - - group = iommu_group_get_for_dev(dev); - if (IS_ERR(group)) - return; - - iommu_group_put(group); -} - static int iommu_init_device(struct device *dev) { struct iommu_dev_data *dev_data; - struct amd_iommu *iommu; int devid; if (dev->archdata.iommu) @@ -390,8 +378,6 @@ static int iommu_init_device(struct device *dev) if (devid < 0) return devid; - iommu = amd_iommu_rlookup_table[devid]; - dev_data = find_dev_data(devid); if (!dev_data) return -ENOMEM; @@ -414,8 +400,6 @@ static int iommu_init_device(struct device *dev) dev->archdata.iommu = dev_data; - iommu_device_link(&iommu->iommu, dev); - return 0; } @@ -433,7 +417,7 @@ static void iommu_ignore_device(struct device *dev) setup_aliases(dev); } -static void iommu_uninit_device(struct device *dev) +static void amd_iommu_uninit_device(struct device *dev) { struct iommu_dev_data *dev_data; struct amd_iommu *iommu; @@ -452,13 +436,6 @@ static void iommu_uninit_device(struct device *dev) if (dev_data->domain) detach_device(dev); - iommu_device_unlink(&iommu->iommu, dev); - - iommu_group_remove_device(dev); - - /* Remove dma-ops */ - dev->dma_ops = NULL; - /* * We keep dev_data around for unplugged devices and reuse it when the * device is re-plugged - not doing so would introduce a ton of races. @@ -2224,55 +2201,50 @@ static void detach_device(struct device *dev) spin_unlock_irqrestore(&domain->lock, flags); } -static int amd_iommu_add_device(struct device *dev) +static struct iommu_device *amd_iommu_probe_device(struct device *dev) { - struct iommu_dev_data *dev_data; - struct iommu_domain *domain; + struct iommu_device *iommu_dev; struct amd_iommu *iommu; int ret, devid; - if (get_dev_data(dev)) - return 0; - if (!check_device(dev)) - return -ENODEV; + return ERR_PTR(-ENODEV); devid = get_device_id(dev); if (devid < 0) - return devid; + return ERR_PTR(devid); iommu = amd_iommu_rlookup_table[devid]; + if (get_dev_data(dev)) + return &iommu->iommu; + ret = iommu_init_device(dev); if (ret) { if (ret != -ENOTSUPP) dev_err(dev, "Failed to initialize - trying to proceed anyway\n"); - + iommu_dev = ERR_PTR(ret); iommu_ignore_device(dev); - dev->dma_ops = NULL; - goto out; + } else { + iommu_dev = &iommu->iommu; } - init_iommu_group(dev); - dev_data = get_dev_data(dev); + iommu_completion_wait(iommu); - BUG_ON(!dev_data); + return iommu_dev; +} - if (dev_data->iommu_v2) - iommu_request_dm_for_dev(dev); +static void amd_iommu_probe_finalize(struct device *dev) +{ + struct iommu_domain *domain; /* Domains are initialized for this device - have a look what we ended up with */ domain = iommu_get_domain_for_dev(dev); if (domain->type == IOMMU_DOMAIN_DMA) iommu_setup_dma_ops(dev, IOVA_START_PFN << PAGE_SHIFT, 0); - -out: - iommu_completion_wait(iommu); - - return 0; } -static void amd_iommu_remove_device(struct device *dev) +static void amd_iommu_release_device(struct device *dev) { struct amd_iommu *iommu; int devid; @@ -2286,7 +2258,7 @@ static void amd_iommu_remove_device(struct device *dev) iommu = amd_iommu_rlookup_table[devid]; - iommu_uninit_device(dev); + amd_iommu_uninit_device(dev); iommu_completion_wait(iommu); } @@ -2784,8 +2756,9 @@ const struct iommu_ops amd_iommu_ops = { .map = amd_iommu_map, .unmap = amd_iommu_unmap, .iova_to_phys = amd_iommu_iova_to_phys, - .add_device = amd_iommu_add_device, - .remove_device = amd_iommu_remove_device, + .probe_device = amd_iommu_probe_device, + .release_device = amd_iommu_release_device, + .probe_finalize = amd_iommu_probe_finalize, .device_group = amd_iommu_device_group, .domain_get_attr = amd_iommu_domain_get_attr, .get_resv_regions = amd_iommu_get_resv_regions, From patchwork Tue Jun 2 07:48:17 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: 1302210 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 49bkhg73jdz9sSn; Tue, 2 Jun 2020 17:49:39 +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 1jg1fz-0005bI-UP; Tue, 02 Jun 2020 07:49:35 +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 1jg1fw-0005XB-3c for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:32 +0000 Received: by mail-pl1-f196.google.com with SMTP id y17so1017638plb.8 for ; Tue, 02 Jun 2020 00:49:31 -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=36jgrRN5ztbpf5W7YJJbJmiyAm5LnLVOvzJFLJrn3rE=; b=BKaNN/eevexAVqTWbfezTXnn5fsxi2OtpkGVvUFFE+Mt5tRsf4wafP8WSkG+inV97u 3i3jwS1bqKY3wWCsjV3+X5CIqC4bRwHN02V55D8iS0NBH+c1EbNrmmOxg0tdUvQHVvKX jlTmsMux7QXsk9XJTX4Bct69xZ10xFOjbk+CosVF+kJdeuwbmBwbbeqxtgFyigyXcOF2 7gBp7mNpx+JsSfhbxPhAIJKROWOXmRNsnKQxa7W4/ILG6+6xBd4OY6rmGk4UOdTI/OQY 2aKeqhD5IOeE7tQfoE2F7k5ywiftRQyPoWamJzAbyvMEFWRbUp2PPApWXh7Q9sokbCoD iBfg== X-Gm-Message-State: AOAM5319rCAieuN7SVrgjjx2rqHUv10/GK2vIa4oF9xTAgD22bO0EKQ6 4JSBa4GdcbRNU8Cems04hpvnTci5xvg= X-Google-Smtp-Source: ABdhPJx+v6bN5bLtqECI/3yGGKeoI/iFSqKDzV59LiqYvJ0pPycJbEKrwx+dTwHt9Cryi2AR2Oofkg== X-Received: by 2002:a17:90b:e0c:: with SMTP id ge12mr4126577pjb.3.1591084169964; Tue, 02 Jun 2020 00:49:29 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id b11sm1522355pjz.54.2020.06.02.00.49.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:29 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 16/42][SRU][U] iommu/vt-d: Convert to probe/release_device() call-backs Date: Tue, 2 Jun 2020 15:48:17 +0800 Message-Id: <20200602074843.1743493-17-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 Convert the Intel IOMMU driver to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel Reviewed-by: Lu Baolu Link: https://lore.kernel.org/r/20200429133712.31431-17-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit e5d1841f18b2401c8b449c024817cd243e363934 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/intel-iommu.c | 67 ++++--------------------------------- 1 file changed, 6 insertions(+), 61 deletions(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index c9e11964fed3..34e08fa2ce3a 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -5781,78 +5781,27 @@ static bool intel_iommu_capable(enum iommu_cap cap) return false; } -static int intel_iommu_add_device(struct device *dev) +static struct iommu_device *intel_iommu_probe_device(struct device *dev) { - struct dmar_domain *dmar_domain; - struct iommu_domain *domain; struct intel_iommu *iommu; - struct iommu_group *group; u8 bus, devfn; - int ret; iommu = device_to_iommu(dev, &bus, &devfn); if (!iommu) - return -ENODEV; - - iommu_device_link(&iommu->iommu, dev); + return ERR_PTR(-ENODEV); if (translation_pre_enabled(iommu)) dev->archdata.iommu = DEFER_DEVICE_DOMAIN_INFO; - group = iommu_group_get_for_dev(dev); - - if (IS_ERR(group)) { - ret = PTR_ERR(group); - goto unlink; - } - - iommu_group_put(group); - - domain = iommu_get_domain_for_dev(dev); - dmar_domain = to_dmar_domain(domain); - if (domain->type == IOMMU_DOMAIN_DMA) { - if (device_def_domain_type(dev) == IOMMU_DOMAIN_IDENTITY) { - ret = iommu_request_dm_for_dev(dev); - if (ret) { - dmar_remove_one_dev_info(dev); - dmar_domain->flags |= DOMAIN_FLAG_LOSE_CHILDREN; - domain_add_dev_info(si_domain, dev); - dev_info(dev, - "Device uses a private identity domain.\n"); - } - } - } else { - if (device_def_domain_type(dev) == IOMMU_DOMAIN_DMA) { - ret = iommu_request_dma_domain_for_dev(dev); - if (ret) { - dmar_remove_one_dev_info(dev); - dmar_domain->flags |= DOMAIN_FLAG_LOSE_CHILDREN; - if (!get_private_domain_for_dev(dev)) { - dev_warn(dev, - "Failed to get a private domain.\n"); - ret = -ENOMEM; - goto unlink; - } - - dev_info(dev, - "Device uses a private dma domain.\n"); - } - } - } - if (device_needs_bounce(dev)) { dev_info(dev, "Use Intel IOMMU bounce page dma_ops\n"); set_dma_ops(dev, &bounce_dma_ops); } - return 0; - -unlink: - iommu_device_unlink(&iommu->iommu, dev); - return ret; + return &iommu->iommu; } -static void intel_iommu_remove_device(struct device *dev) +static void intel_iommu_release_device(struct device *dev) { struct intel_iommu *iommu; u8 bus, devfn; @@ -5863,10 +5812,6 @@ static void intel_iommu_remove_device(struct device *dev) dmar_remove_one_dev_info(dev); - iommu_group_remove_device(dev); - - iommu_device_unlink(&iommu->iommu, dev); - if (device_needs_bounce(dev)) set_dma_ops(dev, NULL); } @@ -6198,8 +6143,8 @@ const struct iommu_ops intel_iommu_ops = { .map = intel_iommu_map, .unmap = intel_iommu_unmap, .iova_to_phys = intel_iommu_iova_to_phys, - .add_device = intel_iommu_add_device, - .remove_device = intel_iommu_remove_device, + .probe_device = intel_iommu_probe_device, + .release_device = intel_iommu_release_device, .get_resv_regions = intel_iommu_get_resv_regions, .put_resv_regions = generic_iommu_put_resv_regions, .apply_resv_region = intel_iommu_apply_resv_region, From patchwork Tue Jun 2 07:48:18 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: 1302211 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 49bkhm04JCz9sSn; Tue, 2 Jun 2020 17:49:44 +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 1jg1g3-0005eO-ME; Tue, 02 Jun 2020 07:49:39 +0000 Received: from mail-pf1-f195.google.com ([209.85.210.195]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1fy-0005ZA-J4 for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:34 +0000 Received: by mail-pf1-f195.google.com with SMTP id a4so4682846pfo.4 for ; Tue, 02 Jun 2020 00:49:34 -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=DgJcHm7jUWLdEN+eJBCV3TOG3LYlCtt1sRUfafCMKlM=; b=UKm+HXPT4WBCE+PDrkx8JfbXUffutZvaS6AQr4Pq5OmFePyYNBnU9y6bgnyqSS/PDw EFqCkMGJ05lNhbxKHmPXxRarnUDRJqsnkeLfvHmZqWMetobo3mn/2N97xH5hPzlLRv7c yEL4R5icJ346xJnnRkBw7QgzSZbFlMcixeJkmX4tf1RC5Mgbd3MiVwHvNTM8JngUXgTf 7XS6aSv9Mq6TXIR3yw7rY9InjsHf+GheH8mfwss8lukJQqEEUyerU50X+5Sb8or68AHd g3ryiozHkZMyKnNRRU3yi7AAJJDdBZlT2f1TlIwi2/Qzc3Ufu0jv2S5x5gVHyoV8ZQ1g SDXA== X-Gm-Message-State: AOAM530pHCfCzInyGKDrjHXOln/3k58VLutFF6nn1pyTBJ/kFHSUlmSj oeS4tFVqpk6/ob/hvUyHcxFR6kJFHoM= X-Google-Smtp-Source: ABdhPJyB8TxIkkP56k7g/N5AqPIAHB4ltaF5E89cvEvRWOLnyQCJssa5gYxOuNMSfIAkTsVZRY7C1g== X-Received: by 2002:a62:1b87:: with SMTP id b129mr23918659pfb.162.1591084172449; Tue, 02 Jun 2020 00:49: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 s23sm1542698pju.35.2020.06.02.00.49.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:31 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 17/42][SRU][U] iommu/arm-smmu: Convert to probe/release_device() call-backs Date: Tue, 2 Jun 2020 15:48:18 +0800 Message-Id: <20200602074843.1743493-18-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 Convert the arm-smmu and arm-smmu-v3 drivers to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-18-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit cefa0d55da3753e969764fb4b161052a1cb4ddfb linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/arm-smmu-v3.c | 38 ++++++++++-------------------------- drivers/iommu/arm-smmu.c | 39 ++++++++++++++----------------------- 2 files changed, 25 insertions(+), 52 deletions(-) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 82508730feb7..42e1ee7e5197 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -2914,27 +2914,26 @@ static bool arm_smmu_sid_in_range(struct arm_smmu_device *smmu, u32 sid) static struct iommu_ops arm_smmu_ops; -static int arm_smmu_add_device(struct device *dev) +static struct iommu_device *arm_smmu_probe_device(struct device *dev) { int i, ret; struct arm_smmu_device *smmu; struct arm_smmu_master *master; struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); - struct iommu_group *group; if (!fwspec || fwspec->ops != &arm_smmu_ops) - return -ENODEV; + return ERR_PTR(-ENODEV); if (WARN_ON_ONCE(dev_iommu_priv_get(dev))) - return -EBUSY; + return ERR_PTR(-EBUSY); smmu = arm_smmu_get_by_fwnode(fwspec->iommu_fwnode); if (!smmu) - return -ENODEV; + return ERR_PTR(-ENODEV); master = kzalloc(sizeof(*master), GFP_KERNEL); if (!master) - return -ENOMEM; + return ERR_PTR(-ENOMEM); master->dev = dev; master->smmu = smmu; @@ -2975,30 +2974,15 @@ static int arm_smmu_add_device(struct device *dev) master->ssid_bits = min_t(u8, master->ssid_bits, CTXDESC_LINEAR_CDMAX); - ret = iommu_device_link(&smmu->iommu, dev); - if (ret) - goto err_disable_pasid; + return &smmu->iommu; - group = iommu_group_get_for_dev(dev); - if (IS_ERR(group)) { - ret = PTR_ERR(group); - goto err_unlink; - } - - iommu_group_put(group); - return 0; - -err_unlink: - iommu_device_unlink(&smmu->iommu, dev); -err_disable_pasid: - arm_smmu_disable_pasid(master); err_free_master: kfree(master); dev_iommu_priv_set(dev, NULL); - return ret; + return ERR_PTR(ret); } -static void arm_smmu_remove_device(struct device *dev) +static void arm_smmu_release_device(struct device *dev) { struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct arm_smmu_master *master; @@ -3010,8 +2994,6 @@ static void arm_smmu_remove_device(struct device *dev) master = dev_iommu_priv_get(dev); smmu = master->smmu; arm_smmu_detach_dev(master); - iommu_group_remove_device(dev); - iommu_device_unlink(&smmu->iommu, dev); arm_smmu_disable_pasid(master); kfree(master); iommu_fwspec_free(dev); @@ -3138,8 +3120,8 @@ static struct iommu_ops arm_smmu_ops = { .flush_iotlb_all = arm_smmu_flush_iotlb_all, .iotlb_sync = arm_smmu_iotlb_sync, .iova_to_phys = arm_smmu_iova_to_phys, - .add_device = arm_smmu_add_device, - .remove_device = arm_smmu_remove_device, + .probe_device = arm_smmu_probe_device, + .release_device = arm_smmu_release_device, .device_group = arm_smmu_device_group, .domain_get_attr = arm_smmu_domain_get_attr, .domain_set_attr = arm_smmu_domain_set_attr, diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index a6a5796e9c41..e622f4e33379 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -220,7 +220,7 @@ static int arm_smmu_register_legacy_master(struct device *dev, * With the legacy DT binding in play, we have no guarantees about * probe order, but then we're also not doing default domains, so we can * delay setting bus ops until we're sure every possible SMMU is ready, - * and that way ensure that no add_device() calls get missed. + * and that way ensure that no probe_device() calls get missed. */ static int arm_smmu_legacy_bus_init(void) { @@ -1062,7 +1062,6 @@ static int arm_smmu_master_alloc_smes(struct device *dev) struct arm_smmu_master_cfg *cfg = dev_iommu_priv_get(dev); struct arm_smmu_device *smmu = cfg->smmu; struct arm_smmu_smr *smrs = smmu->smrs; - struct iommu_group *group; int i, idx, ret; mutex_lock(&smmu->stream_map_mutex); @@ -1090,18 +1089,9 @@ static int arm_smmu_master_alloc_smes(struct device *dev) cfg->smendx[i] = (s16)idx; } - group = iommu_group_get_for_dev(dev); - if (IS_ERR(group)) { - ret = PTR_ERR(group); - goto out_err; - } - iommu_group_put(group); - /* It worked! Now, poke the actual hardware */ - for_each_cfg_sme(cfg, fwspec, i, idx) { + for_each_cfg_sme(cfg, fwspec, i, idx) arm_smmu_write_sme(smmu, idx); - smmu->s2crs[idx].group = group; - } mutex_unlock(&smmu->stream_map_mutex); return 0; @@ -1172,7 +1162,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) /* * FIXME: The arch/arm DMA API code tries to attach devices to its own - * domains between of_xlate() and add_device() - we have no way to cope + * domains between of_xlate() and probe_device() - we have no way to cope * with that, so until ARM gets converted to rely on groups and default * domains, just say no (but more politely than by dereferencing NULL). * This should be at least a WARN_ON once that's sorted. @@ -1382,7 +1372,7 @@ struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode) return dev ? dev_get_drvdata(dev) : NULL; } -static int arm_smmu_add_device(struct device *dev) +static struct iommu_device *arm_smmu_probe_device(struct device *dev) { struct arm_smmu_device *smmu = NULL; struct arm_smmu_master_cfg *cfg; @@ -1403,7 +1393,7 @@ static int arm_smmu_add_device(struct device *dev) } else if (fwspec && fwspec->ops == &arm_smmu_ops) { smmu = arm_smmu_get_by_fwnode(fwspec->iommu_fwnode); } else { - return -ENODEV; + return ERR_PTR(-ENODEV); } ret = -EINVAL; @@ -1444,21 +1434,19 @@ static int arm_smmu_add_device(struct device *dev) if (ret) goto out_cfg_free; - iommu_device_link(&smmu->iommu, dev); - device_link_add(dev, smmu->dev, DL_FLAG_PM_RUNTIME | DL_FLAG_AUTOREMOVE_SUPPLIER); - return 0; + return &smmu->iommu; out_cfg_free: kfree(cfg); out_free: iommu_fwspec_free(dev); - return ret; + return ERR_PTR(ret); } -static void arm_smmu_remove_device(struct device *dev) +static void arm_smmu_release_device(struct device *dev) { struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct arm_smmu_master_cfg *cfg; @@ -1475,13 +1463,11 @@ static void arm_smmu_remove_device(struct device *dev) if (ret < 0) return; - iommu_device_unlink(&smmu->iommu, dev); arm_smmu_master_free_smes(cfg, fwspec); arm_smmu_rpm_put(smmu); dev_iommu_priv_set(dev, NULL); - iommu_group_remove_device(dev); kfree(cfg); iommu_fwspec_free(dev); } @@ -1512,6 +1498,11 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev) else group = generic_device_group(dev); + /* Remember group for faster lookups */ + if (!IS_ERR(group)) + for_each_cfg_sme(cfg, fwspec, i, idx) + smmu->s2crs[idx].group = group; + return group; } @@ -1628,8 +1619,8 @@ static struct iommu_ops arm_smmu_ops = { .flush_iotlb_all = arm_smmu_flush_iotlb_all, .iotlb_sync = arm_smmu_iotlb_sync, .iova_to_phys = arm_smmu_iova_to_phys, - .add_device = arm_smmu_add_device, - .remove_device = arm_smmu_remove_device, + .probe_device = arm_smmu_probe_device, + .release_device = arm_smmu_release_device, .device_group = arm_smmu_device_group, .domain_get_attr = arm_smmu_domain_get_attr, .domain_set_attr = arm_smmu_domain_set_attr, From patchwork Tue Jun 2 07:48:19 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: 1302212 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 49bkhq2X20z9sSy; Tue, 2 Jun 2020 17:49: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 1jg1g6-0005gc-Vw; Tue, 02 Jun 2020 07:49:42 +0000 Received: from mail-pg1-f196.google.com ([209.85.215.196]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1g1-0005bS-Eg for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:37 +0000 Received: by mail-pg1-f196.google.com with SMTP id u5so4725750pgn.5 for ; Tue, 02 Jun 2020 00:49:37 -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=Afp3w6R7FrCt4tS+W56xj787jYqaRl+N+znVxBNsJ0I=; b=SGFjeC/HxpZbDnfbTUq99+/UDZP/uHj0hhsGk+VWmV44k3slqA/PRDbItt96CUEytr b/5eaVHGP/4JPTpwBH4WRmRtedTiZzc97ZdmzdtEPT/UCxndamTTfavfJdUfF0b2Fves 6Og8ymRQWs0kLdGKIblb7yFmVWkOgyvl4UbYPIR/ZCgsRQfBCAv5W8uVp4HQk6CUeBn1 JoEmehe6UxN7bI/Gh0e4w72GbVSLPDIh2GFKQGYvd+1HDHJrYNEaV+tojEvu+PSaNkUw mKTjhXYfqHnIzfdeTLSgZnrgv/PZmNCd4bsWVCvCpTgUtzdK1QSojrsOM5Zum4PMupvD 4UtQ== X-Gm-Message-State: AOAM530y+iLLf2nLXhhXb4XriyzwAYPVCMlzQyjY10HWSZeGhilcMHdR tF3EOWGNqVzWBFbMynMYZPE3KJtPlkU= X-Google-Smtp-Source: ABdhPJyXYYUJb6wVsuVqg+7JEE1/d/NUmFhvE89T9vjr4rxjcijgGA8Io04ssoL2EOic3zZsGngqUQ== X-Received: by 2002:a63:e549:: with SMTP id z9mr23862322pgj.213.1591084174925; Tue, 02 Jun 2020 00:49:34 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id m16sm1469547pfh.187.2020.06.02.00.49.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:34 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 18/42][SRU][U] iommu/pamu: Convert to probe/release_device() call-backs Date: Tue, 2 Jun 2020 15:48:19 +0800 Message-Id: <20200602074843.1743493-19-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 Convert the PAMU IOMMU driver to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-19-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 52dd3ca4176f7f87452ee4b9d9a6d2e57ac4ccb7 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/fsl_pamu_domain.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c index 06828e2698d5..928d37771ece 100644 --- a/drivers/iommu/fsl_pamu_domain.c +++ b/drivers/iommu/fsl_pamu_domain.c @@ -1016,25 +1016,13 @@ static struct iommu_group *fsl_pamu_device_group(struct device *dev) return group; } -static int fsl_pamu_add_device(struct device *dev) +static struct iommu_device *fsl_pamu_probe_device(struct device *dev) { - struct iommu_group *group; - - group = iommu_group_get_for_dev(dev); - if (IS_ERR(group)) - return PTR_ERR(group); - - iommu_group_put(group); - - iommu_device_link(&pamu_iommu, dev); - - return 0; + return &pamu_iommu; } -static void fsl_pamu_remove_device(struct device *dev) +static void fsl_pamu_release_device(struct device *dev) { - iommu_device_unlink(&pamu_iommu, dev); - iommu_group_remove_device(dev); } static const struct iommu_ops fsl_pamu_ops = { @@ -1048,8 +1036,8 @@ static const struct iommu_ops fsl_pamu_ops = { .iova_to_phys = fsl_pamu_iova_to_phys, .domain_set_attr = fsl_pamu_set_domain_attr, .domain_get_attr = fsl_pamu_get_domain_attr, - .add_device = fsl_pamu_add_device, - .remove_device = fsl_pamu_remove_device, + .probe_device = fsl_pamu_probe_device, + .release_device = fsl_pamu_release_device, .device_group = fsl_pamu_device_group, }; From patchwork Tue Jun 2 07:48:20 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: 1302213 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 49bkhr5YZrz9sSn; Tue, 2 Jun 2020 17:49:48 +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 1jg1g8-0005hl-8f; Tue, 02 Jun 2020 07:49:44 +0000 Received: from mail-pl1-f194.google.com ([209.85.214.194]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1g3-0005di-TA for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:40 +0000 Received: by mail-pl1-f194.google.com with SMTP id m7so1025523plt.5 for ; Tue, 02 Jun 2020 00:49:39 -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=lUFb7slEMcu1PkqLbEPEsMvemjxdNnYjTtR+Vvl6OJA=; b=iQSUs7CMoUcJbPZemEj6KLp981qbnhVRUbY6CE9s4qdoKOp6dSBmfItpVs1hGzLHHX O2lJ0jfALbUmLzOfQt8y+8wbVMuzQWv/4KLIh9Pz4m6/SumSCD8ww1dWu0m4iHd2b2QU etjHtqdBrt4xqJaiPZyv5etL+Jr0JBzuFEHRGIe9mnhaGYgqP9vLDVh8cOnrA36DklxY 9KbMerzZlqxA9Vn/JEgYFAUy5KMjC1aM3g1lXXQj/rq5zcLuUH2kVaqsBRQPBRcUSgkk Ysr1Jfx+Glf9qMHhjqbmNdilHOkyBq33f2257FdwJ8594xVJmZvMH4NloTzmekKHCqam vEJg== X-Gm-Message-State: AOAM532y/LKz2JnopNeZ5rYXaNaTnQmwFFS0xHHciV9PnqYxsC1GXeye mvlQFCcuHoMsSlTKRyb9cZVsoXnmBqY= X-Google-Smtp-Source: ABdhPJwpGBfaCd4NqF2bxqzCPdT0Lffviio+oiuZGw3OihT8J5lij6oTW+q+ok3gWX3futYI/3OvZQ== X-Received: by 2002:a17:90a:950b:: with SMTP id t11mr4150733pjo.35.1591084177453; Tue, 02 Jun 2020 00:49:37 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id h3sm1566719pfr.2.2020.06.02.00.49.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:36 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 19/42][SRU][U] iommu/s390: Convert to probe/release_device() call-backs Date: Tue, 2 Jun 2020 15:48:20 +0800 Message-Id: <20200602074843.1743493-20-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 Convert the S390 IOMMU driver to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-20-joro@8bytes.org Signed-off-by: Joerg Roedel (backported from commit 522af649e57b3e3a347a8261f609f73ab4143f20 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/s390-iommu.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c index c60d5c776fc6..8895dbb705eb 100644 --- a/drivers/iommu/s390-iommu.c +++ b/drivers/iommu/s390-iommu.c @@ -166,21 +166,14 @@ static void s390_iommu_detach_device(struct iommu_domain *domain, } } -static int s390_iommu_add_device(struct device *dev) +static struct iommu_device *s390_iommu_probe_device(struct device *dev) { - struct iommu_group *group = iommu_group_get_for_dev(dev); struct zpci_dev *zdev = to_zpci_dev(dev); - if (IS_ERR(group)) - return PTR_ERR(group); - - iommu_group_put(group); - iommu_device_link(&zdev->iommu_dev, dev); - - return 0; + return &zdev->iommu_dev; } -static void s390_iommu_remove_device(struct device *dev) +static void s390_iommu_release_device(struct device *dev) { struct zpci_dev *zdev = to_zpci_dev(dev); struct iommu_domain *domain; @@ -191,7 +184,7 @@ static void s390_iommu_remove_device(struct device *dev) * to vfio-pci and completing the VFIO_SET_IOMMU ioctl (which triggers * the attach_dev), removing the device via * "echo 1 > /sys/bus/pci/devices/.../remove" won't trigger detach_dev, - * only remove_device will be called via the BUS_NOTIFY_REMOVED_DEVICE + * only release_device will be called via the BUS_NOTIFY_REMOVED_DEVICE * notifier. * * So let's call detach_dev from here if it hasn't been called before. @@ -201,9 +194,6 @@ static void s390_iommu_remove_device(struct device *dev) if (domain) s390_iommu_detach_device(domain, dev); } - - iommu_device_unlink(&zdev->iommu_dev, dev); - iommu_group_remove_device(dev); } static int s390_iommu_update_trans(struct s390_domain *s390_domain, @@ -373,8 +363,8 @@ static const struct iommu_ops s390_iommu_ops = { .map = s390_iommu_map, .unmap = s390_iommu_unmap, .iova_to_phys = s390_iommu_iova_to_phys, - .add_device = s390_iommu_add_device, - .remove_device = s390_iommu_remove_device, + .probe_device = s390_iommu_probe_device, + .release_device = s390_iommu_release_device, .device_group = generic_device_group, .pgsize_bitmap = S390_IOMMU_PGSIZES, }; From patchwork Tue Jun 2 07:48:21 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: 1302214 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 49bkht4xH6z9sSy; Tue, 2 Jun 2020 17:49:50 +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 1jg1g9-0005jS-UO; Tue, 02 Jun 2020 07:49:45 +0000 Received: from mail-pg1-f194.google.com ([209.85.215.194]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1g6-0005fF-2L for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:42 +0000 Received: by mail-pg1-f194.google.com with SMTP id d10so4724469pgn.4 for ; Tue, 02 Jun 2020 00:49:41 -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=RaqTqooUCCA+a9Qmj82X9g9MoIysOAtGecUI4DTKUBU=; b=r3oWVU4ypEiyqxB356LBSUTmD+KbbLiEptRE7vQmO8O6+qng+TPbeRld9JDChDRtXR SWiDCcMk+dGIRxg/4eVTzQUJ34eciuneiKCXETT9dtfOuEUtJNRsv/7h+Vf5WwUI41zj i2+/z8FjPa5nB6Qgf0ma3+XM0XCKlmbhkmtC1VVuMEbTxEDN8wUPLp2T4znVfLu6RMh8 c+I+BhPo81mhIekwwHdA7m3Hvrh5BMSe1/8YCn/tjV4BYHGUtt5Y+cXpn+5u8KkjxqHn xVfqYF9LtEqhi1ABd5SSzTJ9KoBMuGXkbdkrJ94qKaEh47O/9vPk9orJQZAvUHzRNF1R cD7w== X-Gm-Message-State: AOAM530nbEkqc4pJPMoLV5Q7ZUt1V6FY3zrjEylh3NLViijyWCPREuHb yFF4meWFftrxYzscnr0wzdUiAtgzlLE= X-Google-Smtp-Source: ABdhPJwgzCRk3vqWATlVEVjSUfWts9tqCHDD7L+2yFNF7MlcHU7CvLiLAOoxFAqcG4hil+O5BfHJMA== X-Received: by 2002:a63:ff52:: with SMTP id s18mr6747308pgk.203.1591084179826; Tue, 02 Jun 2020 00:49:39 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id j26sm1532353pfr.215.2020.06.02.00.49.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:39 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 20/42][SRU][U] iommu/virtio: Convert to probe/release_device() call-backs Date: Tue, 2 Jun 2020 15:48:21 +0800 Message-Id: <20200602074843.1743493-21-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 Convert the VirtIO IOMMU driver to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-21-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 21acf6599cfb4407e9745b36f69c93cf99a3d189 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/virtio-iommu.c | 41 +++++++++--------------------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index 4e1d11af23c8..f6f07489a9aa 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -865,24 +865,23 @@ static struct viommu_dev *viommu_get_by_fwnode(struct fwnode_handle *fwnode) return dev ? dev_to_virtio(dev)->priv : NULL; } -static int viommu_add_device(struct device *dev) +static struct iommu_device *viommu_probe_device(struct device *dev) { int ret; - struct iommu_group *group; struct viommu_endpoint *vdev; struct viommu_dev *viommu = NULL; struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); if (!fwspec || fwspec->ops != &viommu_ops) - return -ENODEV; + return ERR_PTR(-ENODEV); viommu = viommu_get_by_fwnode(fwspec->iommu_fwnode); if (!viommu) - return -ENODEV; + return ERR_PTR(-ENODEV); vdev = kzalloc(sizeof(*vdev), GFP_KERNEL); if (!vdev) - return -ENOMEM; + return ERR_PTR(-ENOMEM); vdev->dev = dev; vdev->viommu = viommu; @@ -896,45 +895,25 @@ static int viommu_add_device(struct device *dev) goto err_free_dev; } - ret = iommu_device_link(&viommu->iommu, dev); - if (ret) - goto err_free_dev; + return &viommu->iommu; - /* - * Last step creates a default domain and attaches to it. Everything - * must be ready. - */ - group = iommu_group_get_for_dev(dev); - if (IS_ERR(group)) { - ret = PTR_ERR(group); - goto err_unlink_dev; - } - - iommu_group_put(group); - - return PTR_ERR_OR_ZERO(group); - -err_unlink_dev: - iommu_device_unlink(&viommu->iommu, dev); err_free_dev: generic_iommu_put_resv_regions(dev, &vdev->resv_regions); kfree(vdev); - return ret; + return ERR_PTR(ret); } -static void viommu_remove_device(struct device *dev) +static void viommu_release_device(struct device *dev) { - struct viommu_endpoint *vdev; struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + struct viommu_endpoint *vdev; if (!fwspec || fwspec->ops != &viommu_ops) return; vdev = dev_iommu_priv_get(dev); - iommu_group_remove_device(dev); - iommu_device_unlink(&vdev->viommu->iommu, dev); generic_iommu_put_resv_regions(dev, &vdev->resv_regions); kfree(vdev); } @@ -960,8 +939,8 @@ static struct iommu_ops viommu_ops = { .unmap = viommu_unmap, .iova_to_phys = viommu_iova_to_phys, .iotlb_sync = viommu_iotlb_sync, - .add_device = viommu_add_device, - .remove_device = viommu_remove_device, + .probe_device = viommu_probe_device, + .release_device = viommu_release_device, .device_group = viommu_device_group, .get_resv_regions = viommu_get_resv_regions, .put_resv_regions = generic_iommu_put_resv_regions, From patchwork Tue Jun 2 07:48:22 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: 1302215 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 49bkhy4MSlz9sSn; Tue, 2 Jun 2020 17:49:54 +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 1jg1gE-0005nN-5L; Tue, 02 Jun 2020 07:49:50 +0000 Received: from mail-pl1-f194.google.com ([209.85.214.194]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1g8-0005h7-GE for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:44 +0000 Received: by mail-pl1-f194.google.com with SMTP id y18so1027144plr.4 for ; Tue, 02 Jun 2020 00:49:44 -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=huNmhrQgmC4xuAaX/i0GV+w68XfF8ohC2Uat+c1Lssc=; b=hM1D3le+zXJ8yddo3yxfo5xCJ4+tyY0dk1/ip2p7i9OxeTtcmRyxmWX4V5TtgajM8g t4iV1+S07V8IFk6KoZhAkdGGMT0JsLYmFT/Cu6IY7RpZp90J7yA3SbiPXKo0vkPN5xDU Oi9Ua0Bsq+e1a8CeKVcSvfYNJGAmHV9Km9Org2iqv7ODsMEZLEhnK1BgLKlWKjFbiWSH AonbMpu8BKNbnWDSTxTOwf6TyL09op7LajTkw53TGnR7csiX84n6sMIv9oJEx9yEpVMz O+4CgLmiGKxSZaWZgimZQKJsVlBhhQc5SKWGfSsMyEb59cyqvr9uB7HRPKZ4jqYxdqyr rOxg== X-Gm-Message-State: AOAM531/+YffZID7e16jgqnt6qeTiJXajkZFYmsMKeTRp78Bv8jXIU+W 9P7CXZ5ZlweNzIKr5gHtbVwdfh5o2YI= X-Google-Smtp-Source: ABdhPJxe1isiSs2iTnnjNVLIqq1oMnZeNUG0qncPoyyureSk4L/oSX48iodiGGVIYBWaY7sL3I3+OA== X-Received: by 2002:a17:90a:224a:: with SMTP id c68mr3677989pje.21.1591084182160; Tue, 02 Jun 2020 00:49:42 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id w4sm1461171pfq.57.2020.06.02.00.49.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:41 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 21/42][SRU][U] iommu/msm: Convert to probe/release_device() call-backs Date: Tue, 2 Jun 2020 15:48:22 +0800 Message-Id: <20200602074843.1743493-22-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 Convert the MSM IOMMU driver to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-22-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit dea74f1c37fb6d9a8f7e0cb85beaa89f5eaea908 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/msm_iommu.c | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c index 94a6df1bddd6..10cd4db0710a 100644 --- a/drivers/iommu/msm_iommu.c +++ b/drivers/iommu/msm_iommu.c @@ -388,43 +388,23 @@ static struct msm_iommu_dev *find_iommu_for_dev(struct device *dev) return ret; } -static int msm_iommu_add_device(struct device *dev) +static struct iommu_device *msm_iommu_probe_device(struct device *dev) { struct msm_iommu_dev *iommu; - struct iommu_group *group; unsigned long flags; spin_lock_irqsave(&msm_iommu_lock, flags); iommu = find_iommu_for_dev(dev); spin_unlock_irqrestore(&msm_iommu_lock, flags); - if (iommu) - iommu_device_link(&iommu->iommu, dev); - else - return -ENODEV; - - group = iommu_group_get_for_dev(dev); - if (IS_ERR(group)) - return PTR_ERR(group); - - iommu_group_put(group); + if (!iommu) + return ERR_PTR(-ENODEV); - return 0; + return &iommu->iommu; } -static void msm_iommu_remove_device(struct device *dev) +static void msm_iommu_release_device(struct device *dev) { - struct msm_iommu_dev *iommu; - unsigned long flags; - - spin_lock_irqsave(&msm_iommu_lock, flags); - iommu = find_iommu_for_dev(dev); - spin_unlock_irqrestore(&msm_iommu_lock, flags); - - if (iommu) - iommu_device_unlink(&iommu->iommu, dev); - - iommu_group_remove_device(dev); } static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) @@ -708,8 +688,8 @@ static struct iommu_ops msm_iommu_ops = { */ .iotlb_sync = NULL, .iova_to_phys = msm_iommu_iova_to_phys, - .add_device = msm_iommu_add_device, - .remove_device = msm_iommu_remove_device, + .probe_device = msm_iommu_probe_device, + .release_device = msm_iommu_release_device, .device_group = generic_device_group, .pgsize_bitmap = MSM_IOMMU_PGSIZES, .of_xlate = qcom_iommu_of_xlate, From patchwork Tue Jun 2 07:48:23 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: 1302216 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 49bkj05drvz9sSn; Tue, 2 Jun 2020 17:49:56 +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 1jg1gF-0005ov-OC; Tue, 02 Jun 2020 07:49:51 +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 1jg1gB-0005jV-By for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:47 +0000 Received: by mail-pj1-f65.google.com with SMTP id a45so825544pje.1 for ; Tue, 02 Jun 2020 00:49:47 -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=7z08W2UZIbaYFsyeRHe8BPiJvN8nVyBeMp0v9QaqTBI=; b=TwrwFLs+lduypsbB1CBojWVpykryZJ5TcIKbANo/4+LTwKqgQnUIta6fRcvBS5TNS3 /EAFqDmCh2nFxHWBLCQ2kUPN4CtrdlnqooGG8ZpHo87OP4pQCvs6YP2zUBkS+CJi6SoX TGGttRhe/DG12ar1bcSCiRbNTsHHD+No1ED/XUI8hj+s5nDy9Lga6NZDYYXEVX0nmuOC nFf9tXcMHmOJsroZIFN85RPFDZJmAkmCQapPvWtMcA8nqNbtb2of2aAi9rKNondivPEo NhKmjEsVx8Z6QIYww5VW/OFtC4Ce46wQjDNS5qZsvIdHKK6YuVK7H3fKBTMW+j1yT9kl rD3Q== X-Gm-Message-State: AOAM5317ohv5kQ37VxB6Rmp6sjWccjZTuuIvd4c3uiuADqFoh5munnk7 3+arsSkf9Mu5ShWcdR1GhxFIc0vRT4c= X-Google-Smtp-Source: ABdhPJydc3Ifkt1DEaTLFenCfBSD77SeDqRdZbahcQwg/J4UokVRhCW8csz9HRZE4WUYyyK/I2cUTA== X-Received: by 2002:a17:90a:fa95:: with SMTP id cu21mr3863682pjb.56.1591084184555; Tue, 02 Jun 2020 00:49:44 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id a83sm1401826pfa.146.2020.06.02.00.49.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:43 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 22/42][SRU][U] iommu/mediatek: Convert to probe/release_device() call-backs Date: Tue, 2 Jun 2020 15:48:23 +0800 Message-Id: <20200602074843.1743493-23-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 Convert the Mediatek IOMMU driver to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-23-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 80e4592a77e4baa33035eaeac646f63f1f5d3d57 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/mtk_iommu.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 5f4d6df59cf6..2be96f1cdbd2 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -441,38 +441,26 @@ static phys_addr_t mtk_iommu_iova_to_phys(struct iommu_domain *domain, return pa; } -static int mtk_iommu_add_device(struct device *dev) +static struct iommu_device *mtk_iommu_probe_device(struct device *dev) { struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct mtk_iommu_data *data; - struct iommu_group *group; if (!fwspec || fwspec->ops != &mtk_iommu_ops) - return -ENODEV; /* Not a iommu client device */ + return ERR_PTR(-ENODEV); /* Not a iommu client device */ data = dev_iommu_priv_get(dev); - iommu_device_link(&data->iommu, dev); - group = iommu_group_get_for_dev(dev); - if (IS_ERR(group)) - return PTR_ERR(group); - - iommu_group_put(group); - return 0; + return &data->iommu; } -static void mtk_iommu_remove_device(struct device *dev) +static void mtk_iommu_release_device(struct device *dev) { struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); - struct mtk_iommu_data *data; if (!fwspec || fwspec->ops != &mtk_iommu_ops) return; - data = dev_iommu_priv_get(dev); - iommu_device_unlink(&data->iommu, dev); - - iommu_group_remove_device(dev); iommu_fwspec_free(dev); } @@ -526,8 +514,8 @@ static const struct iommu_ops mtk_iommu_ops = { .flush_iotlb_all = mtk_iommu_flush_iotlb_all, .iotlb_sync = mtk_iommu_iotlb_sync, .iova_to_phys = mtk_iommu_iova_to_phys, - .add_device = mtk_iommu_add_device, - .remove_device = mtk_iommu_remove_device, + .probe_device = mtk_iommu_probe_device, + .release_device = mtk_iommu_release_device, .device_group = mtk_iommu_device_group, .of_xlate = mtk_iommu_of_xlate, .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M, From patchwork Tue Jun 2 07:48:24 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: 1302217 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 49bkj46WQtz9sSn; Tue, 2 Jun 2020 17:50:00 +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 1jg1gJ-0005s2-Jl; Tue, 02 Jun 2020 07:49:55 +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 1jg1gE-0005mD-0S for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:50 +0000 Received: by mail-pj1-f65.google.com with SMTP id ga6so991245pjb.1 for ; Tue, 02 Jun 2020 00:49:49 -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=2yJ6egspVw5zK6q8DorWvYOCvGqKcH5aV6RwSbMu18k=; b=L9VfwJM1VKqj65uYLocSQCz9LZtKacSjvhbQMn3ZiiMDP1Dmf7OL2NWpX9EyuhITa1 i+4hgASICwp4dLXAEh/EkrWDkq5F1IFUhvOGIlz+qcP6v4L3QN2ybiTvOltDcDWO/I+u lWDEigAu4xsMjLI5Eh5MReHgwzswZQwCudWUVTU+D/IBRQXBIvcBMjc0tsFD+rDzVM1Y bMJgPU2FOT9LCwphyIRpyQT8yu/Z90ftF/304+jniohcmD4uXXWO72UkQsAEfYhFlLl0 TCv4n/S1udPkHZltQ1F31HfpsYwyV3/x4tgVyv18EHLFPC4bS3r4BttbJVfQCLZ2sL8f bTCw== X-Gm-Message-State: AOAM533pY7b7JoMTkobhFrhFiwzxg58T5hJampffZ7pJiRbL1RyEuWEM D/uW4cOhZglkn1We8/jxI5MOGRu5Tko= X-Google-Smtp-Source: ABdhPJz6ht4K52y7DI2lh4JqCurwcXLXpq3Qb67F52gAjwR2FBrA5HfGrcY7hH0tyc26RBfayjh9+A== X-Received: by 2002:a17:90a:35c8:: with SMTP id r66mr3957893pjb.155.1591084187240; Tue, 02 Jun 2020 00:49:47 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id 19sm1527560pjl.52.2020.06.02.00.49.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:46 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 23/42][SRU][U] iommu/mediatek-v1 Convert to probe/release_device() call-backs Date: Tue, 2 Jun 2020 15:48:24 +0800 Message-Id: <20200602074843.1743493-24-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 Convert the Mediatek-v1 IOMMU driver to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-24-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 57dbf81f50c82a0ad895a57828ad1ab539785a25 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/mtk_iommu_v1.c | 50 +++++++++++++++--------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c index a31be05601c9..7bdd74c7cb9f 100644 --- a/drivers/iommu/mtk_iommu_v1.c +++ b/drivers/iommu/mtk_iommu_v1.c @@ -416,14 +416,12 @@ static int mtk_iommu_create_mapping(struct device *dev, return 0; } -static int mtk_iommu_add_device(struct device *dev) +static struct iommu_device *mtk_iommu_probe_device(struct device *dev) { struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); - struct dma_iommu_mapping *mtk_mapping; struct of_phandle_args iommu_spec; struct of_phandle_iterator it; struct mtk_iommu_data *data; - struct iommu_group *group; int err; of_for_each_phandle(&it, err, dev->of_node, "iommus", @@ -442,35 +440,28 @@ static int mtk_iommu_add_device(struct device *dev) } if (!fwspec || fwspec->ops != &mtk_iommu_ops) - return -ENODEV; /* Not a iommu client device */ + return ERR_PTR(-ENODEV); /* Not a iommu client device */ - /* - * This is a short-term bodge because the ARM DMA code doesn't - * understand multi-device groups, but we have to call into it - * successfully (and not just rely on a normal IOMMU API attach - * here) in order to set the correct DMA API ops on @dev. - */ - group = iommu_group_alloc(); - if (IS_ERR(group)) - return PTR_ERR(group); + data = dev_iommu_priv_get(dev); - err = iommu_group_add_device(group, dev); - iommu_group_put(group); - if (err) - return err; + return &data->iommu; +} - data = dev_iommu_priv_get(dev); +static void mtk_iommu_probe_finalize(struct device *dev) +{ + struct dma_iommu_mapping *mtk_mapping; + struct mtk_iommu_data *data; + int err; + + data = dev_iommu_priv_get(dev); mtk_mapping = data->dev->archdata.iommu; - err = arm_iommu_attach_device(dev, mtk_mapping); - if (err) { - iommu_group_remove_device(dev); - return err; - } - return iommu_device_link(&data->iommu, dev); + err = arm_iommu_attach_device(dev, mtk_mapping); + if (err) + dev_err(dev, "Can't create IOMMU mapping - DMA-OPS will not work\n"); } -static void mtk_iommu_remove_device(struct device *dev) +static void mtk_iommu_release_device(struct device *dev) { struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct mtk_iommu_data *data; @@ -479,9 +470,6 @@ static void mtk_iommu_remove_device(struct device *dev) return; data = dev_iommu_priv_get(dev); - iommu_device_unlink(&data->iommu, dev); - - iommu_group_remove_device(dev); iommu_fwspec_free(dev); } @@ -534,8 +522,10 @@ static const struct iommu_ops mtk_iommu_ops = { .map = mtk_iommu_map, .unmap = mtk_iommu_unmap, .iova_to_phys = mtk_iommu_iova_to_phys, - .add_device = mtk_iommu_add_device, - .remove_device = mtk_iommu_remove_device, + .probe_device = mtk_iommu_probe_device, + .probe_finalize = mtk_iommu_probe_finalize, + .release_device = mtk_iommu_release_device, + .device_group = generic_device_group, .pgsize_bitmap = ~0UL << MT2701_IOMMU_PAGE_SHIFT, }; From patchwork Tue Jun 2 07:48: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: 1302218 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 49bkj90Gwnz9sSy; Tue, 2 Jun 2020 17:50:05 +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 1jg1gL-0005uG-VO; Tue, 02 Jun 2020 07:49:57 +0000 Received: from mail-pl1-f193.google.com ([209.85.214.193]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1gG-0005oh-Je for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:52 +0000 Received: by mail-pl1-f193.google.com with SMTP id q16so1030493plr.2 for ; Tue, 02 Jun 2020 00:49:52 -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=7yZ6pARFJeNew8ZAWNiPwGrWVuViaCOecCsQhw2owZE=; b=aGAHFpRc7I3N6i2u1w5Giw42uXJoLK9cefsmPms4RkbDw+7NGz6PYla9OUpS9jNQZR CMX1ZN8Tthtkc1t0lmbJ+a9L4OdpoxjfPF9CMiu+b0nQp2UP+8YhgbQs0NTsZ/wtcvJr UMEnMOV9v8TDuvgeZtQOsQ8WIy8WBk9LXf5LtE6h1qzp/sIaV6DZN6NBGprvQl2Uhgbn G16/pxKdwzOI/CmhDZNBxOUVAhOrrGIAOZVzvE2ssnBAieJhd5/2olE03W0uD7QzFS4N 0qRNFvJvTkyAMtzXxbHqXWsqCXLA99kgXDiXvkfd7tOF4P6ovtvBghEy+b9Xbb1dA4qp 3KMw== X-Gm-Message-State: AOAM5316r4hCJCb+4M9tGeKg6vrcW1l4gnPuN0e4p5i9GM/bQHZE/v1W bONN8bVzbqJd1Wd5SsMlQaxr/dUE+Fc= X-Google-Smtp-Source: ABdhPJxQ5HaSB2W8DducxiwApBXUQ27eBc6UTknMRTSdp4pFNBiJZb9ZuLV7eg90RvCnqgiwZ+rbUw== X-Received: by 2002:a17:90a:22cc:: with SMTP id s70mr4151940pjc.2.1591084190064; Tue, 02 Jun 2020 00:49:50 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id b23sm1361925pgs.33.2020.06.02.00.49.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:49 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 24/42][SRU][U] iommu/qcom: Convert to probe/release_device() call-backs Date: Tue, 2 Jun 2020 15:48:25 +0800 Message-Id: <20200602074843.1743493-25-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 Convert the QCOM IOMMU driver to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-25-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit bfe3bd493b3d3f9a08d1751338ccc711840e4590 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/qcom_iommu.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/drivers/iommu/qcom_iommu.c b/drivers/iommu/qcom_iommu.c index 5b3b270972f8..c3e1fbd1988c 100644 --- a/drivers/iommu/qcom_iommu.c +++ b/drivers/iommu/qcom_iommu.c @@ -524,14 +524,13 @@ static bool qcom_iommu_capable(enum iommu_cap cap) } } -static int qcom_iommu_add_device(struct device *dev) +static struct iommu_device *qcom_iommu_probe_device(struct device *dev) { struct qcom_iommu_dev *qcom_iommu = to_iommu(dev); - struct iommu_group *group; struct device_link *link; if (!qcom_iommu) - return -ENODEV; + return ERR_PTR(-ENODEV); /* * Establish the link between iommu and master, so that the @@ -542,28 +541,19 @@ static int qcom_iommu_add_device(struct device *dev) if (!link) { dev_err(qcom_iommu->dev, "Unable to create device link between %s and %s\n", dev_name(qcom_iommu->dev), dev_name(dev)); - return -ENODEV; + return ERR_PTR(-ENODEV); } - group = iommu_group_get_for_dev(dev); - if (IS_ERR(group)) - return PTR_ERR(group); - - iommu_group_put(group); - iommu_device_link(&qcom_iommu->iommu, dev); - - return 0; + return &qcom_iommu->iommu; } -static void qcom_iommu_remove_device(struct device *dev) +static void qcom_iommu_release_device(struct device *dev) { struct qcom_iommu_dev *qcom_iommu = to_iommu(dev); if (!qcom_iommu) return; - iommu_device_unlink(&qcom_iommu->iommu, dev); - iommu_group_remove_device(dev); iommu_fwspec_free(dev); } @@ -619,8 +609,8 @@ static const struct iommu_ops qcom_iommu_ops = { .flush_iotlb_all = qcom_iommu_flush_iotlb_all, .iotlb_sync = qcom_iommu_iotlb_sync, .iova_to_phys = qcom_iommu_iova_to_phys, - .add_device = qcom_iommu_add_device, - .remove_device = qcom_iommu_remove_device, + .probe_device = qcom_iommu_probe_device, + .release_device = qcom_iommu_release_device, .device_group = generic_device_group, .of_xlate = qcom_iommu_of_xlate, .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M, From patchwork Tue Jun 2 07:48:26 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: 1302219 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 49bkjB1Bv9z9sSd; Tue, 2 Jun 2020 17:50:06 +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 1jg1gO-0005xK-TP; Tue, 02 Jun 2020 07:50:00 +0000 Received: from mail-pj1-f66.google.com ([209.85.216.66]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1gI-0005qq-MF for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:54 +0000 Received: by mail-pj1-f66.google.com with SMTP id 5so1060501pjd.0 for ; Tue, 02 Jun 2020 00:49:54 -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=DFsOeFrgo40eRq0amBe6xcjeTzsdHh/NWRYllbP/P1Y=; b=cXWgdViUoxzEVzDVcO6gKwd4CxcEy307GwMqAS2azY+h6sl2KdBhjWg+LLbQ322Npg cRK9NSBm3Ms+b+t6rF10rXNrBc+c05M0WLUFfxD7uz+GRH+T5q7QcVjm6mkI3VLrvq+O iL3RqY2Xqhxc64GnM0RySD3+Lbha3rk82X1ChW7leb4kFgBER7uB6ryiDinAbQJ45dv4 YDZ7WiMwrzWmio3FbYuGhcFMZNwBu6BzIRVMfkF8DTJxIwj1cQOV+ACFrVFkmYkM5rDm kFyQkyJyfpCv6sfU7nxxB/ROtlIy9Z0IHBw/p1Q/WRVrFkF08s4+qEbbQQcldMctEYvb 4liQ== X-Gm-Message-State: AOAM530Ki/LU2jiW043G02xehc8Bxod3KDs8GxC391C0xfckhM3FpgGm WE70Sr/n7R5a/y92TtEQ1L4TiJU7opQ= X-Google-Smtp-Source: ABdhPJxHRkL7RqG0X5Qk/47lbR0qSZwDOdeeed1JsCU+JFc8y6N+Eg2BeEwQuYcMwZGUVbob2JbknQ== X-Received: by 2002:a17:90b:8d0:: with SMTP id ds16mr3972879pjb.174.1591084192416; Tue, 02 Jun 2020 00:49:52 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id x2sm1677904pfr.186.2020.06.02.00.49.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:51 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 25/42][SRU][U] iommu/rockchip: Convert to probe/release_device() call-backs Date: Tue, 2 Jun 2020 15:48:26 +0800 Message-Id: <20200602074843.1743493-26-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 Convert the Rockchip IOMMU driver to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-26-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit d8260443245dc8e504c3ecde5e86972f5be2b43e linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/rockchip-iommu.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index b33cdd5aad81..d25c2486ca07 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -1054,40 +1054,28 @@ static void rk_iommu_domain_free(struct iommu_domain *domain) kfree(rk_domain); } -static int rk_iommu_add_device(struct device *dev) +static struct iommu_device *rk_iommu_probe_device(struct device *dev) { - struct iommu_group *group; - struct rk_iommu *iommu; struct rk_iommudata *data; + struct rk_iommu *iommu; data = dev->archdata.iommu; if (!data) - return -ENODEV; + return ERR_PTR(-ENODEV); iommu = rk_iommu_from_dev(dev); - group = iommu_group_get_for_dev(dev); - if (IS_ERR(group)) - return PTR_ERR(group); - iommu_group_put(group); - - iommu_device_link(&iommu->iommu, dev); data->link = device_link_add(dev, iommu->dev, DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME); - return 0; + return &iommu->iommu; } -static void rk_iommu_remove_device(struct device *dev) +static void rk_iommu_release_device(struct device *dev) { - struct rk_iommu *iommu; struct rk_iommudata *data = dev->archdata.iommu; - iommu = rk_iommu_from_dev(dev); - device_link_del(data->link); - iommu_device_unlink(&iommu->iommu, dev); - iommu_group_remove_device(dev); } static struct iommu_group *rk_iommu_device_group(struct device *dev) @@ -1126,8 +1114,8 @@ static const struct iommu_ops rk_iommu_ops = { .detach_dev = rk_iommu_detach_device, .map = rk_iommu_map, .unmap = rk_iommu_unmap, - .add_device = rk_iommu_add_device, - .remove_device = rk_iommu_remove_device, + .probe_device = rk_iommu_probe_device, + .release_device = rk_iommu_release_device, .iova_to_phys = rk_iommu_iova_to_phys, .device_group = rk_iommu_device_group, .pgsize_bitmap = RK_IOMMU_PGSIZE_BITMAP, From patchwork Tue Jun 2 07:48:27 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: 1302220 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 49bkjF6QfZz9sT2; Tue, 2 Jun 2020 17:50:09 +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 1jg1gS-000604-Vg; Tue, 02 Jun 2020 07:50:04 +0000 Received: from mail-pf1-f196.google.com ([209.85.210.196]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1gM-0005tD-9w for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:58 +0000 Received: by mail-pf1-f196.google.com with SMTP id b201so578760pfb.0 for ; Tue, 02 Jun 2020 00:49:58 -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=7LqpeApvuXZKkbLk4Cjp+5q9htgvmn7kl62q4f2PJXY=; b=eAfquc0KawOsRhemifWlgPC36zGI22Y8Jg+/XBeNrg15ULkt6jmZfe6U3nwKJHFibr DbY8ET2DRMRvCiIzedRNIhMSpno8n6L6Gqb44TX011jlMJd3Ro9tT2oA8KBrK6iDeN8l L8O1pSgIRfiHDdnA5jskklATJmV9Ssp8Sqal4sTULgF5pPZRTnQWFxScbR7b/kGDFdkk YdKxGkyDvLLqzigkJCqd3T8b2mEAypVIbYxk5DldI2yMc8ykmDzwp/aoRNSczLFyA9EW LO+A3IeOc8nYHAO/RSDCN4f0BC7PNFowuR4mUHA09wpwWbXxKnUBDvaL2FfrXCnbnRQ2 +gUQ== X-Gm-Message-State: AOAM533yE6d+ZfkvAosSbyu6zhUzG/tlUdEfS4L/ay1y4I2ULFJeK5Jh +Sa8pG3WgWpB3kZWUHJtXIzskJERO1k= X-Google-Smtp-Source: ABdhPJyM0t8ezxzqZ54JpNxP7VTn1QDd65l3SVjLWDqtR7eszxZUtV0M0VWvyUePkxn4Io7DIlVXUw== X-Received: by 2002:aa7:970f:: with SMTP id a15mr25313118pfg.80.1591084195451; Tue, 02 Jun 2020 00:49:55 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id p4sm1455274pff.159.2020.06.02.00.49.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:54 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 26/42][SRU][U] iommu/tegra: Convert to probe/release_device() call-backs Date: Tue, 2 Jun 2020 15:48:27 +0800 Message-Id: <20200602074843.1743493-27-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 Convert the Tegra IOMMU drivers to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-27-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit b287ba73789906fc4f4ee821e1014b13e2814849 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/tegra-gart.c | 24 ++++++------------------ drivers/iommu/tegra-smmu.c | 31 ++++++++----------------------- 2 files changed, 14 insertions(+), 41 deletions(-) diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c index db6559e8336f..5fbdff6ff41a 100644 --- a/drivers/iommu/tegra-gart.c +++ b/drivers/iommu/tegra-gart.c @@ -243,28 +243,16 @@ static bool gart_iommu_capable(enum iommu_cap cap) return false; } -static int gart_iommu_add_device(struct device *dev) +static struct iommu_device *gart_iommu_probe_device(struct device *dev) { - struct iommu_group *group; - if (!dev_iommu_fwspec_get(dev)) - return -ENODEV; - - group = iommu_group_get_for_dev(dev); - if (IS_ERR(group)) - return PTR_ERR(group); - - iommu_group_put(group); + return ERR_PTR(-ENODEV); - iommu_device_link(&gart_handle->iommu, dev); - - return 0; + return &gart_handle->iommu; } -static void gart_iommu_remove_device(struct device *dev) +static void gart_iommu_release_device(struct device *dev) { - iommu_group_remove_device(dev); - iommu_device_unlink(&gart_handle->iommu, dev); } static int gart_iommu_of_xlate(struct device *dev, @@ -290,8 +278,8 @@ static const struct iommu_ops gart_iommu_ops = { .domain_free = gart_iommu_domain_free, .attach_dev = gart_iommu_attach_dev, .detach_dev = gart_iommu_detach_dev, - .add_device = gart_iommu_add_device, - .remove_device = gart_iommu_remove_device, + .probe_device = gart_iommu_probe_device, + .release_device = gart_iommu_release_device, .device_group = generic_device_group, .map = gart_iommu_map, .unmap = gart_iommu_unmap, diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index 63a147b623e6..7426b7666e2b 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -757,11 +757,10 @@ static int tegra_smmu_configure(struct tegra_smmu *smmu, struct device *dev, return 0; } -static int tegra_smmu_add_device(struct device *dev) +static struct iommu_device *tegra_smmu_probe_device(struct device *dev) { struct device_node *np = dev->of_node; struct tegra_smmu *smmu = NULL; - struct iommu_group *group; struct of_phandle_args args; unsigned int index = 0; int err; @@ -774,7 +773,7 @@ static int tegra_smmu_add_device(struct device *dev) of_node_put(args.np); if (err < 0) - return err; + return ERR_PTR(err); /* * Only a single IOMMU master interface is currently @@ -783,8 +782,6 @@ static int tegra_smmu_add_device(struct device *dev) */ dev->archdata.iommu = smmu; - iommu_device_link(&smmu->iommu, dev); - break; } @@ -793,26 +790,14 @@ static int tegra_smmu_add_device(struct device *dev) } if (!smmu) - return -ENODEV; - - group = iommu_group_get_for_dev(dev); - if (IS_ERR(group)) - return PTR_ERR(group); - - iommu_group_put(group); + return ERR_PTR(-ENODEV); - return 0; + return &smmu->iommu; } -static void tegra_smmu_remove_device(struct device *dev) +static void tegra_smmu_release_device(struct device *dev) { - struct tegra_smmu *smmu = dev->archdata.iommu; - - if (smmu) - iommu_device_unlink(&smmu->iommu, dev); - dev->archdata.iommu = NULL; - iommu_group_remove_device(dev); } static const struct tegra_smmu_group_soc * @@ -895,8 +880,8 @@ static const struct iommu_ops tegra_smmu_ops = { .domain_free = tegra_smmu_domain_free, .attach_dev = tegra_smmu_attach_dev, .detach_dev = tegra_smmu_detach_dev, - .add_device = tegra_smmu_add_device, - .remove_device = tegra_smmu_remove_device, + .probe_device = tegra_smmu_probe_device, + .release_device = tegra_smmu_release_device, .device_group = tegra_smmu_device_group, .map = tegra_smmu_map, .unmap = tegra_smmu_unmap, @@ -1015,7 +1000,7 @@ struct tegra_smmu *tegra_smmu_probe(struct device *dev, * value. However the IOMMU registration process will attempt to add * all devices to the IOMMU when bus_set_iommu() is called. In order * not to rely on global variables to track the IOMMU instance, we - * set it here so that it can be looked up from the .add_device() + * set it here so that it can be looked up from the .probe_device() * callback via the IOMMU device's .drvdata field. */ mc->smmu = smmu; From patchwork Tue Jun 2 07:48:28 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: 1302221 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 49bkjK1JL1z9sSd; Tue, 2 Jun 2020 17:50:13 +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 1jg1gW-00063T-8s; Tue, 02 Jun 2020 07:50:08 +0000 Received: from mail-pf1-f196.google.com ([209.85.210.196]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1gO-0005w4-Sc for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:50:01 +0000 Received: by mail-pf1-f196.google.com with SMTP id h185so3681068pfg.2 for ; Tue, 02 Jun 2020 00:50:00 -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=rwf4EgEljKD8Dg/tYrbdbZkatNvm8lHjuTkgXdcMotY=; b=aM23VfmntD2e0sJG7Gaov+WVWRA31dE87YXFjNaG+OiQGRpvXuaw6CCrZIczYb1j1C 9IadRVkcNyVbUsgKFVXWMFZT6D0HJUMfdTgsXwtaEEoPmot4pOdq77ULYWdE2qSkETlZ N9pyCyX1vzkLewbLhsdkZYBDar6mWAGYyHDCQlOOCfNFaEXFfJt8fpaIofqs/rWduyNJ t3ODEXDsb8egLvzXpSeay1ibvHR1G4r9ud9uYS9Orzr+5pyVH0HA64KCLiLOl7ktQC2n K9emuXrnVvf/cXhaXtgCiinCH4cV5O5/FCFnF+zB8TjAm4TqVPfhP0Tx1K7Y0kMiK0il y9vQ== X-Gm-Message-State: AOAM532Pd3lu/qynosN4PRfeJd5mcxdLxw27XUesw4ZY/K9/1ZtXsMKc GpxMxA3Dbu3Sl5naQgjupyr1r21j/JY= X-Google-Smtp-Source: ABdhPJzmpQuzKxqY6BoKgt4zp9I8fm1QPwMjkWsM5YJK9R3skAGuLm7afVkM47PocEevFWnRALtQ2g== X-Received: by 2002:a63:5054:: with SMTP id q20mr22968020pgl.117.1591084198424; Tue, 02 Jun 2020 00:49:58 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id v127sm1466725pfv.99.2020.06.02.00.49.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:57 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 27/42][SRU][U] iommu/renesas: Convert to probe/release_device() call-backs Date: Tue, 2 Jun 2020 15:48:28 +0800 Message-Id: <20200602074843.1743493-28-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 Convert the Renesas IOMMU driver to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-28-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 6580c8a78424fb1a0d2bd9134355563c0398fe8e linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/ipmmu-vmsa.c | 60 +++++++++++++------------------------- 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 310cf09feea3..fb7e702dee23 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -805,24 +805,8 @@ static int ipmmu_of_xlate(struct device *dev, static int ipmmu_init_arm_mapping(struct device *dev) { struct ipmmu_vmsa_device *mmu = to_ipmmu(dev); - struct iommu_group *group; int ret; - /* Create a device group and add the device to it. */ - group = iommu_group_alloc(); - if (IS_ERR(group)) { - dev_err(dev, "Failed to allocate IOMMU group\n"); - return PTR_ERR(group); - } - - ret = iommu_group_add_device(group, dev); - iommu_group_put(group); - - if (ret < 0) { - dev_err(dev, "Failed to add device to IPMMU group\n"); - return ret; - } - /* * Create the ARM mapping, used by the ARM DMA mapping core to allocate * VAs. This will allocate a corresponding IOMMU domain. @@ -856,48 +840,39 @@ static int ipmmu_init_arm_mapping(struct device *dev) return 0; error: - iommu_group_remove_device(dev); if (mmu->mapping) arm_iommu_release_mapping(mmu->mapping); return ret; } -static int ipmmu_add_device(struct device *dev) +static struct iommu_device *ipmmu_probe_device(struct device *dev) { struct ipmmu_vmsa_device *mmu = to_ipmmu(dev); - struct iommu_group *group; - int ret; /* * Only let through devices that have been verified in xlate() */ if (!mmu) - return -ENODEV; + return ERR_PTR(-ENODEV); - if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_IOMMU_DMA)) { - ret = ipmmu_init_arm_mapping(dev); - if (ret) - return ret; - } else { - group = iommu_group_get_for_dev(dev); - if (IS_ERR(group)) - return PTR_ERR(group); + return &mmu->iommu; +} - iommu_group_put(group); - } +static void ipmmu_probe_finalize(struct device *dev) +{ + int ret = 0; - iommu_device_link(&mmu->iommu, dev); - return 0; + if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_IOMMU_DMA)) + ret = ipmmu_init_arm_mapping(dev); + + if (ret) + dev_err(dev, "Can't create IOMMU mapping - DMA-OPS will not work\n"); } -static void ipmmu_remove_device(struct device *dev) +static void ipmmu_release_device(struct device *dev) { - struct ipmmu_vmsa_device *mmu = to_ipmmu(dev); - - iommu_device_unlink(&mmu->iommu, dev); arm_iommu_detach_device(dev); - iommu_group_remove_device(dev); } static struct iommu_group *ipmmu_find_group(struct device *dev) @@ -925,9 +900,14 @@ static const struct iommu_ops ipmmu_ops = { .flush_iotlb_all = ipmmu_flush_iotlb_all, .iotlb_sync = ipmmu_iotlb_sync, .iova_to_phys = ipmmu_iova_to_phys, - .add_device = ipmmu_add_device, - .remove_device = ipmmu_remove_device, + .probe_device = ipmmu_probe_device, + .release_device = ipmmu_release_device, + .probe_finalize = ipmmu_probe_finalize, +#if defined(CONFIG_ARM) && !defined(CONFIG_IOMMU_DMA) + .device_group = generic_device_group, +#else .device_group = ipmmu_find_group, +#endif .pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K, .of_xlate = ipmmu_of_xlate, }; From patchwork Tue Jun 2 07:48:29 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: 1302223 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 49bkjT2CfDz9sSd; Tue, 2 Jun 2020 17:50:21 +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 1jg1gd-00069N-GZ; Tue, 02 Jun 2020 07:50:15 +0000 Received: from mail-pl1-f194.google.com ([209.85.214.194]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1gT-0005zk-Hz for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:50:05 +0000 Received: by mail-pl1-f194.google.com with SMTP id x11so1015400plv.9 for ; Tue, 02 Jun 2020 00:50:05 -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=4AuoUa0mQUO1k7h4a+pAc/39U3AyUgbhgiEEJcXF+oI=; b=VzDQo5X1d9LSc3RS6WzejmcwEjM1DkQRQaqked6IWU84wSuUnNxP/iJMdEvYrvsQke k/ZJqd0xsmEmJ2DiXS2sjZnTO5I+YesJOP292iR+0ebeR2KuBLqYsXkEpnkowptPMjwL t1xnHiPvJOFG+1kYMlzbqatAfwjC5wDwhDmbnKVB5vS+/4H1am/nEAVZldfFVu3qCZD4 +VYVOUsCZYs1uobfgOGSw0pJmG6Ce/M9BUqBsBhjBqJB71JlPzBE7R3HBW5+j4chkJkW f7v5eN+iGEwDK3AQ7Wa6juGKh31T06vkcfQu52BWzK8G8KyjGvubzlwPc8As8lNLKWtr 9Y9w== X-Gm-Message-State: AOAM532BmT9tPbLPrN909go3FSvHXMcR0LKowNqRFp6V7+eo0RLPgTMt FXvgOqRj9wRhjmxMS9QLBc9u/hFKoZU= X-Google-Smtp-Source: ABdhPJxRjKRU13+Og2vHnDIY6fAj7ALbn9EjF8bo9NbLaDU6YkrYa19L80go9ZmuhZodhG2xTUEubw== X-Received: by 2002:a17:90a:1d1:: with SMTP id 17mr3911463pjd.211.1591084201413; Tue, 02 Jun 2020 00:50:01 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id a2sm1476687pgh.81.2020.06.02.00.50.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:50:00 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 28/42][SRU][U] iommu/omap: Remove orphan_dev tracking Date: Tue, 2 Jun 2020 15:48:29 +0800 Message-Id: <20200602074843.1743493-29-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 Remove the tracking of device which could not be probed because their IOMMU is not probed yet. Replace it with a call to bus_iommu_probe() when a new IOMMU is probed. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-29-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit c822b37cac48ea0e4c8202a42fdc480ace099b12 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/omap-iommu.c | 54 +++----------------------------------- 1 file changed, 4 insertions(+), 50 deletions(-) diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index 887fefcb03b4..ecc9d0829a91 100644 --- a/drivers/iommu/omap-iommu.c +++ b/drivers/iommu/omap-iommu.c @@ -35,15 +35,6 @@ static const struct iommu_ops omap_iommu_ops; -struct orphan_dev { - struct device *dev; - struct list_head node; -}; - -static LIST_HEAD(orphan_dev_list); - -static DEFINE_SPINLOCK(orphan_lock); - #define to_iommu(dev) ((struct omap_iommu *)dev_get_drvdata(dev)) /* bitmap of the page sizes currently supported */ @@ -62,8 +53,6 @@ static DEFINE_SPINLOCK(orphan_lock); static struct platform_driver omap_iommu_driver; static struct kmem_cache *iopte_cachep; -static int _omap_iommu_add_device(struct device *dev); - /** * to_omap_domain - Get struct omap_iommu_domain from generic iommu_domain * @dom: generic iommu domain handle @@ -1177,7 +1166,6 @@ static int omap_iommu_probe(struct platform_device *pdev) struct omap_iommu *obj; struct resource *res; struct device_node *of = pdev->dev.of_node; - struct orphan_dev *orphan_dev, *tmp; if (!of) { pr_err("%s: only DT-based devices are supported\n", __func__); @@ -1260,13 +1248,8 @@ static int omap_iommu_probe(struct platform_device *pdev) dev_info(&pdev->dev, "%s registered\n", obj->name); - list_for_each_entry_safe(orphan_dev, tmp, &orphan_dev_list, node) { - err = _omap_iommu_add_device(orphan_dev->dev); - if (!err) { - list_del(&orphan_dev->node); - kfree(orphan_dev); - } - } + /* Re-probe bus to probe device attached to this IOMMU */ + bus_iommu_probe(&platform_bus_type); return 0; @@ -1657,7 +1640,7 @@ static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain, return ret; } -static int _omap_iommu_add_device(struct device *dev) +static int omap_iommu_add_device(struct device *dev) { struct omap_iommu_arch_data *arch_data, *tmp; struct omap_iommu *oiommu; @@ -1666,8 +1649,6 @@ static int _omap_iommu_add_device(struct device *dev) struct platform_device *pdev; int num_iommus, i; int ret; - struct orphan_dev *orphan_dev; - unsigned long flags; /* * Allocate the archdata iommu structure for DT-based devices. @@ -1702,23 +1683,7 @@ static int _omap_iommu_add_device(struct device *dev) if (!pdev) { of_node_put(np); kfree(arch_data); - spin_lock_irqsave(&orphan_lock, flags); - list_for_each_entry(orphan_dev, &orphan_dev_list, - node) { - if (orphan_dev->dev == dev) - break; - } - spin_unlock_irqrestore(&orphan_lock, flags); - - if (orphan_dev && orphan_dev->dev == dev) - return -EPROBE_DEFER; - - orphan_dev = kzalloc(sizeof(*orphan_dev), GFP_KERNEL); - orphan_dev->dev = dev; - spin_lock_irqsave(&orphan_lock, flags); - list_add(&orphan_dev->node, &orphan_dev_list); - spin_unlock_irqrestore(&orphan_lock, flags); - return -EPROBE_DEFER; + return -ENODEV; } oiommu = platform_get_drvdata(pdev); @@ -1764,17 +1729,6 @@ static int _omap_iommu_add_device(struct device *dev) return 0; } -static int omap_iommu_add_device(struct device *dev) -{ - int ret; - - ret = _omap_iommu_add_device(dev); - if (ret == -EPROBE_DEFER) - return 0; - - return ret; -} - static void omap_iommu_remove_device(struct device *dev) { struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; From patchwork Tue Jun 2 07:48:30 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: 1302222 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 49bkjN6VYwz9sSy; Tue, 2 Jun 2020 17:50:16 +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 1jg1gZ-00066P-GV; Tue, 02 Jun 2020 07:50:11 +0000 Received: from mail-pl1-f194.google.com ([209.85.214.194]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1gU-00060Z-JG for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:50:06 +0000 Received: by mail-pl1-f194.google.com with SMTP id y18so1027498plr.4 for ; Tue, 02 Jun 2020 00:50:06 -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=62hzcQ6Bu9kVzrFhY09KuaX5ICO+cyVuHAx9F6Y2e2c=; b=dOwClZr6bfvSKlDB7L8y+2eILIaqSyNElTWXELmq6vG7/NpxcurnyEJdW0h/RuvWOV IEAraVB8i0nxAgpdz+QkefUYX5P5cROG/xpGhihBnSfErFxRogRFGb5iMWCOaTiQkq1k t2Roh6Rr7p4lHqmMBLOQIqOB7KdHn2AC45neKD7b4IABSJYxkRDNcx9/GLRR+YAWgTX9 P+wQsdzSv56rNgShnyHZohAVVxbtzwBb7Gc6mHjNa5SdNip83RIhHo9l+v/NsiE7KNm5 uGD8VtPDoU/XSb8WKwvhBm6t1c7NJh+R5tIO1IiL8wQv0vHrzeMl+6CTDOK2X9LQpVgC eb6A== X-Gm-Message-State: AOAM533ROCDUOAlJiht+bq9mzdqAHH4HbtyD3qdIcYVaTIEp2FIqO/F+ KHzYtiI78WhbpVSF4wXaZnb47ey2kRo= X-Google-Smtp-Source: ABdhPJz+v3vBcabH5jq1O4Y41oICWDd2cVKGQMC5DiKekmyh8TXB8tRsy5N7XxoPXW+dFUlKECEK0Q== X-Received: by 2002:a17:902:7c90:: with SMTP id y16mr532638pll.75.1591084203803; Tue, 02 Jun 2020 00:50:03 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id o25sm1401781pgn.84.2020.06.02.00.50.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:50:02 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 29/42][SRU][U] iommu/omap: Convert to probe/release_device() call-backs Date: Tue, 2 Jun 2020 15:48:30 +0800 Message-Id: <20200602074843.1743493-30-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 Convert the OMAP IOMMU driver to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-30-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 6785eb9105e3363aa51408c700a55e8b5f88fcf6 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/omap-iommu.c | 49 ++++++++++---------------------------- 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index ecc9d0829a91..6699fe6d9e06 100644 --- a/drivers/iommu/omap-iommu.c +++ b/drivers/iommu/omap-iommu.c @@ -1640,15 +1640,13 @@ static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain, return ret; } -static int omap_iommu_add_device(struct device *dev) +static struct iommu_device *omap_iommu_probe_device(struct device *dev) { struct omap_iommu_arch_data *arch_data, *tmp; + struct platform_device *pdev; struct omap_iommu *oiommu; - struct iommu_group *group; struct device_node *np; - struct platform_device *pdev; int num_iommus, i; - int ret; /* * Allocate the archdata iommu structure for DT-based devices. @@ -1657,7 +1655,7 @@ static int omap_iommu_add_device(struct device *dev) * IOMMU users. */ if (!dev->of_node) - return 0; + return ERR_PTR(-ENODEV); /* * retrieve the count of IOMMU nodes using phandle size as element size @@ -1670,27 +1668,27 @@ static int omap_iommu_add_device(struct device *dev) arch_data = kcalloc(num_iommus + 1, sizeof(*arch_data), GFP_KERNEL); if (!arch_data) - return -ENOMEM; + return ERR_PTR(-ENOMEM); for (i = 0, tmp = arch_data; i < num_iommus; i++, tmp++) { np = of_parse_phandle(dev->of_node, "iommus", i); if (!np) { kfree(arch_data); - return -EINVAL; + return ERR_PTR(-EINVAL); } pdev = of_find_device_by_node(np); if (!pdev) { of_node_put(np); kfree(arch_data); - return -ENODEV; + return ERR_PTR(-ENODEV); } oiommu = platform_get_drvdata(pdev); if (!oiommu) { of_node_put(np); kfree(arch_data); - return -EINVAL; + return ERR_PTR(-EINVAL); } tmp->iommu_dev = oiommu; @@ -1699,46 +1697,25 @@ static int omap_iommu_add_device(struct device *dev) of_node_put(np); } + dev->archdata.iommu = arch_data; + /* * use the first IOMMU alone for the sysfs device linking. * TODO: Evaluate if a single iommu_group needs to be * maintained for both IOMMUs */ oiommu = arch_data->iommu_dev; - ret = iommu_device_link(&oiommu->iommu, dev); - if (ret) { - kfree(arch_data); - return ret; - } - - dev->archdata.iommu = arch_data; - - /* - * IOMMU group initialization calls into omap_iommu_device_group, which - * needs a valid dev->archdata.iommu pointer - */ - group = iommu_group_get_for_dev(dev); - if (IS_ERR(group)) { - iommu_device_unlink(&oiommu->iommu, dev); - dev->archdata.iommu = NULL; - kfree(arch_data); - return PTR_ERR(group); - } - iommu_group_put(group); - return 0; + return &oiommu->iommu; } -static void omap_iommu_remove_device(struct device *dev) +static void omap_iommu_release_device(struct device *dev) { struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; if (!dev->of_node || !arch_data) return; - iommu_device_unlink(&arch_data->iommu_dev->iommu, dev); - iommu_group_remove_device(dev); - dev->archdata.iommu = NULL; kfree(arch_data); @@ -1763,8 +1740,8 @@ static const struct iommu_ops omap_iommu_ops = { .map = omap_iommu_map, .unmap = omap_iommu_unmap, .iova_to_phys = omap_iommu_iova_to_phys, - .add_device = omap_iommu_add_device, - .remove_device = omap_iommu_remove_device, + .probe_device = omap_iommu_probe_device, + .release_device = omap_iommu_release_device, .device_group = omap_iommu_device_group, .pgsize_bitmap = OMAP_IOMMU_PGSIZES, }; From patchwork Tue Jun 2 07:48:31 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: 1302224 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 49bkjW64LYz9sSd; Tue, 2 Jun 2020 17:50:23 +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 1jg1gg-0006C1-2l; Tue, 02 Jun 2020 07:50:18 +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 1jg1gW-000633-SS for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:50:09 +0000 Received: by mail-pj1-f65.google.com with SMTP id ga6so991593pjb.1 for ; Tue, 02 Jun 2020 00:50:08 -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=Cf3HGZQ588M+bhzv/Xq8neEezkAxMqWcswrn1g3FnBQ=; b=YNJfh8dc01lOLjCd1DqsmAmZTKO3I3WVWf1rFLqbMNpdc8hm6VU20BLJjxEG0IztLv QpQpy4zEiBbM3ntxMGfExcjGa3G0HubefvBUo8XurHVdTYYIDNjM3zirIwoqVMZSnVY1 NF8xJz7W5a8CVjEWLyJHYKxRx/SsidgqobdjYt++Slna8d9sj5ivVsiNqkOGe2BrqoNk KUO6UoLmCzoo/5m4UunLW949fz0VWMDrX0+vGeuxFDKoL5qaMP+OmicKr+A3xmootwyl WFVSXnMbkJvn/zcCMSfsE0bAQ3vHccnTr3uSGYBcR4wXsV5IwzbFXHH7LSPFPdxG5xim IXQQ== X-Gm-Message-State: AOAM533EU1CGwMSmJeOh/XMUg5kHTqGLlKutKiJkwbsz8/oekp+nOWrv GJUwkfrsh6ijHE18Fk7N4wZlTVFTXLk= X-Google-Smtp-Source: ABdhPJwpCVYXNsSoT7XxwWo9yvs2s71DzE905y1ScurXboURdmPf50ptb5WXppTQkg2qyFG3D4lPSw== X-Received: by 2002:a17:90b:3745:: with SMTP id ne5mr4001992pjb.68.1591084206334; Tue, 02 Jun 2020 00:50:06 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id 3sm1466420pfe.85.2020.06.02.00.50.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:50:05 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 30/42][SRU][U] iommu/exynos: Use first SYSMMU in controllers list for IOMMU core Date: Tue, 2 Jun 2020 15:48:31 +0800 Message-Id: <20200602074843.1743493-31-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 On Exynos platforms there can be more than one SYSMMU (IOMMU) for one DMA master device. Since the IOMMU core code expects only one hardware IOMMU, use the first SYSMMU in the list. Signed-off-by: Joerg Roedel Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200429133712.31431-31-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 66ae88e71ecb93bafaacaeef233971eacd10e749 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/exynos-iommu.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 186ff5cc975c..09cdd163560a 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -1261,6 +1261,11 @@ static int exynos_iommu_add_device(struct device *dev) } iommu_group_put(group); + /* There is always at least one entry, see exynos_iommu_of_xlate() */ + data = list_first_entry(&owner->controllers, + struct sysmmu_drvdata, owner_node); + iommu_device_link(&data->iommu, dev); + return 0; } @@ -1286,6 +1291,11 @@ static void exynos_iommu_remove_device(struct device *dev) list_for_each_entry(data, &owner->controllers, owner_node) device_link_del(data->link); + + /* There is always at least one entry, see exynos_iommu_of_xlate() */ + data = list_first_entry(&owner->controllers, + struct sysmmu_drvdata, owner_node); + iommu_device_unlink(&data->iommu, dev); } static int exynos_iommu_of_xlate(struct device *dev, From patchwork Tue Jun 2 07:48:32 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: 1302225 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 49bkjb3DQRz9sSg; Tue, 2 Jun 2020 17:50:27 +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 1jg1gj-0006EJ-4b; Tue, 02 Jun 2020 07:50:21 +0000 Received: from mail-pg1-f193.google.com ([209.85.215.193]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1gZ-00065D-Dh for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:50:11 +0000 Received: by mail-pg1-f193.google.com with SMTP id r10so4711685pgv.8 for ; Tue, 02 Jun 2020 00:50:11 -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=1vaIa8WH9mrg0+n++vkA2WE5r6DHRDSoxTBXFL2JyC8=; b=Yqq/1yEOX9fWqUDvJdop2wrq0T97jfkTy6MMyN4+0tIJ2/x+0UFXXbXb66RN/vcEID URiXGTtoI6klOiMnfMyCFo67WbfTcN0FQ98iqggPto2iCCKgnUzoX+PnzKtWInlEzrVy 7LynfQOjvhLATlltR6bIgCLYt3wsbZwXO44qLjR9vu7p/XnBDboVShM3CVKfhuys58PB 2ZwSoYNgtSaXj1wDudd8p5qtnbeoD3ExS0edWPPLLrs2o8BHn/erDkEaCfbdKjrDceWg +CeCp21wkUXjqN05G50WN/4T4915eF9jJc8bkXZsssg8ZsK7+Zw+xi1CZnt769IJC4eh ywjA== X-Gm-Message-State: AOAM531T/f1ebsY9MBBhyKiNLM9xA4qXaSlPyvWBIHuc+Rt81IigLD7h aKCn9+926Z8we5qBhn5IPY9Op4fLvYs= X-Google-Smtp-Source: ABdhPJzi/ipS1qeat3IrNWdAoe1DibVvuzzvMgY4J8fguJ5oLRsFcJpdhoX5wTxQKiNDYB1Yo24BuQ== X-Received: by 2002:a63:63c4:: with SMTP id x187mr22018178pgb.112.1591084208668; Tue, 02 Jun 2020 00:50:08 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id l23sm1448685pgc.55.2020.06.02.00.50.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:50:07 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 31/42][SRU][U] iommu/exynos: Convert to probe/release_device() call-backs Date: Tue, 2 Jun 2020 15:48:32 +0800 Message-Id: <20200602074843.1743493-32-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 Convert the Exynos IOMMU driver to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200429133712.31431-32-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 3c51c05479c577ea4235d46366d6181a2d6aff2d linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/exynos-iommu.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 09cdd163560a..60c8a56e4a3f 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -1235,19 +1235,13 @@ static phys_addr_t exynos_iommu_iova_to_phys(struct iommu_domain *iommu_domain, return phys; } -static int exynos_iommu_add_device(struct device *dev) +static struct iommu_device *exynos_iommu_probe_device(struct device *dev) { struct exynos_iommu_owner *owner = dev->archdata.iommu; struct sysmmu_drvdata *data; - struct iommu_group *group; if (!has_sysmmu(dev)) - return -ENODEV; - - group = iommu_group_get_for_dev(dev); - - if (IS_ERR(group)) - return PTR_ERR(group); + return ERR_PTR(-ENODEV); list_for_each_entry(data, &owner->controllers, owner_node) { /* @@ -1259,17 +1253,15 @@ static int exynos_iommu_add_device(struct device *dev) DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME); } - iommu_group_put(group); /* There is always at least one entry, see exynos_iommu_of_xlate() */ data = list_first_entry(&owner->controllers, struct sysmmu_drvdata, owner_node); - iommu_device_link(&data->iommu, dev); - return 0; + return &data->iommu; } -static void exynos_iommu_remove_device(struct device *dev) +static void exynos_iommu_release_device(struct device *dev) { struct exynos_iommu_owner *owner = dev->archdata.iommu; struct sysmmu_drvdata *data; @@ -1287,15 +1279,9 @@ static void exynos_iommu_remove_device(struct device *dev) iommu_group_put(group); } } - iommu_group_remove_device(dev); list_for_each_entry(data, &owner->controllers, owner_node) device_link_del(data->link); - - /* There is always at least one entry, see exynos_iommu_of_xlate() */ - data = list_first_entry(&owner->controllers, - struct sysmmu_drvdata, owner_node); - iommu_device_unlink(&data->iommu, dev); } static int exynos_iommu_of_xlate(struct device *dev, @@ -1341,8 +1327,8 @@ static const struct iommu_ops exynos_iommu_ops = { .unmap = exynos_iommu_unmap, .iova_to_phys = exynos_iommu_iova_to_phys, .device_group = generic_device_group, - .add_device = exynos_iommu_add_device, - .remove_device = exynos_iommu_remove_device, + .probe_device = exynos_iommu_probe_device, + .release_device = exynos_iommu_release_device, .pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE, .of_xlate = exynos_iommu_of_xlate, }; From patchwork Tue Jun 2 07:48:33 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: 1302226 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 49bkjc5k3pz9sSn; Tue, 2 Jun 2020 17:50:28 +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 1jg1gk-0006FP-OH; Tue, 02 Jun 2020 07:50:22 +0000 Received: from mail-pg1-f196.google.com ([209.85.215.196]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1gc-00067G-Dk for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:50:14 +0000 Received: by mail-pg1-f196.google.com with SMTP id p30so4709831pgl.11 for ; Tue, 02 Jun 2020 00:50:14 -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=ZT+g+ln4I02RSJwrjZawxrqwHjRoZOe5oEKEnjDEv/M=; b=IaAzn5lZPvreBWaUVHhCYHq0NwGnES3AfS1Qu5TgXN8+b9cNudl8dXSSNAvWMc5oa0 5CtQiuxzeNev850Sh/4u1WBumrmnDAXHFNRqqEtAWh2gFKiV3n/EMGPDRGMHNNvge+uW ju/hBmy8Zhnc9lo5dV7IOpBcAe9CaUmjeEdH9jTTF5ahUst9UDNVLDDad1YOPvhhutvf u8wu5WnDC1WkpyoMVbHlLAGhtsBBnXG0nv+giV9+LHXecJe4gqyDYKYnALL3N4KcuCFs n4dzCxHfS8fbXo2MeTG2I/jFk+80B563Veba70fkn8AxSwNEuaJ1zYo/ChbG9EztJg7d UhRw== X-Gm-Message-State: AOAM532PdaGxQ/a77amwYhnHDkJCGjAyM80ArTLXGIS134wyE0TbEtaa Nbysf4SMHyHlv9I1bIUlmhwxmTEVt8A= X-Google-Smtp-Source: ABdhPJxWzUjCsrHWWXB/qfCRSP214yygWMT3PQQ2/iMz2veYCid6WyZIqAFclIgBdfGhwToYTSS6+A== X-Received: by 2002:a62:641:: with SMTP id 62mr23877766pfg.283.1591084211053; Tue, 02 Jun 2020 00:50:11 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id i26sm1545311pfo.0.2020.06.02.00.50.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:50:10 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 32/42][SRU][U] iommu: Remove add_device()/remove_device() code-paths Date: Tue, 2 Jun 2020 15:48:33 +0800 Message-Id: <20200602074843.1743493-33-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 All drivers are converted to use the probe/release_device() call-backs, so the add_device/remove_device() pointers are unused and the code using them can be removed. Signed-off-by: Joerg Roedel Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200429133712.31431-33-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 3eeeb45c6d0444b368cdeba9bdafa8bbcf5370d1 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/iommu.c | 158 ++++++++++-------------------------------- include/linux/iommu.h | 4 -- 2 files changed, 38 insertions(+), 124 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 95b8701e191c..5fb10690ec93 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -221,12 +221,20 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list return ret; } -static int __iommu_probe_device_helper(struct device *dev) +int iommu_probe_device(struct device *dev) { const struct iommu_ops *ops = dev->bus->iommu_ops; struct iommu_group *group; int ret; + if (!dev_iommu_get(dev)) + return -ENOMEM; + + if (!try_module_get(ops->owner)) { + ret = -EINVAL; + goto err_out; + } + ret = __iommu_probe_device(dev, NULL); if (ret) goto err_out; @@ -260,75 +268,23 @@ static int __iommu_probe_device_helper(struct device *dev) err_release: iommu_release_device(dev); + err_out: return ret; } -int iommu_probe_device(struct device *dev) +void iommu_release_device(struct device *dev) { const struct iommu_ops *ops = dev->bus->iommu_ops; - struct iommu_group *group; - int ret; - - WARN_ON(dev->iommu_group); - - if (!ops) - return -EINVAL; - - if (!dev_iommu_get(dev)) - return -ENOMEM; - - if (!try_module_get(ops->owner)) { - ret = -EINVAL; - goto err_free_dev_param; - } - - if (ops->probe_device) - return __iommu_probe_device_helper(dev); - - ret = ops->add_device(dev); - if (ret) - goto err_module_put; - group = iommu_group_get(dev); - iommu_create_device_direct_mappings(group, dev); - iommu_group_put(group); - - if (ops->probe_finalize) - ops->probe_finalize(dev); - - return 0; - -err_module_put: - module_put(ops->owner); -err_free_dev_param: - dev_iommu_free(dev); - return ret; -} - -static void __iommu_release_device(struct device *dev) -{ - const struct iommu_ops *ops = dev->bus->iommu_ops; + if (!dev->iommu) + return; iommu_device_unlink(dev->iommu->iommu_dev, dev); - iommu_group_remove_device(dev); ops->release_device(dev); -} - -void iommu_release_device(struct device *dev) -{ - const struct iommu_ops *ops = dev->bus->iommu_ops; - - if (!dev->iommu) - return; - - if (ops->release_device) - __iommu_release_device(dev); - else if (dev->iommu_group) - ops->remove_device(dev); module_put(ops->owner); dev_iommu_free(dev); @@ -1570,23 +1526,6 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev) if (ret) goto out_put_group; - /* - * Try to allocate a default domain - needs support from the - * IOMMU driver. There are still some drivers which don't support - * default domains, so the return value is not yet checked. Only - * allocate the domain here when the driver still has the - * add_device/remove_device call-backs implemented. - */ - if (!ops->probe_device) { - iommu_alloc_default_domain(dev); - - if (group->default_domain) - ret = __iommu_attach_device(group->default_domain, dev); - - if (ret) - goto out_put_group; - } - return group; out_put_group: @@ -1601,21 +1540,6 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group) return group->default_domain; } -static int add_iommu_group(struct device *dev, void *data) -{ - int ret = iommu_probe_device(dev); - - /* - * We ignore -ENODEV errors for now, as they just mean that the - * device is not translated by an IOMMU. We still care about - * other errors and fail to initialize when they happen. - */ - if (ret == -ENODEV) - ret = 0; - - return ret; -} - static int probe_iommu_group(struct device *dev, void *data) { const struct iommu_ops *ops = dev->bus->iommu_ops; @@ -1803,47 +1727,41 @@ static int iommu_group_create_direct_mappings(struct iommu_group *group) int bus_iommu_probe(struct bus_type *bus) { - const struct iommu_ops *ops = bus->iommu_ops; + struct iommu_group *group, *next; + LIST_HEAD(group_list); int ret; - if (ops->probe_device) { - struct iommu_group *group, *next; - LIST_HEAD(group_list); - - /* - * This code-path does not allocate the default domain when - * creating the iommu group, so do it after the groups are - * created. - */ - ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group); - if (ret) - return ret; + /* + * This code-path does not allocate the default domain when + * creating the iommu group, so do it after the groups are + * created. + */ + ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group); + if (ret) + return ret; - list_for_each_entry_safe(group, next, &group_list, entry) { - /* Remove item from the list */ - list_del_init(&group->entry); + list_for_each_entry_safe(group, next, &group_list, entry) { + /* Remove item from the list */ + list_del_init(&group->entry); - mutex_lock(&group->mutex); + mutex_lock(&group->mutex); - /* Try to allocate default domain */ - probe_alloc_default_domain(bus, group); + /* Try to allocate default domain */ + probe_alloc_default_domain(bus, group); - if (!group->default_domain) { - mutex_unlock(&group->mutex); - continue; - } + if (!group->default_domain) { + mutex_unlock(&group->mutex); + continue; + } - iommu_group_create_direct_mappings(group); + iommu_group_create_direct_mappings(group); - ret = __iommu_group_dma_attach(group); + ret = __iommu_group_dma_attach(group); - mutex_unlock(&group->mutex); + mutex_unlock(&group->mutex); - if (ret) - break; - } - } else { - ret = bus_for_each_dev(bus, NULL, NULL, add_iommu_group); + if (ret) + break; } return ret; diff --git a/include/linux/iommu.h b/include/linux/iommu.h index fea1622408ad..dd076366383f 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -223,8 +223,6 @@ struct iommu_iotlb_gather { * @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush * queue * @iova_to_phys: translate iova to physical address - * @add_device: add device to iommu grouping - * @remove_device: remove device from iommu grouping * @probe_device: Add device to iommu driver handling * @release_device: Remove device from iommu driver handling * @probe_finalize: Do final setup work after the device is added to an IOMMU @@ -277,8 +275,6 @@ struct iommu_ops { void (*iotlb_sync)(struct iommu_domain *domain, struct iommu_iotlb_gather *iotlb_gather); phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova); - int (*add_device)(struct device *dev); - void (*remove_device)(struct device *dev); struct iommu_device *(*probe_device)(struct device *dev); void (*release_device)(struct device *dev); void (*probe_finalize)(struct device *dev); From patchwork Tue Jun 2 07:48:34 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: 1302227 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 49bkjf4yvkz9sSd; Tue, 2 Jun 2020 17:50:30 +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 1jg1gm-0006Gf-0f; Tue, 02 Jun 2020 07:50:24 +0000 Received: from mail-pf1-f195.google.com ([209.85.210.195]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1ge-000697-K4 for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:50:16 +0000 Received: by mail-pf1-f195.google.com with SMTP id f3so4671001pfd.11 for ; Tue, 02 Jun 2020 00:50:16 -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=aBDZxZlVd+mIb/fxfT1K+X621b8PPjlP8cDVHN/UHC4=; b=JZo9IO5M7AqEkjR9P/oj5F2tj5e8g4+Wa3iCRu/HPkle0/tgcKuS1lav4tFBTFeRpy eaqY00olWrU60lNyyQliUpluuWL8wVxsTxrPxclSvThWTFGAtyMfVVzz5PsSwq4G5Q5G VqudV22TDerH7l3tC6oiEsrYX+14lVcEYuvfMgYZa6LwEJOYHVaGjr0ylbHPUQth3KBG zX4Gpw3gms4l4FBBKfNDVG91PRPwg+z3WzkuGXNCttrRwk6dIgnaIidDVbZ8yWjXTC03 Ef3lLtW6QjXGpfZucwN6CekxU4FLJj76aQ+i3JdmaxWAyUHiE3gVpbNkcB3FmdMrZ7fR oElA== X-Gm-Message-State: AOAM531hb0GpmEEQh4UGwtzstQYGTJw+wzEPk4ct9PzqRe0bGACy8VXV veHUOGUz23LKURE6ijCjHoA5mLXnUzg= X-Google-Smtp-Source: ABdhPJyFvFWXK2HAgQYui8+87ku+/rTNyIP6CXbX2CpM9mQ3/GbAD+w5U5tsE57JpQbVOo2+8qa+pQ== X-Received: by 2002:a63:5465:: with SMTP id e37mr20040573pgm.300.1591084213365; Tue, 02 Jun 2020 00:50:13 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id z8sm1488689pgc.80.2020.06.02.00.50.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:50:12 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 33/42][SRU][U] iommu: Move more initialization to __iommu_probe_device() Date: Tue, 2 Jun 2020 15:48:34 +0800 Message-Id: <20200602074843.1743493-34-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 Move the calls to dev_iommu_get() and try_module_get() into __iommu_probe_device(), so that the callers don't have to do it on their own. Signed-off-by: Joerg Roedel Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200429133712.31431-34-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 4e8906f0d84d1a7d3cf82a30a701b0fb5d48977c linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/iommu.c | 47 +++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 5fb10690ec93..6bda2ed943c6 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -195,9 +195,19 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list struct iommu_group *group; int ret; + if (!dev_iommu_get(dev)) + return -ENOMEM; + + if (!try_module_get(ops->owner)) { + ret = -EINVAL; + goto err_free; + } + iommu_dev = ops->probe_device(dev); - if (IS_ERR(iommu_dev)) - return PTR_ERR(iommu_dev); + if (IS_ERR(iommu_dev)) { + ret = PTR_ERR(iommu_dev); + goto out_module_put; + } dev->iommu->iommu_dev = iommu_dev; @@ -218,6 +228,12 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list out_release: ops->release_device(dev); +out_module_put: + module_put(ops->owner); + +err_free: + dev_iommu_free(dev); + return ret; } @@ -227,14 +243,6 @@ int iommu_probe_device(struct device *dev) struct iommu_group *group; int ret; - if (!dev_iommu_get(dev)) - return -ENOMEM; - - if (!try_module_get(ops->owner)) { - ret = -EINVAL; - goto err_out; - } - ret = __iommu_probe_device(dev, NULL); if (ret) goto err_out; @@ -1542,14 +1550,10 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group) 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) { @@ -1557,22 +1561,7 @@ static int probe_iommu_group(struct device *dev, void *data) return 0; } - if (!try_module_get(ops->owner)) { - ret = -EINVAL; - goto err_free_dev_iommu; - } - ret = __iommu_probe_device(dev, group_list); - if (ret) - goto err_module_put; - - return 0; - -err_module_put: - module_put(ops->owner); -err_free_dev_iommu: - dev_iommu_free(dev); - if (ret == -ENODEV) ret = 0; From patchwork Tue Jun 2 07:48: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: 1302229 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 49bkjr2mrgz9sSd; Tue, 2 Jun 2020 17:50:40 +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 1jg1gu-0006OQ-PR; Tue, 02 Jun 2020 07:50:32 +0000 Received: from mail-pf1-f196.google.com ([209.85.210.196]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1gg-0006BS-RA for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:50:18 +0000 Received: by mail-pf1-f196.google.com with SMTP id b201so579155pfb.0 for ; Tue, 02 Jun 2020 00:50:18 -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=ZLBR0u/dH6cwhNHx+tr/jXLLwHhzSPE6z8YX3hJuz6k=; b=eFtMInqI22JM0filzLdTYw57mvJGfvAEoL/vN+2dLHh16tRuw9Nh3Izwab2Gx3goUq iv4unJQ5ZjM/yQHLkvZ625ykcuG4AjfPb8GBroKt7hoBafYeS0Oz3S4081piE9KIGOBW PYARk/FazprXE+rMp9UII8UrJlZqoMgdrvLjY98ZuYp6oCEbWVnN02BBWwKdZmvTDNtg fguysCSw4pcl4im7wbWo9z4gEBZe6G4VMCA1I15pUsCMlWTGTZBFvbfsvN0J5Vgu53Cc jPJov4XoOffrQkY08QD7/NJTosPhP6RoiMGp3qe3+jF0fuw/9YlGVDESVjMP3pTLWCNJ UQLA== X-Gm-Message-State: AOAM532Kb4MLb28ImZdR49PtkU5ZyNb3Y8tH6/mzrlBkZgHYAuxVKFQ3 qyfDHrNH1Z0+Jcg4b8tnehprEWB6uIs= X-Google-Smtp-Source: ABdhPJykvuaYPgyt6hOuChzdue141I7xcJETqVZQrpnLCfJ1rF4Ol8zPe0ltZTQhFRGmR5ns6elVWw== X-Received: by 2002:a62:8487:: with SMTP id k129mr21915302pfd.296.1591084216137; Tue, 02 Jun 2020 00:50:16 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id v1sm1483693pjn.9.2020.06.02.00.50.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:50:15 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 34/42][SRU][U] iommu: Unexport iommu_group_get_for_dev() Date: Tue, 2 Jun 2020 15:48:35 +0800 Message-Id: <20200602074843.1743493-35-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 The function is now only used in IOMMU core code and shouldn't be used outside of it anyway, so remove the export for it. Signed-off-by: Joerg Roedel Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200429133712.31431-35-joro@8bytes.org Signed-off-by: Joerg Roedel (backported from commit 1b032ec1ecbce6047af7d11c9db432e237cb17d8 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/iommu.c | 4 ++-- include/linux/iommu.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 6bda2ed943c6..4ea8960c3ef9 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -91,6 +91,7 @@ static void __iommu_detach_group(struct iommu_domain *domain, struct iommu_group *group); static int iommu_create_device_direct_mappings(struct iommu_group *group, struct device *dev); +static struct iommu_group *iommu_group_get_for_dev(struct device *dev); #define IOMMU_GROUP_ATTR(_name, _mode, _show, _store) \ struct iommu_group_attribute iommu_group_attr_##_name = \ @@ -1510,7 +1511,7 @@ static int iommu_alloc_default_domain(struct device *dev) * to the returned IOMMU group, which will already include the provided * device. The reference should be released with iommu_group_put(). */ -struct iommu_group *iommu_group_get_for_dev(struct device *dev) +static struct iommu_group *iommu_group_get_for_dev(struct device *dev) { const struct iommu_ops *ops = dev->bus->iommu_ops; struct iommu_group *group; @@ -1541,7 +1542,6 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev) return ERR_PTR(ret); } -EXPORT_SYMBOL_GPL(iommu_group_get_for_dev); struct iommu_domain *iommu_group_default_domain(struct iommu_group *group) { diff --git a/include/linux/iommu.h b/include/linux/iommu.h index dd076366383f..7cfd2dddb49d 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -527,7 +527,6 @@ extern int iommu_page_response(struct device *dev, struct iommu_page_response *msg); extern int iommu_group_id(struct iommu_group *group); -extern struct iommu_group *iommu_group_get_for_dev(struct device *dev); extern struct iommu_domain *iommu_group_default_domain(struct iommu_group *); extern int iommu_domain_get_attr(struct iommu_domain *domain, enum iommu_attr, From patchwork Tue Jun 2 07:48:36 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: 1302228 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 49bkjm1QxGz9sSg; Tue, 2 Jun 2020 17:50:36 +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 1jg1gs-0006Lu-3y; Tue, 02 Jun 2020 07:50:30 +0000 Received: from mail-pg1-f193.google.com ([209.85.215.193]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1gj-0006DX-KL for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:50:21 +0000 Received: by mail-pg1-f193.google.com with SMTP id u5so4726548pgn.5 for ; Tue, 02 Jun 2020 00:50:21 -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=sQtABtbYiaYFKYeG9UTkNpKbhrCyb9PJKpgHw6+ySSQ=; b=hOsRe8mzOWfQZeEBXJ8nIImYkk53IChs/9F9Y4HUf8o3o46UPHHAr8s9eoDuN1ZYYg pukKPastofyr37Jjbo0im7sVfVG78f+5QJK92/woUorlUXn7/MhPakK9pKa/v80+H5Sq h63lmRqXs3XS7nOm/xKywXEPA2IeWju8HUGvwaKWwbHZPVO3bKH4qlwIvAdMRj0B1dVt iYQXfvBfITeBuYppm99I/gyfqY7kYckfpZYjCxIze2Um07eg2xTc6Wg8nAy5qJfuKUHd 44IEtqhtn8+g7a5G56a2cfx7cmQ8TAV1txRUM07Vtoo+Iv5z79+c1o5verHhqS0p3qa2 /XYg== X-Gm-Message-State: AOAM530dTEO3Xqn70kxc1PONf6QLy9ixiJZqAnqxOuL5+v7KNbGqiiGV nxwZ/r4H5+mGwEqM/Csd49jBgyRHXv8= X-Google-Smtp-Source: ABdhPJyv325+XCCtk9bacd6jGSDgMPpBjYQBUY4Z179lIpAN9ZFE3x0n2oSxlGqBeQ54TKzRoEMlFA== X-Received: by 2002:a63:e004:: with SMTP id e4mr21739690pgh.44.1591084218692; Tue, 02 Jun 2020 00:50:18 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id i3sm1526772pfe.44.2020.06.02.00.50.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:50:17 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 35/42][SRU][U] iommu/amd: Fix variable "iommu" set but not used Date: Tue, 2 Jun 2020 15:48:36 +0800 Message-Id: <20200602074843.1743493-36-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: Qian Cai BugLink: https://bugs.launchpad.net/bugs/1876707 The commit dce8d6964ebd ("iommu/amd: Convert to probe/release_device() call-backs") introduced an unused variable, drivers/iommu/amd_iommu.c: In function 'amd_iommu_uninit_device': drivers/iommu/amd_iommu.c:422:20: warning: variable 'iommu' set but not used [-Wunused-but-set-variable] struct amd_iommu *iommu; ^~~~~ Signed-off-by: Qian Cai Link: https://lore.kernel.org/r/20200509015645.3236-1-cai@lca.pw Fixes: dce8d6964ebd ("iommu/amd: Convert to probe/release_device() call-backs") Signed-off-by: Joerg Roedel (cherry picked from commit cfcccbe8879f79bc9f8a162bcb482c74b8768094 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/amd_iommu.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 3d158239bb67..1b36c40d0712 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -420,15 +420,12 @@ static void iommu_ignore_device(struct device *dev) static void amd_iommu_uninit_device(struct device *dev) { struct iommu_dev_data *dev_data; - struct amd_iommu *iommu; int devid; devid = get_device_id(dev); if (devid < 0) return; - iommu = amd_iommu_rlookup_table[devid]; - dev_data = search_dev_data(devid); if (!dev_data) return; From patchwork Tue Jun 2 07:48:37 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: 1302230 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 49bkjs5mV4z9sSy; Tue, 2 Jun 2020 17:50:41 +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 1jg1gy-0006S6-7D; Tue, 02 Jun 2020 07:50:36 +0000 Received: from mail-pg1-f196.google.com ([209.85.215.196]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1gm-0006FQ-7I for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:50:24 +0000 Received: by mail-pg1-f196.google.com with SMTP id d10so4725166pgn.4 for ; Tue, 02 Jun 2020 00:50:24 -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=lwLm4PFecvW5clVoioH4MiDIk62nQZcq7GrbYI/vvE4=; b=qSTGr/2BG9idbwq98c//KZvIYCatSxnIJFq1QrlaH/fKYpvofgFS+lMV8NGxdx+aM+ sTG3Ut2VL+atzdMddZlDxlMkPg9pfecbg0ulL8UYPPWbP2qqfXEAunNdOJLZhNZ1RTGD t0VeCHgcBUhAmUBHqY22t866DcJtSV+jrIepl7/0eqRECR7XmMbnKQIgjbypW8/KpXhT wyA/uxhNPIaSEYLB2q+RfuW8Og1LT9BtDuSBz8xVnrAOe0gEgmHMJaK18F0AWgq5IwCP aVTsGyW5Aq44vsz8PsXBRNUBOkOjdLA70QPpIJ+5MMnHC1x0Cqyj/+antkUeNqgVK7k6 pRJA== X-Gm-Message-State: AOAM530C82YDaXIgkFnAd10iXZMzBCvO0WtTohFrvYStRzQxM+9z9I8m ZHxQSYsFYZMFufoY3ErJoRpqAN31lFE= X-Google-Smtp-Source: ABdhPJxU8y5NUrG835W2WRnjX0KOBhYIgGZv9R1zTilxV0d5Y6+81VwPy6a8TobRn84il0pKiYl7oA== X-Received: by 2002:a63:e34a:: with SMTP id o10mr22717504pgj.258.1591084221186; Tue, 02 Jun 2020 00:50:21 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id x2sm1679632pfr.186.2020.06.02.00.50.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:50:20 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 36/42][SRU][U] iommu/renesas: Fix unused-function warning Date: Tue, 2 Jun 2020 15:48:37 +0800 Message-Id: <20200602074843.1743493-37-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: Arnd Bergmann BugLink: https://bugs.launchpad.net/bugs/1876707 gcc warns because the only reference to ipmmu_find_group is inside of an #ifdef: drivers/iommu/ipmmu-vmsa.c:878:28: error: 'ipmmu_find_group' defined but not used [-Werror=unused-function] Change the #ifdef to an equivalent IS_ENABLED(). Fixes: 6580c8a78424 ("iommu/renesas: Convert to probe/release_device() call-backs") Signed-off-by: Arnd Bergmann Reviewed-by: Simon Horman Link: https://lore.kernel.org/r/20200508220224.688985-1-arnd@arndb.de Signed-off-by: Joerg Roedel (cherry picked from commit 2ba20b5a5b8f948d498f4b38ba910ff339e609ef linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/ipmmu-vmsa.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index fb7e702dee23..4c2972f3153b 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -903,11 +903,8 @@ static const struct iommu_ops ipmmu_ops = { .probe_device = ipmmu_probe_device, .release_device = ipmmu_release_device, .probe_finalize = ipmmu_probe_finalize, -#if defined(CONFIG_ARM) && !defined(CONFIG_IOMMU_DMA) - .device_group = generic_device_group, -#else - .device_group = ipmmu_find_group, -#endif + .device_group = IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_IOMMU_DMA) + ? generic_device_group : ipmmu_find_group, .pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K, .of_xlate = ipmmu_of_xlate, }; From patchwork Tue Jun 2 07:48:38 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: 1302232 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 49bkk11hRMz9sSn; Tue, 2 Jun 2020 17:50:49 +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 1jg1h5-0006Y8-Eb; Tue, 02 Jun 2020 07:50:43 +0000 Received: from mail-pj1-f68.google.com ([209.85.216.68]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1gq-0006Hg-1d for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:50:28 +0000 Received: by mail-pj1-f68.google.com with SMTP id s88so1049041pjb.5 for ; Tue, 02 Jun 2020 00:50:27 -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=T2PjLHFoDYrdCmt/PA6ZbcVSWISmEJ9ohQjDo9fObYQ=; b=GrXrU6hPqJQ/f/+8ff6ViRb+lMJ7CXaEsh4CHMotwnCAacuZiixa/O0/MmC7VwEPbp C64v/fVG7MlaI9tdD3sKiyn/LkmD6UBwUhbufpyN0mMPLfyg0vkcwuHYScROuTDptJiJ osvLZHVAeVxPFtdQ3+FYr4Esgb9Z0Nmc0tsQkkXr/PrWnW7IkVD1N6LWZDu16jR1t+4L o6GdEXqKU2ZDJcrwzUDJOrrletEmpT06/DIxMmJGs/B644QaQfuJQWBP4Xq4z1yNBxXG LNfzVCzxFPTn1uwDc/5cAumI71ZGsGZ29YRi5J8xOEbRbuYFLpukH+rPu9XgTdzq9/xO hShQ== X-Gm-Message-State: AOAM533RT0j7B85qb9clz4Iniq3U3Jpk4QZirFDR5Sn/hx37UZ1OuGcZ 88HapuZmYln0Yh2srHrmAiuK9AKLLTg= X-Google-Smtp-Source: ABdhPJz3DwhRmiplyhbV6FDngwXEK1iiD9TEa0Bfq14Nyo48tiOXTdbvrjohQaugZIIhQD6tPPIPwg== X-Received: by 2002:a17:90a:df82:: with SMTP id p2mr3984853pjv.217.1591084223596; Tue, 02 Jun 2020 00:50:23 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id l187sm1442738pfl.218.2020.06.02.00.50.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:50:22 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 37/42][SRU][U] iommu/omap: Add check for iommu group when no IOMMU in use Date: Tue, 2 Jun 2020 15:48:38 +0800 Message-Id: <20200602074843.1743493-38-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: Tero Kristo via iommu BugLink: https://bugs.launchpad.net/bugs/1876707 Most of the devices in OMAP family of SoCs are not using IOMMU. The patch for converting the OMAP IOMMU to use generic IOMMU bus probe functionality failed to add a check for this, so add it here. Fixes: c822b37cac48 ("iommu/omap: Remove orphan_dev tracking") Reported-by: Tomi Valkeinen Signed-off-by: Tero Kristo Link: https://lore.kernel.org/r/20200518111057.23140-1-t-kristo@ti.com Signed-off-by: Joerg Roedel (cherry picked from commit 46b14fc61bfa409efe95a7752a5dba361d753c66 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/omap-iommu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index 6699fe6d9e06..5a9ba815863b 100644 --- a/drivers/iommu/omap-iommu.c +++ b/drivers/iommu/omap-iommu.c @@ -1726,6 +1726,9 @@ static struct iommu_group *omap_iommu_device_group(struct device *dev) struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; struct iommu_group *group = ERR_PTR(-EINVAL); + if (!arch_data) + return ERR_PTR(-ENODEV); + if (arch_data->iommu_dev) group = iommu_group_ref_get(arch_data->iommu_dev->group); From patchwork Tue Jun 2 07:48:39 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: 1302231 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 49bkjy200Fz9sSd; Tue, 2 Jun 2020 17:50:46 +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 1jg1h2-0006VP-31; Tue, 02 Jun 2020 07:50:40 +0000 Received: from mail-pg1-f193.google.com ([209.85.215.193]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1gq-0006Jr-R3 for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:50:28 +0000 Received: by mail-pg1-f193.google.com with SMTP id w20so4718061pga.6 for ; Tue, 02 Jun 2020 00:50:28 -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=1gm2g8fvkQpCWwJe74mBCcW6He1KkH1H8csmZ4ZjqJU=; b=MLv2aPeJos8uuElK7rtUvBUgl+smYVboNQe9RMIrGPRWdeC2/12liXQE4tZ37lEtPt dPabHnYKBAmm9cIjxnEjjiXiqG09RkpyEV5snwXKjrbl8MIkDFBS4zCjln6/zKgLi1aF h5SESkpszj2sBg8ePuDOl6sAzj+MZhLzb5wpk3NfAzvK2EDAtLEGdfvZJR+tIT/yRy2Y m13hmtO/yvAck3G/++OVIo78NWv4ZmbpO/PCqAFisCE5WtIhFyTP5BOxchoUxqhV8B94 tZIHlo5qOFgBlMzEdML2uAlP51SX5p7CbdV5o7Ynhn4mdQIaV48iEUUTq0W41+cvhZLj /ZmQ== X-Gm-Message-State: AOAM532eD4oWKm+/8HLz9Yd+7wJ/Vf3Vzz9GViKoKLZjAlWIm4hdSOvG 04LFXUmK6V6ZOUDFITp3LM6yw+twK+A= X-Google-Smtp-Source: ABdhPJwO8vuTAP51KQwAp2JC+VJsaQSl15EglyuZr3TUxuTvo/8a9NMnFYBis6hb8Je2x284g5FMbA== X-Received: by 2002:a63:3c17:: with SMTP id j23mr22247851pga.343.1591084226491; Tue, 02 Jun 2020 00:50: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 c8sm1585599pjn.16.2020.06.02.00.50.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:50:25 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 38/42][SRU][U] iommu: Don't call .probe_finalize() under group->mutex Date: Tue, 2 Jun 2020 15:48:39 +0800 Message-Id: <20200602074843.1743493-39-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 The .probe_finalize() call-back of some IOMMU drivers calls into arm_iommu_attach_device(). This function will call back into the IOMMU core code, where it tries to take group->mutex again, resulting in a deadlock. As there is no reason why .probe_finalize() needs to be called under that mutex, move it after the lock has been released to fix the deadlock. Fixes: deac0b3bed26 ("iommu: Split off default domain allocation from group assignment") Reported-by: Yong Wu Signed-off-by: Joerg Roedel Cc: Yong Wu Link: https://lore.kernel.org/r/20200519132824.15163-1-joro@8bytes.org (cherry picked from commit 8350a49c2ef8aa166e498595e68ef3833fd74e55 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/iommu.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 4ea8960c3ef9..a09e9b08c216 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1680,17 +1680,8 @@ static void probe_alloc_default_domain(struct bus_type *bus, static int iommu_group_do_dma_attach(struct device *dev, void *data) { struct iommu_domain *domain = data; - const struct iommu_ops *ops; - int ret; - - ret = __iommu_attach_device(domain, dev); - - ops = domain->ops; - - if (ret == 0 && ops->probe_finalize) - ops->probe_finalize(dev); - return ret; + return __iommu_attach_device(domain, dev); } static int __iommu_group_dma_attach(struct iommu_group *group) @@ -1699,6 +1690,21 @@ static int __iommu_group_dma_attach(struct iommu_group *group) iommu_group_do_dma_attach); } +static int iommu_group_do_probe_finalize(struct device *dev, void *data) +{ + struct iommu_domain *domain = data; + + if (domain->ops->probe_finalize) + domain->ops->probe_finalize(dev); + + return 0; +} + +static void __iommu_group_dma_finalize(struct iommu_group *group) +{ + __iommu_group_for_each_dev(group, group->default_domain, + iommu_group_do_probe_finalize); +} static int iommu_do_create_direct_mappings(struct device *dev, void *data) { struct iommu_group *group = data; @@ -1751,6 +1757,8 @@ int bus_iommu_probe(struct bus_type *bus) if (ret) break; + + __iommu_group_dma_finalize(group); } return ret; From patchwork Tue Jun 2 07:48:40 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: 1302233 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 49bkk36x7Rz9sSg; Tue, 2 Jun 2020 17:50:51 +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 1jg1h8-0006af-JZ; Tue, 02 Jun 2020 07:50:46 +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 1jg1gu-0006Mp-5O for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:50:32 +0000 Received: by mail-pj1-f65.google.com with SMTP id s88so1049159pjb.5 for ; Tue, 02 Jun 2020 00:50:32 -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=zGvhib7XUb0/P7/3zN6SzpLGo8G3SQ45nYX3jGs64LQ=; b=mCYbYR56+jbgi6tuOG103KN1K2WEnZaJ+RoifCbwb+hV8iOI8LiwdqbmBDw9Q3QP4h oBPNTzgf4CFr6yqd2XVC768dKPyrW2vMOVvCWh2hynrhBPQj8fEfW3ZeCFUpV+e9Voix IUicp+mptBQqhtWX7Uf7oGdXZ6kDtFUTcRlYsCcnVa6eZQUC/IM2ATAxBL9pkg4bQGT6 ykV4g9tv5PV+38TTV4e1BMHDhMn9lrjl9ILvq5PbtnU1htd/WqP5oPaH77yZ6GMzA0nm S4Ugt77k/nE6SG9chjQmargu572exo5vriMv1MwWFfJe8GJtBcGpu8BkokVLx6pw18o0 OGKw== X-Gm-Message-State: AOAM531lIsYujHlmCRzSCiJVA7N468rOhhm1UtyDsfxAX2+WjBE7ieay w1t7OiuN7NX59/83TN8Ahan88k8WJYU= X-Google-Smtp-Source: ABdhPJzKyOTj0R0OmS999bdcikuzjxbxXm9KwQHWEaRBYH7+4COanD8nB+cMJi7RgU8Kc75zHE2bGg== X-Received: by 2002:a17:90a:390c:: with SMTP id y12mr4132041pjb.87.1591084229368; Tue, 02 Jun 2020 00:50:29 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id m12sm1541704pjs.41.2020.06.02.00.50.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:50:28 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 39/42][SRU][U] iommu/vt-d: Allow 32bit devices to uses DMA domain Date: Tue, 2 Jun 2020 15:48:40 +0800 Message-Id: <20200602074843.1743493-40-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: Lu Baolu BugLink: https://bugs.launchpad.net/bugs/1876707 Currently, if a 32bit device initially uses an identity domain, Intel IOMMU driver will convert it forcibly to a DMA one if its address capability is not enough for the whole system memory. The motivation was to overcome the overhead caused by possible bounced buffer. Unfortunately, this improvement has led to many problems. For example, some 32bit devices are required to use an identity domain, forcing them to use DMA domain will cause the device not to work anymore. On the other hand, the VMD sub-devices share a domain but each sub-device might have different address capability. Forcing a VMD sub-device to use DMA domain blindly will impact the operation of other sub-devices without any notification. Further more, PCI aliased devices (PCI bridge and all devices beneath it, VMD devices and various devices quirked with pci_add_dma_alias()) must use the same domain. Forcing one device to switch to DMA domain during runtime will cause in-fligh DMAs for other devices to abort or target to other memory which might cause undefind system behavior. With the last private domain usage in iommu_need_mapping() removed, all private domain helpers are also cleaned in this patch. Otherwise, the compiler will complain that some functions are defined but not used. Signed-off-by: Lu Baolu Tested-by: Daniel Drake Reviewed-by: Jon Derrick Reviewed-by: Jerry Snitselaar Cc: Daniel Drake Cc: Derrick Jonathan Cc: Jerry Snitselaar Link: https://lore.kernel.org/r/20200506015947.28662-2-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel (cherry picked from commit 327d5b2fee91c404a3956c324193892cf2cc9528 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/intel-iommu.c | 291 +----------------------------------- 1 file changed, 1 insertion(+), 290 deletions(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 34e08fa2ce3a..16ba7add0f72 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -355,11 +355,6 @@ static void domain_exit(struct dmar_domain *domain); static void domain_remove_dev_info(struct dmar_domain *domain); static void dmar_remove_one_dev_info(struct device *dev); static void __dmar_remove_one_dev_info(struct device_domain_info *info); -static void domain_context_clear(struct intel_iommu *iommu, - struct device *dev); -static int domain_detach_iommu(struct dmar_domain *domain, - struct intel_iommu *iommu); -static bool device_is_rmrr_locked(struct device *dev); static int intel_iommu_attach_device(struct iommu_domain *domain, struct device *dev); static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain, @@ -1930,65 +1925,6 @@ static inline int guestwidth_to_adjustwidth(int gaw) return agaw; } -static int domain_init(struct dmar_domain *domain, struct intel_iommu *iommu, - int guest_width) -{ - int adjust_width, agaw; - unsigned long sagaw; - int ret; - - init_iova_domain(&domain->iovad, VTD_PAGE_SIZE, IOVA_START_PFN); - - if (!intel_iommu_strict) { - ret = init_iova_flush_queue(&domain->iovad, - iommu_flush_iova, iova_entry_free); - if (ret) - pr_info("iova flush queue initialization failed\n"); - } - - domain_reserve_special_ranges(domain); - - /* calculate AGAW */ - if (guest_width > cap_mgaw(iommu->cap)) - guest_width = cap_mgaw(iommu->cap); - domain->gaw = guest_width; - adjust_width = guestwidth_to_adjustwidth(guest_width); - agaw = width_to_agaw(adjust_width); - sagaw = cap_sagaw(iommu->cap); - if (!test_bit(agaw, &sagaw)) { - /* hardware doesn't support it, choose a bigger one */ - pr_debug("Hardware doesn't support agaw %d\n", agaw); - agaw = find_next_bit(&sagaw, 5, agaw); - if (agaw >= 5) - return -ENODEV; - } - domain->agaw = agaw; - - if (ecap_coherent(iommu->ecap)) - domain->iommu_coherency = 1; - else - domain->iommu_coherency = 0; - - if (ecap_sc_support(iommu->ecap)) - domain->iommu_snooping = 1; - else - domain->iommu_snooping = 0; - - if (intel_iommu_superpage) - domain->iommu_superpage = fls(cap_super_page_val(iommu->cap)); - else - domain->iommu_superpage = 0; - - domain->nid = iommu->node; - - /* always allocate the top pgd */ - domain->pgd = (struct dma_pte *)alloc_pgtable_page(domain->nid); - if (!domain->pgd) - return -ENOMEM; - __iommu_flush_cache(iommu, domain->pgd, PAGE_SIZE); - return 0; -} - static void domain_exit(struct dmar_domain *domain) { @@ -2704,94 +2640,6 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu, return domain; } -static int get_last_alias(struct pci_dev *pdev, u16 alias, void *opaque) -{ - *(u16 *)opaque = alias; - return 0; -} - -static struct dmar_domain *find_or_alloc_domain(struct device *dev, int gaw) -{ - struct device_domain_info *info; - struct dmar_domain *domain = NULL; - struct intel_iommu *iommu; - u16 dma_alias; - unsigned long flags; - u8 bus, devfn; - - iommu = device_to_iommu(dev, &bus, &devfn); - if (!iommu) - return NULL; - - if (dev_is_pci(dev)) { - struct pci_dev *pdev = to_pci_dev(dev); - - pci_for_each_dma_alias(pdev, get_last_alias, &dma_alias); - - spin_lock_irqsave(&device_domain_lock, flags); - info = dmar_search_domain_by_dev_info(pci_domain_nr(pdev->bus), - PCI_BUS_NUM(dma_alias), - dma_alias & 0xff); - if (info) { - iommu = info->iommu; - domain = info->domain; - } - spin_unlock_irqrestore(&device_domain_lock, flags); - - /* DMA alias already has a domain, use it */ - if (info) - goto out; - } - - /* Allocate and initialize new domain for the device */ - domain = alloc_domain(0); - if (!domain) - return NULL; - if (domain_init(domain, iommu, gaw)) { - domain_exit(domain); - return NULL; - } - -out: - return domain; -} - -static struct dmar_domain *set_domain_for_dev(struct device *dev, - struct dmar_domain *domain) -{ - struct intel_iommu *iommu; - struct dmar_domain *tmp; - u16 req_id, dma_alias; - u8 bus, devfn; - - iommu = device_to_iommu(dev, &bus, &devfn); - if (!iommu) - return NULL; - - req_id = ((u16)bus << 8) | devfn; - - if (dev_is_pci(dev)) { - struct pci_dev *pdev = to_pci_dev(dev); - - pci_for_each_dma_alias(pdev, get_last_alias, &dma_alias); - - /* register PCI DMA alias device */ - if (req_id != dma_alias) { - tmp = dmar_insert_one_dev_info(iommu, PCI_BUS_NUM(dma_alias), - dma_alias & 0xff, NULL, domain); - - if (!tmp || tmp != domain) - return tmp; - } - } - - tmp = dmar_insert_one_dev_info(iommu, bus, devfn, dev, domain); - if (!tmp || tmp != domain) - return tmp; - - return domain; -} - static int iommu_domain_identity_map(struct dmar_domain *domain, unsigned long long start, unsigned long long end) @@ -2817,45 +2665,6 @@ static int iommu_domain_identity_map(struct dmar_domain *domain, DMA_PTE_READ|DMA_PTE_WRITE); } -static int domain_prepare_identity_map(struct device *dev, - struct dmar_domain *domain, - unsigned long long start, - unsigned long long end) -{ - /* For _hardware_ passthrough, don't bother. But for software - passthrough, we do it anyway -- it may indicate a memory - range which is reserved in E820, so which didn't get set - up to start with in si_domain */ - if (domain == si_domain && hw_pass_through) { - dev_warn(dev, "Ignoring identity map for HW passthrough [0x%Lx - 0x%Lx]\n", - start, end); - return 0; - } - - dev_info(dev, "Setting identity map [0x%Lx - 0x%Lx]\n", start, end); - - if (end < start) { - WARN(1, "Your BIOS is broken; RMRR ends before it starts!\n" - "BIOS vendor: %s; Ver: %s; Product Version: %s\n", - dmi_get_system_info(DMI_BIOS_VENDOR), - dmi_get_system_info(DMI_BIOS_VERSION), - dmi_get_system_info(DMI_PRODUCT_VERSION)); - return -EIO; - } - - if (end >> agaw_to_width(domain->agaw)) { - WARN(1, "Your BIOS is broken; RMRR exceeds permitted address width (%d bits)\n" - "BIOS vendor: %s; Ver: %s; Product Version: %s\n", - agaw_to_width(domain->agaw), - dmi_get_system_info(DMI_BIOS_VENDOR), - dmi_get_system_info(DMI_BIOS_VERSION), - dmi_get_system_info(DMI_PRODUCT_VERSION)); - return -EIO; - } - - return iommu_domain_identity_map(domain, start, end); -} - static int md_domain_init(struct dmar_domain *domain, int guest_width); static int __init si_domain_init(int hw) @@ -3531,98 +3340,16 @@ static unsigned long intel_alloc_iova(struct device *dev, return iova_pfn; } -static struct dmar_domain *get_private_domain_for_dev(struct device *dev) -{ - struct dmar_domain *domain, *tmp; - struct dmar_rmrr_unit *rmrr; - struct device *i_dev; - int i, ret; - - /* Device shouldn't be attached by any domains. */ - domain = find_domain(dev); - if (domain) - return NULL; - - domain = find_or_alloc_domain(dev, DEFAULT_DOMAIN_ADDRESS_WIDTH); - if (!domain) - goto out; - - /* We have a new domain - setup possible RMRRs for the device */ - rcu_read_lock(); - for_each_rmrr_units(rmrr) { - for_each_active_dev_scope(rmrr->devices, rmrr->devices_cnt, - i, i_dev) { - if (i_dev != dev) - continue; - - ret = domain_prepare_identity_map(dev, domain, - rmrr->base_address, - rmrr->end_address); - if (ret) - dev_err(dev, "Mapping reserved region failed\n"); - } - } - rcu_read_unlock(); - - tmp = set_domain_for_dev(dev, domain); - if (!tmp || domain != tmp) { - domain_exit(domain); - domain = tmp; - } - -out: - if (!domain) - dev_err(dev, "Allocating domain failed\n"); - else - domain->domain.type = IOMMU_DOMAIN_DMA; - - return domain; -} - /* Check if the dev needs to go through non-identity map and unmap process.*/ static bool iommu_need_mapping(struct device *dev) { - int ret; - if (iommu_dummy(dev)) return false; if (unlikely(attach_deferred(dev))) do_deferred_attach(dev); - ret = identity_mapping(dev); - if (ret) { - u64 dma_mask = *dev->dma_mask; - - if (dev->coherent_dma_mask && dev->coherent_dma_mask < dma_mask) - dma_mask = dev->coherent_dma_mask; - - if (dma_mask >= dma_direct_get_required_mask(dev)) - return false; - - /* - * 32 bit DMA is removed from si_domain and fall back to - * non-identity mapping. - */ - dmar_remove_one_dev_info(dev); - ret = iommu_request_dma_domain_for_dev(dev); - if (ret) { - struct iommu_domain *domain; - struct dmar_domain *dmar_domain; - - domain = iommu_get_domain_for_dev(dev); - if (domain) { - dmar_domain = to_dmar_domain(domain); - dmar_domain->flags |= DOMAIN_FLAG_LOSE_CHILDREN; - } - dmar_remove_one_dev_info(dev); - get_private_domain_for_dev(dev); - } - - dev_info(dev, "32bit DMA uses non-identity mapping\n"); - } - - return true; + return !identity_mapping(dev); } static dma_addr_t __intel_map_single(struct device *dev, phys_addr_t paddr, @@ -5186,16 +4913,6 @@ int __init intel_iommu_init(void) } up_write(&dmar_global_lock); -#if defined(CONFIG_X86) && defined(CONFIG_SWIOTLB) - /* - * If the system has no untrusted device or the user has decided - * to disable the bounce page mechanisms, we don't need swiotlb. - * Mark this and the pre-allocated bounce pages will be released - * later. - */ - if (!has_untrusted_dev() || intel_no_bounce) - swiotlb = 0; -#endif dma_ops = &intel_dma_ops; init_iommu_pm_ops(); @@ -5296,12 +5013,6 @@ static void __dmar_remove_one_dev_info(struct device_domain_info *info) domain_detach_iommu(domain, iommu); spin_unlock_irqrestore(&iommu->lock, flags); - /* free the private domain */ - if (domain->flags & DOMAIN_FLAG_LOSE_CHILDREN && - !(domain->flags & DOMAIN_FLAG_STATIC_IDENTITY) && - list_empty(&domain->devices)) - domain_exit(info->domain); - free_devinfo_mem(info); } From patchwork Tue Jun 2 07:48:41 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: 1302235 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 49bkk74hk7z9sSn; Tue, 2 Jun 2020 17:50:55 +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 1jg1hC-0006ep-Ps; Tue, 02 Jun 2020 07:50:50 +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 1jg1gx-0006P2-KU for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:50:35 +0000 Received: by mail-pj1-f67.google.com with SMTP id k2so990221pjs.2 for ; Tue, 02 Jun 2020 00:50: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=xOn6df/hyY0n9QuyTU7+KsKkmsPuumwdkCUonc2sBxc=; b=auOnaOxHRi0eeKemryrYnztL6IiLW9M6o2Y0GFpwtjfsv6zrn2PlEeLoIerwZ/3iet t+bhxjgUy93hMo3hOD+gNqpFSqEphYhLtc0KyUSNxpHQZ9orvcHuPRmFIlEBZeLpVefd XQIm8J1nRDiZKwOHmdCgvNuK44LGcxBEhaq2fnitWJM7q2HtH0DEg0r81AqCzGQj/nc6 pLOnFRNgqpIgcbMjGNMz9itiJg2OSAk+A437JKmNL07AcqGxAJyZpQrZnQ8DZk8lCUQt 6bFtsAshL7zUUx49pBSQye2Kt/tb3peE4JPzLHB3Q9w8kVV4IVgr27PhJC2+wqspzCqR szPA== X-Gm-Message-State: AOAM531AHrYSEiA7w3kdz6bbuYmLJs87IGWdDV0kKTkQmRaZuYQJAivw yq3SFyyjvZ57At7WieW2k68gf9v9HJE= X-Google-Smtp-Source: ABdhPJxuX3F1kYWS4K2l+b6k6T2kiGtVonmFQxEMv46yk70/GJ8qMyZpg+5sv0TGK8EniTdVOlpBtw== X-Received: by 2002:a17:90b:e0c:: with SMTP id ge12mr4130641pjb.3.1591084231707; Tue, 02 Jun 2020 00:50:31 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id d15sm2054085pjc.0.2020.06.02.00.50.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:50:30 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 40/42][SRU][U] iommu/vt-d: Allow PCI sub-hierarchy to use DMA domain Date: Tue, 2 Jun 2020 15:48:41 +0800 Message-Id: <20200602074843.1743493-41-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: Lu Baolu BugLink: https://bugs.launchpad.net/bugs/1876707 Before commit fa954e6831789 ("iommu/vt-d: Delegate the dma domain to upper layer"), Intel IOMMU started off with all devices in the identity domain, and took them out later if it found they couldn't access all of memory. This required devices behind a PCI bridge to use a DMA domain at the beginning because all PCI devices behind the bridge use the same source-id in their transactions and the domain couldn't be changed at run-time. Intel IOMMU driver is now aligned with the default domain framework, there's no need to keep this requirement anymore. Signed-off-by: Lu Baolu Tested-by: Daniel Drake Reviewed-by: Jon Derrick Reviewed-by: Jerry Snitselaar Link: https://lore.kernel.org/r/20200506015947.28662-3-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel (cherry picked from commit 14b3526d5909f01e1d1baa05f50952788bb7418e linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/intel-iommu.c | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 16ba7add0f72..af309e8fa6f5 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -2857,31 +2857,6 @@ static int device_def_domain_type(struct device *dev) if ((iommu_identity_mapping & IDENTMAP_GFX) && IS_GFX_DEVICE(pdev)) return IOMMU_DOMAIN_IDENTITY; - - /* - * We want to start off with all devices in the 1:1 domain, and - * take them out later if we find they can't access all of memory. - * - * However, we can't do this for PCI devices behind bridges, - * because all PCI devices behind the same bridge will end up - * with the same source-id on their transactions. - * - * Practically speaking, we can't change things around for these - * devices at run-time, because we can't be sure there'll be no - * DMA transactions in flight for any of their siblings. - * - * So PCI devices (unless they're on the root bus) as well as - * their parent PCI-PCI or PCIe-PCI bridges must be left _out_ of - * the 1:1 domain, just in _case_ one of their siblings turns out - * not to be able to map all of memory. - */ - if (!pci_is_pcie(pdev)) { - if (!pci_is_root_bus(pdev->bus)) - return IOMMU_DOMAIN_DMA; - if (pdev->class >> 8 == PCI_CLASS_BRIDGE_PCI) - return IOMMU_DOMAIN_DMA; - } else if (pci_pcie_type(pdev) == PCI_EXP_TYPE_PCI_BRIDGE) - return IOMMU_DOMAIN_DMA; } return 0; From patchwork Tue Jun 2 07:48:42 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: 1302237 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 49bkk93jqDz9sT2; Tue, 2 Jun 2020 17:50:57 +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 1jg1hF-0006h4-02; Tue, 02 Jun 2020 07:50:53 +0000 Received: from mail-pg1-f196.google.com ([209.85.215.196]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1gz-0006RV-5R for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:50:37 +0000 Received: by mail-pg1-f196.google.com with SMTP id e9so3545069pgo.9 for ; Tue, 02 Jun 2020 00:50:36 -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=rN3X7jduY+uMz/tidsIgZo3Vp94/bCh3GKjUB5BDsTI=; b=S0+9nI6yGwhWq7rTA4il+XJDlQRuoAE8euSs+DpuvhGN0/dSZeWiUhmLcEAGy2s6iJ 6zSsmBrnq0SmRcdkL+bElwl/SaQ+SdAeBjyV+9u7WuW2eYFP9gQ77cPbdmf1iDE/joH1 pr7vhHzW3q2vcYhnz7owpze7ZmE76DffPJPEHUOdIQgukcCJQh3+3CXbDpyzM8AmGnIW wspb5rvNAxqcm/FqNqSRV9nnYeiEdHfop9/FTJGJ3bc+3F1zlCSWk/Q+OjfYV4dEqvF/ hOO3nAJLPoT9gMETAw+CkdhbZc58UGDR49p+Q8yN4dTv1AFEDvAw+DJ3EplQCgpuec+W jNgA== X-Gm-Message-State: AOAM530XOhXBLnr9GWIY+e/9yTw59+zeKHVDTiJIyjnnyHcCNSB8S8wj zictfo9uHQeFIYT4lwE3MrdBpgMBbcM= X-Google-Smtp-Source: ABdhPJycVU32jqVt4yEsrqWmcrSoBRKhnDyylAIzsEs57VcwB2QWvQ7lXyaepDffHOX6TyuTnqDn6Q== X-Received: by 2002:a65:56ca:: with SMTP id w10mr22860470pgs.69.1591084234140; Tue, 02 Jun 2020 00:50:34 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id ft10sm1507947pjb.40.2020.06.02.00.50.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:50:33 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 41/42][SRU][U] iommu/vt-d: Apply per-device dma_ops Date: Tue, 2 Jun 2020 15:48:42 +0800 Message-Id: <20200602074843.1743493-42-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: Lu Baolu BugLink: https://bugs.launchpad.net/bugs/1876707 Current Intel IOMMU driver sets the system level dma_ops. This causes each dma API to go through the IOMMU driver even the devices are using identity mapped domains. This sets per-device dma_ops only if a device is using a DMA domain. Otherwise, use the default system level dma_ops for direct dma. Signed-off-by: Lu Baolu Tested-by: Daniel Drake Reviewed-by: Jon Derrick Reviewed-by: Jerry Snitselaar Link: https://lore.kernel.org/r/20200506015947.28662-4-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel (cherry picked from commit 6fc7020cf298aaec343df423746b44d99c6efaa5 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/intel-iommu.c | 82 ++++++++++++------------------------- 1 file changed, 26 insertions(+), 56 deletions(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index af309e8fa6f5..29d3940847d3 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -2720,17 +2720,6 @@ static int __init si_domain_init(int hw) return 0; } -static int identity_mapping(struct device *dev) -{ - struct device_domain_info *info; - - info = dev->archdata.iommu; - if (info) - return (info->domain == si_domain); - - return 0; -} - static int domain_add_dev_info(struct dmar_domain *domain, struct device *dev) { struct dmar_domain *ndomain; @@ -3315,18 +3304,6 @@ static unsigned long intel_alloc_iova(struct device *dev, return iova_pfn; } -/* Check if the dev needs to go through non-identity map and unmap process.*/ -static bool iommu_need_mapping(struct device *dev) -{ - if (iommu_dummy(dev)) - return false; - - if (unlikely(attach_deferred(dev))) - do_deferred_attach(dev); - - return !identity_mapping(dev); -} - static dma_addr_t __intel_map_single(struct device *dev, phys_addr_t paddr, size_t size, int dir, u64 dma_mask) { @@ -3340,6 +3317,9 @@ static dma_addr_t __intel_map_single(struct device *dev, phys_addr_t paddr, BUG_ON(dir == DMA_NONE); + if (unlikely(attach_deferred(dev))) + do_deferred_attach(dev); + domain = find_domain(dev); if (!domain) return DMA_MAPPING_ERROR; @@ -3391,20 +3371,15 @@ static dma_addr_t intel_map_page(struct device *dev, struct page *page, enum dma_data_direction dir, unsigned long attrs) { - if (iommu_need_mapping(dev)) - return __intel_map_single(dev, page_to_phys(page) + offset, - size, dir, *dev->dma_mask); - return dma_direct_map_page(dev, page, offset, size, dir, attrs); + return __intel_map_single(dev, page_to_phys(page) + offset, + size, dir, *dev->dma_mask); } static dma_addr_t intel_map_resource(struct device *dev, phys_addr_t phys_addr, size_t size, enum dma_data_direction dir, unsigned long attrs) { - if (iommu_need_mapping(dev)) - return __intel_map_single(dev, phys_addr, size, dir, - *dev->dma_mask); - return dma_direct_map_resource(dev, phys_addr, size, dir, attrs); + return __intel_map_single(dev, phys_addr, size, dir, *dev->dma_mask); } static void intel_unmap(struct device *dev, dma_addr_t dev_addr, size_t size) @@ -3455,17 +3430,13 @@ static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr, size_t size, enum dma_data_direction dir, unsigned long attrs) { - if (iommu_need_mapping(dev)) - intel_unmap(dev, dev_addr, size); - else - dma_direct_unmap_page(dev, dev_addr, size, dir, attrs); + intel_unmap(dev, dev_addr, size); } static void intel_unmap_resource(struct device *dev, dma_addr_t dev_addr, size_t size, enum dma_data_direction dir, unsigned long attrs) { - if (iommu_need_mapping(dev)) - intel_unmap(dev, dev_addr, size); + intel_unmap(dev, dev_addr, size); } static void *intel_alloc_coherent(struct device *dev, size_t size, @@ -3475,8 +3446,8 @@ static void *intel_alloc_coherent(struct device *dev, size_t size, struct page *page = NULL; int order; - if (!iommu_need_mapping(dev)) - return dma_direct_alloc(dev, size, dma_handle, flags, attrs); + if (unlikely(attach_deferred(dev))) + do_deferred_attach(dev); size = PAGE_ALIGN(size); order = get_order(size); @@ -3511,9 +3482,6 @@ static void intel_free_coherent(struct device *dev, size_t size, void *vaddr, int order; struct page *page = virt_to_page(vaddr); - if (!iommu_need_mapping(dev)) - return dma_direct_free(dev, size, vaddr, dma_handle, attrs); - size = PAGE_ALIGN(size); order = get_order(size); @@ -3531,9 +3499,6 @@ static void intel_unmap_sg(struct device *dev, struct scatterlist *sglist, struct scatterlist *sg; int i; - if (!iommu_need_mapping(dev)) - return dma_direct_unmap_sg(dev, sglist, nelems, dir, attrs); - for_each_sg(sglist, sg, nelems, i) { nrpages += aligned_nrpages(sg_dma_address(sg), sg_dma_len(sg)); } @@ -3557,8 +3522,9 @@ static int intel_map_sg(struct device *dev, struct scatterlist *sglist, int nele struct intel_iommu *iommu; BUG_ON(dir == DMA_NONE); - if (!iommu_need_mapping(dev)) - return dma_direct_map_sg(dev, sglist, nelems, dir, attrs); + + if (unlikely(attach_deferred(dev))) + do_deferred_attach(dev); domain = find_domain(dev); if (!domain) @@ -3605,8 +3571,6 @@ static int intel_map_sg(struct device *dev, struct scatterlist *sglist, int nele static u64 intel_get_required_mask(struct device *dev) { - if (!iommu_need_mapping(dev)) - return dma_direct_get_required_mask(dev); return DMA_BIT_MASK(32); } @@ -4888,8 +4852,6 @@ int __init intel_iommu_init(void) } up_write(&dmar_global_lock); - dma_ops = &intel_dma_ops; - init_iommu_pm_ops(); down_read(&dmar_global_lock); @@ -5479,11 +5441,6 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev) if (translation_pre_enabled(iommu)) dev->archdata.iommu = DEFER_DEVICE_DOMAIN_INFO; - if (device_needs_bounce(dev)) { - dev_info(dev, "Use Intel IOMMU bounce page dma_ops\n"); - set_dma_ops(dev, &bounce_dma_ops); - } - return &iommu->iommu; } @@ -5498,7 +5455,19 @@ static void intel_iommu_release_device(struct device *dev) dmar_remove_one_dev_info(dev); + set_dma_ops(dev, NULL); +} + +static void intel_iommu_probe_finalize(struct device *dev) +{ + struct iommu_domain *domain; + + domain = iommu_get_domain_for_dev(dev); if (device_needs_bounce(dev)) + set_dma_ops(dev, &bounce_dma_ops); + else if (domain && domain->type == IOMMU_DOMAIN_DMA) + set_dma_ops(dev, &intel_dma_ops); + else set_dma_ops(dev, NULL); } @@ -5830,6 +5799,7 @@ const struct iommu_ops intel_iommu_ops = { .unmap = intel_iommu_unmap, .iova_to_phys = intel_iommu_iova_to_phys, .probe_device = intel_iommu_probe_device, + .probe_finalize = intel_iommu_probe_finalize, .release_device = intel_iommu_release_device, .get_resv_regions = intel_iommu_get_resv_regions, .put_resv_regions = generic_iommu_put_resv_regions, From patchwork Tue Jun 2 07:48:43 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: 1302236 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 49bkkB3xmNz9sSy; Tue, 2 Jun 2020 17:50:58 +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 1jg1hF-0006i4-Nm; Tue, 02 Jun 2020 07:50:53 +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 1jg1h1-0006Tj-Au for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:50:39 +0000 Received: by mail-pj1-f67.google.com with SMTP id i12so986841pju.3 for ; Tue, 02 Jun 2020 00:50:39 -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=lDYwjDNj7vq/MwHl1+atD0aXANx0RfYYoItTk6rLh4I=; b=oBPZYFXqivjJSD59xUOeVKFdP8LEjHsqglYlirZopg1lvotWXjxeGiEw7+cP92/RiR zZnx48/EREIgLEOpABH0+9Ug3SW8qJoHhOnVOSKda/X1RTJrSpFwGrD35jacBcc+qyNh se7+txuPnRFIOCiI+m7F8N+6iugHMo6/HsUiz1LmsEAPXyrhpVyl41wPaWxQKy7ti2n0 hf0vMFi5H/BH2SMEja797MA7JMDrqQwitDER0KfnwrZ55VDDePnlvGJVz7KMFvvPlb1S yLu/cJfMUghD5iztuqACy0INKju9QT5PZPRtGRRnuI+wL5tbRC5ImfVjLO617ihaC+3a Sjtw== X-Gm-Message-State: AOAM532w3Q2Y2J0qBdN8hzXTop35qwKh1fJCZ4JRM8mjyfNnmi87dxF1 Swe+348kv1874fBYAeA4N5wsZciiPBc= X-Google-Smtp-Source: ABdhPJy1nsU88ucYrvzuqquSbPMk6xK7Yd+NBHdeef7mwcLQTWoX6T/DkQ1p50kUohXtsOT277pZXg== X-Received: by 2002:a17:90a:dc83:: with SMTP id j3mr3872304pjv.59.1591084236587; Tue, 02 Jun 2020 00:50:36 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id v3sm1601350pja.8.2020.06.02.00.50.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:50:35 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 42/42][SRU][U] iommu: Remove functions that support private domain Date: Tue, 2 Jun 2020 15:48:43 +0800 Message-Id: <20200602074843.1743493-43-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: Sai Praneeth Prakhya BugLink: https://bugs.launchpad.net/bugs/1876707 After moving iommu_group setup to iommu core code [1][2] and removing private domain support in vt-d [3], there are no users for functions such as iommu_request_dm_for_dev(), iommu_request_dma_domain_for_dev() and request_default_domain_for_dev(). So, remove these functions. [1] commit dce8d6964ebd ("iommu/amd: Convert to probe/release_device() call-backs") [2] commit e5d1841f18b2 ("iommu/vt-d: Convert to probe/release_device() call-backs") [3] commit 327d5b2fee91 ("iommu/vt-d: Allow 32bit devices to uses DMA domain") Signed-off-by: Sai Praneeth Prakhya Cc: Joerg Roedel Cc: Lu Baolu Link: https://lore.kernel.org/r/20200513224721.20504-1-sai.praneeth.prakhya@intel.com Signed-off-by: Joerg Roedel (cherry picked from commit 69cf449166987d9a041020be6422ee7bf94a7228 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/iommu.c | 65 ------------------------------------------- include/linux/iommu.h | 12 -------- 2 files changed, 77 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index a09e9b08c216..c163a82c7ed6 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2546,71 +2546,6 @@ struct iommu_resv_region *iommu_alloc_resv_region(phys_addr_t start, } EXPORT_SYMBOL_GPL(iommu_alloc_resv_region); -static int -request_default_domain_for_dev(struct device *dev, unsigned long type) -{ - struct iommu_domain *domain; - struct iommu_group *group; - int ret; - - /* Device must already be in a group before calling this function */ - group = iommu_group_get(dev); - if (!group) - return -EINVAL; - - mutex_lock(&group->mutex); - - ret = 0; - if (group->default_domain && group->default_domain->type == type) - goto out; - - /* Don't change mappings of existing devices */ - ret = -EBUSY; - if (iommu_group_device_count(group) != 1) - goto out; - - ret = -ENOMEM; - domain = __iommu_domain_alloc(dev->bus, type); - if (!domain) - goto out; - - /* Attach the device to the domain */ - ret = __iommu_attach_group(domain, group); - if (ret) { - iommu_domain_free(domain); - goto out; - } - - /* Make the domain the default for this group */ - if (group->default_domain) - iommu_domain_free(group->default_domain); - group->default_domain = domain; - - iommu_create_device_direct_mappings(group, dev); - - dev_info(dev, "Using iommu %s mapping\n", - type == IOMMU_DOMAIN_DMA ? "dma" : "direct"); - - ret = 0; -out: - mutex_unlock(&group->mutex); - iommu_group_put(group); - - return ret; -} - -/* Request that a device is direct mapped by the IOMMU */ -int iommu_request_dm_for_dev(struct device *dev) -{ - return request_default_domain_for_dev(dev, IOMMU_DOMAIN_IDENTITY); -} - -/* Request that a device can't be direct mapped by the IOMMU */ -int iommu_request_dma_domain_for_dev(struct device *dev) -{ - return request_default_domain_for_dev(dev, IOMMU_DOMAIN_DMA); -} - void iommu_set_default_passthrough(bool cmd_line) { if (cmd_line) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 7cfd2dddb49d..78a26ae5c2b6 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -482,8 +482,6 @@ extern void iommu_get_resv_regions(struct device *dev, struct list_head *list); extern void iommu_put_resv_regions(struct device *dev, struct list_head *list); extern void generic_iommu_put_resv_regions(struct device *dev, struct list_head *list); -extern int iommu_request_dm_for_dev(struct device *dev); -extern int iommu_request_dma_domain_for_dev(struct device *dev); extern void iommu_set_default_passthrough(bool cmd_line); extern void iommu_set_default_translated(bool cmd_line); extern bool iommu_default_passthrough(void); @@ -804,16 +802,6 @@ static inline int iommu_get_group_resv_regions(struct iommu_group *group, return -ENODEV; } -static inline int iommu_request_dm_for_dev(struct device *dev) -{ - return -ENODEV; -} - -static inline int iommu_request_dma_domain_for_dev(struct device *dev) -{ - return -ENODEV; -} - static inline void iommu_set_default_passthrough(bool cmd_line) { }