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: 13773594 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68651C52D7C for ; Thu, 22 Aug 2024 14:48:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+Jb8sm1Xw1MO7W8qJf0xQFy1st66fKi4PEwSDmdhhRU=; b=ZU0AnSL+TuMOr2pnHUPKUK44o+ SKU5xrlK1hytsOFuxIZlaRMNoR1kL5mfivr+eeqy2vNV6OTnfwZsiukEJ7ccW0HyoBcC1maXaUnQW zC5LqCuB4JCWE7g4aKaO0wvc+wZNpQOHzlPG7kaN6FjAHFdN6H7DJehIwC/1rZjjoj1MSCa69nXcn ea/xiGUoJH7Z948Y4AgMMIsyfxEcjCXFK8JVIKitE4LLe7SttDVawT84jUtVgcr3djEoBpia8yxOr BqKrQdU1lrL8VPcr0Ta55UnjFMEB3Nz3F+vD7E4FwWggMxCI9762LnCaoUNolLjVF4x7ElbROlo/c k+NcceLQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh978-0000000DDfw-23lB; Thu, 22 Aug 2024 14:48:38 +0000 Received: from mail-sn1nam02on20626.outbound.protection.outlook.com ([2a01:111:f400:7ea9::626] helo=NAM02-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh94n-0000000DD1M-0TVD for linux-arm-kernel@lists.infradead.org; Thu, 22 Aug 2024 14:46:14 +0000 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) 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/3xUIldyv0WecgmG6h2VimMzt4nAFWainn71eCiu2U5vgl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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: mdWlRwrvczGCtTHtX8nDWvfXAPOYiu5JYaEZw1egg4O2V++kG7AS9hIax3V2ju3LgF+NV2V0uStweCg1HzikAq60ZdsNSeEHy0D73GBIRKb4xZGCbCJj2H7EyUHjxyu22I7pKxi1YghZhiFz2xvGVb1bijQ+/q8HqUalqBeaRQD+zLLnto6hphK9+SwUelIRUAiTiJn4MdlUs1uxMEj4UaivmBqQDnY/V4cZk9DfstGCA4G3reGZOYwrhCv/MDsPOLqGKmPFpzfWo6++VtUkGD02BL9ZN+Z/t2gMkBdF69F/yjH4HNYVHj8dBP3A1accXj2pwgf5TXCiiQ/QYRUeG/3TBSPMv30APUdsX7hzaL+NIOnRZvVwyRzbb91vY4eUfjamerK548IHUGaEPMoA8NpZEwlkJ3fDinmJZJ3M8fMAvQPIdffxTT75nMzWWd4i2VqlL/FUOQ8ZGeG6sXwgOuH3/8BqMD0VldQFLl/3ZB/qTSes8fwPMsXdQB39J/MlU76DIYUyYYgA4PcHknWib0NSp71XAQbCwddVJz/4l+KgpixGdkWQKjkAJOroVkeBOHpCgqGIkGhWA8oM6CzrVtDoc4PcKlFOHIiMuJKZ8FM0m/3vu9TuPprDMbbGzsgWZGgBRWSVx1bJHSfluWYlGi3sWzKWTazd1oUYqo86HQz3c/qQW5VzEfvZlTh7gbH9yUkV8xrn440BHQxbUAZTPkNf207YSqgOd8CLLHwWnazCbU8vNJlGezswie8mKf603/AFp12zDiBgLXLltqiyI4WJ3sbEkZ+nLfR8m3J41NjIA5d/TKe9Pd8Hg94NE3BZpFpC3t7wds3ZsSjxNuI2AO1Vc/2DLMvo2+O3eAHRZue9RzXszDtMqV5/qN/g0dfiwd6PyR/JLPdN4Dbcyx44q/vSrbeCZILTGyJaX+3cIPBje9nnKfhwWU0rFF+HtU/hD47Zy7YiJTlW3hSyJjye0zDSwHeHKeRil6BxPzFCRmzAkOLQp4USqrqaI1cXZqAHWsG854eUIUY8JY5yOz+6w3qHHR8p+76YXd3HbEzi7WFvx+1U2z7PKlFdZLXi466Qecf+mreB75kUYhfUq//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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240822_074613_170456_999190B0 X-CRM114-Status: GOOD ( 12.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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);