pageattr fixes for pmd/pte_present
Subsystems (3)
PATCH 1/2 Revert "x86, mm: Make spurious_fault check explicitly check the PRESENT bit"
In reply to Andrea ArcangeliThis reverts commit 660a293ea9be709b893d371fbc0328fcca33c33a.
--- arch/x86/mm/fault.c | 8 +------- 1 files changed, 1 insertions(+), 7 deletions(-)
arch/x86/mm/fault.c +1 -7
@@ -944,14 +944,8 @@ spurious_fault(unsigned long error_code, unsigned long address)if (pmd_large (*pmd))return spurious_fault_check (error_code, (pte_t *) pmd); -/* -* Note: don't use pte_present() here, since it returns true -* if the _PAGE_PROTNONE bit is set. However, this aliases the -* _PAGE_GLOBAL bit, which for kernel pages give false positives -* when CONFIG_DEBUG_PAGEALLOC is used. -*/ pte =pte_offset_kernel (pmd, address); -if (!(pte_flags (*pte) & _PAGE_PRESENT)) +if (!pte_present (*pte))return 0 ; ret =spurious_fault_check (error_code, pte);
--
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>
Re: [PATCH 1/2] Revert "x86, mm: Make spurious_fault check explicitly check the PRESENT bit"
Quoted 3 lines · Andrea Arcangeli
This reverts commit
660a293ea9be709b893d371fbc0328fcca33c33a.Signed-off-by Andrea Arcangeli <[email protected]>
Motivation/details?
-hpa
--
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>
Re: [PATCH 1/2] Revert "x86, mm: Make spurious_fault check explicitly check the PRESENT bit"
Quoted 6 lines · H. Peter Anvin
Quoted 3 lines · Andrea Arcangeli
This reverts commit
660a293ea9be709b893d371fbc0328fcca33c33a.Signed-off-by Andrea Arcangeli <[email protected]>Motivation/details?
It's all in 0/2 and 2/2. This one arrived first for whatever reason.
--
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>
cover pageattr fixes for pmd/pte_present
Hi,
I got a report for a minor regression introduced by commit 027ef6c87853b0a9df53175063028edb4950d476.
So the problem is, pageattr creates kernel pagetables (pte and pmds) that breaks pte_present/pmd_present and the patch above exposed this invariant breakage for pmd_present.
The same problem already existed for the pte and pte_present and it was fixed by commit 660a293ea9be709b893d371fbc0328fcca33c33a (if it wasn't for that commit, it wouldn't even be a regression). That fix avoids the pagefault to use pte_present. I could follow through by stopping using pmd_present/pmd_huge too.
However I think it's more robust to fix pageattr and to clear the PSE/GLOBAL bitflags too in addition to the present bitflag. So the kernel page fault can keep using the regular pte_present/pmd_present/pmd_huge.
The confusion arises because _PAGE_GLOBAL and _PAGE_PROTNONE are sharing the same bit, and in the pmd case we pretend _PAGE_PSE to be set only in present pmds (to facilitate split_huge_page final tlb flush).
Andrea Arcangeli (2):
Revert "x86, mm: Make spurious_fault check explicitly check the
PRESENT bit"
pageattr: prevent PSE and GLOABL leftovers to confuse pmd/pte_present
and pmd_huge
arch/x86/mm/fault.c | 8 +------ arch/x86/mm/pageattr.c | 50 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 10 deletions(-)
--
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>
PATCH 2/2 pageattr: prevent PSE and GLOABL leftovers to confuse pmd/pte_present and pmd_huge
Without this patch any kernel code that reads kernel memory in non present kernel pte/pmds (as set by pageattr.c) will crash.
With this kernel code:
static struct page *crash_page;
static unsigned long *crash_address;
[..]
crash_page = alloc_pages(GFP_KERNEL, 9);
crash_address = page_address(crash_page);
if (set_memory_np((unsigned long)crash_address, 1))
printk("set_memory_np failure\n");[..]
The kernel will crash if inside the "crash tool" one would try to read the memory at the not present address.
crash> p crash_addresscrash_address = $8 = (long unsigned int *) 0xffff88023c000000 crash> rd 0xffff88023c000000
[ *lockup* ]
The lockup happens because _PAGE_GLOBAL and _PAGE_PROTNONE shares the same bit, and pageattr leaves _PAGE_GLOBAL set on a kernel pte which is then mistaken as _PAGE_PROTNONE (so pte_present returns true by mistake and the kernel fault then gets confused and loops).
With THP the same can happen after we taught pmd_present to check _PAGE_PROTNONE and _PAGE_PSE in commit 027ef6c87853b0a9df53175063028edb4950d476. THP has the same problem with _PAGE_GLOBAL as the 4k pages, but it also has a problem with _PAGE_PSE, which must be cleared too.
After the patch is applied copy_user correctly returns -EFAULT and doesn't lockup anymore.
crash> p crash_addresscrash_address = $9 = (long unsigned int *) 0xffff88023c000000 crash> rd 0xffff88023c000000
rd: read error: kernel virtual address: ffff88023c000000 type: "64-bit KVADDR"
--- arch/x86/mm/pageattr.c | 50 +++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 47 insertions(+), 3 deletions(-)
arch/x86/mm/pageattr.c +47 -3
@@ -445,6 +445,19 @@ try_preserve_large_page(pte_t *kpte, unsigned long address,pgprot_val (req_prot) |=pgprot_val (cpa->mask_set);/* +* Set the PSE and GLOBAL flags only if the PRESENT flag is +* set otherwise pmd_present/pmd_huge will return true even on +* a non present pmd. The canon_pgprot will clear _PAGE_GLOBAL +* for the ancient hardware that doesn't support it. +*/ +if (pgprot_val (new_prot) & _PAGE_PRESENT) +pgprot_val (new_prot) |= _PAGE_PSE | _PAGE_GLOBAL; +else +pgprot_val (new_prot) &= ~(_PAGE_PSE | _PAGE_GLOBAL); + + new_prot =canon_pgprot (new_prot); + +/* * old_pte points to the large page base address. So we need * to add the offset of the virtual address: */
@@ -489,7 +502,7 @@ try_preserve_large_page(pte_t *kpte, unsigned long address,* The address is aligned and the number of pages * covers the full page. */ - new_pte =pfn_pte (pte_pfn (old_pte),canon_pgprot (new_prot)); + new_pte =pfn_pte (pte_pfn (old_pte), new_prot);__set_pmd_pte (kpte, address, new_pte); cpa->flags |=CPA_FLUSHTLB ; do_split =0 ;
@@ -540,16 +553,35 @@ static int split_large_page(pte_t *kpte, unsigned long address)#ifdef CONFIG_X86_64 if (level ==PG_LEVEL_1G ) { pfninc =PMD_PAGE_SIZE >>PAGE_SHIFT ; -pgprot_val (ref_prot) |= _PAGE_PSE; +/* +* Set the PSE flags only if the PRESENT flag is set +* otherwise pmd_present/pmd_huge will return true +* even on a non present pmd. +*/ +if (pgprot_val (ref_prot) & _PAGE_PRESENT) +pgprot_val (ref_prot) |= _PAGE_PSE; +else +pgprot_val (ref_prot) &= ~_PAGE_PSE; }#endif /* +* Set the GLOBAL flags only if the PRESENT flag is set +* otherwise pmd/pte_present will return true even on a non +* present pmd/pte. The canon_pgprot will clear _PAGE_GLOBAL +* for the ancient hardware that doesn't support it. +*/ +if (pgprot_val (ref_prot) & _PAGE_PRESENT) +pgprot_val (ref_prot) |= _PAGE_GLOBAL; +else +pgprot_val (ref_prot) &= ~_PAGE_GLOBAL; + +/* * Get the target pfn from the original entry: */ pfn =pte_pfn (*kpte);for (i =0 ; i <PTRS_PER_PTE ; i++, pfn += pfninc) -set_pte (&pbase[i],pfn_pte (pfn, ref_prot)); +set_pte (&pbase[i],pfn_pte (pfn,canon_pgprot (ref_prot)));if (address >= (unsigned long )__va (0 ) && address < (unsigned long )__va (max_low_pfn_mapped <<PAGE_SHIFT ))
@@ -660,6 +692,18 @@ repeat: new_prot =static_protections (new_prot, address, pfn);/* +* Set the GLOBAL flags only if the PRESENT flag is +* set otherwise pte_present will return true even on +* a non present pte. The canon_pgprot will clear +* _PAGE_GLOBAL for the ancient hardware that doesn't +* support it. +*/ +if (pgprot_val (new_prot) & _PAGE_PRESENT) +pgprot_val (new_prot) |= _PAGE_GLOBAL; +else +pgprot_val (new_prot) &= ~_PAGE_GLOBAL; + +/* * We need to keep the pfn from the existing PTE, * after all we're only going to change it's attributes * not the memory it points to
--
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>
What's the status of these two patches?
Quoted 35 lines · Andrea Arcangeli
Hi,
I got a report for a minor regression introduced by commit
027ef6c87853b0a9df53175063028edb4950d476.So the problem is, pageattr creates kernel pagetables (pte and pmds) that breaks pte_present/pmd_present and the patch above exposed this invariant breakage for
pmd_present.The same problem already existed for the pte and
pte_presentand it was fixed by commit660a293ea9be709b893d371fbc0328fcca33c33a(if it wasn't for that commit, it wouldn't even be a regression). That fix avoids the pagefault to usepte_present. I could follow through by stopping using pmd_present/pmd_huge too.However I think it's more robust to fix pageattr and to clear the PSE/GLOBAL bitflags too in addition to the present bitflag. So the kernel page fault can keep using the regular pte_present/pmd_present/pmd_huge.
The confusion arises because
_PAGE_GLOBALand_PAGE_PROTNONEare sharing the same bit, and in the pmd case we pretend_PAGE_PSEto be set only in present pmds (to facilitatesplit_huge_pagefinal tlb flush).Andrea Arcangeli (2):
Revert "x86, mm: Makespurious_faultcheck explicitly check the
PRESENT bit"
pageattr: prevent PSE and GLOABL leftovers to confuse pmd/pte_present
andpmd_hugearch/x86/mm/fault.c | 8 +------ arch/x86/mm/pageattr.c | 50 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 10 deletions(-)
Quoted 5 lines
--
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>
--
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>
Andrew Morton
maintainerQuoted 1 line · On Sat, 05 Jan 2013 20:59:57 -0600 Simon Jeons <[email protected]> wrote:
(top-posting repaired)
top-posting makes it really hard to reply to your email in a useful fashion. So if you want a reply, please don't top-post!
Quoted 21 lines · Andrea Arcangeli
Quoted 20 lines
Hi,
I got a report for a minor regression introduced by commit
027ef6c87853b0a9df53175063028edb4950d476.So the problem is, pageattr creates kernel pagetables (pte and pmds) that breaks pte_present/pmd_present and the patch above exposed this invariant breakage for
pmd_present.The same problem already existed for the pte and
pte_presentand it was fixed by commit660a293ea9be709b893d371fbc0328fcca33c33a(if it wasn't for that commit, it wouldn't even be a regression). That fix avoids the pagefault to usepte_present. I could follow through by stopping using pmd_present/pmd_huge too.However I think it's more robust to fix pageattr and to clear the PSE/GLOBAL bitflags too in addition to the present bitflag. So the kernel page fault can keep using the regular pte_present/pmd_present/pmd_huge.
Quoted 7 lines
Quoted 5 lines
The confusion arises because
_PAGE_GLOBALand_PAGE_PROTNONEare sharing the same bit, and in the pmd case we pretend_PAGE_PSEto be set only in present pmds (to facilitatesplit_huge_pagefinal tlb flush).What's the status of these two patches?
I expect they fell through the christmas cracks. I added them to my (getting large) queue of x86 patches for consideration by the x86 maintainers.
Why do you ask? It seems the bug is a pretty minor one and that we need only fix it in 3.8 or even 3.9. Is that supposition incorrect?
--
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>
Quoted 6 lines · Andrew Morton
Quoted 2 lines
What's the status of these two patches?
I expect they fell through the christmas cracks. I added them to my (getting large) queue of x86 patches for consideration by the x86 maintainers.
Yes, I'm just coming back online today, and needless to say, I have a *huge* backlog.
Quoted 2 lines
Why do you ask? It seems the bug is a pretty minor one and that we need only fix it in 3.8 or even 3.9. Is that supposition incorrect?
I would like to know this as well.
-hpa
--
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>
Hi,
Quoted 8 lines · H. Peter Anvin
Quoted 6 lines · Andrew Morton
Quoted 2 lines
What's the status of these two patches?
I expect they fell through the christmas cracks. I added them to my (getting large) queue of x86 patches for consideration by the x86 maintainers.
Quoted 7 lines
Yes, I'm just coming back online today, and needless to say, I have a *huge* backlog.
Quoted 2 lines
Why do you ask? It seems the bug is a pretty minor one and that we need only fix it in 3.8 or even 3.9. Is that supposition incorrect?
I would like to know this as well.
It is a minor regression that was reported. The only way to notice it should be to use the crash tool or other non standard root stuff. So it shouldn't be too urgent.
Thanks,
Andrea
--
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>
Quoted 20 lines · Andrea Arcangeli
Hi,
I got a report for a minor regression introduced by commit
027ef6c87853b0a9df53175063028edb4950d476.So the problem is, pageattr creates kernel pagetables (pte and pmds) that breaks pte_present/pmd_present and the patch above exposed this invariant breakage for
pmd_present.The same problem already existed for the pte and
pte_presentand it was fixed by commit660a293ea9be709b893d371fbc0328fcca33c33a(if it wasn't for that commit, it wouldn't even be a regression). That fix avoids the pagefault to usepte_present. I could follow through by stopping using pmd_present/pmd_huge too.However I think it's more robust to fix pageattr and to clear the PSE/GLOBAL bitflags too in addition to the present bitflag. So the kernel page fault can keep using the regular pte_present/pmd_present/pmd_huge.
Quoted 4 lines
The confusion arises because
_PAGE_GLOBALand_PAGE_PROTNONEare sharing the same bit, and in the pmd case we pretend_PAGE_PSEto be set only in present pmds (to facilitatesplit_huge_pagefinal tlb flush).
Hi all,
One offline question.
Why free pages should map to kernel virtual address in function isolate_freepages? If you said that those pages are about to be used as migration targets, it's splitting a free page but those pages are about to be used for copying data to, then why kernel need to access these pages? These target pages are isolated buddy pages and they will be the migration targets of normal processes' pages, why kernel need to access them?
Quoted 11 lines
Andrea Arcangeli (2):
Revert "x86, mm: Makespurious_faultcheck explicitly check the
PRESENT bit"
pageattr: prevent PSE and GLOABL leftovers to confuse pmd/pte_present
andpmd_hugearch/x86/mm/fault.c | 8 +------ arch/x86/mm/pageattr.c | 50 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 10 deletions(-)
Quoted 5 lines
--
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>
--
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>
Re: [PATCH 2/2] pageattr: prevent PSE and GLOABL leftovers to confuse pmd/pte_present and pmd_huge
In reply to Andrea Arcangeliarch/x86/mm/pageattr.c try_preserve_large_page(pte_t *kpte, unsigned long address,
Quoted 51 lines · Andrea Arcangeli
Without this patch any kernel code that reads kernel memory in non present kernel pte/pmds (as set by
pageattr.c) will crash.With this kernel code:
static struct page
*crash_page;
static unsigned long*crash_address;
[..]crash_page = alloc_pages(GFP_KERNEL, 9); crash_address = page_address(crash_page); if (set_memory_np((unsigned long)crash_address, 1)) printk("set_memory_np failure\n");[..]
The kernel will crash if inside the "crash tool" one would try to read the memory at the not present address.
crash> p
crash_addresscrash_address= $8 = (long unsigned int *)0xffff88023c000000crash> rd0xffff88023c000000
[ *lockup* ]The lockup happens because
_PAGE_GLOBALand_PAGE_PROTNONEshares the same bit, and pageattr leaves_PAGE_GLOBALset on a kernel pte which is then mistaken as_PAGE_PROTNONE(sopte_presentreturns true by mistake and the kernel fault then gets confused and loops).With THP the same can happen after we taught
pmd_presentto check_PAGE_PROTNONEand_PAGE_PSEin commit027ef6c87853b0a9df53175063028edb4950d476. THP has the same problem with_PAGE_GLOBALas the 4k pages, but it also has a problem with_PAGE_PSE, which must be cleared too.After the patch is applied
copy_usercorrectly returns-EFAULTand doesn't lockup anymore.crash> p
crash_addresscrash_address= $9 = (long unsigned int *)0xffff88023c000000crash> rd0xffff88023c000000
rd: read error: kernel virtual address:ffff88023c000000type: "64-bit KVADDR"Signed-off-by Andrea Arcangeli <[email protected]>--- arch/x86/mm/pageattr.c | 50 +++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 47 insertions(+), 3 deletions(-)arch/x86/mm/pageattr.c +0
-0@@ -445,6 +445,19 @@ try_preserve_large_page(pte_t *kpte, unsigned long address,
Hi Andrea,
Since function kernel_physical_mapping_init has already setup identity mapping of pgd/pmd/pte, why need preserve large page here?
cat /proc/meminfo
Quoted 2 lines
DirectMap4k: 12280 kB DirectMap2M: 894976 kB
Why DirectMap2M is not equal to DirectMap4k?
It seems that DirectMap2M should consist of DirectMap4K.
Quoted 87 lines
arch/x86/mm/pageattr.c +47
-4pgprot_val (req_prot) |=pgprot_val (cpa->mask_set);/* +* Set the PSE and GLOBAL flags only if the PRESENT flag is +* set otherwise pmd_present/pmd_huge will return true even on +* a non present pmd. The canon_pgprot will clear _PAGE_GLOBAL +* for the ancient hardware that doesn't support it. +*/ +if (pgprot_val (new_prot) & _PAGE_PRESENT) +pgprot_val (new_prot) |= _PAGE_PSE | _PAGE_GLOBAL; +else +pgprot_val (new_prot) &= ~(_PAGE_PSE | _PAGE_GLOBAL); + + new_prot =canon_pgprot (new_prot); + +/* * old_pte points to the large page base address. So we need * to add the offset of the virtual address: */ @@ -489,7 +502,7 @@ try_preserve_large_page(pte_t *kpte, unsigned long address,* The address is aligned and the number of pages * covers the full page. */ - new_pte =pfn_pte (pte_pfn (old_pte),canon_pgprot (new_prot)); + new_pte =pfn_pte (pte_pfn (old_pte), new_prot);__set_pmd_pte (kpte, address, new_pte); cpa->flags |=CPA_FLUSHTLB ; do_split =0 ;@@ -540,16 +553,35 @@ static int split_large_page(pte_t *kpte, unsigned long address)#ifdef CONFIG_X86_64 if (level ==PG_LEVEL_1G ) { pfninc =PMD_PAGE_SIZE >>PAGE_SHIFT ; -pgprot_val (ref_prot) |= _PAGE_PSE; +/* +* Set the PSE flags only if the PRESENT flag is set +* otherwise pmd_present/pmd_huge will return true +* even on a non present pmd. +*/ +if (pgprot_val (ref_prot) & _PAGE_PRESENT) +pgprot_val (ref_prot) |= _PAGE_PSE; +else +pgprot_val (ref_prot) &= ~_PAGE_PSE; }#endif /* +* Set the GLOBAL flags only if the PRESENT flag is set +* otherwise pmd/pte_present will return true even on a non +* present pmd/pte. The canon_pgprot will clear _PAGE_GLOBAL +* for the ancient hardware that doesn't support it. +*/ +if (pgprot_val (ref_prot) & _PAGE_PRESENT) +pgprot_val (ref_prot) |= _PAGE_GLOBAL; +else +pgprot_val (ref_prot) &= ~_PAGE_GLOBAL; + +/* * Get the target pfn from the original entry: */ pfn =pte_pfn (*kpte);for (i =0 ; i <PTRS_PER_PTE ; i++, pfn += pfninc) -set_pte (&pbase[i],pfn_pte (pfn, ref_prot)); +set_pte (&pbase[i],pfn_pte (pfn,canon_pgprot (ref_prot)));if (address >= (unsigned long )__va (0 ) && address < (unsigned long )__va (max_low_pfn_mapped <<PAGE_SHIFT ))@@ -660,6 +692,18 @@ repeat: new_prot =static_protections (new_prot, address, pfn);/* +* Set the GLOBAL flags only if the PRESENT flag is +* set otherwise pte_present will return true even on +* a non present pte. The canon_pgprot will clear +* _PAGE_GLOBAL for the ancient hardware that doesn't +* support it. +*/ +if (pgprot_val (new_prot) & _PAGE_PRESENT) +pgprot_val (new_prot) |= _PAGE_GLOBAL; +else +pgprot_val (new_prot) &= ~_PAGE_GLOBAL; + +/* * We need to keep the pfn from the existing PTE, * after all we're only going to change it's attributes * not the memory it points to --
Quoted 4 lines
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>
--
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>