Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH v4 2/3] fs/proc/task_mmu: don't read young/dirty from a non-present PMD in smaps
       [not found] <20261125115014.4014507-1-usama.arif@linux.dev>
@ 2026-11-25 11:49 ` Usama Arif
  2026-11-25 11:49 ` [PATCH v4 3/3] fs/proc/task_mmu: account device-private PMDs as present " Usama Arif
  1 sibling, 0 replies; 2+ 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] 2+ messages in thread

* [PATCH v4 3/3] fs/proc/task_mmu: account device-private PMDs as present in smaps
       [not found] <20261125115014.4014507-1-usama.arif@linux.dev>
  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
  1 sibling, 0 replies; 2+ 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] 2+ messages in thread

end of thread, other threads:[~2026-11-25 11:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261125115014.4014507-1-usama.arif@linux.dev>
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 " Usama Arif

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox