All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/3] fs/proc/task_mmu: smaps fixes for non-present and device-private PMDs
@ 2026-11-25 11:49 Usama Arif
  2026-11-25 11:49 ` [PATCH v4 1/3] fs/proc/task_mmu: read the PMD once in smaps_pmd_entry() Usama Arif
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Usama Arif @ 2026-11-25 11:49 UTC (permalink / raw)
  To: Andrew Morton, apopple, byungchul, david, gourry, jannh,
	joshua.hahnjy, liam, linux-fsdevel, linux-kernel, linux-mm, ljs,
	matthew.brost, mhocko, pfalcato, rppt, surenb, vbabka, ying.huang,
	ziy, kas, hannes, riel, shakeel.butt, kernel-team, baolin.wang,
	Nico Pache, ryan.roberts, dev.jain, baohua, lance.yang
  Cc: Usama Arif

This series contains two fixes for the smaps PMD path, plus the cleanup
they build on. They were extracted from the work on PMD swap entries for
anonymous THPs [1] and can be merged independently.

1. Read the PMD once in smaps_pmd_entry(), the way smaps_pte_entry()
   already does. No functional change.

2. Stop reading the accessed and dirty bits out of a non-present PMD
   in smaps, where they encode the softleaf entry rather than
   accessed/dirty state.

3. Account device-private PMDs using mapcounts in smaps, matching the
   PTE path. Shared mappings get proportional PSS, and exclusive
   mappings are counted as private.

This applies on top of mm-new (5bd93e4b0b35).

v3 -> v4: https://lore.kernel.org/r/20261123163301.1568240-1-usama.arif@linux.dev/
- Patches 1 and 2 of v3 have been picked up in mm/core.git
  (migrate-7.5.misc and core-7.5.misc), so this revision only carries
  the three smaps patches, renumbered 1-3 (David). The patch numbers in
  the older entries below are the ones from the five patch series.
- Patch 1: make pmdval const (Lorenzo).
- Collect the Reviewed-by tags from v3.

v2 -> v3: https://lore.kernel.org/r/20261116063624.1382944-1-usama.arif@linux.dev/
- Patch 2: move the hwpoison check to the top of the batching block, so
  the two bit tests run before the page table scan rather than after
  it (David, Zi Yan, Kiryl).
- Patch 3 is new: read the PMD once with pmdp_get(), so patch 4 only
  has to move pmd_young() and pmd_dirty() under the present branch
  (Kiryl). Patch 4 is unchanged in effect and keeps its v2 tags.
- Collect the Reviewed-by tags from v2.

v1 -> v2: https://lore.kernel.org/r/20261111113904.650722-1-usama.arif@linux.dev/
- Patch 2: use the existing folio_contain_hwpoisoned_page()
  rather than adding a helper that scans every page of the folio
  (Lorenzo, David). Only skip batching for anon folios, since
  falling back for a freshly read folio frees it with the poisoned
  page in it, and the retried fault can get the same block back.
- Collect the Reviewed-by and Acked-by tags from v1.

[1] PMD-level swap entries for anonymous THPs:
https://lore.kernel.org/r/20261002095503.3585565-1-usama.arif@linux.dev/
 
Usama Arif (3):
  fs/proc/task_mmu: read the PMD once in smaps_pmd_entry()
  fs/proc/task_mmu: don't read young/dirty from a non-present PMD in
    smaps
  fs/proc/task_mmu: account device-private PMDs as present in smaps

 fs/proc/task_mmu.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

-- 
2.53.1-Meta


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v4 1/3] fs/proc/task_mmu: read the PMD once in smaps_pmd_entry()
  2026-11-25 11:49 [PATCH v4 0/3] fs/proc/task_mmu: smaps fixes for non-present and device-private PMDs Usama Arif
@ 2026-11-25 11:49 ` Usama Arif
  2026-11-25 11:59   ` David Hildenbrand (Arm)
  2026-11-30  5:55   ` + fs-proc-task_mmu-read-the-pmd-once-in-smaps_pmd_entry.patch added to mm-new branch Andrew Morton
  2026-11-25 11:49 ` [PATCH v4 2/3] fs/proc/task_mmu: don't read young/dirty from a non-present PMD in smaps Usama Arif
  2026-11-25 11:49 ` [PATCH v4 3/3] fs/proc/task_mmu: account device-private PMDs as present in smaps Usama Arif
  2 siblings, 2 replies; 8+ messages in thread
