From: Jacob Shin <jacob.shin@amd.com>
To: X86-ML <x86@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
"H. Peter Anvin" <hpa@zytor.com>, Yinghai Lu <yinghai@kernel.org>,
Tejun Heo <tj@kernel.org>, Dave Young <dyoung@redhat.com>,
Chao Wang <chaowang@redhat.com>, Vivek Goyal <vgoyal@redhat.com>,
Andreas Herrmann <andreas.herrmann3@amd.com>,
Borislav Petkov <borislav.petkov@amd.com>,
Jacob Shin <jacob.shin@amd.com>
Subject: [PATCH 2/5] x86: find_early_table_space based on memory ranges that are being mapped
Date: Fri, 24 Aug 2012 18:55:13 -0500 [thread overview]
Message-ID: <1345852516-3125-3-git-send-email-jacob.shin@amd.com> (raw)
In-Reply-To: <1345852516-3125-1-git-send-email-jacob.shin@amd.com>
Current logic finds enough space for direct mapping page tables from 0
to end. Instead, we only need to find enough space to cover mr[0].start
to mr[nr_range].end -- the range that is actually being mapped by
init_memory_mapping()
This patch also reportedly fixes suspend/resume issue reported in:
https://lkml.org/lkml/2012/8/11/83
Signed-off-by: Jacob Shin <jacob.shin@amd.com>
---
arch/x86/mm/init.c | 62 +++++++++++++++++++++++++++++-----------------------
1 file changed, 35 insertions(+), 27 deletions(-)
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 2f07e09..e2b21e0 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -35,40 +35,48 @@ struct map_range {
unsigned page_size_mask;
};
-static void __init find_early_table_space(struct map_range *mr, unsigned long end,
- int use_pse, int use_gbpages)
+/*
+ * First calculate space needed for kernel direct mapping page tables to cover
+ * mr[0].start to mr[nr_range - 1].end, while accounting for possible 2M and 1GB
+ * pages. Then find enough contiguous space for those page tables.
+ */
+static void __init find_early_table_space(struct map_range *mr, int nr_range)
{
- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
+ int i;
+ unsigned long puds = 0, pmds = 0, ptes = 0, tables;
+ unsigned long start = 0, good_end;
phys_addr_t base;
- puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
- tables = roundup(puds * sizeof(pud_t), PAGE_SIZE);
-
- if (use_gbpages) {
- unsigned long extra;
-
- extra = end - ((end>>PUD_SHIFT) << PUD_SHIFT);
- pmds = (extra + PMD_SIZE - 1) >> PMD_SHIFT;
- } else
- pmds = (end + PMD_SIZE - 1) >> PMD_SHIFT;
+ for (i = 0; i < nr_range; i++) {
+ unsigned long range, extra;
- tables += roundup(pmds * sizeof(pmd_t), PAGE_SIZE);
+ range = mr[i].end - mr[i].start;
+ puds += (range + PUD_SIZE - 1) >> PUD_SHIFT;
- if (use_pse) {
- unsigned long extra;
+ if (mr[i].page_size_mask & (1 << PG_LEVEL_1G)) {
+ extra = range - ((range >> PUD_SHIFT) << PUD_SHIFT);
+ pmds += (extra + PMD_SIZE - 1) >> PMD_SHIFT;
+ } else {
+ pmds += (range + PMD_SIZE - 1) >> PMD_SHIFT;
+ }
- extra = end - ((end>>PMD_SHIFT) << PMD_SHIFT);
+ if (mr[i].page_size_mask & (1 << PG_LEVEL_2M)) {
+ extra = range - ((range >> PMD_SHIFT) << PMD_SHIFT);
#ifdef CONFIG_X86_32
- extra += PMD_SIZE;
+ extra += PMD_SIZE;
#endif
- /* The first 2/4M doesn't use large pages. */
- if (mr->start < PMD_SIZE)
- extra += mr->end - mr->start;
-
- ptes = (extra + PAGE_SIZE - 1) >> PAGE_SHIFT;
- } else
- ptes = (end + PAGE_SIZE - 1) >> PAGE_SHIFT;
+ /* The first 2/4M doesn't use large pages. */
+ if (mr[i].start < PMD_SIZE)
+ extra += range;
+
+ ptes += (extra + PAGE_SIZE - 1) >> PAGE_SHIFT;
+ } else {
+ ptes += (range + PAGE_SIZE - 1) >> PAGE_SHIFT;
+ }
+ }
+ tables = roundup(puds * sizeof(pud_t), PAGE_SIZE);
+ tables += roundup(pmds * sizeof(pmd_t), PAGE_SIZE);
tables += roundup(ptes * sizeof(pte_t), PAGE_SIZE);
#ifdef CONFIG_X86_32
@@ -86,7 +94,7 @@ static void __init find_early_table_space(struct map_range *mr, unsigned long en
pgt_buf_top = pgt_buf_start + (tables >> PAGE_SHIFT);
printk(KERN_DEBUG "kernel direct mapping tables up to %#lx @ [mem %#010lx-%#010lx]\n",
- end - 1, pgt_buf_start << PAGE_SHIFT,
+ mr[nr_range - 1].end - 1, pgt_buf_start << PAGE_SHIFT,
(pgt_buf_top << PAGE_SHIFT) - 1);
}
@@ -257,7 +265,7 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
* nodes are discovered.
*/
if (!after_bootmem)
- find_early_table_space(&mr[0], end, use_pse, use_gbpages);
+ find_early_table_space(mr, nr_range);
for (i = 0; i < nr_range; i++)
ret = kernel_physical_mapping_init(mr[i].start, mr[i].end,
--
1.7.9.5
next prev parent reply other threads:[~2012-08-24 23:57 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-24 23:55 [PATCH V4 0/5] x86: Create direct mappings for E820_RAM only Jacob Shin
2012-08-24 23:55 ` [PATCH 1/5] x86: Move enabling of PSE and PGE out of init_memory_mapping Jacob Shin
2012-08-25 1:25 ` Yinghai Lu
2012-08-25 1:49 ` Yinghai Lu
2012-08-25 2:06 ` Yinghai Lu
2012-08-25 4:15 ` Jacob Shin
2012-08-25 4:13 ` Jacob Shin
2012-08-24 23:55 ` Jacob Shin [this message]
2012-10-21 21:22 ` [PATCH 2/5] x86: find_early_table_space based on memory ranges that are being mapped Tom Rini
2012-08-24 23:55 ` [PATCH 3/5] x86: Only direct map addresses that are marked as E820_RAM Jacob Shin
2012-08-25 0:17 ` Jacob Shin
2012-08-25 0:30 ` H. Peter Anvin
2012-08-25 0:49 ` Jacob Shin
2012-08-25 1:13 ` H. Peter Anvin
2012-08-25 4:20 ` Jacob Shin
2012-08-25 4:21 ` H. Peter Anvin
2012-08-27 19:17 ` Jacob Shin
2012-08-27 20:15 ` H. Peter Anvin
2012-08-25 1:07 ` Yinghai Lu
2012-08-25 4:24 ` Jacob Shin
2012-08-25 4:54 ` Yinghai Lu
2012-08-27 18:49 ` Jacob Shin
2012-08-27 20:16 ` H. Peter Anvin
2012-08-28 16:06 ` Jacob Shin
2012-08-28 16:11 ` H. Peter Anvin
2012-08-24 23:55 ` [PATCH 4/5] x86: Fixup code testing if a pfn is direct mapped Jacob Shin
2012-08-24 23:55 ` [PATCH 5/5] x86: if kernel .text .data .bss are not marked as E820_RAM, complain and fix Jacob Shin
2012-08-25 1:23 ` Yinghai Lu
2012-08-25 4:25 ` Jacob Shin
-- strict thread matches above, loose matches on Subject: below --
2012-08-13 21:46 [PATCH V2 0/5] x86: Create direct mappings for E820_RAM only Jacob Shin
2012-08-13 21:47 ` [PATCH 2/5] x86: find_early_table_space based on memory ranges that are being mapped Jacob Shin
2012-08-09 21:23 [PATCH 0/5] Only create direct mappings for E820_RAM regions Jacob Shin
2012-08-09 21:23 ` [PATCH 2/5] x86: find_early_table_space based on memory ranges that are being mapped Jacob Shin
2012-08-11 19:56 ` Tejun Heo
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=1345852516-3125-3-git-send-email-jacob.shin@amd.com \
--to=jacob.shin@amd.com \
--cc=andreas.herrmann3@amd.com \
--cc=borislav.petkov@amd.com \
--cc=chaowang@redhat.com \
--cc=dyoung@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
--cc=vgoyal@redhat.com \
--cc=x86@kernel.org \
--cc=yinghai@kernel.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).