efi/libstub: use EFI provided memcpy/memset routines
authorArd Biesheuvel <ardb@kernel.org>
Tue, 9 Aug 2022 14:45:17 +0000 (16:45 +0200)
committerArd Biesheuvel <ardb@kernel.org>
Sat, 17 Sep 2022 13:13:21 +0000 (15:13 +0200)
commitc82ceb440b886cc0f3945b6db979c49c48a4af29
tree39477aada6d7d90672fc086a4599c1c49d088922
parentc7007d9f19527b47992ff78a088e8697a9e9d5f5
efi/libstub: use EFI provided memcpy/memset routines

The stub is used in different execution environments, but on arm64,
RISC-V and LoongArch, we still use the core kernel's implementation of
memcpy and memset, as they are just a branch instruction away, and can
generally be reused even from code such as the EFI stub that runs in a
completely different address space.

KAsan complicates this slightly, resulting in the need for some hacks to
expose the uninstrumented, __ prefixed versions as the normal ones, as
the latter are instrumented to include the KAsan checks, which only work
in the core kernel.

Unfortunately, #define'ing memcpy to __memcpy when building C code does
not guarantee that no explicit memcpy() calls will be emitted. And with
the upcoming zboot support, which consists of a separate binary which
therefore needs its own implementation of memcpy/memset anyway, it's
better to provide one explicitly instead of linking to the existing one.

Given that EFI exposes implementations of memmove() and memset() via the
boot services table, let's wire those up in the appropriate way, and
drop the references to the core kernel ones.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
arch/arm64/kernel/image-vars.h
arch/loongarch/kernel/image-vars.h
arch/riscv/kernel/image-vars.h
drivers/firmware/efi/libstub/Makefile
drivers/firmware/efi/libstub/efistub.h
drivers/firmware/efi/libstub/intrinsics.c [new file with mode: 0644]