Skip to contentSkip to conversation

mm, pagemap: Fix soft dirty marking for PMD migration entry

PATCH Applied Huang, Ying 4 participants 6 messages Oct 17, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm, pagemap: Fix soft dirty marking for PMD migration entry

From: Huang Ying <[email protected]>

Now, when the page table is walked in the implementation of /proc/<pid>/pagemap, pmd_soft_dirty() is used for both the PMD huge page map and the PMD migration entries. That is wrong, pmd_swp_soft_dirty() should be used for the PMD migration entries instead because the different page table entry flag is used.

Cc Michal Hocko <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc David Rientjes <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc "JA(C)rA'me Glisse" <[email protected]>
Cc Daniel Colascione <[email protected]>
Cc Zi Yan <[email protected]>
Cc Naoya Horiguchi <[email protected]>
---
 fs/proc/task_mmu.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/proc/task_mmu.c +5 -1
index 2593a0c609d7..01aad772f8db 100644
@@ -1311,13 +1311,15 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end,
 		pmd_t pmd = *pmdp;
 		struct page *page = NULL;
 
-		if ((vma->vm_flags & VM_SOFTDIRTY) || pmd_soft_dirty(pmd))
+		if (vma->vm_flags & VM_SOFTDIRTY)
 			flags |= PM_SOFT_DIRTY;
 
 		if (pmd_present(pmd)) {
 			page = pmd_page(pmd);
 
 			flags |= PM_PRESENT;
+			if (pmd_soft_dirty(pmd))
+				flags |= PM_SOFT_DIRTY;
 			if (pm->show_pfn)
 				frame = pmd_pfn(pmd) +
 					((addr & ~PMD_MASK) >> PAGE_SHIFT);
@@ -1329,6 +1331,8 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end,
 			frame = swp_type(entry) |
 				(swp_offset(entry) << MAX_SWAPFILES_SHIFT);
 			flags |= PM_SWAP;
+			if (pmd_swp_soft_dirty(pmd))
+				flags |= PM_SOFT_DIRTY;
 			VM_BUG_ON(!is_pmd_migration_entry(pmd));
 			page = migration_entry_to_page(entry);
 		}
Signature · 7 lines
2.14.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 7 lines · Ying

From: Huang Ying <[email protected]>

Now, when the page table is walked in the implementation of /proc/<pid>/pagemap, pmd_soft_dirty() is used for both the PMD huge page map and the PMD migration entries. That is wrong, pmd_swp_soft_dirty() should be used for the PMD migration entries instead because the different page table entry flag is used.

Yeah, different flags can be used on various archs to represent mapped a PMD and a migration PMD entry. Sounds good.

Quoted 37 lines
Cc Michal Hocko <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc David Rientjes <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc "JA(C)rA'me Glisse" <[email protected]>
Cc Daniel Colascione <[email protected]>
Cc Zi Yan <[email protected]>
Cc Naoya Horiguchi <[email protected]>
---
 fs/proc/task_mmu.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/proc/task_mmu.c +3 -1
index 2593a0c609d7..01aad772f8db 100644
@@ -1311,13 +1311,15 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end,
 		pmd_t pmd = *pmdp;
 		struct page *page = NULL;
 
