From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.46.15 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796357902; b=PzSIyR+N+ZyRMBpzx8mFcDW35ERwmVAm70pbTV2EmrZdPgL7qR48qt5nj2XIVH55hWAy t4MfTBg8n25WP7Ken3CMIE44qRGkXBXZWdVKMRtawKiPNuj712M6EE20nJIMW2Y35GgCW ZU6QdkJ9pwYFHR/orVxfhuIrBqbgoCCT0ANqc5GbASRQ4yNaT/QCfquE8Ednq8ydY4EFj /uGSb7ZivJBoqEHLmeTKa04sM6VLId5EYAEm4Wve3i3pi+fMk25w870k8tHJpTXeu2wOM SSLAkVKEsBLMFbktpRK8grDwG+YPrstH7ZENsMFbql3WXt+lulK2cq1owRQ1e0tvo3A== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796357902; h=DMARC-Filter:DKIM-Signature:Received:Received:From:Subject:Date: Message-Id:Content-Type:Content-Transfer-Encoding:X-B4-Tracking: X-Change-ID:To:Cc:X-Mailer:X-ClientProxiedBy:MIME-Version: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=C4OjFuFdjiodBLLm/e8WoQCPBI8RODqVmNWicsFyUvQ=; b=ETh4rNM0UUy/ffEpSxrlK6X7kx1tk/U10e3k2Ycxrpgj9UgySlDDhOrILGH9kAhMNUZB mmhRxT9lfcTvwg/TMm3kgu5t3IzvKRyxyx+oadlW6MwW1wqw9+DNNZVJ+5pJTGQgh84YZ EJNkbgz2k0ktYc02ZOVzsmrZVfan4G3EgB70diidOsuDDkALL3qMJQ9uA8qUlrJO037P8 D9ApMV03/FU3WNm6xfDu/RKtQnpw0CjlQk/YlynARRsDnduIr9h6t3jWY93YCORoDVAQH hjdvFQeX6taXsXsOg+91ID2Jmaf4gOS80R2JiOJu+e8ljh/hURW/H/2l7fwxrI8NNjg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=oIRsGRbc; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.46.15 Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11010015.outbound.protection.outlook.com [52.101.46.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 990B9606A6AC; Fri, 4 Dec 2026 04:18:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 990B9606A6AC 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, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=oIRsGRbc ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IX9ms7miYDsAIqI/J3l2bf4eVETj9Qt9DlSFejFop2YtKYyELxVSktp+r5ZOvO4KO19kGzih7o+G+MRH3R4jUZzPDn9oGxqAalU9C+PDeszv/9NvOWir/pxh4bkz6b2AZ5BwSEYRlT9PHCNldPZxP1/kYNJIz5pa8ZIoAi9NJr8Ts98zZCbEoMR50GVkvx0Vv+5T1v1pytvagc0otctujonQzpBMX3HQyQgino4cSASdNYcnF6Tqpeqm4la5Gb2vMkOvxb3tg+7ziYt7vRwP3Ui1L3acPhkU8USK31jPduYVqskuDvWihYjuT2pQ3CX5XmOFhy5yQlPY/z0SKz9dmQ== 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=C4OjFuFdjiodBLLm/e8WoQCPBI8RODqVmNWicsFyUvQ=; b=ItgKI/3d2kTn4U9MJCbm6dbd5IVxJzyKwFjq7Z0klVPStsydtfKGdscamLnUax/pX9PhNGEUXIdi9ssRq6HbMCPwLv1iaEhaSeVwIbBvm2xTHBMQDY9Ver30unx4wMLTgeoRS4jdu/D639rDQKkgpN3aoqAHKORksIENX9ZuVGySKLfIeKT95OTwbFkt571Gu9HQjeB9NgFP4YaChQEQt5rOwDJKBn3yJt9Xcgz3BUSrGsrnTC+IJXExXvQw3MLfkSvRvalXVp4pd0QTrsyvxxjbgYZIvisgaxVaL6ld1Vr2mIECGsrdzQLlaguoS8AWPiPZmqCPs9mX5tznJqgBpw== 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=C4OjFuFdjiodBLLm/e8WoQCPBI8RODqVmNWicsFyUvQ=; b=oIRsGRbcm9bRwzKoYdxZ1T9sAjcw4YPiEY6j2dyozIymrCRraqd287ZpNTrPw+6OMXYxO8F2vaGokSBohzMzzcMSVyb2OpFRZ0SDkSwWwgsDbpAGh4e13Wg+8IwKY3DzJGKIlPznaRpVcB4GLyOa5vg6dgWIbHtOrLhMjIYokLX8XAWtK6QOy5dG/nSnvFIdzPbCeSX50YwItVGMvY9uTfoW8nnORvkrY234WPlnBWpqsdebaub1a912v+QBDkFBinoR8kSb0/hnrwTScXMdXu0CuC0ew63hjW125IE3yygd7LgwWytx7+QDubD0Q8Yxu09PjMDF9XbkoC5NV5jH7g== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from IA0PR12MB8374.namprd12.prod.outlook.com (2603:10b6:208:40e::7) by SJ5PPF0AEDE5C3D.namprd12.prod.outlook.com (2603:10b6:a0f:fc02::989) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Fri, 4 Dec 2026 04:18:13 +0000 Received: from IA0PR12MB8374.namprd12.prod.outlook.com ([fe80::d85f:4c87:ae84:3f16]) by IA0PR12MB8374.namprd12.prod.outlook.com ([fe80::d85f:4c87:ae84:3f16%6]) with mapi id 15.21.0688.011; Fri, 4 Dec 2026 04:18:12 +0000 From: Zi Yan Subject: [PATCH v2 0/9] Re-enable discarding lazyfree PMD THPs and transient none PMD fixes Date: Thu, 03 Dec 2026 23:17:48 -0500 Message-Id: <20261203-anon_vma_uaf_fix-v2-0-3d4c746e8839@nvidia.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAAAAAAAC/2WOyw6CMBBFf4V0bU1b1EZX/ochpI9BxoQWW2g0h H+3IIkLl+fmzj0zkQgBIZJLMZEACSN6l0HsCmJa5e5A0WYmgokTZ0xS5byrU6fqUTV1gy8KUhl juRUAnOSzPkCO18lb9eU46geYYdnZGgGeY3YNv1qLcfDhvT6S+JJuTn78dyZOGZX6LGXJSn0Q+ uoSWlR74ztSzfP8AXkfT0fYAAAA X-Change-ID: 20261007-anon_vma_uaf_fix-e7accd1d2ee1 To: David Hildenbrand , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Kiryl Shutsemau , Lorenzo Stoakes , Rik van Riel , Vlastimil Babka , Harry Yoo , Jann Horn , Kyle Zeng , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zi Yan , stable@vger.kernel.org, Balbir Singh , Alistair Popple , Madhavan Srinivasan , Andrew Donnellan , Rohan McLure , Pasha Tatashin , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , "Ritesh Harjani (IBM)" , Shrikanth Hegde , linuxppc-dev@lists.ozlabs.org, Sashiko , Jisheng Zhang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Zong Li , Deepak Gupta , Palmer Dabbelt , John Hubbard , Peter Xu , linux-riscv@lists.infradead.org, Huacai Chen , WANG Xuerui , loongarch@lists.linux.dev, Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , linux-s390@vger.kernel.org, "David S. Miller" , Andreas Larsson , sparclinux@vger.kernel.org, Andrea Arcangeli , Suren Baghdasaryan , Jason Gunthorpe X-Mailer: b4 0.16.0 X-ClientProxiedBy: YQZPR01CA0103.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:83::12) To IA0PR12MB8374.namprd12.prod.outlook.com (2603:10b6:208:40e::7) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: IA0PR12MB8374:EE_|SJ5PPF0AEDE5C3D:EE_ X-MS-Office365-Filtering-Correlation-Id: 248eedf4-9f82-4ed7-f921-08df51bd9c57 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|376014|7416014|1800799024|6133799003|18002099003|260925022911599003|921020|260925021911599003|261026140227099003|261021135927099003|260925021311599003|56012099006|10067099003|261028144727099003|261009223027099003|11063799006|261021123027099003|261102123227099003|261022075727099003|261022105027099003|261021121427099003|261026121527099003|261022113327099003; X-Microsoft-Antispam-Message-Info: jhN9pNzBfmoOl0QHxvYXEsy3xrQxwyg4wNao+VqL1Z7cle66lAbeKE5sM5ErshBHh0iw/IuqGETtz6+05YNiWATvjl3UpkD/2XoLOvVTv+AJBmlPtBKca9GP5zyPhfAaRRDqbutARzsO72J+jvEBqYmgWPxa/PYF2PI0yIP8221jumehp3+LZsmnT0XuLCM8i1qF20sVCj63eSXJc6tWzvc/ul2o/Br/TzsEZhR697xy2qto7xkeYj4mz2rvQf2SY6VWK7CY+obRP/9PwLtzGODmHTG6b/KRwPI3RXOSKcDPxYRbpbzr30SNQA8xqGcFTyPF9VOcTRvgt8qm+qlcKSGIU7dfcUU5Dx4BHu0ta9Gl1Qy0virbUx6UwUYhZmPs0as9oJ6Mj7aD3PGjt+JP2F7p7LzxhP1kiW6aKDG38y/gPvfuxqW3XnUJ0Lb7C6/ZoCsUyh/+hEtM0u6XUCS1nsPLsEBpPE0kivX0W9sk3kd5smb3TBLIkN7tmt4XvccpwrA3bvK8aF/RPL8pUmkwjmby/61TYWEho0nul+h7g8jV8P2q/NGuN7fPofYXYMfNmyuXg6nJUDAzxSgj03/eSSEvr2vTRtwK+VRL7A2xFUSS4vLf+1cqpKJWgj9ZC+Ik0//R3IcMScY1EpKRJlBrc2v+rSnRLJg0EhCiTms7VCRyHhDyQUeqnTEUt6tctuuVZYI3tiG/2q/xjyUmFO2W5Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:IA0PR12MB8374.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(376014)(7416014)(1800799024)(6133799003)(18002099003)(260925022911599003)(921020)(260925021911599003)(261026140227099003)(261021135927099003)(260925021311599003)(56012099006)(10067099003)(261028144727099003)(261009223027099003)(11063799006)(261021123027099003)(261102123227099003)(261022075727099003)(261022105027099003)(261021121427099003)(261026121527099003)(261022113327099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?VWNka3hoQ2hoUVYwUUFHRG9rVEtSSERhcm91UEI2RmxFQ3lDd3dOcjRCVFBw?= =?utf-8?B?a2pqMHRSbzhuTE9YNUczUlF3S3Rqa1A4SHU1eDl0cmxiVWVWRG5ETUV0b1hW?= =?utf-8?B?ZkxHRWE3L2RiVHZkY2s1aytRUWJ3L0ZNeXkrYWNWOFFmaGhOeEJuMFZ3WUlG?= =?utf-8?B?TU4reFhJMHY3eHVLL3BCajdzZ2pxejF2ZGZRUlRuQUNqZUlEOXRZd1M5cHd2?= =?utf-8?B?TTlacVhZNk9wWG53UXd1cFpISXUwMU9NTW1UOUg4QnpQaUJLcGY0NDdxRTR4?= =?utf-8?B?eldyK2tSUlN1eGcvMjduenpiYmxMbEVRQlVLZjQwUWdJdkd3b2FaN2ZIOFJL?= =?utf-8?B?aUpwMGZWejVMbTh5YVE0eGNUMzU0ZUhldHNWMEI2cWNvWkI0c1BNNnJFOWRa?= =?utf-8?B?WXNNeDNIV3JtNFAwVXRnZUJubzhFUVdNNVh3V0dzcmUrcnNYMzd1NEU2MVNY?= =?utf-8?B?K3NoRnpHa0FZcFVSdHl0Y1B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Bk?= =?utf-8?Q?YVg4PniEYdk5S+4/Zu?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 248eedf4-9f82-4ed7-f921-08df51bd9c57 X-MS-Exchange-CrossTenant-AuthSource: IA0PR12MB8374.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2026 04:18:12.5886 (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: ZqV+m83zJjX1rIn+DOWlXkOD/tUIDhUutbxG0IracYn2YB+jkBYHDR7W3j7MJyHw X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ5PPF0AEDE5C3D Patch 1 can be picked up separately if more work is needed for the rest of the patches. For maintainers, Patch 7 and 9 use pmdp_invalidate() in place of PMD clearing, so they need the arch fixes from Patch 2 to 6. It might be better to get ack from arch maintainers for Patch 2 to 6 and merge the series via mm tree. Motivation === A bug was found in the PMD-level discard of lazyfree THPs [1]. The proposed fix keeps the PMD invalidated with pmdp_invalidate() instead of clearing it, but that does not work on every architecture: 1. riscv, LoongArch and s390 let GUP-fast follow an invalidated PMD; 2. powerpc/book3s64 page table check counts an invalidated PMD as mapped; 3. sparc64's thp_pte_count becomes unbalanced around pmdp_invalidate(). So the PMD-level discard was disabled instead [2]. This series fixes the arch code and re-enables it. The discard decides from the folio refcount, so GUP-fast must not take a reference through an invalidated PMD, and arch accounting must stay balanced when an invalidated PMD is set again or cleared. Details === Patch 1 fixes set_pmd_migration_entry() when migrating a device private folio. set_pmd_migration_entry() clears the device private PMD unnecessarily and the transient none PMD can be skipped by a concurrent zap. It can cause lost deposited page table, RSS stats mismatch, or data loss. Patches 2-6 fix the arch code, patch 7 from Kyle keeps the PMD invalidated instead of cleared until the discard is committed, and patch 8 enables the PMD-level discard again: 2. powerpc/book3s64: page table check counts an invalidated PMD as a live mapping, so setting it again or clearing it decrements the map count a second time and hits BUG_ON(). This is already reachable via mprotect(), and via MADV_COLD before v7.4, with CONFIG_PAGE_TABLE_CHECK. 3. riscv: an invalidated PMD still passes pmd_present() and the generic pmd_access_permitted(), so GUP-fast follows it. The generic helpers also let GUP-fast read execute-only entries and write shadow stack entries. Require _PAGE_PRESENT and _PAGE_READ in pte_access_permitted() and use it for PMDs and PUDs too. This patch was posted on its own [3] and has Cc: stable; it is carried here because the series depends on it. 4. LoongArch: an invalidated PMD passes the generic pmd_access_permitted() too. Add a pmd_access_permitted() that requires _PAGE_PRESENT. 5. s390: _SEGMENT_ENTRY_INVALID also marks an old PMD, so GUP-fast follows an invalidated PMD. Always clear _SEGMENT_ENTRY_READ in pmdp_invalidate(), which makes it pmd_protnone(), so GUP-fast rejects it. 6. sparc64: pmdp_invalidate() decrements thp_pte_count assuming a THP split follows, so setting the PMD again loses a count. Move the decrement to pmd_set(), which THP split uses to replace the huge PMD with a page table, and initialize the split's on-stack _pmd to none. 7. mm/huge_memory: use pmdp_invalidate() in the discard, so munmap() and mremap() wait on the PMD lock instead of skipping a none PMD. 8. mm/rmap: discard lazyfree THPs at PMD level again. Patch 9 fixes a similar transient none PMD issue using pmdp_invalidate() in UFFDIO_MOVE. Note === 1. x86, arm64 and powerpc already make GUP-fast reject an invalidated PMD, and sparc64 has no GUP-fast. 32-bit MIPS would not reject it, but it cannot have THP: _PAGE_HUGE makes PFN_PTE_SHIFT exceed PAGE_SHIFT, so the BUILD_BUG_ON() in arch_mm_preinit() fires, which is why Ingenic dropped huge pages in commit 69b686ddd579 ("MIPS: ingenic: Remove CPU_SUPPORTS_HUGEPAGES"). 2. A follow-up patch to remove on-stack _pmd in PMD split code can get rid of the for-sparc64 _pmd initialization code Link: https://lore.kernel.org/all/20261009165214.40212-2-kylebot@openai.com/ [1] Link: https://lore.kernel.org/all/20261012-lazyfree-stable-fix-v2-1-6387d6e30063@nvidia.com/ [2] Link: https://lore.kernel.org/all/20261015-riscv-gup-read-fix-v1-1-8cf7f2504029@nvidia.com/ [3] Signed-off-by: Zi Yan --- Changes in v2: - Patch 1: new. Do not clear a device private PMD in set_pmd_migration_entry(), since a concurrent zap can skip the transient none PMD. - Patch 2: cite riscv commit bdda2887cbf39 instead of its subject; added Usama's Acked-by. - Patch 3: replaced "riscv: mm: don't let GUP-fast follow invalidated THP PMDs" with the standalone "riscv: mm: don't let GUP-fast follow entries without _PAGE_READ" [3], which also rejects execute-only and shadow stack entries (Sashiko); added Jisheng's Reviewed-by. - Patch 4: revised the commit message. - Patch 5: revised the commit message. - Patch 6: move the decrement to pmd_set() instead of counting only valid huge PMDs: _PAGE_VALID is also the referenced bit (_PAGE_R), so v1 dropped old THPs from the count. - Patch 7: dropped the dependency note. - Patch 8: call update_hiwater_rss() before the PMD-level discard, as the PTE path does (Sashiko). - Patch 9: new. Use pmdp_invalidate() instead of clearing the PMD in UFFDIO_MOVE. - Dropped the Assisted-by tags; Claude and Codex were used to analyze the code and review the patches. - Link to v1: https://patch.msgid.link/20261015-anon_vma_uaf_fix-v1-0-7b977303b42b@nvidia.com --- Kyle Zeng (1): mm/huge_memory: avoid transient none PMDs during lazyfree reclaim Zi Yan (8): mm/migrate: do not clear device private entry in set_pmd_migration_entry() powerpc/book3s64/mm: don't count invalidated PMDs in page table check riscv: mm: don't let GUP-fast follow entries without _PAGE_READ LoongArch: mm: don't let GUP-fast follow invalidated THP PMDs s390/mm: always clear _SEGMENT_ENTRY_READ in pmdp_invalidate() sparc64: mm: fix thp_pte_count accounting around pmdp_invalidate() mm/rmap: re-enable discarding lazyfree THPs at PMD level userfaultfd: avoid transient none PMDs during UFFDIO_MOVE arch/loongarch/include/asm/pgtable.h | 6 ++++++ arch/powerpc/include/asm/book3s/64/pgtable.h | 7 +++---- arch/riscv/include/asm/pgtable.h | 27 ++++++++++++++++++++++++++ arch/s390/include/asm/pgtable.h | 8 ++++++-- arch/sparc/include/asm/pgtable_64.h | 7 +++++++ arch/sparc/mm/tlb.c | 27 ++++++++++++++------------ mm/huge_memory.c | 29 ++++++++++++++++++++++------ mm/rmap.c | 13 +++++++++++++ 8 files changed, 100 insertions(+), 24 deletions(-) --- base-commit: c6952260203fadee8e9f96c3f999f03b301d6f6d change-id: 20261007-anon_vma_uaf_fix-e7accd1d2ee1 Best regards, -- Yan, Zi