Add a kernel parameter to change the padding size for KASLR
Subsystems (4)
v4 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 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 an option 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
parameter
Documentation/admin-guide/kernel-parameters.txt | 7 +++++++ arch/x86/include/asm/setup.h | 2 ++ arch/x86/mm/kaslr.c | 17 ++++++++++++++++- drivers/acpi/numa.c | 14 ++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-)
Signature · 1 line
2.18.0
PATCH v4 1/3 x86/mm: Add a kernel parameter to change the padding used for the physical memory mapping
From: Masayoshi Mizuma <[email protected]>
If the physical memory layout has huge space for memory hotplug, the padding used for the physical memory mapping section is not enough. For example 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 physical memory layout defined by SRAT. 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
PATCH v4 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 | 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,8 @@ acpi_table_parse_srat(enum acpi_srat_type id,int __init acpi_numa_init (void ) {int cnt =0 ; +u32 max_phys_addr_tb; +u64 max_phys_addr;if (acpi_disabled)return -EINVAL ;
@@ -463,6 +466,17 @@ int __init acpi_numa_init(void) cnt =acpi_table_parse_srat (ACPI_SRAT_TYPE_MEMORY_AFFINITY , acpi_parse_memory_affinity,0 ); + +if (parsed_numa_memblks &&kaslr_enabled ()) { + max_phys_addr =PFN_PHYS (max_possible_pfn); + max_phys_addr_tb = (roundup (max_phys_addr,1ULL <<40 )) >>40 ; + +if (max_phys_addr_tb > rand_mem_physical_padding) +pr_warn ("Set 'rand_mem_physical_padding=%d' " +"as the kernel parameter. " +"Otherwise, memory hotadd may be failed.\n" , + max_phys_addr_tb); + } }/* SLIT: System Locality Information Table */
Signature · 1 line
2.18.0
Borislav Petkov
maintainerRe: [PATCH v4 2/3] ACPI / NUMA: Add warning message if the padding size for KASLR is not enough
Quoted 50 lines · Masayoshi Mizuma
From: 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.Signed-off-by Masayoshi Mizuma <[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 +3
-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,8 @@ acpi_table_parse_srat(enum acpi_srat_type id,int __init acpi_numa_init (void ) {int cnt =0 ; +u32 max_phys_addr_tb; +u64 max_phys_addr;if (acpi_disabled)return -EINVAL ;@@ -463,6 +466,17 @@ int __init acpi_numa_init(void) cnt =acpi_table_parse_srat (ACPI_SRAT_TYPE_MEMORY_AFFINITY , acpi_parse_memory_affinity,0 );
drivers/acpi/numa.c int __init acpi_numa_init(void) · line 478
Quoted 10 lines
drivers/acpi/numa.c +10
-0+ +if (parsed_numa_memblks &&kaslr_enabled ()) { + max_phys_addr =PFN_PHYS (max_possible_pfn); + max_phys_addr_tb = (roundup (max_phys_addr,1ULL <<40 )) >>40 ; + +if (max_phys_addr_tb > rand_mem_physical_padding) +pr_warn ("Set 'rand_mem_physical_padding=%d' " +"as the kernel parameter. " +"Otherwise, memory hotadd may be failed.\n" , + max_phys_addr_tb);
Please integrate scripts/checkpatch.pl into your patch creation workflow. Some of the warnings/errors *actually* make sense:
WARNING: quoted string split across lines
#75: FILE: drivers/acpi/numa.c:476:
+ pr_warn("Set 'rand_mem_physical_padding=%d' "
+ "as the kernel parameter. "
WARNING: quoted string split across lines
#76: FILE: drivers/acpi/numa.c:477:
+ "as the kernel parameter. "
+ "Otherwise, memory hotadd may be failed.\n",
total: 0 errors, 2 warnings, 40 lines checked
Also, that sentence needs polishing:
pr_warn("Set 'rand_mem_physical_padding=%d' to avoid memory hotadd failure.\n",
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [PATCH v4 2/3] ACPI / NUMA: Add warning message if the padding size for KASLR is not enough
Quoted 75 lines · Borislav Petkov
Quoted 50 lines · Masayoshi Mizuma
From: 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.Signed-off-by Masayoshi Mizuma <[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 +3
-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,8 @@ acpi_table_parse_srat(enum acpi_srat_type id,int __init acpi_numa_init (void ) {int cnt =0 ; +u32 max_phys_addr_tb; +u64 max_phys_addr;if (acpi_disabled)return -EINVAL ;@@ -463,6 +466,17 @@ int __init acpi_numa_init(void) cnt =acpi_table_parse_srat (ACPI_SRAT_TYPE_MEMORY_AFFINITY , acpi_parse_memory_affinity,0 );drivers/acpi/numa.c int __init acpi_numa_init(void) · line 478
Quoted 10 lines
drivers/acpi/numa.c +10
-0+ +if (parsed_numa_memblks &&kaslr_enabled ()) { + max_phys_addr =PFN_PHYS (max_possible_pfn); + max_phys_addr_tb = (roundup (max_phys_addr,1ULL <<40 )) >>40 ; + +if (max_phys_addr_tb > rand_mem_physical_padding) +pr_warn ("Set 'rand_mem_physical_padding=%d' " +"as the kernel parameter. " +"Otherwise, memory hotadd may be failed.\n" , + max_phys_addr_tb);Please integrate
scripts/checkpatch.plinto your patch creation workflow. Some of the warnings/errors *actually* make sense:WARNING: quoted string split across lines
#75: FILE:drivers/acpi/numa.c:476:drivers/acpi/numa.c +2
-0+pr_warn ("Set 'rand_mem_physical_padding=%d' " + "as the kernel parameter. "WARNING: quoted string split across lines
#76: FILE:drivers/acpi/numa.c:477:drivers/acpi/numa.c +2
-0+"as the kernel parameter. " + "Otherwise, memory hotadd may be failed.\n",
Quoted 5 lines
total: 0 errors, 2 warnings, 40 lines checked
Also, that sentence needs polishing:
pr_warn("Set 'rand_mem_physical_padding=%d' to avoid memory hotadd failure.\n",
Thank you for pointing it out.
I'll fix it.
Thnaks,
Masa
Quoted 7 lines
Signature · 5 lines
-- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.
Re: [PATCH v4 2/3] ACPI / NUMA: Add warning message if the padding size for KASLR is not enough
In reply to Masayoshi MizumaQuoted 47 lines · Masayoshi Mizuma
From: 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.Signed-off-by Masayoshi Mizuma <[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 +3
-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,8 @@ acpi_table_parse_srat(enum acpi_srat_type id,int __init acpi_numa_init (void ) {int cnt =0 ; +u32 max_phys_addr_tb; +u64 max_phys_addr;if (acpi_disabled)return -EINVAL ;
drivers/acpi/numa.c int __init acpi_numa_init(void) · line 474
Quoted 9 lines
drivers/acpi/numa.c +6
-0@@ -463,6 +466,17 @@ int __init acpi_numa_init(void) cnt =acpi_table_parse_srat (ACPI_SRAT_TYPE_MEMORY_AFFINITY , acpi_parse_memory_affinity,0 ); + +if (parsed_numa_memblks &&kaslr_enabled ()) { + max_phys_addr =PFN_PHYS (max_possible_pfn); + max_phys_addr_tb = (roundup (max_phys_addr,1ULL <<40 )) >>40 ; + +if (max_phys_addr_tb > rand_mem_physical_padding)
Here I assume max_phys_addr_tb is the end of the possible RAM in system. rand_mem_physical_padding is the preserved space for later memory extending. Don't we add the actual RAM size to the rand_mem_physical_padding, then compare with max_phys_addr_tb?
Please correct me if I am wrong.
Thanks
Baoquan
Quoted 11 lines
drivers/acpi/numa.c +5
-0+pr_warn ("Set 'rand_mem_physical_padding=%d' " +"as the kernel parameter. " +"Otherwise, memory hotadd may be failed.\n" , + max_phys_addr_tb); + } }/* SLIT: System Locality Information Table */ Signature · 1 line
2.18.0
Re: [PATCH v4 2/3] ACPI / NUMA: Add warning message if the padding size for KASLR is not enough
Quoted 49 lines · Baoquan He
Quoted 48 lines · Masayoshi Mizuma
From: 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.Signed-off-by Masayoshi Mizuma <[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 +3
-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,8 @@ acpi_table_parse_srat(enum acpi_srat_type id,int __init acpi_numa_init (void ) {int cnt =0 ; +u32 max_phys_addr_tb; +u64 max_phys_addr;if (acpi_disabled)return -EINVAL ;@@ -463,6 +466,17 @@ int __init acpi_numa_init(void)
Quoted 10 lines
drivers/acpi/numa.c int __init acpi_numa_init(void) · line 474
Quoted 8 lines
drivers/acpi/numa.c +6
-0cnt =acpi_table_parse_srat (ACPI_SRAT_TYPE_MEMORY_AFFINITY , acpi_parse_memory_affinity,0 ); + +if (parsed_numa_memblks &&kaslr_enabled ()) { + max_phys_addr =PFN_PHYS (max_possible_pfn); + max_phys_addr_tb = (roundup (max_phys_addr,1ULL <<40 )) >>40 ; + +if (max_phys_addr_tb > rand_mem_physical_padding)Here I assume
max_phys_addr_tbis the end of the possible RAM in system.
Yes, correct.
Quoted 3 lines
rand_mem_physical_paddingis the preserved space for later memory extending. Don't we add the actual RAM size to therand_mem_physical_padding, then compare withmax_phys_addr_tb?
This is very good point! You are right, the padding should be adjusted to exceed the possible RAM size, like as follows.
ADDRESS
0
:
1TB <= actual RAM size
:
2TB <= possible RAM size
2TB and more <= actual + padding size (kaslr_regions[0].size_tb)
I'll fix it, thanks!
- Masa
Quoted 17 lines
Please correct me if I am wrong.
Thanks
BaoquanQuoted 11 lines
drivers/acpi/numa.c +5
-0+pr_warn ("Set 'rand_mem_physical_padding=%d' " +"as the kernel parameter. " +"Otherwise, memory hotadd may be failed.\n" , + max_phys_addr_tb); + } }/* SLIT: System Locality Information Table */ Signature · 1 line
2.18.0
PATCH v4 3/3 docs: kernel-parameters.txt: document rand_mem_physical_padding parameter
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.
--- Documentation/admin-guide/kernel-parameters.txt | 7 +++++++ 1 file changed, 7 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +7 -0
@@ -3529,6 +3529,13 @@ 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 memory is enabled. + 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
Borislav Petkov
maintainerRe: [PATCH v4 3/3] docs: kernel-parameters.txt: document rand_mem_physical_padding parameter
Quoted 20 lines · Masayoshi Mizuma
From: 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.Signed-off-by Masayoshi Mizuma <[email protected]>--- Documentation/admin-guide/kernel-parameters.txt | 7 +++++++ 1 file changed, 7 insertions(+)Documentation/admin-guide/kernel-parameters.txt +0
-0
Documentation/admin-guide/kernel-parameters.txt line 3537
Quoted 9 lines
Documentation/admin-guide/kernel-parameters.txt +6
-0@@ -3529,6 +3529,13 @@ 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 memory is enabled. + The default value is + CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING.
Yet another kernel parameter which forces me to go look at what the code does because this help text doesn't really help. And I see that in previous iterations ok lkml it was *actually* properly explained why this parameter is needed.
So please summarize that explanation here so that the user can make an informed decision when reading this help text. Always think of explaning this to a colleague of yours who doesn't know about the memory padding and memory hotadd problematic and try to write it in such a way so that your colleague understands it.
:-)
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [PATCH v4 3/3] docs: kernel-parameters.txt: document rand_mem_physical_padding parameter
Quoted 36 lines · Borislav Petkov
Quoted 20 lines · Masayoshi Mizuma
From: 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.Signed-off-by Masayoshi Mizuma <[email protected]>--- Documentation/admin-guide/kernel-parameters.txt | 7 +++++++ 1 file changed, 7 insertions(+)Documentation/admin-guide/kernel-parameters.txt +0
-0Documentation/admin-guide/kernel-parameters.txt line 3537
Quoted 9 lines
Documentation/admin-guide/kernel-parameters.txt +6
-0@@ -3529,6 +3529,13 @@ 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 memory is enabled. + The default value is + CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING.Yet another kernel parameter which forces me to go look at what the code does because this help text doesn't really help. And I see that in previous iterations ok lkml it was *actually* properly explained why this parameter is needed.
Quoted 7 lines
So please summarize that explanation here so that the user can make an informed decision when reading this help text. Always think of explaning this to a colleague of yours who doesn't know about the memory padding and memory hotadd problematic and try to write it in such a way so that your colleague understands it.
:-)
You are right, I didn't make it clear enough... Thank you for your comments, I'll fix the description.
Thanks!
Masa