-		if ((vma->vm_flags & VM_SOFTDIRTY) || pmd_soft_dirty(pmd))
+		if (vma->vm_flags & VM_SOFTDIRTY)
 			flags |= PM_SOFT_DIRTY;
 
 		if (pmd_present(pmd)) {
 			page = pmd_page(pmd);
 
 			flags |= PM_PRESENT;
+			if (pmd_soft_dirty(pmd))
+				flags |= PM_SOFT_DIRTY;
 			if (pm->show_pfn)
 				frame = pmd_pfn(pmd) +
 					((addr & ~PMD_MASK) >> PAGE_SHIFT);

fs/proc/task_mmu.c static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, · line 1335

Quoted 5 lines
fs/proc/task_mmu.c +2 -0
@@ -1329,6 +1331,8 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end,
 			frame = swp_type(entry) |
 				(swp_offset(entry) << MAX_SWAPFILES_SHIFT);
 			flags |= PM_SWAP;
+			if (pmd_swp_soft_dirty(pmd))
+				flags |= PM_SOFT_DIRTY;

Though I was initially skeptical about whether this will compile on POWER because of lack of a pmd_swp_soft_dirty() definition but it turns out we have a generic one to fallback on as we dont define ARCH_ENABLE_THP_MIGRATION yet.

#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
#ifndef CONFIG_ARCH_ENABLE_THP_MIGRATION static inline pmd_t pmd_swp_mksoft_dirty(pmd_t pmd)

{
	return pmd;
}

static inline int pmd_swp_soft_dirty(pmd_t pmd)

{
	return 0;
}

static inline pmd_t pmd_swp_clear_soft_dirty(pmd_t pmd)

{
	return pmd;
}

#endif

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Acked-by on v1 1/1
#2 lore raw
In reply to Huang, Ying
Quoted 8 lines · Ying

From: Huang Ying <[email protected]>

Now, when the page table is walked in the implementation of /proc/<pid>/pagemap, pmd_soft_dirty() is used for both the PMD huge page map and the PMD migration entries. That is wrong, pmd_swp_soft_dirty() should be used for the PMD migration entries instead because the different page table entry flag is used.

Quoted 10 lines
Cc Michal Hocko <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc David Rientjes <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc "Jerome Glisse" <[email protected]>
Cc Daniel Colascione <[email protected]>
Cc Zi Yan <[email protected]>
Cc Naoya Horiguchi <[email protected]>

What is effect of the misbehaviour? pagemap reports garbage?

Shoudn't it be in stable@? And maybe add Fixes: <sha1>.

Otherwise, looks good to me.

Signature · 7 lines
 Kirill A. Shutemov

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw
Quoted 20 lines · Kirill A. Shutemov
Quoted 8 lines · Ying

From: Huang Ying <[email protected]>

Now, when the page table is walked in the implementation of /proc/<pid>/pagemap, pmd_soft_dirty() is used for both the PMD huge page map and the PMD migration entries. That is wrong, pmd_swp_soft_dirty() should be used for the PMD migration entries instead because the different page table entry flag is used.

Quoted 10 lines
Cc Michal Hocko <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc David Rientjes <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc "J.r.me Glisse" <[email protected]>
Cc Daniel Colascione <[email protected]>
Cc Zi Yan <[email protected]>
Cc Naoya Horiguchi <[email protected]>
Quoted 1 line

What is effect of the misbehaviour? pagemap reports garbage?

Yes. pagemap may report incorrect soft dirty information for PMD migration entries.

Quoted 1 line

Shoudn't it be in stable@? And maybe add Fixes: <sha1>.

Yes. Will do that in the next version.

Quoted 3 lines

Otherwise, looks good to me.

Thanks!

Best Regards,
Huang, Ying

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 21 lines · Ying
Quoted 19 lines · Kirill A. Shutemov
Quoted 18 lines · Ying

From: Huang Ying <[email protected]>

Now, when the page table is walked in the implementation of /proc/<pid>/pagemap, pmd_soft_dirty() is used for both the PMD huge page map and the PMD migration entries. That is wrong, pmd_swp_soft_dirty() should be used for the PMD migration entries instead because the different page table entry flag is used.

Cc Michal Hocko <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc David Rientjes <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc "J.r.me Glisse" <[email protected]>
Cc Daniel Colascione <[email protected]>
Cc Zi Yan <[email protected]>
Cc Naoya Horiguchi <[email protected]>
Quoted 4 lines
Quoted 1 line

What is effect of the misbehaviour? pagemap reports garbage?

Yes. pagemap may report incorrect soft dirty information for PMD migration entries.

Thanks for fixing it.

Quoted 4 lines
Quoted 2 lines

Shoudn't it be in stable@? And maybe add Fixes: <sha1>.

Yes. Will do that in the next version.

PMD migration is merged in 4.14, which is not final yet. Do we need to split the patch, so that first hunk(for present PMD entries) goes into stable and second hunk(for PMD migration entries) goes into 4.14?

Signature · 2 lines
Best Regards,
Yan Zi
#5 lore raw
Quoted 30 lines · Zi Yan
Quoted 21 lines · Ying
Quoted 19 lines · Kirill A. Shutemov
Quoted 18 lines · Ying

From: Huang Ying <[email protected]>

Now, when the page table is walked in the implementation of /proc/<pid>/pagemap, pmd_soft_dirty() is used for both the PMD huge page map and the PMD migration entries. That is wrong, pmd_swp_soft_dirty() should be used for the PMD migration entries instead because the different page table entry flag is used.

Cc Michal Hocko <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc David Rientjes <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc "J.r.me Glisse" <[email protected]>
Cc Daniel Colascione <[email protected]>
Cc Zi Yan <[email protected]>
Cc Naoya Horiguchi <[email protected]>
Quoted 4 lines
Quoted 1 line

What is effect of the misbehaviour? pagemap reports garbage?

Yes. pagemap may report incorrect soft dirty information for PMD migration entries.

Thanks for fixing it.

Quoted 1 line
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Shoudn't it be in stable@? And maybe add Fixes: <sha1>.

Yes. Will do that in the next version.

PMD migration is merged in 4.14, which is not final yet. Do we need to split the patch, so that first hunk(for present PMD entries) goes into stable and second hunk(for PMD migration entries) goes into 4.14?

Oh, if so, I think we don't need to back port it to stable kernel. But we still need Fixes: tag.

Best Regards,
Huang, Ying

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>