* [RESEND PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation
@ 2026-04-27 8:47 WANG Rui
2026-04-27 8:47 ` [RESEND PATCH v2 1/2] efi/loongarch: Implement efi_cache_sync_image() WANG Rui
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: WANG Rui @ 2026-04-27 8:47 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.
* Add "()" after function name in the subject.
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] 6+ messages in thread* [RESEND PATCH v2 1/2] efi/loongarch: Implement efi_cache_sync_image()
2026-04-27 8:47 [RESEND PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation WANG Rui
@ 2026-04-27 8:47 ` WANG Rui
2026-04-27 8:47 ` [RESEND PATCH v2 2/2] efi/libstub: Synchronize instruction cache after kernel relocation WANG Rui
2026-04-27 16:11 ` [RESEND PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency " Ard Biesheuvel
2 siblings, 0 replies; 6+ messages in thread
From: WANG Rui @ 2026-04-27 8:47 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] 6+ messages in thread* [RESEND PATCH v2 2/2] efi/libstub: Synchronize instruction cache after kernel relocation
2026-04-27 8:47 [RESEND PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation WANG Rui
2026-04-27 8:47 ` [RESEND PATCH v2 1/2] efi/loongarch: Implement efi_cache_sync_image() WANG Rui
@ 2026-04-27 8:47 ` WANG Rui
2026-04-27 16:11 ` [RESEND PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency " Ard Biesheuvel
2 siblings, 0 replies; 6+ messages in thread
From: WANG Rui @ 2026-04-27 8:47 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] 6+ messages in thread
* Re: [RESEND PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation
2026-04-27 8:47 [RESEND PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation WANG Rui
2026-04-27 8:47 ` [RESEND PATCH v2 1/2] efi/loongarch: Implement efi_cache_sync_image() WANG Rui
2026-04-27 8:47 ` [RESEND PATCH v2 2/2] efi/libstub: Synchronize instruction cache after kernel relocation WANG Rui
@ 2026-04-27 16:11 ` Ard Biesheuvel
2026-04-28 11:07 ` Ard Biesheuvel
2 siblings, 1 reply; 6+ messages in thread
From: Ard Biesheuvel @ 2026-04-27 16:11 UTC (permalink / raw)
To: WANG Rui, Huacai Chen
Cc: Ilias Apalodimas, WANG Xuerui, linux-efi, linux-kernel, loongarch
On Mon, 27 Apr 2026, at 10:47, WANG Rui wrote:
> Changes since [v1]:
> * Move efi_cache_sync_image() after check_platform_features(), matching arm64.
> * Add "()" after function name in the subject.
>
> 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
>
Queued up in efi/urgent - thanks.
> 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] 6+ messages in thread
* Re: [RESEND PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation
2026-04-27 16:11 ` [RESEND PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency " Ard Biesheuvel
@ 2026-04-28 11:07 ` Ard Biesheuvel
2026-04-29 7:32 ` Huacai Chen
0 siblings, 1 reply; 6+ messages in thread
From: Ard Biesheuvel @ 2026-04-28 11:07 UTC (permalink / raw)
To: WANG Rui, Huacai Chen
Cc: Ilias Apalodimas, WANG Xuerui, linux-efi, linux-kernel, loongarch
On Mon, 27 Apr 2026, at 18:11, Ard Biesheuvel wrote:
> On Mon, 27 Apr 2026, at 10:47, WANG Rui wrote:
>> Changes since [v1]:
>> * Move efi_cache_sync_image() after check_platform_features(), matching arm64.
>> * Add "()" after function name in the subject.
>>
>> 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
>>
>
> Queued up in efi/urgent - thanks.
>
This breaks the ARM build.
Since LoongArch is the only remaining user of efi_relocate_kernel(), I'll move it into drivers/firmware/efi/libstub/loongarch-stub.c first, and fix up these patches accordingly afterwards (no need to resend anything)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RESEND PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation
2026-04-28 11:07 ` Ard Biesheuvel
@ 2026-04-29 7:32 ` Huacai Chen
0 siblings, 0 replies; 6+ messages in thread
From: Huacai Chen @ 2026-04-29 7:32 UTC (permalink / raw)
To: Ard Biesheuvel
Cc: WANG Rui, Ilias Apalodimas, WANG Xuerui, linux-efi, linux-kernel,
loongarch
On Tue, Apr 28, 2026 at 7:07 PM Ard Biesheuvel <ardb@kernel.org> wrote:
>
>
>
> On Mon, 27 Apr 2026, at 18:11, Ard Biesheuvel wrote:
> > On Mon, 27 Apr 2026, at 10:47, WANG Rui wrote:
> >> Changes since [v1]:
> >> * Move efi_cache_sync_image() after check_platform_features(), matching arm64.
> >> * Add "()" after function name in the subject.
> >>
> >> 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
> >>
> >
> > Queued up in efi/urgent - thanks.
Maybe this series should cc stable?
Huacai
> >
>
> This breaks the ARM build.
>
> Since LoongArch is the only remaining user of efi_relocate_kernel(), I'll move it into drivers/firmware/efi/libstub/loongarch-stub.c first, and fix up these patches accordingly afterwards (no need to resend anything)
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-04-29 7:32 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-27 8:47 [RESEND PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation WANG Rui
2026-04-27 8:47 ` [RESEND PATCH v2 1/2] efi/loongarch: Implement efi_cache_sync_image() WANG Rui
2026-04-27 8:47 ` [RESEND PATCH v2 2/2] efi/libstub: Synchronize instruction cache after kernel relocation WANG Rui
2026-04-27 16:11 ` [RESEND PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency " Ard Biesheuvel
2026-04-28 11:07 ` Ard Biesheuvel
2026-04-29 7:32 ` Huacai Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox