* Re: [PATCH v2] efi/libstub: fix building loongarch32 without zboot enabled
2026-11-26 12:41 [PATCH v2] efi/libstub: fix building loongarch32 without zboot enabled Dmitry Antipov
@ 2026-11-26 12:53 ` Ard Biesheuvel
2026-11-26 13:11 ` Ard Biesheuvel
2026-11-26 13:16 ` Dmitry Antipov
2026-11-26 12:59 ` sashiko-bot
1 sibling, 2 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2026-11-26 12:53 UTC (permalink / raw)
To: Dmitry Antipov, Huacai Chen
Cc: WANG Xuerui, linux-efi, loongarch, kernel test robot
On Thu, 26 Nov 2026, at 13:41, Dmitry Antipov wrote:
> Kernel test robot has reported the following error observed on loongarch:
>
> loongarch64-linux-ld:
> ./drivers/firmware/efi/libstub/lib-cmdline.stub.o: in function
> `__efistub_.L47':
> __efistub_cmdline.c:(.init.text+0x258): undefined reference to
> `__efistub___ashldi3'
> loongarch64-linux-ld: __efistub_cmdline.c:(.init.text+0x268): undefined
> reference to `__efistub___lshrdi3'
>
> Following the approach introduced in commit a354b8de9ad6
> ("riscv: add platform-specific double word shifts for riscv32"),
> define EFI stub aliases for __ashldi3() and __lshrdi3() for
> loongarch32 as well, thus making the related EFI stub's Makefile
> quirks redundant.
>
> Suggested-by: Ard Biesheuvel <ardb@kernel.org>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes:
> https://lore.kernel.org/oe-kbuild-all/20261122125352.gAcg5yLx-lkp@intel.com/
> Fixes: 442082297e3d ("riscv: fix building compressed EFI image")
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
> ---
> v2: define relevant EFI stubs in image-vars.h (Ard)
> ---
> arch/loongarch/kernel/image-vars.h | 2 ++
> drivers/firmware/efi/libstub/Makefile | 7 +------
> 2 files changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/arch/loongarch/kernel/image-vars.h
> b/arch/loongarch/kernel/image-vars.h
> index e557ebd46c2b..19202f4f84c2 100644
> --- a/arch/loongarch/kernel/image-vars.h
> +++ b/arch/loongarch/kernel/image-vars.h
> @@ -8,6 +8,8 @@
> #ifdef CONFIG_EFI_STUB
>
> __efistub_strcmp = strcmp;
> +__efistub___lshrdi3 = __lshrdi3;
> +__efistub___ashldi3 = __ashldi3;
> __efistub_kernel_entry = kernel_entry;
> __efistub_kernel_asize = kernel_asize;
> __efistub_kernel_fsize = kernel_fsize;
For the part above ^^^:
Acked-by: Ard Biesheuvel <ardb@kernel.org>
NAK to the changes below, they break zboot and need to be dropped.
Huacai, I'd prefer to take this via the efi tree - otherwise,
it will conflict with other changes that are queued up for
the next cycle.
> diff --git a/drivers/firmware/efi/libstub/Makefile
> b/drivers/firmware/efi/libstub/Makefile
> index bbab12b8eb4b..bcf2a5981678 100644
> --- a/drivers/firmware/efi/libstub/Makefile
> +++ b/drivers/firmware/efi/libstub/Makefile
> @@ -96,12 +96,7 @@ zboot-obj-y := zboot-decompress-gzip.o
> CFLAGS_zboot-decompress-gzip.o += -I$(srctree)/lib/zlib_inflate
> zboot-obj-$(CONFIG_KERNEL_ZSTD) := zboot-decompress-zstd.o lib-xxhash.o
> CFLAGS_zboot-decompress-zstd.o += -I$(srctree)/lib/zstd
> -
> -zboot-riscv-obj-$(CONFIG_32BIT) := lib-ashldi3.o lib-lshrdi3.o
> -zboot-obj-$(CONFIG_RISCV) += lib-clz_ctz.o $(zboot-riscv-obj-y)
> -zboot-loongarch-obj-$(CONFIG_32BIT) := lib-ashldi3.o lib-lshrdi3.o
> -zboot-obj-$(CONFIG_LOONGARCH) += lib-clz_ctz.o $(zboot-loongarch-obj-y)
> -lib-$(CONFIG_EFI_ZBOOT) += zboot.o $(zboot-obj-y)
> +lib-$(CONFIG_EFI_ZBOOT) += zboot.o
>
> lib-$(CONFIG_UNACCEPTED_MEMORY) += unaccepted_memory.o bitmap.o find.o
>
> --
> 2.56.1
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] efi/libstub: fix building loongarch32 without zboot enabled
2026-11-26 12:41 [PATCH v2] efi/libstub: fix building loongarch32 without zboot enabled Dmitry Antipov
2026-11-26 12:53 ` Ard Biesheuvel
@ 2026-11-26 12:59 ` sashiko-bot
1 sibling, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-26 12:59 UTC (permalink / raw)
To: Dmitry Antipov, Ard Biesheuvel
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Huacai Chen,
WANG Xuerui, linux-efi, kernel test robot
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] efi/libstub: dropping $(zboot-obj-y) breaks all
CONFIG_EFI_ZBOOT builds
- [High] efi/libstub: removing shift helpers breaks 32-bit
CONFIG_EFI_ZBOOT link
- [High] efi/libstub: removing lib-clz_ctz.o breaks ZSTD
CONFIG_EFI_ZBOOT link
- [Medium] efi/libstub: loongarch32 aliases shift helpers to
instrumented kernel C code
--
commit 387fa3daffaccbaba76887c4a051e10a5a6deaf6
Author: Dmitry Antipov <dmantipov@yandex.ru>
efi/libstub: fix building loongarch32 without zboot enabled
This commit defines EFI stub symbol aliases for __lshrdi3 and __ashldi3 in
arch/loongarch/kernel/image-vars.h and removes the zboot helper object rules
from drivers/firmware/efi/libstub/Makefile.
> diff --git a/arch/loongarch/kernel/image-vars.h b/arch/loongarch/kernel/image-vars.h
> index e557ebd46c2b3..19202f4f84c2b 100644
> --- a/arch/loongarch/kernel/image-vars.h
> +++ b/arch/loongarch/kernel/image-vars.h
> @@ -8,6 +8,8 @@
> #ifdef CONFIG_EFI_STUB
>
> __efistub_strcmp = strcmp;
> +__efistub___lshrdi3 = __lshrdi3;
> +__efistub___ashldi3 = __ashldi3;
> __efistub_kernel_entry = kernel_entry;
> __efistub_kernel_asize = kernel_asize;
> __efistub_kernel_fsize = kernel_fsize;
[Severity: Medium]
Is it safe for the LoongArch EFI stub to call the core kernel's __lshrdi3()
and __ashldi3() before kernel_entry?
Unlike RISC-V in commit a354b8de9ad6 ("riscv: add platform-specific double
word shifts for riscv32"), which implements these helpers in assembly,
LoongArch selects CONFIG_GENERIC_LIB_ASHLDI3 and CONFIG_GENERIC_LIB_LSHRDI3
and builds the C implementations in lib/ashldi3.c and lib/lshrdi3.c as
normal kernel objects. They are marked notrace, which only suppresses
ftrace, not KCOV, UBSAN, branch profiling or stack-protector
instrumentation.
With CONFIG_KCOV=y, the branches in __ashldi3() and __lshrdi3() call
__sanitizer_cov_trace_pc(), which dereferences current via the $tp register.
When efi_pe_entry() -> efi_handle_cmdline() calls memparse() in the pre-boot
EFI environment before kernel_entry initializes $tp to init_task, that
access crashes before the kernel boots. Building lib-ashldi3.o and
lib-lshrdi3.o in drivers/firmware/efi/libstub/Makefile avoids kernel
instrumentation.
> diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
> index bbab12b8eb4b2..bcf2a59816782 100644
> --- a/drivers/firmware/efi/libstub/Makefile
> +++ b/drivers/firmware/efi/libstub/Makefile
> @@ -96,12 +96,7 @@ zboot-obj-y := zboot-decompress-gzip.o
> CFLAGS_zboot-decompress-gzip.o += -I$(srctree)/lib/zlib_inflate
> zboot-obj-$(CONFIG_KERNEL_ZSTD) := zboot-decompress-zstd.o lib-xxhash.o
> CFLAGS_zboot-decompress-zstd.o += -I$(srctree)/lib/zstd
> -
> -zboot-riscv-obj-$(CONFIG_32BIT) := lib-ashldi3.o lib-lshrdi3.o
> -zboot-obj-$(CONFIG_RISCV) += lib-clz_ctz.o $(zboot-riscv-obj-y)
> -zboot-loongarch-obj-$(CONFIG_32BIT) := lib-ashldi3.o lib-lshrdi3.o
> -zboot-obj-$(CONFIG_LOONGARCH) += lib-clz_ctz.o $(zboot-loongarch-obj-y)
[Severity: High]
Does removing lib-ashldi3.o and lib-lshrdi3.o break linking vmlinuz.efi.elf
on 32-bit RISC-V and 32-bit LoongArch when CONFIG_EFI_ZBOOT=y?
The __efistub___ashldi3 and __efistub___lshrdi3 aliases in
arch/{riscv,loongarch}/kernel/image-vars.h are only included by
vmlinux.lds.S when linking vmlinux. In
drivers/firmware/efi/libstub/Makefile.zboot, vmlinuz.efi.elf is linked as a
standalone binary with zboot.lds against only vmlinuz.o, zboot-header.o and
drivers/firmware/efi/libstub/lib.a, where efi_zboot_entry() ->
efi_handle_cmdline() still pulls in lib-cmdline.stub.o and leaves
__efistub___ashldi3 and __efistub___lshrdi3 unresolved, reintroducing the
build failure fixed by commit 442082297e3d ("riscv: fix building compressed
EFI image").
[Severity: High]
Does removing lib-clz_ctz.o break linking vmlinuz.efi.elf on RISC-V and
32-bit LoongArch when CONFIG_EFI_ZBOOT=y and CONFIG_KERNEL_ZSTD=y?
zboot-decompress-zstd.c uses __builtin_ctz(), __builtin_clz(),
__builtin_ctzll() and __builtin_clzll() in lib/zstd/common/bits.h, which
emit calls to __efistub___ctz* and __efistub___clz* when target instructions
are not enabled. Because vmlinuz.efi.elf is linked standalone against
drivers/firmware/efi/libstub/lib.a without the kernel's lib/lib.a, dropping
lib-clz_ctz.o leaves those symbols undefined at link time.
> -lib-$(CONFIG_EFI_ZBOOT) += zboot.o $(zboot-obj-y)
> +lib-$(CONFIG_EFI_ZBOOT) += zboot.o
[Severity: High]
Does dropping $(zboot-obj-y) from lib-$(CONFIG_EFI_ZBOOT) break all
CONFIG_EFI_ZBOOT=y builds across every architecture?
Without $(zboot-obj-y), neither zboot-decompress-gzip.stub.o nor
zboot-decompress-zstd.stub.o and lib-xxhash.stub.o are added to
drivers/firmware/efi/libstub/lib.a, so linking vmlinuz.efi.elf fails with
undefined references to __efistub_efi_zboot_decompress_init and
__efistub_efi_zboot_decompress from efi_zboot_entry().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126124145.876953-1-dmantipov@yandex.ru?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread