From: Nicolai Stange <nicstange@gmail.com>
To: Dan Williams <dan.j.williams@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, Nicolai Stange <nicstange@gmail.com>
Subject: [RFC 2/3] sparse-vmemmap: make vmemmap_populate_basepages() skip HP mapped ranges
Date: Wed, 15 Feb 2017 21:58:25 +0100 [thread overview]
Message-ID: <20170215205826.13356-3-nicstange@gmail.com> (raw)
In-Reply-To: <20170215205826.13356-1-nicstange@gmail.com>
WARNING: this will break at least arm64 due to the lack of a pmd_large()!!!
While x86' vmemmap_populate_hugepages() checks whether the range to
populate has already been covered in part by conventional pages and falls
back to vmemmap_populate_basepages() if so, the converse is not true:
vmemmap_populate_basepages() will happily allocate conventional pages for
regions already covered by a hugepage and write the corresponding PTEs to
that hugepage, pretending that it's a PMD. At best, this results in those
conventional pages getting leaked.
Such a situation does exist: the initialization code in
arch/x86/mm/kasan_init_64.c calls into vmemmap_populate().
Since commit 7b79d10a2d64 ("mm: convert kmalloc_section_memmap() to
populate_section_memmap()"), the latter invokes either
vmemmap_populate_basepages() or vmemmap_populate_hugepages(), depending on
the requested region's size. vmemmap_populate_basepages() invocations
on regions already covered by a hugepage have actually been obvserved in
this context.
Make vmemmap_populate_basepages() skip regions covered by hugepages
already.
Signed-off-by: Nicolai Stange <nicstange@gmail.com>
---
mm/sparse-vmemmap.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
index d45bd2714a2b..f08872b58e48 100644
--- a/mm/sparse-vmemmap.c
+++ b/mm/sparse-vmemmap.c
@@ -224,12 +224,13 @@ int __meminit vmemmap_populate_basepages(unsigned long start,
unsigned long end, int node)
{
unsigned long addr = start & ~(PAGE_SIZE - 1);
+ unsigned long next;
pgd_t *pgd;
pud_t *pud;
pmd_t *pmd;
pte_t *pte;
- for (; addr < end; addr += PAGE_SIZE) {
+ for (; addr < end; addr = next) {
pgd = vmemmap_pgd_populate(addr, node);
if (!pgd)
return -ENOMEM;
@@ -239,10 +240,16 @@ int __meminit vmemmap_populate_basepages(unsigned long start,
pmd = vmemmap_pmd_populate(pud, addr, node);
if (!pmd)
return -ENOMEM;
- pte = vmemmap_pte_populate(pmd, addr, node);
- if (!pte)
- return -ENOMEM;
- vmemmap_verify(pte, node, addr, addr + PAGE_SIZE);
+ if (!pmd_large(*pmd)) {
+ pte = vmemmap_pte_populate(pmd, addr, node);
+ if (!pte)
+ return -ENOMEM;
+ next = addr + PAGE_SIZE;
+ } else {
+ pte = (pte_t *)pmd;
+ next = (addr & ~(PMD_SIZE - 1)) + PMD_SIZE;
+ }
+ vmemmap_verify(pte, node, addr, next);
}
return 0;
--
2.11.1
--
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>
next prev parent reply other threads:[~2017-02-15 20:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-15 20:58 [RFC 0/3] Regressions due to 7b79d10a2d64 ("mm: convert kmalloc_section_memmap() to populate_section_memmap()") and Kasan initialization on Nicolai Stange
2017-02-15 20:58 ` [RFC 1/3] sparse-vmemmap: let vmemmap_populate_basepages() cover the whole range Nicolai Stange
2017-02-15 20:58 ` Nicolai Stange [this message]
2017-02-15 20:58 ` [RFC 3/3] sparse-vmemmap: let vmemmap_verify() ignore NUMA_NO_NODE requests Nicolai Stange
2017-02-15 21:10 ` [RFC 0/3] Regressions due to 7b79d10a2d64 ("mm: convert kmalloc_section_memmap() to populate_section_memmap()") and Kasan initialization on Andrew Morton
2017-02-15 21:26 ` Dan Williams
2017-02-15 21:54 ` Andrew Morton
2017-02-25 19:03 ` Dan Williams
2017-02-27 9:34 ` Dmitry Vyukov
2017-03-03 16:08 ` Andrey Ryabinin
2017-03-10 0:58 ` Dan Williams
2017-03-10 8:46 ` Andrey Ryabinin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170215205826.13356-3-nicstange@gmail.com \
--to=nicstange@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=dan.j.williams@intel.com \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).