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: 834007 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2085.outbound.protection.outlook.com [40.107.236.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C05B1E260F for ; Wed, 9 Oct 2024 16:23:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491020; cv=fail; b=jo68B0D5buIYjyJoB3KjE8EbpXPV0mCyGq4aNvfydgKqVmN84lYabQL+KC6eBA5/TCsNGe2Uc6fxT2mOGrJrO183yK7Cn0RZ89OsW0yUxH5dS9rkD++eL4eR3OwC+D0vQe9X40HrNDRVPl3RbL4cKWjR+5bEzISeZXNsM0Wc+D8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491020; c=relaxed/simple; bh=13XIPhzPixZBnmAScrwHpiKjtNd0BnIIDm76rCNfJnY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Ox/yOKAgTLOy0bfJdenquLTbOkd3AEWUCO2j71Vmgze2xLc3UK1Z7cnaW2G83vDY/ZA+Oro/k+4jjmkIqK3s3xrsdOakvdTIIG6oTKIt9r8rTWsWcwPTeROPixYF9TfRI7K/Hvk3GYEX+djZfN0jkIFxUsd3eq8nkAxRdBBea8Q= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=kD+e2dRl; arc=fail smtp.client-ip=40.107.236.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="kD+e2dRl" 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) Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 834009 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2071.outbound.protection.outlook.com [40.107.243.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B52011E22FE; Wed, 9 Oct 2024 16:23:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491016; cv=fail; b=sNzH6Nk1BLNdcmpx8p4vDUt4x/4GhPvHh5KikYhVGw603XChEkMF2L2h9GlTByqFigVsVwUNfLT8D1SNtEa/dJGSd79BCW/nMbWdk6RBQkSCOm76FZWrHM683UDgIiF8Nrilc+THfizItNdMNRZJuYx733N7+RKgIu5JTWvq3B0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491016; c=relaxed/simple; bh=pdzsj8eeFQ7CCxjSAY5f8fb4UEa+pYHl7dLdVqsi2is=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=XZfJ/xTRedyELDR8SxQXhWboil9iuSVf/ZK70oFFO3mZki61atey9gf1uFh+qG7A97X5biTHvCPYPGhtoTm2+6VYRe/F1Y9NxjvuleX7EKVDBhx8GIKhXW4Zey36rXWt1kuzjUUEdjRvdOSOpYsIMEYLgQ9/C4Yvvqoka2e8ki0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=h5ht0td6; arc=fail smtp.client-ip=40.107.243.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="h5ht0td6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ajSfjQrJV3//r9R9KIDVZHyr/nI7+mEE08lpzg5GXWceSZZNgzgo6ydwkAgDW4o2Sewsy8GDATMIPRg8N82uIdV3cGZ6ejX6tMaWueI/gEj4xQVniHn5N5gewcV3987Nin9I6uNsFoNr2DUbxiROu4B6hFk3swzgyzL+2ZQ9tPyUio2lVvNx4Y4sAzQ8pNDakH6RoXmik3gKnCtVmEnVsDqMTVhUF93YUE0zQ1oYJPmPNO8ORI8zUajRDUnCN6Kg5JegK6ZoqbpUcGCfZ4m6ouYzOfE5JT7dJCMg8nB6CfyKNtEwqqzNc9vpN1UzSN60baYLLlw7t8oafzHlsYjrfw== 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=B2xwBDmPgab8vmGL2upbaC67SHJ8zaSD1u+x6YDaBewnSGuPZYBrydy21QLZZ0CFJlsFow3KwOCDXDfyKs0L32A+7QY348t5UovToQ0TDv3LxnTaCcITGsjGbrKh+yi6xpJcG6SA6h2rUYxb7c7igWIYMyoAEHgN528vlckT6UcHBcqCybz1xWfNMaHYfasfjKlgLrxcRze4koO/V05E4fi63N8plHMDk5wIcs0pY0zDmNUOMYJ2rgyVslv0JeMumIlzIMfY9tUMQJggzQxzALTwX+6GkhsU2kWm8/GkWv0lbxQ95EVFSLK8L/GfIjcLbKXV99tjNXMpsZt0NdjXyg== 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 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 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: BL1PR13CA0017.namprd13.prod.outlook.com (2603:10b6:208:256::22) To CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB8659:EE_|SJ1PR12MB6073:EE_ X-MS-Office365-Filtering-Correlation-Id: f6b0f993-8715-4676-fa6e-08dce87eaed7 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: 9amE+EP+CFP/AU5Vr+Z8VXM2wHgtSaRyNziKs/fulNFITqr4DTuIAHeQ9ng3IsD8oz9SB340R50co5mLEb8KrezhrDrPls5tuEfje+LpB8QzxXevXXst1CkpGxOfZIhQrWwDkg8OoxJ+HkG8++5WG3O9UPvQWxyyrc/bvIj3zy9ECQyFGu33LUsR7Hyc0uwc8kUyzpvOMOvgFng4CWZgvuiS/wm651b/G1RWinKpIU7l5VprLbsIYNIpDylftuAnSfgdwD6e8VIACuhDg5RzwNAHoK+D+esnCIbmX89+02mjUbk6tQ5Q7wyCtN8JGkKGy89qVTIwayxelMAOZNdssaULfXGDqE4ECRP/HUl/j4RjeRHaq5eTHDPh7Jq+FBkaseAChPRvMZ5+pKwHkMskrLz5bgYat3v/ZMZCrHEC0lK9LhAjgtYfwzLjUFck3epKx53vfmUhmsxk+gPaOtyfAYF7gcQzqFZjBliGnb0wzN9VUi/uHaXbCXPyCOvQKQbjKUn9A8ZIwt/BxjebCYPv3C2r+s7W7nogY3VjoMHOQ2zyzjyiXBDCroJVfGT5WTMIrN2sXWbS0cRQDZx/hwD2WAoP2IM87WkA7l/5zm6756dru/wKxoZ8UaYbQoAxyzkodx7itaYCFAmhsTqbxrk5LN7InBRmYyJ4SeofARvabLYLVjWRfZr9CLW40f4HJGV+gg6ThUlCf9Tdnud2HVEerylJAhiR3C3KBBC5hE3mR4B6N4CJzY0vm3J6Sc/5AY4TGFUcL8x5A6BhhECdqKbATW8Y8/jH4sW2H5890uY1cNyqjw7MOJ6Hx7YdlSnMVxIcTx9/Bhw76XA7XlDSA6xkVtLOFE57ijWbq5318qC/jW+o6pLISzx81CdfHQIN1nw7y962Ga59VU8RrOlGkXjgr/odLyBvqt2pKSwbSAPtURmVwzVZst3TrZMZMr6FIx6dNwA+ris0YppKd1+OKnDcFXiyQTVMi2cSC5mAsmTaMEUvhAfDPPepxKcXr7nghPjISufrroaiMM7vBlGZ9G4rvvcl+WLS73nSyTqgE2Q2TNBZ28l65+fS1stntJEupD5HkZI3Ftnlq2TFnpGlff/1TvQuHkgndHjAJ/+p23L7w2Xi8ArPqgWcnQwjvSX8cHb+Zk/eKK+PD/mF3lNxln9SMrku4cGbtA4rYWDWKojIBlvErg5rE9ck8mBSOM0HZE3PrV29RDAUxJEWDRW3xgIPG713OnIVZRYO7OjV/SD7gulJDRcYoKxZIf7w7G0JeJK1C8ZDO8oF6NEY6WiYykT4Q90OtbMcEqePYJrF+J4GrIF3x+QIRTvx/XqEktprQIP+ 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: R2hCg1whHGXEevV8GCpZxsVO5M/MO4cHpp7lLk4/W6HMX6TWp0tw14Rv3ZBUU4vvpIR0SrKAFVkHH/oP30v2ePSyKbxn292xDYdzdhILX9e9Z9VfRByrNgXpJ4sNvYo9aRcr1T1HI9AeT/8ofiC0Qm9drTAKsdjGm0DvbzKA26CfO6BQYG1NCuWpQOAQvP2fqX0vtDVcpJg28zudu8TPp0TCJziB2iSfCm+lvs+DePEBB/dahnPAdkmIHOI5WH5bS1NZgwBi6l4Y00vKB/84Sw8sUIvhGx0LUnDmEo1T6FWqfsx2YIra4DvYOVwaxFt8Hjtp5GmVpxwSoB/qo7zXZabxEu8Drutnjb6odRJuvfU1niuHy6QdUWl3E2NGKQjm7o7VvWmY/43ncbURTudO7O2ltl3fMNreFufhaFHuqJ3M9Qr9anaUc+buW6mmv08qSqpRi1jgavA9ZN+otE2hcb2dHE2Y8UI93cnDhKI65sXCJ78PXlz02aGsvabT3IXlRaVrEPW/pNen6TqNVKlu+iPnHBN3dsTI8zzP4sdR4jtf61sD2AlQj5qfIA7uonU2Xx7k2l5jr1OtKoQsCXa+EXK25OmC96ZyeEJ17GM+SIvSqIw3joEOSvBwjRs71AgGvS/DHhemvFok54QAMH/L68GdKOf7zh8PWJLbbcmNuE3ixh+/IWxnkggLfFQDsi9UNejy6BylUVZ3wVudCbIwxBoAd+WC6P2BeRT+3ekiuT3cE/cXTgJO6uXy5CDc8puKQRE1XwGlQ9GzzaKG7PF8tPHd68rJ64DjPqqyYS+LnaYi+yyBkmzl4WHftMIeHcEf+DKUAs7bUYyxbZhK2GMwQJA+bsPjgSqOAxw6cy3L+d133hfS1nLV5Aof+pbIKhfNEnRkUhXeuSV6jODCm1+qu0s6qK5Nw10ZKtgtpqSVeDgPzd5snkCcE63C3YbMWs4L+tglrUe7xmqQP8o57khNWjYtHLJY4vdAs7Ajymz9iYX+3jUxt3VrUHSsCBlwqIGP4pHjPHVYHpSyuDJWyUfUpcaHTjKYh+loaF9omFimUxe/SxnqUl+Th4ndj6oPKr1WzzSJ21v7ohutge/xubnmiISfofJVPbDbgVC/XXWvFUNTYwybB3ec3o88cV1SH6jmKmw1uLnxxOHcT92I8uQOStLla2A2r//06Ep6hB/lqUyM12CHa6KPbZshUwPCmMIfxBPucIeXUyoOwj4oGn2HKdLQD+lXYkc4AnbQvb6bK26IuX8KBUEIC3fSlvHZygqVZnGPJnmBrVAizRMkH2KSWKWdrRa4IWPlGZnZxf6nCQJrIcY4XUj51d62oHWPs1m4VE6pjlIw6zWwXL15newaVMUdvbCnepLFFNem2ld1gHDajej92aN9edZjhkJpTN2l02wSMKl66fXXpRhPxXcLfwnrmoWuvcWMybQsRi8AMB6YI6ygHTIJ9v1q8c0GpaTteXah+2Ys+QMMB3VmgJuK4XLm2b+24TGom3TnlgeP5ancCfUY6jkLreqORVYs39mVwCe4k6IHswin6a3dFwb9o730TShUBJFtQEHNnhKyaao= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f6b0f993-8715-4676-fa6e-08dce87eaed7 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.8249 (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: wBqh1YN4c3T/3DisoVWoGfnMefu7KsrtI4+NpbNZTITf4lWFCCnLVtTqKlJR9Dpq X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6073 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: 834010 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2079.outbound.protection.outlook.com [40.107.237.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 551991E1C36 for ; Wed, 9 Oct 2024 16:23:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491013; cv=fail; b=PRI5An/k9nFtEp/WNRE9oXFBwME1Lt6y6IblT5CRakRYZJgu92WyhOwaal3x5/gsA3o+RFgQR0KKMatdWwnVczbyRntqRuPaTdUmDu68oCBwwh8pxGuzfZYk7fPqcb55elPv6H0VABksVqk5od6rwC9Vy1NFB0cP/lrJp5CW8NY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491013; c=relaxed/simple; bh=mKT1IJJeKHX4ypen5n7Whj6rhvt4w+VnV0D5xGA4VGw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=oofrV1e4Y6I68p5q8arbPMmNPf2V88gNMbSVVh4TddjTIeei4TTBIioqt7L3AG2Rodgy/7F8Vdw4LAwtOynDDqpy+rtpZAgQM63LvDLDxI+SzhK/L8pusZup2hT4+cv8Pi2AVAabnN7lKUpVC1He2sN8BeAD6yIVKjlNiLnhIUY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=CZEs+Ejn; arc=fail smtp.client-ip=40.107.237.79 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="CZEs+Ejn" 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) Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 834011 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2079.outbound.protection.outlook.com [40.107.237.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25F231E1C09 for ; Wed, 9 Oct 2024 16:23:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491008; cv=fail; b=A5rT0oHr2oBT52Zs2bvy6J4PzDR0wMClSYnMRh8Lovv1A9VKj7btiIsidBUQlKSeKlZFfQBfvCfIHfZ7cT3EOSapX3Qsm9vMYWJqlajh7evevwPjs0+9DRysSfZrOj+rrMErL9o8RFldzg1hJU1uy5OkNYXP9KMI3DAnqn33+5c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491008; c=relaxed/simple; bh=HLgJSx9zNbLKmh+2CXeB+LrMw50jskRmGn9phyJNGss=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=W3/Z905OxhDCq/at7rrw3VTZWD7VWIcxtdoe8OCwmFf1cxF2g55C89PXXjMGyh6cFhY0BeTRp2waUMoiGE0f/Z7/kJm4OEbvGjfR1AUfEyTxAlo5TxeUL32ODWbaoodSZvp+UWvSU/a7bgp7l1NnXrbbP2Kx7jAt1I3WWONWHac= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=d50cU2wX; arc=fail smtp.client-ip=40.107.237.79 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="d50cU2wX" 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) Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 834186 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2085.outbound.protection.outlook.com [40.107.236.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82DB31E284A; Wed, 9 Oct 2024 16:23:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491022; cv=fail; b=FoZB774xCFXl8cm/eKkj4PIdVDqriCT3avPjd6uUo57tMMZBQB4nV0MOpVzpLHvR2WcFNWPPOqKJvJwvXYoLjdxlOhxCEIlTZ+f/JKuIu2TLD/aBSNdJcyii2IvGFnOkYSO7DzM0hWdubMCnVFoUnQEQObItQIh5YZ4UWeETV2I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491022; c=relaxed/simple; bh=W0bDaGzbM2yFHU/wV8ASZR5jFfzSvY1/pjJEzpw9BX8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=sXSNaVkjBPLgc9oEsHwmoOau7eIrTi2DiSPeL3ffYRaWvbJEJjcp7EMk732KOo/LL3k37FFCrY9jfjC/8cQSDRGa0Y4NBHoAZZzp0GkgdhXyD8k9S3ZvNjGhLh9/g8AHLgN+aETE8z/wJ4QzMNNrqW1JZFQOXY0NMyoW7Tl2sFo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=N1LftJdH; arc=fail smtp.client-ip=40.107.236.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="N1LftJdH" 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) Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 834188 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2079.outbound.protection.outlook.com [40.107.237.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F16B1E2013; Wed, 9 Oct 2024 16:23:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491017; cv=fail; b=RBIMTDCEarVnX4uUThPD7RX8u4nfU9d3a7Ug/ashXbvCF2qmouTyJ537icQN06iL0vzo4ILkR1OXfMbKsuIWALdLQ0vW8RwZJpBCnjx5BhHcTeQK1k8gQjy+WXtRPW15FB2hC9AH+TNRQtQY6/wotLAaNvRIqsp4xRNbRvJCGJU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491017; c=relaxed/simple; bh=d4scfK/awn6fiN+nl4ph6GbOw9++bWGOjgYGwfK9yFM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Yw/niIBp/MhZ9NI9/gQrGozzoriI0PSZVCbJuD1vc8GrtuSmYUxb9Rbu5UJWTIVsHYdxiyeiDHjbPkIfNDzBUxCuTlRHAc806pyozs49LKq9yDuFD0bak900A5tuJIeRcMFh98bWCJqTNaq6Eh0wb1xJ972Dmzyzx8DLnlpIFuE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=L0abM61l; arc=fail smtp.client-ip=40.107.237.79 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="L0abM61l" 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) Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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 --- 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: 834008 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2085.outbound.protection.outlook.com [40.107.236.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 662231E1C28; Wed, 9 Oct 2024 16:23:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491018; cv=fail; b=loK1aI8n9097eP6b3LVo1U8XzH/3/d7b6JkaDdqDctIpEPHf3ntxE9MLFcU73uE1mialmiYofsNxTmAYBxSkTsnS3YH/R/BxV4liuPfj6khvGIFjmuYkmxxYh5VtrZsf/FzGeuENJ1VhJlTAxTf13ICnZ8EEG2DoKY8lpLg4WiA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491018; c=relaxed/simple; bh=aO4bbQ0a8b9xl+qDwfqWXHEHMH+lGK3NUhAJ4TCyPNg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=n2Fw7NcRyB+xG16fLrBwAABUo9kZHK7ANfEv/f76iu+sOyh0feDbDA7XDTMA3jSoyBMNThux5o0Nvo0l+05GMPytigjrUYMpXkkYMExM8KFQMwMMKj0Qmvva2GYoDV/WVErb991dUeu06LWd2mwpUd6bJOC6wmf2FeWsDL4xAV8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=iMigaRbG; arc=fail smtp.client-ip=40.107.236.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="iMigaRbG" 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) Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: Kevin Tian --- 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: 834187 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2071.outbound.protection.outlook.com [40.107.243.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 802D21E2317; Wed, 9 Oct 2024 16:23:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491018; cv=fail; b=CuhgpeZAht/fRow8CdGY9lOLdkqQG+A8VSu8aszQiQX5mBWUHpLIKEgLtDvyJiH1DTIQICxvZi5RpGn0LafQL2XV550B+fa2MrNLmxkwfaH+Dqkp8SgNnhz8f+/JvxLRCiWtuLrqXlnpGoffItcqPIMBWgbgQYzgOs7312gO/Q4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491018; c=relaxed/simple; bh=V2wjOx6gOKr155TZ6M3kkJiXVarvl9lBIltKidwRr4c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=ji5q+yc3PLErRBfNwqSVykZ68oqxKyI5it+xdrmyeFaSPwf1ZlneklztoDwW2siAtZFevPnq0PlwItTCDtzjyf5j15a8DKkSj5FeSiSoPnn/Lnfy0w33TRStmUAYvmky4BqbE/9Anubu5wblBYJLwr1gUapz+Ll21F7yR9V7WyQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=WP59PQSV; arc=fail smtp.client-ip=40.107.243.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="WP59PQSV" 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) Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 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: 834189 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2071.outbound.protection.outlook.com [40.107.243.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD6411E2039; Wed, 9 Oct 2024 16:23:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491014; cv=fail; b=H0hTy75ui7Pty2MHEF9VMZ+gecozTwDEiAIwvKH3VSj7fDRe6AnGLHLZ2dEhA6eay4Jvvhf84wKqx671W4MmfQIk90VV6LkDY/mbUiLe8hbjnzeuZBgTLd0il3DgxQZdy1vn1wuv4OmoGuSB/3K1ddkq+Dp6DcoBBsgCNLwZCCI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728491014; c=relaxed/simple; bh=/dNsMUgLCXStd/1eTrKLB0hnuAZyLKP2B18hk7Hldog=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=sTFVU5VEQGawttewuwn3FE8v+mHO4/3yBUKdex9E4fD6jTyZQWqF2XDbLI65ugS7pOoPxpSvn0gV+HrK+ApqJCx5XsXOrjXByTlLLweVOkZpqUW5D8we97WDazS67NlH5Ui2cWBVZPHFIoW+LtKzfXaPPGVlLbGMCdS8XG1WydY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=U/wQ7FC4; arc=fail smtp.client-ip=40.107.243.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="U/wQ7FC4" 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) Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 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;