Skip to contentSkip to conversation

x86/efi: Auto enable EFI memmap on SGI UV systems

RFC PATCH New Joseph Thelen 3 participants 7 messages Jun 2, 2016 – Jun 17, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 x86/efi: Auto enable EFI memmap on SGI UV systems

The intent here is to automatically enable the EFI memory map entries on SGI UV systems, which can have more than 128 E820 entries and will cause headaches if the EFI memory map entries are not added.

The assumption is made that the community would prefer that this change be a UV specific quirk, as opposed to automatically adding the EFI memory map entries whenever more then 128 E820 entries exist. If this assumption is incorrect, the patch can be changed to check the number of E820 entries rather than for whether or not the system is a UV.

Cc Alex Thorlton <athorlton-sJ/[email protected]>
Cc Matt Fleming <matt-mF/unelCI9GS6iBeEJttW/[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>

Joseph Thelen (1):
x86/efi: Auto enable EFI memmap on SGI UV systems

 arch/x86/platform/efi/efi.c | 43 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 39 insertions(+), 4 deletions(-)
Signature · 1 line
1.8.5.6
#1 lore raw

PATCH 1/1 x86/efi: Auto enable EFI memmap on SGI UV systems

Currently, the EFI memory map entries are disabled by default and must be enabled by passing the kernel boot option:

add_efi_memmap

The EFI memory map entries should be enabled on systems with more than 128 E820 entries, which includes many UV systems. Check if we're on a UV system by chekcing the uv system table. Enable the EFI memory map entries if we're on a UV system.

This change is backward compatible because the EFI memory map entries are still disabled by default on non-UV systems, and it maintains the previous behavior of the kernel boot option. In addition, it allows the EFI memory map entries to be explicitly disabled (will not be automatically enabled) by setting the add_efi_memmap boot option to anything that kstringtobool will determine to be false.

Cc Alex Thorlton <[email protected]>
Cc Matt Fleming <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/platform/efi/efi.c | 43 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 39 insertions(+), 4 deletions(-)
arch/x86/platform/efi/efi.c +39 -4
index f93545e..26e3ff5 100644
@@ -66,10 +66,32 @@ static efi_config_table_type_t arch_tables[] __initdata = {
 
 u64 efi_setup;		/* efi setup_data physical address */
 
-static int add_efi_memmap __initdata;
+static __initdata enum {
+	EFI_MEMMAP_DEFAULT,
+	EFI_MEMMAP_ENABLED,
+	EFI_MEMMAP_DISABLED
+} add_efi_memmap;
+
 static int __init setup_add_efi_memmap(char *arg)
 {
-	add_efi_memmap = 1;
+	static bool arg_as_bool;
+	int ret = strtobool(arg, &arg_as_bool);
+
+	/* check for a non-existent arg, to maintain backward compatibility */
+	if (!arg) {
+		add_efi_memmap = EFI_MEMMAP_ENABLED;
+	} else {
+		if (ret) {
+			/* a bad argument was passed... */
+			return ret;
+		} else {
+			if (arg_as_bool)
+				add_efi_memmap = EFI_MEMMAP_ENABLED;
+			else
+				add_efi_memmap = EFI_MEMMAP_DISABLED;
+		}
+	}
+
 	return 0;
 }
 early_param("add_efi_memmap", setup_add_efi_memmap);
@@ -433,6 +455,7 @@ static int __init efi_runtime_init(void)
 static int __init efi_memmap_init(void)
 {
 	unsigned long addr, size;
+	bool is_uv_sys;
 
 	if (efi_enabled(EFI_PARAVIRT))
 		return 0;
@@ -449,8 +472,20 @@ static int __init efi_memmap_init(void)
 
 	efi.memmap.map_end = efi.memmap.map + size;
 
-	if (add_efi_memmap)
-		do_add_efi_memmap();
+	is_uv_sys = !((efi.uv_systab == EFI_INVALID_TABLE_ADDR)
+			|| !efi.uv_systab);
+
+	if (add_efi_memmap != EFI_MEMMAP_DISABLED) {
+		if (add_efi_memmap == EFI_MEMMAP_ENABLED) {
+			do_add_efi_memmap();
+			pr_info("EFI memmap enabled: Explicitly\n");
+		} else if (is_uv_sys) {
+			do_add_efi_memmap();
+			pr_info("EFI memmap enabled: this is a UV system\n");
+		}
+	} else {
+		pr_info("EFI memmap disabled: Explicitly\n");
+	}
 
 	set_bit(EFI_MEMMAP, &efi.flags);
 
Signature · 1 line
1.8.5.6
#2 lore raw

arch/x86/platform/efi/efi.c static efi_config_table_type_t arch_tables[] __initdata = { · line 77

Quoted 3 lines · Joseph Thelen

static int __init setup_add_efi_memmap(char *arg) {

arch/x86/platform/efi/efi.c +1 -0
+	static bool arg_as_bool;

Why hidden inside local variables as static?

Quoted 8 lines
arch/x86/platform/efi/efi.c +8 -0
+	int ret = strtobool(arg, &arg_as_bool);
+
+	/* check for a non-existent arg, to maintain backward compatibility */
+	if (!arg) {
+		add_efi_memmap = EFI_MEMMAP_ENABLED;
+	} else {
+		if (ret) {
+			/* a bad argument was passed... */

arch/x86/platform/efi/efi.c static efi_config_table_type_t arch_tables[] __initdata = { · line 95

Quoted 10 lines
arch/x86/platform/efi/efi.c +9 -0
+			return ret;
+		} else {
+			if (arg_as_bool)
+				add_efi_memmap = EFI_MEMMAP_ENABLED;
+			else
+				add_efi_memmap = EFI_MEMMAP_DISABLED;
+		}
+	}
+
 	return 0;

And that's a really weird code flow!

How about something straightforward:

	int val = 0;
	int ret;

	/* Check for a non-existent arg, to maintain backward compatibility: */
	if (!arg) {
		add_efi_memmap = EFI_MEMMAP_ENABLED;
		return 0;
	}

	ret = strtobool(arg, &val);

	/* Was a bad argument passed? */
	if (ret)
		return ret;

	if (val)
		add_efi_memmap = EFI_MEMMAP_ENABLED;
	else
		add_efi_memmap = EFI_MEMMAP_DISABLED;

	return 0;

?

Also note the rename to 'val'.

Thanks,

Ingo

#4 lore raw
In reply to Joseph Thelen

(Cc'ing people familiar with e820 map woes)

Quoted 25 lines · Joseph Thelen

Currently, the EFI memory map entries are disabled by default and must be enabled by passing the kernel boot option:

add_efi_memmap

The EFI memory map entries should be enabled on systems with more than 128 E820 entries, which includes many UV systems. Check if we're on a UV system by chekcing the uv system table. Enable the EFI memory map entries if we're on a UV system.

This change is backward compatible because the EFI memory map entries are still disabled by default on non-UV systems, and it maintains the previous behavior of the kernel boot option. In addition, it allows the EFI memory map entries to be explicitly disabled (will not be automatically enabled) by setting the add_efi_memmap boot option to anything that kstringtobool will determine to be false.

Cc Alex Thorlton <athorlton-sJ/[email protected]>
Cc Matt Fleming <matt-mF/unelCI9GS6iBeEJttW/[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Quoted 3 lines
---
 arch/x86/platform/efi/efi.c | 43 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 39 insertions(+), 4 deletions(-)

What's the ultimate goal here? To not require that users specify the add_efi_memmap kernel parameter in the future? Presumably they do today?

FYI, a lot of non-UV systems have more than 128 entries and the way we handle it is by using the SETUP_E820_EXT setup_data entry in boot_params in the EFI boot stub (I don't think boot loaders use it because they largely go via the stub anyhow).

So if you've got control over your boot loader, and assuming SGI UV systems don't boot using the EFI boot stub, you could look at adding boot loader support for SETUP_E820_EXT to force enable > 128 entries automatically without any new kernel code.

#3 lore raw
In reply to Ingo Molnar
Quoted 8 lines · Ingo Molnar

arch/x86/platform/efi/efi.c static efi_config_table_type_t arch_tables[] __initdata = { · line 77

Quoted 3 lines · Joseph Thelen

static int __init setup_add_efi_memmap(char *arg) {

arch/x86/platform/efi/efi.c +1 -0
+	static bool arg_as_bool;

Why hidden inside local variables as static?

Likely muscle memory of some kind after being forced to do a bunch of things in Java for awhile. Thanks for pointing that out.

Quoted 46 lines
Quoted 9 lines
arch/x86/platform/efi/efi.c +8 -0
+	int ret = strtobool(arg, &arg_as_bool);
+
+	/* check for a non-existent arg, to maintain backward compatibility */
+	if (!arg) {
+		add_efi_memmap = EFI_MEMMAP_ENABLED;
+	} else {
+		if (ret) {
+			/* a bad argument was passed... */

arch/x86/platform/efi/efi.c static efi_config_table_type_t arch_tables[] __initdata = { · line 95

Quoted 10 lines
arch/x86/platform/efi/efi.c +9 -0
+			return ret;
+		} else {
+			if (arg_as_bool)
+				add_efi_memmap = EFI_MEMMAP_ENABLED;
+			else
+				add_efi_memmap = EFI_MEMMAP_DISABLED;
+		}
+	}
+
 	return 0;

And that's a really weird code flow!

How about something straightforward:

	int val = 0;
	int ret;

	/* Check for a non-existent arg, to maintain backward compatibility: */
	if (!arg) {
		add_efi_memmap = EFI_MEMMAP_ENABLED;
		return 0;
	}

	ret = strtobool(arg, &val);

	/* Was a bad argument passed? */
	if (ret)
		return ret;

	if (val)
		add_efi_memmap = EFI_MEMMAP_ENABLED;
	else
		add_efi_memmap = EFI_MEMMAP_DISABLED;

	return 0;
Quoted 7 lines

?

Also note the rename to 'val'.

Thanks,

Ingo

That certainly is much cleaner!
Having only recently come from a place where "extra" returns were to be avoided at any cost, the fact that they do not appear to be quite so tabo here is nice.

These changes will be made to whatever version of this comes into being after considering Matt Fleming's comments.

Thanks,

Joseph Thelen

#5 lore raw
In reply to Matt Fleming
Quoted 41 lines · Matt Fleming

(Cc'ing people familiar with e820 map woes)

Quoted 25 lines · Joseph Thelen

Currently, the EFI memory map entries are disabled by default and must be enabled by passing the kernel boot option:

add_efi_memmap

The EFI memory map entries should be enabled on systems with more than 128 E820 entries, which includes many UV systems. Check if we're on a UV system by chekcing the uv system table. Enable the EFI memory map entries if we're on a UV system.

This change is backward compatible because the EFI memory map entries are still disabled by default on non-UV systems, and it maintains the previous behavior of the kernel boot option. In addition, it allows the EFI memory map entries to be explicitly disabled (will not be automatically enabled) by setting the add_efi_memmap boot option to anything that kstringtobool will determine to be false.

Cc Alex Thorlton <athorlton-sJ/[email protected]>
Cc Matt Fleming <matt-mF/unelCI9GS6iBeEJttW/[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Quoted 3 lines
---
 arch/x86/platform/efi/efi.c | 43 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 39 insertions(+), 4 deletions(-)

What's the ultimate goal here? To not require that users specify the add_efi_memmap kernel parameter in the future? Presumably they do today?

FYI, a lot of non-UV systems have more than 128 entries and the way we handle it is by using the SETUP_E820_EXT setup_data entry in boot_params in the EFI boot stub (I don't think boot loaders use it because they largely go via the stub anyhow).

Quoted 4 lines

So if you've got control over your boot loader, and assuming SGI UV systems don't boot using the EFI boot stub, you could look at adding boot loader support for SETUP_E820_EXT to force enable > 128 entries automatically without any new kernel code.

We're still reasonably confident we'll need something like this. Although, after looking into the stuff you mention, it seems that it should perhaps be a bit more sophisticated than just checking if we're on a UV system.

We'll get back to you after digging into this a bit more and coming up with some more specific reasons for the change.

Thanks,

Joseph Thelen

#6 lore raw
Quoted 11 lines · Joseph Thelen

We're still reasonably confident we'll need something like this. Although, after looking into the stuff you mention, it seems that it should perhaps be a bit more sophisticated than just checking if we're on a UV system.

We'll get back to you after digging into this a bit more and coming up with some more specific reasons for the change.

Thanks,

Joseph Thelen

After investigating a bit more, it seems that this is really only an issue where people are using older bootloaders/managers and kernels, some of which are still supported / used by big distros like redhat.

Given that this is, as you've pointed out, either a non-issue or easily remedied without kernel changes now and in the future, we'll try talking about it directly with any distro where it's still an issue.

Thanks,

Joseph Thelen