linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/3] Add a kernel parameter to change the padding size for KASLR
@ 2018-09-27 20:31 Masayoshi Mizuma
  2018-09-27 20:31 ` [PATCH v4 1/3] x86/mm: Add a kernel parameter to change the padding used for the physical memory mapping Masayoshi Mizuma
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Masayoshi Mizuma @ 2018-09-27 20:31 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	x86, Baoquan He
  Cc: Masayoshi Mizuma, linux-kernel

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(-)

-- 
2.18.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v4 1/3] x86/mm: Add a kernel parameter to change the padding used for the physical memory mapping
  2018-09-27 20:31 [PATCH v4 0/3] Add a kernel parameter to change the padding size for KASLR Masayoshi Mizuma
@ 2018-09-27 20:31 ` Masayoshi Mizuma
  2018-09-27 20:31 ` [PATCH v4 2/3] ACPI / NUMA: Add warning message if the padding size for KASLR is not enough Masayoshi Mizuma
  2018-09-27 20:31 ` [PATCH v4 3/3] docs: kernel-parameters.txt: document rand_mem_physical_padding parameter Masayoshi Mizuma
  2 siblings, 0 replies; 10+ messages in thread
From: Masayoshi Mizuma @ 2018-09-27 20:31 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	x86, Baoquan He
  Cc: Masayoshi Mizuma, Masayoshi Mizuma, linux-kernel

From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>

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.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Reviewed-by: Baoquan He <bhe@redhat.com>
---
 arch/x86/mm/kaslr.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c
index 61db77b..00cf4ca 100644
--- a/arch/x86/mm/kaslr.c
+++ b/arch/x86/mm/kaslr.c
@@ -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)
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v4 2/3] ACPI / NUMA: Add warning message if the padding size for KASLR is not enough
  2018-09-27 20:31 [PATCH v4 0/3] Add a kernel parameter to change the padding size for KASLR Masayoshi Mizuma
  2018-09-27 20:31 ` [PATCH v4 1/3] x86/mm: Add a kernel parameter to change the padding used for the physical memory mapping Masayoshi Mizuma
@ 2018-09-27 20:31 ` Masayoshi Mizuma
  2018-09-27 21:14   ` Borislav Petkov
  2018-09-28  2:48   ` Baoquan He
  2018-09-27 20:31 ` [PATCH v4 3/3] docs: kernel-parameters.txt: document rand_mem_physical_padding parameter Masayoshi Mizuma
  2 siblings, 2 replies; 10+ messages in thread
From: Masayoshi Mizuma @ 2018-09-27 20:31 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	x86, Baoquan He
  Cc: Masayoshi Mizuma, Masayoshi Mizuma, linux-kernel

From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>

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 <m.mizuma@jp.fujitsu.com>
---
 arch/x86/include/asm/setup.h |  2 ++
 drivers/acpi/numa.c          | 14 ++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h
index ae13bc9..65a5bf8 100644
--- a/arch/x86/include/asm/setup.h
+++ b/arch/x86/include/asm/setup.h
@@ -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.
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index 8516760..9c3cc3c 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -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 */
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v4 3/3] docs: kernel-parameters.txt: document rand_mem_physical_padding parameter
  2018-09-27 20:31 [PATCH v4 0/3] Add a kernel parameter to change the padding size for KASLR Masayoshi Mizuma
  2018-09-27 20:31 ` [PATCH v4 1/3] x86/mm: Add a kernel parameter to change the padding used for the physical memory mapping Masayoshi Mizuma
  2018-09-27 20:31 ` [PATCH v4 2/3] ACPI / NUMA: Add warning message if the padding size for KASLR is not enough Masayoshi Mizuma
@ 2018-09-27 20:31 ` Masayoshi Mizuma
  2018-09-27 21:17   ` Borislav Petkov
  2 siblings, 1 reply; 10+ messages in thread
From: Masayoshi Mizuma @ 2018-09-27 20:31 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	x86, Baoquan He
  Cc: Masayoshi Mizuma, Masayoshi Mizuma, linux-kernel

From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>

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 <m.mizuma@jp.fujitsu.com>
---
 Documentation/admin-guide/kernel-parameters.txt | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 92eb1f4..de43cdf 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -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]
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 2/3] ACPI / NUMA: Add warning message if the padding size for KASLR is not enough
  2018-09-27 20:31 ` [PATCH v4 2/3] ACPI / NUMA: Add warning message if the padding size for KASLR is not enough Masayoshi Mizuma