From: Usama Arif @ 2026-11-25 11:49 UTC (permalink / raw)
  To: Andrew Morton, apopple, byungchul, david, gourry, jannh,
	joshua.hahnjy, liam, linux-fsdevel, linux-kernel, linux-mm, ljs,
	matthew.brost, mhocko, pfalcato, rppt, surenb, vbabka, ying.huang,
	ziy, kas, hannes, riel, shakeel.butt, kernel-team, baolin.wang,
	Nico Pache, ryan.roberts, dev.jain, baohua, lance.yang
  Cc: Usama Arif

smaps_pmd_entry() dereferences the pmd pointer six times. Read it once
into a local with pmdp_get(), the way smaps_pte_entry() already does
with ptep_get(), so that every test sees the same value.

No functional change intended.

Suggested-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
Signed-off-by: Usama Arif <usama.arif@linux.dev>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
---
 fs/proc/task_mmu.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index d2a524c6ad4b93..cb5e335bf05da4 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -1022,14 +1022,15 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr,
 	struct page *page = NULL;
 	bool present = false;
 	struct folio *folio;
+	const pmd_t pmdval = pmdp_get(pmd);
 
-	if (pmd_none(*pmd))
+	if (pmd_none(pmdval))
 		return;
-	if (pmd_present(*pmd)) {
-		page = vm_normal_page_pmd(vma, addr, *pmd);
+	if (pmd_present(pmdval)) {
+		page = vm_normal_page_pmd(vma, addr, pmdval);
 		present = true;
 	} else if (unlikely(thp_migration_supported())) {
-		const softleaf_t entry = softleaf_from_pmd(*pmd);
+		const softleaf_t entry = softleaf_from_pmd(pmdval);
 
 		if (softleaf_has_pfn(entry))
 			page = softleaf_to_page(entry);
@@ -1046,7 +1047,7 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr,
 	else
 		mss->file_thp += HPAGE_PMD_SIZE;
 
-	smaps_account(mss, page, true, pmd_young(*pmd), pmd_dirty(*pmd),
+	smaps_account(mss, page, true, pmd_young(pmdval), pmd_dirty(pmdval),
 		      locked, present);
 }
 #else
-- 
2.53.1-Meta


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v4 2/3] fs/proc/task_mmu: don't read young/dirty from a non-present PMD in smaps
  2026-11-25 11:49 [PATCH v4 0/3] fs/proc/task_mmu: smaps fixes for non-present and device-private PMDs Usama Arif
  2026-11-25 11:49 ` [PATCH v4 1/3] fs/proc/task_mmu: read the PMD once in smaps_pmd_entry() Usama Arif
@ 2026-11-25 11:49 ` Usama Arif
  2026-11-30  5:55   ` + fs-proc-task_mmu-dont-read-young-dirty-from-a-non-present-pmd-in-smaps.patch added to mm-new branch Andrew Morton
  2026-11-25 11:49 ` [PATCH v4 3/3] fs/proc/task_mmu: account device-private PMDs as present in smaps Usama Arif
  2 siblings, 1 reply; 8+ messages in thread
From: Usama Arif @ 2026-11-25 11:49 UTC (permalink / raw)
  To: Andrew Morton, apopple, byungchul, david, gourry, jannh,
	joshua.hahnjy, liam, linux-fsdevel, linux-kernel, linux-mm, ljs,
	matthew.brost, mhocko, pfalcato, rppt, surenb, vbabka, ying.huang,
	ziy, kas, hannes, riel, shakeel.butt, kernel-team, baolin.wang,
	Nico Pache, ryan.roberts, dev.jain, baohua, lance.yang
  Cc: Usama Arif, stable

smaps_pmd_entry() passes pmd_young() and pmd_dirty() to smaps_account()
for every PMD, including softleaf entries (migration and device-private),
where those bits encode the entry rather than accessed/dirty state.
smaps_pte_entry() only reads them when the entry is present.

On x86_64 the entry's offset is stored inverted across bits 9-58, which
overlap _PAGE_SAVED_DIRTY, so pmd_dirty() returns garbage: a clean 2MB
device-private mapping is accounted as 2048 kB dirty, and lazyfree
accounting is suppressed. pgtable_64.h also warns that the hardware can
set the accessed and dirty bits on non-present entries by mistake.

Only read the bits when the PMD is present.

Fixes: c94b6923fa0a ("/proc/PID/smaps: Add PMD migration entry parsing")
Cc: stable@vger.kernel.org
Signed-off-by: Usama Arif <usama.arif@linux.dev>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
---
 fs/proc/task_mmu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index cb5e335bf05da4..cf1732935c73df 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -1020,7 +1020,7 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr,
 	struct vm_area_struct *vma = walk->vma;
 	bool locked = !!(vma->vm_flags & VM_LOCKED);
 	struct page *page = NULL;
-	bool present = false;
+	bool present = false, young = false, dirty = false;
 	struct folio *folio;
 	const pmd_t pmdval = pmdp_get(pmd);
 
@@ -1028,6 +1028,8 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr,
 		return;
 	if (pmd_present(pmdval)) {
 		page = vm_normal_page_pmd(vma, addr, pmdval);
+		young = pmd_young(pmdval);
+		dirty = pmd_dirty(pmdval);
 		present = true;
 	} else if (unlikely(thp_migration_supported())) {
 		const softleaf_t entry = softleaf_from_pmd(pmdval);
@@ -1047,8 +1049,7 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr,
 	else
 		mss->file_thp += HPAGE_PMD_SIZE;
 
-	smaps_account(mss, page, true, pmd_young(pmdval), pmd_dirty(pmdval),
-		      locked, present);
+	smaps_account(mss, page, true, young, dirty, locked, present);
 }
 #else
 static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr,
-- 
2.53.1-Meta


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v4 3/3] fs/proc/task_mmu: account device-private PMDs as present in smaps
  2026-11-25 11:49 [PATCH v4 0/3] fs/proc/task_mmu: smaps fixes for non-present and device-private PMDs Usama Arif
  2026-11-25 11:49 ` [PATCH v4 1/3] fs/proc/task_mmu: read the PMD once in smaps_pmd_entry() Usama Arif
  2026-11-25 11:49 ` [PATCH v4 2/3] fs/proc/task_mmu: don't read young/dirty from a non-present PMD in smaps Usama Arif
