x86: don't reserve SETUP_RNG_SEED in e820

Message ID ZbmOjKnARGiaYBd5@dwarf.suse.cz
State New
Headers
Series x86: don't reserve SETUP_RNG_SEED in e820 |

Commit Message

Jiri Bohac Jan. 31, 2024, 12:04 a.m. UTC
  SETUP_RNG_SEED in setup_data is supplied by kexec and should
not be reserved in the e820 map.

Doing so reserves 16 bytes of RAM when booting with kexec.
(16 bytes because data->len is zeroed by parse_setup_data so only
sizeof(setup_data) is reserved.)

When kexec is used repeatedly, each boot adds two entries in the
kexec-provided e820 map as the 16-byte range splits a larger
range of usable memory. Eventually all of the 128 available entries
get used up. The next split will result in losing usable memory
as the new entries cannot be added to the e820 map.

Fixes: 68b8e9713c8e ("x86/setup: Use rng seeds from setup_data")
Signed-off-by: Jiri Bohac <jbohac@suse.cz>
---
 arch/x86/kernel/e820.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
  

Comments

Jiri Bohac Feb. 28, 2024, 9:45 a.m. UTC | #1
Adding Andrew Morton - have I been sending this to the wrong people/lists?

On Tue, Feb 20, 2024 at 02:55:27PM +0100, Jiri Bohac wrote:
> SETUP_RNG_SEED in setup_data is supplied by kexec and should
> not be reserved in the e820 map.
> 
> Doing so reserves 16 bytes of RAM when booting with kexec.
> (16 bytes because data->len is zeroed by parse_setup_data so only
> sizeof(setup_data) is reserved.)
> 
> When kexec is used repeatedly, each boot adds two entries in the
> kexec-provided e820 map as the 16-byte range splits a larger
> range of usable memory. Eventually all of the 128 available entries
> get used up. The next split will result in losing usable memory
> as the new entries cannot be added to the e820 map.
> 
> Fixes: 68b8e9713c8e ("x86/setup: Use rng seeds from setup_data")
> Signed-off-by: Jiri Bohac <jbohac@suse.cz>
> ---
>  arch/x86/kernel/e820.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
> index 91ade749f184..7be1362a31aa 100644
> --- a/arch/x86/kernel/e820.c
> +++ b/arch/x86/kernel/e820.c
> @@ -1018,10 +1018,12 @@ void __init e820__reserve_setup_data(void)
>  		e820__range_update(pa_data, sizeof(*data)+data->len, E820_TYPE_RAM, E820_TYPE_RESERVED_KERN);
>  
>  		/*
> -		 * SETUP_EFI and SETUP_IMA are supplied by kexec and do not need
> -		 * to be reserved.
> +		 * SETUP_EFI, SETUP_IMA and SETUP_RNG_SEED are supplied by
> +		 * kexec and do not need to be reserved.
>  		 */
> -		if (data->type != SETUP_EFI && data->type != SETUP_IMA)
> +		if (data->type != SETUP_EFI &&
> +		    data->type != SETUP_IMA &&
> +		    data->type != SETUP_RNG_SEED)
>  			e820__range_update_kexec(pa_data,
>  						 sizeof(*data) + data->len,
>  						 E820_TYPE_RAM, E820_TYPE_RESERVED_KERN);
  
Borislav Petkov Feb. 28, 2024, 10:43 a.m. UTC | #2
On Wed, Feb 28, 2024 at 10:45:02AM +0100, Jiri Bohac wrote:
> Adding Andrew Morton - have I been sending this to the wrong people/lists?

You're experiencing people trying to drink from the water hose...
  

Patch

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 91ade749f184..7be1362a31aa 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -1018,10 +1018,12 @@  void __init e820__reserve_setup_data(void)
 		e820__range_update(pa_data, sizeof(*data)+data->len, E820_TYPE_RAM, E820_TYPE_RESERVED_KERN);
 
 		/*
-		 * SETUP_EFI and SETUP_IMA are supplied by kexec and do not need
-		 * to be reserved.
+		 * SETUP_EFI, SETUP_IMA and SETUP_RNG_SEED are supplied by
+		 * kexec and do not need to be reserved.
 		 */
-		if (data->type != SETUP_EFI && data->type != SETUP_IMA)
+		if (data->type != SETUP_EFI &&
+		    data->type != SETUP_IMA &&
+		    data->type != SETUP_RNG_SEED)
 			e820__range_update_kexec(pa_data,
 						 sizeof(*data) + data->len,
 						 E820_TYPE_RAM, E820_TYPE_RESERVED_KERN);