From mboxrd@z Thu Jan 1 00:00:00 1970 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 57343CFD641 for ; Wed, 7 Jan 2026 14:19:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1681610E0E8; Wed, 7 Jan 2026 14:19:38 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.b="i7cmNFz6"; dkim-atps=neutral Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011018.outbound.protection.outlook.com [40.93.194.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id E4E5010E0AC; Wed, 31 Dec 2025 04:32:10 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ld3S0mbZAx+P/KhegAtFAS5Wd6cOKE7R0TOasNWF+QkWmgt0enL8Ffd9Yab4SkVbT//+eajMH+0PUobr6PA7vR+KcDkqVNl/xTmD61I5Bfg0jR16ieTqhtCpXZc6bu8psaPvF47iOvK2KPGTBZR/lKzTuk1jznCq+9CGvwzNNpDet9D6akCEFJRTotSX36OrCjEGGcg7F8Av6PIu4WKmsrkVx08IrfnfBxptm8Rgqqs6ajlYr16qq/ou/yEHKTdB42V1okk2TcoUE6d+wfr+1xi/wjhLfi/E6CiZv0ZZNfUDxN+A4P89KyVwj+nPngaSs8dTpoSJLMe3EZOlzq1YSQ== 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=1lH5SS3FPf98eOj3RCW19JIBohzq9Muvg/PqFYkKtXs=; b=hhTk+l8ClmXDeX3O7UBlFdHa5ykG3urnwWGL0oRKnuKYA0VuU1wSJKy07xZmZ/KtCz20lQak/dj4aGf08enCwwN3IcCR9qcTYL5xJbK8hrXD3G9U2FvUUViI/IK/AjAPQoVi7DNb4Pxa8189aFEApqf0tk0IkyIsArxgiNNvmiuurxNfsZ5XbpbR4lMDvq/5Cjnj/zmiaow8he0ZBohHC5DNDRDVnltsjgFs/Lhn8/R5f2rM8reNn0jgTF1oMFYmXEowCRSu5C0R+QrMGmUFbx82sEjxUQoAfxuct4x2n56on++iEPuJA1ZVEBN02/kM/z7jKnYBzxV160ZQ5TF02w== 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=1lH5SS3FPf98eOj3RCW19JIBohzq9Muvg/PqFYkKtXs=; b=i7cmNFz67D5+8LUUwFZJqlkceu51H7njFptSKujumkPFx2L9jbAL74xBMp2Gj1eXxNhDymWGUPyl31FRvqYmyCPB3UkT3nthuHoR1qEBrGLpvPpRNkGyqDuMaHhanzAK8gy0UlLF3t/Q3BPMRbDYKKFhwnEtVPYkDpz9Fs3D43ye7NYpkCjknulOtlAzR+cad+AyNeib+Tb9EIhTRpCOlGOzEqiU+O8dKQ5f4nye96lZbnXYHx94VKoJRN+BDApbMkfLAsAIlPjeOMbZLOTQ1nrb8AHqXWmmAXSgvdL1nkKr6VLB7WT2Lxtgnwdhm96hO8e490bUF7sQ2F9TbTq0Uw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM4PR12MB9072.namprd12.prod.outlook.com (2603:10b6:8:be::6) by DS7PR12MB6045.namprd12.prod.outlook.com (2603:10b6:8:86::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9478.4; Wed, 31 Dec 2025 04:32:07 +0000 Received: from DM4PR12MB9072.namprd12.prod.outlook.com ([fe80::9e49:782:8e98:1ff1]) by DM4PR12MB9072.namprd12.prod.outlook.com ([fe80::9e49:782:8e98:1ff1%5]) with mapi id 15.20.9478.004; Wed, 31 Dec 2025 04:32:07 +0000 From: Jordan Niethe To: linux-mm@kvack.org Cc: balbirs@nvidia.com, matthew.brost@intel.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, david@redhat.com, ziy@nvidia.com, apopple@nvidia.com, lorenzo.stoakes@oracle.com, lyude@redhat.com, dakr@kernel.org, airlied@gmail.com, simona@ffwll.ch, rcampbell@nvidia.com, mpenttil@redhat.com, jgg@nvidia.com, willy@infradead.org, linuxppc-dev@lists.ozlabs.org, intel-xe@lists.freedesktop.org, jgg@ziepe.ca, Felix.Kuehling@amd.com Subject: [PATCH v1 0/8] Remove device private pages from physical address space Date: Wed, 31 Dec 2025 15:31:46 +1100 Message-Id: <20251231043154.42931-1-jniethe@nvidia.com> X-Mailer: git-send-email 2.34.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SJ2PR07CA0011.namprd07.prod.outlook.com (2603:10b6:a03:505::20) To DM4PR12MB9072.namprd12.prod.outlook.com (2603:10b6:8:be::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR12MB9072:EE_|DS7PR12MB6045:EE_ X-MS-Office365-Filtering-Correlation-Id: 195d558d-b1af-4b2b-ca7e-08de48258e26 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?v7z+Epud0MLEh8Glr95i21wOlMvzPKqrReTVwdzWo9Z/HVJpU/boIibyNdSN?= =?us-ascii?Q?hzO40HXYwTC3K+vMNuxzYr4PUz81EfxnM9RgJmy2MzD2OyRXWNvIHkL6b1MR?= =?us-ascii?Q?yjd0koA+AvrctSh9ud8AmVJrlguuun/YDxA2ZkTcWWy7fzMimm1HtVUTpIJ6?= =?us-ascii?Q?fIOdA09Ax8DlVQxuv+kGfRDa1zrWyOZaFGOAm640c3z0q9oPDtvKIOxs6nZr?= =?us-ascii?Q?W2K80MOMktp52aoR00tLYFG/dGCcw/GxzZtagM3sUZDR47GUMary2tfm728v?= =?us-ascii?Q?/1w53CISEO6V0qY0WCxq6/CZTwEyZ+jH3q+2s8e5ig6tNWITQGqsYi7vWI3U?= =?us-ascii?Q?hS586RaeuYo5VzYDikJG3aQ7cplj4tmlUA7M+G+tQwIpAddkCtUtnNd2Hqkm?= =?us-ascii?Q?dx/B6WH/anCCEj9V01cD4Etulg6CpCps0QWW1j21PwBZDq8sn89KtF+WD9Vh?= =?us-ascii?Q?+BFg1aBteTX4z7Agw3FCAQEDieNEoK6pr31dsbD20TLVABcTHEFUFcmRS12b?= =?us-ascii?Q?YFy5lxCOqWS/KJUlUQku/QZOXqjqJESlAhnG23JQk1RtmI8vZgbvMhlsnaQU?= =?us-ascii?Q?rW0kQ3JBNfs6V/IdY4dwyMKZ9M8wrnogpZ0AxM52ZowPzuJtAY2FbMfrCKlp?= =?us-ascii?Q?ks9/fA9Bu7SWP+6f80RrV3lrQkMXt2sNh+z4CJv+Q9QN+VaIt3Zgc2EEwvS5?= =?us-ascii?Q?D1hbTeLDE5gqzY1nYKqi2cMEBA9uOoL/eyFCXUlLI3jC+8bvI1X8SkNzKj00?= =?us-ascii?Q?VfkS3OD643d4xsOHnIC6mhaVH+fr66Rvt3S3r/qPwW5Tkm2hR48cxaSYcwdH?= =?us-ascii?Q?zbAN3MrDUOcuLO/1qF07ilbm5oZuzMCjpzjUgeAs0GD7+PK6FFkwbTXTtMqG?= =?us-ascii?Q?zJcaiRhndUd0CJk9mJn1bJhqU+M9qBgoqXWLm8YGbiGCtX3rZP/lZH5TBE8S?= =?us-ascii?Q?66fjY3U/SsaPKuW9I8XhPhZSnKWXGY36O/tOVvPdJ4IPXRTZTTaXr2EiwkSk?= =?us-ascii?Q?CtwPrq8Qit/0vTVyJ4zSD2lcNfQa4UfEfqu6sDMsshZYpkHorDK19tSczOCb?= =?us-ascii?Q?EjIfhfm6/1githw8Te2cpkcn8nzoG/zl0xSSnaiaFy1H9ZfAf0ZHnFT5QJlD?= =?us-ascii?Q?qO+MXrXnz71z3g/9Ds+jQbRUOshYHD+afzy4+h3g+mJkfSYthVaTKN5Z1Acy?= =?us-ascii?Q?pD959lJOgOjVydpxcBjLuJ5ldj25mOWgcuaQ1GYohj2Z+TmRrW7kyQtfR79d?= =?us-ascii?Q?GSnKSY/a2GJW8FVscqjhRKCwQIgD32G3jmgFwhAkT3PuioYb63Frpq+lOivw?= =?us-ascii?Q?jIlR5TN8Cm0T79B6PchZ4oJO/ZLGHGHb5C9l2344zh9V+eyPOBYNyHwtcB8j?= =?us-ascii?Q?H8c52jBDC6A0+ULytdC9LUcyHnzDjx3RW/e00VHoOvjntizTT8e+tAqhEmY8?= =?us-ascii?Q?KQN0zMpDsQBRDaSodMt9EdCJYtvu6C5M5JGPAmBQMsMnIUj4xGCplQ=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR12MB9072.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(7416014)(366016)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?qgB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=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 195d558d-b1af-4b2b-ca7e-08de48258e26 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB9072.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Dec 2025 04:32:07.3442 (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: 9adz8+UN241fopJFBADuBy0nKi0yy9ISndUHRFI7e2fx6rTnOxJsus7cYl+JbMtaS5N7OCOOdvkLhdBib7TujQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6045 X-Mailman-Approved-At: Wed, 07 Jan 2026 14:19:15 +0000 X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" Today, when creating these device private struct pages, the first step is to use request_free_mem_region() to get a range of physical address space large enough to represent the devices memory. This allocated physical address range is then remapped as device private memory using memremap_pages. Needing allocation of physical address space has some problems: 1) There may be insufficient physical address space to represent the device memory. KASLR reducing the physical address space and VM configurations with limited physical address space increase the likelihood of hitting this especially as device memory increases. This has been observed to prevent device private from being initialized. 2) Attempting to add the device private pages to the linear map at addresses beyond the actual physical memory causes issues on architectures like aarch64 - meaning the feature does not work there [0]. This series changes device private memory so that it does not require allocation of physical address space and these problems are avoided. Instead of using the physical address space, we introduce a "device private address space" and allocate from there. A consequence of placing the device private pages outside of the physical address space is that they no longer have a PFN. However, it is still necessary to be able to look up a corresponding device private page from a device private PTE entry, which means that we still require some way to index into this device private address space. Instead of a PFN, device private pages use an offset into this device private address space to look up device private struct pages. The problem that then needs to be addressed is how to avoid confusing these device private offsets with PFNs. It is the inherent limited usage of the device private pages themselves which make this possible. A device private page is only used for userspace mappings, we do not need to be concerned with them being used within the mm more broadly. This means that the only way that the core kernel looks up these pages is via the page table, where their PTE already indicates if they refer to a device private page via their swap type, e.g. SWP_DEVICE_WRITE. We can use this information to determine if the PTE contains a PFN which should be looked up in the page map, or a device private offset which should be looked up elsewhere. This applies when we are creating PTE entries for device private pages - because they have their own type there are already must be handled separately, so it is a small step to convert them to a device private PFN now too. The first part of the series updates callers where device private offsets might now be encountered to track this extra state. The last patch contains the bulk of the work where we change how we convert between device private pages to device private offsets and then use a new interface for allocating device private pages without the need for reserving physical address space. By removing the device private pages from the physical address space, this series also opens up the possibility to moving away from tracking device private memory using struct pages in the future. This is desirable as on systems with large amounts of memory these device private struct pages use a signifiant amount of memory and take a significant amount of time to initialize. Changes in v1: - mm/migrate_device: Add migrate PFN flag to track device private pages - Update for HMM huge page support - Update existing drivers to use MIGRATE_PFN_DEVICE - mm/page_vma_mapped: Add flags to page_vma_mapped_walk::pfn to track device private pages - Update for HMM huge page support - mm: Add helpers to create migration entries from struct pages - New to series - mm: Add a new swap type for migration entries of device private pages - Update for softleaf infrastructure - Handle make_readable_migration_entry_from_page() and friends - mm: Add helpers to create device private entries from struct pages - New to series - mm/hmm: Add flag to track device private pages - Update HMM_PFN_ORDER_SHIFT - Handle hmm_vma_handle_absent_pmd() - mm: Remove device private pages from the physical address space - Include NUMA node paramater for memremap_device_private_pagemap() - Add devm_memremap_device_private_pagemap() and friends - Update existing users of memremap_pages(): - ppc ultravisor - drm/amd/amdkfd - gpu/drm/xe - gpu/drm/nouveau - Update for HMM huge page support Testing: - selftests/mm/hmm-tests on an amd64 VM * NOTE: I will need help in testing the driver changes * Revisions: - RFC: https://lore.kernel.org/all/20251128044146.80050-1-jniethe@nvidia.com/ [0] https://lore.kernel.org/lkml/CAMj1kXFZ=4hLL1w6iCV5O5uVoVLHAJbc0rr40j24ObenAjXe9w@mail.gmail.com/ Jordan Niethe (8): mm/migrate_device: Add migrate PFN flag to track device private pages mm/page_vma_mapped: Add flags to page_vma_mapped_walk::pfn to track device private pages mm: Add helpers to create migration entries from struct pages mm: Add a new swap type for migration entries of device private pages mm: Add helpers to create device private entries from struct pages mm/util: Add flag to track device private pages in page snapshots mm/hmm: Add flag to track device private pages mm: Remove device private pages from the physical address space Documentation/mm/hmm.rst | 11 +- arch/powerpc/kvm/book3s_hv_uvmem.c | 43 ++--- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 32 ++-- drivers/gpu/drm/drm_pagemap.c | 4 +- drivers/gpu/drm/nouveau/nouveau_dmem.c | 37 ++--- drivers/gpu/drm/xe/xe_svm.c | 28 +--- fs/proc/page.c | 6 +- include/linux/hmm.h | 7 +- include/linux/leafops.h | 86 ++++++++-- include/linux/memremap.h | 64 +++++++- include/linux/migrate.h | 5 + include/linux/mm.h | 9 +- include/linux/rmap.h | 33 +++- include/linux/swap.h | 8 +- include/linux/swapops.h | 124 +++++++++++++++ lib/test_hmm.c | 73 +++++---- mm/debug.c | 9 +- mm/hmm.c | 5 +- mm/huge_memory.c | 53 ++++--- mm/memory.c | 14 +- mm/memremap.c | 193 ++++++++++++++++++----- mm/migrate.c | 6 +- mm/migrate_device.c | 45 +++--- mm/mm_init.c | 8 +- mm/mprotect.c | 21 ++- mm/page_vma_mapped.c | 32 +++- mm/rmap.c | 59 ++++--- mm/util.c | 8 +- mm/vmscan.c | 2 +- 29 files changed, 737 insertions(+), 288 deletions(-) base-commit: f8f9c1f4d0c7a64600e2ca312dec824a0bc2f1da -- 2.34.1