@ 2018-09-27 21:14   ` Borislav Petkov
  2018-09-28  2:21     ` Masayoshi Mizuma
  2018-09-28  2:48   ` Baoquan He
  1 sibling, 1 reply; 10+ messages in thread
From: Borislav Petkov @ 2018-09-27 21:14 UTC (permalink / raw)
  To: Masayoshi Mizuma
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, Baoquan He,
	Masayoshi Mizuma, linux-kernel

On Thu, Sep 27, 2018 at 04:31:45PM -0400, Masayoshi Mizuma wrote:
> From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
> 
> 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 <m.mizuma@jp.fujitsu.com>
> ---
>  arch/x86/include/asm/setup.h |  2 ++
>  drivers/acpi/numa.c          | 14 ++++++++++++++
>  2 files changed, 16 insertions(+)
> 
> diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h
> index ae13bc9..65a5bf8 100644
> --- a/arch/x86/include/asm/setup.h
> +++ b/arch/x86/include/asm/setup.h
> @@ -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.
> diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
> index 8516760..9c3cc3c 100644
> --- a/drivers/acpi/numa.c
> +++ b/drivers/acpi/numa.c
> @@ -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);

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",


-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 3/3] docs: kernel-parameters.txt: document rand_mem_physical_padding parameter
  2018-09-27 20:31 ` [PATCH v4 3/3] docs: kernel-parameters.txt: document rand_mem_physical_padding parameter Masayoshi Mizuma
@ 2018-09-27 21:17   ` Borislav Petkov
  2018-09-28  2:26     ` Masayoshi Mizuma
  0 siblings, 1 reply; 10+ messages in thread
From: Borislav Petkov @ 2018-09-27 21:17 UTC (permalink / raw)
  To: Masayoshi Mizuma
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, Baoquan He,
	Masayoshi Mizuma, linux-kernel

On Thu, Sep 27, 2018 at 04:31:46PM -0400, Masayoshi Mizuma wrote:
> From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
> 
> 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 <m.mizuma@jp.fujitsu.com>
> ---
>  Documentation/admin-guide/kernel-parameters.txt | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index 92eb1f4..de43cdf 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -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.

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 2/3] ACPI / NUMA: Add warning message if the padding size for KASLR is not enough
  2018-09-27 21:14   ` Borislav Petkov
@ 2018-09-28  2:21     ` Masayoshi Mizuma
  0 siblings, 0 replies; 10+ messages in thread
From: Masayoshi Mizuma @ 2018-09-28  2:21 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, Baoquan He,
	Masayoshi Mizuma, linux-kernel

On Thu, Sep 27, 2018 at 11:14:25PM +0200, Borislav Petkov wrote:
> On Thu, Sep 27, 2018 at 04:31:45PM -0400, Masayoshi Mizuma wrote:
> > From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
> > 
> > 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 <m.mizuma@jp.fujitsu.com>
> > ---
> >  arch/x86/include/asm/setup.h |  2 ++
> >  drivers/acpi/numa.c          | 14 ++++++++++++++
> >  2 files changed, 16 insertions(+)
> > 
> > diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h
> > index ae13bc9..65a5bf8 100644
> > --- a/arch/x86/include/asm/setup.h
> > +++ b/arch/x86/include/asm/setup.h
> > @@ -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.
> > diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
> > index 8516760..9c3cc3c 100644
> > --- a/drivers/acpi/numa.c
> > +++ b/drivers/acpi/numa.c
> > @@ -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);
> 
> 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",

Thank you for pointing it out.
I'll fix it.

Thnaks,
Masa

> 
> 
> -- 
> Regards/Gruss,
>     Boris.
> 
> Good mailing practices for 400: avoid top-posting and trim the reply.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 3/3] docs: kernel-parameters.txt: document rand_mem_physical_padding parameter
  2018-09-27 21:17   ` Borislav Petkov
@ 2018-09-28  2:26     ` Masayoshi Mizuma
  0 siblings, 0 replies; 10+ messages in thread
From: Masayoshi Mizuma @ 2018-09-28  2:26 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, Baoquan He,
	Masayoshi Mizuma, linux-kernel

On Thu, Sep 27, 2018 at 11:17:47PM +0200, Borislav Petkov wrote:
> On Thu, Sep 27, 2018 at 04:31:46PM -0400, Masayoshi Mizuma wrote:
> > From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
> > 
> > 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 <m.mizuma@jp.fujitsu.com>
> > ---
> >  Documentation/admin-guide/kernel-parameters.txt | 7 +++++++
> >  1 file changed, 7 insertions(+)
> > 
> > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> > index 92eb1f4..de43cdf 100644
> > --- a/Documentation/admin-guide/kernel-parameters.txt
> > +++ b/Documentation/admin-guide/kernel-parameters.txt
> > @@ -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.
> 
> :-)

