From patchwork Tue Nov 5 18:14:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13863348 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 7A24ED3177E for ; Tue, 5 Nov 2024 18:24:17 +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=jIANugGwnks22NqB2MR2YkkiCEPRDteg9Ba1oy9SDAU=; b=FhLslxBAZ9UymQiZkGntbN39/3 OPj5nRWUt+JcZhDJyXTFy8JPj/zDOrpkebgTVdEj4pDDzMve5ajonYB5VYx/onn2mCzTvLpaLI0H6 ffJX5+qtXFnehmgQtqsjxCbcpZjnRFsPuoUb7YSFYKu9RiZSPJ+ySDPyFgowoRbCnMIMpdPRKfvVz mckg/OBXmRzRsx/R06fFbZ/wfB0HKKaUI7Mg2kGGmlme5VHu77u7d75Y1Ey4HMSCjrMy7aEBwSZNf wVhWl7aOuO85FcQz2N58feyuqjQ7qhXw6WrxLFbu/YlbKNFgfZnp8UvcgcZoOePN+Nn6M0eSBXoyN 1qbUMhhg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8ODh-00000000MSp-1D7T; Tue, 05 Nov 2024 18:24:01 +0000 Received: from mail-dm6nam04on20605.outbound.protection.outlook.com ([2a01:111:f403:2409::605] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8O58-00000000LGm-3ofH for linux-arm-kernel@lists.infradead.org; Tue, 05 Nov 2024 18:15:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GDMxhwEzLh/5pUVrDVRbCDjJiMnnxjUrKaD3iLnFou+V2akgJgVU1XQJONVXw4pQ8Out3GzvkgZ6GMGlIVwIqGxzyoRn/ewWeEUOZfO12SFhiSwxT2x/U6gCKHimhHiDIXcx8zXxCIdpJ6k+vMjwIoXd0De8eGszQpRu4pnuRq8wrE7iX3/3WpWGDgcncu6QrHFH2wV8FsE/Wl38XaPDuT91e1QEwbYWIaFD0sgM/4ryVXpnFu7aXY5l4KD5WAJmBvIiAvLsXnCgg79XP8Qqsj0DSGK5LQcnB52P+T4DO1GNSaHtUW1H+okHkNTFJKVD7a0S9aztc+FKE5Ym8GAksA== 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=jIANugGwnks22NqB2MR2YkkiCEPRDteg9Ba1oy9SDAU=; b=sfGUYHSeyF0jODt/AHSLh49qsNqQ/413b4phEF86FDM/QPX5JFsxZcBTIAocsDQF5CAyNqtOYCvG6Ukkr2T0HcyTL3xCXBG6IPfHYeT8taHHLBZaAulj5DcO6Y4s2NiyxzZDwXtcldKrWjl4GiOVTtBbuWd3JXdEIVyMdewOUasdEAd0lGwsVAnP7aRSMTxAlD48Aw3u78skfz90nmE5ZRJ64TZ9vReSrXtIJZDefPbiMwRd4poEIFkYbyuwnJoepSC/NBBWZRyAYgGFl4dR0Y9TWrS053qEML1VkGSoy+MIVaPB8GegGLH+nZFkpxLcRtNx7ONnD8IEZ5v2FZklPQ== 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=jIANugGwnks22NqB2MR2YkkiCEPRDteg9Ba1oy9SDAU=; b=jfKbGY+Yq8hTV1JDouK1v70d5+mg7OuAqu6nYDgOEtsuNMnFb0gxplkfwn3GRwCuyx+0kBruSKAgC+XKfnGURUECLsHD/GCSNxYHhnLq4NVbZbS4JJ0ZasvJFE9OEcVxmQqad5+HGXAh6EluAVs0HdNfneB2Yo83GEKoMdo8b7LzQZCUL7rx0Nxaw2r2slghltpFlNQvx3lHV3ATp8Tiqa2Bv46Z5SUtysZ3KEGMTHOQDij2Zrteed+8+C3rEUP/tclEbJcD2K/z8dGgunWbegeHBOq+14X4qVyxtfH5+4D9gX/lITL2O8LKiduRMpiLP+nplKA90n7YYpwthN9FgQ== 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 IA0PR12MB7508.namprd12.prod.outlook.com (2603:10b6:208:440::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.18; Tue, 5 Nov 2024 18:14:28 +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.8137.018; Tue, 5 Nov 2024 18:14:28 +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 v3 1/3] iommu/io-pgtable-arm: Remove split on unmap behavior Date: Tue, 5 Nov 2024 14:14:24 -0400 Message-ID: <1-v3-b3a5b5937f56+7bb-arm_no_split_jgg@nvidia.com> In-Reply-To: <0-v3-b3a5b5937f56+7bb-arm_no_split_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR05CA0052.namprd05.prod.outlook.com (2603:10b6:208:236::21) To CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB8659:EE_|IA0PR12MB7508:EE_ X-MS-Office365-Filtering-Correlation-Id: 8264e3de-73e4-49d6-e7a1-08dcfdc5af89 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: 1P4glLet5wBtg0Tb4Na6agMq+CMnMJOGeSTONbnJ8UWptdjNoWlivnarY92wCwbuYguJch/g2jErpWQCIheqXLixnt0eLl8qUZFcQNWq5txoa4H4AGuxLcbyqd84gn02+ELPn57BLEHwFC5Ju0IclI6lmTHxexjl2Ut2ZJ29ZnC4N1mbGzubcoUmqvcxQXpheDNlIhk2destXMVAkgvJRJ+dL4bIpQuH2n8k4tSKixw6Uj4Q1NcdZUAN6CLUIpnPIdS5bTYjJr506kpS206O54DfqGvysLyfeBLSp6wAXAu7e2g4NgLOsnlAwdzeCqQnl44NG3T/C8ejGmL1gI6zAKx3Y430gU5+n63K+BriHOMot/q/WtsMa3hbxknp6sD/FQPKuHY1ijJ6iJruVM5nYkQaZ1DXV0yQB3B9ElO55NGdf9vENT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QnwtDDRjwLfe7FzoNMt2mzGH6U0vh0HH0Ioiaevk3Z3mNAX5kyv2S7GFefjnweD5N+CZCeoX8ahP5pHvfb+lFVGg1X25yjOCq/E7iwDb/VDhTj3zTij5MMPdFUN5Ti3TBkth4Ud62ydnHqnMsBDXz2H4QFlBJM/bwlQFX7G7zqXtBLWxKf2KxaSPuSi6gLlMln+ApqVyeQlZTQyQJnub4HcFXrEujNiURQX9Z9Nv8uEqOG1mwZ6BsnbJaf9OsG2m1Ur4R4y81dj29ubVsU7dzILeX37l8RKvihjPNiTQuyvElXl5ALRRiXmPgu0RfDnZsoLQiwBlLSqkH5gArnCHZ+Z/ed6wTwYzUAYjz223p9AqeSWY/JkUgy6DvgtGgIA0ePHAX4Fqn417u6wbh5SmqgbguIzEpdRlBIVIfShRxChbarxYE7oQA9kAAOc5A395VZMttRrunE4TOsinK6866F22BCjfHb/PJXJTaCSJjFkHitiyghw8I0WRWTYWZd34k8Q9wNCNv42jrLxYNveoNfXSw+TLPJwm9Jq8bSMIoBOajCeAhD0uXk1GXC4fcHXcRbVAOJQaG X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8264e3de-73e4-49d6-e7a1-08dcfdc5af89 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8659.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Nov 2024 18:14:27.6525 (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: 7T/RSCxsZyB8hZ8Ha3tA0z/1jzrD3ESLFouvLwOw/vVXuFPw43bxwEd3ZnHuGUTZ X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7508 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241105_101510_967283_E8352B47 X-CRM114-Status: GOOD ( 20.98 ) 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 Reviewed-by: Liviu Dudau Signed-off-by: Jason Gunthorpe --- drivers/iommu/io-pgtable-arm.c | 81 +--------------------------------- 1 file changed, 2 insertions(+), 79 deletions(-) diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index 0e67f1721a3d98..4e7689f5f12b4c 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' */ @@ -1347,19 +1283,6 @@ static int __init arm_lpae_run_tests(struct io_pgtable_cfg *cfg) iova += SZ_1G; } - /* Partial unmap */ - size = 1UL << __ffs(cfg->pgsize_bitmap); - if (ops->unmap_pages(ops, SZ_1G + size, size, 1, NULL) != size) - return __FAIL(ops, i); - - /* Remap of partial unmap */ - if (ops->map_pages(ops, SZ_1G + size, size, size, 1, - IOMMU_READ, GFP_KERNEL, &mapped)) - return __FAIL(ops, i); - - if (ops->iova_to_phys(ops, SZ_1G + size + 42) != (size + 42)) - return __FAIL(ops, i); - /* Full unmap */ iova = 0; for_each_set_bit(j, &cfg->pgsize_bitmap, BITS_PER_LONG) { From patchwork Tue Nov 5 18:14:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13863349 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 61509D3177E for ; Tue, 5 Nov 2024 18:25:56 +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=nSsxSmPxlksAOVGjYdQmoHC2LN7QlKhIRFvU/0aUrDE=; b=vQt3yB4mBnEdKCOQZ5oNB7hJ+F qUxmjp8V7Hm5OSi6anwFiw4kYAS0PiVTvDtWG6dDKMc6KmFl6V3HOTMDX8LP68x3oO9St09hSkUs6 3UAWaTKOQj8XaxcEnyZuYJy6wH4Yh56ZdVJoMgmq9A2QgIPYSryGn8aX96uNazvz2s924tQlATvKt ZWxK0TsflZ3JczSTPorv+CGH/7I/S/XSpp9H8KNACYq1rR4Lsl2XBYPsfqvsrdNSOijd8uo2MMj93 FzB0vFMKud0PHf8kPHo2rEiz9W80Rz02hTzaocJRVxEOyIhqVP/Sagwb2a894mZIH1EJJaa2cGLmc 8kwpzS2g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8OFN-00000000Mix-0rAo; Tue, 05 Nov 2024 18:25:45 +0000 Received: from mail-dm6nam04on20605.outbound.protection.outlook.com ([2a01:111:f403:2409::605] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8O5L-00000000LGm-17gA for linux-arm-kernel@lists.infradead.org; Tue, 05 Nov 2024 18:15:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Q+vuUKAisc3Qvt65gYbca/pp1VkLcdrJ2qrjrrF6LAricMe5eZz3QOqin3sAGuAoTW0WT2mGac2AuI8SzzErtWONbkHqmO4j2EIAHB4jJAT1yrw5f4GS8lFUbH3wY4GU/ewOi5iuGP21EiMRmUhm9EASffjQhRVaqtWGUUwyiKJOSPPf9/F01XltILfR2wJWbA8RgcU027d+tACLaTBJ5x4+mM448V1FCmIWIcRioyTbsFO8Ga7FsY7E/Ac2Mffwuuqk1KXQMNUnm63wI9ssdRVChQlOri1ByE9vopVA0shV95nwmFZhnZ9EoGhAhMkAsQQ/qSDGCAmygQBDI3fYGw== 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=nSsxSmPxlksAOVGjYdQmoHC2LN7QlKhIRFvU/0aUrDE=; b=CMODATzuOphn/4KhGkurmO4OVXKAPCQXKMu6JXFeIdTQW4Y3oZRZ5m1nStSInb2TjRNKjWEU2yAmTO+BODflK7tHsvaT+rd4/BpW4APUOvYprwdyzVst+ITjkbG4TCn5X7EnwSSnMtBXtB3aZDiAD3ZgLQy/oVP+cpVkanb6sBUXNYgnUsNpGcKiXvFhmGz3OAG/HkMVYcF0RtJ0g2HGAOtgx/brtYHA8IJcbFFgwiYx194SufYgGGzRA/lrFbN+T5TM2rB8SBFYWON5TLG0AakKgdn04yiH1iso5imG3wu9ybRtENvuE/5HXFrCVNpn+5EvKqPDTFBwIe7pemitoQ== 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=nSsxSmPxlksAOVGjYdQmoHC2LN7QlKhIRFvU/0aUrDE=; b=ix3xOg95VV7fD34FVsFNxiNYrCYqM11njBLw/YSxT5wXr3ghNDukiuRw767X4Lo71qP2wRsuAdjmb5qa3nyZDdUznvuWqFWVciMmjv1SyHI/YlNiwb4KcVpQnHsckXB3EmlGbXErBcM87fLFfj+AX+74K2+p6n8sjRX4CafKLZHF+64KlR+H9nfpqMyeggurI8+UZfj1jfjGxI/wZhkm1/Se9NSJjXqFxS4+kG6J4b+ZYPhixoTR7Jv7V4p7Kbh9wO7Gu7rsnb5Qoz+J3wXunPIb6F0Sh1jYwszXvLVfwk0fyngHmbu3Up7lYs+6t3S3Cv0cFEY5CkGxM11xXnKZIQ== 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 IA0PR12MB7508.namprd12.prod.outlook.com (2603:10b6:208:440::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.18; Tue, 5 Nov 2024 18:14:28 +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.8137.018; Tue, 5 Nov 2024 18:14:28 +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 v3 2/3] iommu/io-pgtable-arm-v7s: Remove split on unmap behavior Date: Tue, 5 Nov 2024 14:14:25 -0400 Message-ID: <2-v3-b3a5b5937f56+7bb-arm_no_split_jgg@nvidia.com> In-Reply-To: <0-v3-b3a5b5937f56+7bb-arm_no_split_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR05CA0054.namprd05.prod.outlook.com (2603:10b6:208:236::23) To CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB8659:EE_|IA0PR12MB7508:EE_ X-MS-Office365-Filtering-Correlation-Id: 8a7b208d-38aa-4d57-2897-08dcfdc5af95 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: okNpcY9dailgwi/fcAMGhW25C78owI2s5Lcl0614gGiJEeOkeuUr2q2EOTMQyC180xVHHepgGjGDFSss7uACRKIPxBVSQPGm8kxkY2iLpAzUuAaNyRlAxQkUwniXlc34xrawfAkc5T8kDTke57KiJ4B0UtiSmrNuEzsklOQmPKQBAoDWQRyFJ2ARmEGhqLcJw+x5eUNTmjvqw2AqFAcQhNwYFkv0B4iepTle94uqLxop9jCqzEhfbWhEx4oK3lEjmFEJT5c2JHlNV5OBeabnuRDaWbPkh+10nEDzD1GB3ljRpVlTBBmqrzAkaZ6OUwkU+qdNHbAIZN8RaPSdP/4b8zZc61zPTXOUh8g1gBMkk/QmGBubuSerTFP85ppc5CaPo0zkoArWDruUlvZS3azAoKo35nKcMGt3oRenl9qQJfpqa8MZ0mRoNucpALxqKXnRgDwqKFRzENr6CTGLV+JnGuH9qJep2gQ7YlZgfrrlVQ3KTRhU121AdvBmo4QiBoIlaT4fWdlhLFDkJq1k56HeM2BmhU2iaY8n/ys3ugB/uNyIxBFD40MHTAmfQAWe89NyuC9D3FYjoFs37FlZKYP89wx6b46S81bQpWsJa0i9owcqf6EEXOm+Sseuj/CKqO1jlOcfwDpvajSutHIHjzP3OJGKO23ysdp6hsYBec0om2kY3mZyIKWTiwurSSO/OY3evNQZ3UJqfO1sufCyx08lKaIfbwL4H3iprZ/U+mJcOD2kPdjaVcy0Y5oL+EYkwo4AfyV0H10knFCnaOn0eqSNDbxp3d3rbxqPEEQ2rfHWI9V5DXMPrKPJuq7nWyY6npQj7yfCuGk8gcqBafLH1wK3IdfxLfz68fqNB/LtjrxxSWjvD8/NavXBLqtNKtTX7uCdli1fsiwFxrMU5IFSE2/IP5dUH9B53EIdSOnhD1SHBc4bY9FdAUNCYiq5Qn3KP+M6KbDE7OFg65yX5XDqBEuGGqn+T4J8airHttkbAAJOFehfa8mrwAfKRF8gNKhx6Y2g3jeuZ9RV/WGcCfQCA5tvts+y80yj31rVd6YcUK1YcAwtI5BWeN+fitXr2k4JApaywca/dJbd9462l8JJdF/lbAtT7rkLsJOO7bZsjQLBYodnVMHmWzVZCrSZsL5re1S/vYatbv3cFX3W7aXJgO8BiQPj5IZan52GCLb8WKEhgRSlJ2ly1dMDTlnB3ovty9YihMoQSUYvQahy2fo2uOXVWtA1hpChad7B9g7Omvk9+a8TeuqiPKjyHvRlCatUL03MNIRvS+py0eUtaBeIVWPioyUfj7FV+pthIM5myY9lAwpmZm7TSVjQSbMiNmV8pNgn 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)(1800799024)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sFwDArlOtGr2PbxTse1Y4t1GPmxFnmrOICsK7o5zHSctcklKfbaYrJdASiVr7WxpvPSBWfKHJOMy5zvC+S0WIc2QEZjFYuwT8katJxQ8KihmQGWaFeH9hH4lPdDM7Mizsym6Dmn6lIipw25AMeLm3vio7A7PsZYMdNXab1VubFxOkMY7EWoDbOATbhuxSEgYS9ApA+rIzFv4VkUFR+PhLEMcKRrYq68zZu4KO6NArusdf83K9BjCX652oy5Yl/dEsG6Xq1VYr1nIt2GOdmncBiFUdxy+mQ8Oup6m9uSm8S/SlSicWoOWoFubzlYvXXhVx/jjRdd5JIl4yjXrtdZnmArIilZ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rwoEhJfz7lH6K3RFto2vNOiHsUaGr/6qm6vn4x/5eVAIFmQ044Uei0gQnvs1mOhGM92/BEGwcWdUVvPHASQEwqqQG9jh2rX8wYZpQZW9FP8JqPEm0wOwadpKKYFqLimXbCRTzvL8rpMnYALPM9nDgsMPJVA6C2U X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8a7b208d-38aa-4d57-2897-08dcfdc5af95 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8659.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Nov 2024 18:14:27.7746 (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: YopAym4rrJD1iEjhynvnVj0GgYoJ18v1bPB/YPQHcnAqIWQMYI4mjEKAWpL3oaze X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7508 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241105_101523_465681_85888270 X-CRM114-Status: GOOD ( 20.60 ) 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 | 146 +---------------------------- 1 file changed, 5 insertions(+), 141 deletions(-) diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c index 06ffc683b28fee..9ae8cb8999ef51 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. @@ -936,7 +819,7 @@ static int __init arm_v7s_do_selftests(void) .quirks = IO_PGTABLE_QUIRK_ARM_NS, .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M, }; - unsigned int iova, size, iova_start; + unsigned int iova, size; unsigned int i, loopnr = 0; size_t mapped; @@ -988,25 +871,6 @@ static int __init arm_v7s_do_selftests(void) loopnr++; } - /* Partial unmap */ - i = 1; - size = 1UL << __ffs(cfg.pgsize_bitmap); - while (i < loopnr) { - iova_start = i * SZ_16M; - if (ops->unmap_pages(ops, iova_start + size, size, 1, NULL) != size) - return __FAIL(ops); - - /* Remap of partial unmap */ - if (ops->map_pages(ops, iova_start + size, size, size, 1, - IOMMU_READ, GFP_KERNEL, &mapped)) - return __FAIL(ops); - - if (ops->iova_to_phys(ops, iova_start + size + 42) - != (size + 42)) - return __FAIL(ops); - i++; - } - /* Full unmap */ iova = 0; for_each_set_bit(i, &cfg.pgsize_bitmap, BITS_PER_LONG) { From patchwork Tue Nov 5 18:14:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13863339 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 1A90DD3177E for ; Tue, 5 Nov 2024 18:22:28 +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=ba2ruC0I9kodvIkVGDgELdqKrtG3OCBw2QTqZjaMAcA=; b=nLTUHAeWxidM+Hcqv3dJvVxiwy aTpQTvZUg9VLgv9h/LF3Sw9wuBH+KpK6B/dt2Mx3kGs664Rs9QFh+VbfQWP6FAOrxGwl653bA06Vk mTvX+gBNmgdHdIkGsl1ie16sao6rNgrHqoS+O+QgoiDHXqViS5IJirT1kE8P3a81MuFrWzyBQ0Wcu 4OPhWNNyeB0qzRxhuvwYC+4OV658DzRNWjul7Hx/z3xjvbUsUY+1EaCiy/xWONnuNiSo3+23y1Xba Gyj6Zt7eIps9GHxMidktbXul55euDeNtA/ojIsbRYlJAbxurEFMaXXT6rtW1Q/VbpZGHaqfChZ5Nm M5o3hJfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8OC1-00000000MH1-37xR; Tue, 05 Nov 2024 18:22:17 +0000 Received: from mail-dm6nam04on20605.outbound.protection.outlook.com ([2a01:111:f403:2409::605] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8O4j-00000000LGm-1BrL for linux-arm-kernel@lists.infradead.org; Tue, 05 Nov 2024 18:15:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=szwICDRD1K8d5mblymqUsVJ1WWcw/22BwjssjAzQ7cfR6qCxO59P/6sTnFDUlLKozKmumumJuzGdMmwS1/wiYi1/+/GocR1UTdZI3EwZw51SPDus3PDKhtaQfXnGOmWEsQJM4nV1J6VSgrmitZithvAGt+CLOh8zXLhT8/GGxfhXgr/klKt1IxdgvkHAn8mzdwMoTdGQn1UJzH59ZHVEwvzi4pZXAo+vutvtaKHnImHyw+pQhPKd4NXPd9jdYn9Ebw/9Ut2SViBHt6T5+tSlUdUxZpqL7ozneDV0da4TlT4xQDcpXvi5d+O+sYG8YZIZ8SdViofNEE7hiAwdg2IWfw== 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=ba2ruC0I9kodvIkVGDgELdqKrtG3OCBw2QTqZjaMAcA=; b=lCASXe6RKLJtzVylSjm93HuYwvLsA7FJvGw0+tA3NsTvflL08H83tODUxEB4sTF2/HNteqNHYWAFvlLnpUNswXWe6fyh/TmQy7icRt/BELDPENOEiZyPCs+gC9QgRr2RVc6ytDeXJ2s/Or+V3ecoOgFoJUtWjU2emKkdppjC3nFNXfoNLogbpKXKz3z5e4PkuNKqBe31amAnAyuz0JfioBmeJG24b+aOwn+vh5/QxVpNjOYtZiacXaj3ZbaO01LapuLATOJhgISMn4JgJIYeUEgcRxMOhIV7UTt7rcxU+vJ4PiaKFvVKgRrtWD0eK5yPuZYg06QLbFNnwojKfTgu4Q== 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=ba2ruC0I9kodvIkVGDgELdqKrtG3OCBw2QTqZjaMAcA=; b=iWWtJIw5t7/wbZHMEGpJUt1anBxRlsDjMV5aFTsr1BglX56pu+LuusRC9E6gOgKqnYpoKj1f8AQk+al7FfOMFGT6LXbm8zA7Zh5zRyXkZKT6xQaANok5XnkXGkW7W4vzHEwhADbXbC1pQmQKKTInbpe/OhooA9yHaNE0OcPamyn/E4IcaYX+YV7H0DSzGrS9zSiXjL9G3V7FARDMkGkoMG9gzkDrT1BgARMq2yByEeC6N17yzwvcUpndiRNXW09x9/ANzVrzhPgZmnV2rtneDyVEMviap/QGczeNTag1YcryGdeKVAsqZQcC+BKV0V+vKgISMzy0D2/kL3NmC+nmdQ== 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 IA0PR12MB7508.namprd12.prod.outlook.com (2603:10b6:208:440::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.18; Tue, 5 Nov 2024 18:14:28 +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.8137.018; Tue, 5 Nov 2024 18:14:27 +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 v3 3/3] iommu: Add a kdoc to iommu_unmap() Date: Tue, 5 Nov 2024 14:14:26 -0400 Message-ID: <3-v3-b3a5b5937f56+7bb-arm_no_split_jgg@nvidia.com> In-Reply-To: <0-v3-b3a5b5937f56+7bb-arm_no_split_jgg@nvidia.com> References: X-ClientProxiedBy: BN9PR03CA0382.namprd03.prod.outlook.com (2603:10b6:408:f7::27) To CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB8659:EE_|IA0PR12MB7508:EE_ X-MS-Office365-Filtering-Correlation-Id: 7a28bfd6-0570-4e5c-7320-08dcfdc5af86 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: +rtGmT8+v47bhLSYwH24vCw24W5dHHronzdwdPueGflipYkAvN4JzNFdA1nUy7o8wtYwTjM3Ks/MU+fgmIOVWaIVh3ju62GeB4XlcTSNYHW9yXtYneD7VhgPNN1IE/gXSDKTIuHVtfotjuzFgsaw7iF3FY/TYoKFM82L1g3oKbXsPNHzy2nHMbOjlFNrxcE6KfQqsVpuU3mFZZIeQ7i1jWf2N79uE7jut70XNfoQsgpS3IiWMrEJO+orKYQJ5rnAgQplayYgvswrss7l3RJvaX26hkENTI9bK6SVTVImz9QIn+bIAzUsi+gWu9PWUMitAs9BS9PBag2NB7OXFzjfCGg/Qm1WdrolOgx7AdcrP4ecIHU/TFPlRy6T420uKzl06csfjQRGswf9y0KK/GONbYN0N1odZL7n6Z9lmlT02vx5GZmeSsaHQAHgfdRRrx3LEqKeEXap4y76SsH8YYg/4VULiknppM2lP8wLgaKW1T8RvJTWPYr9/HUHfoiGP1xLSieQVR4keRQCzeARwzSSQ4a6d1Jp5aXYjTHdj3+cj9/wtjqLzDOvhg6+F+Uj4z/pgSV1+d40sl/ejDX4EZu55RYlCKkO3RKeHoJIJvydIyNMdI3nlUdM4pkgKb27PW/0cEBPa3M9F60ALd5AAb+JQYqqePk4XfAIb7ISCOYXL4n5h2YvUCJUuS5kkDRGgUOEXZZBpyt+p3Cx+YbGXc6GtHcl9o9xSKjHVzQGnA3Z3G7eqs50SlLynRoB2/y6xOSn9fkBys93rPxDIvuxgxJ8iiIhua1xNY2SOzKjL3bHYUZOY+FEa7AsksaWABAJasm9kUX4tvI++mruWPcdvFQt/lkwWMqeEvVE1CwinsGXgb66SH+iblfHTUfecAZj1uF0nPhYXizh8QeAgFxR5/zu5Ghm/X0iVedge6Kg4VpJK4plylF7d1Yy1bQVbCHuXcD4zw6BFJEWl8kwT3oZUSI1TloUhsO0P5FUKBiuul2zz9UvTyFcJgIHY4QmwagM4p6ZSvXgL3Hr7nCjN1Eh93grKdsy6EyyzzI+61jByMT03iFh3kLooS2x9HWgzT9InHoKdeLffc95/7O2Hhlxvsu5dnS9yBHjBVzQLZRLl0PJn3YwHy+4NxBEbSSBScf2HbipYPU5X9LxlxKSaQtKRKHrRskAaZTNirHap2jceX+CrkuFWCbMeBPp6wIOJBu19YJkAsfsurhpYHUarmSEWOJgayq3+fZR0ytbYjv5kFWoZotd0IRDu13ZwjHW2aqbT/22RnwQgqsCa1Df5zmVzfA9vENO3bGTfCqcfedjRdDvsD+/A2n6tIVny4wih9znSiQR 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)(1800799024)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9S3Aav1NVnPjIlk6GgEXzAEe9gMxRVwbIftDEYY8y6QJpjnd+bdX8siNOnfsNgqyiSps2l60LX+JzlhVV5LA9m/kbF0XWfmdILcYjc8d9zvN6ZRljhzzzevepS1k/uXZpFvu9+tzjqq+Kbe9tqfH+L/OaF6hqNbLUcBgNlIz1e/6IQeJHtNIPv7WcEja/2koptX0fAVJZa4him1+FSb2XIDNqfHIGVi3X6HlUsSxgIkqHcvtsoJ/KmjqTpaOKRpdiuzQe9B7aecxc6fITCgLr0FkH+v7CZzHJFQbCB81YuB6OtXlUcif4DOQ1YkO09HHLsTmmB5Cr1UPGBN8stWQzwfXl6gXIXPC7BQqlHPcp5F5KfYtI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O7hmVq4B/9cAqXYE/AmzRoqcLDvH8J8Sk5IeEYSJolV96Uq+0HN4zDu67L4b4Cf8dfBQFMQBZJgWKqKzURaV5PV3MaitQKK//dRFVff45A4RDL+ZlTWjKbwqaHfVcSDepSGilaXU0wWADiLJk X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7a28bfd6-0570-4e5c-7320-08dcfdc5af86 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8659.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Nov 2024 18:14:27.6290 (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: CIIhoFEp5BgQAd8qQQPV0h8GYX0p047ZMQqOE8ZsdUEtPXMO296SfnclL+hAeKzq X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7508 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241105_101445_359009_4E0D4EB3 X-CRM114-Status: GOOD ( 11.48 ) 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. Reviewed-by: Liviu Dudau Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 83c8e617a2c588..19b177720d3aca 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 + * @size: 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) {