提交 88c26d7d 编写于 作者: A Ard Biesheuvel 提交者: Hongchen Zhang

efi/libstub: use EFI provided memcpy/memset routines

LoongArch inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5OHOB

--------------------------------

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: NArd Biesheuvel <ardb@kernel.org>
Signed-off-by: NHuacai Chen <chenhuacai@loongson.cn>
上级 3d668b6d
...@@ -27,9 +27,6 @@ __efistub_primary_entry_offset = primary_entry - _text; ...@@ -27,9 +27,6 @@ __efistub_primary_entry_offset = primary_entry - _text;
*/ */
__efistub_memcmp = __pi_memcmp; __efistub_memcmp = __pi_memcmp;
__efistub_memchr = __pi_memchr; __efistub_memchr = __pi_memchr;
__efistub_memcpy = __pi_memcpy;
__efistub_memmove = __pi_memmove;
__efistub_memset = __pi_memset;
__efistub_strlen = __pi_strlen; __efistub_strlen = __pi_strlen;
__efistub_strnlen = __pi_strnlen; __efistub_strnlen = __pi_strnlen;
__efistub_strcmp = __pi_strcmp; __efistub_strcmp = __pi_strcmp;
...@@ -38,12 +35,6 @@ __efistub_strrchr = __pi_strrchr; ...@@ -38,12 +35,6 @@ __efistub_strrchr = __pi_strrchr;
__efistub_strchr = __pi_strchr; __efistub_strchr = __pi_strchr;
__efistub___clean_dcache_area_poc = __pi___clean_dcache_area_poc; __efistub___clean_dcache_area_poc = __pi___clean_dcache_area_poc;
#ifdef CONFIG_KASAN
__efistub___memcpy = __pi_memcpy;
__efistub___memmove = __pi_memmove;
__efistub___memset = __pi_memset;
#endif
__efistub__text = _text; __efistub__text = _text;
__efistub__end = _end; __efistub__end = _end;
__efistub__edata = _edata; __efistub__edata = _edata;
......
...@@ -9,9 +9,6 @@ ...@@ -9,9 +9,6 @@
__efistub_memcmp = memcmp; __efistub_memcmp = memcmp;
__efistub_memchr = memchr; __efistub_memchr = memchr;
__efistub_memcpy = memcpy;
__efistub_memmove = memmove;
__efistub_memset = memset;
__efistub_strcat = strcat; __efistub_strcat = strcat;
__efistub_strcmp = strcmp; __efistub_strcmp = strcmp;
__efistub_strlen = strlen; __efistub_strlen = strlen;
......
...@@ -25,21 +25,12 @@ ...@@ -25,21 +25,12 @@
*/ */
__efistub_memcmp = memcmp; __efistub_memcmp = memcmp;
__efistub_memchr = memchr; __efistub_memchr = memchr;
__efistub_memcpy = memcpy;
__efistub_memmove = memmove;
__efistub_memset = memset;
__efistub_strlen = strlen; __efistub_strlen = strlen;
__efistub_strnlen = strnlen; __efistub_strnlen = strnlen;
__efistub_strcmp = strcmp; __efistub_strcmp = strcmp;
__efistub_strncmp = strncmp; __efistub_strncmp = strncmp;
__efistub_strrchr = strrchr; __efistub_strrchr = strrchr;
#ifdef CONFIG_KASAN
__efistub___memcpy = memcpy;
__efistub___memmove = memmove;
__efistub___memset = memset;
#endif
__efistub__start = _start; __efistub__start = _start;
__efistub__start_kernel = _start_kernel; __efistub__start_kernel = _start_kernel;
__efistub__end = _end; __efistub__end = _end;
......
...@@ -63,7 +63,7 @@ efi-deps-y := fdt_rw.c fdt_ro.c fdt_wip.c fdt.c fdt_empty_tree.c fdt_sw.c ...@@ -63,7 +63,7 @@ efi-deps-y := fdt_rw.c fdt_ro.c fdt_wip.c fdt.c fdt_empty_tree.c fdt_sw.c
$(obj)/lib-%.o: $(srctree)/lib/%.c FORCE $(obj)/lib-%.o: $(srctree)/lib/%.c FORCE
$(call if_changed_rule,cc_o_c) $(call if_changed_rule,cc_o_c)
lib-$(CONFIG_EFI_GENERIC_STUB) += efi-stub.o fdt.o string.o \ lib-$(CONFIG_EFI_GENERIC_STUB) += efi-stub.o fdt.o string.o intrinsics.o \
$(patsubst %.c,lib-%.o,$(efi-deps-y)) $(patsubst %.c,lib-%.o,$(efi-deps-y))
lib-$(CONFIG_ARM) += arm32-stub.o lib-$(CONFIG_ARM) += arm32-stub.o
......
...@@ -298,8 +298,8 @@ union efi_boot_services { ...@@ -298,8 +298,8 @@ union efi_boot_services {
efi_status_t (__efiapi *install_multiple_protocol_interfaces)(efi_handle_t *, ...); efi_status_t (__efiapi *install_multiple_protocol_interfaces)(efi_handle_t *, ...);
efi_status_t (__efiapi *uninstall_multiple_protocol_interfaces)(efi_handle_t, ...); efi_status_t (__efiapi *uninstall_multiple_protocol_interfaces)(efi_handle_t, ...);
void *calculate_crc32; void *calculate_crc32;
void *copy_mem; void (__efiapi *copy_mem)(void *, const void *, unsigned long);
void *set_mem; void (__efiapi *set_mem)(void *, unsigned long, unsigned char);
void *create_event_ex; void *create_event_ex;
}; };
struct { struct {
......
// SPDX-License-Identifier: GPL-2.0
#include <linux/efi.h>
#include <asm/efi.h>
#include <asm/string.h>
#include "efistub.h"
#ifdef CONFIG_KASAN
#undef memcpy
#undef memmove
#undef memset
void *__memcpy(void *__dest, const void *__src, size_t __n) __alias(memcpy);
void *__memmove(void *__dest, const void *__src, size_t count) __alias(memmove);
void *__memset(void *s, int c, size_t count) __alias(memset);
#endif
void *memcpy(void *dst, const void *src, size_t len)
{
efi_bs_call(copy_mem, dst, src, len);
return dst;
}
extern void *memmove(void *dst, const void *src, size_t len) __alias(memcpy);
void *memset(void *dst, int c, size_t len)
{
efi_bs_call(set_mem, dst, len, c & U8_MAX);
return dst;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册