You are right, I didn't make it clear enough...
Thank you for your comments, I'll fix the description.

Thanks!
Masa

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 2/3] ACPI / NUMA: Add warning message if the padding size for KASLR is not enough
  2018-09-27 20:31 ` [PATCH v4 2/3] ACPI / NUMA: Add warning message if the padding size for KASLR is not enough Masayoshi Mizuma
  2018-09-27 21:14   ` Borislav Petkov
@ 2018-09-28  2:48   ` Baoquan He
  2018-09-28 14:26     ` Masayoshi Mizuma
  1 sibling, 1 reply; 10+ messages in thread
From: Baoquan He @ 2018-09-28  2:48 UTC (permalink / raw)
  To: Masayoshi Mizuma
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	x86, Masayoshi Mizuma, linux-kernel

On 09/27/18 at 04:31pm, Masayoshi Mizuma wrote:
> From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
> 
> 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 <m.mizuma@jp.fujitsu.com>
> ---
>  arch/x86/include/asm/setup.h |  2 ++
>  drivers/acpi/numa.c          | 14 ++++++++++++++
>  2 files changed, 16 insertions(+)
> 
> diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h
> index ae13bc9..65a5bf8 100644
> --- a/arch/x86/include/asm/setup.h
> +++ b/arch/x86/include/asm/setup.h
> @@ -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.
> diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
> index 8516760..9c3cc3c 100644
> --- a/drivers/acpi/numa.c
> +++ b/drivers/acpi/numa.c
> @@ -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)

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

> +				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 */
> -- 
> 2.18.0
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 2/3] ACPI / NUMA: Add warning message if the padding size for KASLR is not enough
  2018-09-28  2:48   ` Baoquan He
@ 2018-09-28 14:26     ` Masayoshi Mizuma
  0 siblings, 0 replies; 10+ messages in thread
From: Masayoshi Mizuma @ 2018-09-28 14:26 UTC (permalink / raw)
  To: Baoquan He
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	x86, Masayoshi Mizuma, linux-kernel

On Fri, Sep 28, 2018 at 10:48:57AM +0800, Baoquan He wrote:
> On 09/27/18 at 04:31pm, Masayoshi Mizuma wrote:
> > From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
> > 
> > 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 <m.mizuma@jp.fujitsu.com>
> > ---
> >  arch/x86/include/asm/setup.h |  2 ++
> >  drivers/acpi/numa.c          | 14 ++++++++++++++
> >  2 files changed, 16 insertions(+)
> > 
> > diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h
> > index ae13bc9..65a5bf8 100644
> > --- a/arch/x86/include/asm/setup.h
> > +++ b/arch/x86/include/asm/setup.h
> > @@ -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.
> > diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
> > index 8516760..9c3cc3c 100644
> > --- a/drivers/acpi/numa.c
> > +++ b/drivers/acpi/numa.c
> > @@ -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)
> 
> Here I assume max_phys_addr_tb is the end of the possible RAM in system.

Yes, correct.

> 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?

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

> 
> Please correct me if I am wrong.
> 
> Thanks
> Baoquan
> 
> > +				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 */
> > -- 
> > 2.18.0
> > 

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-09-28 14:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-27 20:31 [PATCH v4 0/3] Add a kernel parameter to change the padding size for KASLR Masayoshi Mizuma
2018-09-27 20:31 ` [PATCH v4 1/3] x86/mm: Add a kernel parameter to change the padding used for the physical memory mapping Masayoshi Mizuma
2018-09-27 20:31 ` [PATCH v4 2/3] ACPI / NUMA: Add warning message if the padding size for KASLR is not enough Masayoshi Mizuma
2018-09-27 21:14   ` Borislav Petkov
2018-09-28  2:21     ` Masayoshi Mizuma
2018-09-28  2:48   ` Baoquan He
2018-09-28 14:26     ` Masayoshi Mizuma
2018-09-27 20:31 ` [PATCH v4 3/3] docs: kernel-parameters.txt: document rand_mem_physical_padding parameter Masayoshi Mizuma
2018-09-27 21:17   ` Borislav Petkov
2018-09-28  2:26     ` Masayoshi Mizuma

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).