@ 2026-11-25 11:49 ` Usama Arif
  2026-11-30  5:55   ` + fs-proc-task_mmu-account-device-private-pmds-as-present-in-smaps.patch added to mm-new branch Andrew Morton
  2 siblings, 1 reply; 8+ messages in thread
From: Usama Arif @ 2026-11-25 11:49 UTC (permalink / raw)
  To: Andrew Morton, apopple, byungchul, david, gourry, jannh,
	joshua.hahnjy, liam, linux-fsdevel, linux-kernel, linux-mm, ljs,
	matthew.brost, mhocko, pfalcato, rppt, surenb, vbabka, ying.huang,
	ziy, kas, hannes, riel, shakeel.butt, kernel-team, baolin.wang,
	Nico Pache, ryan.roberts, dev.jain, baohua, lance.yang
  Cc: Usama Arif, stable

Device-private PMDs represent mapped pages, but smaps_pmd_entry()
passes present=false to smaps_account(). That treats them like migration
entries: mapcounts are ignored, PSS is charged in full, and exclusive
mappings are accounted as shared.

Match smaps_pte_entry() and mark device-private PMDs as present so
smaps_account() uses mapcounts for PSS and private/shared accounting.

Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")
Cc: stable@vger.kernel.org
Signed-off-by: Usama Arif <usama.arif@linux.dev>
Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
---
 fs/proc/task_mmu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index cf1732935c73df..9017b312f404ef 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -1034,8 +1034,11 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr,
 	} else if (unlikely(thp_migration_supported())) {
 		const softleaf_t entry = softleaf_from_pmd(pmdval);
 
-		if (softleaf_has_pfn(entry))
+		if (softleaf_has_pfn(entry)) {
+			if (softleaf_is_device_private(entry))
+				present = true;
 			page = softleaf_to_page(entry);
+		}
 	}
 	if (IS_ERR_OR_NULL(page))
 		return;
