From patchwork Wed Oct 9 16:23:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13828803 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6893DCEE330 for ; Wed, 9 Oct 2024 16:40:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pzkew/fTCrQzoPLzoQu5qlbNv+Zi5AHyETLlK5w1NyA=; b=amnJbQIy0/sPziSAzUriSUglJ2 Sc4+kqNzeIN82GOUB/CrL17D43mQQga2WJ5Vgy29sGWkm7WvKPFmjFNxuRVw6D97sG17/JnlIoNdp kK+KTxvGMLcxBveDy10WihH9EMW45LtMzmEB3+H62AUhAnMq2ZkmpwuHgw/GFgWQwE0Feb6AXCM9b zQTyYQND+LmxwQVe7pdQs59X/ltJbU1ua2wgIKke7ntCzBRCOqG8Yno0P1t9S15juv8HzkvnFuVpl KyrsKYuP5w0H+4WbzrbkRv4bE65WVd/H+L7TH03lJ6ErTi6SqJtlzRaU5sh1Qqf0j8EodoSlEMOvR SAaXX9Kw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syZjH-0000000A0vj-0KIP; Wed, 09 Oct 2024 16:40:03 +0000 Received: from mail-co1nam11on20607.outbound.protection.outlook.com ([2a01:111:f403:2416::607] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syZTO-00000009wV5-21xV for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 16:23:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JSmVXoM08drGa4OfD/E/HbhWBlZfk8+bmuhm/kUdDXdfyfhE7gxGdnSILi305KfEHGC9ZxJIq/Qcx7JU1Z7ZHmfzpiEETkb/J1Zpo6iQEWO9+KQoczGvbsFxx66OKIkt+NcgCh0hlN2XElrgVrwTygqSvH12/tH0pszc77JG0/NiPwKajK9F7alNMN94EmLp/uWh63Fs3kujgJK6lxi/plGZ8xshQiABPfFJ89mnMP/WFZ1yOhHGLhZ8dJH1kgS1vZJWbqHUXNycrNx/KV0m9VDd+W4eKznx2Ug+MTDafkd0eES9wirYYdRDqetOg0SLFYuJE4BW9kCzjpZLaKOCyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pzkew/fTCrQzoPLzoQu5qlbNv+Zi5AHyETLlK5w1NyA=; b=acCOOcZRir9GS2BIlqFmboJiZQP7JAOZTSnnNBzlj3we8WiUQ2ScCpuUggy4v6m7J1FPTvVOGRhGHo86FvBMDyC5+8tVbu4j8i3/nQZC5lKOHYujoWP0Br0lXPONBTmCEEA0T2B2fZYOW2aNJvuCqfLZr6jIUr0rqqcwjpCXHMOoaSRpyIDJrYsFcz8KgkzYVB3A3/W7WBgzz/749V1ItrBxrvqmWGX5SkIhuLGLQ+dXMTympAzZ0oLmVsbbX1bVr3xPuPuxy8WNLhHKN+jywZj69dtRVsxvHlnvrPsBPlU/vhokMmUyirtQMoU0mDmkFDMIeRV+hNtJS9RStZl+5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pzkew/fTCrQzoPLzoQu5qlbNv+Zi5AHyETLlK5w1NyA=; b=kD+e2dRlNg0rWVOcg1LToYNERSHJ6WWMWRjA9O9rKHgGczwC6i5JMJnXRNdr7sIyEqEOreiblaF4fC/+ikWB+KLsXjpA0Vr3Ug7KN4wn8ARdKInKmoMkuY4LYdQ9w1XTm14wszKaizFvRZM44xhujc5c0CghUdpdoL5l9EZtn+rMXoes8Iv/lFiXnr7CYAvq2IUX+7kvFgb1LYTbNvWz6ReC/N43cGc1TjDEDgZkaD1kgIOwAgG2wVEGhZfIepQJPa/RNHznLvyu6dd59FgU0QjC7EvBQoj1XqEFnlIecBtzSyf4NnsEL/5vBDBmdA3tMxnJa8qY1dL6qR4CxHUXiA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) by DS0PR12MB8768.namprd12.prod.outlook.com (2603:10b6:8:14f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Wed, 9 Oct 2024 16:23:26 +0000 Received: from CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732]) by CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732%4]) with mapi id 15.20.8048.013; Wed, 9 Oct 2024 16:23:26 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, Hanjun Guo , iommu@lists.linux.dev, Joerg Roedel , Kevin Tian , kvm@vger.kernel.org, Len Brown , linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lorenzo Pieralisi , "Rafael J. Wysocki" , Robert Moore , Robin Murphy , Sudeep Holla , Will Deacon Cc: Alex Williamson , Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, "Rafael J. Wysocki" , Shameerali Kolothum Thodi , Mostafa Saleh Subject: [PATCH v3 1/9] vfio: Remove VFIO_TYPE1_NESTING_IOMMU Date: Wed, 9 Oct 2024 13:23:07 -0300 Message-ID: <1-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> In-Reply-To: <0-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> References: X-ClientProxiedBy: BL6PEPF0001641F.NAMP222.PROD.OUTLOOK.COM (2603:10b6:22e:400:0:1004:0:f) To CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB8659:EE_|DS0PR12MB8768:EE_ X-MS-Office365-Filtering-Correlation-Id: e155ae1f-5390-4456-fc52-08dce87eaf7a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016|921020; X-Microsoft-Antispam-Message-Info: yPCKF8SZ7rNa44WlWAahBoRgalYQgwIP6a5BHxqI11Cig7Pt27KSEOO66YvwR/zSxl4L4HJ4VmW1dR+aaE1DkWBYjh0YqNCaB02sANdxNnaYLCX8CMQYn4rQ/nF6NaL4SWSjCVoM/XwNpokuQ63lgCkbZoZyKxMTv5IvKxHEOg/92vkAA7fp3+F5FnVwEivgsrzsfyrmrTeLi63AKnnsa1JeOPc7aefAaeCo4qHefBeDJppr9JOwnwoKzYzSANWybR5bAiDpH5s0RLucloAROmamKrix9u5l6yyA0WEsdIxibYR6vUUeymOGSoVyKE+Ld4hf4MmXIFYNTEoqKrlxxLJqWI1pgPaLs8DoFLlktKfmygfUtq8Xt7HETy7Nkdc+vpkPZQwDSF2XXkJwtrN5Aj0YP39qBLoxST3RU3Ha+E1UTFTBPW5gBBckKRz/A8IoiSGmjcp0arFinkKbD2qhfijhJI4GAAIMbpdtJbSWG7FYgKojgAPNQbqftNK1dX+ju6y4sUaATwU6kYwzMyvZtmO9hALyN0ELXetMdNiLI4M5uBauRc+IGiU81IxYiNHbGtyrFlj4VP6A18BSHUeMHPp5zAdh79GvyRyQZd9WcmQFsc8UY91VaH+PJg/QgmMZsz0LjYzuSPvqDab4XdCJViTcN3v7mrXNrltnXa4/+moPEM9XeOEhT9dX/Ikprb1Ahy6oGdW3jhvtNGYHCALBXIhQtOCBXuWxuBqamOgfUbc7sEkOgQhpwslMrlBftm+8tV5+aKNU+eiQWdOPV8Wz95ytzWaqVzhWJADr6eNzHmqp2TeLTGLKBgZvvqGG6xu164sfpg3mlpcvtu5B6z9iAP9fMVtxWMTjdEVE0lIutUacXizLM3xKRsTTnJ6v+8cUZyFrVzPCBI4nFv8WaBiEa0Yu1wDSOGaV6d6veJrmblpHxTQcESM/DLbCd/lGhNG7fsi5WOtI/7jxZvQ3GRyzaBDQx58eTAcB/JgZxD4aIFVfqYsIvnR2QMSYjAmGaNqMby98UNnpzoppbBDH7gCDBXNPALgHX1zNSlbnFsrBWF7dFeOgHkKTqhQvZj7VaAKbFs9L+P748g3czJCXyCEP0LkhAqhBrC9tQUDxgrHrQYzxAG3vIAMrR0mACSj1lS75MPE0XkEvdIQhIzuHO4UnPb+yGRYNkSiCM/kVPLHKeT2QVvUonVBbXg9XG0CGUx8D9yJq6YyRRG6Ji4F0zVoMmSXU9lcmvnb9N8scw2BdgKlXVpP995DbusJyZfKu6g7iO94V+4BGOxwyb+8Hg7s1zdS0aRoH7I6CALVLgp1wXe0eBgebrM02zhFe/ext8V1D X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB8659.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(366016)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6BwOzHulyjHUPjnoTNpClEdcELbQhxA4EzHYkXaRcRLuwWdhKINkWzAQM6XtT+Nvg/Rd5yDtCofjcg2vIctdXfoZchU/Tpi3em4KEQgxLS6GS6t1eyVGcOKeedlJSl3KlIAUOGJZqTVhPnnBbqwmp7gfMuUFi7P/BF7EXogMEZmTtyKFyH0p+PlY9TrvshOrGwBT3xQerMdcIukeeBt+Q3h57dUSXcPeUDl82b5L9JK8eC6ZgBgOKrXC186+16yFZKdS2HrwOFyh4bZb0DN6HkaowiPaIEK1t3l8LzCEyiRDeQqa7tjuYJ4sHgc+y7sXt7EJXMOK5wH0FpjZiH4G9iNn1S4D4vxm7TQxXnBGekTocKjcsq6bQmujPlf1KDJ7PSKSd7qjDHUBxPOwts6hyqouy/WUgHC5XVG2tM9TOGowYGf1VIQsdCW13buDieMuHWPacHXkxynUGVZEameLNqIZO/6xLshB8HLdMuwpLAlEcy+C5l6qE3/KGQGu0G7ilyKjYyaeZXCoL2wKQBGSalqV34Y5CR79ARjjq3yUQ7VlhLT7zhSASJTWrTk+z40sqkF6TI6mnGj0AtSj1fS/dvSxQseln5OhnPcy9z5DmrTH4B5o19B1dcPSo7clWKi0ml6XL4hFxGp/KnkFz+evRAMz4xkrBZhlYoN92+Cs6w83zvR2jZdnKJ05xe7L66L3eNXj6qFgzC7GQgZ5WnvVQXImtEZ/CydualZX2D5HsPVxZFyI4Y8+rBDBANHBsVP2XnnczZortfoCeipriQlb9OO7gbmvulBu35mvnuE6Yx3RVtXgGPVdKEPWYGNlhdMvsITng/r8bvIMCMhkeeb1PEaKTG6Fl9liq00eH+sT+LOseiWdvFggXq23kHj33b+Mqs7+2sW+QWzh+1xJHF4IjjLT4wwYx1D2OS+QtAgVtclHwPDd3q9YccTsIa4dLW7S1VKtMaHsqPKsmW6rVTO7JZJUqyBfAJtvNLPTX6FuQ49sEGCozTlb6s1Zmth+hOs3aJElSHfPm6QoSBPN19WQctf1SAA4pxF4N5Xyrn90FJYq6w71zxOkDyZiYS66SEnVw0kKIG6id1Ml0XelnPZQ4JZ5Kk7GVdocVucH7bYbxx96zQPmOJ0ihWRr/e922tTtG+TKd/4xTu4rN5hJFu3yhx/OE1yL2yey33axJKvqyFnOAWwUy3ecPcg82pB9R6ncv+l3zwuU7qkWs1umGC6KFs24+Ztsv3anYsi6GPQle+R4dBJgVjPhKGmPYJrUezHozFRRPlZMHMz61tKeCyzMzT8+VS5ffFcYpztb7nsyUXZhVtDfOBpkflSLi5/sAeK2osYWU2+Fv44xEYuZL5IKuYiWU5VLEGm6NNtlrU0q0ka8Pg1LejL00TlWPA0nitD2fX/ROVayC94lqvAIzvOwbOBUo8ZlhtngJyzbAwlf1CM1HWkNstf9+67gkQWCu2Gtdt4OTkf+i+8c/Y/6zSAphU26KtH7VvgeFT1Qdpm+fus0kShB5TSdJsGB2rM96pD3ujkBw5p7WjKN8fktuNaHU9HtlJYnCYDdSoZUsndhw6k= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e155ae1f-5390-4456-fc52-08dce87eaf7a X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8659.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2024 16:23:18.8827 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Cycn3a0f57uU8wOGgWZJin6a208dxnAuRyfYd8lzQzEF6W1kB0jZsRqCuMDSD+o2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8768 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241009_092338_627346_B5821838 X-CRM114-Status: GOOD ( 21.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This control causes the ARM SMMU drivers to choose a stage 2 implementation for the IO pagetable (vs the stage 1 usual default), however this choice has no significant visible impact to the VFIO user. Further qemu never implemented this and no other userspace user is known. The original description in commit f5c9ecebaf2a ("vfio/iommu_type1: add new VFIO_TYPE1_NESTING_IOMMU IOMMU type") suggested this was to "provide SMMU translation services to the guest operating system" however the rest of the API to set the guest table pointer for the stage 1 and manage invalidation was never completed, or at least never upstreamed, rendering this part useless dead code. Upstream has now settled on iommufd as the uAPI for controlling nested translation. Choosing the stage 2 implementation should be done by through the IOMMU_HWPT_ALLOC_NEST_PARENT flag during domain allocation. Remove VFIO_TYPE1_NESTING_IOMMU and everything under it including the enable_nesting iommu_domain_op. Just in-case there is some userspace using this continue to treat requesting it as a NOP, but do not advertise support any more. Acked-by: Alex Williamson Reviewed-by: Mostafa Saleh Reviewed-by: Kevin Tian Tested-by: Nicolin Chen Signed-off-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 16 ---------------- drivers/iommu/arm/arm-smmu/arm-smmu.c | 16 ---------------- drivers/iommu/iommu.c | 10 ---------- drivers/iommu/iommufd/vfio_compat.c | 7 +------ drivers/vfio/vfio_iommu_type1.c | 12 +----------- include/linux/iommu.h | 3 --- include/uapi/linux/vfio.h | 2 +- 7 files changed, 3 insertions(+), 63 deletions(-) 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 737c5b88235510..acf250aeb18b27 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3378,21 +3378,6 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev) return group; } -static int arm_smmu_enable_nesting(struct iommu_domain *domain) -{ - struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); - int ret = 0; - - mutex_lock(&smmu_domain->init_mutex); - if (smmu_domain->smmu) - ret = -EPERM; - else - smmu_domain->stage = ARM_SMMU_DOMAIN_S2; - mutex_unlock(&smmu_domain->init_mutex); - - return ret; -} - static int arm_smmu_of_xlate(struct device *dev, const struct of_phandle_args *args) { @@ -3514,7 +3499,6 @@ 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, - .enable_nesting = arm_smmu_enable_nesting, .free = arm_smmu_domain_free_paging, } }; diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index 8321962b37148b..12b173eec4540d 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -1558,21 +1558,6 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev) return group; } -static int arm_smmu_enable_nesting(struct iommu_domain *domain) -{ - struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); - int ret = 0; - - mutex_lock(&smmu_domain->init_mutex); - if (smmu_domain->smmu) - ret = -EPERM; - else - smmu_domain->stage = ARM_SMMU_DOMAIN_NESTED; - mutex_unlock(&smmu_domain->init_mutex); - - return ret; -} - static int arm_smmu_set_pgtable_quirks(struct iommu_domain *domain, unsigned long quirks) { @@ -1656,7 +1641,6 @@ 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, - .enable_nesting = arm_smmu_enable_nesting, .set_pgtable_quirks = arm_smmu_set_pgtable_quirks, .free = arm_smmu_domain_free, } diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 83c8e617a2c588..dbd70d5a4702cc 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2723,16 +2723,6 @@ static int __init iommu_init(void) } core_initcall(iommu_init); -int iommu_enable_nesting(struct iommu_domain *domain) -{ - if (domain->type != IOMMU_DOMAIN_UNMANAGED) - return -EINVAL; - if (!domain->ops->enable_nesting) - return -EINVAL; - return domain->ops->enable_nesting(domain); -} -EXPORT_SYMBOL_GPL(iommu_enable_nesting); - int iommu_set_pgtable_quirks(struct iommu_domain *domain, unsigned long quirk) { diff --git a/drivers/iommu/iommufd/vfio_compat.c b/drivers/iommu/iommufd/vfio_compat.c index a3ad5f0b6c59dd..514aacd6400949 100644 --- a/drivers/iommu/iommufd/vfio_compat.c +++ b/drivers/iommu/iommufd/vfio_compat.c @@ -291,12 +291,7 @@ static int iommufd_vfio_check_extension(struct iommufd_ctx *ictx, case VFIO_DMA_CC_IOMMU: return iommufd_vfio_cc_iommu(ictx); - /* - * This is obsolete, and to be removed from VFIO. It was an incomplete - * idea that got merged. - * https://lore.kernel.org/kvm/0-v1-0093c9b0e345+19-vfio_no_nesting_jgg@nvidia.com/ - */ - case VFIO_TYPE1_NESTING_IOMMU: + case __VFIO_RESERVED_TYPE1_NESTING_IOMMU: return 0; /* diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index bf391b40e576fc..50ebc9593c9d70 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -72,7 +72,6 @@ struct vfio_iommu { uint64_t pgsize_bitmap; uint64_t num_non_pinned_groups; bool v2; - bool nesting; bool dirty_page_tracking; struct list_head emulated_iommu_groups; }; @@ -2195,12 +2194,6 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, goto out_free_domain; } - if (iommu->nesting) { - ret = iommu_enable_nesting(domain->domain); - if (ret) - goto out_domain; - } - ret = iommu_attach_group(domain->domain, group->iommu_group); if (ret) goto out_domain; @@ -2541,9 +2534,7 @@ static void *vfio_iommu_type1_open(unsigned long arg) switch (arg) { case VFIO_TYPE1_IOMMU: break; - case VFIO_TYPE1_NESTING_IOMMU: - iommu->nesting = true; - fallthrough; + case __VFIO_RESERVED_TYPE1_NESTING_IOMMU: case VFIO_TYPE1v2_IOMMU: iommu->v2 = true; break; @@ -2638,7 +2629,6 @@ static int vfio_iommu_type1_check_extension(struct vfio_iommu *iommu, switch (arg) { case VFIO_TYPE1_IOMMU: case VFIO_TYPE1v2_IOMMU: - case VFIO_TYPE1_NESTING_IOMMU: case VFIO_UNMAP_ALL: return 1; case VFIO_UPDATE_VADDR: diff --git a/include/linux/iommu.h b/include/linux/iommu.h index bd722f47363520..c88d18d2c9280d 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -635,7 +635,6 @@ struct iommu_ops { * @enforce_cache_coherency: Prevent any kind of DMA from bypassing IOMMU_CACHE, * including no-snoop TLPs on PCIe or other platform * specific mechanisms. - * @enable_nesting: Enable nesting * @set_pgtable_quirks: Set io page table quirks (IO_PGTABLE_QUIRK_*) * @free: Release the domain after use. */ @@ -663,7 +662,6 @@ struct iommu_domain_ops { dma_addr_t iova); bool (*enforce_cache_coherency)(struct iommu_domain *domain); - int (*enable_nesting)(struct iommu_domain *domain); int (*set_pgtable_quirks)(struct iommu_domain *domain, unsigned long quirks); @@ -844,7 +842,6 @@ extern void iommu_group_put(struct iommu_group *group); extern int iommu_group_id(struct iommu_group *group); extern struct iommu_domain *iommu_group_default_domain(struct iommu_group *); -int iommu_enable_nesting(struct iommu_domain *domain); int iommu_set_pgtable_quirks(struct iommu_domain *domain, unsigned long quirks); diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 2b68e6cdf1902f..c8dbf8219c4fcb 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -35,7 +35,7 @@ #define VFIO_EEH 5 /* Two-stage IOMMU */ -#define VFIO_TYPE1_NESTING_IOMMU 6 /* Implies v2 */ +#define __VFIO_RESERVED_TYPE1_NESTING_IOMMU 6 /* Implies v2 */ #define VFIO_SPAPR_TCE_v2_IOMMU 7 From patchwork Wed Oct 9 16:23:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13828807 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A40DDCEE332 for ; Wed, 9 Oct 2024 16:44:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=1PkoTZUjhuR/nKmtRTOKzRg40EpQKs10xY4n4MrkeFM=; b=iOmly5x+Wql0EM9b9AhDeMja3O Hb1c1WrA50mtv6IctOkO63BdxRat+jQe022Bffd0COCCYJREKQB0rijPtZUPO0X7Xs9XFJrpb20K+ d3M7i+Wu30M7jtF+IplrEhAH1DXrkus5hVJ3YmNfHfInj6eRdeMb3mqL3G6AgduZd6OAJbkHfSMua cTvF0rfcLDNOcOHGIVEdmVjFyv2TJMnI6O+sadDn+2I179EarjH6OA9xXqSDdFNdCE5WF/6jtjyBc frhlevOOj8bjFALbTzb0fO6K5UyQJMtxPTJ3f54/ayvnS+ma+qROWHw0A+bMiXLe3YAAY8TMr01n2 4BtL8Gdw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syZnK-0000000A2Zo-296w; Wed, 09 Oct 2024 16:44:14 +0000 Received: from mail-co1nam11on20607.outbound.protection.outlook.com ([2a01:111:f403:2416::607] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syZTW-00000009wV5-1tbj for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 16:23:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uHBa4XqNARGQPwIQNy7n3vM1yamQohnFUL9e9n1tzzspm9CBKOtn5d6IBvo1IUeUNCAU2lGalSVGtyaxkxTJyBwuSFlz9KyvU+45ve/WUe95eBYryDfnFCJruFvZlSHrjyC/fgtKq2+HZcoYSDszwXVOlBMzPk8HzuPkGRdh/LPsPk/5d6v+se1a8fhiS5NKGlwXHXGcdFdOlEXjBbc1MYjkmeC729Wv4zbyjjBBAzi2Qqr3f6bbDmBZSoxQnWp0cqfbYQqNgQpb2tKp+ntmCH7DG821WMPIQvGpOFIf+tu1NtpUBFlTTchquLNgtn0DE+sOisYT4M5sJ4rYO1kZng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1PkoTZUjhuR/nKmtRTOKzRg40EpQKs10xY4n4MrkeFM=; b=Dcu+7QsIFuoIWrjPFjBWUvxebk+4KfVuK9d9NkYeT9gjIVNnHZAkqi1GoLNthrcegtLA3AQXWbZwuXaWWbUMnJLv7nsONJ5HQzKGmSVnMQ/uG1mgv9PwgRT0LKOEpxiPpxkO1G1+9HNWChqbtw8eCKlz7w82DNIiiYHtxz7jWxTiryMykmGK2Xcertl+K2JKoCokf9i849JhC4kNN3bZNbhlpPvwHNjg3FIAhB4UfiV87x/Q/WoogshLgZ0PH5pk1JdirbEWm41odmpYlzZmpxdggrpwPp7SXI9MEbtvZ87aSfV7Pz8V6SPkwDq0XboSL2oUvx7+0Ckwv+P4L2fhrg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1PkoTZUjhuR/nKmtRTOKzRg40EpQKs10xY4n4MrkeFM=; b=h5ht0td6G/QaJzn6gidg/C5OKT0qB/6qb6SbyoM12mLjCsuYD2r0ow/obZ0Pd4XzQdF/Ta6XSZ20HHU6TZ5B2umpXWWSC/36MGZvh/1cxX9nmZXrqZEFgvBXTo7fq+VmakWLUU4ko33lQQmhxXnwFVyoc1vZoqUtesbVY1RaGZIYW/tQlFKrIUlGrdQLz6KLxIgeeoddmGiAn3NdaPt+C76deR05A16MQVjDB+YklD11eT216Q5p6QW6SFEFMsEY96+QN06Jd8LYH/e1dJxt7ThQFYRiUmP5L41GHS6f0fX0sej2DW1xlegGheQ2+b8Sg7mA7OFwUUg/iGp9/z4l4g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) by DS0PR12MB8768.namprd12.prod.outlook.com (2603:10b6:8:14f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Wed, 9 Oct 2024 16:23:30 +0000 Received: from CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732]) by CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732%4]) with mapi id 15.20.8048.013; Wed, 9 Oct 2024 16:23:30 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, Hanjun Guo , iommu@lists.linux.dev, Joerg Roedel , Kevin Tian , kvm@vger.kernel.org, Len Brown , linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lorenzo Pieralisi , "Rafael J. Wysocki" , Robert Moore , Robin Murphy , Sudeep Holla , Will Deacon Cc: Alex Williamson , Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, "Rafael J. Wysocki" , Shameerali Kolothum Thodi , Mostafa Saleh Subject: [PATCH v3 2/9] ACPICA: IORT: Update for revision E.f Date: Wed, 9 Oct 2024 13:23:08 -0300 Message-ID: <2-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> In-Reply-To: <0-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR05CA0023.namprd05.prod.outlook.com (2603:10b6:208:36e::25) To CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB8659:EE_|DS0PR12MB8768:EE_ X-MS-Office365-Filtering-Correlation-Id: faa7778b-7f1c-4989-2ae7-08dce87eafb4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016|921020; X-Microsoft-Antispam-Message-Info: 1j6DkjtN/eEXnT1SSOT7wF052uTJpKqrPmccvR6xcdaWnBMT8p8gZXtj+eotyERcTcNGn04LLE8fG4+yWW6wBnN/1wdN1s9pVOca5aqYPtw4BZXlBUcSc79L/xOUr68cByfAF6eDAYRqGQQyAgdUWLy9P3HLguf4RgWECP7LpC4jurYF7MnE5sQkCs59Gx5mCRwPWf9Q2bFS1ZprlvVRf7eZW3kCZbiMmTRVX24epucOr0C1KSFmcHWINiQXkPl34OCGynggUcZudCcRfeMRoe03VlQ/5qL7S911Y8nshD0BAy0nh325Jx7noOp5dkokmDI5pfoEPm0NbrgwJCq5VlWR4xd9nHaYIW/QvticMyBU22G0ggO5Mye23kCUjUoeW3+hWh6NWH4oIFmdJVF1XfSYORwh6vhfaP7j4pErsSSOPM5js3pyDeBeNN5G2U34jZriTSbKixX9ksdeVdgrRLebIuKmzGS6sjo+O1i+KVVIObwZf/sQyKiBX/krhJkboWqvOJF2uwlLqy0EhZafDv5MM1I4L1w8NgfiIkhUo6qTYMbWfUl1voi7rJQv77RvzB8Efc8pBjRQlGjeKwJ5mouwiMaQn2SvhHJ4Bb5+oGux5bUmZrmr0x0DCTw5fXg3NNZd9kx8V1p+jLEVRJxqMqD6ontPD96V6iXK6MJSrTEJd0/++pNGYosvI/AVQ0ale+ByTkxQkScy0QzslSdRCFq0tFIarYRusvrF3MoaRVlCV5jVsrM4Z42AO9TNVtIEGauq/K7ae/4lbG1JOM/Sz1Kvv5y/a9DioBPkxpC76I2oNiRUFinlC/xWPgPxfm8Ii2ks7q49wbmzpYM3lOYImODWbf7/YwDy201K04BFQMhLDsUrtTkmpCDKctJS1CCnteTm5fNaqd9TqzzqARe+8DhmmQtXusOx6XrUSluw7Pep47XeghMs/bYeLJ7hko0f4ROfCMNZsCTs5ypwugzCFcoVRuKnb+PlgahscCus5nVc26ilQ5NUF8pvs/W7SjRUTYAk3O7EMqpQQVDEdJi+M62aLdPg/JZu3dTbU+A2NbFtOOdn8Piy6SmojumLt7koU5J9KO3YD6foSdqjDXNAcbg9zK0hUUTRUKkHtdCCaHMr5wraM0TS3Y3zfDmw4AEKa4d2q1opCEgVR1ZPceTujz81WdVDsDkx2Pzk4D1UyI4h20dOiHKqUUptG1qVX6wtcxTyxDf+GbujRmHLxnn/oI/tQXSaNMEFwivDiREXYQWlG5570cKSWIL83eyg8q2vt67pF+27ONXvKsnMCnfLiJ6OWCReSgAXsuKZ7EIbTKS8LE2rpDpCljTFbg/k8SUF X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB8659.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(366016)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: i33xyxz4oD0Gd991rnuY/VPUWYPYKrOhHeYJDbEAPtNBLMlYoQanxuSJ6e86YimtTIfbD4zYnSxiLfJfMt19MnzcSqtBQyM2brE3vOtleFGg+f2+wMzqZWx/psU3rm4PE7jP61aQPgLGRvbX1stJkoLKOCcqa5gjuQcF8nPR/XYtFBWjLxuNc/IUoWNWBD2ZS7DNqcXUX1p4BKi2JByWYvNhfja71gu252hwQ6tWM5bjBnfegGGzL48/GUZ6BCMiZdi25FjJoca4VZnamBV6mgOM75orQ6y6QkEM19jPK6X0DL/okvHqS8thfTrTmPaXGjJR74oLzYo8wUN8RpNugkiMuyMKTww7LQ0E7A85wqyTTRKFKDjOTTl+f1Ex+0I8MheGOSYkyuW1oAu1Io8Xx8qAPCEwMMiQEEHMR8liiM8i57Vf+jSc5h4OZdkL77lMFdQFkC8kF54Yn7AZa3/2cHzq+S7BvNxPfcFKbcyeXP0Y0ZfNN8UZdhx8+cZuTVubmhXzGM3WSUq4k5tVb3812ZtYXz44kKQyvNY7gyXx6gSM1VZa4fXFI1sqzT+fpvl+7rzzq9uxKlBnNI4rzVSvX83olqUhiTKutzxbbRYSFbbJbgRivSqsPmFT3CzshKM6PW4K697Z6xug3QFvEU/Rs2ChCaDvQb8Qx4LB0WyQQT0QOhvqqy0n6r/3iCPs1z7lxvHneKArblifWvfVROeMaFuex87eTYegYTyGGyhc27G2+FelATMJbHRCOEnprMk008G+TGB51pvzLumZtDrN4h0UHmQc+usVUxHvwFbF2FMwcZO0DT7BY+j+/PK818JyKCg5LdgByeYfI+n0Gzi1ZU/9yPY8eAPZ4FiKfxZjVFpb/jxmcOw74b2JjA26XKj4ckzAFJUVoUZouCF+FoVnojmPZGscT3gH0q4JI7VfEg7lIY8OKcCG+bsjmBeqebfIwNULq1L7LkdzEkMFK2bE2G4o0Wy+yBCXOflwk1+03cjH1hZZ8dH9xj5ezMtLCzOBypLAigx0Pmdb44bEGC6qU4XVB4T/xuTRiMpkVdCOuPmhoG/xfyK9ZClypK3YJembFGUwUZ0tw5TdtYALBrr2efwMdVFeunQn02gZ0p2wxYLI3kjgnYT3NeAPYPJ0GIopD6sPGBMkRWrNutPA6iww9dEOnfg7OCEpiSC4vS/mFRuZr3Mmj94xehK6KbyrXN8eE+Uj7S80b1b+xIKggWd22oSW3a+tcaUxnT4U/lNTZkfSNWtvU951AQb/MUx0UlyA5ZYBo5r5S1c4KoF4hLsD6cEQ2iq7W+RfTyUjF6WIq8B6NlnHZXJ1kGg2AN9NIgrMOU3LGf522UllllKSoxPjnItC7Oc0hxFyvGyYXS6SBFmpC5GesF+yDp82P1DXzdXZVc33pUYE8C+JKrygWaWzDMD1J49M91NlG3Y8+eGmtm6HleK3sS1A+5XW/thhIy+oKRgZjljo1wyForQLsr3zuyRQSiUND36bPCSkMhR8WgB5a5O78VtAyCoqQ5l77ykDVR2sGeOWkbv3ne0ZPHBgaHvA3f2Zomolhdbx3Ps4W68= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: faa7778b-7f1c-4989-2ae7-08dce87eafb4 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8659.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2024 16:23:19.2402 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: KRvUPVcdCVKtF0yGTznb4GrUn9PnlNZxJdh6IivDQsuWJy3FLS4gJcCeQTpf/IXo X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8768 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241009_092347_630173_9DD4FDFC X-CRM114-Status: GOOD ( 12.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Nicolin Chen ACPICA commit c4f5c083d24df9ddd71d5782c0988408cf0fc1ab The IORT spec, Issue E.f (April 2024), adds a new CANWBS bit to the Memory Access Flag field in the Memory Access Properties table, mainly for a PCI Root Complex. This CANWBS defines the coherency of memory accesses to be not marked IOWB cacheable/shareable. Its value further implies the coherency impact from a pair of mismatched memory attributes (e.g. in a nested translation case): 0x0: Use of mismatched memory attributes for accesses made by this device may lead to a loss of coherency. 0x1: Coherency of accesses made by this device to locations in Conventional memory are ensured as follows, even if the memory attributes for the accesses presented by the device or provided by the SMMU are different from Inner and Outer Write-back cacheable, Shareable. Link: https://github.com/acpica/acpica/commit/c4f5c083 Acked-by: Rafael J. Wysocki Signed-off-by: Nicolin Chen Signed-off-by: Jason Gunthorpe Acked-by: Hanjun Guo --- include/acpi/actbl2.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index d3858eebc2553b..2e917a8f8bca82 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -453,7 +453,7 @@ struct acpi_table_ccel { * IORT - IO Remapping Table * * Conforms to "IO Remapping Table System Software on ARM Platforms", - * Document number: ARM DEN 0049E.e, Sep 2022 + * Document number: ARM DEN 0049E.f, Apr 2024 * ******************************************************************************/ @@ -524,6 +524,7 @@ struct acpi_iort_memory_access { #define ACPI_IORT_MF_COHERENCY (1) #define ACPI_IORT_MF_ATTRIBUTES (1<<1) +#define ACPI_IORT_MF_CANWBS (1<<2) /* * IORT node specific subtables From patchwork Wed Oct 9 16:23:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13828771 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 968A9CEE330 for ; Wed, 9 Oct 2024 16:34:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=UM/OqRVKfdnk+8DUpdClNjxJr4a69tRo13nfkCjpyJA=; b=OYI3fkhzHVHt9A/EuM7VJEFNOy Qw+Tk6YdMETYC2RA3nTGgs673nM7Jci+NTlLtCeHb0jSG1MdlOfCSYkQ6zaKEOLrf7xKxUtCkWfBN kXTtOWyEhbIUXdLghQIHfQgscKOZ0Y3Jy10pWfn9G1WoGdPLU3hhpjnzlPgvdldpLYnjx12iH1Cun XJzF+QZ2jorC8WV0u3Vr+hyPqdZGUdZAEJXHnpacKpwhcOWoXIzagphCXUMxvi5rS09NQKb+vKNWk SNpV+1Q+HZT0JroW6Zk+hTGrs3O3LPZ7VGM9jUUBBpklfve9rMUJ0LmqjhoMRJUZac2CipxijM1MG 46Q+S4Iw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syZds-00000009z1u-0v4R; Wed, 09 Oct 2024 16:34:28 +0000 Received: from mail-bn8nam12on2062f.outbound.protection.outlook.com ([2a01:111:f403:2418::62f] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syZTJ-00000009wSe-0QdL for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 16:23:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Loj2TqiceABW4PO3prqsIgmEXZkYUekzH3VuVJ+4TASz/xXNp84ixFRUUQG+YLL8EXppLdLx7c5p0jStBmAlNAzlBbuWmE/6rpnpFC1xQUB2nb6/gFa1Me7OgR4VcomcNNiudcZgksjbCCqvsIm9dpOcyR1D/5yR+dwhIO3rSk7Dhumh/JPocfvSOip0HFCNwrBWvJKpVcPfDI+WxZA+LBm5VlY742qyIGa2JE2WgcHtk90UzQsApNyjoTAr3Qbi73siMX5pwq1jgOA9fAaaRrs5lYNRqSp/NREixazR22sqxl69FDUprvJCPYupjkHH0WJs5xBi4YFqqjWFGL9esQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UM/OqRVKfdnk+8DUpdClNjxJr4a69tRo13nfkCjpyJA=; b=eVSAmg5MOcC29o2kC5Q2kaGcxAF3YFv0k+Fn4l5njeIfJ+h5nOnZn5xwmkMse6/AzGEerzuL6q0/PSZXll2XZq9zWJx6s0TNtPO5VAMhZJadwFKkUJXT+BBIz0RAlafHUT7pXjr5qn7n8DpKvoxItggoiDI2pLxobWk9CcjWOpbZQfoQKVnTWdWbGaJ/P04Cy8zgUzO8W77dB/g8fB9rvrAQco/i2AZ2ANKpjv7bpLr2wc7/8G7UnUgJVXxQjRrSWR7EUA7APziwBPsXAOl9R6WLK1SUBhU1rQCJeUlfXKoBy00Kw83q5vpw6AZsJjN+yJzXF0Bw1aAtAHBm1V9sQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UM/OqRVKfdnk+8DUpdClNjxJr4a69tRo13nfkCjpyJA=; b=CZEs+EjnQu+7dwxWbDCjVec05nOucftxscXNoyXH/Z7yzX0rIVP3+F0ZSd/DN3AEgCKfZqhZDNjQO1jnRiT5qDWp5UhAbM59/yerxYp+H0/bg+7PggdMPrexT2XEdywqM08uqAFbQZWG+VGet7wNF2oD74XiNIJt4YlyCFaC8xuzsZ1Oppq37zAmesD1E3URUo0hnONVp0vkvepHxV37KqaQm3kpkrOuMu+cfrO7fAIcjbCypq7HNx1qgJNf2Qe5FLMbRoqUfqsvMUJHhdiCr43I4f+F7bSzUSmuxjnZbCVlKi2+A78fdzdhGwsrrlaxj00rjPhtquIz2dJ49GBtiA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) by SJ1PR12MB6073.namprd12.prod.outlook.com (2603:10b6:a03:488::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Wed, 9 Oct 2024 16:23:18 +0000 Received: from CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732]) by CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732%4]) with mapi id 15.20.8048.013; Wed, 9 Oct 2024 16:23:18 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, Hanjun Guo , iommu@lists.linux.dev, Joerg Roedel , Kevin Tian , kvm@vger.kernel.org, Len Brown , linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lorenzo Pieralisi , "Rafael J. Wysocki" , Robert Moore , Robin Murphy , Sudeep Holla , Will Deacon Cc: Alex Williamson , Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, "Rafael J. Wysocki" , Shameerali Kolothum Thodi , Mostafa Saleh Subject: [PATCH v3 3/9] ACPI/IORT: Support CANWBS memory access flag Date: Wed, 9 Oct 2024 13:23:09 -0300 Message-ID: <3-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> In-Reply-To: <0-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> References: X-ClientProxiedBy: BN0PR04CA0150.namprd04.prod.outlook.com (2603:10b6:408:ed::35) To CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB8659:EE_|SJ1PR12MB6073:EE_ X-MS-Office365-Filtering-Correlation-Id: 71d76295-0202-478b-92f6-08dce87eae69 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|7416014|1800799024|921020; X-Microsoft-Antispam-Message-Info: Qnjhu8Bde1Oevx+ZcdHbbvYD8XC2lv5KVgjNlEl5UTmdQpOd6wkJ+fqMPIOwH2bP158razPk6Yl37NgeFaRAGu2n1KTM/TbN4r/YMse5MeAgL0qVz0yDj4Jhr+sijxQbL8+xovFPZ3dDWToFqqFE4R8cvt4Fx/PkpQl6dmXCZcstV/hLMCbWBGSu9N1fuadwcnYW77VzxQi7MQuY9xwVUNzvTqPeh79ISZONgG0rZAa7ya5pTSQxKTC15XmpyszAq3Lo6fCooWbmJMpDmBgUFXMEkSk4HJ0ng9ptx5669eY1+gOeJOk5T2efb1A9s8rc1FPOOniRNnY4GvnwpIfxwyVjoqObG5AhqeD4GARw7Sn9En8McfzlAG1Fbf34KQwZEId8S4cB2E2c2c97SAllHCF3ke4nhcvmhwmeBU9Oi98gTEpmrrbsHhzkHUyQdCEQxMJwJlMCsxOqbJndhSCVIK947S7tkC0eKLHXxLu0vyzogoAxwD9IT4aJaJISwbSbvZowqpiNtgzQG3kBwGWWqWZl5TTiQaLVfK4fn/T+m2s9WFhqtpTLaA724JR7IOuLvOHg/3bqS4Wf4nE8LbKkF51ciMoKs3xmvUlcmlHr+rs67WL60OuTdnaZ9JZ/GaccXnxmSysDw6FO7ZmRDA96uin/Z56XG07yGrmnVptpZOsCtGMP1sFUjLo4LQSedLGbodf/blD7ReFNprUbR9wg/WlvHkyo2oKVwLdFc1RPpDEvgDF/KePKujKoDvV6poUzGkXwsscN1LzC+PqoiSt1YXrRqjwL8ylGX17ZQ0vVAMviXKYjBdjuTPHZUS/ER615BWWXTOOsufCn9Cx7A+5V+yo2rM5rNSl2GhU8m7w8SQcvIxSYgJ06WRIRh14oXSQp8cfOZ7XdQZJrvhlA+FxbIs9WaG45n6V0t9o/9ZXJGVXbzd7zWhfNrkvroonTjGitKyZ1hWsLim7IilvLC3GS1ZWZAPHBHMS+XSO3bXaQkeSpHq6+vb8J3cXNvrzO65Vlro2u+6k3rybCQuG+091Y5FvStuFSOpTysIT4WkdI8wX4+bTeMlsPeeWAUmUDKaEFhljJUHUEl9fgT+AcdifYXpkPiglvMuKlT9wtcSlDO9AnzVHKZ93c+bfJm7/SIVQA6MA/nrM8vtHJOTkDEgs7JWJvt9nqiFXzfjFw10i145lr6ka5RXhG8UkM3RH3GxwdhPdz+Lu+gXDh6LZWvzFjj6y6uPw9T/nCiCUzZ0aUMRy/E4lcDYWUPN5mXxqbimcpjsS4WEJC4XGkZr0Oq1JA5Rxh3zOmMdiNBW1mppHGdK5SkceNhqRf8XojuHbz91cp X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB8659.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(7416014)(1800799024)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qxlGwldOWm2u2AuF3q5eCits0aUWddCIsL2PvyruTQN55dyrKUrHQ7riK5j2ZDF6XHFcJ7hkRCbzkQriL85G8tra8v50kYQsMVcjO4MK2plvfiiHGzuc3EYq2LsvSReBnP1mXNt3QMcj87rG54pppplGV1Em/BcitawRz8YPnGauneX6qE8GyrlIonbY1+qtLnrt/elc5Juk4giOc1swC3uCLZV9yd6gPsQAXl2NeFTioJYOfQ4vuzS/2PToBlE+R6q44iQJ7c2PTSU43vIj7oAPhhOJi1FYpZojgv6XcfWVZI+GDBhp9ERV56VK0fMC6ecIGUP/8VXN1/hle5LEvQSLvoN0pUV98h4dKvgY3Ei5vEvXKdixcGFCWIoduuNZALUQfrhMHTnSuYGGMEKoFfSOqcpw0emtUHM8IYXyoxIeHBSYPxfUw1VaTcQPMDMBs5+6PdHIalVU8yNGankzQcs4aEFlgiJe8g3T42I3+BI/ce7Cgwn1+/hh5kjRlXEQyXBtD2/Na4eVlIptorilqGN5OFtytGWc7j3UoYcEec6Z7CfVWzS330AYudpUjncHF3PgglACJdfdgt/3PzkFvtlh95ev2r6nD+gziGdSs2Dsd+VCMMNFO1EO+1XfzQ59t0F4JlfRMPIoBUhzV1/I/ojYKV2AshupFvuTUGZm/Ghw5T3kNo17/FK5qfFQbgFPeaIocBsdnaQuduH2ZSppvfDpitMGofBvgVc1Ya7qyKJDxtKcrzep2iitnmRUgjXsI9kwzl3Sd/GjEnBhaEGRIZLg/YUwU1dPKbFeRCYda1M+7jARW7p8fDXD/E5OihPKXBLT5xfyuwHpnamhiKFYPlhVqhZGY1oMDpZYwN3vVvnUESxQyUmbCfTT3XesDZCA3Kq+4eHoJpbtXLnj/ju5uwMAi2rYCnBbTGMp36yx0/JOdndVKPUmToo0OOGNObPQpvFwqr2o98mE/csDuCPpFkFN87j/48RUDWsV4ZrqQUgZT804eV7MCy0QWN3RhDeA4aYJjjLAsuGUVzKroGtrQJRYRBzWy8Yx1T5E5R0k3+V+m/U1X2jMGcBgjPBD5ylMpXThPita4NzdEoSDJO8qY5v1STzLefg6l1QfTlkPd8yjx3kB0Ad9Ylb1YCcJ4qnzLMLTjsOZWumPm8sxzeid+COAk9AXNt4R4wWvRbRSxMf8lnDDA/AD+Bhm2P0w7m7LrWDdrmhfS6+aNUY/P9ofgw2gRiA5ePHQiS2vWddYtNO2/g9eGf6AJYFMhr0/NSPCK7nP/hKGcFtxF4YzHfki7l2PPMHFZVrUNgn90rreHL1llzu+FmaJwFM2GO8RJp3eGSEcvU2EwEU//jJ3GCt9AmuI99SfVy+18E1e5snp4i9FRnPElug4XELZimjvNZeY3RN4ti3VYBwbWfBLEmyTKm0P4dG8RPibzkoTVFslnGLf+UDxHvOtNpXYlkc2ees4P0shWAXa0+jRS30YMmvsYRTmqpiehmq2v8LLsH6vTbu6GPd1NQGl8GyeMr2Pl5S+F95Qp+EGk58W3Eqi3SAXSGkjJpvBMaZ0c91rdDeN2ng= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 71d76295-0202-478b-92f6-08dce87eae69 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8659.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2024 16:23:17.0717 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fzV3DIQp0gkbWnuegAh+abXT7GjefFb21K/DvB7YXRKGbwcc7TYdp+rAtV4+a2bI X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6073 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241009_092333_470117_A81E9394 X-CRM114-Status: GOOD ( 15.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Nicolin Chen The IORT spec, Issue E.f (April 2024), adds a new CANWBS bit to the Memory Access Flag field in the Memory Access Properties table, mainly for a PCI Root Complex. This CANWBS defines the coherency of memory accesses to be not marked IOWB cacheable/shareable. Its value further implies the coherency impact from a pair of mismatched memory attributes (e.g. in a nested translation case): 0x0: Use of mismatched memory attributes for accesses made by this device may lead to a loss of coherency. 0x1: Coherency of accesses made by this device to locations in Conventional memory are ensured as follows, even if the memory attributes for the accesses presented by the device or provided by the SMMU are different from Inner and Outer Write-back cacheable, Shareable. Note that the loss of coherency on a CANWBS-unsupported HW typically could occur to an SMMU that doesn't implement the S2FWB feature where additional cache flush operations would be required to prevent that from happening. Add a new ACPI_IORT_MF_CANWBS flag and set IOMMU_FWSPEC_PCI_RC_CANWBS upon the presence of this new flag. CANWBS and S2FWB are similar features, in that they both guarantee the VM can not violate coherency, however S2FWB can be bypassed by PCI No Snoop TLPs, while CANWBS cannot. Thus CANWBS meets the requirements to set IOMMU_CAP_ENFORCE_CACHE_COHERENCY. Architecturally ARM has expected that VFIO would disable No Snoop through PCI Config space, if this is done then the two would have the same protections. Tested-by: Nicolin Chen Signed-off-by: Nicolin Chen Signed-off-by: Jason Gunthorpe Acked-by: Hanjun Guo Reviewed-by: Kevin Tian --- drivers/acpi/arm64/iort.c | 13 +++++++++++++ include/linux/iommu.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index 4c745a26226b27..1f7e4c691d9ee3 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -1218,6 +1218,17 @@ static bool iort_pci_rc_supports_ats(struct acpi_iort_node *node) return pci_rc->ats_attribute & ACPI_IORT_ATS_SUPPORTED; } +static bool iort_pci_rc_supports_canwbs(struct acpi_iort_node *node) +{ + struct acpi_iort_memory_access *memory_access; + struct acpi_iort_root_complex *pci_rc; + + pci_rc = (struct acpi_iort_root_complex *)node->node_data; + memory_access = + (struct acpi_iort_memory_access *)&pci_rc->memory_properties; + return memory_access->memory_flags & ACPI_IORT_MF_CANWBS; +} + static int iort_iommu_xlate(struct device *dev, struct acpi_iort_node *node, u32 streamid) { @@ -1335,6 +1346,8 @@ int iort_iommu_configure_id(struct device *dev, const u32 *id_in) fwspec = dev_iommu_fwspec_get(dev); if (fwspec && iort_pci_rc_supports_ats(node)) fwspec->flags |= IOMMU_FWSPEC_PCI_RC_ATS; + if (fwspec && iort_pci_rc_supports_canwbs(node)) + fwspec->flags |= IOMMU_FWSPEC_PCI_RC_CANWBS; } else { node = iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT, iort_match_node_callback, dev); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index c88d18d2c9280d..4ad9b9ec6c9b27 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -991,6 +991,8 @@ struct iommu_fwspec { /* ATS is supported */ #define IOMMU_FWSPEC_PCI_RC_ATS (1 << 0) +/* CANWBS is supported */ +#define IOMMU_FWSPEC_PCI_RC_CANWBS (1 << 1) /* * An iommu attach handle represents a relationship between an iommu domain From patchwork Wed Oct 9 16:23:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13828770 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2E5DDCEE32D for ; Wed, 9 Oct 2024 16:31:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=UpiN5oo4z3lvMmB3amQBIgcZf9ooTUIzQ5WEgszjOO4=; b=XNsyFNtG7uAe8rioL5PTKdOsLw DUr5S3MyXawkWmSfxr+aDyOZ66r77cqHGSCuu+jgf3EIr0l4jflk7PPsCLt4fMv3H9gb0ik/q67s1 lb6yhOl6FeNNbkf5NT91gpQG2ptqp8Mw7iX12eMy3+gZKgtyUKddUpRv/2So2yb3uqgv015z2IctM wA8DicYpRR4v52j+4/m6nhokk7WExvvwSbHVv/x2J7rYErpEqaOD/mNQPXrAfwKKkgkCebzQTRHER J4qjEoh05V1TDa8Uht50mXNlcJpELhkphNSoVwTQxvsOsGtjNz6tmcc0DNT/TWw8CiQh2Kb2rU8wD 233u0e2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syZbG-00000009ySG-3LgA; Wed, 09 Oct 2024 16:31:46 +0000 Received: from mail-bn8nam12on2062f.outbound.protection.outlook.com ([2a01:111:f403:2418::62f] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syZTF-00000009wSe-1ZnW for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 16:23:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KgANiwPFZXeKoUJymz/WPW8JF9ralZ/w7KSUo/dlotwQvZhrjqgc0uGtHsmx64NEcQ9v+aerPSSriQzD1KDjgAw+jOvojd/K4fuuSvkTYe8I87o/Y3GmypWfEKmcLSK0zAL5Tw9QpjW88e7gJvPfaqa6iVgOcudrfjXgkkXFA9MymrkBygDDLKm9t5Ad0A04SS6vtGEfv4w5AoCwn0nFVilnU62djbxGv1/vIQJcKBG7qXgjcQ6IeVQHpEz3CfBV2zM3OVxjYTbHq9PxNTF6OLEO+2rY8QkB84zk1VmGhV/7xfDHXdMdTO4GTc8xHiw0igEpqHY4C+GxAnrklwxKGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UpiN5oo4z3lvMmB3amQBIgcZf9ooTUIzQ5WEgszjOO4=; b=JBne/XsaUl58Ov+HzrthiGsND6PCL0HOYIEpCntkTxXgqaMgXj4Ifvnw8LVlRe8OoLLc1ihSYm6THhVRqPeDPY6cC0mGMlPzp5G1C6XYuyXEgLEVOhBPVkxtV1K67OMFZmcTQgega2K0zCldAAlunvnRVTCC477eBA8fMOsf3YYpfA1KeKPz+EHFHEwlw9uXIKbu7x1q+kr/Q+4Cn1AfFQTwdaaZj0d9Y36R85+B/i86b1AGnGTD1Og785Oq3pJxAqlEUoBJd9Hp+09+fRlWr98GgPI9qTmZUZEVaO4Q5h9sj5mOucaI+eQSw1z+EO1dED3pvF8jXt7U3kTtFI7huA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UpiN5oo4z3lvMmB3amQBIgcZf9ooTUIzQ5WEgszjOO4=; b=d50cU2wXXX4tpCgnPtBgw3FI+ThGtUmAiTH1UQ5VGYyTasQgEhYu2wCWokHn23qcV8EXFUzvuzAfSo5MQGPxiiy0BEH+XFXKNJFxIgG6eeOkYmFMcmZr6KOMxSSZlYjy43ohiSfWCzS6rojnuVWBQZJ5GCzF8Fl03LavhdeTe4q/+0BjDqafU2Ymhe8t+8oMPwzvRfwlhCGJ2ACwVavlxKndRy7zhe2LxPIVSlJFcgSiB1AsPJ+dodEOaBcVr25bIBiAqP9yyM9zWojGKkCYieC/vMxvtVYOyDh1yaPS6+ErHfGBZJhJB6QOmCTCrH3k5YSiZqVSooL2f7NJQ3CkyQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) by SJ1PR12MB6073.namprd12.prod.outlook.com (2603:10b6:a03:488::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Wed, 9 Oct 2024 16:23:17 +0000 Received: from CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732]) by CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732%4]) with mapi id 15.20.8048.013; Wed, 9 Oct 2024 16:23:17 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, Hanjun Guo , iommu@lists.linux.dev, Joerg Roedel , Kevin Tian , kvm@vger.kernel.org, Len Brown , linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lorenzo Pieralisi , "Rafael J. Wysocki" , Robert Moore , Robin Murphy , Sudeep Holla , Will Deacon Cc: Alex Williamson , Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, "Rafael J. Wysocki" , Shameerali Kolothum Thodi , Mostafa Saleh Subject: [PATCH v3 4/9] iommu/arm-smmu-v3: Report IOMMU_CAP_ENFORCE_CACHE_COHERENCY for CANWBS Date: Wed, 9 Oct 2024 13:23:10 -0300 Message-ID: <4-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> In-Reply-To: <0-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0224.namprd13.prod.outlook.com (2603:10b6:208:2bf::19) To CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB8659:EE_|SJ1PR12MB6073:EE_ X-MS-Office365-Filtering-Correlation-Id: 3b5bcaba-4be7-4cac-a8ad-08dce87eae39 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024|921020; X-Microsoft-Antispam-Message-Info: SqFRJX3mx2+QQomHypksFTpSykVYlvBUUQPHfoxgDh9g3zW2kDl7aWsxz4rj3OEntwiGVTNFGd+ttcmrIzwAvnLGCRE6QcWrFb3+SdcIdG0xZlOwoifYkT/QuPHIgxyt2MKdt4QaV/mvvrJNWUKfEoMvZxd5Atn0IhTR3iSweLtM9mJu1bYim9v0GaVMtTv023jJKTspzbSmUfwK6f+ajxP7bQ84/lMJqqEKxQ3JEpo1RL7s2XMqqE7ARDr4YZ17z4zq4PL3uGcmHOiYIe/H9UaC2QuX+JmprU2fOAPArZ2fKgljOlJnCX5sycy6+g9XFjNZpVdy5WViOhGElcgQHbMLGKEAVSH+jKha4ZvCj7G2D+xMFrj8GHYGLAyk8T5WAxg/GBnNDuPNsnpbF8zqp8BnXD/4frmZHWgAhOuLoBpikq5zuEFvxUqmfFp1BagzzUUYx9CkTJRq1wJz3TJormskKjHAsUkkMOS3Y53/3qcvAXYdG/rEOLogeKflfTnLKg1NPnJc5tjZ01F2gbjrVkEMM9eG2O8mok4o3uMf+jr73p2mSDcDt02QVv75IWzq2Z23Y7uudp0hRp1ihfGfg4DiYJ31fcdBbOif3muDmsAFtYu0mkuuc8MzQ7nB4XAPNtBdt1ZfC0VXIe5g+W4fJNpkRfsBH5ph0i9VCiHFPXYM5SbyI0e3BmXKeaBjLxpRVlu8tphO4wl9i0tJ0V9S/+G8MHzU0zGTFBZ5ysCjh005YmSfoTkev7tvLTubpoiS+AAwLPWVUfvfrq48jVqAPTPdMeamb6IU4YS6sSl/TJhkE2zCFxdceiyEs09QZymDo6bJlhIa0qTHu60MP1PWaUfZCz7ZeZORjiBihfRUcTUXluFFbT0bpOkZX+QcmNE57SYWUK/7gWWs0EEiMJbtMb5Xh3u3/MHekhoE/Ayy4yK1OfzHdP1NhmJ5QTyxTMW1bvtN49CKoBekKoBbH/AC7ybNDsEXIdDKZUjToWgjkFgpbNMM0xlHPt5JY2y6+Hput1qPe4A4yWQ4QRpXdmlhNvFr9nThc+v/X/nZQAFITWdKRIbl/dyuWQ+hvsTlCCL2vs6wqmSvA5LR+L9p91F8REF9fDt6oW1IlAei1sbgF8O6r853MYRhTOjj8DzpJO0GZPVqjXZZsc0JEy9KQXpvXblT5qD9Oki1aZa9KWF0h4JLj4ei/RW+3DWCAOt9GecxJHGkttNJtaRlIG3pAHkWQ+GJLpOGD92M4Kzf74qT8EyO8zTHBHYqxoa0kdWABWpo50z9a4HhfWLCG+ld0DNf/G+Vq+Wg1SvmFMOUR3p18szIwCpGMutzM8sh1QlWsazy X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB8659.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(1800799024)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: irmSj1wv0w71F+l/lFBXKHLFY/69FiKqeTKm1i+hz4A/mtEd7QCc5DN+cJNm45sutIlvF4bywdCrHTVkggSZAdbYI7Q7YXh7QVjnuDtEsSh6McL2vx57uBO3/7C5fn3lG749IAlnCfLpm/gJTFKOlZ2B2y3DmPjBJrfdbNQ1Rd+PklFLCMMuGIn71tQzd4LIeMzgf18WNe0J7PfVdGvBk4fVDBvGtE6gZuW42eJKZHl7zGbw2HrcLS8mdS0teP3MTTwyz+xAPMpoW35ejE+7XdgDAlr+VwQcG1q0IMIuDoxvrdpQmuf1c3A0stsfqCQ9rk9rWrOL+1XnWtf1cZnQQvRIlN0stMwP5akiDLvof61vC0pPLAwBnOv0qIHK4DhHxWvt++7AKdlQtF8/Nc5ndQDHys9yVxIoyE3k96rbDuFwxGBRJ+gGtv65BO4y+SMozK/PehiHOhUgfDsmz/uwYHTwIhhGT88o+MeChd9Ukx8G9EorpZFGAgq1Z+knq9BAlvzG98BlmwBiuHPQ8TUHgOxgNpFATojnR+ZFlM3jHSAuIZyXDq9b5z8V4D6Xxv4WXHtErHf3U0N2HX1djTx6/1Xmb6RbkD1SBfQLm80fDE+GcvDyu74gPawXJgUpHcN/BTTGClK++OTI8jDU148WdMVBUqhzurvA3TZyxjHutPc4nEpJVpQR7Jd33B1gJQA7pQ+jUPUVX8o4rgI4iv9z8CtiVpsIqm4c72MYQlnsfS3QkodBHvpBwe8v9fTB0RejdeWS8e6QqUcsdHW1iOslZMbOrP4B3tX1vaqqpUw+vr8ZtSsECti37GaTmm4lPZVlIGAVHmBkFD3xo6YxRUgsykOSOin1Klu848XHLKrH/ZFn3yxBSTpcwQUjesNxTf5z5TTD9kFsREV7MjE89tBL12Gy73sonu8qeorn8xZZ5rwBfyZePjkJ41t2Br3T5vQ9ZzEfaIz3aMSLI/uyjUOXrezo4tmVx8edLQupNzbOQPYS+IkmfRxd+CVsADdOQD4F1jhmlZeMDQXXZCzWC8gEDjVR7CWBfBJSjucKmm7Y9260s3nm8lfhXI0EUIoXq4aBo1up4fiv5yo8uSCrLsWP3bsWLU8n9bJKfRcC5/6ps4+sPUJhh5v3si8v8qCSUgecfu64VfxJJeicjOl1cyYvTj4+y1+o2+UjTz53JQKVIwWYIVH93wzAvWOM3yddHyDVtdD0k/RvKxoz0eXJHBR3TglLsCX61tI66wYznbZptQtGSWrOuFLOIOSOBFW5udlNketN8rJXCfxVDXJJpK//qp8t6pY27f6YatqYG0Snmt7wuwX9U7FcRSGdhcWFSraT2eWY6nrJJmOq7IQSr8t3ouTN7JeilzaoV7uQ4iNrSUukgIfc1CTsYqQ4SB421mZyffmqujvkN+ZyScWlOuz6sdGRkmy7kc98eYOGIZ4OgC9UeFBvnhDG/2uAalo6xgpkVTYcCsZzO/YW2ol2rhmKlLzlPz08YRfflf0U7BhIG1Wz99CitPamx4wiBXxC2wxOjvYQIVYL1PChEKBqKwkJV2rmqFy22JqPDR31kmXPepc= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3b5bcaba-4be7-4cac-a8ad-08dce87eae39 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8659.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2024 16:23:16.8492 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: WZi9RBK54LUj5/rXkaHwmnHi29o5N0cqg80YXVErXrHS0v9bovmVShySAx5LmxPC X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6073 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241009_092329_461610_DE33F77B X-CRM114-Status: GOOD ( 13.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org HW with CANWBS is always cache coherent and ignores PCI No Snoop requests as well. This meets the requirement for IOMMU_CAP_ENFORCE_CACHE_COHERENCY, so let's return it. Implement the enforce_cache_coherency() op to reject attaching devices that don't have CANWBS. Reviewed-by: Nicolin Chen Reviewed-by: Mostafa Saleh Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 31 +++++++++++++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 7 +++++ 2 files changed, 38 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 acf250aeb18b27..38725810c14eeb 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2293,6 +2293,8 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) case IOMMU_CAP_CACHE_COHERENCY: /* Assume that a coherent TCU implies coherent TBUs */ return master->smmu->features & ARM_SMMU_FEAT_COHERENCY; + case IOMMU_CAP_ENFORCE_CACHE_COHERENCY: + return arm_smmu_master_canwbs(master); case IOMMU_CAP_NOEXEC: case IOMMU_CAP_DEFERRED_FLUSH: return true; @@ -2303,6 +2305,26 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) } } +static bool arm_smmu_enforce_cache_coherency(struct iommu_domain *domain) +{ + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + struct arm_smmu_master_domain *master_domain; + unsigned long flags; + bool ret = true; + + spin_lock_irqsave(&smmu_domain->devices_lock, flags); + list_for_each_entry(master_domain, &smmu_domain->devices, + devices_elm) { + if (!arm_smmu_master_canwbs(master_domain->master)) { + ret = false; + break; + } + } + smmu_domain->enforce_cache_coherency = ret; + spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); + return ret; +} + struct arm_smmu_domain *arm_smmu_domain_alloc(void) { struct arm_smmu_domain *smmu_domain; @@ -2731,6 +2753,14 @@ static int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, * one of them. */ spin_lock_irqsave(&smmu_domain->devices_lock, flags); + if (smmu_domain->enforce_cache_coherency && + !arm_smmu_master_canwbs(master)) { + spin_unlock_irqrestore(&smmu_domain->devices_lock, + flags); + kfree(master_domain); + return -EINVAL; + } + if (state->ats_enabled) atomic_inc(&smmu_domain->nr_ats_masters); list_add(&master_domain->devices_elm, &smmu_domain->devices); @@ -3493,6 +3523,7 @@ static struct iommu_ops arm_smmu_ops = { .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops) { .attach_dev = arm_smmu_attach_dev, + .enforce_cache_coherency = arm_smmu_enforce_cache_coherency, .set_dev_pasid = arm_smmu_s1_set_dev_pasid, .map_pages = arm_smmu_map_pages, .unmap_pages = arm_smmu_unmap_pages, diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 1e9952ca989f87..06e3d88932df12 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -811,6 +811,7 @@ struct arm_smmu_domain { /* List of struct arm_smmu_master_domain */ struct list_head devices; spinlock_t devices_lock; + bool enforce_cache_coherency : 1; struct mmu_notifier mmu_notifier; }; @@ -893,6 +894,12 @@ int arm_smmu_init_one_queue(struct arm_smmu_device *smmu, int arm_smmu_cmdq_init(struct arm_smmu_device *smmu, struct arm_smmu_cmdq *cmdq); +static inline bool arm_smmu_master_canwbs(struct arm_smmu_master *master) +{ + return dev_iommu_fwspec_get(master->dev)->flags & + IOMMU_FWSPEC_PCI_RC_CANWBS; +} + #ifdef CONFIG_ARM_SMMU_V3_SVA bool arm_smmu_sva_supported(struct arm_smmu_device *smmu); bool arm_smmu_master_sva_supported(struct arm_smmu_master *master); From patchwork Wed Oct 9 16:23:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13828806 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E3625CEE330 for ; Wed, 9 Oct 2024 16:43:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hXoN2/k1t0N48cYu5/juISVNQw8ZQ6RwXIvLr02cO/A=; b=35Nxvk7iHEC5PMB8HTSDQmNFLW +5Sazqw8QqVEeHYVs2sXYFKvj+YN1Bo7m6YWXSo3JCvqQ2Dje50fsn80wEy10FIBHn5Ed5qTun8yO hsZq1mXZBnhreU7YP8ULqnh1jHfh/wVDT1ZvfpU/buq1Yacq1HeE/NQ6oQrtzEe00Ue3dBT65LimN KJE5ImDlBNouMuFe1De0dwxpQ9SajI+lYDmVgNzZLwYzN9BPITaNP00P8RpVOlIarvQxraNTicBmK bv3OLoJjRXJHoBcp8pSKok1bj8A/6UnTUCLbMBaNFpP2WIpJ8ZPyWeR7Uj3YYCqc+sDJ/gVcV0Tay UhsY9HSA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syZlz-0000000A1vU-25U0; Wed, 09 Oct 2024 16:42:51 +0000 Received: from mail-co1nam11on20607.outbound.protection.outlook.com ([2a01:111:f403:2416::607] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syZTQ-00000009wV5-2cvb for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 16:23:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Z4laIYW++xBmB1ZuVYycqqePTaLPdimffuByhiAsmWikmwM7byIIs2XISzFw7NoHEvttPD/sB2I+QFG3KBAsuAy+sGJ6qOKN/FpN81IMX61WDx4takrUA47HYJ6myY4Dl/Nci8AS3TU+j0MF+1Wpfyd9DvwQFPGd3kDGPIXUCQNC4SJwvKcVdA6etovFE99pebFQTHmxqXxudjK05PoaHhCuv06ZFe0fewCCtVDYghMcDGXWcMy6fQh2tHNG/lMj3SqFKjS2VX/sqXJVL/gpmNwh3CaChiYuotfIe/JFx3Cfx1jcLszr03PW/8cDn57l0zoMlA3OvWkAyAiBFj/A4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hXoN2/k1t0N48cYu5/juISVNQw8ZQ6RwXIvLr02cO/A=; b=t657nu++99pNIW4ZSgnUBSr2Seylg12eEqnaa1C3oTwORaMINo4zBJetZZoSBILvO4KZWGWB7iXwtkzogl2Aeo9WS1WWPcZ3Lwl5WLwzOeoZa6KceCF9nQOWai/43qm31a6yHCHPHQM+gF9rbD8RWtHBbHGhv/F2sMi41z9gPbN0TK6GOWV+Y9qzXKC68CpmZMVAdp3/JR8w9pQICHmy4PH9pFEltfsjr5J0o0Sgzwx+1+LDqc94wPvBIimyarwzYzDnOg+ocyseVs84iOPfgHo0K3Ug01cdQCrZOIoP+JDQRbhN6SrSyyVzGBg7tKqtkAH18Boe5dTAv6MOPBMJyQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hXoN2/k1t0N48cYu5/juISVNQw8ZQ6RwXIvLr02cO/A=; b=N1LftJdHK0xFXrR2z1orUdYQqzBBL8hdZb7gfmEoh9Zdo1qaQ3mNT6JRBgQkBo9LHo+AD7ZfqgUEjGjCNodJTAMwcmFZpKTqJC2suDPuVtrpRY161gha/+657BoZB+pfCl9t01G84Ls4XtWdTZWc9xREPGKiBPFn/sDno16lmfuaHEqw83ziwX5QMoYGHdooFYp/MNELpM2szPi3ZBcA4pQrEuDQl+MsBYBu5DyoDTsUlvwM+eXKyygcTxdJwLlG4atCoaQd4zwCfbiPKtJ4aWwiHpvbMLbM3G4GWLS5qO2NgssSyFLx8tPjsT1Af1ExHZVO2IiqjHsNMB9o61+epw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) by DS0PR12MB8768.namprd12.prod.outlook.com (2603:10b6:8:14f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Wed, 9 Oct 2024 16:23:27 +0000 Received: from CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732]) by CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732%4]) with mapi id 15.20.8048.013; Wed, 9 Oct 2024 16:23:27 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, Hanjun Guo , iommu@lists.linux.dev, Joerg Roedel , Kevin Tian , kvm@vger.kernel.org, Len Brown , linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lorenzo Pieralisi , "Rafael J. Wysocki" , Robert Moore , Robin Murphy , Sudeep Holla , Will Deacon Cc: Alex Williamson , Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, "Rafael J. Wysocki" , Shameerali Kolothum Thodi , Mostafa Saleh Subject: [PATCH v3 5/9] iommu/arm-smmu-v3: Support IOMMU_GET_HW_INFO via struct arm_smmu_hw_info Date: Wed, 9 Oct 2024 13:23:11 -0300 Message-ID: <5-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> In-Reply-To: <0-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> References: X-ClientProxiedBy: BL6PEPF00016413.NAMP222.PROD.OUTLOOK.COM (2603:10b6:22e:400:0:1004:0:b) To CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB8659:EE_|DS0PR12MB8768:EE_ X-MS-Office365-Filtering-Correlation-Id: 2f519bf9-ff0f-4af3-392d-08dce87eaf9a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016|921020; X-Microsoft-Antispam-Message-Info: n3kjIuG5U3fG/1tiOddWmxjlVbeuxQ4fZSVO1eZQdIZYnQ6pDzHrBx08pWVc+xDmhv2k6ZIjftoDYaqiyhRlYyncmcblZTuww/TNycgB1xf+0VXzB27/LcSHAZd8MTQOT97nsEOLf98Yb6es9HfUjK3mb1IYAe/odLyHFitiOGEyjS4KBiwebLqb2IfJyAsTb34oireEVKh1TvdsGTT78Zcy5pOrw4TYWTl2LDUmXWJrUvtsw94ZFpW+X2qHupqTbK6qG0wUBwTYDkp8mieY91FFg4VQM6HdhFY1XOad5RzOASjuQVYy24NrHsNyADy6/eWgfjHg2QA66Oem9QIJ+LwFVUFmkBQEGLIKBjBo6+3PuwWhfPGJQSYr610U1WqP9AbTXpK76cY3dcsQ1j3Oqo6rju0hMYUXnY6xJeXdtGS/ZNvG5X7RwH+SyvRjX9+rhtrAscowzCLpKuLo7e9FjSrBV2OKhNrECb2PxAuqM7qb94elhNmX0aQev1xjFO28XHMiyM+D4RoKT2fyxXJEar92RkgzTBVqT+uG8EKBCGAbqeM/VdOWQ+oCUVYSTPvOsmVPht5OQUk+DcBVRBtrojxBAt3Rmkwo072FV3o/886u0bVNYP3QB8ULF+67KPdcGKMK5B6YcO2Wi+ihsMT+Q3T8ClhvDtoh9tkZ15OsCDP97wWSbiRfX2GkvLHFbkiQb94AbSbXwL04pqA8u+dJT3JHDZJ/y5gyhgtlLxWB9VebNPoLAQU8xGrzyceV4GFv0gugZh1FFNOLomqlXnJlHGIEq/SxIQp2yXj7bUFX1Jo3htS7mIWAaBO3nQTDwwoATRTkVlARf2SbEhuT19L4z0WjQzcernoT3V3rOBudn77muV3Ko4ciC1WqJhI9dqHY9tuFdoO74ORmssDgf3ZT1Du4vv+/Zi4Mc0NusU/hQ3RQygMgQV+d08O1b7A0OSA44qGtWYTb5nHja6R/DUCEg4mcUQMMK/3IOUVjW/VqayM6q+VCvpH4M0hg+bEMOTE6NIbe0MuqVMSLdGmnkhLq907G+z/nueJFkfUint1cRnhz80nByjnCZHCZlaQXZFmxV8L1lj+psbXXv09EZV+xkifFpwSkya9GYw7ESHuGyrAYQf4Q99m9tVhcPiW2+3qVrSUDGpb+F8L4vprB/SThSd+eS2Amqr+fzeMuWs/KvLjryaIWL9d7lUY7IqZANXgWEi6lLwdoMf6mcjLu0HG8AgaxBXD+5XeutlywahDd+RpubXk8e8JsPf0eyR77PRfRYB8jCjBNtAQR54gfIWfvDmgUp6mIJyOgPfq5cHdG1vWHXGZ79paRWs9gnabwlVdN X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB8659.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(366016)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7Q2mOP1O3J2kZvsjlRE7zdyETcdPtaNs2Cn11wQQsb4eyIwz+lSc+cYrlupuHW5n10xfBqcldF6TRqzRzppdOyDoHa9VnZ6AktGyHSy8pdGL/AtvJaIX4Iir7pKyB1XXjOT0+rnz2gKwGk624eozq/w6QymRc+avguKX3n5zBRewI9A1jEQ3zUetjofD2vh13p880OY6BVqAwCgchWp8WDPzmyfwHQkstEG1G7Pj26dUxGwH2lpJzBk3HUV2Qv3EX9edgCX8Eqx2JOZID0WGKGDrKXw18er2FtbfgfHjypglTaDsUO/hjby12JfA5dLrEPJdV8Ee2H0y52wDrXuo732EAEqaeXHGq86XS3IeF9Jqpjbmaggh/2+IooQKeL2obpvcDiWp+Q0PQkcjQZLrNaolwBcdPA0GjFc7lg9LG021akDgUJZf9dQgefoXZC3PSDpeGPOcke+WL1DO/WxnWdFBON/Ke8927QuxLsOtJ+bqGUsuUEBqHeuaSK3Ji0/ND9WnzmWatoC3nTUeW3n1WFubuoj4VpR1zucsGoA7/ojmA9RiEvw3y3m6jAMs7bepEMhH+3NrzSQdjKQevDEM+cYosnfDcWRZaikqVUMuKQOxwEPS8j75ysQibrQ8rkQmPnGK0uc/+hrExBeKvlPP1nU8fEVT0/z+QV1cmU47GECdiuB6wOHnYbpXZr7Ii7BhXCuc4VFfamoM/7Fzxkgd1WIHEDmsHvLmYv4MvPiNVf8CEHl6IyEGUO8RRfy1Hwepj/mUlFWVNc+b7+3IOF8nio/eWHC9n3mkCFAHtqwgf0cyur5aCvPE5WgbeikMuYdc5v/V8j5XoDAaL0KV53y48+zoS7Y6M9fq7z2jiUl5hhaRHD00w4z7dQ6pXMcB33AjHBh84bdil7x/mRpkbje623aJTo8MQONlOCPIvlCdP4z/ZLgqZI9AXnWGZqAqXiDo95ySfrbOJsDCKRzm78FAr5wLRc0ztrbVljizKnym37PNJAQ2lZrvgtwXLOsSt2GBiGCYqm+6VXpX9vrxCJC4EUeN+uLhFj/Yo/l4dect5ZmSOyUpggpTJCGOm+/1tZhsX4nxjEpgX3rSu+LxUjlCosa3Tf0Sn1DcaT4UWIWQutERXRFCIuPQfe1EDeiSeh9XmJJajWpTuu6z9S0P547Nxx9KE1bsXojn/adVFnsr5Il7KimUGjJWPTJEnwBSYAGlfQSP0MuKMyM7FULz4gdBM9xwuHov3GLd4zYwMiQSnfNF7LipgtOqK1MGMKHJICsA751bWFsRohrGHbyx479gsUdg5vV4zKP5opytdZeQBxw7qiyQhwTFQLTgpcgpJhQ9Vvixrz5qAO2Qyb+tni8+/9Im+ZUzzxQg84B3uaHA29y17B8wuBkvAGsm1gIvRYcoW6qDK/FUGC2PzNiKYmulIjczkrxEYWjeFVd/Gx64ve7qzzPLbHZZD3wzKgUeFy+ZJ+hNOQ1lSRMH+RHTJ+MlyNhoBYHyZ36JBcUMdMgysVMZjjwtXVCVBwwR+2kVSAP/ceGxzlCDEW5KQE07RkGKa65mzparTNJJJ9YmGyHm+3M= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f519bf9-ff0f-4af3-392d-08dce87eaf9a X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8659.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2024 16:23:19.1540 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6zSpb3VB8aJ9YYsKUiAu4pXTbBV6w+NyEBRpqSdR4TXXQpWlAH1cGYOljTAB8Aun X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8768 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241009_092340_852496_E7A9850F X-CRM114-Status: GOOD ( 25.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Nicolin Chen For virtualization cases the IDR/IIDR/AIDR values of the actual SMMU instance need to be available to the VMM so it can construct an appropriate vSMMUv3 that reflects the correct HW capabilities. For userspace page tables these values are required to constrain the valid values within the CD table and the IOPTEs. The kernel does not sanitize these values. If building a VMM then userspace is required to only forward bits into a VM that it knows it can implement. Some bits will also require a VMM to detect if appropriate kernel support is available such as for ATS and BTM. Start a new file and kconfig for the advanced iommufd support. This lets it be compiled out for kernels that are not intended to support virtualization, and allows distros to leave it disabled until they are shipping a matching qemu too. Tested-by: Nicolin Chen Signed-off-by: Nicolin Chen Reviewed-by: Kevin Tian Signed-off-by: Jason Gunthorpe --- drivers/iommu/Kconfig | 9 +++++ drivers/iommu/arm/arm-smmu-v3/Makefile | 1 + .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 31 ++++++++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 1 + drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 9 +++++ include/uapi/linux/iommufd.h | 35 +++++++++++++++++++ 6 files changed, 86 insertions(+) create mode 100644 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index b3aa1f5d53218b..0c9bceb1653d5f 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -415,6 +415,15 @@ config ARM_SMMU_V3_SVA Say Y here if your system supports SVA extensions such as PCIe PASID and PRI. +config ARM_SMMU_V3_IOMMUFD + bool "Enable IOMMUFD features for ARM SMMUv3 (EXPERIMENTAL)" + depends on IOMMUFD + help + Support for IOMMUFD features intended to support virtual machines + with accelerated virtual IOMMUs. + + Say Y here if you are doing development and testing on this feature. + config ARM_SMMU_V3_KUNIT_TEST tristate "KUnit tests for arm-smmu-v3 driver" if !KUNIT_ALL_TESTS depends on KUNIT diff --git a/drivers/iommu/arm/arm-smmu-v3/Makefile b/drivers/iommu/arm/arm-smmu-v3/Makefile index dc98c88b48c827..493a659cc66bb2 100644 --- a/drivers/iommu/arm/arm-smmu-v3/Makefile +++ b/drivers/iommu/arm/arm-smmu-v3/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_ARM_SMMU_V3) += arm_smmu_v3.o arm_smmu_v3-y := arm-smmu-v3.o +arm_smmu_v3-$(CONFIG_ARM_SMMU_V3_IOMMUFD) += arm-smmu-v3-iommufd.o arm_smmu_v3-$(CONFIG_ARM_SMMU_V3_SVA) += arm-smmu-v3-sva.o arm_smmu_v3-$(CONFIG_TEGRA241_CMDQV) += tegra241-cmdqv.o diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c new file mode 100644 index 00000000000000..3d2671031c9bb5 --- /dev/null +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES + */ + +#include + +#include "arm-smmu-v3.h" + +void *arm_smmu_hw_info(struct device *dev, u32 *length, u32 *type) +{ + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct iommu_hw_info_arm_smmuv3 *info; + u32 __iomem *base_idr; + unsigned int i; + + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) + return ERR_PTR(-ENOMEM); + + base_idr = master->smmu->base + ARM_SMMU_IDR0; + for (i = 0; i <= 5; i++) + info->idr[i] = readl_relaxed(base_idr + i); + info->iidr = readl_relaxed(master->smmu->base + ARM_SMMU_IIDR); + info->aidr = readl_relaxed(master->smmu->base + ARM_SMMU_AIDR); + + *length = sizeof(*info); + *type = IOMMU_HW_INFO_TYPE_ARM_SMMUV3; + + return info; +} 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 38725810c14eeb..996774d461aea2 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3506,6 +3506,7 @@ static struct iommu_ops arm_smmu_ops = { .identity_domain = &arm_smmu_identity_domain, .blocked_domain = &arm_smmu_blocked_domain, .capable = arm_smmu_capable, + .hw_info = arm_smmu_hw_info, .domain_alloc_paging = arm_smmu_domain_alloc_paging, .domain_alloc_sva = arm_smmu_sva_domain_alloc, .domain_alloc_user = arm_smmu_domain_alloc_user, diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 06e3d88932df12..66261fd5bfb2d2 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -81,6 +81,8 @@ struct arm_smmu_device; #define IIDR_REVISION GENMASK(15, 12) #define IIDR_IMPLEMENTER GENMASK(11, 0) +#define ARM_SMMU_AIDR 0x1C + #define ARM_SMMU_CR0 0x20 #define CR0_ATSCHK (1 << 4) #define CR0_CMDQEN (1 << 3) @@ -956,4 +958,11 @@ tegra241_cmdqv_probe(struct arm_smmu_device *smmu) return ERR_PTR(-ENODEV); } #endif /* CONFIG_TEGRA241_CMDQV */ + +#if IS_ENABLED(CONFIG_ARM_SMMU_V3_IOMMUFD) +void *arm_smmu_hw_info(struct device *dev, u32 *length, u32 *type); +#else +#define arm_smmu_hw_info NULL +#endif /* CONFIG_ARM_SMMU_V3_IOMMUFD */ + #endif /* _ARM_SMMU_V3_H */ diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 72010f71c5e479..b5c94fecb94ca5 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -484,15 +484,50 @@ struct iommu_hw_info_vtd { __aligned_u64 ecap_reg; }; +/** + * struct iommu_hw_info_arm_smmuv3 - ARM SMMUv3 hardware information + * (IOMMU_HW_INFO_TYPE_ARM_SMMUV3) + * + * @flags: Must be set to 0 + * @__reserved: Must be 0 + * @idr: Implemented features for ARM SMMU Non-secure programming interface + * @iidr: Information about the implementation and implementer of ARM SMMU, + * and architecture version supported + * @aidr: ARM SMMU architecture version + * + * For the details of @idr, @iidr and @aidr, please refer to the chapters + * from 6.3.1 to 6.3.6 in the SMMUv3 Spec. + * + * User space should read the underlying ARM SMMUv3 hardware information for + * the list of supported features. + * + * Note that these values reflect the raw HW capability, without any insight if + * any required kernel driver support is present. Bits may be set indicating the + * HW has functionality that is lacking kernel software support, such as BTM. If + * a VMM is using this information to construct emulated copies of these + * registers it should only forward bits that it knows it can support. + * + * In future, presence of required kernel support will be indicated in flags. + */ +struct iommu_hw_info_arm_smmuv3 { + __u32 flags; + __u32 __reserved; + __u32 idr[6]; + __u32 iidr; + __u32 aidr; +}; + /** * enum iommu_hw_info_type - IOMMU Hardware Info Types * @IOMMU_HW_INFO_TYPE_NONE: Used by the drivers that do not report hardware * info * @IOMMU_HW_INFO_TYPE_INTEL_VTD: Intel VT-d iommu info type + * @IOMMU_HW_INFO_TYPE_ARM_SMMUV3: ARM SMMUv3 iommu info type */ enum iommu_hw_info_type { IOMMU_HW_INFO_TYPE_NONE = 0, IOMMU_HW_INFO_TYPE_INTEL_VTD = 1, + IOMMU_HW_INFO_TYPE_ARM_SMMUV3 = 2, }; /** From patchwork Wed Oct 9 16:23:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13828802 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 428A4CEE330 for ; Wed, 9 Oct 2024 16:38:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SlLcOotZn7KIOaZEjh+wsvcl99WKrYuATj4rVYT/KFo=; b=RyHDBf+z2jjolQuNE/0p9s/HbE 48bk7QkV20OMcfulKX/IUEi72r4mDgCPSwJWa2AhAm6emIiwnO8NclqnkxPbqNgXLFod0mW+R1KRB B08wc9FJT86/ZePhhfgpO9MqRd0LnQWfPk8OTL0rcGL7NS17YYMEKLz1lAr+YE5qrcfCFkdAcuoBi SVMmhPrP1WScZ7XNcFJjQyitc3cAQpmWY2k1Mc65ohhNGh/gtS8d8xUP5dsvUVPsVvsKDClShNbKC I0+f4Dhdy4WUD1hVFXRS5uu8Drdnv2YsYpRbeyKoeUuvWbvud6XoTeaxbdzBl136Jx2dqeDPlTmF/ /khwbYPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syZhm-0000000A0C7-1CPu; Wed, 09 Oct 2024 16:38:30 +0000 Received: from mail-bn8nam12on2062f.outbound.protection.outlook.com ([2a01:111:f403:2418::62f] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syZTO-00000009wSe-27VV for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 16:23:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VjpZAG7muyJcbbsEc6VJDy2rdTRtDpPsgoUmh2WjScWn96jIYzbH1PNOrqNbFT8La6z6K15zj/ta4p2aRXVM2FhRN5F59CVev5pPHWnKGmUI5cwuItypZXaC9hOULxjpNfQ5i9esGJ10FhInPY7kJITjPdyqts+GTo5ScKZoWRrxhFBeCMtSZdPxA7rKlVkZVKL53H6+M69OXOpfQ3CTWFRqJ2SjnUE7AVeVZvLGcUZtLJ6CBxOaZy7CWsxMwdO9cLNI6lZrysepIR7d5DZCD+ItdKl7gYYZfOL2ghzsmd42cXiVXu2mKacOG3is05H3mZ/JpVq96vZSo8oKd7JuDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SlLcOotZn7KIOaZEjh+wsvcl99WKrYuATj4rVYT/KFo=; b=RX1CkfmEg3SZOG3G6vJdJS+7z/dfdoCuQKyxBwopRGl/s5o3xB6mv9o/XvrbrSs+ATJR/PB2hzK3A/SIGjszs2wkSE7GTTD2u6H5RABGImJSp5N3QKX1Ph4L23Fv+dhmL9bmx2xj3Z5a3gfPuZxYFtS/LkyMWhsUd+pdu5cuAIAGbb2fss9Mj8DHvK8HSjnyjl8f3SfzAaXmyQF51iTp5ROKxNisFX6oemwfm4LB7eQqAtGMFSVr8eFpR9X8R+COxt66L7fFRz4CSpT215R5Vt+LnEwLLD5Djuonz7NlECH7DXcsfUZeGARLaGd1vacT4I/S5F1oFfbDHk7UI+qcww== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SlLcOotZn7KIOaZEjh+wsvcl99WKrYuATj4rVYT/KFo=; b=L0abM61li+IwBHOnjEj57Ld2YA3fd2R/WjAgNnMoyrGNwhVzHhCZe+2V2HPWZ4kHmDdPG6eid/0sH5Dy28+OY675bi2WH7ljsSPxpSrKBgEd6PwQiZ5HlBLUvuRPD37EdTHP6mo+jzRmLrC8huGX2pwYDp3Xhg2qTNXfo+wpomUrrE54lQ9OpVVg1laAumNkpDCW3a/QnN3SvHrkdzCbn2QWUAwCjregTeLglcm0OD80gNJnJNYQmbmB6r1AcSCpfwYVDh1nPRuDCGePRhxrGh0pWQzjbhZT2QPd7ZkFP+6T8/r56U1C+TfgkO1Dvzq7UyP+u4imRDEJLktQFJzcIA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) by SJ1PR12MB6073.namprd12.prod.outlook.com (2603:10b6:a03:488::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Wed, 9 Oct 2024 16:23:21 +0000 Received: from CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732]) by CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732%4]) with mapi id 15.20.8048.013; Wed, 9 Oct 2024 16:23:21 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, Hanjun Guo , iommu@lists.linux.dev, Joerg Roedel , Kevin Tian , kvm@vger.kernel.org, Len Brown , linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lorenzo Pieralisi , "Rafael J. Wysocki" , Robert Moore , Robin Murphy , Sudeep Holla , Will Deacon Cc: Alex Williamson , Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, "Rafael J. Wysocki" , Shameerali Kolothum Thodi , Mostafa Saleh Subject: [PATCH v3 6/9] iommu/arm-smmu-v3: Implement IOMMU_HWPT_ALLOC_NEST_PARENT Date: Wed, 9 Oct 2024 13:23:12 -0300 Message-ID: <6-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> In-Reply-To: <0-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> References: X-ClientProxiedBy: BL6PEPF0001641A.NAMP222.PROD.OUTLOOK.COM (2603:10b6:22e:400:0:1004:0:6) To CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB8659:EE_|SJ1PR12MB6073:EE_ X-MS-Office365-Filtering-Correlation-Id: 21fe00e8-0e1a-4953-213a-08dce87eaed4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|7416014|1800799024|921020; X-Microsoft-Antispam-Message-Info: EigncHmRPu74f2uvlLsm8lh+jcdT7adM4Y02T9GwFuNoD2EH3xkIr411UqiMU+EswcQOW4YK8PfGKPQBmPD7yrGxnc6wh/uEDZcEVZZMNm5zU19KiG7lqWzRo+GdsV3BUK1SYUhTsT0jMKJJG1B/SKCOdN0snjchxJB1gxkwgQ8fnM3rGXeP7XblDx+U/8aGv5HTsT3UD8hVFOhxkcG80ktrO4Q1Bn/YLHin9Yz+JGk4VQa5jCfn/y31NQMSpfvaDnoO/1A5LdcrEbskkQLnZhdlhlW54ReTCQWGRdBS+sReIHvsMPfluD/uOq5KGW4luOoUnAjj7+FFm4ZOJFlWRy2QCFUR7ojv1lni5c9BficDE6hPYNNapZxIDldya+50LSDJsVzs3EqwmVOmBq3U2XsNqU3D+zTbPI1r12JMEeQBUlhMNgbLmprJ8onASS3x1fgAI/Q1o/yydioIa6NQB+PNeNkgfPKOKhkQMVeXU9jSUdmn3uCQ0zRziKvNYXrCzNZZv++cxcpd75+3yLzIkxvtxW+uPsLxXPTfe3Hj5cUggrdiKyq3bIDbf0FiG/PgZ9ahS7KkO+8+AfUYB6BQR3xef8gm9isSes7cX6Mz9lwy3qYUqVMbw4k3hZ9JgCKwWuklo/cSmJmnP24vZ64OEvLTWO0270A+csHJ/81h1pdIlDjHfWWgdFBW8WDGLcT5kbBS2Jk/UHL8d+rzBJNfGPaGyhjccYcqpuAnwguAFHXlgm65KLGva5jirDuU9iqj10QRO6RZlz9EmDNq/toZ0unKdpbvVzdd6UjzexyCJ5RE9f9asQonKgJcL7UpTdhZ/M8Kw8/cB0RuibcmrzlZpo+6j0B5dHqEv3OcLYaZdIq70J6GS/PwXuChRHRHoEtanJ/l22m+uwlCVLAPAckzixBqOkrA8SMd8O+FNa97HRZoYx2BmypUsGQVbhCG3kKkP1OLnJC4nGWgLwe725s+EVI6Tftrv99ymFCUtnh45PXOPrd5K0vXMOrR/JKEp+n7j7rKCLEnxJtwlpeX6MOZGtTylqgVwrrDIPxCsC37xv8gGj2zwJaEl2mFbxi2Kv0f/lXilHYFYsh6zoRgfcfHzxnD43D8Ce7iwuKQ8nbooTIQbP+a6cYg+7h+ec5jgJLkYY0AIip6yiKRJTL/0iReYjpo78Qb0zBUgYWjaKin9vf86bXd2fdEmBHWG2npgHKXADK2hCGLqP37ehyA4r+HTIk7an/H+xt+hZ9TNRKXFE6lmXaG61FGucIlMCPJYK6+uZBG6kOabOdQgFi9KnUh6Mfk3leB7DaW2PgeKqaf+fiTTsJWeqJHEJOZYY4cPE1R X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB8659.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(7416014)(1800799024)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uWaSKc6V7eDdh4iQywFbqQEKY9bcRbzA0dDIDj8oewfEwWGzy70/0TRnM021Wr3BZwXVANadJThAoy8sYGEa6b4ite/xi3DssWsJUl9tHKqO+L4/R9k7BWIjE/MGP8HkANpo+MCNlxz5zhQwoUw4Gi/k9bkAUebuYpYBIRlS8BdOrvVEuWcmAvfW30wEKVD9IkVZu2wZunWJB7BalcQNuuq58Pq0eD8POIojumnAT8E/MRySVGWelIzuVfNXOyDzpCPzdNbwtQtaOSy2SyRAAUQLTIDkwg0AttuEsLmpfkGVxTGca59tvzvxD9RJmrWsNeUJwrLP9W13zPZHs+1MeZJo3TX8+yHa+jDroI1u730Ydi08LRX9LHSh/bOsHKVTC5dMLUS4yX8zB+B805uqSXSgtN2srhOpcEk0Sm/r5Xf+fkxbD5xeRIEFr5zinormw1pECrIHOApu0PrtuXFZu/0aCP2RZVX3Xk19B0DynPqzulj9y/DCG5xy4Fb2eaTHQZxoqRxNMa5HroebZB5/DHkwYFxWZO0zIAXnzEI2D9TXLaFJ/v10NcqOkrwECdRa3jwgf6pEq0Y4PPLuKtm6rGe//mLjlfnBs8+TvqlnVMtTREpWXD8eOEfUHu0s5TKiFo9tCccFg71w5MD+A4542wbUyjULXUoKIIXgLAXzHQpSSghkOpJvuSgICFrHsPVEWBXMugno4C7U5lWp19nwAnyccLBtRjxT8vitt+vvYZ5AE5m6g35CocUvtDnKAuWaF5suAsLjvgQBlcni7+YMOKGuvaABFKtZLeGTrvwqL1MPnTK2h8un+okwVyLmawvla9IIPlgdqf6oRF44o8j1znGh5+BWRHB1jy3dr2jPRyYAKXkrwXBajYCjTUnao7eCBDXjKyVVFTE5wcHY0Ky6C1MFGOjXZoMIAMls6o+9exNyP9QMcc3hv7RoBUzdcTwwrPCymf7/QRkGwR9ABAhBd2aX/5XM2b251FuAd5M/tawbJFXiA+oVjlw9r0eRRmdjeGR23W9AA48goS3Qp9QxFJLBtNG5g+r+ST7gzJ+nUiIwNV2LWI+X6X0goXR/mRROSnZr2Nt/yLGskb7mDLq4rSxLbqfT64hSBHZX6fb5GdvUyvQJJ2p4tbxwJgIr7d31PnUfivdPwfSyU8pzbQxMD7ObsQbaEN4RuvMh2a13WdpCE2QN1ll9PSn/E4nzpTveizf5LskzTVFnxs1numYB0cMEnUkNLUqdWWYVzhBNglQfAIRD5bUL+MAyhpWy0gTQUuMAr4Zqf2pMpsbFpdjy979Q0NXsUytXUdyf4E1BagkrbtqITNRXvKPBLDCgDQIHsgc+T6Gqk+JX5IRXM0Wusqw4GtcBxpxBOpJytUeC9zHlLJBnTSmMRPf8LCu9348ktj+6fb37jhqTgVUeGhti1iwbEF4zAqusVmrRJXU8dHedQjvH5BlqUH+zttODlNK5pb/IN43Ql759P1xil18dqDQlM4UGV1hzgkaqWwFD+yzL0jOx8bM3nsK/Mul4fvG9/MNfJak8O5PSAOa7rx6mFC0aGdcatElrTWCvDMxiC1U= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21fe00e8-0e1a-4953-213a-08dce87eaed4 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8659.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2024 16:23:17.7939 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7e5WfGQIzrqh7kpVor/W3PumPuSt60ZHXEJTFdgUFS9CdjxwhF3Mcf5KtKl7j+ii X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6073 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241009_092338_627469_D63F62B4 X-CRM114-Status: GOOD ( 10.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org For SMMUv3 the parent must be a S2 domain, which can be composed into a IOMMU_DOMAIN_NESTED. In future the S2 parent will also need a VMID linked to the VIOMMU and even to KVM. Reviewed-by: Nicolin Chen Tested-by: Nicolin Chen Reviewed-by: Kevin Tian Signed-off-by: Jason Gunthorpe Reviewed-by: Mostafa Saleh --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 996774d461aea2..80847fa386fcd2 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3114,7 +3114,8 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags, const struct iommu_user_data *user_data) { struct arm_smmu_master *master = dev_iommu_priv_get(dev); - const u32 PAGING_FLAGS = IOMMU_HWPT_ALLOC_DIRTY_TRACKING; + const u32 PAGING_FLAGS = IOMMU_HWPT_ALLOC_DIRTY_TRACKING | + IOMMU_HWPT_ALLOC_NEST_PARENT; struct arm_smmu_domain *smmu_domain; int ret; @@ -3127,6 +3128,14 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags, if (IS_ERR(smmu_domain)) return ERR_CAST(smmu_domain); + if (flags & IOMMU_HWPT_ALLOC_NEST_PARENT) { + if (!(master->smmu->features & ARM_SMMU_FEAT_NESTING)) { + ret = -EOPNOTSUPP; + goto err_free; + } + smmu_domain->stage = ARM_SMMU_DOMAIN_S2; + } + smmu_domain->domain.type = IOMMU_DOMAIN_UNMANAGED; smmu_domain->domain.ops = arm_smmu_ops.default_domain_ops; ret = arm_smmu_domain_finalise(smmu_domain, master->smmu, flags); From patchwork Wed Oct 9 16:23:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13828801 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A4B09CEE330 for ; Wed, 9 Oct 2024 16:37:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jT6Y5LUXQWoArwiC5FxjhovM1kp7zOqJgFz7SRJmliM=; b=xd8iXqHQhIDS0T57eiKOV6+i3S zGl/zhF61xLirUOGra6Y/SjYfEA4p79MzxORlflojsvz4MMV7ANXdjLWwwfUme9xq2bNAXPOZYfyN 2V/XxsZhyl8UG03jsnnpd103JEMUXTrzfOxh6I2xdRt4Ss8ch3/tnsi0EJjozK542jPVF7IMfiK3J Q12Zh720ysFVF37tyULcGiRMR64h6FGtB33l022+GhiJrT1sZQUoFY7COQke2ioE/WnQcX+LZexI5 /rawBY42vGB0yv1aX87KIKA85ydJ5pokvu2tilanA4Em1FtAcZ0JxY5XOZznle3rmBfYlDlHkFipv ElTrbl6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syZgT-00000009zqN-22UD; Wed, 09 Oct 2024 16:37:09 +0000 Received: from mail-co1nam11on20607.outbound.protection.outlook.com ([2a01:111:f403:2416::607] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syZTL-00000009wV5-4AnJ for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 16:23:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xM2/+PyHCF/aDP5xcUjr17W6Ul2zex0TtCIZNU6bI7gQ27pXREy8MaNiODl7qGB9LyQp72evhJP409OX0y+OIz4BHLnBTTPzr0h/wEe8FhCOLIJ1fjqYUGlAHM+0jgAuUPqB9fwFw5QC8DlVYBncIUo3qWvYm/5RkIQPHHor0xHHERe3NtU3u/gPQoSF6Q/aU6cspLO4x+9Syn5u+NhQK1HOZ2KTUvKpqsI6df9wi6FB9q7w2VciuWWAcpDZRZYGdEAWhUpQijT9ktExC6jdHm/WClIWRsntHozFhiA+vCuG26onbRYNBxDHCFLdc24nQfYr0cENrUW2h+4OOYrbHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jT6Y5LUXQWoArwiC5FxjhovM1kp7zOqJgFz7SRJmliM=; b=qhMmZG3J5RvxqyazREXyYklDTU+eMvRIcO4urdNXQ7xhk06AFn0Ht+CR3BECEJNDPU1Zv/BrZFJaAtm/i8d2YuACFAN9QDp1zJ4ib9Dz30BPDgR38fId1ZxhAUg7KfS29oN9s5Y7K+nihKlEERT7ec/L9qNvCbdqgJv5H+JYLDO8np5UlL5942FBNxOmhKxcNg8chT2kTMzAF//UDfhtEFvCS2exbQW0i1fwHgA6Q52kvtL2xBKBMFZjTPG0JV/weB9DYGVxAWKCUsqJU+XTc7YBRwf7ldompWL6tCzikK8it1RfyYf5qIMrJwf6TXQRCNYe7DXxDFDZVfyrqN0uEw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jT6Y5LUXQWoArwiC5FxjhovM1kp7zOqJgFz7SRJmliM=; b=iMigaRbGwZDtnaRrUu5viu/hrnTyNxmvrE2+8Q74ibmPLv8ZNd8qsxsuLWezEtbtLwLbBX+qX36zDUmzFpE/dhmLuKrKNEqLscQqwdvHdfR2wVWPq1VGHmexdEPpEVFO/Sher5MEUgDRbmqo7Ok1iyNUdOMylBXLjG5UV6RpJwT8KKOdiOhq5AhNgB3WtVXlpsaXHBHfPh8n1DTTg56uPo14EacAdOHPBfYSQK/xJrxEnOMbAlwkwJItUadhni5qbfhrKk3smjXbz+yOjMdYNQgGRv6iH/Y3aDMK2etHA+9Qr4YfRJcZzgDoEkGybNFeuLM/dIpnUZSJbK2145iwsg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) by DS0PR12MB8768.namprd12.prod.outlook.com (2603:10b6:8:14f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Wed, 9 Oct 2024 16:23:24 +0000 Received: from CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732]) by CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732%4]) with mapi id 15.20.8048.013; Wed, 9 Oct 2024 16:23:24 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, Hanjun Guo , iommu@lists.linux.dev, Joerg Roedel , Kevin Tian , kvm@vger.kernel.org, Len Brown , linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lorenzo Pieralisi , "Rafael J. Wysocki" , Robert Moore , Robin Murphy , Sudeep Holla , Will Deacon Cc: Alex Williamson , Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, "Rafael J. Wysocki" , Shameerali Kolothum Thodi , Mostafa Saleh Subject: [PATCH v3 7/9] iommu/arm-smmu-v3: Expose the arm_smmu_attach interface Date: Wed, 9 Oct 2024 13:23:13 -0300 Message-ID: <7-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> In-Reply-To: <0-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0027.namprd13.prod.outlook.com (2603:10b6:208:256::32) To CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB8659:EE_|DS0PR12MB8768:EE_ X-MS-Office365-Filtering-Correlation-Id: 0d113752-b73c-4cd4-f9a2-08dce87eaf4d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016|921020; X-Microsoft-Antispam-Message-Info: eXe1KiZLtsvSdPU5XJqEAUaDb3KcDQIAQxsGyCOh+gZjCPkeG3QCWq1dp2SHeM8eo4sZCuNaqb6/oaiyX0DztdVMyixjJh5YdwzwEHXupCz5v+40w3rXg0a0Tzj1GbCAhd/IPqk1vvGXtCt0C7FGX4Jc2rnzID9ddnGAnPUKXzFfeEtZIRJomS8T2UlV+miFlnL487VKamXImjBUEt9xRVcvomB7oczLB+ffpAhXw0KcyQXVjnknxxVJHr/rn4+KpRx/rraZxXO0XojN1m7fEveg4cyOuPNXKQAW8oYxIsrj/7LB3uXrdxssW50BlnQHlKgUlEsTifMbMkDz+bBLHtaKT5yMGnbrceZEWpRa0PGSUA4HuewmBu4NIKHhdstLdQDFFk/LwOR0sCXUrUMoYVi5NYSXUwg7G8VKvdUOVb+/qoGn7GfpZUWMhssCVnpx+6dGZMxW9DS4dJGjE/IFyNLK1shPA3fwHgPGUQpH+HUUT2rM+RPA6L1PL74kw0njnaznsjfO6Pqo4XJ4sVxNW4BSJ0tffD4SIG82JaRX2QWqF+3AFClUYt/Coj0yLyEqiUkXGgZya6h9sFrzrrjKjztI+CitKPFeUNZ93z0hSQE4B/GKzCbXobkcp1QvQYn5xFkh6itV8Mb3B/RFhPNdSxrHHq/jpM9SQr7YHaJQAsMlXK245S2LzXOPcnn5957FM3mHxghpdhfgYkO+pUN9OpaVhs237L4ZbVE4rSoeG3kun/wbxDgCvm6temIXrrRoc/1S8iMnZTJB9qzZnar3jjmlcS/4asNR6GhV2YLU00Dxsd9VtQ65k2GNhB20rNaclGWhFC+qfzdLaHlFDzo+dv3+vbYi7ql7RqY6Ia9apqL5Aj/AuHyLAj3dJfh7H1lFXVO4Fqsll2TauQ/WW/GZ2ZHHniPgWENxzeSiwDu0SCE/izbD4zWCFuLxSWUZebyMQI32f0Gk2OXoLbc9rC9WjjK3JEe/JNUeLqc1xPgz/Pk9ZA7wiV7zOjt68zKh1BiWvzdH5pmbBJCEQgyN+ReethmwQzRPsr8IkaJ+gpoapoNyCMwRe1ogj1pKgbnbtkW05xIrYtEqcuBwQRoPkUHcQn3C0tnnmFDhE9LIQ+jot4BZh7pHFnQbft7FRM9nRcjG5o/c42DSn0A9tOcutzvz9WNDjr8KvKsDkWMlEvtTcpyZjYHJHjax675EjvasfOBneZdaMoFKi2nze2pinnekPou/Hf+gMkhH7KfUiVNSPLyEaL3xZy1bRK9JZpb65V800+jHYjXIsUdIbXFH9YHjoXbGHkMr5pxgtMMs33a80GQokAciobWKOUDRNM7XYgKs X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB8659.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(366016)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jPBCbswzEzb71qftBregg+k9uYHloAu5HeACD8DUzVn8DZsVyZ3hpKdDxZtT/nVO2XrQmi/VBlbmR6IsD2mmnCK7Z56A9LQcGtJ0U7IULVwJAu6L1hhbhHz5rr/7rref8MJnrSm1NNfQSAmlJ4+U4U8DiTALjGG9NBiOwaQWwrUll0+1/0Tv3BQ3QOb/qQ+EQimZ9riO/SCrHMWT/lPR5Ijom11nNoyfv0gYDa2i7VdeYDJZOiK9ZJCSSVQHlw/DpIJJIH+gmAluuJZS+qiY5wvcsGXs08tuoP8ZnL6onV1vLLE4B0h3XZJqA47bVALe5duo6TBxZuKdwbBsdvSxT3fw5NgU7QqT2i7GZOnOT1+N+2q/8A7BVe0N7x3LSIzg+jrZkYGmvq1Wn5eO7pLb+5MT7hszUtVRs7FRy79mJLZZ5s1dK8TDEkHfSNag6AhNSMEbgf0BtXDt6mrztZTZSTCZM84Pe+EoXHPtBH4lqwDldSRdRWi10AHlNFO5ikqh+NwrYYzW9bqhEsyGlFmpEhqrlnBDXnb3DK34ahOV7UY81gvI+kQWAdsFF7MLrdznMA5VCC8FtG475cRBdGAKaEzj+k0RTzMnZYBEZjCZXCpSoV5SzOvi6oVYXHCV1tn5jsLdDim2II1jHAerIcAkmLH6TMCLwOdXvQqJLdHi2rHUoEO6egudmHDOVLG0DGSPNEEklPrZN6/4XU3dKY12GNBjCRYXFVlO7VUJbCk3nEXcRhbPTASk76HSgcCqFkwikKmgv14PKoO6NXQJeu2kMv1eDuwlKbb6J/UHVAAriYnz3SKqisEdUWxNFQS+8tTdJuWtgQY+Gsd+fIXcxoEwySJPP0vQX4vAdbcTkNsRG57iAVJzXo3PcMYbBqnIxPRC2R5Gj/26iSM7rIafpgi/QpjIov8w5DPTE3PxvLiQrHe6pK5kqPmm8T4IeltEksY2sRYoDv1Fz0/8nj4r2YAg4SwMG6iclJ3fLCGvQXVT10OVgtvKOfSZvSSkqQ3+li6HSbPcpBMQTNYRvP65Py+NEr0g6VhLYnwshfEPu5LVhLJLVw7j7GY9IH+CKFCNXs4mdujX4ikZGjAuZ2qEusmxFRTVeFFpEQut9MvPtWSSOGannauCLtclIJXTebxAoWBcmTwRTrz1pQZ7OPsSEgaxfJTp4c9BGWm4/6511NvuDWYwkHcGaEGzEiI2vIZIHTRFocuzL6EB4WSOgkwIa35wDLcp2ZCz57WThvyyEqa2x8ytcmlumvEkA7Vd/BxoLYFV4cwI1qDAIhYFOSnah1fRtivykxl7/7BbNDYiFCvSibVZhNfGjxGYqPYBfcljnEgwoD3i5RJhPrAkW4cv87zgsBpsQEiQUd6lbvwddr3LhXAEAALC5QtmdEuyeYqKjiNnMr+b5u0FpaZl7F+0hagAxPlsoUqn9LJJPtAJDBBjh82OARh0jXMlblTsmkxrEiZo1algJ/BfhvSYP+cyIf+326cwlaiZXaCsGBIGpazXTPuDLfsmHQZ0wC36N8N+1oUBTX26+jN1vd10U3vDYn6o+NXM0ei5p6/r3AWBXFwteX4= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d113752-b73c-4cd4-f9a2-08dce87eaf4d X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8659.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2024 16:23:18.5693 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RV3QZpXL9qUp5ARwKdZnmDLG33bkwAT55o14qCpseXs0MgMBrjgMcqFgQ6tQ/EJf X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8768 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241009_092336_087309_0A7BD2C3 X-CRM114-Status: GOOD ( 13.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The arm-smmuv3-iommufd.c file will need to call these functions too. Remove statics and put them in the header file. Remove the kunit visibility protections from arm_smmu_make_abort_ste() and arm_smmu_make_s2_domain_ste(). Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Reviewed-by: Kevin Tian Reviewed-by: Mostafa Saleh --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 22 ++++------------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 27 +++++++++++++++++---- 2 files changed, 27 insertions(+), 22 deletions(-) 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 80847fa386fcd2..b4b03206afbf48 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1549,7 +1549,6 @@ static void arm_smmu_write_ste(struct arm_smmu_master *master, u32 sid, } } -VISIBLE_IF_KUNIT void arm_smmu_make_abort_ste(struct arm_smmu_ste *target) { memset(target, 0, sizeof(*target)); @@ -1632,7 +1631,6 @@ void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, } EXPORT_SYMBOL_IF_KUNIT(arm_smmu_make_cdtable_ste); -VISIBLE_IF_KUNIT void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, struct arm_smmu_master *master, struct arm_smmu_domain *smmu_domain, @@ -2505,8 +2503,8 @@ arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid) } } -static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master, - const struct arm_smmu_ste *target) +void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master, + const struct arm_smmu_ste *target) { int i, j; struct arm_smmu_device *smmu = master->smmu; @@ -2671,16 +2669,6 @@ static void arm_smmu_remove_master_domain(struct arm_smmu_master *master, spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); } -struct arm_smmu_attach_state { - /* Inputs */ - struct iommu_domain *old_domain; - struct arm_smmu_master *master; - bool cd_needs_ats; - ioasid_t ssid; - /* Resulting state */ - bool ats_enabled; -}; - /* * Start the sequence to attach a domain to a master. The sequence contains three * steps: @@ -2701,8 +2689,8 @@ struct arm_smmu_attach_state { * new_domain can be a non-paging domain. In this case ATS will not be enabled, * and invalidations won't be tracked. */ -static int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, - struct iommu_domain *new_domain) +int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, + struct iommu_domain *new_domain) { struct arm_smmu_master *master = state->master; struct arm_smmu_master_domain *master_domain; @@ -2784,7 +2772,7 @@ static int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, * completes synchronizing the PCI device's ATC and finishes manipulating the * smmu_domain->devices list. */ -static void arm_smmu_attach_commit(struct arm_smmu_attach_state *state) +void arm_smmu_attach_commit(struct arm_smmu_attach_state *state) { struct arm_smmu_master *master = state->master; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 66261fd5bfb2d2..c9e5290e995a64 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -830,21 +830,22 @@ struct arm_smmu_entry_writer_ops { void (*sync)(struct arm_smmu_entry_writer *writer); }; +void arm_smmu_make_abort_ste(struct arm_smmu_ste *target); +void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, + struct arm_smmu_master *master, + struct arm_smmu_domain *smmu_domain, + bool ats_enabled); + #if IS_ENABLED(CONFIG_KUNIT) void arm_smmu_get_ste_used(const __le64 *ent, __le64 *used_bits); void arm_smmu_write_entry(struct arm_smmu_entry_writer *writer, __le64 *cur, const __le64 *target); void arm_smmu_get_cd_used(const __le64 *ent, __le64 *used_bits); -void arm_smmu_make_abort_ste(struct arm_smmu_ste *target); void arm_smmu_make_bypass_ste(struct arm_smmu_device *smmu, struct arm_smmu_ste *target); void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, struct arm_smmu_master *master, bool ats_enabled, unsigned int s1dss); -void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, - struct arm_smmu_master *master, - struct arm_smmu_domain *smmu_domain, - bool ats_enabled); void arm_smmu_make_sva_cd(struct arm_smmu_cd *target, struct arm_smmu_master *master, struct mm_struct *mm, u16 asid); @@ -902,6 +903,22 @@ static inline bool arm_smmu_master_canwbs(struct arm_smmu_master *master) IOMMU_FWSPEC_PCI_RC_CANWBS; } +struct arm_smmu_attach_state { + /* Inputs */ + struct iommu_domain *old_domain; + struct arm_smmu_master *master; + bool cd_needs_ats; + ioasid_t ssid; + /* Resulting state */ + bool ats_enabled; +}; + +int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, + struct iommu_domain *new_domain); +void arm_smmu_attach_commit(struct arm_smmu_attach_state *state); +void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master, + const struct arm_smmu_ste *target); + #ifdef CONFIG_ARM_SMMU_V3_SVA bool arm_smmu_sva_supported(struct arm_smmu_device *smmu); bool arm_smmu_master_sva_supported(struct arm_smmu_master *master); From patchwork Wed Oct 9 16:23:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13828805 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ADA4DCEE32D for ; Wed, 9 Oct 2024 16:41:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AtyZeUfVqQGF+J92e/Ex+NfEnCO3YPW4rt3u8dymwIs=; b=vGlOvDQQhyNWmBT6lW3eDpfkia ZXgunPFhxLQJFK0vv7vfS8WtpFe6xtQxSEbI/1RGpHIxgKQEDBgYrGh6D5huiD46myk3dAK5JSMf9 F2M/+4bRGg0EY24yKstR1MpZ0a0xeLTuqJeo50qSNpt6Z39sALK7MXzHvt9EnxfGty1iiteOf4H61 3uwFkMFGmkSNHud69flYp1WFSA5fR3kHTaM7okkc3mwlAMDu1hFqvsvuZOIEZBfUmgAnbUNeW5Gmf Si5AzqaFqrE258r2Xw95Vqs1KaIbO82EbXKO1nlxkxn5+o5AArSaZKIUDdjjFZCiOt0qF39yrr7mQ SSdZmWsQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syZkd-0000000A1QB-0sHN; Wed, 09 Oct 2024 16:41:27 +0000 Received: from mail-bn8nam12on2062f.outbound.protection.outlook.com ([2a01:111:f403:2418::62f] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syZTQ-00000009wSe-1bat for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 16:23:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BOJQKsvd8pGoQj6v6NjZ5eAxB5cQh9+vqiCUHAoFPT4HcAVo2AZ60pRY6XH7p1cUbVhMU2qj+U82h4Y2TX3JW5SsgV9RGPN9ycNeIsoWMpEVz6JtkCTpVrb+BKkb8TrC2piYTNk4OJQHSdKtH/oYyRn66Kl4sn1BiTy3dczBiYJgVpaFLGT5m3F4z66AfHNAN8lHTFYYHAltdvmzv06b573wTadcDHdwJXKPzRCGNTESpKESY5YR8n7d40V27sRHn0vHHXNg5nvxj0hcGo6RBPBnnL1jJFHAvEfeP2pdpSZTEbzL5GT1IWIFih4+SJqZZZsVBHIWWZwjDf2rFwjM/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=AtyZeUfVqQGF+J92e/Ex+NfEnCO3YPW4rt3u8dymwIs=; b=jJ17CGYEI595qlH07ysOnzS4lEKsVLJ+zpW5qA4O57betT3JY8rsojoxCKhuTm9GTZTvN84LPilZYPbpfdU2RZqASefBOYRYF3eJ3Nmi5XnHBQfW/r9zeFLKOKJPnN8+zB5eG4xlVmR8jSeCbt40fiq3YVH7OC5q60wiJmn6+98VAyPA9q/94fpHQ/M75Dkdy5QIGDb0MHRlaH/wjxG/X/HVEB+ZWrLNSR/0kitP3D/S4tX6cfKrR1EzOH9wT7SuvvGs0Wrt+8nc0PBq+7a34+KBJv4uey2YNKPHgWuUjoEnmc8cz4qKn0obMrLH4Tq4LqCVkNnYXjkfrId7XYMBAw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AtyZeUfVqQGF+J92e/Ex+NfEnCO3YPW4rt3u8dymwIs=; b=WP59PQSVodu260F+XMV+x2ZpSxJW5tug+aRRPJlQUfOc+Y3OdkvSNrZH8fvNhRMu5FVPdjF3LopeI/uXEYCEMbfZcgjnbH52TPIq9vAGl10RPS8CS9Y/DZPlSs51/OoecXDk11NZcUnyuk3aIBWR13rc6AuhqrCb83Vt0OP0gBgmA57nHRksBhgGZtA+GoJMTmAX/Tho/mKd0oq4R8f8eArW3+Qs1qN1MkieYEOfG9ZRh3ZuWyzFrsyD3lKOG+DXIFIJmWFUP5C6D/9PUXclAYGDJwhTN+WpCQUUxMF2PVRNJ0mHTF5QENRTZpmMw0NmjYDxXEeakYxMYwDSrJ17ew== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) by SJ1PR12MB6073.namprd12.prod.outlook.com (2603:10b6:a03:488::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Wed, 9 Oct 2024 16:23:22 +0000 Received: from CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732]) by CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732%4]) with mapi id 15.20.8048.013; Wed, 9 Oct 2024 16:23:22 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, Hanjun Guo , iommu@lists.linux.dev, Joerg Roedel , Kevin Tian , kvm@vger.kernel.org, Len Brown , linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lorenzo Pieralisi , "Rafael J. Wysocki" , Robert Moore , Robin Murphy , Sudeep Holla , Will Deacon Cc: Alex Williamson , Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, "Rafael J. Wysocki" , Shameerali Kolothum Thodi , Mostafa Saleh Subject: [PATCH v3 8/9] iommu/arm-smmu-v3: Support IOMMU_DOMAIN_NESTED Date: Wed, 9 Oct 2024 13:23:14 -0300 Message-ID: <8-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> In-Reply-To: <0-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0020.namprd13.prod.outlook.com (2603:10b6:208:256::25) To CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB8659:EE_|SJ1PR12MB6073:EE_ X-MS-Office365-Filtering-Correlation-Id: 275fb3f3-e540-466e-2cef-08dce87eaee9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|7416014|1800799024|921020; X-Microsoft-Antispam-Message-Info: uDjN32kFZQexoxC52aRugyqIm6xXk7RhgbYv3jR8YTpn3ZQ8wi17jEoXzkVPO8gnFc7YkGbHbx1b1/Fuf8Tf5mmZvusHaqrEaouo4XIkshurJ1oXyfv4ipM0CtsCM+V4khC0IwbS2GXXo0iaLpMEK41Nlm9NJs7+2p7L5YCdIWHEr0IWBgigaJSLrNBFJghgXrKKV0YGGLLzS3zojubUG91aAfeS+Jea2nOyconQdE4bVyahgA19EB6I91eYKu4Kn4o23QG/waQBkBwShbFvLlWeMXxCuSkuR5tgrTS1d6+vee6DrpMwbaGwsuR12bBTW2yL7FaCnCSPNypaDWG5HvrOALR3tY5vW+MdWr1uPm/lxuTFF/l1ThMX2USycEBzJokUbO6i0KQauLXGdHaiWL0AMbQVSxT0VNARmUGLxDVam3cxtl4OXj2KbE4gIIUentDA6CoSVufODcDLs7TMH+faS6DOppI1yx8Cx8ZRmF/tfyHOQRhp1R4upj4/mRg08Zlh1DsM5as8Mhw3Q/q/sd8UYesYhdz3REqQBVgzhdF9DWH0C2m8APU4XsHJEXBFIuc9Iz9pviz4IvAH6EDK4AnEtLjwK2plu78yvjfXQFUPjoSgewNvbFTUZgwTV7km/KDuW5xya0kXQjheLloQHE3sw+qyxGKGDUY7JHwB78UPaq7N5Cn4GILX0HJ51UW2oqJV7i4B3MWAf1FC6iDUMuus08Qm3NQdcB2ry9lOO53b5X/xUkTkS7PWtpHFIujdqIoo82llQ/6kwpNu69NpkiAam4pAbqMqY+Mj/ubNQr/rZFCwW2j+Ew/isXYheoOdq2Yq4pBXD/JPPREuQavC+B0dD8GjE7TNsFoSqJ18gywX1Ty/cTcPC2hhl5GzucsDLpRKSNLDbkOrZWRnwfqMlanKGFOXmiPBsVr9IzIJxwiMdVykqv20su0oKiMkmV13yL8PETOsHD7cvztWV57PW5I5c5wefmHGKfJIjjW0rzZ/IzmCbyRRQqgqLN51BJDFE992WEzdspYHjlW6JKIUKylbgD4i7PQNvKK7ILrFI3gv5Aiqm5Ar2ncUfFlSBDvP+y2A6Wue+TiJ2sOOzXUeQauVaXxwYcUi1WlBN2SRQJ9///Qixmw5fpCg29Oi9Q+T3IlBz5foD7q9lFrnh8jjJqnI60BtO1GciIvQsCnePyVfiuvGwaOoTKYD7YbJ7FERXJLyps2UiRBechGR33IPgnhwahgq6VYNblSTpCQ5xBH6Nq2jkViGoRvn6ddWYO/mq9kYta40ZOrn5BU1y17357W49hOQyDfRJQJiyz5zOxMupz2Ab+6Qx3AKJxfxBIfI X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB8659.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(7416014)(1800799024)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: G7mub9zJeUEvUl4ZLcffbxwrxPP/cklt+6NX4dxmljmwaoFRR1yRWmTvL+1jmVKqODsj3Ogke6jeenl3X626mMJuHJZwAuVzd0q2lw+xJdv60hqtCOTo/AKyrBw0k9ZdUIZODa/C+21AxCkPtfr/SUd0BRmfIv14h4sxK4ES1wSkjVhE8s1u0XkIECnh0p/S9UVlluERyA4c6bBxXfHhKJe/ElyoIOOpiEPWTYvK317nLD1iTKnw//ZiqAfwXyqJKk+GhpTnbMtl2DfAoNwIWgpdwwZDErMDuLtWvTOY1kuGYaVvU2TJvZQmEIIxyFZVD4zZw8lTRcrrRLpqRgKOYc8fIn980VRvP9zEQHVrLDlv0/sW6xGxw9qtdZ5kFm0bl81bT8oSydqgH8H498tO2xV4putrn+AaJB1tYAf7n9B7gdxe0e6eCA1+Zb/sBFXsWrGL/FnZLAabfjjRGIH2LZ0ESwI51aslYzYCDa9/jYmyP3lVaCKmwczFV0Tf8ZJZtFj4ieCKfe39Y143nXXD4S6vU25m9XliTjPOMCW8iJl8rSfzPoV2QFyu044LicHJJiVf2hCgkjoAqCudZVuSGsO4FeK71alZuaNc3rFs5DLGZt12/eOxUOjRs163w9QctP7Jvjyvm6lj1r9mINpE60Jar3958IWeIA7NyxYobfVwPkMfFKKjmV1cyqMxZAsx1lxLneIHrs6O90uw/rt2i753ueqE1iHaEXqb5zBMJXePFbmfCYtWW+haczhLhIAzOC4baoPyE8w1KTEJLR4ixbvFfuyCg1s0do0BhPzUramW4/FaGa/npAurCh2LZyNCUwDPyFUi3JiPZm9dLlk2gDrhUdmRAViKbSzGlYDOEde0Th6CflLEOm/ErTUgu5tdyqq3gBY+INr7DJeEMEa3xJK+fZcfjX52Ev7aUXs9bpimTBiLzW+DOcv2H3vo96tXIQxjBZ8FlsTXaiXEkNZUaRUWJ+nGTRefdsAR9UN96Y4OjN020u/WLpkMDTZ71nwEjyfDPaT5uASno3NjLlPlHMnD87ZM2uyecezWji7Tf8AN/kZIJRaCXDkyFPuQa8vDwvjyffYgqXxOw/DcDTsrgH8qdhj3aJxpeOn/LeQUI9d3Cfj+XbNpKAW65K3inDKSQUWnusGzPUU3xUxv0HCzSadvsCB+v2GQgR4YHaBzmf88/znxe2AoN5Lu6OivNWnwy525BYGP2WE/wBqtMuZIhJvqseoPZftkVW4u8WmLs1CPxYf4KD+Co3/Z6h1s7B/TlR+6aWBzUkw5CgtDbL8V9ZWA+9JpeuTxektLLahWTJKHX4+77F/Pv6hdrEvPwHRzX9WxzDDWaShKZ5oFW5y6x60Z4hSajUjKREMATzDnaHYL4O6GGjlg8SKPP6DYmLeV1E5mDmcNdJF+otIinxPzkfXBxL+BERZ1xqWva6cLtnr/Km8e0H13MYj4Ot74NxmpiXJ48BE6a0TyMu4wo/YYQxWO2tQR1nZ5UuZl7Y1nEvEqcznGmRkLH734DuUIO+uwjPbW2MJPLy9yoY2WD7FfZeO8tQl2h5ovNosv+1wGp80= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 275fb3f3-e540-466e-2cef-08dce87eaee9 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8659.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2024 16:23:18.0294 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ZQ8inluB3mx/TrznFevgN0AY9V1FKGD2pS87on0qWqZdoCB6FVwqnqX3RcaCPEcl X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6073 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241009_092340_634036_6195CACE X-CRM114-Status: GOOD ( 22.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org For SMMUv3 a IOMMU_DOMAIN_NESTED is composed of a S2 iommu_domain acting as the parent and a user provided STE fragment that defines the CD table and related data with addresses translated by the S2 iommu_domain. The kernel only permits userspace to control certain allowed bits of the STE that are safe for user/guest control. IOTLB maintenance is a bit subtle here, the S1 implicitly includes the S2 translation, but there is no way of knowing which S1 entries refer to a range of S2. For the IOTLB we follow ARM's guidance and issue a CMDQ_OP_TLBI_NH_ALL to flush all ASIDs from the VMID after flushing the S2 on any change to the S2. Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Reviewed-by: Kevin Tian --- .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 172 ++++++++++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 25 ++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 37 ++++ include/uapi/linux/iommufd.h | 20 ++ 4 files changed, 250 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c index 3d2671031c9bb5..a9aa7514e65ce4 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c @@ -29,3 +29,175 @@ void *arm_smmu_hw_info(struct device *dev, u32 *length, u32 *type) return info; } + +static void arm_smmu_make_nested_cd_table_ste( + struct arm_smmu_ste *target, struct arm_smmu_master *master, + struct arm_smmu_nested_domain *nested_domain, bool ats_enabled) +{ + arm_smmu_make_s2_domain_ste(target, master, nested_domain->s2_parent, + ats_enabled); + + target->data[0] = cpu_to_le64(STRTAB_STE_0_V | + FIELD_PREP(STRTAB_STE_0_CFG, + STRTAB_STE_0_CFG_NESTED)); + target->data[0] |= nested_domain->ste[0] & + ~cpu_to_le64(STRTAB_STE_0_CFG); + target->data[1] |= nested_domain->ste[1]; +} + +/* + * Create a physical STE from the virtual STE that userspace provided when it + * created the nested domain. Using the vSTE userspace can request: + * - Non-valid STE + * - Abort STE + * - Bypass STE (install the S2, no CD table) + * - CD table STE (install the S2 and the userspace CD table) + */ +static void arm_smmu_make_nested_domain_ste( + struct arm_smmu_ste *target, struct arm_smmu_master *master, + struct arm_smmu_nested_domain *nested_domain, bool ats_enabled) +{ + unsigned int cfg = + FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(nested_domain->ste[0])); + + /* + * Userspace can request a non-valid STE through the nesting interface. + * We relay that into an abort physical STE with the intention that + * C_BAD_STE for this SID can be generated to userspace. + */ + if (!(nested_domain->ste[0] & cpu_to_le64(STRTAB_STE_0_V))) + cfg = STRTAB_STE_0_CFG_ABORT; + + switch (cfg) { + case STRTAB_STE_0_CFG_S1_TRANS: + arm_smmu_make_nested_cd_table_ste(target, master, nested_domain, + ats_enabled); + break; + case STRTAB_STE_0_CFG_BYPASS: + arm_smmu_make_s2_domain_ste( + target, master, nested_domain->s2_parent, ats_enabled); + break; + case STRTAB_STE_0_CFG_ABORT: + default: + arm_smmu_make_abort_ste(target); + break; + } +} + +static int arm_smmu_attach_dev_nested(struct iommu_domain *domain, + struct device *dev) +{ + struct arm_smmu_nested_domain *nested_domain = + to_smmu_nested_domain(domain); + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_attach_state state = { + .master = master, + .old_domain = iommu_get_domain_for_dev(dev), + .ssid = IOMMU_NO_PASID, + /* Currently invalidation of ATC is not supported */ + .disable_ats = true, + }; + struct arm_smmu_ste ste; + int ret; + + if (nested_domain->s2_parent->smmu != master->smmu) + return -EINVAL; + if (arm_smmu_ssids_in_use(&master->cd_table)) + return -EBUSY; + + mutex_lock(&arm_smmu_asid_lock); + ret = arm_smmu_attach_prepare(&state, domain); + if (ret) { + mutex_unlock(&arm_smmu_asid_lock); + return ret; + } + + arm_smmu_make_nested_domain_ste(&ste, master, nested_domain, + state.ats_enabled); + arm_smmu_install_ste_for_dev(master, &ste); + arm_smmu_attach_commit(&state); + mutex_unlock(&arm_smmu_asid_lock); + return 0; +} + +static void arm_smmu_domain_nested_free(struct iommu_domain *domain) +{ + kfree(to_smmu_nested_domain(domain)); +} + +static const struct iommu_domain_ops arm_smmu_nested_ops = { + .attach_dev = arm_smmu_attach_dev_nested, + .free = arm_smmu_domain_nested_free, +}; + +static int arm_smmu_validate_vste(struct iommu_hwpt_arm_smmuv3 *arg) +{ + unsigned int cfg; + + if (!(arg->ste[0] & cpu_to_le64(STRTAB_STE_0_V))) { + memset(arg->ste, 0, sizeof(arg->ste)); + return 0; + } + + /* EIO is reserved for invalid STE data. */ + if ((arg->ste[0] & ~STRTAB_STE_0_NESTING_ALLOWED) || + (arg->ste[1] & ~STRTAB_STE_1_NESTING_ALLOWED)) + return -EIO; + + cfg = FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(arg->ste[0])); + if (cfg != STRTAB_STE_0_CFG_ABORT && cfg != STRTAB_STE_0_CFG_BYPASS && + cfg != STRTAB_STE_0_CFG_S1_TRANS) + return -EIO; + return 0; +} + +struct iommu_domain * +arm_smmu_domain_alloc_nesting(struct device *dev, u32 flags, + struct iommu_domain *parent, + const struct iommu_user_data *user_data) +{ + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_nested_domain *nested_domain; + struct arm_smmu_domain *smmu_parent; + struct iommu_hwpt_arm_smmuv3 arg; + int ret; + + if (flags || !(master->smmu->features & ARM_SMMU_FEAT_NESTING)) + return ERR_PTR(-EOPNOTSUPP); + + /* + * Must support some way to prevent the VM from bypassing the cache + * because VFIO currently does not do any cache maintenance. + */ + if (!arm_smmu_master_canwbs(master)) + return ERR_PTR(-EOPNOTSUPP); + + /* + * The core code checks that parent was created with + * IOMMU_HWPT_ALLOC_NEST_PARENT + */ + smmu_parent = to_smmu_domain(parent); + if (smmu_parent->smmu != master->smmu) + return ERR_PTR(-EINVAL); + + ret = iommu_copy_struct_from_user(&arg, user_data, + IOMMU_HWPT_DATA_ARM_SMMUV3, ste); + if (ret) + return ERR_PTR(ret); + + ret = arm_smmu_validate_vste(&arg); + if (ret) + return ERR_PTR(ret); + + nested_domain = kzalloc(sizeof(*nested_domain), GFP_KERNEL_ACCOUNT); + if (!nested_domain) + return ERR_PTR(-ENOMEM); + + nested_domain->domain.type = IOMMU_DOMAIN_NESTED; + nested_domain->domain.ops = &arm_smmu_nested_ops; + nested_domain->s2_parent = smmu_parent; + nested_domain->ste[0] = arg.ste[0]; + nested_domain->ste[1] = arg.ste[1] & ~cpu_to_le64(STRTAB_STE_1_EATS); + + return &nested_domain->domain; +} 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 b4b03206afbf48..eb401a4adfedc8 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -295,6 +295,7 @@ static int arm_smmu_cmdq_build_cmd(u64 *cmd, struct arm_smmu_cmdq_ent *ent) case CMDQ_OP_TLBI_NH_ASID: cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_ASID, ent->tlbi.asid); fallthrough; + case CMDQ_OP_TLBI_NH_ALL: case CMDQ_OP_TLBI_S12_VMALL: cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_VMID, ent->tlbi.vmid); break; @@ -2230,6 +2231,15 @@ static void arm_smmu_tlb_inv_range_domain(unsigned long iova, size_t size, } __arm_smmu_tlb_inv_range(&cmd, iova, size, granule, smmu_domain); + if (smmu_domain->nest_parent) { + /* + * When the S2 domain changes all the nested S1 ASIDs have to be + * flushed too. + */ + cmd.opcode = CMDQ_OP_TLBI_NH_ALL; + arm_smmu_cmdq_issue_cmd_with_sync(smmu_domain->smmu, &cmd); + } + /* * Unfortunately, this can't be leaf-only since we may have * zapped an entire table. @@ -2614,8 +2624,7 @@ static void arm_smmu_disable_pasid(struct arm_smmu_master *master) static struct arm_smmu_master_domain * arm_smmu_find_master_domain(struct arm_smmu_domain *smmu_domain, - struct arm_smmu_master *master, - ioasid_t ssid) + struct arm_smmu_master *master, ioasid_t ssid) { struct arm_smmu_master_domain *master_domain; @@ -2644,6 +2653,8 @@ to_smmu_domain_devices(struct iommu_domain *domain) if ((domain->type & __IOMMU_DOMAIN_PAGING) || domain->type == IOMMU_DOMAIN_SVA) return to_smmu_domain(domain); + if (domain->type == IOMMU_DOMAIN_NESTED) + return to_smmu_nested_domain(domain)->s2_parent; return NULL; } @@ -2716,7 +2727,8 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, * enabled if we have arm_smmu_domain, those always have page * tables. */ - state->ats_enabled = arm_smmu_ats_supported(master); + state->ats_enabled = !state->disable_ats && + arm_smmu_ats_supported(master); } if (smmu_domain) { @@ -3107,9 +3119,13 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags, struct arm_smmu_domain *smmu_domain; int ret; + if (parent) + return arm_smmu_domain_alloc_nesting(dev, flags, parent, + user_data); + if (flags & ~PAGING_FLAGS) return ERR_PTR(-EOPNOTSUPP); - if (parent || user_data) + if (user_data) return ERR_PTR(-EOPNOTSUPP); smmu_domain = arm_smmu_domain_alloc(); @@ -3122,6 +3138,7 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags, goto err_free; } smmu_domain->stage = ARM_SMMU_DOMAIN_S2; + smmu_domain->nest_parent = true; } smmu_domain->domain.type = IOMMU_DOMAIN_UNMANAGED; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index c9e5290e995a64..b5dbf5acbfc4db 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -243,6 +243,7 @@ static inline u32 arm_smmu_strtab_l2_idx(u32 sid) #define STRTAB_STE_0_CFG_BYPASS 4 #define STRTAB_STE_0_CFG_S1_TRANS 5 #define STRTAB_STE_0_CFG_S2_TRANS 6 +#define STRTAB_STE_0_CFG_NESTED 7 #define STRTAB_STE_0_S1FMT GENMASK_ULL(5, 4) #define STRTAB_STE_0_S1FMT_LINEAR 0 @@ -294,6 +295,15 @@ static inline u32 arm_smmu_strtab_l2_idx(u32 sid) #define STRTAB_STE_3_S2TTB_MASK GENMASK_ULL(51, 4) +/* These bits can be controlled by userspace for STRTAB_STE_0_CFG_NESTED */ +#define STRTAB_STE_0_NESTING_ALLOWED \ + cpu_to_le64(STRTAB_STE_0_V | STRTAB_STE_0_CFG | STRTAB_STE_0_S1FMT | \ + STRTAB_STE_0_S1CTXPTR_MASK | STRTAB_STE_0_S1CDMAX) +#define STRTAB_STE_1_NESTING_ALLOWED \ + cpu_to_le64(STRTAB_STE_1_S1DSS | STRTAB_STE_1_S1CIR | \ + STRTAB_STE_1_S1COR | STRTAB_STE_1_S1CSH | \ + STRTAB_STE_1_S1STALLD) + /* * Context descriptors. * @@ -513,6 +523,7 @@ struct arm_smmu_cmdq_ent { }; } cfgi; + #define CMDQ_OP_TLBI_NH_ALL 0x10 #define CMDQ_OP_TLBI_NH_ASID 0x11 #define CMDQ_OP_TLBI_NH_VA 0x12 #define CMDQ_OP_TLBI_EL2_ALL 0x20 @@ -814,10 +825,18 @@ struct arm_smmu_domain { struct list_head devices; spinlock_t devices_lock; bool enforce_cache_coherency : 1; + bool nest_parent : 1; struct mmu_notifier mmu_notifier; }; +struct arm_smmu_nested_domain { + struct iommu_domain domain; + struct arm_smmu_domain *s2_parent; + + __le64 ste[2]; +}; + /* The following are exposed for testing purposes. */ struct arm_smmu_entry_writer_ops; struct arm_smmu_entry_writer { @@ -862,6 +881,12 @@ static inline struct arm_smmu_domain *to_smmu_domain(struct iommu_domain *dom) return container_of(dom, struct arm_smmu_domain, domain); } +static inline struct arm_smmu_nested_domain * +to_smmu_nested_domain(struct iommu_domain *dom) +{ + return container_of(dom, struct arm_smmu_nested_domain, domain); +} + extern struct xarray arm_smmu_asid_xa; extern struct mutex arm_smmu_asid_lock; @@ -908,6 +933,7 @@ struct arm_smmu_attach_state { struct iommu_domain *old_domain; struct arm_smmu_master *master; bool cd_needs_ats; + bool disable_ats; ioasid_t ssid; /* Resulting state */ bool ats_enabled; @@ -978,8 +1004,19 @@ tegra241_cmdqv_probe(struct arm_smmu_device *smmu) #if IS_ENABLED(CONFIG_ARM_SMMU_V3_IOMMUFD) void *arm_smmu_hw_info(struct device *dev, u32 *length, u32 *type); +struct iommu_domain * +arm_smmu_domain_alloc_nesting(struct device *dev, u32 flags, + struct iommu_domain *parent, + const struct iommu_user_data *user_data); #else #define arm_smmu_hw_info NULL +static inline struct iommu_domain * +arm_smmu_domain_alloc_nesting(struct device *dev, u32 flags, + struct iommu_domain *parent, + const struct iommu_user_data *user_data) +{ + return ERR_PTR(-EOPNOTSUPP); +} #endif /* CONFIG_ARM_SMMU_V3_IOMMUFD */ #endif /* _ARM_SMMU_V3_H */ diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index b5c94fecb94ca5..cd4920886ad05e 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -394,14 +394,34 @@ struct iommu_hwpt_vtd_s1 { __u32 __reserved; }; +/** + * struct iommu_hwpt_arm_smmuv3 - ARM SMMUv3 Context Descriptor Table info + * (IOMMU_HWPT_DATA_ARM_SMMUV3) + * + * @ste: The first two double words of the user space Stream Table Entry for + * a user stage-1 Context Descriptor Table. Must be little-endian. + * Allowed fields: (Refer to "5.2 Stream Table Entry" in SMMUv3 HW Spec) + * - word-0: V, Cfg, S1Fmt, S1ContextPtr, S1CDMax + * - word-1: S1DSS, S1CIR, S1COR, S1CSH, S1STALLD + * + * -EIO will be returned if @ste is not legal or contains any non-allowed field. + * Cfg can be used to select a S1, Bypass or Abort configuration. A Bypass + * nested domain will translate the same as the nesting parent. + */ +struct iommu_hwpt_arm_smmuv3 { + __aligned_le64 ste[2]; +}; + /** * enum iommu_hwpt_data_type - IOMMU HWPT Data Type * @IOMMU_HWPT_DATA_NONE: no data * @IOMMU_HWPT_DATA_VTD_S1: Intel VT-d stage-1 page table + * @IOMMU_HWPT_DATA_ARM_SMMUV3: ARM SMMUv3 Context Descriptor Table */ enum iommu_hwpt_data_type { IOMMU_HWPT_DATA_NONE = 0, IOMMU_HWPT_DATA_VTD_S1 = 1, + IOMMU_HWPT_DATA_ARM_SMMUV3 = 2, }; /** From patchwork Wed Oct 9 16:23:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13828930 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7671ECEE336 for ; Wed, 9 Oct 2024 17:46:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=98Ksrj+miS0+Ca6vrt/OMLd71nk6UKW0sXWR7yptuXw=; b=lOSSr2+OuQaZ5EsK8XJq0EaMl5 UahacEOGUvc9ZnLhzB7DxClOECwUeHE4PNw7qAaURrlS2RvkCA4OrjfwVOFYL1dT9TNYEWYfEZ6Qx VlZJ1DJpKz0WFNWGUR8WfvHf7C0ulWJG+3It6pHkDe46+0HKNafOnNfIRpxoV9I7H/J0kD5RZ42jv ORFI1jt2LxGn+qKm9IwyDJB7wkjCxqB1l+XdbA+WSPrYKxbg3ueYR9xIghRWpJJavWfGncQUDo2ml DqiN9sqmIHZT9dLQ4lxXF1h84l/x1GZp2Yjudi05QL/UWuSj45s4LiDk/GkockPepS0lz2NTUSfpv TEEGg+Pg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syakx-0000000AFDc-1Ry1; Wed, 09 Oct 2024 17:45:51 +0000 Received: from mail-bn8nam12on2062f.outbound.protection.outlook.com ([2a01:111:f403:2418::62f] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syZTL-00000009wSe-0IVd for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 16:23:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ka6wwIphiA3Ys62J9UgRWyPAqWU3MpD7JKXVAjrZBMzORGaV3M1j8HfgtE5SwY+sanhbC2UW8JOKtuGqnzBELmgQrNt8ryiE9CSWbY3t41XawfHCDVwx7cnGITxU7DH/+DKIoKQcgukr928GDaAS0Ms07nvMQCtzncDxAfoOD0FaBBUv4WisC32/pXPQUevCYo+Ewa717r+izlQCJp9W8jJRI8oPB6CUPryuE/ElKbvcf66LEModRLjSWpfjiG0cLJ+ze/W6LRo7jQdIEy7NLWijVrHWA9OGWQRmLM6I9Ul74WW244YCB7gZO0jDXR63+1vzNYChXPTDGmHLbm8/EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=98Ksrj+miS0+Ca6vrt/OMLd71nk6UKW0sXWR7yptuXw=; b=Q3Zvr4IccUXcY7N+3AMNFaGi2qf3Mt2HgN8sb4xk4JgQ0S3uOHJoHWZ65sAad55EqSuv8J6BL6o2pOZmlGPQGFi7x4+ct/CGPoRxfhCTiDKo1cQmBmVSITSoazM01zTDdaXeCGtC/Xz/WwPDj3FVrgwdntQbpCdTL7CEAnUW4EiapnrpxW9JXfmtv6BU/b1w+hslc/lpcIyO6OUkL7J01WmeTYZi0WgAyC2BFcS+SHf3CN3ob6hak3D69WW61mFrHiJ8GAVN2v+eFNnlTXUvXl3ePYxP1UpiOxWqvaIaAe/O8J+ZinJMg/SS0CLPav3p6lNDNTWZe9Dxw2dbu0db+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=98Ksrj+miS0+Ca6vrt/OMLd71nk6UKW0sXWR7yptuXw=; b=U/wQ7FC4cXPvEdRQhijiyS6FPoU0E7MC/kiIyIR18+iVZlaD5AjJriIvgoRf/wn282AF97MTYc9I+xF0nkBnFpJJqqkhPzknfZEbb+oW8KuLwyimKeWKdKtfdfgvPhL8uZcU4aC5vTViRr06GgOAUGirMjtgI52K+xkkMR7fBIyifpQofoF9U4SseUYgmQMXsG/8wRtbifxl1aVUfQ6Ui+oBcGIpdF1evllouUFSAKVK3WbYD1YjG576+I1B2nKN/IBr4+uDHfBiaJxhIlUiAYde0Tz8uSBxfll/HDUrDaY2Vm4uv3+6FcSCgoNtU6KQa82aSGMKNAavMXY5UYvtvw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) by SJ1PR12MB6073.namprd12.prod.outlook.com (2603:10b6:a03:488::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Wed, 9 Oct 2024 16:23:21 +0000 Received: from CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732]) by CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732%4]) with mapi id 15.20.8048.013; Wed, 9 Oct 2024 16:23:21 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, Hanjun Guo , iommu@lists.linux.dev, Joerg Roedel , Kevin Tian , kvm@vger.kernel.org, Len Brown , linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lorenzo Pieralisi , "Rafael J. Wysocki" , Robert Moore , Robin Murphy , Sudeep Holla , Will Deacon Cc: Alex Williamson , Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, "Rafael J. Wysocki" , Shameerali Kolothum Thodi , Mostafa Saleh Subject: [PATCH v3 9/9] iommu/arm-smmu-v3: Use S2FWB for NESTED domains Date: Wed, 9 Oct 2024 13:23:15 -0300 Message-ID: <9-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> In-Reply-To: <0-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR0102CA0001.prod.exchangelabs.com (2603:10b6:207:18::14) To CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB8659:EE_|SJ1PR12MB6073:EE_ X-MS-Office365-Filtering-Correlation-Id: 1c64ad2d-be5a-4ee8-f850-08dce87eaeca X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|7416014|1800799024|921020; X-Microsoft-Antispam-Message-Info: VdkkOrmGfwVfmnhDvvP7rBfFzp+VhgC+RjKVN10n2yN7t0qn2HHHAetHXqLTBJCx0qacYa2p7yreh0c/iFfUh60fTME76/yCfyUSotqDaf2vPGd+Rm7gVH8YQu+CuIekkHMXpDC4zXcwsg774mOvnWIwU8eL4PwCtxroLRrPeEzKckBMUInuc4FNtluSk/jQ+cpAZ4CCP2uhM8ykUDafF8oyFcEhFU61T5DkIJKSfmGtVLRubTfncune4XF0ldNRNn5o4eDreBarJeMrHXpySWJsTHkv5N2LCCwas/ZEP//GaL4trDEC8EnYL+axklnZxHFs9NnUf9DTncp17YFxisYD9f+7h1s4MoO0zsnYeEjbRxGoBmEQiaVXvlXx/Lwh2MfJqbNYQbht4RdURetAmfr712daFxkLDJalDFg/G0BDPAvi0LKCgTkxEueOHArxy6K4oHeAWLgpN1XpqKBvIvLHocaPtIET2j4jRZKSMLarxORmUfRNOaeXQKWVbZ3b9DXahaPqk3Uuzc7dxSAQ74WcLH01GhZrjJm9vgLThsE17sJ94BJAzNvLA6myru3sdvTWWk3mLHQoE31PgFCGSmfIU7CLuX03njx/Aos8dUeyxJv8bAZAkq2G2p6NsaYqQV+Q2vxpR60sF1YZrnZQ5jDGhtgFBuom0i+0EUH+MeWHUuTPEqAqJ1YbxtkWDZDWtjkFMAAfk7nSMlUQmpPGcqaoi9r6YvAc5M6zjIMVuu4q3x3HjJa2HRv/WQPr556TTvV7Vp4MuqVe6L2rb99S6OvuzlpJJTV/opu6YmBMKWqtexOARbZzrpXmHb+X/g7GMqIrAE3IJHn4Z1XBcsn3avttybQx8WSU9F9YIULNEeZ4uJhQrmURYBc/bY4MX+XnIuyypSf23eV4WdhWxVMCxj8GRLYjiVisV0WzAmXGo69e9C59XhO2+YY1zbGaRadanVXnVbmMypDEdS8k1i9HJqztGWHJ63LVxT5DznvXcCqDek0cb5LIoA++tvMJL5o6qYXCLGQ9NI6HCJ2IQ7zrG4cqWQ/p/sG5BoZXyJ3tcWVvbDW2j0T7BChbCArPwzZPEBkqp7uJtOdcxlqNgFG9K6ZB8WiyY7KBMqv9X576IRxhQQ97jjU2qWTLo5We2f4jB+u0duIgfJYsSxwVhO0Y9gj0ysPLjhCW4+1nqMvQYLCy9+FEoZMUwoy8TzusdqL0WNwuBTKIuQggfe5CCxTF2wsBpbwyh+1hXxlizKLLW/vzFOY3CQol/qOjaJ/gWXJ5AXlzJA9AsJIwFETEVqtSy4RSliV0+rz4vVjXRCpDTtSkwnA7M0nStPQsy0yBgtyn X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB8659.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(7416014)(1800799024)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ekv1FHkdWzsQq6b9CZx+ELZeTbejWoF5A+rH1w8Hf+Dhs2h6H0uFUIUL7bGhxTfbNPGnP5UEun5GwN7HZ7iC7KOC1PoDshj9WOtAR3oj6zzPTWXVw95ZJBV1SLqUoORu4sjfF+3GcvH24i0b25XtDaVinoahr8P2cCifJp2o4QSk+dzW7FX4EEco+5EAoPGyQPBSVVmQuGjpR53A67KxFSjouBgnguRsKsOw3iPYw3EBUnklZehVoyoGxYBNZTTZxuB2H0aNGKgG8NvGQfXruRKu5EOrgDythVx/tNQvuF5gP1w/EbBUOr4rPBhXyO3g1TjyL2zCFKKUUcL5IOcUzggClVEz/eA5jAvzBypkCBImncM7f20RcpfoJPrSvZusRYSSDefhuKeNmLskSQzEMpACYkE2ZWblGWxMLx2kpiEQ0Vrq7wO0QNrzI14IhoLKD/fX0/4Wym/aBtpibPZZpyKIgp7BRMdZuAGoYFoFCN+2p7vkMq536jEph1/pu1iUsQsHtcte04e+B48LJm5pTNYdrxaHtPcojnvHEiozhQgulseh9z88uYOQcTb3cPl0wVniPSZeQKuqJkv+71Ih1nbA2ntoEWBzGJT8iLs0SN/elJ7HnDgV4Ef0oSh7W9vTJILn+Je5DxyHLuTpPAele1swmkszFOcVwthGi16YPM0nyZdjrAexFZVyRAmwQP+NnABTs50Yl9D05X+6+Fp5/zJ8V9iB6U22zlxK7PjCNok3yVhQkC/Tzn3brSBgI5tiX9hN3YzB5oQ+sgqBna2G7A6dRZ5CNylemseaTXfgFe4f1fRZc6nkmFDXdbEevVlR4w5QE2oS3dwwcNY41j07PVTEvHwgyYkr/szdedV7EL7LaZVDZMqmvnLqxppq2I2pCClEzaejlXpHn9XGcJksIiKa3aXn+5s53K2ht5Ws5GCe5Y0G9cYbqkZOV1c5gv9dqry6W2q3jd07on5mTutXvSEyPuXjt+hd/pVCQ2Oixzn54zlgQiaI74sHZCPv6MbRDLHNQKy+mKrxwY9Kn4whaLbDK3n6uWFWy72MEsv8sm3X6uom/dhhEpxXL+gDqq+pCvQKi430M8Nwh1rKHRqzkvETa7tGYw77UJhYbn5wwDqbQoh92YrMHbkIXBm6KCsfS5/vAvMCXmElQu6ewPd0QU+wxCFl6oJuobtrpCaXlJ8zjt9pETd1ByVhe+WNw21uOp+lbGJmblyrt+4LP63lgygo0I5dLvW7PWdaiOUQWRRWYUF63kWlNd3HF/oc0Pob72bRbDwi33u2nvth00bi2aZnS82NHo35fEvz3dqS6Xbo3amZk3TUJkQY4VYdu1cy56y9h5ohHrAvmt7qk7HuwYoPiNcZtQFSqRAry/D4DhVhoJqKc1dGEzFpYRuQSeaSHkAkek0ReTKj4AWUbCpASzzfx3krk0NGawiSbbAmzlRTJVspcRaudAejuo3lLkGbI2G068bG8KRiXxp6UP6VW6ltAspcHwpuMI0GAFyG3hvZ5GzUXEuWSiII4fAuwjhddU6ZrrbZ4qFeoICag/6hv6JdEuGO7ttZm+Jtk3ScyhQ= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1c64ad2d-be5a-4ee8-f850-08dce87eaeca X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8659.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2024 16:23:17.7355 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8sJ1UY3SBdRpCS4getabSeHkZ0Mjdi5CZnZK2tlfUeY+lPMl05rOitlM8DVJQeBR X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6073 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241009_092335_233127_40630BFA X-CRM114-Status: GOOD ( 21.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Force Write Back (FWB) changes how the S2 IOPTE's MemAttr field works. When S2FWB is supported and enabled the IOPTE will force cachable access to IOMMU_CACHE memory when nesting with a S1 and deny cachable access otherwise. When using a single stage of translation, a simple S2 domain, it doesn't change things for PCI devices as it is just a different encoding for the existing mapping of the IOMMU protection flags to cachability attributes. For non-PCI it also changes the combining rules when incoming transactions have inconsistent attributes. However, when used with a nested S1, FWB has the effect of preventing the guest from choosing a MemAttr in it's S1 that would cause ordinary DMA to bypass the cache. Consistent with KVM we wish to deny the guest the ability to become incoherent with cached memory the hypervisor believes is cachable so we don't have to flush it. Allow NESTED domains to be created if the SMMU has S2FWB support and use S2FWB for NESTING_PARENTS. This is an additional option to CANWBS. Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Reviewed-by: Kevin Tian --- .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 3 ++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 8 +++++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 3 +++ drivers/iommu/io-pgtable-arm.c | 27 ++++++++++++++----- include/linux/io-pgtable.h | 2 ++ 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c index a9aa7514e65ce4..44e1b9bef850d9 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c @@ -169,7 +169,8 @@ arm_smmu_domain_alloc_nesting(struct device *dev, u32 flags, * Must support some way to prevent the VM from bypassing the cache * because VFIO currently does not do any cache maintenance. */ - if (!arm_smmu_master_canwbs(master)) + if (!arm_smmu_master_canwbs(master) && + !(master->smmu->features & ARM_SMMU_FEAT_S2FWB)) return ERR_PTR(-EOPNOTSUPP); /* 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 eb401a4adfedc8..4e559e02514983 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1046,7 +1046,8 @@ void arm_smmu_get_ste_used(const __le64 *ent, __le64 *used_bits) /* S2 translates */ if (cfg & BIT(1)) { used_bits[1] |= - cpu_to_le64(STRTAB_STE_1_EATS | STRTAB_STE_1_SHCFG); + cpu_to_le64(STRTAB_STE_1_S2FWB | STRTAB_STE_1_EATS | + STRTAB_STE_1_SHCFG); used_bits[2] |= cpu_to_le64(STRTAB_STE_2_S2VMID | STRTAB_STE_2_VTCR | STRTAB_STE_2_S2AA64 | STRTAB_STE_2_S2ENDI | @@ -1654,6 +1655,8 @@ void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, FIELD_PREP(STRTAB_STE_1_EATS, ats_enabled ? STRTAB_STE_1_EATS_TRANS : 0)); + if (pgtbl_cfg->quirks & IO_PGTABLE_QUIRK_ARM_S2FWB) + target->data[1] |= cpu_to_le64(STRTAB_STE_1_S2FWB); if (smmu->features & ARM_SMMU_FEAT_ATTR_TYPES_OVR) target->data[1] |= cpu_to_le64(FIELD_PREP(STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING)); @@ -2472,6 +2475,9 @@ static int arm_smmu_domain_finalise(struct arm_smmu_domain *smmu_domain, pgtbl_cfg.oas = smmu->oas; fmt = ARM_64_LPAE_S2; finalise_stage_fn = arm_smmu_domain_finalise_s2; + if ((smmu->features & ARM_SMMU_FEAT_S2FWB) && + (flags & IOMMU_HWPT_ALLOC_NEST_PARENT)) + pgtbl_cfg.quirks |= IO_PGTABLE_QUIRK_ARM_S2FWB; break; default: return -EINVAL; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index b5dbf5acbfc4db..e394943c0b4bfe 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -57,6 +57,7 @@ struct arm_smmu_device; #define IDR1_SIDSIZE GENMASK(5, 0) #define ARM_SMMU_IDR3 0xc +#define IDR3_FWB (1 << 8) #define IDR3_RIL (1 << 10) #define ARM_SMMU_IDR5 0x14 @@ -265,6 +266,7 @@ static inline u32 arm_smmu_strtab_l2_idx(u32 sid) #define STRTAB_STE_1_S1CSH GENMASK_ULL(7, 6) #define STRTAB_STE_1_S1STALLD (1UL << 27) +#define STRTAB_STE_1_S2FWB (1UL << 25) #define STRTAB_STE_1_EATS GENMASK_ULL(29, 28) #define STRTAB_STE_1_EATS_ABT 0UL @@ -739,6 +741,7 @@ struct arm_smmu_device { #define ARM_SMMU_FEAT_ATTR_TYPES_OVR (1 << 20) #define ARM_SMMU_FEAT_HA (1 << 21) #define ARM_SMMU_FEAT_HD (1 << 22) +#define ARM_SMMU_FEAT_S2FWB (1 << 23) u32 features; #define ARM_SMMU_OPT_SKIP_PREFETCH (1 << 0) diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index 0e67f1721a3d98..74f58c6ac30cbd 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -106,6 +106,18 @@ #define ARM_LPAE_PTE_HAP_FAULT (((arm_lpae_iopte)0) << 6) #define ARM_LPAE_PTE_HAP_READ (((arm_lpae_iopte)1) << 6) #define ARM_LPAE_PTE_HAP_WRITE (((arm_lpae_iopte)2) << 6) +/* + * For !FWB these code to: + * 1111 = Normal outer write back cachable / Inner Write Back Cachable + * Permit S1 to override + * 0101 = Normal Non-cachable / Inner Non-cachable + * 0001 = Device / Device-nGnRE + * For S2FWB these code: + * 0110 Force Normal Write Back + * 0101 Normal* is forced Normal-NC, Device unchanged + * 0001 Force Device-nGnRE + */ +#define ARM_LPAE_PTE_MEMATTR_FWB_WB (((arm_lpae_iopte)0x6) << 2) #define ARM_LPAE_PTE_MEMATTR_OIWB (((arm_lpae_iopte)0xf) << 2) #define ARM_LPAE_PTE_MEMATTR_NC (((arm_lpae_iopte)0x5) << 2) #define ARM_LPAE_PTE_MEMATTR_DEV (((arm_lpae_iopte)0x1) << 2) @@ -458,12 +470,16 @@ static arm_lpae_iopte arm_lpae_prot_to_pte(struct arm_lpae_io_pgtable *data, */ if (data->iop.fmt == ARM_64_LPAE_S2 || data->iop.fmt == ARM_32_LPAE_S2) { - if (prot & IOMMU_MMIO) + if (prot & IOMMU_MMIO) { pte |= ARM_LPAE_PTE_MEMATTR_DEV; - else if (prot & IOMMU_CACHE) - pte |= ARM_LPAE_PTE_MEMATTR_OIWB; - else + } else if (prot & IOMMU_CACHE) { + if (data->iop.cfg.quirks & IO_PGTABLE_QUIRK_ARM_S2FWB) + pte |= ARM_LPAE_PTE_MEMATTR_FWB_WB; + else + pte |= ARM_LPAE_PTE_MEMATTR_OIWB; + } else { pte |= ARM_LPAE_PTE_MEMATTR_NC; + } } else { if (prot & IOMMU_MMIO) pte |= (ARM_LPAE_MAIR_ATTR_IDX_DEV @@ -1035,8 +1051,7 @@ arm_64_lpae_alloc_pgtable_s2(struct io_pgtable_cfg *cfg, void *cookie) struct arm_lpae_io_pgtable *data; typeof(&cfg->arm_lpae_s2_cfg.vtcr) vtcr = &cfg->arm_lpae_s2_cfg.vtcr; - /* The NS quirk doesn't apply at stage 2 */ - if (cfg->quirks) + if (cfg->quirks & ~(IO_PGTABLE_QUIRK_ARM_S2FWB)) return NULL; data = arm_lpae_alloc_pgtable(cfg); diff --git a/include/linux/io-pgtable.h b/include/linux/io-pgtable.h index b1ecfc3cd5bcc0..ce86b09ae80f18 100644 --- a/include/linux/io-pgtable.h +++ b/include/linux/io-pgtable.h @@ -87,6 +87,7 @@ struct io_pgtable_cfg { * attributes set in the TCR for a non-coherent page-table walker. * * IO_PGTABLE_QUIRK_ARM_HD: Enables dirty tracking in stage 1 pagetable. + * IO_PGTABLE_QUIRK_ARM_S2FWB: Use the FWB format for the MemAttrs bits */ #define IO_PGTABLE_QUIRK_ARM_NS BIT(0) #define IO_PGTABLE_QUIRK_NO_PERMS BIT(1) @@ -95,6 +96,7 @@ struct io_pgtable_cfg { #define IO_PGTABLE_QUIRK_ARM_TTBR1 BIT(5) #define IO_PGTABLE_QUIRK_ARM_OUTER_WBWA BIT(6) #define IO_PGTABLE_QUIRK_ARM_HD BIT(7) + #define IO_PGTABLE_QUIRK_ARM_S2FWB BIT(8) unsigned long quirks; unsigned long pgsize_bitmap; unsigned int ias;