* [PATCH 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation
@ 2026-04-27 3:44 WANG Rui
2026-04-27 3:44 ` [PATCH 1/2] efi/loongarch: Implement efi_cache_sync_image WANG Rui
2026-04-27 3:44 ` [PATCH 2/2] efi/libstub: Synchronize instruction cache after kernel relocation WANG Rui
0 siblings, 2 replies; 5+ messages in thread
From: WANG Rui @ 2026-04-27 3:44 UTC (permalink / raw)
To: Ard Biesheuvel, Huacai Chen
Cc: Ilias Apalodimas, WANG Xuerui, linux-efi, linux-kernel, loongarch,
WANG Rui
The EFI stub relocates the kernel image by copying it to a new memory
location using memcpy(). On architectures where the instruction and data
caches are not automatically coherent, the copied instructions may not be
visible to the instruction fetch unit without explicit cache maintenance.
This series adds the missing call to efi_cache_sync_image() in the generic
relocation path, and provides a LoongArch implementation using the ibar
instruction to ensure instruction fetches observe the updated contents.
WANG Rui (2):
efi/loongarch: Implement efi_cache_sync_image
efi/libstub: Synchronize instruction cache after kernel relocation
drivers/firmware/efi/libstub/loongarch.c | 5 +++++
drivers/firmware/efi/libstub/relocate.c | 1 +
2 files changed, 6 insertions(+)
--
2.54.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] efi/loongarch: Implement efi_cache_sync_image
2026-04-27 3:44 [PATCH 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation WANG Rui
@ 2026-04-27 3:44 ` WANG Rui
2026-04-27 8:09 ` Huacai Chen
2026-04-27 3:44 ` [PATCH 2/2] efi/libstub: Synchronize instruction cache after kernel relocation WANG Rui
1 sibling, 1 reply; 5+ messages in thread
From: WANG Rui @ 2026-04-27 3:44 UTC (permalink / raw)
To: Ard Biesheuvel, Huacai Chen
Cc: Ilias Apalodimas, WANG Xuerui, linux-efi, linux-kernel, loongarch,
WANG Rui
Provide a LoongArch implementation of efi_cache_sync_image() to ensure
instruction cache coherency after the kernel image is relocated.
Signed-off-by: WANG Rui <r@hev.cc>
---
drivers/firmware/efi/libstub/loongarch.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/firmware/efi/libstub/loongarch.c b/drivers/firmware/efi/libstub/loongarch.c
index 9825f5218137..26495747f69f 100644
--- a/drivers/firmware/efi/libstub/loongarch.c
+++ b/drivers/firmware/efi/libstub/loongarch.c
@@ -82,3 +82,8 @@ efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
real_kernel_entry(true, (unsigned long)cmdline_ptr,
(unsigned long)efi_system_table);
}
+
+void efi_cache_sync_image(unsigned long image_base, unsigned long alloc_size)
+{
+ asm volatile ("ibar 0" ::: "memory");
+}
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 1/2] efi/loongarch: Implement efi_cache_sync_image
2026-04-27 3:44 ` [PATCH 1/2] efi/loongarch: Implement efi_cache_sync_image WANG Rui
@ 2026-04-27 8:09 ` Huacai Chen
0 siblings, 0 replies; 5+ messages in thread
From: Huacai Chen @ 2026-04-27 8:09 UTC (permalink / raw)
To: WANG Rui
Cc: Ard Biesheuvel, Ilias Apalodimas, WANG Xuerui, linux-efi,
linux-kernel, loongarch
Hi, Rui,
On Mon, Apr 27, 2026 at 11:45 AM WANG Rui <r@hev.cc> wrote:
>
> Provide a LoongArch implementation of efi_cache_sync_image() to ensure
> instruction cache coherency after the kernel image is relocated.
Please also add "()" after function name in the subject.
>
> Signed-off-by: WANG Rui <r@hev.cc>
> ---
> drivers/firmware/efi/libstub/loongarch.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/firmware/efi/libstub/loongarch.c b/drivers/firmware/efi/libstub/loongarch.c
> index 9825f5218137..26495747f69f 100644
> --- a/drivers/firmware/efi/libstub/loongarch.c
> +++ b/drivers/firmware/efi/libstub/loongarch.c
> @@ -82,3 +82,8 @@ efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
> real_kernel_entry(true, (unsigned long)cmdline_ptr,
> (unsigned long)efi_system_table);
> }
> +
> +void efi_cache_sync_image(unsigned long image_base, unsigned long alloc_size)
> +{
> + asm volatile ("ibar 0" ::: "memory");
> +}
Please move it after check_platform_features(), which is the same as arm64.
Others look good to me.
Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
> --
> 2.54.0
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] efi/libstub: Synchronize instruction cache after kernel relocation
2026-04-27 3:44 [PATCH 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation WANG Rui
2026-04-27 3:44 ` [PATCH 1/2] efi/loongarch: Implement efi_cache_sync_image WANG Rui
@ 2026-04-27 3:44 ` WANG Rui
2026-04-27 8:09 ` Huacai Chen
1 sibling, 1 reply; 5+ messages in thread
From: WANG Rui @ 2026-04-27 3:44 UTC (permalink / raw)
To: Ard Biesheuvel, Huacai Chen
Cc: Ilias Apalodimas, WANG Xuerui, linux-efi, linux-kernel, loongarch,
WANG Rui
The relocated kernel image is copied to its new location using memcpy().
On architectures with separate instruction and data caches, the copied
instructions may remain stale in the instruction cache, leading to the
execution of outdated contents.
Call efi_cache_sync_image() after the relocation copy to ensure the
instruction cache is synchronized with the updated memory contents before
control is transferred to the relocated kernel.
Signed-off-by: WANG Rui <r@hev.cc>
---
drivers/firmware/efi/libstub/relocate.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/firmware/efi/libstub/relocate.c b/drivers/firmware/efi/libstub/relocate.c
index d4264bfb6dc1..913b425d089d 100644
--- a/drivers/firmware/efi/libstub/relocate.c
+++ b/drivers/firmware/efi/libstub/relocate.c
@@ -158,6 +158,7 @@ efi_status_t efi_relocate_kernel(unsigned long *image_addr,
* have been allocated by UEFI, so we can safely use memcpy.
*/
memcpy((void *)new_addr, (void *)cur_image_addr, image_size);
+ efi_cache_sync_image(new_addr, image_size);
/* Return the new address of the relocated image. */
*image_addr = new_addr;
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] efi/libstub: Synchronize instruction cache after kernel relocation
2026-04-27 3:44 ` [PATCH 2/2] efi/libstub: Synchronize instruction cache after kernel relocation WANG Rui
@ 2026-04-27 8:09 ` Huacai Chen
0 siblings, 0 replies; 5+ messages in thread
From: Huacai Chen @ 2026-04-27 8:09 UTC (permalink / raw)
To: WANG Rui
Cc: Ard Biesheuvel, Ilias Apalodimas, WANG Xuerui, linux-efi,
linux-kernel, loongarch
On Mon, Apr 27, 2026 at 11:45 AM WANG Rui <r@hev.cc> wrote:
>
> The relocated kernel image is copied to its new location using memcpy().
> On architectures with separate instruction and data caches, the copied
> instructions may remain stale in the instruction cache, leading to the
> execution of outdated contents.
>
> Call efi_cache_sync_image() after the relocation copy to ensure the
> instruction cache is synchronized with the updated memory contents before
> control is transferred to the relocated kernel.
>
> Signed-off-by: WANG Rui <r@hev.cc>
Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
> drivers/firmware/efi/libstub/relocate.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/firmware/efi/libstub/relocate.c b/drivers/firmware/efi/libstub/relocate.c
> index d4264bfb6dc1..913b425d089d 100644
> --- a/drivers/firmware/efi/libstub/relocate.c
> +++ b/drivers/firmware/efi/libstub/relocate.c
> @@ -158,6 +158,7 @@ efi_status_t efi_relocate_kernel(unsigned long *image_addr,
> * have been allocated by UEFI, so we can safely use memcpy.
> */
> memcpy((void *)new_addr, (void *)cur_image_addr, image_size);
> + efi_cache_sync_image(new_addr, image_size);
>
> /* Return the new address of the relocated image. */
> *image_addr = new_addr;
> --
> 2.54.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-04-27 8:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-27 3:44 [PATCH 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation WANG Rui
2026-04-27 3:44 ` [PATCH 1/2] efi/loongarch: Implement efi_cache_sync_image WANG Rui
2026-04-27 8:09 ` Huacai Chen
2026-04-27 3:44 ` [PATCH 2/2] efi/libstub: Synchronize instruction cache after kernel relocation WANG Rui
2026-04-27 8:09 ` Huacai Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox