From patchwork Mon Nov 4 17:41:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13861798 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 1F80FD1BDD9 for ; Mon, 4 Nov 2024 18:07:59 +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=N4lP75VHOZXzY4aLyenhJUvf9MzNwBiTzNXMKjL0i7Q=; b=Xu4cAnXAPTV9TvWoUIWsz5uYzI pZ/wflV3FdMfNkKqm9s0SXnBBKy3R4ibvwVbaY5ivfJQMJn0miGliXziI3yMtnpBrUWPPNLIY7Cqx EYl4h6gBZAvzPEKX+dmwH+ejPzeJt31NZRh4yqFMwF+SccX+6fqHAvME4m8mb7Q5YPE8lBdetEvcu yDVjWz1FoaCA7muSEacaaxkjeMrO0xP8RUsLoXh+lQ2jtk7q/sv/dFdHIB6dSjhd1rY+XoXNAr0J9 s41uXUbIxbOLIl0zKS6CzGNKGnL7WaF3gCDoZIoIDWuchuVqVo7AVjCbrEo7/H8Bro9YNqG3GLYJK 8V+YSMuQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t81UM-0000000EeoC-3t2N; Mon, 04 Nov 2024 18:07:42 +0000 Received: from mail-bn8nam11on2062f.outbound.protection.outlook.com ([2a01:111:f403:2414::62f] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t816b-0000000EZKk-1QKs for linux-arm-kernel@lists.infradead.org; Mon, 04 Nov 2024 17:43:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=zRkf32p6YQIi9Vq1cjDbQZMtZNUT+myoXUry1dVlx7Zd7aNr/4JkCk42tjQZqYUHzHteTl0kgSUDhvbf2V2ilzlv7uUK+47TGJz/D3Jk7NCYsJ5QxvUCudYabNtJ+OuXByct0RGBsuPy5F1dBJx3KO+cYEvt/i5EQA6n5rQOLcC7VJnFKtZ4e8ovUtcbZWQGyNK9t5yHHMXaWuzsn6c/H74O2JjAO3VjRxVoFyBCqspVPKzQE3lEZW5GNuGKunddNSvwHDrfa2RNxD95oDJkCojozvrDpKE0WDdJkpy6vwDznlqADqJvaGy+S8cpREFXZSH5jBYmodSMdy8CpxINKw== 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=N4lP75VHOZXzY4aLyenhJUvf9MzNwBiTzNXMKjL0i7Q=; b=YLEXmPQ++xEIHHfVwB/AtMIVHykqpZ9l5xPmetZs6QV0z23R8TVoaUIlXy1q7u0eTGJiOyFXxvZQ49B4Ujiupd6/juGm1+AMxg6m2+Bp2o59bB3R2clPIsX//SKlXqtbT7Vw+N8cMh5aaGA6f1s5n0et7vbJ5Ht9eEUEaoxI+86GRLEfLPOa4RlvWi03qI5lA3JXKwnimLquWktR1f9CDPWBLD8xCFl/dXBRChHYLXls6+boYBUs9frQ8z/fRKUD1IXCNjXhga3bFnW0sXFzpK7R++0tIeAexyFKmPGTanFRsWWnPFVHQIJPbfuok3etqAkHiSL1+laJfW17uBEF0g== 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=N4lP75VHOZXzY4aLyenhJUvf9MzNwBiTzNXMKjL0i7Q=; b=Xq8tv1tBRt8ylch8HmhhHGlXVZgC4GlsTZV8jN2dmCvLCkUmrju/we1o7IHPikeAPti/17GeLq4rrmwN7G3Vzj1K8x+ljllefRa2xs7BzQ4FKWAJITFpl7bnIC5cDZ+3HYhoYMFIJcW6zHJl8yKXsJFBSaWIA/jiWRfw9UJwqc4ArhDtKzSmSwZLkMMOWdt18Psr5d+RpJuD8ye8cR3WQNEI4zgLcTPVRDdwhkdZmU7ujQqcH4IoC/JvV75wu/Tr0PQkHqE5vv6iWPWjBGrWWhlsnEh1teFyiUweZovIX7DZCmrYvwi/1CuRiUQnjFDxbwl3jrF07GeehF/Ec2AKig== 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 IA1PR12MB6578.namprd12.prod.outlook.com (2603:10b6:208:3a2::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.30; Mon, 4 Nov 2024 17:42:05 +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.8114.015; Mon, 4 Nov 2024 17:42:05 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Boris Brezillon , dri-devel@lists.freedesktop.org, Liviu Dudau , patches@lists.linux.dev, Steven Price Subject: [PATCH v2 1/3] iommu/io-pgtable-arm: Remove split on unmap behavior Date: Mon, 4 Nov 2024 13:41:29 -0400 Message-ID: <1-v2-fd55d00a60b2+c69-arm_no_split_jgg@nvidia.com> In-Reply-To: <0-v2-fd55d00a60b2+c69-arm_no_split_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0421.namprd13.prod.outlook.com (2603:10b6:208:2c3::6) To CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB8659:EE_|IA1PR12MB6578:EE_ X-MS-Office365-Filtering-Correlation-Id: bfe5103c-2591-4b95-ba13-08dcfcf7ebdd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: SftlwhmoIMuEnxWlCfXTUSeVn+Fw9TYoScnZysJ0IZix5cpHIras7WjLkdKj7nV7WX9RXMvbTtkXC2wJkEFFwKkNxqYFfuWG25kJRqFxYegYtXL696SFxiMNYJAsu1C2ypb3b+XvSSSlXO1Cl3rCbObUW/Ooo+w8EYH4XnLcJC+HtuZmGehGYuPqGovpwjjBz8HX5jMzzAgE/uBBgnBvMGrNSMMyaKNruIMgQVPCB12zCzzJUUcLpVA4sXnwGngXKFMR5mg2nwOr49Esq2x6zjRngwkly1TM1wEO0oakZlGSYgi2CJdTabFYNC16q8kfnRaSbTyIVJx7t1endXnYQ2kgGVffd2JPG4XrXOXcFsUn2vswPdZgW01FfXViI0OUpdp+M7sBrw1ZIgT7XxMSQ3nLB1GRstKYOviUPG4MxfGRPzatb5N7l5qfm23UnBB+qfB6RfjEyw9Wb4hqmJJBTxoyrvDe+6u9wZOhwBCv7PD7lOcg69awkYMgQoncA8NPEywK8Xw0sk9cLmDYZ4k3f8Q3w8H263S5F6Zyw3xzdbNnnfVPriSZeGUAEvZLhRXqvrSIDsXb41jsLH7tLOE6edUirLwY0UAJInZSilZi45hpUNf3FECxbQ30wKVUcYlgCC0AUe6VwHdnKjSBtLn7Sfo42SJ+YgrhV7XPPR+Wsiif9g+WYQN+wej1fHif2ARFuKh9x2IP9Ql2d1AEjPjwSUuXs6sSshkWVHoz3I0edBTxngyNR8FjHoUT7u5h+lnjEcV1zeZUq974gniLmDJOtf1fjJFHQ4kxGcfTcerRrCpLpLQabqzV89Em/1yT/HOxxe5ZcgwcT8hqdj4bxn9nryOFGEzui3c/da9n/O1bJW1F+Umm9e8oQTGUb7C8lGBK/JR992Yqh9IMln1H2XrYWRI31TLqQN3C4deJAD2zOFM0C1RZLkkMMycym8JEGJ/1hrC5xA5hCckG4G3lgFWgNWbTKed3Y1fZ5y9ccxpSJMK/mpf0BDSari19r+qljU7JlYeoDbyzxt3QS5W1vD81459N9qCAYCoP2vG2X6+H5a9swY3zY2nBW1jUqYT4inBLQ+PRDUidiOS5Cib07KnNigX+/CFnmV+ZWKmTxca7dDoxOuwfRu+0f8slQHobr5qDLCZ+ZHAJJ8U1ikWA0GwDBtIJgF3QQhCUZBygHHf+N/VhpUHgpG0HFPeDOfRj3c4YUOI+Chl8u1uKHIiDFvMdGgaut5QAFRJHhVydjhjOHVNkw55jpdEHDnjufvIz4sQkPnt5L894YOQVsg08cb6vfpEdA02t8xzunt9mG87DtL1ZQVq7f9UkfMZnXPfYNiVu 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);DIR: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K7fPOR1P5yIpHFA+W2JMOM93tktCy46nro3tX3NRVf5uRAAnfoAQXdto5GS90r7b7lBovWyaDqaYcStVg5fYqgySs9Js3ddbkKosKu/S6O2hGssd+DMg2W0Fq2OT6ODGaFMUBLFvwyC3RABTGh+N+cVUjV1GbFcK+L36/I4H4FFcNAUXdZXeMXfTtzoJvlKGSKev+B7cg6CuNCmMwW4cqsYDJoyDxnUiRAPIovPJx44ySI7jBNjTyQCVjVDB4W2ObXzXMNUQLUX24gdBYWkJnNOkvhCb5Nrw0f8CasIJZAFaZzKyRYgB/cBs/oCJvd2eF0XXIyYJdwODOIUKmEF4q+3NJh1ErOKOPW+hkyJ1KN62HO5cko5uWiKhlk57JSt4WIH7u2IQfdqaHR+NmX5qlaalAQQlO/rKNQ9/W2hfNrVNejXSDmhAegCPdnIXV4spkO/UtQlqAhEiqHL6Mq6PmxVjUex73m2eXj+wcln1QOJlboq8jJzSul+mr7xAgL+vquU7UgYISoOAcw0y8KOBgIaXMjtRSC6IjiHY/4NGYYeMvcEBCSQ6IOXOKE= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: bfe5103c-2591-4b95-ba13-08dcfcf7ebdd X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8659.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2024 17:41:32.7086 (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: 0fXtXv2oomVvB7GxYQYB2lcoK2cDDJSrUCXlY2xFvPYIvsHJyvbs//wIuaxUdeGf X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6578 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241104_094309_414498_04BA3DD2 X-CRM114-Status: GOOD ( 20.71 ) 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 A minority of page table implementations (arm_lpae, armv7) are unique in how they handle partial unmap of large IOPTEs. Other implementations will unmap the large IOPTE and return it's length. For example if a 2M IOPTE is present and the first 4K is requested to be unmapped then unmap will remove the whole 2M and report 2M as the result. arm_lpae instead replaces the IOPTE with a table of smaller IOPTEs, unmaps the 4K and returns 4k. This is actually an illegal/non-hitless operation on at least SMMUv3 because of the BBM level 0 rules. Will says this was done to support VFIO, but upon deeper analysis this was never strictly necessary: https://lore.kernel.org/all/20241024134411.GA6956@nvidia.com/ In summary, historical VFIO supported the AMD behavior of unmapping the whole large IOPTE and returning the size, even if asked to unmap a portion. The driver would see this as a request to split a large IOPTE. Modern VFIO always unmaps entire large IOPTEs (except on AMD) and drivers don't see an IOPTE split. Given it doesn't work fully correctly on SMMUv3 and relying on ARM unique behavior would create portability problems across IOMMU drivers, retire this functionality. Outside the iommu users, this will potentially effect io_pgtable users of ARM_32_LPAE_S1, ARM_32_LPAE_S2, ARM_64_LPAE_S1, ARM_64_LPAE_S2, and ARM_MALI_LPAE formats. Cc: Boris Brezillon Cc: Steven Price Cc: Liviu Dudau Cc: dri-devel@lists.freedesktop.org Signed-off-by: Jason Gunthorpe Reviewed-by: Liviu Dudau --- drivers/iommu/io-pgtable-arm.c | 68 +--------------------------------- 1 file changed, 2 insertions(+), 66 deletions(-) diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index 0e67f1721a3d98..9a16815b3f3434 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -569,66 +569,6 @@ static void arm_lpae_free_pgtable(struct io_pgtable *iop) kfree(data); } -static size_t arm_lpae_split_blk_unmap(struct arm_lpae_io_pgtable *data, - struct iommu_iotlb_gather *gather, - unsigned long iova, size_t size, - arm_lpae_iopte blk_pte, int lvl, - arm_lpae_iopte *ptep, size_t pgcount) -{ - struct io_pgtable_cfg *cfg = &data->iop.cfg; - arm_lpae_iopte pte, *tablep; - phys_addr_t blk_paddr; - size_t tablesz = ARM_LPAE_GRANULE(data); - size_t split_sz = ARM_LPAE_BLOCK_SIZE(lvl, data); - int ptes_per_table = ARM_LPAE_PTES_PER_TABLE(data); - int i, unmap_idx_start = -1, num_entries = 0, max_entries; - - if (WARN_ON(lvl == ARM_LPAE_MAX_LEVELS)) - return 0; - - tablep = __arm_lpae_alloc_pages(tablesz, GFP_ATOMIC, cfg, data->iop.cookie); - if (!tablep) - return 0; /* Bytes unmapped */ - - if (size == split_sz) { - unmap_idx_start = ARM_LPAE_LVL_IDX(iova, lvl, data); - max_entries = ptes_per_table - unmap_idx_start; - num_entries = min_t(int, pgcount, max_entries); - } - - blk_paddr = iopte_to_paddr(blk_pte, data); - pte = iopte_prot(blk_pte); - - for (i = 0; i < ptes_per_table; i++, blk_paddr += split_sz) { - /* Unmap! */ - if (i >= unmap_idx_start && i < (unmap_idx_start + num_entries)) - continue; - - __arm_lpae_init_pte(data, blk_paddr, pte, lvl, 1, &tablep[i]); - } - - pte = arm_lpae_install_table(tablep, ptep, blk_pte, data); - if (pte != blk_pte) { - __arm_lpae_free_pages(tablep, tablesz, cfg, data->iop.cookie); - /* - * We may race against someone unmapping another part of this - * block, but anything else is invalid. We can't misinterpret - * a page entry here since we're never at the last level. - */ - if (iopte_type(pte) != ARM_LPAE_PTE_TYPE_TABLE) - return 0; - - tablep = iopte_deref(pte, data); - } else if (unmap_idx_start >= 0) { - for (i = 0; i < num_entries; i++) - io_pgtable_tlb_add_page(&data->iop, gather, iova + i * size, size); - - return num_entries * size; - } - - return __arm_lpae_unmap(data, gather, iova, size, pgcount, lvl, tablep); -} - static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, struct iommu_iotlb_gather *gather, unsigned long iova, size_t size, size_t pgcount, @@ -678,12 +618,8 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, return i * size; } else if (iopte_leaf(pte, lvl, iop->fmt)) { - /* - * Insert a table at the next level to map the old region, - * minus the part we want to unmap - */ - return arm_lpae_split_blk_unmap(data, gather, iova, size, pte, - lvl + 1, ptep, pgcount); + WARN_ONCE(true, "Unmap of a partial large IOPTE is not allowed"); + return 0; } /* Keep on walkin' */ From patchwork Mon Nov 4 17:41:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13861797 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 EAF50D1BDD9 for ; Mon, 4 Nov 2024 18:05:58 +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=w5dyMpaxVKJ7sq3235EVEehNwOlgEvvq442grvZzSWI=; b=RzUxYgchWVLRESOxoKD7BL+yQi RSh1zDm8WA+Rrhvh64D+wuLr/U7p8aaDF5tFxoerCBLAm9JrzkKFRLs/OzrRaGykjCNTfPII866Kp L3y19FscVfaCqGFxSWYxMJi6cZvkvK0wh41x7sPiVOJvfOXUqgMJg939LPP/kDsTQqNQ7TNaWyjkC w5OSLZulZBGPJFANvC4WichUwSzcuGKvf9CQqHHaMqv7Pbt7MPkkH8yE2yAyU6+DRWxFE1i0gf5u4 a7sqDQxnxBGMEMwKDO+XvxrnFrhsu6MizqHtEtoVFe+QZ7H+WpNEOWkKq8fxbvwn+S5XgthXJVSS+ ST96OknQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t81SS-0000000EeRh-1Osn; Mon, 04 Nov 2024 18:05:44 +0000 Received: from mail-dm6nam12on20621.outbound.protection.outlook.com ([2a01:111:f403:2417::621] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t815p-0000000EZFx-2DmN for linux-arm-kernel@lists.infradead.org; Mon, 04 Nov 2024 17:42:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KRbN9s9N3Cv5uUW2BeiattptOvl/RaMSSOGYu2VoPkICCoO7GMfmx5ABep1tpHT5IQ5e1ZO0vpsIas38+Q5qTUlOJYWjk/DqSxgXtPeDr98X7pCKHUrRQz+PDPXJLBIPawfOZ8/4A7aunAFpv6NCUihcJ9sqVfR3ujmW32ezwxXAoMx4vbgAUs56dTci05Wj7V+sqjaSTNwPOy9te9xkgHBKMZE6i+rtLWiwTOwDNIqRQ6o2K8YUj94awYAB7ylWX+9fSG3sC6CKku2hHXa9ZYXecVHd7JdpoYCuqakQJJNK51QNywIK9AdblldbYAc1yxHvXpfJGTBiYFIfmWG+nA== 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=w5dyMpaxVKJ7sq3235EVEehNwOlgEvvq442grvZzSWI=; b=gIUDeXpzj7l+oWIB+B/262/2im8eohvzntNrY/+5dyEm/VACEp34eS4aouCmUDFhs2bmZfUeoqivR15BzrWowm+xp6JQDsWf+AJUJjaQVBlk1K8jDmVRwNv3D9D32uzAmW1DJ7ZLSMwdbxlbh4Ce1oH8gyH5Ps43+loLE+i8Aksy1x2WlmOEmyhyO/3lEuWmTwz3KW7WPmBlpZK8Rzj70QuhwtNflmuNT8RGD72OD4xTyUlCr+NmWHeRF7yaRc7TzJ+DtHKvaouQdBkAk0nG1Sa08vZ3l1W+G+Efj/Eq0rHSyksjwtjHbc8AeyxoxTZQy69DfPrnRKH1XHn0tWrehQ== 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=w5dyMpaxVKJ7sq3235EVEehNwOlgEvvq442grvZzSWI=; b=r4Dj0MIzhdDxj/fhldTu8jJncnmCCDWhjyJgGcKBLAOCZ/nWJGbf8LIug4s4bnS1rqIDscAx+DtaUI+PKDyXL5Wjq6q5cx+lOEDZmu7dM/J/EySFSxSq3e330nnq9BBei8fBswkqereR2UvOaZu3EqTZ7k/TpopG0D8wyWT6Hui/dvreeEL15v6XY0Krw6IyV8q14BOps/q0K4YSzMxO9Zms75vemncAEyK+z6DaDZ5TyrewZpnwN1r6ZATw4UlnbFHeak8NvR/MdqjN7w9b3iTggG9AlSA4plVX3pNQb9eT1Iixa22ISI3cHoM9BZegxXtQHQMs8UH52zJRnx8ozg== 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 PH7PR12MB5619.namprd12.prod.outlook.com (2603:10b6:510:136::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.26; Mon, 4 Nov 2024 17:42:15 +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.8114.015; Mon, 4 Nov 2024 17:42:14 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Boris Brezillon , dri-devel@lists.freedesktop.org, Liviu Dudau , patches@lists.linux.dev, Steven Price Subject: [PATCH v2 2/3] iommu/io-pgtable-arm-v7s: Remove split on unmap behavior Date: Mon, 4 Nov 2024 13:41:30 -0400 Message-ID: <2-v2-fd55d00a60b2+c69-arm_no_split_jgg@nvidia.com> In-Reply-To: <0-v2-fd55d00a60b2+c69-arm_no_split_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0411.namprd13.prod.outlook.com (2603:10b6:208:2c2::26) To CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB8659:EE_|PH7PR12MB5619:EE_ X-MS-Office365-Filtering-Correlation-Id: cc683a0e-d0b2-48ea-4756-08dcfcf7ec7d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016; X-Microsoft-Antispam-Message-Info: p8BKxDqxAZ79LCeFJVtsDcpb+UgJkSnLGnmuTQ+REPY3unaTGKoSf4yjmAN1p4lmGPFHTm4IfvXu4xcDP+UqaCy0OFjZuVaBOFexCRQXUJC9lDey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c5FMq4C7u2rl5dC5CkmxMzbsXcRQl6QK7aKPt7ngJt7S1r6xKXoygSZ7SW7YR3uQuDssLkanMdbSUxS20E/hKF+feytSRnpIFam4lvvIDIV08K8suFX7AaDJZaFNKWdjQr99/sYIGcnFd45kCFsnfksOczpMM 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fJ28kxfHJFZ2RUYFcf3+M8+ZJbY2ybI4rC0Jtr2f779CysZ6N5BoP5Z+5OZLLHAsWUB9BlGJhxboNOfQLNt/zuqRe8oFgZEGHScLVwZZNa8dgB623fpV5B2WPCBJYbM2mM7+SSZFJkF8/yXIwkNfALKpDJR78nO9qMUD+IbipWC5YQ6kNrU/TnkNXpEVo3vFGWqKyJ+hoDwtXEXCNVDnuYekc2CTvZGz5kSZkjf0YuIjqVrAgO1lB58+vB0Of6euz2w0l5Gqh8jxdeK7YPdESBXIHmmpH8HqODykzi8Ro7/VhUMH+Fo7wLJpBax8MHcim1UUQFRFdVBkDspDy0bOxAo02wxE8cuen8RP86z2ft3VhsnlvWnTWl1QHB/ic2RaRoN7gGFA/z3wmhow4aYM5TLOgDa67eg4f0s7NdgYVX/KXlyqtGqlrkZ18UcBdPiQMHyTa6q2can2t7heqL9koRxHBZqoFji4o37pO0BS0/c/uaqN4aLhL+zrOeZxKTrpeh3g6+4u9ihbyrmH7W3hT8L6sCTktBTe269RGFsIKj2ZDzS/dR9GyMczjJZpVbPW25BNd7riXvOcGGB7iEoFi1FZ2A0SP48rTzPwIWdfMgddgswJSt2g0L8Fg8KokdG1N/3QLaZCJ8h8/kC3DfE3C5yYuJ0PHztzJnRe3QMlINQG/cVuj8oVyj9N65pT7MIJ5hpfsjigIEPCXnKGpcB/bQMe1Rh0fc9RLtXkTEVYMKNGZclsUARuTC6P93qzeEqUGZiPGNasEqWKgtZwaoOLmzwMymluqEatfYAZsUumHB+SMXrrLXVgyQ6wnFSmjkj+no7fpJalQCDsVUZA1+svYGqNPlSjHMkTeZ2xLzFYs90pUOUGgZUQoSx9nMzaghekSdave7N2AJQ7nnH7gmC5KlyNj3732MhHxzzUJPPy/QrmGa6V7R5iuNtymEdiMVKhWXrG5iPpIJeuX7EaZ1piPNgB2k2kF8HnaMcCHb/uAftpX/4ijW4XhPtcLGhebpdN7STE1O39BA3IW4usviZfhvBF3ggzwNJCtws8EA/HIv53z8GRcRauQtQJL4cgIlshQUx8Ofi8k8p/ZW1pP4dpRagk0Vz+t3Y+mPsOihCodYS5TEewc0oPcVGZ4Xddx1rEzPaqXzzpWXTwD4pf6qd63ejbXERAoCNgBmh1/dRp9MwYZH2seNVjESRNz7EVUmuRMiy8uaNjorM+7s11MeUN8olk1XYuKJYNmiUry63zsc7zvfB31JFl3yGJqK4snp2o9N7N7t7SQnprcRMeqQske/3whLA6WKUNSOcCE0HT5V2rkizl+p9Xv8DQHJYWOkdxd8D7FqbllSuvHGoRLlB1kZ0NVNKQcdMmR9panWn+VhbSG5crKuROmMJqAZF0wcKatj7ALEpGvEfY0NclijodWof5zTriRW8df+7D1yTdCKV6j8JI9slzPBFP6GSSUYBUe33eBIlyHf5kWbNfWhkFTvmHwz2iYjkKGanuT0zU4GSWhEXasE3ameWhTCTcAgN/yRICiueYrk99+FW4V8+cNBOY1vrmLPbA36Tf+G3048Y= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: cc683a0e-d0b2-48ea-4756-08dcfcf7ec7d X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8659.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2024 17:41:33.6003 (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: UA/vnZc/KZnaDqHK7UMYFnJZry8hZyxFvI2kKBQKeSinfV68ei27DyfUxfmmmQnY X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5619 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241104_094221_630212_33C29927 X-CRM114-Status: GOOD ( 19.57 ) 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 A minority of page table implementations (arm_lpae, armv7) are unique in how they handle partial unmap of large IOPTEs. Other implementations will unmap the large IOPTE and return it's length. For example if a 2M IOPTE is present and the first 4K is requested to be unmapped then unmap will remove the whole 2M and report 2M as the result. armv7 instead will break up contiguous entries and replace an entry with a whole table so it can unmap the requested 4k. This seems copied from the arm_lpae implementation, which was analyzed here: https://lore.kernel.org/all/20241024134411.GA6956@nvidia.com/ Bring consistency to the implementations and remove this unused functionality. There are no uses outside iommu, this effects the ARM_V7S drivers msm_iommu, mtk_iommu, and arm-smmmu. Signed-off-by: Jason Gunthorpe --- drivers/iommu/io-pgtable-arm-v7s.c | 125 +---------------------------- 1 file changed, 4 insertions(+), 121 deletions(-) diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c index 06ffc683b28fee..7e37459cd28332 100644 --- a/drivers/iommu/io-pgtable-arm-v7s.c +++ b/drivers/iommu/io-pgtable-arm-v7s.c @@ -166,7 +166,6 @@ struct arm_v7s_io_pgtable { arm_v7s_iopte *pgd; struct kmem_cache *l2_tables; - spinlock_t split_lock; }; static bool arm_v7s_pte_is_cont(arm_v7s_iopte pte, int lvl); @@ -363,25 +362,6 @@ static arm_v7s_iopte arm_v7s_prot_to_pte(int prot, int lvl, return pte; } -static int arm_v7s_pte_to_prot(arm_v7s_iopte pte, int lvl) -{ - int prot = IOMMU_READ; - arm_v7s_iopte attr = pte >> ARM_V7S_ATTR_SHIFT(lvl); - - if (!(attr & ARM_V7S_PTE_AP_RDONLY)) - prot |= IOMMU_WRITE; - if (!(attr & ARM_V7S_PTE_AP_UNPRIV)) - prot |= IOMMU_PRIV; - if ((attr & (ARM_V7S_TEX_MASK << ARM_V7S_TEX_SHIFT)) == 0) - prot |= IOMMU_MMIO; - else if (pte & ARM_V7S_ATTR_C) - prot |= IOMMU_CACHE; - if (pte & ARM_V7S_ATTR_XN(lvl)) - prot |= IOMMU_NOEXEC; - - return prot; -} - static arm_v7s_iopte arm_v7s_pte_to_cont(arm_v7s_iopte pte, int lvl) { if (lvl == 1) { @@ -398,23 +378,6 @@ static arm_v7s_iopte arm_v7s_pte_to_cont(arm_v7s_iopte pte, int lvl) return pte; } -static arm_v7s_iopte arm_v7s_cont_to_pte(arm_v7s_iopte pte, int lvl) -{ - if (lvl == 1) { - pte &= ~ARM_V7S_CONT_SECTION; - } else if (lvl == 2) { - arm_v7s_iopte xn = pte & BIT(ARM_V7S_CONT_PAGE_XN_SHIFT); - arm_v7s_iopte tex = pte & (ARM_V7S_CONT_PAGE_TEX_MASK << - ARM_V7S_CONT_PAGE_TEX_SHIFT); - - pte ^= xn | tex | ARM_V7S_PTE_TYPE_CONT_PAGE; - pte |= (xn >> ARM_V7S_CONT_PAGE_XN_SHIFT) | - (tex >> ARM_V7S_CONT_PAGE_TEX_SHIFT) | - ARM_V7S_PTE_TYPE_PAGE; - } - return pte; -} - static bool arm_v7s_pte_is_cont(arm_v7s_iopte pte, int lvl) { if (lvl == 1 && !ARM_V7S_PTE_IS_TABLE(pte, lvl)) @@ -591,77 +554,6 @@ static void arm_v7s_free_pgtable(struct io_pgtable *iop) kfree(data); } -static arm_v7s_iopte arm_v7s_split_cont(struct arm_v7s_io_pgtable *data, - unsigned long iova, int idx, int lvl, - arm_v7s_iopte *ptep) -{ - struct io_pgtable *iop = &data->iop; - arm_v7s_iopte pte; - size_t size = ARM_V7S_BLOCK_SIZE(lvl); - int i; - - /* Check that we didn't lose a race to get the lock */ - pte = *ptep; - if (!arm_v7s_pte_is_cont(pte, lvl)) - return pte; - - ptep -= idx & (ARM_V7S_CONT_PAGES - 1); - pte = arm_v7s_cont_to_pte(pte, lvl); - for (i = 0; i < ARM_V7S_CONT_PAGES; i++) - ptep[i] = pte + i * size; - - __arm_v7s_pte_sync(ptep, ARM_V7S_CONT_PAGES, &iop->cfg); - - size *= ARM_V7S_CONT_PAGES; - io_pgtable_tlb_flush_walk(iop, iova, size, size); - return pte; -} - -static size_t arm_v7s_split_blk_unmap(struct arm_v7s_io_pgtable *data, - struct iommu_iotlb_gather *gather, - unsigned long iova, size_t size, - arm_v7s_iopte blk_pte, - arm_v7s_iopte *ptep) -{ - struct io_pgtable_cfg *cfg = &data->iop.cfg; - arm_v7s_iopte pte, *tablep; - int i, unmap_idx, num_entries, num_ptes; - - tablep = __arm_v7s_alloc_table(2, GFP_ATOMIC, data); - if (!tablep) - return 0; /* Bytes unmapped */ - - num_ptes = ARM_V7S_PTES_PER_LVL(2, cfg); - num_entries = size >> ARM_V7S_LVL_SHIFT(2); - unmap_idx = ARM_V7S_LVL_IDX(iova, 2, cfg); - - pte = arm_v7s_prot_to_pte(arm_v7s_pte_to_prot(blk_pte, 1), 2, cfg); - if (num_entries > 1) - pte = arm_v7s_pte_to_cont(pte, 2); - - for (i = 0; i < num_ptes; i += num_entries, pte += size) { - /* Unmap! */ - if (i == unmap_idx) - continue; - - __arm_v7s_set_pte(&tablep[i], pte, num_entries, cfg); - } - - pte = arm_v7s_install_table(tablep, ptep, blk_pte, cfg); - if (pte != blk_pte) { - __arm_v7s_free_table(tablep, 2, data); - - if (!ARM_V7S_PTE_IS_TABLE(pte, 1)) - return 0; - - tablep = iopte_deref(pte, 1, data); - return __arm_v7s_unmap(data, gather, iova, size, 2, tablep); - } - - io_pgtable_tlb_add_page(&data->iop, gather, iova, size); - return size; -} - static size_t __arm_v7s_unmap(struct arm_v7s_io_pgtable *data, struct iommu_iotlb_gather *gather, unsigned long iova, size_t size, int lvl, @@ -694,11 +586,8 @@ static size_t __arm_v7s_unmap(struct arm_v7s_io_pgtable *data, * case in a lock for the sake of correctness and be done with it. */ if (num_entries <= 1 && arm_v7s_pte_is_cont(pte[0], lvl)) { - unsigned long flags; - - spin_lock_irqsave(&data->split_lock, flags); - pte[0] = arm_v7s_split_cont(data, iova, idx, lvl, ptep); - spin_unlock_irqrestore(&data->split_lock, flags); + WARN_ONCE(true, "Unmap of a partial large IOPTE is not allowed"); + return 0; } /* If the size matches this level, we're in the right place */ @@ -721,12 +610,8 @@ static size_t __arm_v7s_unmap(struct arm_v7s_io_pgtable *data, } return size; } else if (lvl == 1 && !ARM_V7S_PTE_IS_TABLE(pte[0], lvl)) { - /* - * Insert a table at the next level to map the old region, - * minus the part we want to unmap - */ - return arm_v7s_split_blk_unmap(data, gather, iova, size, pte[0], - ptep); + WARN_ONCE(true, "Unmap of a partial large IOPTE is not allowed"); + return 0; } /* Keep on walkin' */ @@ -811,8 +696,6 @@ static struct io_pgtable *arm_v7s_alloc_pgtable(struct io_pgtable_cfg *cfg, if (!data) return NULL; - spin_lock_init(&data->split_lock); - /* * ARM_MTK_TTBR_EXT extend the translation table base support larger * memory address. From patchwork Mon Nov 4 17:41:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13861829 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 BA84ED1BDD9 for ; Mon, 4 Nov 2024 18:13:06 +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=3FmUti5hyPngciJaVxe7xicKq4d8a253X8yWeIASYzw=; b=flyxpCueSJVFHcwUSFI7q+Rj6m zy8MxKrWrzB5pJLja4XnPRtl7T+jIC3bk3fwR7hjrfKyC506KCtJeAC8aqud5EaDqjTB9tOJDB8MS rNIMIjjoiUL+9BtDeZsETNO2m8Asdt0IAXM2wvzy0/RwfAqgUHhICi8lDde0HJ8mEeMSzmSJ59Yth J8eC+a5H7U+1E2Nw7kHOwWlIppo+3x8sB2HtSSI9yWdM4VD5YRZddf+LFysslMELmR95T/tmvmWB6 tNPTqFud+DCxLNRxxb92QsqSfIkh/mFS25L9Ur6Ffj+RNkxXtIp6HwVVTU8A1QmnvXTSbXISqTJu7 NdE61Z1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t81ZR-0000000Egaz-0LKW; Mon, 04 Nov 2024 18:12:57 +0000 Received: from mail-bn8nam11on2062f.outbound.protection.outlook.com ([2a01:111:f403:2414::62f] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t816Z-0000000EZKk-1rIb for linux-arm-kernel@lists.infradead.org; Mon, 04 Nov 2024 17:43:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AIzEIylxcHRps6/EZCt4Sqm39kGABWndptlmWE4dYq8At/jyRE5xG33dgbuWJpdC+eIfhmgK/QJkBNrwQwDUxN+35mLk79LH4LVN3a74/lRNOOzXa0tQVrF6JsPVG8fNktYP80mFL9KTfUEIyXq8G3uyJ+GbO39ck6OpRwsuiM18TC/EzWkhANMqCsPdz7GKmKLCqvu8CsJs6pIIXK57f/ni3t7MQi0uv4Fr4UVqcMvNUYOdAT+PlP8Ytx1rX2r4DwStwQwQ6ZgIBHnzqFTOqtZ6+sp+wBI3dd8M3suL6zdGtAi46wFxJP8E9Y+y4g4J6fOVsZvz6o0YvXpbh94/7w== 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=3FmUti5hyPngciJaVxe7xicKq4d8a253X8yWeIASYzw=; b=HyC5W6Oa+VbH3BhUvBG9+bY/xhkUVfBJRE6KZk4j32g5WG9H/LfcptKCTgRqQKxyIP6ky+fmGjfqwSOMlJufuLDj/onLgy2ojX8wa3JPX3ySq4IzoyEtbI7gngaSEwonmvmSlBE6/KG10xP/sY5vey3zlmM9mNys8cK0FjuuXMHyWVgdZ7g/wNYe4y6n7hw4St+pXsA4KvxNnVCcwUxJixRvr/adqjpPuDBXaNeDrIMvoxpmcz947HpV6kpNcwfqHKzzGqeHbXVu+kCPnCYg+x/5fSu6szu0zoEW7uc0ltkGTsmaTx0Zpma7jcuTLpcXis00a4uyrqF9Du31CRIXMw== 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=3FmUti5hyPngciJaVxe7xicKq4d8a253X8yWeIASYzw=; b=kSlXz3CBHdilCkShRtJU60f2d6VT2+q0XGV0wivq6MPRJ9JZGI5qMOvxjpdFsBUuyYOFUTFDX37kuWCucZawydQ39JzT+vBBLYyYrFdj73TId+iyKZ1Pr33gche9ZKxE310PwKcmZA9+ZPFLKrkCEm60O5KlXZCrJ9KHAzmQDDJ+72wuOw0NyEtVjODYn9txvLC+brOwhWrCMz4qeUvpdIE6YEIUlwp5h3SewXqUcpvOXbMOVj0mUPOYgNEMaezJD+H9B9fAQ9IOqtI+DoaSfqzaOXlC3gYN2ajdMQcz3PQhgPm76Mchn6YR7KghxToRdcQT/W7Q09D3RCwYTObYVQ== 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 IA1PR12MB6578.namprd12.prod.outlook.com (2603:10b6:208:3a2::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.30; Mon, 4 Nov 2024 17:41:33 +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.8114.015; Mon, 4 Nov 2024 17:41:33 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Boris Brezillon , dri-devel@lists.freedesktop.org, Liviu Dudau , patches@lists.linux.dev, Steven Price Subject: [PATCH v2 3/3] iommu: Add a kdoc to iommu_unmap() Date: Mon, 4 Nov 2024 13:41:31 -0400 Message-ID: <3-v2-fd55d00a60b2+c69-arm_no_split_jgg@nvidia.com> In-Reply-To: <0-v2-fd55d00a60b2+c69-arm_no_split_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0433.namprd13.prod.outlook.com (2603:10b6:208:2c3::18) To CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB8659:EE_|IA1PR12MB6578:EE_ X-MS-Office365-Filtering-Correlation-Id: 0ac6cfea-f5fc-4adc-6a5a-08dcfcf7ebd9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: sZYyiaHSjmF9C2eyWM+0gsK/CmYCoTcHAHF6ct4e/8G6l5rrWlrwo02mPJO0kI0e/sn1QwwQIfFQ3iKwsO1J5fHa/SaMlXI/HXCqyWBdyh9ReXM1D9Ozg3bnWOBTa/A4PbpKyriOmBBaYZ1oqVVS/GRG4fVivxH1aC4jVAgpBCKOxeCqGK81m37Ab63ve3XZxpVsSzLCLISqk489Ap3cHRjxfAbM7SDImlgWNCt6q3Lwegzw+nChE2EF6j1sUhF7K3j511I04mvH9diE7g4cIMP5O2kZznkJz1bEb6Qon9kyBEOOdA9sbnjdnt/qUhNug4PLKnW5evaZxKmErMsFcFjvNLTX9QSgbrvHA/kNJbuP2bU4GfifJv6v35JwWMiZq/i9JP5akGJRktijo/SG3/NykNb0/cf/9bOgri2pNBw+txrWFo4pKYCb7V0BHvo3Nb+5YgS0erBQzDTKi92fPXV/4cCV8ksjxMsZGPnw4U29pBz/suUNR07a1KWxRQYOwV71zr2Ef+uXwfAn9d8Yad3sP+BUUkjd7rxkMlP1g66HWws/v93PxGRiYg/xI9fR2UObpgJNfxc1QR8g4yokFxiGAAgjyqKPsc1b0okHHMO/0Ko1H0Z2zAn4igH23cysgQG0ypL/tEByJZir3zUMPWk73xY1wc3qnCgi7H4Rmz3DEbshoPfTvbWO6TB9DvU7AwtgGO/pm0RyVT3JXSsyo5Gu1zJHye1c86usqjmvJtVs34bzYxeYGHncl8XgkvnwE24hCB0Q9R7mco5veuDv3EBo4tNJzl4Ceaq45lomALR5wHqCDpRPe5ywkzmmkpVS8gxS8DWKy23KndTaeeqpdhi7PPKYEaeHIfhT9nHEj6Wip+7AXAD6ZWR1yltVuV1o+fc47iu19vsYySRBmQXpmzZuSBGVkWL6Ow6febnnCCzX3IMO6sIAUywY1sLYkcy6OzQIMHMK2YIbFciQx6Yvanc/W7SX+fnBqk+AbFTeKvjy4bg0Eq37QdGYRejsNCZe+RjXlnE1z2qbrm87B7JCp7/PHzIL1+io+BrQY5kDoWD6f7g19fewxqu8Q5L7kNFDWcJr4fjT9tZvpWiWLHEsrKlQMg0YqdFUFnSiH4+YBrDFv1BARuSknWBkJJ71vXEZcUhhmvn1eqcaFU8eZaDZmbt6wlghHbjJHVYnhHOmHDPhO8BF2Y1WaUkFsPMkxEg0V1tqFhJ3P2gK+/PXi7AfKYKgPzMmnVxm5vK5WoQ/XOJbIp5iYZSzd7+Q5jqcT+HdkL6QgrbzWjraxpndDg9zUPg01Yb7Eu7sC3CeJUBMxxGZHkNcJ5grFVvAJq+XWUJt 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: R4DDVGzffy2OyPaaZrV8XRW2/W5tMUwbqeH8yrIoUu4U8i3b6ABAgV5774a6suB+vl8nQWiV/j0+eQnsUwM2yyQF8Z79qhIz4QAGPs+72erC3dzK5Ucs8FZcs2sZ20PVBnr2wT+7LA4BMhtTGgOAVLq1lZTU3Co6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wnYmJCkTQ75Vg9lTJMPJKaGxj1HsLaifVB5P9bh5zZvbY67JCdUK4yHAN4MXQFFivqMLfW8jlNnHcA6oK9+LEp6e+buBszXGiFvL0cLlVS54lP8gsZmkvZ0S/h8X/FGpUMo9ue4qgulH9WQBuvQY7HEmo+Cg8X1YOIKutDThg5tSAysjqTmM+RZMawYcgwvIH7Wedm9Lv8soq88PvNkardt0HWEVfVcyz3mrpMv35sSfPn/YkQmF5Iw+dMMM1yjfhbTEEU813rh3gktPSPOzdU7/RENjFv99OiOt25f3uUGLjPmnHDhyQiOdbQfkN1pYtQ2d7n5bLiW0eBnzMpbTm2bPN9ktgjBOLh69nBrE X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0ac6cfea-f5fc-4adc-6a5a-08dcfcf7ebd9 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8659.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2024 17:41:32.6334 (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: VffEiAghkG2nFxqpAdL4DKhEJioefqDnLF77zGzItlqhvtM6awX4tDVwSdm08nuC X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6578 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241104_094307_494546_05BC42DC X-CRM114-Status: GOOD ( 11.33 ) 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 Describe the most conservative version of the driver implementations. All drivers should support this. Many drivers support extending the range if a large page is hit, but let's not make that officially approved API. The main point is to document explicitly that split is not supported. Signed-off-by: Jason Gunthorpe Reviewed-by: Liviu Dudau --- drivers/iommu/iommu.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 83c8e617a2c588..d3cf7cc69c797c 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2586,6 +2586,20 @@ static size_t __iommu_unmap(struct iommu_domain *domain, return unmapped; } +/** + * iommu_unmap() - Remove mappings from a range of IOVA + * @domain: Domain to manipulate + * @iova: IO virtual address to start + * @len: Length of the range starting from @iova + * + * iommu_unmap() will remove a translation created by iommu_map(). It cannot + * subdivide a mapping created by iommu_map(), so it should be called with IOVA + * ranges that match what was passed to iommu_map(). The range can aggregate + * contiguous iommu_map() calls so long as no individual range is split. + * + * Returns: Number of bytes of IOVA unmapped. iova + res will be the point + * unmapping stopped. + */ size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size) {