From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 8C0D933065C; Tue, 30 Jun 2026 02:25:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782786307; cv=none; b=d2i2fmY8as/KZEE/dpjB0sEt2PvlXyclxKs+AOVZv0ExOH1uUeeE80Y3Jf50O/NZ3j4hkpqX9RHj4NHAvq0O3zEGJKf9O3lzGTvD4g8W363lKHbeVeKS/9N6ZUNNtC3LNOVgkW60ZfZ5YRzhShtkUcxuv7L9GTIDeFvherpL3Ns= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782786307; c=relaxed/simple; bh=HmyaUhETQ3psk/gjNIk85I2wmYyzTFspPzmzcV8EQR0=; h=Date:To:From:Subject:Message-Id; b=e+N6KvxNumNkw9QgbkmBgHBc3Qt0Ls8g40KMisA8vSsWKeBvSkhluRkcftQlPe7yyzsmhtUT2sVKVn3ihhSgQnoTlqCFbnwuuDoy0VX+DpUwgNBkz76WEWcW8t/iNPlcKF6cug7xRHcXvrfqMBEty2pQhDetQRAsVJqVLmsrLJ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=sTi8Q08/; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="sTi8Q08/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2112B1F000E9; Tue, 30 Jun 2026 02:25:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1782786306; bh=ftGC2LjujBssyZngqrXsX05yVdKVKQ0aNOoEdG1l3cY=; h=Date:To:From:Subject; b=sTi8Q08/JBA1K2oehR0UJVTJ3Y7yhYrMLrL/YPFW/hoxkGtU6rIaDq/Un7zpd+sAt csp33pFS9G45Fx/lMgViWVvDuKuNl3u8QcbxrLzKFTb8rv+Upeu83YqzS6NAJH0VRz yoLlnG3cl6yNrDfvhuxhi9Ki40tNjs73tWeKPsHQ= Date: Mon, 29 Jun 2026 19:25:05 -0700 To: mm-commits@vger.kernel.org,ziy@nvidia.com,stable@vger.kernel.org,sj@kernel.org,ljs@kernel.org,lance.yang@linux.dev,david@kernel.org,balbirs@nvidia.com,richard.weiyang@gmail.com,akpm@linux-foundation.org From: Andrew Morton Subject: + mm-page_vma_mapped-fix-device-private-pmd-handling.patch added to mm-hotfixes-unstable branch Message-Id: <20260630022506.2112B1F000E9@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The patch titled Subject: mm/page_vma_mapped: fix device-private PMD handling has been added to the -mm mm-hotfixes-unstable branch. Its filename is mm-page_vma_mapped-fix-device-private-pmd-handling.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-page_vma_mapped-fix-device-private-pmd-handling.patch This patch will later appear in the mm-hotfixes-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Wei Yang Subject: mm/page_vma_mapped: fix device-private PMD handling Date: Tue, 30 Jun 2026 02:15:40 +0000 Commit 65edfda6f3f2 ("mm/rmap: extend rmap and migration support device-private entries") introduced the concept of device-private PMD entries, but did not correctly update the rmap walk code to account for them. As a result, when page_vma_mapped_walk() encounters device-private PMD entries, it takes no action other than to acquire the PMD lock and exit. However this is highly problematic for two reasons - firstly, device private entries possess a PFN so check_pmd() needs to be called to ensure an overlapping PFN range. Secondly, and more importantly, if PVMW_MIGRATION is set the caller assumes the returned entry is a migration entry, resulting in memory corruption when the caller tries to interpret the device private entry as such. In addition, commit 146287290023 ("mm/huge_memory: implement device-private THP splitting") allowed device private PMDs to be split like THP mappings, but again did not update this code path. As a result, we might race a PMD split prior to acquiring the PMD lock. This patch addresses all of these issues by invoking check_pmd(), ensuring PMVW_MIGRATION is not set and checks whether a split raced us we do for PMD THP and migration entries. Instead of checking for a subset of the cases after taking the pmd_lock(), put device-private along with pmd_trans_huge() and pmd_is_migration_entry(). Also remove thp_migration_supported() as it is already guarded by pmd_is_migration_entry(). Link: https://lore.kernel.org/20260630021540.17297-1-richard.weiyang@gmail.com Fixes: 65edfda6f3f2 ("mm/rmap: extend rmap and migration support device-private entries") Signed-off-by: Wei Yang Suggested-by: David Hildenbrand Cc: Balbir Singh Cc: SeongJae Park Cc: Zi Yan Cc: Lorenzo Stoakes Cc: Lance Yang Cc: Signed-off-by: Andrew Morton --- mm/page_vma_mapped.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) --- a/mm/page_vma_mapped.c~mm-page_vma_mapped-fix-device-private-pmd-handling +++ a/mm/page_vma_mapped.c @@ -243,21 +243,30 @@ restart: */ pmde = pmdp_get_lockless(pvmw->pmd); - if (pmd_trans_huge(pmde) || pmd_is_migration_entry(pmde)) { + if (pmd_trans_huge(pmde) || pmd_is_migration_entry(pmde) || + pmd_is_device_private_entry(pmde)) { pvmw->ptl = pmd_lock(mm, pvmw->pmd); pmde = *pvmw->pmd; - if (!pmd_present(pmde)) { + if (pmd_is_migration_entry(pmde)) { softleaf_t entry; - if (!thp_migration_supported() || - !(pvmw->flags & PVMW_MIGRATION)) + if (!(pvmw->flags & PVMW_MIGRATION)) return not_found(pvmw); entry = softleaf_from_pmd(pmde); + if (!check_pmd(softleaf_to_pfn(entry), pvmw)) + return not_found(pvmw); + return true; + } else if (pmd_is_device_private_entry(pmde)) { + softleaf_t entry; - if (!softleaf_is_migration(entry) || - !check_pmd(softleaf_to_pfn(entry), pvmw)) + if (pvmw->flags & PVMW_MIGRATION) + return not_found(pvmw); + entry = softleaf_from_pmd(pmde); + if (!check_pmd(softleaf_to_pfn(entry), pvmw)) return not_found(pvmw); return true; + } else if (!pmd_present(pmde)) { + return not_found(pvmw); } if (likely(pmd_trans_huge(pmde))) { if (pvmw->flags & PVMW_MIGRATION) @@ -266,17 +275,10 @@ restart: return not_found(pvmw); return true; } - /* THP pmd was split under us: handle on pte level */ + /* THP/device-private pmd was split under us: handle on pte level */ spin_unlock(pvmw->ptl); pvmw->ptl = NULL; } else if (!pmd_present(pmde)) { - const softleaf_t entry = softleaf_from_pmd(pmde); - - if (softleaf_is_device_private(entry)) { - pvmw->ptl = pmd_lock(mm, pvmw->pmd); - return true; - } - if ((pvmw->flags & PVMW_SYNC) && thp_vma_suitable_order(vma, pvmw->address, PMD_ORDER) && _ Patches currently in -mm which might be from richard.weiyang@gmail.com are mm-page_vma_mapped-fix-device-private-pmd-handling.patch