Commit 37aee82c authored by Ard Biesheuvel's avatar Ard Biesheuvel
Browse files

x86/efi: Drop support for fake EFI memory maps



Between kexec and confidential VM support, handling the EFI memory maps
correctly on x86 is already proving to be rather difficult (as opposed
to other EFI architectures which manage to never modify the EFI memory
map to begin with)

EFI fake memory map support is essentially a development hack (for
testing new support for the 'special purpose' and 'more reliable' EFI
memory attributes) that leaked into production code. The regions marked
in this manner are not actually recognized as such by the firmware
itself or the EFI stub (and never have), and marking memory as 'more
reliable' seems rather futile if the underlying memory is just ordinary
RAM.

Marking memory as 'special purpose' in this way is also dubious, but may
be in use in production code nonetheless. However, the same should be
achievable by using the memmap= command line option with the ! operator.

EFI fake memmap support is not enabled by any of the major distros
(Debian, Fedora, SUSE, Ubuntu) and does not exist on other
architectures, so let's drop support for it.

Acked-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
Acked-by: default avatarDan Williams <dan.j.williams@intel.com>
Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
parent f2661062
Loading
Loading
Loading
Loading
+0 −21
Original line number Diff line number Diff line
@@ -1450,27 +1450,6 @@
			you are really sure that your UEFI does sane gc and
			fulfills the spec otherwise your board may brick.

	efi_fake_mem=	nn[KMG]@ss[KMG]:aa[,nn[KMG]@ss[KMG]:aa,..] [EFI,X86,EARLY]
			Add arbitrary attribute to specific memory range by
			updating original EFI memory map.
			Region of memory which aa attribute is added to is
			from ss to ss+nn.

			If efi_fake_mem=2G@4G:0x10000,2G@0x10a0000000:0x10000
			is specified, EFI_MEMORY_MORE_RELIABLE(0x10000)
			attribute is added to range 0x100000000-0x180000000 and
			0x10a0000000-0x1120000000.

			If efi_fake_mem=8G@9G:0x40000 is specified, the
			EFI_MEMORY_SP(0x40000) attribute is added to
			range 0x240000000-0x43fffffff.

			Using this parameter you can do debugging of EFI memmap
			related features. For example, you can do debugging of
			Address Range Mirroring feature even if your box
			doesn't support it, or mark specific memory as
			"soft reserved".

	efivar_ssdt=	[EFI; X86] Name of an EFI variable that contains an SSDT
			that is to be dynamically loaded by Linux. If there are
			multiple variables with the same name but with different
+0 −20
Original line number Diff line number Diff line
@@ -2038,26 +2038,6 @@ config EFI_MIXED

	  If unsure, say N.

config EFI_FAKE_MEMMAP
	bool "Enable EFI fake memory map"
	depends on EFI
	help
	  Saying Y here will enable "efi_fake_mem" boot option.  By specifying
	  this parameter, you can add arbitrary attribute to specific memory
	  range by updating original (firmware provided) EFI memmap.  This is
	  useful for debugging of EFI memmap related feature, e.g., Address
	  Range Mirroring feature.

config EFI_MAX_FAKE_MEM
	int "maximum allowable number of ranges in efi_fake_mem boot option"
	depends on EFI_FAKE_MEMMAP
	range 1 128
	default 8
	help
	  Maximum allowable number of ranges in efi_fake_mem boot option.
	  Ranges can be set up to this value using comma-separated list.
	  The default value is 8.

config EFI_RUNTIME_MAP
	bool "Export EFI runtime maps to sysfs" if EXPERT
	depends on EFI
+9 −34
Original line number Diff line number Diff line
@@ -119,13 +119,8 @@ char *skip_spaces(const char *str)
#include "../../../../lib/ctype.c"
#include "../../../../lib/cmdline.c"

enum parse_mode {
	PARSE_MEMMAP,
	PARSE_EFI,
};

static int
parse_memmap(char *p, u64 *start, u64 *size, enum parse_mode mode)
parse_memmap(char *p, u64 *start, u64 *size)
{
	char *oldp;

@@ -148,29 +143,11 @@ parse_memmap(char *p, u64 *start, u64 *size, enum parse_mode mode)
		*start = memparse(p + 1, &p);
		return 0;
	case '@':
		if (mode == PARSE_MEMMAP) {
		/*
		 * memmap=nn@ss specifies usable region, should
		 * be skipped
		 */
		*size = 0;
		} else {
			u64 flags;

			/*
			 * efi_fake_mem=nn@ss:attr the attr specifies
			 * flags that might imply a soft-reservation.
			 */
			*start = memparse(p + 1, &p);
			if (p && *p == ':') {
				p++;
				if (kstrtoull(p, 0, &flags) < 0)
					*size = 0;
				else if (flags & EFI_MEMORY_SP)
					return 0;
			}
			*size = 0;
		}
		fallthrough;
	default:
		/*
@@ -185,7 +162,7 @@ parse_memmap(char *p, u64 *start, u64 *size, enum parse_mode mode)
	return -EINVAL;
}

static void mem_avoid_memmap(enum parse_mode mode, char *str)
static void mem_avoid_memmap(char *str)
{
	static int i;

@@ -200,7 +177,7 @@ static void mem_avoid_memmap(enum parse_mode mode, char *str)
		if (k)
			*k++ = 0;

		rc = parse_memmap(str, &start, &size, mode);
		rc = parse_memmap(str, &start, &size);
		if (rc < 0)
			break;
		str = k;
@@ -281,7 +258,7 @@ static void handle_mem_options(void)
			break;

		if (!strcmp(param, "memmap")) {
			mem_avoid_memmap(PARSE_MEMMAP, val);
			mem_avoid_memmap(val);
		} else if (IS_ENABLED(CONFIG_X86_64) && strstr(param, "hugepages")) {
			parse_gb_huge_pages(param, val);
		} else if (!strcmp(param, "mem")) {
@@ -295,8 +272,6 @@ static void handle_mem_options(void)

			if (mem_size < mem_limit)
				mem_limit = mem_size;
		} else if (!strcmp(param, "efi_fake_mem")) {
			mem_avoid_memmap(PARSE_EFI, val);
		}
	}

+0 −15
Original line number Diff line number Diff line
@@ -384,23 +384,8 @@ static inline void efi_reserve_boot_services(void)
}
#endif /* CONFIG_EFI */

#ifdef CONFIG_EFI_FAKE_MEMMAP
extern void __init efi_fake_memmap_early(void);
extern void __init efi_fake_memmap(void);
#else
static inline void efi_fake_memmap_early(void)
{
}

static inline void efi_fake_memmap(void)
{
}
#endif

extern int __init efi_memmap_alloc(unsigned int num_entries,
				   struct efi_memory_map_data *data);
extern void __efi_memmap_free(u64 phys, unsigned long size,
			      unsigned long flags);

extern int __init efi_memmap_install(struct efi_memory_map_data *data);
extern int __init efi_memmap_split_count(efi_memory_desc_t *md,
+0 −1
Original line number Diff line number Diff line
@@ -995,7 +995,6 @@ void __init setup_arch(char **cmdline_p)
	mem_encrypt_setup_arch();
	cc_random_init();

	efi_fake_memmap();
	efi_find_mirror();
	efi_esrt_init();
	efi_mokvar_table_init();
Loading