-- 
2.53.1-Meta


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 1/3] fs/proc/task_mmu: read the PMD once in smaps_pmd_entry()
  2026-11-25 11:49 ` [PATCH v4 1/3] fs/proc/task_mmu: read the PMD once in smaps_pmd_entry() Usama Arif
@ 2026-11-25 11:59   ` David Hildenbrand (Arm)
  2026-11-30  5:55   ` + fs-proc-task_mmu-read-the-pmd-once-in-smaps_pmd_entry.patch added to mm-new branch Andrew Morton
  1 sibling, 0 replies; 8+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-25 11:59 UTC (permalink / raw)
  To: Usama Arif, Andrew Morton, apopple, byungchul, gourry, jannh,
	joshua.hahnjy, liam, linux-fsdevel, linux-kernel, linux-mm, ljs,
	matthew.brost, mhocko, pfalcato, rppt, surenb, vbabka, ying.huang,
	ziy, kas, hannes, riel, shakeel.butt, kernel-team, baolin.wang,
	Nico Pache, ryan.roberts, dev.jain, baohua, lance.yang

On 11/25/26 12:49, Usama Arif wrote:
> smaps_pmd_entry() dereferences the pmd pointer six times. Read it once
> into a local with pmdp_get(), the way smaps_pte_entry() already does
> with ptep_get(), so that every test sees the same value.
> 
> No functional change intended.
> 
> Suggested-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
> Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> Reviewed-by: Zi Yan <ziy@nvidia.com>
> ---

Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>

-- 
Cheers,

David


^ permalink raw reply	[flat|nested] 8+ messages in thread

* + fs-proc-task_mmu-read-the-pmd-once-in-smaps_pmd_entry.patch added to mm-new branch
  2026-11-25 11:49 ` [PATCH v4 1/3] fs/proc/task_mmu: read the PMD once in smaps_pmd_entry() Usama Arif
  2026-11-25 11:59   ` David Hildenbrand (Arm)
@ 2026-11-30  5:55   ` Andrew Morton
  1 sibling, 0 replies; 8+ messages in thread
From: Andrew Morton @ 2026-11-30  5:55 UTC (permalink / raw)
  To: mm-commits, ziy, ying.huang, vbabka, surenb, shakeel.butt,
	ryan.roberts, rppt, riel, pfalcato, nico.pache, mhocko,
	matthew.brost, ljs, liam, lance.yang, kas, joshua.hahnjy, jannh,
	hannes, gourry, dev.jain, david, chris, byungchul, baolin.wang,
	baohua, apopple, usama.arif, akpm


The patch titled
     Subject: fs/proc/task_mmu: read the PMD once in smaps_pmd_entry()
has been added to the -mm mm-new branch.  Its filename is
     fs-proc-task_mmu-read-the-pmd-once-in-smaps_pmd_entry.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/fs-proc-task_mmu-read-the-pmd-once-in-smaps_pmd_entry.patch

This patch will later appear in the mm-new branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews.  Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.

The mm-new branch of mm.git is not included in linux-next

If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next

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: Usama Arif <usama.arif@linux.dev>
Subject: fs/proc/task_mmu: read the PMD once in smaps_pmd_entry()
Date: Wed, 25 Nov 2026 03:49:57 -0800

Patch series "fs/proc/task_mmu: smaps fixes for non-present and
device-private PMDs", v4.

This series contains two fixes for the smaps PMD path, plus the cleanup
they build on. They were extracted from the work on PMD swap entries for
anonymous THPs [1] and can be merged independently.

1. Read the PMD once in smaps_pmd_entry(), the way smaps_pte_entry()
   already does. No functional change.

2. Stop reading the accessed and dirty bits out of a non-present PMD
   in smaps, where they encode the softleaf entry rather than
   accessed/dirty state.

3. Account device-private PMDs using mapcounts in smaps, matching the
   PTE path. Shared mappings get proportional PSS, and exclusive
   mappings are counted as private.


This patch (of 3):

smaps_pmd_entry() dereferences the pmd pointer six times. Read it once
into a local with pmdp_get(), the way smaps_pte_entry() already does
with ptep_get(), so that every test sees the same value.

No functional change intended.

