linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/mm/64: Fix crash in remove_pagetable()
@ 2017-04-25  9:25 Kirill A. Shutemov
  2017-04-25 16:43 ` Dan Williams
  0 siblings, 1 reply; 4+ messages in thread
From: Kirill A. Shutemov @ 2017-04-25  9:25 UTC (permalink / raw)
  To: x86, Thomas Gleixner, Ingo Molnar, H. Peter Anvin
  Cc: Andi Kleen, Dave Hansen, Andy Lutomirski, Dan Williams, linux-mm,
	linux-kernel, Kirill A. Shutemov

remove_pagetable() does page walk using p*d_page_vaddr() plus cast.
It's not canonical approach -- we usually use p*d_offset() for that.

It works fine as long as all page table levels are present. We broke the
invariant by introducing folded p4d page table level.

As result, remove_pagetable() interprets PMD as PUD and it leads to
crash:

	BUG: unable to handle kernel paging request at ffff880300000000
	IP: memchr_inv+0x60/0x110
	PGD 317d067
	P4D 317d067
	PUD 3180067
	PMD 33f102067
	PTE 8000000300000060

Let's fix this by using p*d_offset() instead of p*d_page_vaddr() for
page walk.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reported-by: Dan Williams <dan.j.williams@intel.com>
Fixes: f2a6a7050109 ("x86: Convert the rest of the code to support p4d_t")
---
 arch/x86/mm/init_64.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index a242139df8fe..745e5e183169 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -962,7 +962,7 @@ remove_pud_table(pud_t *pud_start, unsigned long addr, unsigned long end,
 			continue;
 		}
 
-		pmd_base = (pmd_t *)pud_page_vaddr(*pud);
+		pmd_base = pmd_offset(pud, 0);
 		remove_pmd_table(pmd_base, addr, next, direct);
 		free_pmd_table(pmd_base, pud);
 	}
@@ -988,7 +988,7 @@ remove_p4d_table(p4d_t *p4d_start, unsigned long addr, unsigned long end,
 
 		BUILD_BUG_ON(p4d_large(*p4d));
 
-		pud_base = (pud_t *)p4d_page_vaddr(*p4d);
+		pud_base = pud_offset(p4d, 0);
 		remove_pud_table(pud_base, addr, next, direct);
 		free_pud_table(pud_base, p4d);
 	}
@@ -1013,7 +1013,7 @@ remove_pagetable(unsigned long start, unsigned long end, bool direct)
 		if (!pgd_present(*pgd))
 			continue;
 
-		p4d = (p4d_t *)pgd_page_vaddr(*pgd);
+		p4d = p4d_offset(pgd, 0);
 		remove_p4d_table(p4d, addr, next, direct);
 	}
 
-- 
2.11.0

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

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

* Re: [PATCH] x86/mm/64: Fix crash in remove_pagetable()
  2017-04-25  9:25 [PATCH] x86/mm/64: Fix crash in remove_pagetable() Kirill A. Shutemov
@ 2017-04-25 16:43 ` Dan Williams
  2017-04-25 18:53   ` Ingo Molnar
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Williams @ 2017-04-25 16:43 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: X86 ML, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Andi Kleen,
	Dave Hansen, Andy Lutomirski, Linux MM,
	linux-kernel@vger.kernel.org

On Tue, Apr 25, 2017 at 2:25 AM, Kirill A. Shutemov
<kirill.shutemov@linux.intel.com> wrote:
> remove_pagetable() does page walk using p*d_page_vaddr() plus cast.
> It's not canonical approach -- we usually use p*d_offset() for that.
>
> It works fine as long as all page table levels are present. We broke the
> invariant by introducing folded p4d page table level.
>
> As result, remove_pagetable() interprets PMD as PUD and it leads to
> crash:
>
>         BUG: unable to handle kernel paging request at ffff880300000000
>         IP: memchr_inv+0x60/0x110
>         PGD 317d067
>         P4D 317d067
>         PUD 3180067
>         PMD 33f102067
>         PTE 8000000300000060
>
> Let's fix this by using p*d_offset() instead of p*d_page_vaddr() for
> page walk.
>
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Reported-by: Dan Williams <dan.j.williams@intel.com>
> Fixes: f2a6a7050109 ("x86: Convert the rest of the code to support p4d_t")

Thanks! This patch on top of tip/master passes a full run of the
nvdimm regression suite.

Tested-by: Dan Williams <dan.j.williams@intel.com>

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

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

* Re: [PATCH] x86/mm/64: Fix crash in remove_pagetable()
  2017-04-25 16:43 ` Dan Williams
