Add a kernel parameter to change the padding size for KASLR
Subsystems (4)
v5 cover Add a kernel parameter to change the padding size for KASLR
This patch series are adding an kernel parameter to change the padding size used for KASLR. It is useful for memory hotplug capable system. User can adjust the padding size to use it.
It is better if the padding size is calculated automatically, however, ACPI SRAT is not available at the KASLR initialization time. So, I add a message for user to tell the suitable padding size. User can set it on next reboot.
This patch series don't change the current default padding size.
Change log from v4:
- Fix the padding size check (2nd patch)
- Add explanation for the parameter in the document. (3rd patch)
Change log from v3:
- Add a warning message if the padding size for KASLR is not enough. And it says the suitable padding size to user.
Change log from v2:
- Simplify the description. As Baoquan said, this is similar SGI UV issue, but a little different. Remove SGI UV description.
Masayoshi Mizuma (3):
x86/mm: Add a kernel parameter to change the padding used for the physical
memory mapping
ACPI / NUMA: Add warning message if the padding size for KASLR is not
enough
docs: kernel-parameters.txt: document rand_mem_physical_padding
.../admin-guide/kernel-parameters.txt | 18 ++++++++++++++++++ arch/x86/include/asm/setup.h | 2 ++ arch/x86/mm/kaslr.c | 17 ++++++++++++++++- drivers/acpi/numa.c | 16 ++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-)
Signature · 1 line
2.18.0
PATCH v5 1/3 x86/mm: Add a kernel parameter to change the padding used for the physical memory mapping
From: Masayoshi Mizuma <[email protected]>
If each node of physical memory layout has huge space for hotplug, the padding used for the physical memory mapping section is not enough. For exapmle of the layout:
SRAT: Node 6 PXM 4 [mem 0x100000000000-0x13ffffffffff] hotplug
SRAT: Node 7 PXM 5 [mem 0x140000000000-0x17ffffffffff] hotplug
SRAT: Node 2 PXM 6 [mem 0x180000000000-0x1bffffffffff] hotplug
SRAT: Node 3 PXM 7 [mem 0x1c0000000000-0x1fffffffffff] hotplug
We can increase the padding by CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING, however, the needed padding size depends on the system environment. The kernel option is better than changing the config.
--- arch/x86/mm/kaslr.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
arch/x86/mm/kaslr.c +16 -1
@@ -40,6 +40,7 @@*/ static const unsigned long vaddr_end =CPU_ENTRY_AREA_BASE ; +int __initdata rand_mem_physical_padding =CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING ;/* * Memory regions randomized by KASLR (except modules that use a separate logic * earlier during boot). The list is ordered based on virtual addresses. This
@@ -69,6 +70,20 @@ static inline bool kaslr_memory_enabled(void)return kaslr_enabled () && !IS_ENABLED (CONFIG_KASAN ); } +static int __init rand_mem_physical_padding_setup (char *str) +{ +int max_padding = (1 << (MAX_PHYSMEM_BITS -TB_SHIFT )) -1 ; + +get_option (&str, &rand_mem_physical_padding); +if (rand_mem_physical_padding <0 ) + rand_mem_physical_padding =0 ; +else if (rand_mem_physical_padding > max_padding) + rand_mem_physical_padding = max_padding; + +return 0 ; +} +early_param ("rand_mem_physical_padding" , rand_mem_physical_padding_setup); +/* Initialize base and padding for each memory region randomized with KASLR */ void __init kernel_randomize_memory (void ) {
@@ -102,7 +117,7 @@ void __init kernel_randomize_memory(void)*/ BUG_ON (kaslr_regions[0 ].base != &page_offset_base); memory_tb =DIV_ROUND_UP (max_pfn <<PAGE_SHIFT ,1UL <<TB_SHIFT ) + -CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING ; + rand_mem_physical_padding;/* Adapt phyiscal memory region size based on available memory */ if (memory_tb < kaslr_regions[0 ].size_tb)
Signature · 1 line
2.18.0
tip-bot for Masayoshi Mizuma
merge bot[tip:x86/boot] x86/mm: Add a kernel parameter to change the padding used for the physical memory mapping
x86/mm: Add a kernel parameter to change the padding used for the physical memory mapping
Commit-ID: e79ac9354cf95d75ff6afd341f9c5aa5cbcd638b Gitweb: https://git.kernel.org/tip/e79ac9354cf95d75ff6afd341f9c5aa5cbcd638b Author: Masayoshi Mizuma <[email protected]> AuthorDate: Mon, 1 Oct 2018 10:08:41 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 2 Oct 2018 11:47:20 +0200
x86/mm: Add a kernel parameter to change the padding used for the physical memory mapping
If each node of physical memory layout has huge space for hotplug, the padding used for the physical memory mapping section is not enough. For exapmle of the layout:
SRAT: Node 6 PXM 4 [mem 0x100000000000-0x13ffffffffff] hotplug
SRAT: Node 7 PXM 5 [mem 0x140000000000-0x17ffffffffff] hotplug
SRAT: Node 2 PXM 6 [mem 0x180000000000-0x1bffffffffff] hotplug
SRAT: Node 3 PXM 7 [mem 0x1c0000000000-0x1fffffffffff] hotplug
We can increase the padding via CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING, however, the needed padding size depends on the system environment. The kernel option is better than changing the config.
--- arch/x86/mm/kaslr.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
arch/x86/mm/kaslr.c +16 -1
@@ -40,6 +40,7 @@*/ static const unsigned long vaddr_end =CPU_ENTRY_AREA_BASE ; +int __initdata rand_mem_physical_padding =CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING ;/* * Memory regions randomized by KASLR (except modules that use a separate logic * earlier during boot). The list is ordered based on virtual addresses. This
@@ -69,6 +70,20 @@ static inline bool kaslr_memory_enabled(void)return kaslr_enabled () && !IS_ENABLED (CONFIG_KASAN ); } +static int __init rand_mem_physical_padding_setup (char *str) +{ +int max_padding = (1 << (MAX_PHYSMEM_BITS -TB_SHIFT )) -1 ; + +get_option (&str, &rand_mem_physical_padding); +if (rand_mem_physical_padding <0 ) + rand_mem_physical_padding =0 ; +else if (rand_mem_physical_padding > max_padding) + rand_mem_physical_padding = max_padding; + +return 0 ; +} +early_param ("rand_mem_physical_padding" , rand_mem_physical_padding_setup); +/* Initialize base and padding for each memory region randomized with KASLR */ void __init kernel_randomize_memory (void ) {
@@ -102,7 +117,7 @@ void __init kernel_randomize_memory(void)*/ BUG_ON (kaslr_regions[0 ].base != &page_offset_base); memory_tb =DIV_ROUND_UP (max_pfn <<PAGE_SHIFT ,1UL <<TB_SHIFT ) + -CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING ; + rand_mem_physical_padding;/* Adapt phyiscal memory region size based on available memory */ if (memory_tb < kaslr_regions[0 ].size_tb)
PATCH v5 2/3 ACPI / NUMA: Add warning message if the padding size for KASLR is not enough
In reply to Masayoshi MizumaFrom: Masayoshi Mizuma <[email protected]>
Add warning message if the padding size for KASLR, rand_mem_physical_padding, is not enough. The message also says the suitable padding size.
--- arch/x86/include/asm/setup.h | 2 ++ drivers/acpi/numa.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+)
arch/x86/include/asm/setup.h +2 -0
@@ -80,6 +80,8 @@ static inline unsigned long kaslr_offset(void)return (unsigned long )&_text - __START_KERNEL; } +extern int rand_mem_physical_padding; +/* * Do NOT EVER look at the BIOS memory size location. * It does not work on many machines.
drivers/acpi/numa.c +16 -0
@@ -32,6 +32,7 @@#include <linux/numa.h> #include <linux/nodemask.h> #include <linux/topology.h> +#include <asm/setup.h> static nodemask_t nodes_found_map =NODE_MASK_NONE ;
@@ -435,6 +436,7 @@ acpi_table_parse_srat(enum acpi_srat_type id,int __init acpi_numa_init (void ) {int cnt =0 ; +u64 max_possible_phys, max_actual_phys, threshold;if (acpi_disabled)return -EINVAL ;
@@ -463,6 +465,20 @@ int __init acpi_numa_init(void) cnt =acpi_table_parse_srat (ACPI_SRAT_TYPE_MEMORY_AFFINITY , acpi_parse_memory_affinity,0 ); + +/* check the padding size for KASLR is enough. */ +if (parsed_numa_memblks &&kaslr_enabled ()) { + max_actual_phys =roundup (PFN_PHYS (max_pfn), +1ULL <<40 ); + max_possible_phys =roundup (PFN_PHYS (max_possible_pfn), +1ULL <<40 ); + threshold = max_actual_phys + + ((u64 )rand_mem_physical_padding <<40 ); + +if (max_possible_phys > threshold) +pr_warn ("Set 'rand_mem_physical_padding=%llu' to avoid memory hotadd failure.\n" , + (max_possible_phys - max_actual_phys) >>40 ); + } }/* SLIT: System Locality Information Table */
Signature · 1 line
2.18.0
tip-bot for Masayoshi Mizuma
merge bot[tip:x86/boot] ACPI/NUMA: Add warning message if the padding size for KASLR is not enough
ACPI/NUMA: Add warning message if the padding size for KASLR is not enough
Commit-ID: 3b054ca88c4f4dd5f516a12d4b6d6bd0ae826f41 Gitweb: https://git.kernel.org/tip/3b054ca88c4f4dd5f516a12d4b6d6bd0ae826f41 Author: Masayoshi Mizuma <[email protected]> AuthorDate: Mon, 1 Oct 2018 10:08:42 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 2 Oct 2018 11:47:21 +0200
ACPI/NUMA: Add warning message if the padding size for KASLR is not enough
Add warning message if the padding size for KASLR, rand_mem_physical_padding, is not enough. The message also says the suitable padding size.
--- arch/x86/include/asm/setup.h | 2 ++ drivers/acpi/numa.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+)
arch/x86/include/asm/setup.h +2 -0
@@ -80,6 +80,8 @@ static inline unsigned long kaslr_offset(void)return (unsigned long )&_text - __START_KERNEL; } +extern int rand_mem_physical_padding; +/* * Do NOT EVER look at the BIOS memory size location. * It does not work on many machines.
drivers/acpi/numa.c +14 -0
@@ -32,6 +32,7 @@#include <linux/numa.h> #include <linux/nodemask.h> #include <linux/topology.h> +#include <asm/setup.h> static nodemask_t nodes_found_map =NODE_MASK_NONE ;
@@ -435,6 +436,7 @@ acpi_table_parse_srat(enum acpi_srat_type id,int __init acpi_numa_init (void ) {int cnt =0 ; +u64 max_possible_phys, max_actual_phys, threshold;if (acpi_disabled)return -EINVAL ;
@@ -463,6 +465,18 @@ int __init acpi_numa_init(void) cnt =acpi_table_parse_srat (ACPI_SRAT_TYPE_MEMORY_AFFINITY , acpi_parse_memory_affinity,0 ); + +/* check the padding size for KASLR is enough. */ +if (parsed_numa_memblks &&kaslr_enabled ()) { + max_actual_phys =roundup (PFN_PHYS (max_pfn),1ULL <<40 ); + max_possible_phys =roundup (PFN_PHYS (max_possible_pfn),1ULL <<40 ); + threshold = max_actual_phys + ((u64 )rand_mem_physical_padding <<40 ); + +if (max_possible_phys > threshold) { +pr_warn ("Set 'rand_mem_physical_padding=%llu' to avoid memory hotadd failure.\n" , + (max_possible_phys - max_actual_phys) >>40 ); + } + } }/* SLIT: System Locality Information Table */
Borislav Petkov
maintainerRe: [tip:x86/boot] ACPI/NUMA: Add warning message if the padding size for KASLR is not enough
Quoted 61 lines · tip-bot for Masayoshi Mizuma
Commit-ID: 3b054ca88c4f4dd5f516a12d4b6d6bd0ae826f41 Gitweb: https://git.kernel.org/tip/3b054ca88c4f4dd5f516a12d4b6d6bd0ae826f41 Author: Masayoshi Mizuma <[email protected]> AuthorDate: Mon, 1 Oct 2018 10:08:42 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 2 Oct 2018 11:47:21 +0200ACPI/NUMA: Add warning message if the padding size for KASLR is not enough
Add warning message if the padding size for KASLR,
rand_mem_physical_padding, is not enough. The message also says the suitable padding size.Signed-off-by Masayoshi Mizuma <[email protected]>Cc Baoquan He <[email protected]>Cc Borislav Petkov <[email protected]>Cc Linus Torvalds <[email protected]>Cc Masayoshi Mizuma <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Signed-off-by Ingo Molnar <[email protected]>--- arch/x86/include/asm/setup.h | 2 ++ drivers/acpi/numa.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+)arch/x86/include/asm/setup.h +2
-0@@ -80,6 +80,8 @@ static inline unsigned long kaslr_offset(void)return (unsigned long )&_text - __START_KERNEL; } +extern int rand_mem_physical_padding; +/* * Do NOT EVER look at the BIOS memory size location. * It does not work on many machines. drivers/acpi/numa.c +2
-0@@ -32,6 +32,7 @@#include <linux/numa.h> #include <linux/nodemask.h> #include <linux/topology.h> +#include <asm/setup.h> static nodemask_t nodes_found_map =NODE_MASK_NONE ;@@ -435,6 +436,7 @@ acpi_table_parse_srat(enum acpi_srat_type id,int __init acpi_numa_init (void ) {int cnt =0 ; +u64 max_possible_phys, max_actual_phys, threshold;if (acpi_disabled)return -EINVAL ;
drivers/acpi/numa.c int __init acpi_numa_init(void) · line 473
Quoted 9 lines
drivers/acpi/numa.c +6
-0@@ -463,6 +465,18 @@ int __init acpi_numa_init(void) cnt =acpi_table_parse_srat (ACPI_SRAT_TYPE_MEMORY_AFFINITY , acpi_parse_memory_affinity,0 ); + +/* check the padding size for KASLR is enough. */ +if (parsed_numa_memblks &&kaslr_enabled ()) { + max_actual_phys =roundup (PFN_PHYS (max_pfn),1ULL <<40 ); + max_possible_phys =roundup (PFN_PHYS (max_possible_pfn),1ULL <<40 ); + threshold = max_actual_phys + ((u64 )rand_mem_physical_padding <<40 );
Nope, not really:
ld: drivers/acpi/numa.o: in function `acpi_numa_init':/home/boris/kernel/linux/drivers/acpi/numa.c:473: undefined reference to `rand_mem_physical_padding'
make: *** [Makefile:1030: vmlinux] Error 1
due to CONFIG_RANDOMIZE_MEMORY=n in my .config.
You need to add a fix ontop which adds a function get_rand_mem_physical_padding() which is defined in CONFIG_RANDOMIZE_MEMORY=y and outside returns 0.
And then make that rand_mem_physical_padding static and do not export it to anything outside of kaslr.c but use the accessor.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [tip:x86/boot] ACPI/NUMA: Add warning message if the padding size for KASLR is not enough
Quoted 78 lines · Borislav Petkov
Quoted 61 lines · tip-bot for Masayoshi Mizuma
Commit-ID: 3b054ca88c4f4dd5f516a12d4b6d6bd0ae826f41 Gitweb: https://git.kernel.org/tip/3b054ca88c4f4dd5f516a12d4b6d6bd0ae826f41 Author: Masayoshi Mizuma <[email protected]> AuthorDate: Mon, 1 Oct 2018 10:08:42 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 2 Oct 2018 11:47:21 +0200ACPI/NUMA: Add warning message if the padding size for KASLR is not enough
Add warning message if the padding size for KASLR,
rand_mem_physical_padding, is not enough. The message also says the suitable padding size.Signed-off-by Masayoshi Mizuma <[email protected]>Cc Baoquan He <[email protected]>Cc Borislav Petkov <[email protected]>Cc Linus Torvalds <[email protected]>Cc Masayoshi Mizuma <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Signed-off-by Ingo Molnar <[email protected]>--- arch/x86/include/asm/setup.h | 2 ++ drivers/acpi/numa.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+)arch/x86/include/asm/setup.h +2
-0@@ -80,6 +80,8 @@ static inline unsigned long kaslr_offset(void)return (unsigned long )&_text - __START_KERNEL; } +extern int rand_mem_physical_padding; +/* * Do NOT EVER look at the BIOS memory size location. * It does not work on many machines. drivers/acpi/numa.c +2
-0@@ -32,6 +32,7 @@#include <linux/numa.h> #include <linux/nodemask.h> #include <linux/topology.h> +#include <asm/setup.h> static nodemask_t nodes_found_map =NODE_MASK_NONE ;@@ -435,6 +436,7 @@ acpi_table_parse_srat(enum acpi_srat_type id,int __init acpi_numa_init (void ) {int cnt =0 ; +u64 max_possible_phys, max_actual_phys, threshold;if (acpi_disabled)return -EINVAL ;drivers/acpi/numa.c int __init acpi_numa_init(void) · line 473
Quoted 9 lines
drivers/acpi/numa.c +6
-0@@ -463,6 +465,18 @@ int __init acpi_numa_init(void) cnt =acpi_table_parse_srat (ACPI_SRAT_TYPE_MEMORY_AFFINITY , acpi_parse_memory_affinity,0 ); + +/* check the padding size for KASLR is enough. */ +if (parsed_numa_memblks &&kaslr_enabled ()) { + max_actual_phys =roundup (PFN_PHYS (max_pfn),1ULL <<40 ); + max_possible_phys =roundup (PFN_PHYS (max_possible_pfn),1ULL <<40 ); + threshold = max_actual_phys + ((u64 )rand_mem_physical_padding <<40 );Nope, not really:
ld:
drivers/acpi/numa.o: in function `acpi_numa_init':/home/boris/kernel/linux/drivers/acpi/numa.c:473: undefined reference to `rand_mem_physical_padding'
make: *** [Makefile:1030: vmlinux] Error 1
Quoted 8 lines
due to
CONFIG_RANDOMIZE_MEMORY=nin my .config.You need to add a fix ontop which adds a function
get_rand_mem_physical_padding()which is defined inCONFIG_RANDOMIZE_MEMORY=yand outside returns 0.And then make that
rand_mem_physical_paddingstatic and do not export it to anything outside ofkaslr.cbut use the accessor.
Thank you for the report and suggetions!
I'll fix it and resubmit soon.
Thanks,
Masa
Re: [tip:x86/boot] ACPI/NUMA: Add warning message if the padding size for KASLR is not enough
In reply to tip-bot for Masayoshi MizumaFrom: Masayoshi Mizuma <[email protected]>
Subject: [PATCH] Fix for build error if CONFIG_RANDOMIZE_BASE is not defined.
Fix the following build error.
ld: drivers/acpi/numa.o: in function `acpi_numa_init':
drivers/acpi/numa.c:473: undefined reference to `rand_mem_physical_padding'
make: *** [Makefile:1030: vmlinux] Error 1
- Add get_rand_mem_physical_padding() which returns rand_mem_physical_padding or 0 if CONFIG_RANDOMIZE_MEMORY is not defined.
- Make rand_mem_physical_padding static
--- arch/x86/include/asm/setup.h | 9 ++++++++- arch/x86/mm/kaslr.c | 9 +++++++-- drivers/acpi/numa.c | 3 ++- 3 files changed, 17 insertions(+), 4 deletions(-)
arch/x86/include/asm/setup.h +8 -1
@@ -80,7 +80,14 @@ static inline unsigned long kaslr_offset(void)return (unsigned long )&_text - __START_KERNEL; } -extern int rand_mem_physical_padding; +#ifdef CONFIG_RANDOMIZE_MEMORY +extern inline int __init get_rand_mem_physical_padding (void ); +#else +static inline int __init get_rand_mem_physical_padding (void ) +{ +return 0 ; +} +#endif /* * Do NOT EVER look at the BIOS memory size location.
arch/x86/mm/kaslr.c +7 -2
@@ -40,7 +40,7 @@*/ static const unsigned long vaddr_end =CPU_ENTRY_AREA_BASE ; -int __initdata rand_mem_physical_padding =CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING ; +static int rand_mem_physical_padding__initdata =CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING ;/* * Memory regions randomized by KASLR (except modules that use a separate logic * earlier during boot). The list is ordered based on virtual addresses. This
@@ -70,6 +70,11 @@ static inline bool kaslr_memory_enabled(void)return kaslr_enabled () && !IS_ENABLED (CONFIG_KASAN ); } +inline int __init get_rand_mem_physical_padding (void ) +{ +return rand_mem_physical_padding; +} +static int __init rand_mem_physical_padding_setup (char *str) {int max_padding = (1 << (MAX_PHYSMEM_BITS -TB_SHIFT )) -1 ;
@@ -117,7 +122,7 @@ void __init kernel_randomize_memory(void)*/ BUG_ON (kaslr_regions[0 ].base != &page_offset_base); memory_tb =DIV_ROUND_UP (max_pfn <<PAGE_SHIFT ,1UL <<TB_SHIFT ) + - rand_mem_physical_padding; +get_rand_mem_physical_padding ();/* Adapt phyiscal memory region size based on available memory */ if (memory_tb < kaslr_regions[0 ].size_tb)
drivers/acpi/numa.c +2 -1
@@ -470,7 +470,8 @@ int __init acpi_numa_init(void)if (parsed_numa_memblks &&kaslr_enabled ()) { max_actual_phys =roundup (PFN_PHYS (max_pfn),1ULL <<40 ); max_possible_phys =roundup (PFN_PHYS (max_possible_pfn),1ULL <<40 ); - threshold = max_actual_phys + ((u64 )rand_mem_physical_padding <<40 ); + threshold = max_actual_phys + + ((u64 )get_rand_mem_physical_padding () <<40 );if (max_possible_phys > threshold) { pr_warn("Set 'rand_mem_physical_padding=%llu' to avoid memory hotadd failure.\n",
--
2.18.0
Quoted 79 lines · tip-bot for Masayoshi Mizuma
Commit-ID: 3b054ca88c4f4dd5f516a12d4b6d6bd0ae826f41 Gitweb: https://git.kernel.org/tip/3b054ca88c4f4dd5f516a12d4b6d6bd0ae826f41 Author: Masayoshi Mizuma <[email protected]> AuthorDate: Mon, 1 Oct 2018 10:08:42 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 2 Oct 2018 11:47:21 +0200ACPI/NUMA: Add warning message if the padding size for KASLR is not enough
Add warning message if the padding size for KASLR,
rand_mem_physical_padding, is not enough. The message also says the suitable padding size.Signed-off-by Masayoshi Mizuma <[email protected]>Cc Baoquan He <[email protected]>Cc Borislav Petkov <[email protected]>Cc Linus Torvalds <[email protected]>Cc Masayoshi Mizuma <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Signed-off-by Ingo Molnar <[email protected]>--- arch/x86/include/asm/setup.h | 2 ++ drivers/acpi/numa.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+)arch/x86/include/asm/setup.h +2
-0@@ -80,6 +80,8 @@ static inline unsigned long kaslr_offset(void)return (unsigned long )&_text - __START_KERNEL; } +extern int rand_mem_physical_padding; +/* * Do NOT EVER look at the BIOS memory size location. * It does not work on many machines. drivers/acpi/numa.c +14
-0@@ -32,6 +32,7 @@#include <linux/numa.h> #include <linux/nodemask.h> #include <linux/topology.h> +#include <asm/setup.h> static nodemask_t nodes_found_map =NODE_MASK_NONE ;@@ -435,6 +436,7 @@ acpi_table_parse_srat(enum acpi_srat_type id,int __init acpi_numa_init (void ) {int cnt =0 ; +u64 max_possible_phys, max_actual_phys, threshold;if (acpi_disabled)return -EINVAL ;@@ -463,6 +465,18 @@ int __init acpi_numa_init(void) cnt =acpi_table_parse_srat (ACPI_SRAT_TYPE_MEMORY_AFFINITY , acpi_parse_memory_affinity,0 ); + +/* check the padding size for KASLR is enough. */ +if (parsed_numa_memblks &&kaslr_enabled ()) { + max_actual_phys =roundup (PFN_PHYS (max_pfn),1ULL <<40 ); + max_possible_phys =roundup (PFN_PHYS (max_possible_pfn),1ULL <<40 ); + threshold = max_actual_phys + ((u64 )rand_mem_physical_padding <<40 ); + +if (max_possible_phys > threshold) { +pr_warn ("Set 'rand_mem_physical_padding=%llu' to avoid memory hotadd failure.\n" , + (max_possible_phys - max_actual_phys) >>40 ); + } + } }/* SLIT: System Locality Information Table */
Peter Zijlstra
maintainerRe: [tip:x86/boot] ACPI/NUMA: Add warning message if the padding size for KASLR is not enough
In reply to tip-bot for Masayoshi MizumaSubject: ACPI/NUMA: Fix KASLR build error
There is no point in trying to compile KASLR specific code when there is no KASLR.
---
drivers/acpi/numa.c +4 -1
@@ -436,7 +436,6 @@ acpi_table_parse_srat(enum acpi_srat_type id,int __init acpi_numa_init (void ) {int cnt =0 ; -u64 max_possible_phys, max_actual_phys, threshold;if (acpi_disabled)return -EINVAL ;
@@ -466,8 +465,11 @@ int __init acpi_numa_init(void) cnt =acpi_table_parse_srat (ACPI_SRAT_TYPE_MEMORY_AFFINITY , acpi_parse_memory_affinity,0 ); +#ifdef CONFIG_RANDOMIZE_MEMORY /* check the padding size for KASLR is enough. */ if (parsed_numa_memblks &&kaslr_enabled ()) { +u64 max_possible_phys, max_actual_phys, threshold; + max_actual_phys =roundup (PFN_PHYS (max_pfn),1ULL <<40 ); max_possible_phys =roundup (PFN_PHYS (max_possible_pfn),1ULL <<40 ); threshold = max_actual_phys + ((u64 )rand_mem_physical_padding <<40 );
@@ -477,6 +479,7 @@ int __init acpi_numa_init(void) (max_possible_phys - max_actual_phys) >> 40); } } +#endif }/* SLIT: System Locality Information Table */
Borislav Petkov
maintainerRe: [tip:x86/boot] ACPI/NUMA: Add warning message if the padding size for KASLR is not enough
Quoted 8 lines · Peter Zijlstra
Subject: ACPI/NUMA: Fix KASLR build error
There is no point in trying to compile KASLR specific code when there is no KASLR.
Signed-off-by Peter Zijlstra (Intel) <[email protected]>---
Yeah, Peter and I were just talking on IRC and he gave me a much better idea how to fix this, see below. I'll run this through the *config builder and commit it if no complaints.
---
From: "Peter Zijlstra (Intel)" <[email protected]>
Date: Wed, 3 Oct 2018 14:41:27 +0200
Subject: [PATCH] ACPI/NUMA: Fix KASLR build error
There is no point in trying to compile KASLR specific code when there is no KASLR.
[ bp: Move the whole crap into kaslr.c and make
rand_mem_physical_padding static. ]
--- arch/x86/include/asm/kaslr.h | 2 ++ arch/x86/include/asm/setup.h | 2 -- arch/x86/mm/kaslr.c | 18 +++++++++++++++++- drivers/acpi/numa.c | 15 +++------------ 4 files changed, 22 insertions(+), 15 deletions(-)
arch/x86/include/asm/kaslr.h +2 -0
@@ -6,8 +6,10 @@ unsigned long kaslr_get_random_long(const char *purpose);#ifdef CONFIG_RANDOMIZE_MEMORY void kernel_randomize_memory (void ); +void kaslr_check_padding (void );#else static inline void kernel_randomize_memory (void ) { } +static inline void kaslr_check_padding (void ) { }#endif /* CONFIG_RANDOMIZE_MEMORY */ #endif
arch/x86/include/asm/setup.h +0 -2
@@ -80,8 +80,6 @@ static inline unsigned long kaslr_offset(void)return (unsigned long )&_text - __START_KERNEL; } -extern int rand_mem_physical_padding; -/* * Do NOT EVER look at the BIOS memory size location. * It does not work on many machines.
arch/x86/mm/kaslr.c +17 -1
@@ -40,7 +40,7 @@*/ static const unsigned long vaddr_end =CPU_ENTRY_AREA_BASE ; -int __initdata rand_mem_physical_padding =CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING ; +static int __initdata rand_mem_physical_padding =CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING ;/* * Memory regions randomized by KASLR (except modules that use a separate logic * earlier during boot). The list is ordered based on virtual addresses. This
@@ -70,6 +70,22 @@ static inline bool kaslr_memory_enabled(void)return kaslr_enabled () && !IS_ENABLED (CONFIG_KASAN ); } +/* +* Check the padding size for KASLR is enough. +*/ +void kaslr_check_padding (void ) +{ +u64 max_possible_phys, max_actual_phys, threshold; + + max_actual_phys =roundup (PFN_PHYS (max_pfn),1ULL <<40 ); + max_possible_phys =roundup (PFN_PHYS (max_possible_pfn),1ULL <<40 ); + threshold = max_actual_phys + ((u64 )rand_mem_physical_padding <<40 ); + +if (max_possible_phys > threshold) +pr_warn ("Set 'rand_mem_physical_padding=%llu' to avoid memory hotadd failure.\n" , + (max_possible_phys - max_actual_phys) >>40 ); +} +static int __init rand_mem_physical_padding_setup (char *str) {int max_padding = (1 << (MAX_PHYSMEM_BITS -TB_SHIFT )) -1 ;
drivers/acpi/numa.c +3 -12
@@ -32,7 +32,7 @@#include <linux/numa.h> #include <linux/nodemask.h> #include <linux/topology.h> -#include <asm/setup.h> +#include <asm/kaslr.h> static nodemask_t nodes_found_map =NODE_MASK_NONE ;
@@ -436,7 +436,6 @@ acpi_table_parse_srat(enum acpi_srat_type id,int __init acpi_numa_init (void ) {int cnt =0 ; -u64 max_possible_phys, max_actual_phys, threshold;if (acpi_disabled)return -EINVAL ;
@@ -466,17 +465,9 @@ int __init acpi_numa_init(void) cnt =acpi_table_parse_srat (ACPI_SRAT_TYPE_MEMORY_AFFINITY , acpi_parse_memory_affinity,0 ); -/* check the padding size for KASLR is enough. */ -if (parsed_numa_memblks &&kaslr_enabled ()) { - max_actual_phys =roundup (PFN_PHYS (max_pfn),1ULL <<40 ); - max_possible_phys =roundup (PFN_PHYS (max_possible_pfn),1ULL <<40 ); - threshold = max_actual_phys + ((u64 )rand_mem_physical_padding <<40 ); +if (parsed_numa_memblks) +kaslr_check_padding (); -if (max_possible_phys > threshold) { -pr_warn ("Set 'rand_mem_physical_padding=%llu' to avoid memory hotadd failure.\n" , - (max_possible_phys - max_actual_phys) >>40 ); - } - } }/* SLIT: System Locality Information Table */
Signature · 7 lines
2.19.0.271.gfe8321ec057f
--
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [tip:x86/boot] ACPI/NUMA: Add warning message if the padding size for KASLR is not enough
Quoted 7 lines · Borislav Petkov
Quoted 6 lines · Peter Zijlstra
Subject: ACPI/NUMA: Fix KASLR build error
There is no point in trying to compile KASLR specific code when there is no KASLR.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Peter Zijlstra (Intel) <[email protected]>---
Yeah, Peter and I were just talking on IRC and he gave me a much better idea how to fix this, see below. I'll run this through the *config builder and commit it if no complaints.
Hi Boris and Peter,
Thank you for the fix. It is great!
- Masa
Quoted 141 lines
---
From: "Peter Zijlstra (Intel)" <[email protected]>
Date: Wed, 3 Oct 2018 14:41:27 +0200
Subject: [PATCH] ACPI/NUMA: Fix KASLR build errorThere is no point in trying to compile KASLR specific code when there is no KASLR.
[ bp: Move the whole crap into
kaslr.cand make
rand_mem_physical_paddingstatic. ]Signed-off-by Peter Zijlstra (Intel) <[email protected]>Signed-off-by Borislav Petkov <[email protected]>Cc <[email protected]>Cc <[email protected]>Cc <[email protected]>Cc <[email protected]>Cc <[email protected]>Cc <[email protected]>--- arch/x86/include/asm/kaslr.h | 2 ++ arch/x86/include/asm/setup.h | 2 -- arch/x86/mm/kaslr.c | 18 +++++++++++++++++- drivers/acpi/numa.c | 15 +++------------ 4 files changed, 22 insertions(+), 15 deletions(-)arch/x86/include/asm/kaslr.h +2
-0@@ -6,8 +6,10 @@ unsigned long kaslr_get_random_long(const char *purpose);#ifdef CONFIG_RANDOMIZE_MEMORY void kernel_randomize_memory (void ); +void kaslr_check_padding (void );#else static inline void kernel_randomize_memory (void ) { } +static inline void kaslr_check_padding (void ) { }#endif /* CONFIG_RANDOMIZE_MEMORY */ #endif arch/x86/include/asm/setup.h +0
-2@@ -80,8 +80,6 @@ static inline unsigned long kaslr_offset(void)return (unsigned long )&_text - __START_KERNEL; } -extern int rand_mem_physical_padding; -/* * Do NOT EVER look at the BIOS memory size location. * It does not work on many machines. arch/x86/mm/kaslr.c +17
-1@@ -40,7 +40,7 @@*/ static const unsigned long vaddr_end =CPU_ENTRY_AREA_BASE ; -int __initdata rand_mem_physical_padding =CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING ; +static int __initdata rand_mem_physical_padding =CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING ;/* * Memory regions randomized by KASLR (except modules that use a separate logic * earlier during boot). The list is ordered based on virtual addresses. This @@ -70,6 +70,22 @@ static inline bool kaslr_memory_enabled(void)return kaslr_enabled () && !IS_ENABLED (CONFIG_KASAN ); } +/* +* Check the padding size for KASLR is enough. +*/ +void kaslr_check_padding (void ) +{ +u64 max_possible_phys, max_actual_phys, threshold; + + max_actual_phys =roundup (PFN_PHYS (max_pfn),1ULL <<40 ); + max_possible_phys =roundup (PFN_PHYS (max_possible_pfn),1ULL <<40 ); + threshold = max_actual_phys + ((u64 )rand_mem_physical_padding <<40 ); + +if (max_possible_phys > threshold) +pr_warn ("Set 'rand_mem_physical_padding=%llu' to avoid memory hotadd failure.\n" , + (max_possible_phys - max_actual_phys) >>40 ); +} +static int __init rand_mem_physical_padding_setup (char *str) {int max_padding = (1 << (MAX_PHYSMEM_BITS -TB_SHIFT )) -1 ;drivers/acpi/numa.c +3
-12@@ -32,7 +32,7 @@#include <linux/numa.h> #include <linux/nodemask.h> #include <linux/topology.h> -#include <asm/setup.h> +#include <asm/kaslr.h> static nodemask_t nodes_found_map =NODE_MASK_NONE ;@@ -436,7 +436,6 @@ acpi_table_parse_srat(enum acpi_srat_type id,int __init acpi_numa_init (void ) {int cnt =0 ; -u64 max_possible_phys, max_actual_phys, threshold;if (acpi_disabled)return -EINVAL ;@@ -466,17 +465,9 @@ int __init acpi_numa_init(void) cnt =acpi_table_parse_srat (ACPI_SRAT_TYPE_MEMORY_AFFINITY , acpi_parse_memory_affinity,0 ); -/* check the padding size for KASLR is enough. */ -if (parsed_numa_memblks &&kaslr_enabled ()) { - max_actual_phys =roundup (PFN_PHYS (max_pfn),1ULL <<40 ); - max_possible_phys =roundup (PFN_PHYS (max_possible_pfn),1ULL <<40 ); - threshold = max_actual_phys + ((u64 )rand_mem_physical_padding <<40 ); +if (parsed_numa_memblks) +kaslr_check_padding (); -if (max_possible_phys > threshold) { -pr_warn ("Set 'rand_mem_physical_padding=%llu' to avoid memory hotadd failure.\n" , - (max_possible_phys - max_actual_phys) >>40 ); - } - } }/* SLIT: System Locality Information Table */ Signature · 7 lines
2.19.0.271.gfe8321ec057f -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.
tip-bot for Peter Zijlstra (Intel)
merge bot[tip:x86/boot] x86/kaslr, ACPI/NUMA: Fix KASLR build error
In reply to Peter Zijlstrax86/kaslr, ACPI/NUMA: Fix KASLR build error
Commit-ID: 3a387c6d96e69f1710a3804eb68e1253263298f2 Gitweb: https://git.kernel.org/tip/3a387c6d96e69f1710a3804eb68e1253263298f2 Author: Peter Zijlstra (Intel) <[email protected]> AuthorDate: Wed, 3 Oct 2018 14:41:27 +0200 Committer: Borislav Petkov <[email protected]> CommitDate: Wed, 3 Oct 2018 16:15:49 +0200
x86/kaslr, ACPI/NUMA: Fix KASLR build error
There is no point in trying to compile KASLR-specific code when there is no KASLR.
[ bp: Move the whole crap into kaslr.c and make
rand_mem_physical_padding static. ]
--- arch/x86/include/asm/kaslr.h | 2 ++ arch/x86/include/asm/setup.h | 2 -- arch/x86/mm/kaslr.c | 19 ++++++++++++++++++- drivers/acpi/numa.c | 15 +++------------ 4 files changed, 23 insertions(+), 15 deletions(-)
arch/x86/include/asm/kaslr.h +2 -0
@@ -6,8 +6,10 @@ unsigned long kaslr_get_random_long(const char *purpose);#ifdef CONFIG_RANDOMIZE_MEMORY void kernel_randomize_memory (void ); +void kaslr_check_padding (void );#else static inline void kernel_randomize_memory (void ) { } +static inline void kaslr_check_padding (void ) { }#endif /* CONFIG_RANDOMIZE_MEMORY */ #endif
arch/x86/include/asm/setup.h +0 -2
@@ -80,8 +80,6 @@ static inline unsigned long kaslr_offset(void)return (unsigned long )&_text - __START_KERNEL; } -extern int rand_mem_physical_padding; -/* * Do NOT EVER look at the BIOS memory size location. * It does not work on many machines.
arch/x86/mm/kaslr.c +18 -1
@@ -23,6 +23,7 @@#include <linux/kernel.h> #include <linux/init.h> #include <linux/random.h> +#include <linux/bootmem.h> #include <asm/pgalloc.h> #include <asm/pgtable.h>
@@ -40,7 +41,7 @@*/ static const unsigned long vaddr_end =CPU_ENTRY_AREA_BASE ; -int __initdata rand_mem_physical_padding =CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING ; +static int __initdata rand_mem_physical_padding =CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING ;/* * Memory regions randomized by KASLR (except modules that use a separate logic * earlier during boot). The list is ordered based on virtual addresses. This
@@ -70,6 +71,22 @@ static inline bool kaslr_memory_enabled(void)return kaslr_enabled () && !IS_ENABLED (CONFIG_KASAN ); } +/* +* Check the padding size for KASLR is enough. +*/ +void __init kaslr_check_padding (void ) +{ +u64 max_possible_phys, max_actual_phys, threshold; + + max_actual_phys =roundup (PFN_PHYS (max_pfn),1ULL <<40 ); + max_possible_phys =roundup (PFN_PHYS (max_possible_pfn),1ULL <<40 ); + threshold = max_actual_phys + ((u64 )rand_mem_physical_padding <<40 ); + +if (max_possible_phys > threshold) +pr_warn ("Set 'rand_mem_physical_padding=%llu' to avoid memory hotadd failure.\n" , + (max_possible_phys - max_actual_phys) >>40 ); +} +static int __init rand_mem_physical_padding_setup (char *str) {int max_padding = (1 << (MAX_PHYSMEM_BITS -TB_SHIFT )) -1 ;
drivers/acpi/numa.c +3 -12
@@ -32,7 +32,7 @@#include <linux/numa.h> #include <linux/nodemask.h> #include <linux/topology.h> -#include <asm/setup.h> +#include <asm/kaslr.h> static nodemask_t nodes_found_map =NODE_MASK_NONE ;
@@ -436,7 +436,6 @@ acpi_table_parse_srat(enum acpi_srat_type id,int __init acpi_numa_init (void ) {int cnt =0 ; -u64 max_possible_phys, max_actual_phys, threshold;if (acpi_disabled)return -EINVAL ;
@@ -466,17 +465,9 @@ int __init acpi_numa_init(void) cnt =acpi_table_parse_srat (ACPI_SRAT_TYPE_MEMORY_AFFINITY , acpi_parse_memory_affinity,0 ); -/* check the padding size for KASLR is enough. */ -if (parsed_numa_memblks &&kaslr_enabled ()) { - max_actual_phys =roundup (PFN_PHYS (max_pfn),1ULL <<40 ); - max_possible_phys =roundup (PFN_PHYS (max_possible_pfn),1ULL <<40 ); - threshold = max_actual_phys + ((u64 )rand_mem_physical_padding <<40 ); +if (parsed_numa_memblks) +kaslr_check_padding (); -if (max_possible_phys > threshold) { -pr_warn ("Set 'rand_mem_physical_padding=%llu' to avoid memory hotadd failure.\n" , - (max_possible_phys - max_actual_phys) >>40 ); - } - } }/* SLIT: System Locality Information Table */
Re: [tip:x86/boot] x86/kaslr, ACPI/NUMA: Fix KASLR build error
Linux next build for arm64 failed due to
numa.c:34:10: fatal error: asm/kaslr.h: No such file or directory
Quoted 10 lines · tip-bot for Peter Zijlstra (Intel)
Commit-ID: 3a387c6d96e69f1710a3804eb68e1253263298f2 Gitweb: https://git.kernel.org/tip/3a387c6d96e69f1710a3804eb68e1253263298f2 Author: Peter Zijlstra (Intel) <[email protected]> AuthorDate: Wed, 3 Oct 2018 14:41:27 +0200 Committer: Borislav Petkov <[email protected]> CommitDate: Wed, 3 Oct 2018 16:15:49 +0200x86/kaslr, ACPI/NUMA: Fix KASLR build error
Quoted 7 lines
There is no point in trying to compile KASLR-specific code when there is no KASLR.
[ bp: Move the whole crap into
kaslr.cand make
rand_mem_physical_paddingstatic. ]Signed-off-by Peter Zijlstra (Intel) <[email protected]>
<trim>
drivers/acpi/numa.c line 35
Quoted 10 lines
drivers/acpi/numa.c +1
-1@@ -32,7 +32,7 @@#include <linux/numa.h> #include <linux/nodemask.h> #include <linux/topology.h> -#include <asm/setup.h> +#include <asm/kaslr.h>
kernel-source/drivers/acpi/numa.c:34:10: fatal error: asm/kaslr.h: No such file or directory
#include <asm/kaslr.h>
^~~~~~~~~~~~~compilation terminated. kernel-source/scripts/Makefile.build:295: recipe for target 'drivers/acpi/numa.o' failed
make[4]: *** [drivers/acpi/numa.o] Error 1 make[4]: *** Waiting for unfinished jobs....
CC lib/win_minmax.o
CC drivers/base/soc.o
kernel-source/scripts/Makefile.build:520: recipe for target 'drivers/acpi' failed
make[3]: *** [drivers/acpi] Error 2
Re: [tip:x86/boot] x86/kaslr, ACPI/NUMA: Fix KASLR build error
Quoted 2 lines · Naresh Kamboju
Linux next build for arm64 failed due to
numa.c:34:10: fatal error:asm/kaslr.h: No such file or directory
Thanks for letting me know, I guess we could fix that with a weak function:
--- arch/x86/include/asm/kaslr.h | 2 -- drivers/acpi/numa.c | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/include/asm/kaslr.h +0 -2
@@ -6,10 +6,8 @@ unsigned long kaslr_get_random_long(const char *purpose);#ifdef CONFIG_RANDOMIZE_MEMORY void kernel_randomize_memory (void ); -void kaslr_check_padding (void );#else static inline void kernel_randomize_memory (void ) { } -static inline void kaslr_check_padding (void ) { }#endif /* CONFIG_RANDOMIZE_MEMORY */ #endif
drivers/acpi/numa.c +3 -1
@@ -32,7 +32,6 @@#include <linux/numa.h> #include <linux/nodemask.h> #include <linux/topology.h> -#include <asm/kaslr.h> static nodemask_t nodes_found_map =NODE_MASK_NONE ;
@@ -433,6 +432,9 @@ acpi_table_parse_srat(enum acpi_srat_type id, handler, max_entries); } +/* To be overridden by architectures */ +void __init __weak kaslr_check_padding (void ) { } +int __init acpi_numa_init (void ) {int cnt =0 ;
Signature · 7 lines
2.19.0.271.gfe8321ec057f
--
Regards/Gruss,
Boris.
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)Re: [tip:x86/boot] x86/kaslr, ACPI/NUMA: Fix KASLR build error
Quoted 10 lines · Borislav Petkov
Quoted 2 lines · Naresh Kamboju
Linux next build for arm64 failed due to
numa.c:34:10: fatal error:asm/kaslr.h: No such file or directoryThanks for letting me know, I guess we could fix that with a weak function:
drivers/acpi/numa.c acpi_table_parse_srat(enum acpi_srat_type id, · line 440
Quoted 6 lines
drivers/acpi/numa.c +3
-0+/* To be overridden by architectures */ +void __init __weak kaslr_check_padding (void ) { } +int __init acpi_numa_init (void ) {int cnt =0 ;
I think __weak functions are too fragile, when you do this and it turns out that another architecture does need to do something, you won't ever get any indication of it.
If we know that arm64 doesn't need to do anything here, just add an arch/arm64/include/asm/kaslr.h with an empty function there.
Arnd
Re: [tip:x86/boot] x86/kaslr, ACPI/NUMA: Fix KASLR build error
Quoted 7 lines · Arnd Bergmann
I think
__weakfunctions are too fragile, when you do this and it turns out that another architecture does need to do something, you won't ever get any indication of it.If we know that arm64 doesn't need to do anything here, just add an
arch/arm64/include/asm/kaslr.hwith an empty function there.
I'm looking at fs/proc/vmcore.c and all those other weak functions there and just doing the same.
Also, judging by
$ git grep CONFIG_PROC_VMCORE
output, ia64, mips and powerpc would need that include too.
Signature · 4 lines
Regards/Gruss,
Boris.
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)tip-bot for Peter Zijlstra (Intel)
merge bot[tip:x86/boot] x86/kaslr, ACPI/NUMA: Fix KASLR build error
In reply to Peter Zijlstrax86/kaslr, ACPI/NUMA: Fix KASLR build error
Commit-ID: 9d94e8b1d4f94a3c4cee5ad11a1be460cd070839 Gitweb: https://git.kernel.org/tip/9d94e8b1d4f94a3c4cee5ad11a1be460cd070839 Author: Peter Zijlstra (Intel) <[email protected]> AuthorDate: Wed, 3 Oct 2018 14:41:27 +0200 Committer: Borislav Petkov <[email protected]> CommitDate: Tue, 9 Oct 2018 12:30:25 +0200
x86/kaslr, ACPI/NUMA: Fix KASLR build error
There is no point in trying to compile KASLR-specific code when there is no KASLR.
[ bp: Move the whole crap into kaslr.c and make
rand_mem_physical_padding static. Make kaslr_check_padding() weak to avoid build breakage on other architectures. ]
--- arch/x86/include/asm/setup.h | 2 -- arch/x86/mm/kaslr.c | 19 ++++++++++++++++++- drivers/acpi/numa.c | 17 +++++------------ 3 files changed, 23 insertions(+), 15 deletions(-)
arch/x86/include/asm/setup.h +0 -2
@@ -80,8 +80,6 @@ static inline unsigned long kaslr_offset(void)return (unsigned long )&_text - __START_KERNEL; } -extern int rand_mem_physical_padding; -/* * Do NOT EVER look at the BIOS memory size location. * It does not work on many machines.
arch/x86/mm/kaslr.c +18 -1
@@ -23,6 +23,7 @@#include <linux/kernel.h> #include <linux/init.h> #include <linux/random.h> +#include <linux/bootmem.h> #include <asm/pgalloc.h> #include <asm/pgtable.h>
@@ -40,7 +41,7 @@*/ static const unsigned long vaddr_end =CPU_ENTRY_AREA_BASE ; -int __initdata rand_mem_physical_padding =CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING ; +static int __initdata rand_mem_physical_padding =CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING ;/* * Memory regions randomized by KASLR (except modules that use a separate logic * earlier during boot). The list is ordered based on virtual addresses. This
@@ -70,6 +71,22 @@ static inline bool kaslr_memory_enabled(void)return kaslr_enabled () && !IS_ENABLED (CONFIG_KASAN ); } +/* +* Check the padding size for KASLR is enough. +*/ +void __init kaslr_check_padding (void ) +{ +u64 max_possible_phys, max_actual_phys, threshold; + + max_actual_phys =roundup (PFN_PHYS (max_pfn),1ULL <<40 ); + max_possible_phys =roundup (PFN_PHYS (max_possible_pfn),1ULL <<40 ); + threshold = max_actual_phys + ((u64 )rand_mem_physical_padding <<40 ); + +if (max_possible_phys > threshold) +pr_warn ("Set 'rand_mem_physical_padding=%llu' to avoid memory hotadd failure.\n" , + (max_possible_phys - max_actual_phys) >>40 ); +} +static int __init rand_mem_physical_padding_setup (char *str) {int max_padding = (1 << (MAX_PHYSMEM_BITS -TB_SHIFT )) -1 ;
drivers/acpi/numa.c +5 -12
@@ -32,7 +32,6 @@#include <linux/numa.h> #include <linux/nodemask.h> #include <linux/topology.h> -#include <asm/setup.h> static nodemask_t nodes_found_map =NODE_MASK_NONE ;
@@ -433,10 +432,12 @@ acpi_table_parse_srat(enum acpi_srat_type id, handler, max_entries); } +/* To be overridden by architectures */ +void __init __weak kaslr_check_padding (void ) { } +int __init acpi_numa_init (void ) {int cnt =0 ; -u64 max_possible_phys, max_actual_phys, threshold;if (acpi_disabled)return -EINVAL ;
@@ -466,17 +467,9 @@ int __init acpi_numa_init(void) cnt =acpi_table_parse_srat (ACPI_SRAT_TYPE_MEMORY_AFFINITY , acpi_parse_memory_affinity,0 ); -/* check the padding size for KASLR is enough. */ -if (parsed_numa_memblks &&kaslr_enabled ()) { - max_actual_phys =roundup (PFN_PHYS (max_pfn),1ULL <<40 ); - max_possible_phys =roundup (PFN_PHYS (max_possible_pfn),1ULL <<40 ); - threshold = max_actual_phys + ((u64 )rand_mem_physical_padding <<40 ); +if (parsed_numa_memblks) +kaslr_check_padding (); -if (max_possible_phys > threshold) { -pr_warn ("Set 'rand_mem_physical_padding=%llu' to avoid memory hotadd failure.\n" , - (max_possible_phys - max_actual_phys) >>40 ); - } - } }/* SLIT: System Locality Information Table */
PATCH v5 3/3 docs: kernel-parameters.txt: document rand_mem_physical_padding
In reply to Masayoshi MizumaFrom: Masayoshi Mizuma <[email protected]>
This kernel parameter allows to change the padding used for the physical memory mapping section when KASLR memory is enabled.
For memory hotplug capable systems, the default padding size, CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING, may not be enough. The option is useful to adjust the padding size.
--- .../admin-guide/kernel-parameters.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +18 -0
@@ -3529,6 +3529,24 @@ fully seed the kernel's CRNG. Default is controlled by CONFIG_RANDOM_TRUST_CPU. + rand_mem_physical_padding= + [KNL] Define the padding size in terabytes + used for the physical memory mapping section + when KASLR is enabled. + If the padding size is not enough, you can see + 'Set rand_mem_physical_padding=XX ...' in system + boot message, so set the parameter as the message. + + This parameter is useful for the memory hot-add capable + system. Such system may have more space than + actual memory size to hot-add memory. If the + padding size is not enough and a memory is hot-added, + the hot-adding will fail because it destroys the + system memory map. So, the padding size is needed to + adjust in such system. + The default value is + CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING. + ras=option[,option,...] [KNL] RAS-specific options cec_disable [X86]
Signature · 1 line
2.18.0
tip-bot for Masayoshi Mizuma
merge bot[tip:x86/boot] Documentation/kernel-parameters.txt: Document rand_mem_physical_padding=
Documentation/kernel-parameters.txt: Document rand_mem_physical_padding=
Commit-ID: 2d580c160ada91049fc24b244ed74d8775bd1c96 Gitweb: https://git.kernel.org/tip/2d580c160ada91049fc24b244ed74d8775bd1c96 Author: Masayoshi Mizuma <[email protected]> AuthorDate: Mon, 1 Oct 2018 10:08:43 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 2 Oct 2018 11:47:22 +0200
Documentation/kernel-parameters.txt: Document rand_mem_physical_padding=
This kernel parameter allows the modification of the padding used for the physical memory mapping section when KASLR memory is enabled.
For memory hotplug capable systems, the default padding size, CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING, may not be enough.
The option is useful to adjust the padding size.
--- Documentation/admin-guide/kernel-parameters.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +18 -0
@@ -3529,6 +3529,24 @@ fully seed the kernel's CRNG. Default is controlled by CONFIG_RANDOM_TRUST_CPU. + rand_mem_physical_padding= + [KNL] Define the padding size in terabytes + used for the physical memory mapping section + when KASLR is enabled. + If the padding size is not enough, you can see + 'Set rand_mem_physical_padding=XX ...' in system + boot message, so set the parameter as the message suggests. + + This parameter is useful for memory hot-add capable + systems. Such systems may have more space than + actual memory size to hot-add memory. If the + padding size is not enough and memory is hot-added, + the hot-adding will fail because it destroys the + system memory map. So, the padding size needs to be + adjusted in such a system. + The default value is the value of + CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING. + ras=option[,option,...] [KNL] RAS-specific options cec_disable [X86]