From patchwork Thu Aug 22 14:45:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13773589 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2063.outbound.protection.outlook.com [40.107.96.63]) (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 9E3CD1CC172 for ; Thu, 22 Aug 2024 14:45:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724337961; cv=fail; b=XkqyO2t9/vzNExXEUSvSmmTkFGjc2yTlAIXg5MRmXznM2zUVMjot36TR5A6YmzYJ9zw6ROtZtb4ng7MjdsILxg9MQEccWV81lgug8IjwYJbRNV7ObsSnT+i3fA0S/2Yx6dW1a8CyQQLcYir7l5/tyCOEtw3ZDlvNQ1yFOWHJSdU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724337961; c=relaxed/simple; bh=mSCo+qIbwYGsrzeFEZ5i2qEJZHxFJNsyDEBdTY1kcwI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=ncCMKAjD/dYgfRM+SiwntzPsGPoQAa3Bd4TzNFmb2EHDo40/GU9OKeizhP7QKAGr3SriGUUjPOonyo9CcfzhO3KJh+l0r5zh+pkJQaT1Qj9/racwZ5Z7OP7fvarp+URHuU2513ELOEcAa0+dfpnOGLTN4mwHqRGq0BepgwxMYZ4= 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=TF2fTJ5H; arc=fail smtp.client-ip=40.107.96.63 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="TF2fTJ5H" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MfNuHdCpzZsjCK5ktOOLqTENyi2lBtZBh5xUXkfQqB1hMp/dVCcF9kC9/T9uJeKuQpZTYHKrIAsN+9anEsj+DInKnrAjy3r90RVULFnD21qMbHPtzW25WOa8qN7sVt66aSyKfCNKnIf9SDobg/nb+s6ARH6vQozOglx0E/gk9/OqXDDU2Iz6fCaVvr1+KK2WhgSNNnLuNtHyA7J+F181S0Y8wttl+hkyAw5A2MU4C4IYc2Sk5vroJeHb1BAWReAM5a5S9cRE7lgmI73LQGoyZMgohusvC4lM/m+SnrLRRCqEFHwK53+krEZXD26lTzHIvdA1OoZ8TcLjxzaMvQJJmw== 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=Bniip3OlQHmIpoUbt1Eu7JQNJITIadPtNd79nLHSkRo=; b=O9WbqMKE+DY2yVRniwV7jjVCxRsl8k7r+P1eExFN60ad6cE/inqFx+IkPIkhqTYPtFF4LCrekmzWSUqsvU4IIL6Up1Z4XbvRYk7i3PjpHPqtFaWKMJIsGy4mZYcV80Sw49kMccXtJzjZj0znhkf5MGjUc8rut7RgKFTH5dc/yYPcRA1XTRsjSXnSUNIxmEg0NZ9tTP5sPBgXyb4eu+IbgqMBwfd7JxI2VPzmsxWHJ6aN+Otzp+jJzBT8WrSXpyb4JM/BPirvsHHMCbCeKgFgET1ZfIwDvoPK/hulPXrYFU+DLobDLFIkZL64XjtsKz3yswBCijb/xnnpU/3S61A2aw== 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=Bniip3OlQHmIpoUbt1Eu7JQNJITIadPtNd79nLHSkRo=; b=TF2fTJ5HvjkdDq/0Miug6RUcnJ5oZRyhIMK6x0h48FKyvnW1Ei/yIlT1Wt8Qf1uBvzPVGZuXvk+bQ7N8tuUE/BiLvM8EDlE1aJqKVifQzuu0/7MNtIdZSvzY51DSLCql7ShJI6buEKgwryJ15rqMPqS3flD01nq4h11TcZutN/oOSIcCWJWzvh9iAvk8B7sJ/4Y2DFkYy5HIY3BCk6KFpruk0oGLnj2uptBUeKahh9OMEHM1oLmfxZ+MCG5Xeq2QZmLieg52RkLKpg91o5d3zCAj17q+HDJLQegu18g43ySwoDeMbo9MGB5A2wNzoKFhFJMNDCy9NKKYNSgCJ3X4sg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by CY8PR12MB7121.namprd12.prod.outlook.com (2603:10b6:930:62::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.18; Thu, 22 Aug 2024 14:45:56 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7875.023; Thu, 22 Aug 2024 14:45:56 +0000 From: Jason Gunthorpe To: Alyssa Rosenzweig , asahi@lists.linux.dev, iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Robin Murphy , Shuah Khan , Will Deacon Cc: Eric Auger , Janne Grunau , Joerg Roedel , Kevin Tian , Laurent Pinchart , Lixiao Yang , Hector Martin , Matthew Rosato , Nicolin Chen , patches@lists.linux.dev, Sven Peter , Will Deacon , Yi Liu , Yong Wu Subject: [PATCH rc 1/2] iommufd: Do not allow creating areas without READ or WRITE Date: Thu, 22 Aug 2024 11:45:54 -0300 Message-ID: <1-v1-1211e1294c27+4b1-iommu_no_prot_jgg@nvidia.com> In-Reply-To: <0-v1-1211e1294c27+4b1-iommu_no_prot_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0146.namprd13.prod.outlook.com (2603:10b6:208:2bb::31) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|CY8PR12MB7121:EE_ X-MS-Office365-Filtering-Correlation-Id: c1016b6e-abf1-42e7-597a-08dcc2b92118 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: 8wbC9w3HtGMlC4bBHKHpVxED3Tenb5CiGcA/3VgPz6vcUSaoHJl1oY1T+gklRrmOU0M6npRgx98go2nEC+V6Lgh0smLkhtUDIiWWY5nOLzQaJG2b2KHL9qjPSQIZ3yP6mj+u2IBwsAe6wVWurG42+h2PU1Ib+NZbbHjcbyGIbbpNhYND77+qsHiVhTgrNjVtr9NukV1dnrheNhiqAKDNNVYalr6HyRY369uGjg0PO5cTgNYPzxlKxNGYAN6GFjOoKCLdbabBEeUPJf+VXS8BlP0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+RHvYOFWEcZw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UH25TAbopC/2ZUQYlR0V1iSKF5XVGtdP14r8JPJHtgg6Rb4r1H+RKRqFW5c0g7kzWDov7I6WYOkxSMl9y1Es2ZWL1gXYSD+eHNAOPZ2PXUF8alSPxL1+5Ms7o0awuPTfjgH41Xz54WNnCBdPgMeOrGvL6c76KKpAEoWYvu0j3xqzyeZXuuRXEc01Lrmpy3OGmzNYpAtfUsgXbIuyraVRxKzMxeuyHx5/c98/8NzjU1SiMpX1sy2kolIif3Molz5cXIRBCHIHZ6BeJj8qWnwXMxX6LFQnogbJr4ptaATOor8vo+FM3C+Pa1HtEwRnPVpMuvtWGITCgf7BE2hqJ1xwmJlfTKDqn/1enC4InUNXsoa/+EDVYaUP3NLv1gT0UkJPSoKok82ptjXIVxK7bbM055CiueQNJwXhcYFGIpJkp9ySKi9C46sx8/UCF0IjyGeOjGO8LQbVwaPY8NZy9wxylWPuGw4uDciOImwf+WJNoDPFQTKjBUx70uyTLLYfV2iSNqy3SIrvf+2bZPOZtSCcXR1yLO7N6AXeeRuW8t7tJE7q8RfhqGe+D+iPzmiWqSr0734wn8bCgnXVNq4s6FE1/OFaYJVTrTMN6Lw2VCaU5hbbjvv2CVfRHBEwNSi4v0y5//2UAvPzpGy1mIXnQlMDD035GvsZvTZM0c2ROWmaUVEOWHjAS02ua84j0hZFGVS54b/+trzSj3Ew7hx1aYxpLhFRFBfi9tzBv/Hlua/twO4jvrlUEmVV7GNwnh7tRsP6nbv85XMvtOFjmdujsACEQQlhPlDyfeplTjaB8knphRy0+q7uCGzAAo+lrI0vnQMUNAzcSBSYpTGjmVEMPCIWKx9DCiQ1dNXnRB7NKw3z3b3oMUCAGCFTNBetxFbbgDXXK0IfjPgLqtyYTDYsAZZqGdc18yPDrEP8vxOrupdb6N/m2cU5CUrP9XLgSPLPHZXHENzCmphkQiKDVslTqVZdMe9x4zlc56qeanSY01W7v1l5DRXCV1q/vdLLiUv2lRJPEv1rbwMwQMJTo8C0Ahqn11fejZDHea5oYYKEJku5vIkjO8exG4DykFxa+1YcosmNDXP3PEASZDksGNZdk7Z4X73a9K2rXqattD7H9MoQb/fSJ3DoWBDXZCr6uHP/gfK/S830109fjqBgKSWSE89yZ06kyoutebZkBOG/Zt7cfdPoYix8c12xX06kARf3AZKXwiwHzgRoVX/+AljA5tJpn2BuXfcYOFLhqgEQMsZOBr8JuHcA83pKwXz62MaMnUK/a6oaB0x31N4PB+M2lYdimNRRsTseZ7pHjJTOcbdnOb3/aWCUooOzDclxVXpIKSYQVbLPnxuwo8VHkJa1gg28is+0GITki+m1wBbYDoYI1XsXLVRLT0ngMLKmB+1Q0sVlQDpMqMIZjdorlihQtDunBIb8ZXu35uGQNMoaSscLokYZakK95TfibUHpF4bIyI8Z+caTECsED7DPW7C3Lp3kFzL5i8SzcayISRUjg8TNzhGpBMr7nW6/vDzLoF2oFe0n4GsCt5XguffZzhZliUL6BacA5jhmyaTUEA+LtLrPtLwnOMMo51XqFZ8x9WI5NB31 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c1016b6e-abf1-42e7-597a-08dcc2b92118 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2024 14:45:56.1031 (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: HZcbBiYY6NH7homoYyXYkOOoIuUwa9PdU3M87+kjC+NZH4bhwXJ7YfbjXr7klhCf X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7121 This results in passing 0 or just IOMMU_CACHE to iommu_map(). Most of the page table formats don't like this: amdv1 - -EINVAL armv7s - returns 0, doesn't update mapped arm-lpae - returns 0 doesn't update mapped dart - returns 0, doesn't update mapped VT-D - returns -EINVAL Unfortunately the three formats that return 0 cause serious problems: - Returning ret = but not uppdating mapped from domain->map_pages() causes an infinite loop in __iommu_map() - Not writing ioptes means that VFIO/iommufd have no way to recover them and we will have memory leaks and worse during unmap Since almost nothing can support this, and it is a useless thing to do, block it early in iommufd. Cc: stable@kernel.org Fixes: aad37e71d5c4 ("iommufd: IOCTLs for the io_pagetable") Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Reviewed-by: Kevin Tian --- drivers/iommu/iommufd/ioas.c | 8 ++++++++ tools/testing/selftests/iommu/iommufd.c | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/iommufd/ioas.c b/drivers/iommu/iommufd/ioas.c index 82428e44a837ca..2c4b2bb11e78ce 100644 --- a/drivers/iommu/iommufd/ioas.c +++ b/drivers/iommu/iommufd/ioas.c @@ -213,6 +213,10 @@ int iommufd_ioas_map(struct iommufd_ucmd *ucmd) if (cmd->iova >= ULONG_MAX || cmd->length >= ULONG_MAX) return -EOVERFLOW; + if (!(cmd->flags & + (IOMMU_IOAS_MAP_WRITEABLE | IOMMU_IOAS_MAP_READABLE))) + return -EINVAL; + ioas = iommufd_get_ioas(ucmd->ictx, cmd->ioas_id); if (IS_ERR(ioas)) return PTR_ERR(ioas); @@ -253,6 +257,10 @@ int iommufd_ioas_copy(struct iommufd_ucmd *ucmd) cmd->dst_iova >= ULONG_MAX) return -EOVERFLOW; + if (!(cmd->flags & + (IOMMU_IOAS_MAP_WRITEABLE | IOMMU_IOAS_MAP_READABLE))) + return -EINVAL; + src_ioas = iommufd_get_ioas(ucmd->ictx, cmd->src_ioas_id); if (IS_ERR(src_ioas)) return PTR_ERR(src_ioas); diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index 6343f4053bd46e..4927b9add5add9 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -825,7 +825,7 @@ TEST_F(iommufd_ioas, copy_area) { struct iommu_ioas_copy copy_cmd = { .size = sizeof(copy_cmd), - .flags = IOMMU_IOAS_MAP_FIXED_IOVA, + .flags = IOMMU_IOAS_MAP_FIXED_IOVA | IOMMU_IOAS_MAP_WRITEABLE, .dst_ioas_id = self->ioas_id, .src_ioas_id = self->ioas_id, .length = PAGE_SIZE, @@ -1318,7 +1318,7 @@ TEST_F(iommufd_ioas, copy_sweep) { struct iommu_ioas_copy copy_cmd = { .size = sizeof(copy_cmd), - .flags = IOMMU_IOAS_MAP_FIXED_IOVA, + .flags = IOMMU_IOAS_MAP_FIXED_IOVA | IOMMU_IOAS_MAP_WRITEABLE, .src_ioas_id = self->ioas_id, .dst_iova = MOCK_APERTURE_START, .length = MOCK_PAGE_SIZE, @@ -1608,7 +1608,7 @@ TEST_F(iommufd_mock_domain, user_copy) }; struct iommu_ioas_copy copy_cmd = { .size = sizeof(copy_cmd), - .flags = IOMMU_IOAS_MAP_FIXED_IOVA, + .flags = IOMMU_IOAS_MAP_FIXED_IOVA | IOMMU_IOAS_MAP_WRITEABLE, .dst_ioas_id = self->ioas_id, .dst_iova = MOCK_APERTURE_START, .length = BUFFER_SIZE, From patchwork Thu Aug 22 14:45:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13773591 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2063.outbound.protection.outlook.com [40.107.96.63]) (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 178A11CC883 for ; Thu, 22 Aug 2024 14:46:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724337964; cv=fail; b=DXrjWXHGvh6adJ2BUs3T+591Tfatr+GpR/hSn+NH/2U375lJYiyOVUc1p3y/VqAh6CJ4ILkJK4nvv5RMaWzgDMOOLPAdHIBsyPA5SwbOyLIzqh6zws/3e1tB3UrwX9RoT8Dx5xcioO05I7LgCLj/fxQgvZkpBhyORk4k/Ud1JN8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724337964; c=relaxed/simple; bh=nL630AwvgUKg/rFHkWv2OtHuea7d8GSMkAk6aT1la0w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=XwoLrSD4ZMBkAltKk+yS5Nhcuja8BgXUvJsCHW6QHX9eUiXefekkf7IvPqUmUj5FAZGOeUhywydgHR1AmT+0Dl8uZJF2DkQmcA4qqUspaiL5KPcZCGpTXFdH0029aHT79XUohGEvJ7gT1dqAt0aJ7UjhP30X1mFXDyPpAGuyUgI= 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=ZqHqYE1n; arc=fail smtp.client-ip=40.107.96.63 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="ZqHqYE1n" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=X7yEAflkMRbyl/guCb/Wf5Ru1C91lnScGdmF5by14oLQXt/mV3Idd/hV5RxSv3RtbTczDTzFjQF0wUO1hROmxddFlOLTVi+v21duLwr7wk6Cxz4KFhyeUqczzKvxqgD/cujgQlZ5cdVutobsV9VpJah3y6oHlhvxTY+hTzkkxboDQFkk4WE4DyDZQaPEnNUveEW8uehSzhICJcXrjHVVsmZ8QUVqjVJz0ASQbvxrQavpBn4tU9kkO66KF25ZMLG3GhASKr74RJRXmjNLu/zjnNXmusPFaSIlhnM0jRGYxSppowlfd+MzsndHfhl7+QjKOaCZOyQuoWQY0t3FRGBtlw== 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=+Jb8sm1Xw1MO7W8qJf0xQFy1st66fKi4PEwSDmdhhRU=; b=vUlHiKOmCbqdrLDm+GlHs3C3SvnVZpomMz423Abb5GUOV9P3380ZX2youhvSzObvTpfKFeWiUmr+mN7OyXYpeDWvr5++FadFMXJwAbCia9yFahgrwoFWvU8SvDD4XUTKEPMpqv8i6DXFMQrzCS8R6mAJrz5nj8wC1/d15OULgMtobYEvs5QD/3BaeGJnkKOv4hrU2VNhNwm4wZRSBUxmfj/wfegathfns/FWMOwFuNYAEc2ERafQt6XF81aMPpUXN102zdpMiOUPlGXydE6F2cYsCKnWHPpRtKA76Q578gqxnmXd5PxlYuieXDJSWZ80ixZIxLsmEWKr3tM8vHSMlQ== 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=+Jb8sm1Xw1MO7W8qJf0xQFy1st66fKi4PEwSDmdhhRU=; b=ZqHqYE1nAyzJxm6uWyibCJmW61ng/rzrhePeo9TIAFDOd0qwsfDzAw16rot/+oebYFBcSXuhjbpFi9L1rGoBHJKMNeafEZYuj4WXNnUQtsz+wuNRaNjsueHYqKApNx8c7X7palBj95gnrHiPyQ5ZrWDDQ5Wb91XHuP+hqhJXS2HE/cgCEhIxdssttEcH6gAwJr7iwQvcUxT4YTPWpTY9H45urzV9n4AEP+rOF4VARHftg7BuU7Bl6XCZx65MaMkCD1kOUbAHerzqmWpduJiwGV42OgYPESxNtrUJWz/6ZAbfScbockfCorTAX2ntHZC+enMnbt3rKGqS/CbUDHvFcw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by CY8PR12MB7121.namprd12.prod.outlook.com (2603:10b6:930:62::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.18; Thu, 22 Aug 2024 14:45:57 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7875.023; Thu, 22 Aug 2024 14:45:57 +0000 From: Jason Gunthorpe To: Alyssa Rosenzweig , asahi@lists.linux.dev, iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Robin Murphy , Shuah Khan , Will Deacon Cc: Eric Auger , Janne Grunau , Joerg Roedel , Kevin Tian , Laurent Pinchart , Lixiao Yang , Hector Martin , Matthew Rosato , Nicolin Chen , patches@lists.linux.dev, Sven Peter , Will Deacon , Yi Liu , Yong Wu Subject: [PATCH rc 2/2] iommu: Do not return 0 from map_pages if it doesn't do anything Date: Thu, 22 Aug 2024 11:45:55 -0300 Message-ID: <2-v1-1211e1294c27+4b1-iommu_no_prot_jgg@nvidia.com> In-Reply-To: <0-v1-1211e1294c27+4b1-iommu_no_prot_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0147.namprd13.prod.outlook.com (2603:10b6:208:2bb::32) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|CY8PR12MB7121:EE_ X-MS-Office365-Filtering-Correlation-Id: d2623062-a322-4bd8-b32c-08dcc2b921a1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: Ks0+DvlGmO0H1kFfWYe+5uK3XxJomMCnKQYr1/TqVl3WcTpK7/xUvRr+DIV6qXsNfk9u9Wlfn0GYCwQidNd5VhF+n/n9Hz+EsqCrC5CZZu+hBQ7fI/hZbOtjGekoPQVySfx8mJoSBtwQo2SUvlsSKUSwwx3gWsiyfJGyIndow+R16tx8bw2uVEaz8MmiYV86dPIkPlQ7eG1nA39ayY0U6UEmqhHF3uB1wKO9j6QKc6B7bPMCPuP6qyoXbAgBrA/q765QATSlj4BmBEEOztG5RuIcyFh/3xUIldyv0WecgmG6h2VimMzt4nAFWainn71eCiu2U5vglQwOJuda5e95Q9Y+QQTTxQMPxXr0AEES3LSnhX7UBmFb9ELiznz3/VCXfssqrerg5cHg3+BUHTOx/p84DN68hqhx79GKwZ8WA4Fws7I9CoNE7dRRHVpCXZn7i+z1SC1noUSHhZlcSB3/5+crQ8VRhAzGR/T2dKZAC1SH0qPb3sYFBnjjjaXlTpyJ07f/ObRIGWiFci9mwbZ7BZWimifymfWLrQHuMGDFGQxIArzH9vWteKqg53ttRYwsl6aCIdkUKITm41bDrjqwmEghULTzXj9Z1rCbWStfj+M3QU7Z5otgB8yV1d736xioI6TXML3bhWjaeeMUDvdEmaHT1FSZD9JV28x0hmevfbLSL9Vpdpt5ruBITI/guGB5RKqF4ALyOxfmhWkvD+6sjENngn4MX9f/lO207ABDnB1EHUrrKU70aRDHI2xmKfXSfbWhWUjjSXxPElI53IKEiEjXKthuGmOG6mATIbwAuFkihAVZcx6lK5RCleWUXLgDoh0iiebCnHeus9jjRMCyUGT43mkutv8Q0KSus6OMRa5QvMtlx8KsDPmuO5ym3l9mB2yINDCdGxH+sVEXOPXhMHM1SQRHDKLpPtkLacB0fA+3VLv8NIUUzysm9H674xOulvatn7PsbTPbuZbN1GHBeEwpuRB4r36C2a74+k1SUIf4hjXZ0NMAdbnssPEHeK15A/GY8yV6hh7WUfUu29dHDeXJ/C1biYq+Mfi2l6Or3lB188FhlEXvm7O2kAKGIVuJIcyS8cJCOJ6PFW/4TiF30Jat7vrGkNiR4Z9TGO0NhNtw8kWBqvZSt2lUc/uBlIEx8CgT9jXFShFTyM6YTj60aqArNDH5pVhjlB5SbO0FIYnbPcYF0aDD/dszcjgND1tyQumzSK+/tyq+yApiCZSWhYVIrBYabfrplM0BLCl4A2RbJmQOxO3zdvYXtTv9bW6i6lkPJNhDZR6AxkBqnI0HVhn7Jmsn6lfqjKqSX3OGtzDcB32gMcrr6ljn48nJDVdqP+2zZj/ZF0xEb/S0cgSeOA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mdWlRwrvczGCtTHtX8nDWv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//07Oz45aZx7akR0ig2ZaJK4qr7BWza+g87pkmm3hIhQBTTJ5fRXXLzkwxOBmJ6VPlJLgyCXYOZbq6OwvvlzHpm3w3rCsrmKBqGNvBiRo3m8Y0eFhHoSI7ThUjY4oAjyTl0RM62W/RxvEEyTR3K7lg3fGkvosIeZF3FrO2huHrI+pREQW72aZcCt/GbqhAcfaperW3NnAat3T8BbtvLdnKKN1LOTzRDiFHYx4DwlmT9DI67zBWAsFjgCIzoa4R9B6/9bgnt54DsaDQHqY13oki9PYHhXjXDJuoqRqu4lCZRUI2/YdXClGf4WEFHtqUAyPW98+ZfXOk3DldA8OpynQ1fRLo2N1r1iTZVy2HLG8smyxP6QW2Sz+5sFHZek0xm/3pfnAIptTF8O1lz6o/89B66gToet88hlPCvtmsxZ5LwYK94YY4ULNGHJSy2qs4WfZ1k3HuTCfe4aACqhAWhw6M3/5+rN38vlGNT/RMkdP3Rph6b X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d2623062-a322-4bd8-b32c-08dcc2b921a1 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2024 14:45:56.9755 (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: XvrgSAovCG1pHM7ci3uKPsTxA9j+eiH6ukIhmh6ZRjY3KfSqWpeozboCfHvD8FcF X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7121 These three implementations of map_pages() all succeed if a mapping is requested with no read or write. Since they return back to __iommu_map() leaving the mapped output as 0 it triggers an infinite loop. Therefore nothing is using no-access protection bits. Further, VFIO and iommufd rely on iommu_iova_to_phys() to get back PFNs stored by map, if iommu_map() succeeds but iommu_iova_to_phys() fails that will create serious bugs. Thus remove this never used "nothing to do" concept and just fail map immediately. Fixes: e5fc9753b1a8 ("iommu/io-pgtable: Add ARMv7 short descriptor support") Fixes: e1d3c0fd701d ("iommu: add ARM LPAE page table allocator") Fixes: 745ef1092bcf ("iommu/io-pgtable: Move Apple DART support to its own file") Signed-off-by: Jason Gunthorpe Acked-by: Will Deacon Reviewed-by: Kevin Tian --- drivers/iommu/io-pgtable-arm-v7s.c | 3 +-- drivers/iommu/io-pgtable-arm.c | 3 +-- drivers/iommu/io-pgtable-dart.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c index 75f244a3e12df6..06ffc683b28fee 100644 --- a/drivers/iommu/io-pgtable-arm-v7s.c +++ b/drivers/iommu/io-pgtable-arm-v7s.c @@ -552,9 +552,8 @@ static int arm_v7s_map_pages(struct io_pgtable_ops *ops, unsigned long iova, paddr >= (1ULL << data->iop.cfg.oas))) return -ERANGE; - /* If no access, then nothing to do */ if (!(prot & (IOMMU_READ | IOMMU_WRITE))) - return 0; + return -EINVAL; while (pgcount--) { ret = __arm_v7s_map(data, iova, paddr, pgsize, prot, 1, data->pgd, diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index f5d9fd1f45bf49..ff4149ae1751d4 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -515,9 +515,8 @@ static int arm_lpae_map_pages(struct io_pgtable_ops *ops, unsigned long iova, if (WARN_ON(iaext || paddr >> cfg->oas)) return -ERANGE; - /* If no access, then nothing to do */ if (!(iommu_prot & (IOMMU_READ | IOMMU_WRITE))) - return 0; + return -EINVAL; prot = arm_lpae_prot_to_pte(data, iommu_prot); ret = __arm_lpae_map(data, iova, paddr, pgsize, pgcount, prot, lvl, diff --git a/drivers/iommu/io-pgtable-dart.c b/drivers/iommu/io-pgtable-dart.c index ad28031e1e93d6..c004640640ee50 100644 --- a/drivers/iommu/io-pgtable-dart.c +++ b/drivers/iommu/io-pgtable-dart.c @@ -245,9 +245,8 @@ static int dart_map_pages(struct io_pgtable_ops *ops, unsigned long iova, if (WARN_ON(paddr >> cfg->oas)) return -ERANGE; - /* If no access, then nothing to do */ if (!(iommu_prot & (IOMMU_READ | IOMMU_WRITE))) - return 0; + return -EINVAL; tbl = dart_get_table(data, iova);