Link: https://lore.kernel.org/20261125115014.4014507-1-usama.arif@linux.dev
Link: https://patch.msgid.link/20261125115014.4014507-2-usama.arif@linux.dev
Signed-off-by: Usama Arif <usama.arif@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Suggested-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
Cc: Nico Pache <nico.pache@linux.dev>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Byungchul Park <byungchul@sk.com>
Cc: Gregory Price <gourry@gourry.net>
Cc: Jann Horn <jannh@google.com>
Cc: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Pedro Falcato <pfalcato@suse.de>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Ying Huang <ying.huang@linux.alibaba.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Rik van Riel <riel@surriel.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Chris Down <chris@chrisdown.name>

 fs/proc/task_mmu.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

--- a/fs/proc/task_mmu.c~fs-proc-task_mmu-read-the-pmd-once-in-smaps_pmd_entry
+++ a/fs/proc/task_mmu.c
@@ -1022,14 +1022,15 @@ static void smaps_pmd_entry(pmd_t *pmd,
 	struct page *page = NULL;
 	bool present = false;
 	struct folio *folio;
+	const pmd_t pmdval = pmdp_get(pmd);
 
-	if (pmd_none(*pmd))
+	if (pmd_none(pmdval))
 		return;
-	if (pmd_present(*pmd)) {
-		page = vm_normal_page_pmd(vma, addr, *pmd);
+	if (pmd_present(pmdval)) {
+		page = vm_normal_page_pmd(vma, addr, pmdval);
 		present = true;
 	} else if (unlikely(thp_migration_supported())) {
-		const softleaf_t entry = softleaf_from_pmd(*pmd);
+		const softleaf_t entry = softleaf_from_pmd(pmdval);
 
 		if (softleaf_has_pfn(entry))
 			page = softleaf_to_page(entry);
@@ -1046,7 +1047,7 @@ static void smaps_pmd_entry(pmd_t *pmd,
 	else
 		mss->file_thp += HPAGE_PMD_SIZE;
 
-	smaps_account(mss, page, true, pmd_young(*pmd), pmd_dirty(*pmd),
+	smaps_account(mss, page, true, pmd_young(pmdval), pmd_dirty(pmdval),
 		      locked, present);
 }
 #else
_

Patches currently in -mm which might be from usama.arif@linux.dev are

mm-zswap-use-separate-compression-and-decompression-requests.patch
mm-zswap-use-stack-requests-for-synchronous-decompression.patch
fs-proc-task_mmu-read-the-pmd-once-in-smaps_pmd_entry.patch
fs-proc-task_mmu-dont-read-young-dirty-from-a-non-present-pmd-in-smaps.patch
fs-proc-task_mmu-account-device-private-pmds-as-present-in-smaps.patch


^ permalink raw reply	[flat|nested] 8+ messages in thread

* + fs-proc-task_mmu-dont-read-young-dirty-from-a-non-present-pmd-in-smaps.patch added to mm-new branch
  2026-11-25 11:49 ` [PATCH v4 2/3] fs/proc/task_mmu: don't read young/dirty from a non-present PMD in smaps Usama Arif
@ 2026-11-30  5:55   ` Andrew Morton
  0 siblings, 0 replies; 8+ messages in thread
From: Andrew Morton @ 2026-11-30  5:55 UTC (permalink / raw)
  To: mm-commits, ziy, ying.huang, vbabka, surenb, stable, shakeel.butt,
	ryan.roberts, rppt, riel, pfalcato, nico.pache, mhocko,
	matthew.brost, ljs, liam, lance.yang, kas, joshua.hahnjy, jannh,
	hannes, gourry, dev.jain, david, chris, byungchul, baolin.wang,
	baohua, apopple, usama.arif, akpm


The patch titled
     Subject: fs/proc/task_mmu: don't read young/dirty from a non-present PMD in smaps
has been added to the -mm mm-new branch.  Its filename is
     fs-proc-task_mmu-dont-read-young-dirty-from-a-non-present-pmd-in-smaps.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/fs-proc-task_mmu-dont-read-young-dirty-from-a-non-present-pmd-in-smaps.patch

This patch will later appear in the mm-new branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews.  Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.

The mm-new branch of mm.git is not included in linux-next

If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next

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: Usama Arif <usama.arif@linux.dev>
Subject: fs/proc/task_mmu: don't read young/dirty from a non-present PMD in smaps
Date: Wed, 25 Nov 2026 03:49:58 -0800

smaps_pmd_entry() passes pmd_young() and pmd_dirty() to smaps_account()
for every PMD, including softleaf entries (migration and device-private),
where those bits encode the entry rather than accessed/dirty state.
smaps_pte_entry() only reads them when the entry is present.

On x86_64 the entry's offset is stored inverted across bits 9-58, which
overlap _PAGE_SAVED_DIRTY, so pmd_dirty() returns garbage: a clean 2MB
device-private mapping is accounted as 2048 kB dirty, and lazyfree
accounting is suppressed. pgtable_64.h also warns that the hardware can
set the accessed and dirty bits on non-present entries by mistake.

Only read the bits when the PMD is present.

Link: https://patch.msgid.link/20261125115014.4014507-3-usama.arif@linux.dev
Fixes: c94b6923fa0a ("/proc/PID/smaps: Add PMD migration entry parsing")
Signed-off-by: Usama Arif <usama.arif@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Cc: Nico Pache <nico.pache@linux.dev>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Byungchul Park <byungchul@sk.com>
Cc: Gregory Price <gourry@gourry.net>
Cc: Jann Horn <jannh@google.com>
Cc: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Pedro Falcato <pfalcato@suse.de>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Ying Huang <ying.huang@linux.alibaba.com>
Cc: Kiryl Shutsemau <kas@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Rik van Riel <riel@surriel.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Chris Down <chris@chrisdown.name>
Cc: <stable@vger.kernel.org>

 fs/proc/task_mmu.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

--- a/fs/proc/task_mmu.c~fs-proc-task_mmu-dont-read-young-dirty-from-a-non-present-pmd-in-smaps
+++ a/fs/proc/task_mmu.c
@@ -1020,7 +1020,7 @@ static void smaps_pmd_entry(pmd_t *pmd,
 	struct vm_area_struct *vma = walk->vma;
 	bool locked = vma_test(vma, VMA_LOCKED_BIT);
 	struct page *page = NULL;
-	bool present = false;
+	bool present = false, young = false, dirty = false;
 	struct folio *folio;
 	const pmd_t pmdval = pmdp_get(pmd);
 
@@ -1028,6 +1028,8 @@ static void smaps_pmd_entry(pmd_t *pmd,
 		return;
 	if (pmd_present(pmdval)) {
 		page = vm_normal_page_pmd(vma, addr, pmdval);
+		young = pmd_young(pmdval);
+		dirty = pmd_dirty(pmdval);
 		present = true;
 	} else if (unlikely(thp_migration_supported())) {
 		const softleaf_t entry = softleaf_from_pmd(pmdval);
@@ -1047,8 +1049,7 @@ static void smaps_pmd_entry(pmd_t *pmd,
 	else
 		mss->file_thp += HPAGE_PMD_SIZE;
 
-	smaps_account(mss, page, true, pmd_young(pmdval), pmd_dirty(pmdval),
-		      locked, present);
+	smaps_account(mss, page, true, young, dirty, locked, present);
 }
 #else
 static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr,
_

Patches currently in -mm which might be from usama.arif@linux.dev are

mm-zswap-use-separate-compression-and-decompression-requests.patch
mm-zswap-use-stack-requests-for-synchronous-decompression.patch
fs-proc-task_mmu-read-the-pmd-once-in-smaps_pmd_entry.patch
fs-proc-task_mmu-dont-read-young-dirty-from-a-non-present-pmd-in-smaps.patch
fs-proc-task_mmu-account-device-private-pmds-as-present-in-smaps.patch


^ permalink raw reply	[flat|nested] 8+ messages in thread

* + fs-proc-task_mmu-account-device-private-pmds-as-present-in-smaps.patch added to mm-new branch
  2026-11-25 11:49 ` [PATCH v4 3/3] fs/proc/task_mmu: account device-private PMDs as present in smaps Usama Arif
@ 2026-11-30  5:55   ` Andrew Morton
  0 siblings, 0 replies; 8+ messages in thread
From: Andrew Morton @ 2026-11-30  5:55 UTC (permalink / raw)
  To: mm-commits, ziy, ying.huang, vbabka, surenb, stable, shakeel.butt,
	ryan.roberts, rppt, riel, pfalcato, nico.pache, mhocko,
	matthew.brost, ljs, liam, lance.yang, kas, joshua.hahnjy, jannh,
	hannes, gourry, dev.jain, david, chris, byungchul, baolin.wang,
	baohua, apopple, usama.arif, akpm


The patch titled
     Subject: fs/proc/task_mmu: account device-private PMDs as present in smaps
has been added to the -mm mm-new branch.  Its filename is
     fs-proc-task_mmu-account-device-private-pmds-as-present-in-smaps.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/fs-proc-task_mmu-account-device-private-pmds-as-present-in-smaps.patch

This patch will later appear in the mm-new branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews.  Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.

The mm-new branch of mm.git is not included in linux-next

If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next

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: Usama Arif <usama.arif@linux.dev>
Subject: fs/proc/task_mmu: account device-private PMDs as present in smaps
Date: Wed, 25 Nov 2026 03:49:59 -0800

Device-private PMDs represent mapped pages, but smaps_pmd_entry()
passes present=false to smaps_account(). That treats them like migration
entries: mapcounts are ignored, PSS is charged in full, and exclusive
mappings are accounted as shared.

Match smaps_pte_entry() and mark device-private PMDs as present so
smaps_account() uses mapcounts for PSS and private/shared accounting.

Link: https://patch.msgid.link/20261125115014.4014507-4-usama.arif@linux.dev
Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")
Signed-off-by: Usama Arif <usama.arif@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
Cc: Nico Pache <nico.pache@linux.dev>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Byungchul Park <byungchul@sk.com>
Cc: Gregory Price <gourry@gourry.net>
Cc: Jann Horn <jannh@google.com>
Cc: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Pedro Falcato <pfalcato@suse.de>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Ying Huang <ying.huang@linux.alibaba.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Rik van Riel <riel@surriel.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Chris Down <chris@chrisdown.name>
Cc: <stable@vger.kernel.org>

 fs/proc/task_mmu.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

--- a/fs/proc/task_mmu.c~fs-proc-task_mmu-account-device-private-pmds-as-present-in-smaps
+++ a/fs/proc/task_mmu.c
@@ -1034,8 +1034,11 @@ static void smaps_pmd_entry(pmd_t *pmd,
 	} else if (unlikely(thp_migration_supported())) {
 		const softleaf_t entry = softleaf_from_pmd(pmdval);
 
-		if (softleaf_has_pfn(entry))
+		if (softleaf_has_pfn(entry)) {
+			if (softleaf_is_device_private(entry))
+				present = true;
 			page = softleaf_to_page(entry);
+		}
 	}
 	if (IS_ERR_OR_NULL(page))
 		return;
_

Patches currently in -mm which might be from usama.arif@linux.dev are

mm-zswap-use-separate-compression-and-decompression-requests.patch
mm-zswap-use-stack-requests-for-synchronous-decompression.patch
fs-proc-task_mmu-read-the-pmd-once-in-smaps_pmd_entry.patch
fs-proc-task_mmu-dont-read-young-dirty-from-a-non-present-pmd-in-smaps.patch
fs-proc-task_mmu-account-device-private-pmds-as-present-in-smaps.patch


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-30  5:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 11:49 [PATCH v4 0/3] fs/proc/task_mmu: smaps fixes for non-present and device-private PMDs Usama Arif
2026-11-25 11:49 ` [PATCH v4 1/3] fs/proc/task_mmu: read the PMD once in smaps_pmd_entry() Usama Arif
2026-11-25 11:59   ` David Hildenbrand (Arm)
2026-11-30  5:55   ` + fs-proc-task_mmu-read-the-pmd-once-in-smaps_pmd_entry.patch added to mm-new branch Andrew Morton
2026-11-25 11:49 ` [PATCH v4 2/3] fs/proc/task_mmu: don't read young/dirty from a non-present PMD in smaps Usama Arif
2026-11-30  5:55   ` + fs-proc-task_mmu-dont-read-young-dirty-from-a-non-present-pmd-in-smaps.patch added to mm-new branch Andrew Morton
2026-11-25 11:49 ` [PATCH v4 3/3] fs/proc/task_mmu: account device-private PMDs as present in smaps Usama Arif
2026-11-30  5:55   ` + fs-proc-task_mmu-account-device-private-pmds-as-present-in-smaps.patch added to mm-new branch Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.