diff mbox

[v5,12/17] mm: Add pt_mm to struct page

Message ID 20180504183318.14415-13-willy@infradead.org (mailing list archive)
State New, archived
Headers show

Commit Message

Matthew Wilcox May 4, 2018, 6:33 p.m. UTC
From: Matthew Wilcox <mawilcox@microsoft.com>

x86 overloads the page->index field to store a pointer to the mm_struct.
Rename this to pt_mm so it's visible to other users.

Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
---
 arch/x86/mm/pgtable.c    | 5 ++---
 include/linux/mm_types.h | 2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)

Comments

Vlastimil Babka May 15, 2018, 9:27 a.m. UTC | #1
On 05/04/2018 08:33 PM, Matthew Wilcox wrote:
> From: Matthew Wilcox <mawilcox@microsoft.com>
> 
> x86 overloads the page->index field to store a pointer to the mm_struct.

Maybe start the sentence with "For page table pages, ..." or "For pgd
page table pages, ..." ?

> Rename this to pt_mm so it's visible to other users.
> 
> Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>

Also a suggestion below, otherwise:

Acked-by: Vlastimil Babka <vbabka@suse.cz>

>  static void pgd_ctor(struct mm_struct *mm, pgd_t *pgd)
> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> index 90a6dbeeef11..5a519279dcd5 100644
> --- a/include/linux/mm_types.h
> +++ b/include/linux/mm_types.h
> @@ -139,7 +139,7 @@ struct page {
>  			unsigned long _pt_pad_1;	/* compound_head */
>  			pgtable_t pmd_huge_pte; /* protected by page->ptl */
>  			unsigned long _pt_pad_2;	/* mapping */
> -			unsigned long _pt_pad_3;
> +			struct mm_struct *pt_mm;

Add comment that it's x86-only so somebody doesn't try to write a
generic code expecting it?

>  #if ALLOC_SPLIT_PTLOCKS
>  			spinlock_t *ptl;
>  #else
>
Matthew Wilcox May 15, 2018, 12:23 p.m. UTC | #2
On Tue, May 15, 2018 at 11:27:25AM +0200, Vlastimil Babka wrote:
> On 05/04/2018 08:33 PM, Matthew Wilcox wrote:
> > From: Matthew Wilcox <mawilcox@microsoft.com>
> > 
> > x86 overloads the page->index field to store a pointer to the mm_struct.
> 
> Maybe start the sentence with "For page table pages, ..." or "For pgd
> page table pages, ..." ?

Thanks, done.

> > -			unsigned long _pt_pad_3;
> > +			struct mm_struct *pt_mm;
> 
> Add comment that it's x86-only so somebody doesn't try to write a
> generic code expecting it?

Done.

My plan is to actually make this true for all page table pages so that
we can always track a page table back to its owner, but that's not part
of this patch set, and we can remove the comment when that changes.

That's part of the generic infrastructure we need to be able to survive
an uncorrectable error in a process's page table.
diff mbox

Patch

diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index ffc8c13c50e4..938dbcd46b97 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -114,13 +114,12 @@  static inline void pgd_list_del(pgd_t *pgd)
 
 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
 {
-	BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
-	virt_to_page(pgd)->index = (pgoff_t)mm;
+	virt_to_page(pgd)->pt_mm = mm;
 }
 
 struct mm_struct *pgd_page_get_mm(struct page *page)
 {
-	return (struct mm_struct *)page->index;
+	return page->pt_mm;
 }
 
 static void pgd_ctor(struct mm_struct *mm, pgd_t *pgd)
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 90a6dbeeef11..5a519279dcd5 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -139,7 +139,7 @@  struct page {
 			unsigned long _pt_pad_1;	/* compound_head */
 			pgtable_t pmd_huge_pte; /* protected by page->ptl */
 			unsigned long _pt_pad_2;	/* mapping */
-			unsigned long _pt_pad_3;
+			struct mm_struct *pt_mm;
 #if ALLOC_SPLIT_PTLOCKS
 			spinlock_t *ptl;
 #else