x86/mm: Fix the size calculation of mapping tables
Commit-ID: 722bc6b16771ed80871e1fd81c86d3627dda2ac8 Gitweb: http://git.kernel.org/tip/722bc6b16771ed80871e1fd81c86d3627dda2ac8 Author: WANG Cong <[email protected]> AuthorDate: Mon, 5 Mar 2012 15:05:13 -0800 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 6 Mar 2012 09:38:26 +0100
x86/mm: Fix the size calculation of mapping tables
For machines that enable PSE, the first 2/4M memory region still uses 4K pages, so needs more PTEs in this case, but find_early_table_space() doesn't count this.
This patch fixes it.
The bug was found via code review, no misbehavior of the kernel was observed.
--- arch/x86/mm/init.c | 21 ++++++++++++--------- 1 files changed, 12 insertions(+), 9 deletions(-)
arch/x86/mm/init.c +12 -9
@@ -30,8 +30,14 @@ int direct_gbpages#endif ; -static void __init find_early_table_space (unsigned long end,int use_pse, -int use_gbpages) +struct map_range { +unsigned long start; +unsigned long end; +unsigned page_size_mask; +}; + +static void __init find_early_table_space (struct map_range *mr,unsigned long end, +int use_pse,int use_gbpages) {unsigned long puds, pmds, ptes, tables, start =0 , good_end = end;phys_addr_t base;
@@ -56,6 +62,9 @@ static void __init find_early_table_space(unsigned long end, int use_pse,#ifdef CONFIG_X86_32 extra +=PMD_SIZE ;#endif +/* The first 2/4M doesn't use large pages. */ + extra += mr->end - mr->start; + ptes = (extra +PAGE_SIZE -1 ) >>PAGE_SHIFT ; }else ptes = (end +PAGE_SIZE -1 ) >>PAGE_SHIFT ;
@@ -85,12 +94,6 @@ void __init native_pagetable_reserve(u64 start, u64 end)memblock_reserve (start, end - start); } -struct map_range { -unsigned long start; -unsigned long end; -unsigned page_size_mask; -}; -#ifdef CONFIG_X86_32 #define NR_RANGE_MR 3#else /* CONFIG_X86_64 */
@@ -262,7 +265,7 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,* nodes are discovered. */ if (!after_bootmem) -find_early_table_space (end, use_pse, use_gbpages); +find_early_table_space (&mr[0 ], end, use_pse, use_gbpages);for (i =0 ; i < nr_range; i++) ret = kernel_physical_mapping_init(mr[i].start, mr[i].end,
Quoted 51 lines · tip-bot for WANG Cong
Commit-ID: 722bc6b16771ed80871e1fd81c86d3627dda2ac8
Gitweb: http://git.kernel.org/tip/722bc6b16771ed80871e1fd81c86d3627dda2ac8
Author: WANG Cong <[email protected]>
AuthorDate: Mon, 5 Mar 2012 15:05:13 -0800
Committer: Ingo Molnar <[email protected]>
CommitDate: Tue, 6 Mar 2012 09:38:26 +0100x86/mm: Fix the size calculation of mapping tables
For machines that enable PSE, the first 2/4M memory region still uses 4K pages, so needs more PTEs in this case, but
find_early_table_space()doesn't count this.This patch fixes it.
The bug was found via code review, no misbehavior of the kernel was observed.
Signed-off-by WANG Cong <[email protected]>Cc Yinghai Lu <[email protected]>Cc Tejun Heo <[email protected]>Cc <[email protected]>Signed-off-by Andrew Morton <[email protected]>Signed-off-by Ingo Molnar <[email protected]>---
arch/x86/mm/init.c | 21 ++++++++++++---------1 files changed, 12 insertions(+), 9 deletions(-)arch/x86/mm/init.c +8
-2@@ -30,8 +30,14 @@ int direct_gbpages #endif ; -static void __init find_early_table_space (unsigned long end,int use_pse, - int use_gbpages) +struct map_range { + unsigned long start; + unsigned long end; + unsigned page_size_mask; +}; + +static void __init find_early_table_space (struct map_range *mr,unsigned long end, + int use_pse, int use_gbpages) { unsigned long puds, pmds, ptes, tables, start = 0, good_end = end; phys_addr_t base;
arch/x86/mm/init.c static void __init find_early_table_space(unsigned long end, int use_pse, · line 67
Quoted 6 lines
arch/x86/mm/init.c +3
-0@@ -56,6 +62,9 @@ static void __init find_early_table_space(unsigned long end, int use_pse, #ifdef CONFIG_X86_32 extra += PMD_SIZE; #endif + /* The first 2/4M doesn't use large pages. */ + extra += mr->end - mr->start; +
Something wrong here, you need to check if this MR is really cover first 2/4M ...
something like
arch/x86/mm/init.c +2 -1
@@ -63,7 +63,8 @@ static void __init find_early_table_spac extra +=PMD_SIZE ;#endif /* The first 2/4M doesn't use large pages. */ - extra += mr->end - mr->start; +if (mr->start <PMD_SIZE ) + extra += mr->end - mr->start; ptes = (extra +PAGE_SIZE -1 ) >>PAGE_SHIFT ; }else
otherwise, for system with 512G or more. page table for [4G, 512g) may have preallocate more
but only use little.
Yinghai