From patchwork Thu Oct 29 15:41:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 11866721 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5519DC4363A for ; Thu, 29 Oct 2020 15:43:57 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 87A8F20838 for ; Thu, 29 Oct 2020 15:43:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="B+wTXRbV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 87A8F20838 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=uBPNVfNXzyIoCTtxNOdRxWo8Qs6zTHD3CVF2ov0e7lI=; b=B+wTXRbV8wXKpRirbpW4LQLkle 1fTq48FLPJu8H9UVlg7zkJ+vUaUQoBnk4gMMIR1NI6ZJsmgHk+j3aG1IoDQo/PH3MUlmkGghglDnO Z3gDaMBRB2LV4/8a95NkgtKpU0txkLdt2Xq68fM3kteAlWkucyBrpBO9LxiWh0RTx4nvu9rI/8Wlt EiUKomx71JBRY6/lu9ED40yUv5dj+cEI235TITZv11SOR8Doam12+dIVlVSfpRK8KKRrldTN7DD2b RNIJdYywYpQHc+ZJ0FJQSphxQ2bFOGklXF2iFaS0+xJmHIvRie5iHtdKIUjcvB31O1rmNJkbNjxoi occ7sTeg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kYA4P-0004IM-Lr; Thu, 29 Oct 2020 15:42:33 +0000 Received: from szxga05-in.huawei.com ([45.249.212.191]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kYA4D-0004DA-Ew for linux-arm-kernel@lists.infradead.org; Thu, 29 Oct 2020 15:42:30 +0000 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CMV7C0yCzzLnGB; Thu, 29 Oct 2020 23:42:15 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.47.27.104) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 29 Oct 2020 23:42:03 +0800 From: Shameer Kolothum To: , Subject: [PATCH] iommu/arm-smmu-v3: Add def_domain_type callback Date: Thu, 29 Oct 2020 15:41:14 +0000 Message-ID: <20201029154114.20364-1-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.47.27.104] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201029_114229_656707_12B2A4F0 X-CRM114-Status: GOOD ( 16.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: song.bao.hua@hisilicon.com, jean-philippe@linaro.org, ashok.raj@intel.com, will@kernel.org, joro@8bytes.org, john.garry@huawei.com, linuxarm@huawei.com, jonathan.cameron@huawei.com, robin.murphy@arm.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With the introduction of def_domain_type in iommu_ops, vendor drivers can now inform the iommu generic layer about any specific default domain requirement for a device. Any pci dev marked as untrusted is now prevented from having an IDENTITY mapping domain.  The callback is also required when the support for dynamically changing the default domain of a group is available. Signed-off-by: Shameer Kolothum --- -Only devices downstream from externally exposed PCIe hierarchies   (such as Thunderbolt outside the platform) are currently marked as "untrusted". Not aware of any ARM64 platforms that may use this type of device.     Nevertheless, the main motivation for this patch is to have the flexibility of changing the iommu default domain for a group based on the series[1] "iommu: Add support to change default domain of an iommu group" and that mandates vendor iommu driver to provide this callback.  -This is tested along with [1] and was able to change the default   domain of an iommu group on an HiSilicon D06 hardware. 1. https://lore.kernel.org/linux-iommu/20200925190620.18732-1-ashok.raj@intel.com/ --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index e634bbe60573..d5dbcee995db 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2567,6 +2567,31 @@ static int arm_smmu_dev_disable_feature(struct device *dev, } } +/* + * Return the required default domain type for a specific device. + * + * @dev: the device in query + * + * Returns: + * - IOMMU_DOMAIN_DMA: device requires a dynamic mapping domain + * - 0: both identity and dynamic domains work for this device + */ +static int arm_smmu_def_domain_type(struct device *dev) +{ + if (dev_is_pci(dev)) { + struct pci_dev *pdev = to_pci_dev(dev); + + /* + * Prevent any device marked as untrusted from getting + * placed into the Identity mapping domain. + */ + if (pdev->untrusted) + return IOMMU_DOMAIN_DMA; + } + + return 0; +} + static struct iommu_ops arm_smmu_ops = { .capable = arm_smmu_capable, .domain_alloc = arm_smmu_domain_alloc, @@ -2589,6 +2614,7 @@ static struct iommu_ops arm_smmu_ops = { .dev_feat_enabled = arm_smmu_dev_feature_enabled, .dev_enable_feat = arm_smmu_dev_enable_feature, .dev_disable_feat = arm_smmu_dev_disable_feature, + .def_domain_type = arm_smmu_def_domain_type, .pgsize_bitmap = -1UL, /* Restricted during device attach */ };