* [PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation
@ 2026-04-27 8:39 WANG Rui
2026-04-27 8:39 ` [PATCH v2 1/2] efi/loongarch: Implement efi_cache_sync_image WANG Rui
2026-04-27 8:39 ` [PATCH v2 2/2] efi/libstub: Synchronize instruction cache after kernel relocation WANG Rui
0 siblings, 2 replies; 3+ messages in thread
From: WANG Rui @ 2026-04-27 8:39 UTC (permalink / raw)
To: Ard Biesheuvel, Huacai Chen
Cc: Ilias Apalodimas, WANG Xuerui, linux-efi, linux-kernel, loongarch,
WANG Rui
Changes since [v1]:
* Move efi_cache_sync_image() after check_platform_features(), matching arm64.
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.
[v1]: https://lore.kernel.org/loongarch/20260427034451.717817-1-r@hev.cc
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] 3+ messages in thread
* [PATCH v2 1/2] efi/loongarch: Implement efi_cache_sync_image
2026-04-27 8:39 [PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation WANG Rui
@ 2026-04-27 8:39 ` WANG Rui
2026-04-27 8:39 ` [PATCH v2 2/2] efi/libstub: Synchronize instruction cache after kernel relocation WANG Rui
1 sibling, 0 replies; 3+ messages in thread
From: WANG Rui @ 2026-04-27 8:39 UTC (permalink / raw)
To: Ard Biesheuvel, Huacai Chen
Cc: Ilias Apalodimas, WANG Xuerui, linux-efi, linux-kernel, loongarch,
WANG Rui, Huacai Chen
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>
Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
---
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..f7938d5c196a 100644
--- a/drivers/firmware/efi/libstub/loongarch.c
+++ b/drivers/firmware/efi/libstub/loongarch.c
@@ -18,6 +18,11 @@ efi_status_t check_platform_features(void)
return EFI_SUCCESS;
}
+void efi_cache_sync_image(unsigned long image_base, unsigned long alloc_size)
+{
+ asm volatile ("ibar 0" ::: "memory");
+}
+
struct exit_boot_struct {
efi_memory_desc_t *runtime_map;
int runtime_entry_count;
--
2.54.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH v2 2/2] efi/libstub: Synchronize instruction cache after kernel relocation
2026-04-27 8:39 [PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation WANG Rui
2026-04-27 8:39 ` [PATCH v2 1/2] efi/loongarch: Implement efi_cache_sync_image WANG Rui
@ 2026-04-27 8:39 ` WANG Rui
1 sibling, 0 replies; 3+ messages in thread
From: WANG Rui @ 2026-04-27 8:39 UTC (permalink / raw)
To: Ard Biesheuvel, Huacai Chen
Cc: Ilias Apalodimas, WANG Xuerui, linux-efi, linux-kernel, loongarch,
WANG Rui, Huacai Chen
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 related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-27 8:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-27 8:39 [PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation WANG Rui
2026-04-27 8:39 ` [PATCH v2 1/2] efi/loongarch: Implement efi_cache_sync_image WANG Rui
2026-04-27 8:39 ` [PATCH v2 2/2] efi/libstub: Synchronize instruction cache after kernel relocation WANG Rui
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox