[PATCH 1/1] efi_selftest: check executing in EL2

Ilias Apalodimas ilias.apalodimas at linaro.org
Fri Apr 11 12:00:09 CEST 2025


Hi Heinrich,

[...]

> +
> +/**
> + * current_exception_level()
> + *
> + * Return:     current exception level, 0 - 3
> + */
> +static unsigned int current_exception_level(void)
> +{
> +       unsigned long el;
> +
> +       asm volatile (
> +               "MRS %0, CurrentEL"
> +               : "=r" (el) : : );
> +
> +       return (el >> 2) & 0x3;
> +}
> +

We have an identical function in arch/arm/include/asm/system.h, can we
use that? It's static inline so you may be able to just include the
header file directly. Also, that function adds a 'cc,' which tells the
compiler that the instruction might change the condition code flags. I
don't remember if this is needed, but it doesn't hurt to have it.


> +/**
> + * execute() - execute test
> + *
> + * Check that the exception level is not EL3.
> + */
> +static int execute(void)
> +{
> +       unsigned int el = current_exception_level();
> +
> +       efi_st_printf("Exception level EL%u\n", el);
> +       if (el != 1 && el != 2) {
> +               efi_st_error("EL1 or EL2 expected");
> +               return EFI_ST_FAILURE;
> +       }
> +
> +       return EFI_ST_SUCCESS;
> +}
> +
> +EFI_UNIT_TEST(el) = {
> +       .name = "exception level",
> +       .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
> +       .execute = execute,
> +};
> --
> 2.48.1
>

Other than that LGTM

/Ilias


More information about the U-Boot mailing list