Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp632893ybz; Wed, 29 Apr 2020 06:43:56 -0700 (PDT) X-Google-Smtp-Source: APiQypIadiJHY7YoV0RQnY+hnihA+mFPuJYtBdz+DwW6UVmE9z/Wq4C/BLD1hieqT7EmFIjwAjoH X-Received: by 2002:a50:de02:: with SMTP id z2mr2403025edk.292.1588167835878; Wed, 29 Apr 2020 06:43:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588167835; cv=none; d=google.com; s=arc-20160816; b=Emu6Du5ZWMzmJyx5tKq9DR8rjjubXhKthicMhVjMJOANxZazntQhEcDR+q2pbwuUqh KF4dtf++brQwiL8pAMXN/pwldVNbAzF8rHlr9H8piNUGsNfFPA8XJf5XE300xdhAODNb EHdCJO4h78Xl/xBGo/GCmEErL24DWQfkXY3AXAJsbX7z3+JhQIiuqTbzGPauV7fK+2B9 0Dr3QgEp3CCd/e3TXo3sdB0PX9SINggXePc6xh0GYDgCOCrjn8zvQhuAK0lCn9rZnTDQ YH7vXhWI4awGN0l1yUB36KWVOsTknruRi8CFVQN8zdloXA38wg8sJcNoduX7i5WGg0Qj xIFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=kooLJZX6b4dW9WSParGOFfUE4heYWgmUf4U85PaAmAY=; b=B/6yJnnx4l51AMxoTUWuFOJ3tsvjaeXJFUdNwpBJMd+XohBIsHDCzxPt8eEDaMyFC+ 3wYscbJlX1/bEHtq+CZIaAIuB807gKGBvL6ZORQotMvZcaXHm/EMQGNHDiUgIKV1H4fb trLGsFdatpFOPMpTa6utLwYAvAsmNW7f5K7vnOShjj7Cj8d+c/2A5hpqsNrB/WV4b8MD hqZomtFMkswXUqfxgcBgt1xS+167LneQzOxbqjXI3vQkJYYcca2g9BJNPFGqKC+1Sal1 gWYId+9QIwzX0nA+4Kh1pNryD2DOx+/yTGmXxGn7Th6gHF41Kh3od/8VqMw0iU/bIiKf arJg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r11si3354204edq.390.2020.04.29.06.43.32; Wed, 29 Apr 2020 06:43:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728584AbgD2NlF (ORCPT + 99 others); Wed, 29 Apr 2020 09:41:05 -0400 Received: from 8bytes.org ([81.169.241.247]:39570 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727871AbgD2Nhj (ORCPT ); Wed, 29 Apr 2020 09:37:39 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id 84C5C434; Wed, 29 Apr 2020 15:37:35 +0200 (CEST) From: Joerg Roedel To: Joerg Roedel , Will Deacon , Robin Murphy , Marek Szyprowski , Kukjin Kim , Krzysztof Kozlowski , David Woodhouse , Lu Baolu , Andy Gross , Bjorn Andersson , Matthias Brugger , Rob Clark , Heiko Stuebner , Gerald Schaefer , Thierry Reding , Jonathan Hunter , Jean-Philippe Brucker Cc: Daniel Drake , jonathan.derrick@intel.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-tegra@vger.kernel.org, virtualization@lists.linux-foundation.org, Sai Praneeth Prakhya , Joerg Roedel Subject: [PATCH v3 02/34] iommu: Add def_domain_type() callback in iommu_ops Date: Wed, 29 Apr 2020 15:36:40 +0200 Message-Id: <20200429133712.31431-3-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200429133712.31431-1-joro@8bytes.org> References: <20200429133712.31431-1-joro@8bytes.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sai Praneeth Prakhya 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 Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Signed-off-by: Joerg Roedel --- 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 bfe011760ed1..5877abd9b693 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1361,21 +1361,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; }; -- 2.17.1