Re: [PATCH v9 24/43] x86/compressed/acpi: Move EFI detection to helper

Borislav Petkov
2022-02-03T14:40:08Z

On Fri, Jan 28, 2022 at 11:17:45AM -0600, Brijesh Singh wrote:
> diff --git a/arch/x86/boot/compressed/efi.c b/arch/x86/boot/compressed/efi.c
> new file mode 100644
> index 000000000000..daa73efdc7a5
> --- /dev/null
> +++ b/arch/x86/boot/compressed/efi.c
> @@ -0,0 +1,50 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Helpers for early access to EFI configuration table.
> + *
> + * Originally derived from arch/x86/boot/compressed/acpi.c
> + */
> +
> +#include "misc.h"
> +#include <linux/efi.h>
> +#include <asm/efi.h>

Yap, it is includes like that which cause this whole decompressor
include hell. One day...

> +
> +/**
> + * efi_get_type - Given boot_params, determine the type of EFI environment.
> + *
> + * @boot_params: pointer to boot_params
> + *
> + * Return: EFI_TYPE_{32,64} for valid EFI environments, EFI_TYPE_NONE otherwise.
> + */
> +enum efi_type efi_get_type(struct boot_params *boot_params)

struct boot_params *bp

> +{
> + struct efi_info *ei;
> + enum efi_type et;
> + const char *sig;
> +
> + ei = &boot_params->efi_info;
> + sig = (char *)&ei->efi_loader_signature;
> +
> + if (!strncmp(sig, EFI64_LOADER_SIGNATURE, 4)) {
> + et = EFI_TYPE_64;
> + } else if (!strncmp(sig, EFI32_LOADER_SIGNATURE, 4)) {
> + et = EFI_TYPE_32;
> + } else {
> + debug_putstr("No EFI environment detected.\n");
> + et = EFI_TYPE_NONE;
> + }
> +
> +#ifndef CONFIG_X86_64
> + /*
> + * Existing callers like acpi.c treat this case as an indicator to
> + * fall-through to non-EFI, rather than an error, so maintain that
> + * functionality here as well.
> + */
> + if (ei->efi_systab_hi || ei->efi_memmap_hi) {
> + debug_putstr("EFI system table is located above 4GB and cannot be accessed.\n");
> + et = EFI_TYPE_NONE;
> + }
> +#endif
> +
> + return et;
> +}
> diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
> index 01cc13c12059..a26244c0fe01 100644
> --- a/arch/x86/boot/compressed/misc.h
> +++ b/arch/x86/boot/compressed/misc.h
> @@ -176,4 +176,20 @@ void boot_stage2_vc(void);
>
> unsigned long sev_verify_cbit(unsigned long cr3);
>
> +enum efi_type {
> + EFI_TYPE_64,
> + EFI_TYPE_32,
> + EFI_TYPE_NONE,
> +};

Haha, EFI folks will be wondering where in the spec that thing is... :-)))

--
Regards/Gruss,
Boris.