@ 2017-04-25 18:53   ` Ingo Molnar
  2017-04-25 19:01     ` Dan Williams
  0 siblings, 1 reply; 4+ messages in thread
From: Ingo Molnar @ 2017-04-25 18:53 UTC (permalink / raw)
  To: Dan Williams
  Cc: Kirill A. Shutemov, X86 ML, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, Andi Kleen, Dave Hansen, Andy Lutomirski,
	Linux MM, linux-kernel@vger.kernel.org


* Dan Williams <dan.j.williams@intel.com> wrote:

> On Tue, Apr 25, 2017 at 2:25 AM, Kirill A. Shutemov
> <kirill.shutemov@linux.intel.com> wrote:
> > remove_pagetable() does page walk using p*d_page_vaddr() plus cast.
> > It's not canonical approach -- we usually use p*d_offset() for that.
> >
> > It works fine as long as all page table levels are present. We broke the
> > invariant by introducing folded p4d page table level.
> >
> > As result, remove_pagetable() interprets PMD as PUD and it leads to
> > crash:
> >
> >         BUG: unable to handle kernel paging request at ffff880300000000
> >         IP: memchr_inv+0x60/0x110
> >         PGD 317d067
> >         P4D 317d067
> >         PUD 3180067
> >         PMD 33f102067
> >         PTE 8000000300000060
> >
> > Let's fix this by using p*d_offset() instead of p*d_page_vaddr() for
> > page walk.
> >
> > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > Reported-by: Dan Williams <dan.j.williams@intel.com>
> > Fixes: f2a6a7050109 ("x86: Convert the rest of the code to support p4d_t")
> 
> Thanks! This patch on top of tip/master passes a full run of the
> nvdimm regression suite.
> 
> Tested-by: Dan Williams <dan.j.williams@intel.com>

Does a re-application of:

  "x86/mm/gup: Switch GUP to the generic get_user_page_fast() implementation"

still work (which you can achive via 'git revert 6dd29b3df975'), or is that 
another breakage?

Thanks,

	Ingo

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

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

* Re: [PATCH] x86/mm/64: Fix crash in remove_pagetable()
  2017-04-25 18:53   ` Ingo Molnar
@ 2017-04-25 19:01     ` Dan Williams
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Williams @ 2017-04-25 19:01 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Kirill A. Shutemov, X86 ML, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, Andi Kleen, Dave Hansen, Andy Lutomirski,
	Linux MM, linux-kernel@vger.kernel.org

On Tue, Apr 25, 2017 at 11:53 AM, Ingo Molnar <mingo@kernel.org> wrote:
>
> * Dan Williams <dan.j.williams@intel.com> wrote:
>
>> On Tue, Apr 25, 2017 at 2:25 AM, Kirill A. Shutemov
>> <kirill.shutemov@linux.intel.com> wrote:
>> > remove_pagetable() does page walk using p*d_page_vaddr() plus cast.
>> > It's not canonical approach -- we usually use p*d_offset() for that.
>> >
>> > It works fine as long as all page table levels are present. We broke the
>> > invariant by introducing folded p4d page table level.
>> >
>> > As result, remove_pagetable() interprets PMD as PUD and it leads to
>> > crash:
>> >
>> >         BUG: unable to handle kernel paging request at ffff880300000000
>> >         IP: memchr_inv+0x60/0x110
>> >         PGD 317d067
>> >         P4D 317d067
>> >         PUD 3180067
>> >         PMD 33f102067
>> >         PTE 8000000300000060
>> >
>> > Let's fix this by using p*d_offset() instead of p*d_page_vaddr() for
>> > page walk.
>> >
>> > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
>> > Reported-by: Dan Williams <dan.j.williams@intel.com>
>> > Fixes: f2a6a7050109 ("x86: Convert the rest of the code to support p4d_t")
>>
>> Thanks! This patch on top of tip/master passes a full run of the
>> nvdimm regression suite.
>>
>> Tested-by: Dan Williams <dan.j.williams@intel.com>
>
> Does a re-application of:
>
>   "x86/mm/gup: Switch GUP to the generic get_user_page_fast() implementation"
>
> still work (which you can achive via 'git revert 6dd29b3df975'), or is that
> another breakage?

That's another breakage. We're discussing how to resolve it in this thread:

    http://www.spinics.net/lists/linux-mm/msg126056.html

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

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

end of thread, other threads:[~2017-04-25 19:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-25  9:25 [PATCH] x86/mm/64: Fix crash in remove_pagetable() Kirill A. Shutemov
2017-04-25 16:43 ` Dan Williams
2017-04-25 18:53   ` Ingo Molnar
2017-04-25 19:01     ` Dan Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).