From nobody Mon Feb 9 04:03:57 2026 Received: from BYAPR05CU005.outbound.protection.outlook.com (mail-westusazon11010069.outbound.protection.outlook.com [52.101.85.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74EDA2F5A35 for ; Wed, 7 Jan 2026 09:18:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.85.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767777541; cv=fail; b=CAtgjKCRRfo3GADRa1O3tSwvz9J+Vi4M6m5LBoDoZRv0CtygWqRGTLEPXL+GxAazAwyLTZU9A4CE+/REwciUwwG3r3DCBoeATB8h5mgpyf3ZBQIMnsvXR1TFgSYjTr2Uyf6cUP3wzFtmYC7Ah9P8fEAX0G4hLVp9hXZwoEg1YFs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767777541; c=relaxed/simple; bh=AbkbuY6ugfj4s81cGnT3M0y4OE4yvTh3176FAtQHCYE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=rgL1AQL6UikzYrNAJIA8BZeq2rb4759E8nbG2fN1XaWZMxHxTUsHRsHsTetCGdXzGPC75cHRG6VCOTqzDe5aDzWX1Vf3HWetA8SYMlWCe70VBMrIwvZ8HQp8GsBvigb8PcUaTTIWQI8v5oKLaJWzLQHc4xoOHkYNTvJumEvAFAU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=c63egCc+; arc=fail smtp.client-ip=52.101.85.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="c63egCc+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QULxXJwmkntpLOv6fDP7+KyT01Ie9KZIWyrnv4AtaGmzljyeuRO3uQTyoWiSvJjv/64MeykcvFcgNGQvCLuoGsEgr+abd7V/hTgCdbRofSGclLMkrwTmo7g4h7AgYrxOjxhklZz06S9LpVUQQWwdeS0qYZ9Ght68s4eOrmq/wVi8vNdfROdZHWIvrL9yubyofFcDwl+IUggm4Rx99omVLzag8VbuNS3ZKs5bui9GkuekXi7BR86kJYsIhJQa4LCUnRd+bWKiqIGwxccTeXlxCq5pgD46AsIIxq9649G9/uqPkf5NgU1quXOUmxua7X3l5VWVjTfffhx75PmWLlI92w== 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=Zf6IV6tZXTgf1IS6YNiAkxg/IGQzn0YllYcg+NS+wHs=; b=qzndGrIBQsbqILl+4xpVRgOGbMrfLSQmS9EZQj8iigwAiyrQIOdBDyVlnVR406ODp3vSGptDSidAHtvqAAYRxZqrClx3on4Kap04fG3ZB8i8tPdSAKaC0k+bb+dgKDYTjrVfObre+RSKqBjJi1y6Ex+/38pLdbZE+HkE5ELtZ4bRceWTgFdOz5C/JfAFkbFm+v9k+ghCAhDIKKQu9XrU77UJtY6py8uHPZvl9wINlA2uUhD4JLk8wITr3yvzvrJoQ7Pjs5zBlVC3DKJs/DIDu8tMMvcnx8sHkVh0dc0n+fSEItu1rdgL2YMt2wy2viIBPZYif3mGITKgB+UFS9A6hg== 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=Zf6IV6tZXTgf1IS6YNiAkxg/IGQzn0YllYcg+NS+wHs=; b=c63egCc+rCvpGLlnqmT34iyjdBn9BewTq84VqrwmjTxonQytbcJyHPumQAmDnsaIW0Yc6VU7zQipLMlv2jTCU87gYMELdN6yMC7GLDvVOwwcsKW/Qci+RnkFUlZ0FSYV6L8dZiFaWYhXdx/NPu4E0tvQRANMA+kYYg3B8KxETaoMTmN87LuvIJUfF0X5qHj86sPKZ1ETcS6Ps1ACWO/Cz2YAICQO36v00SuXOYgOxbZWptbyt2X79cvGA5KNGM0plZzxQ0CrJWX/kiiv3pY8oGX01UDQ1K66bjfJaaPBABg4X9YPGa0LnLoQby1DgeltFN33sKgLGkt6kXUbkbJNSg== 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 MN2PR12MB4335.namprd12.prod.outlook.com (2603:10b6:208:1d4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9499.2; Wed, 7 Jan 2026 09:18:54 +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.9499.002; Wed, 7 Jan 2026 09:18:54 +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 v2 06/11] mm: Add helpers to create migration entries from struct pages Date: Wed, 7 Jan 2026 20:18:18 +1100 Message-Id: <20260107091823.68974-7-jniethe@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260107091823.68974-1-jniethe@nvidia.com> References: <20260107091823.68974-1-jniethe@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SJ0PR03CA0222.namprd03.prod.outlook.com (2603:10b6:a03:39f::17) To DM4PR12MB9072.namprd12.prod.outlook.com (2603:10b6:8:be::6) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR12MB9072:EE_|MN2PR12MB4335:EE_ X-MS-Office365-Filtering-Correlation-Id: ed9d0255-1ba9-4962-8240-08de4dcdc79c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Ss+e89OmxvIPdxHV529XDg76+6jI+nNnNn+jf8iTeHF6n92rb8AQg7SLT88/?= =?us-ascii?Q?EZQNzop/BewZUIcClUleIXBBnsIhXuQxJCGRsoCaiy6+50AHflq0jdUUojM8?= =?us-ascii?Q?tsILHH/hOportFgfztPmV4i0I/kB5BfqoBs/BA1Pe40SayMz2E2maCzBvmDl?= =?us-ascii?Q?cCShP1hiF65beUYex7DdEk/b0mDffgzwpV1yIhRtVtpAsFNqfsGG/VhUH3d/?= =?us-ascii?Q?2yUxsDHAXXYoHnXprhV6L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= =?us-ascii?Q?eN+PgJCKmO8CXJAZ1RPdMEQ9bc8pP6rMwIaBXRYlH6RtYZKPFdCnhZjozTxg?= =?us-ascii?Q?wKKJnPPZef9dAcXeBkFAYL3bzmwZ74Fw7zpankC0kJjSSGUiIii2GXbmT+Wk?= =?us-ascii?Q?epUxv0129LZC8WDIvSHupWBtndYIUJjvk9h33yJSQ5EiXkzoOQBTivi/zSJW?= =?us-ascii?Q?PFG2HrF6NaCQXi9+W7MWECd1pV2nBd5JYhku+LKtmrJrSZgXZMlnnwMpUcQe?= =?us-ascii?Q?g7HIvxn3Ev9ja9oHzpf5wIW39A+XvhMp0nH/rwUMYZvCkrnp9BMtPEdHvQTQ?= =?us-ascii?Q?4yiM6zhWv2MsgPD7+1XmSl+rqU3Qry/H?= 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)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?qhSh1ak+t13fIw2XRUH+9FUq6MUb46Qgu0rnGAGHnlmPLOnnqt74T9JErbag?= =?us-ascii?Q?QlnlZqBQ0Y+J/D9Hi9ukIw/B5SOau3+y18y6cyZxBrWA07owkKaRIHGgZmrD?= =?us-ascii?Q?JykPoUO8KobaEQI5+q8rt4BJ9wJ8OiRCUh8aq8qgHhqnay30d4EYybOcVTUc?= =?us-ascii?Q?QK8tojC1VdDGn4lJdS4pr6j2cPoj4ePKAYQ7TbVWUhw9AVSVnh66NWQ92dcC?= =?us-ascii?Q?Mt4Sh/EFPqcWHpaKLl2LjBneMsl8kILvW9AjhP8VO1YBUXJRE/Ui1vAUFnpb?= =?us-ascii?Q?hm0etE1ngoO+ahobYFNNUjhUOzWKWu0lNTaIkO0Ks5N2Izzj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yvlgbQm2iK+lMxV6Ufh+rDOS3TSnTMuxw4tTtAZcoT?= =?us-ascii?Q?36r6yGJjen0Bba+M1Dwn7trWOFENR1Jl9McCWMt56397JtUoaMqkQwT5r6wn?= =?us-ascii?Q?/IpXfVdzm69pEyaM+U8xwPdltdqqhr1qnpXbQJtCRkGbjV/Z0560MUMIqAP1?= =?us-ascii?Q?rdPEh2Pbk7sR7w9mfgdGBoReLn7UfJWrcUb9D6D8g/v8vwc3cYbDLil06V1p?= =?us-ascii?Q?dmqB6cByGjhNbr3VXl9GvyC8XJ305KdkZYSwgFcdtgHWge+ApcxoFLaawGHg?= =?us-ascii?Q?V6B/o4HSBiyaqCFjEzaKAfSAR6eoVTNfZJbCW0ZnIFRLHttfwxJX7NVJ9r+W?= =?us-ascii?Q?slHo3I+GZW8fvPY2RgQbo8QS0g72V43fvspHNQ/1cd3h/2gIiaP3a0Vt/RjF?= =?us-ascii?Q?JbL1svu+OPBh6u1ImFbsektxIUPAvMahz4qtYG8ksEPcxbzk09cCr2TxJazR?= =?us-ascii?Q?3yRQRVgZO/Z5ECTep+weJrVkaAa9jIEY8Oy3nElQNjqI56G0IOGpD2VSwTBu?= =?us-ascii?Q?oFwo2D0jBw=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ed9d0255-1ba9-4962-8240-08de4dcdc79c X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB9072.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2026 09:18:54.7160 (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: CVf5792X5i5KCYV/pwbIG33k0SxUgDQkrNz4jv7ILaGq2m9nqLchiwc7Wi+WKyjMiYBpdpkL9OLj0V8vZYqbUQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4335 Content-Type: text/plain; charset="utf-8" To create a new migration entry for a given struct page, that page is first converted to its pfn, before passing the pfn to make_readable_migration_entry() (and friends). A future change will remove device private pages from the physical address space. This will mean that device private pages no longer have a pfn and must be handled separately. Prepare for this with a new set of helpers: - make_readable_migration_entry_from_page() - make_readable_exclusive_migration_entry_from_page() - make_writable_migration_entry_from_page() These helpers take a struct page as parameter instead of a pfn. This will allow more flexibility for handling the swap offset field differently for device private pages. Signed-off-by: Jordan Niethe --- v1: - New to series v2: - Add flags param --- include/linux/leafops.h | 14 ++++++++++++++ include/linux/swapops.h | 33 +++++++++++++++++++++++++++++++++ mm/huge_memory.c | 29 +++++++++++++++++------------ mm/hugetlb.c | 15 +++++++++------ mm/memory.c | 5 +++-- mm/migrate_device.c | 12 ++++++------ mm/mprotect.c | 10 +++++++--- mm/rmap.c | 12 ++++++------ 8 files changed, 95 insertions(+), 35 deletions(-) diff --git a/include/linux/leafops.h b/include/linux/leafops.h index cfafe7a5e7b1..2fde8208da13 100644 --- a/include/linux/leafops.h +++ b/include/linux/leafops.h @@ -363,6 +363,20 @@ static inline unsigned long softleaf_to_pfn(softleaf_t= entry) return swp_offset(entry) & SWP_PFN_MASK; } =20 +/** + * softleaf_to_flags() - Obtain flags encoded within leaf entry. + * @entry: Leaf entry, softleaf_has_pfn(@entry) must return true. + * + * Returns: The flags associated with the leaf entry. + */ +static inline unsigned long softleaf_to_flags(softleaf_t entry) +{ + VM_WARN_ON_ONCE(!softleaf_has_pfn(entry)); + + /* Temporary until swp_entry_t eliminated. */ + return swp_offset(entry) & (SWP_MIG_YOUNG | SWP_MIG_DIRTY); +} + /** * softleaf_to_page() - Obtains struct page for PFN encoded within leaf en= try. * @entry: Leaf entry, softleaf_has_pfn(@entry) must return true. diff --git a/include/linux/swapops.h b/include/linux/swapops.h index 8cfc966eae48..a9ad997bd5ec 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -173,16 +173,33 @@ static inline swp_entry_t make_readable_migration_ent= ry(pgoff_t offset) return swp_entry(SWP_MIGRATION_READ, offset); } =20 +static inline swp_entry_t make_readable_migration_entry_from_page(struct p= age *page, pgoff_t flags) +{ + return swp_entry(SWP_MIGRATION_READ, page_to_pfn(page) | flags); +} + static inline swp_entry_t make_readable_exclusive_migration_entry(pgoff_t = offset) { return swp_entry(SWP_MIGRATION_READ_EXCLUSIVE, offset); } =20 +static inline swp_entry_t make_readable_exclusive_migration_entry_from_pag= e(struct page *page, + pgoff_t flags) +{ + return swp_entry(SWP_MIGRATION_READ_EXCLUSIVE, page_to_pfn(page) | flags); +} + static inline swp_entry_t make_writable_migration_entry(pgoff_t offset) { return swp_entry(SWP_MIGRATION_WRITE, offset); } =20 +static inline swp_entry_t make_writable_migration_entry_from_page(struct p= age *page, + pgoff_t flags) +{ + return swp_entry(SWP_MIGRATION_WRITE, page_to_pfn(page) | flags); +} + /* * Returns whether the host has large enough swap offset field to support * carrying over pgtable A/D bits for page migrations. The result is @@ -222,11 +239,27 @@ static inline swp_entry_t make_readable_migration_ent= ry(pgoff_t offset) return swp_entry(0, 0); } =20 +static inline swp_entry_t make_readable_migration_entry_from_page(struct p= age *page, pgoff_t flags) +{ + return swp_entry(0, 0); +} + +static inline swp_entry_t make_writeable_migration_entry_from_page(struct = page *page, pgoff_t flags) +{ + return swp_entry(0, 0); +} + static inline swp_entry_t make_readable_exclusive_migration_entry(pgoff_t = offset) { return swp_entry(0, 0); } =20 +static inline swp_entry_t make_readable_exclusive_migration_entry_from_pag= e(struct page *page, + pgoff_t flags) +{ + return swp_entry(0, 0); +} + static inline swp_entry_t make_writable_migration_entry(pgoff_t offset) { return swp_entry(0, 0); diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 40cf59301c21..e3a448cdb34d 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1800,7 +1800,8 @@ static void copy_huge_non_present_pmd( =20 if (softleaf_is_migration_write(entry) || softleaf_is_migration_read_exclusive(entry)) { - entry =3D make_readable_migration_entry(swp_offset(entry)); + entry =3D make_readable_migration_entry_from_page(softleaf_to_page(entry= ), + softleaf_to_flags(entry)); pmd =3D swp_entry_to_pmd(entry); if (pmd_swp_soft_dirty(*src_pmd)) pmd =3D pmd_swp_mksoft_dirty(pmd); @@ -2524,9 +2525,13 @@ static void change_non_present_huge_pmd(struct mm_st= ruct *mm, * just be safe and disable write */ if (folio_test_anon(folio)) - entry =3D make_readable_exclusive_migration_entry(swp_offset(entry)); + entry =3D make_readable_exclusive_migration_entry_from_page( + softleaf_to_page(entry), + softleaf_to_flags(entry)); else - entry =3D make_readable_migration_entry(swp_offset(entry)); + entry =3D make_readable_migration_entry_from_page( + softleaf_to_page(entry), + softleaf_to_flags(entry)); newpmd =3D swp_entry_to_pmd(entry); if (pmd_swp_soft_dirty(*pmd)) newpmd =3D pmd_swp_mksoft_dirty(newpmd); @@ -3183,14 +3188,14 @@ static void __split_huge_pmd_locked(struct vm_area_= struct *vma, pmd_t *pmd, =20 for (i =3D 0, addr =3D haddr; i < HPAGE_PMD_NR; i++, addr +=3D PAGE_SIZE= ) { if (write) - swp_entry =3D make_writable_migration_entry( - page_to_pfn(page + i)); + swp_entry =3D make_writable_migration_entry_from_page( + page + i, 0); else if (anon_exclusive) - swp_entry =3D make_readable_exclusive_migration_entry( - page_to_pfn(page + i)); + swp_entry =3D make_readable_exclusive_migration_entry_from_page( + page + i, 0); else - swp_entry =3D make_readable_migration_entry( - page_to_pfn(page + i)); + swp_entry =3D make_readable_migration_entry_from_page( + page + i, 0); if (young) swp_entry =3D make_migration_entry_young(swp_entry); if (dirty) @@ -4890,11 +4895,11 @@ int set_pmd_migration_entry(struct page_vma_mapped_= walk *pvmw, if (pmd_dirty(pmdval)) folio_mark_dirty(folio); if (pmd_write(pmdval)) - entry =3D make_writable_migration_entry(page_to_pfn(page)); + entry =3D make_writable_migration_entry_from_page(page, 0); else if (anon_exclusive) - entry =3D make_readable_exclusive_migration_entry(page_to_pfn(page)); + entry =3D make_readable_exclusive_migration_entry_from_page(page, 0); else - entry =3D make_readable_migration_entry(page_to_pfn(page)); + entry =3D make_readable_migration_entry_from_page(page, 0); if (pmd_young(pmdval)) entry =3D make_migration_entry_young(entry); if (pmd_dirty(pmdval)) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 51273baec9e5..6a5e40d4cfc2 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4939,8 +4939,9 @@ int copy_hugetlb_page_range(struct mm_struct *dst, st= ruct mm_struct *src, * COW mappings require pages in both * parent and child to be set to read. */ - softleaf =3D make_readable_migration_entry( - swp_offset(softleaf)); + softleaf =3D make_readable_migration_entry_from_page( + softleaf_to_page(softleaf), + softleaf_to_flags(softleaf)); entry =3D swp_entry_to_pte(softleaf); if (userfaultfd_wp(src_vma) && uffd_wp) entry =3D pte_swp_mkuffd_wp(entry); @@ -6491,11 +6492,13 @@ long hugetlb_change_protection(struct vm_area_struc= t *vma, =20 if (softleaf_is_migration_write(entry)) { if (folio_test_anon(folio)) - entry =3D make_readable_exclusive_migration_entry( - swp_offset(entry)); + entry =3D make_readable_exclusive_migration_entry_from_page( + softleaf_to_page(entry), + softleaf_to_flags(entry)); else - entry =3D make_readable_migration_entry( - swp_offset(entry)); + entry =3D make_readable_migration_entry_from_page( + softleaf_to_page(entry), + softleaf_to_flags(entry)); newpte =3D swp_entry_to_pte(entry); pages++; } diff --git a/mm/memory.c b/mm/memory.c index 2a55edc48a65..16493fbb3adb 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -963,8 +963,9 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm= _struct *src_mm, * to be set to read. A previously exclusive entry is * now shared. */ - entry =3D make_readable_migration_entry( - swp_offset(entry)); + entry =3D make_readable_migration_entry_from_page( + softleaf_to_page(entry), + softleaf_to_flags(entry)); pte =3D softleaf_to_pte(entry); if (pte_swp_soft_dirty(orig_pte)) pte =3D pte_swp_mksoft_dirty(pte); diff --git a/mm/migrate_device.c b/mm/migrate_device.c index a2baaa2a81f9..c876526ac6a3 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -432,14 +432,14 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, =20 /* Setup special migration page table entry */ if (mpfn & MIGRATE_PFN_WRITE) - entry =3D make_writable_migration_entry( - page_to_pfn(page)); + entry =3D make_writable_migration_entry_from_page( + page, 0); else if (anon_exclusive) - entry =3D make_readable_exclusive_migration_entry( - page_to_pfn(page)); + entry =3D make_readable_exclusive_migration_entry_from_page( + page, 0); else - entry =3D make_readable_migration_entry( - page_to_pfn(page)); + entry =3D make_readable_migration_entry_from_page( + page, 0); if (pte_present(pte)) { if (pte_young(pte)) entry =3D make_migration_entry_young(entry); diff --git a/mm/mprotect.c b/mm/mprotect.c index 283889e4f1ce..adfe1b7a4a19 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -328,10 +328,14 @@ static long change_pte_range(struct mmu_gather *tlb, * just be safe and disable write */ if (folio_test_anon(folio)) - entry =3D make_readable_exclusive_migration_entry( - swp_offset(entry)); + entry =3D make_readable_exclusive_migration_entry_from_page( + softleaf_to_page(entry), + softleaf_to_flags(entry)); else - entry =3D make_readable_migration_entry(swp_offset(entry)); + entry =3D make_readable_migration_entry_from_page( + softleaf_to_page(entry), + softleaf_to_flags(entry)); + newpte =3D swp_entry_to_pte(entry); if (pte_swp_soft_dirty(oldpte)) newpte =3D pte_swp_mksoft_dirty(newpte); diff --git a/mm/rmap.c b/mm/rmap.c index 79a2478b4aa9..6a63333f8722 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -2539,14 +2539,14 @@ static bool try_to_migrate_one(struct folio *folio,= struct vm_area_struct *vma, * pte is removed and then restart fault handling. */ if (writable) - entry =3D make_writable_migration_entry( - page_to_pfn(subpage)); + entry =3D make_writable_migration_entry_from_page( + subpage, 0); else if (anon_exclusive) - entry =3D make_readable_exclusive_migration_entry( - page_to_pfn(subpage)); + entry =3D make_readable_exclusive_migration_entry_from_page( + subpage, 0); else - entry =3D make_readable_migration_entry( - page_to_pfn(subpage)); + entry =3D make_readable_migration_entry_from_page( + subpage, 0); if (likely(pte_present(pteval))) { if (pte_young(pteval)) entry =3D make_migration_entry_young(entry); --=20 2.34.1