Re: [PATCH 2/2] efi/libstub: Synchronize instruction cache after kernel relocation

Huacai Chen <[email protected]>
Newsgroups org.kernel.vger.linux-efi,dev.linux.lists.loongarch,org.kernel.vger.linux-kernel
Message-ID <CAAhV-H7zGFjzBTCLMZvE+etd2J9Te1+9Xr9GwtjvBSXgGYfQEw@mail.gmail.com>
On Mon, Apr 27, 2026 at 11:45 AM WANG Rui <[email protected]> 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 <[email protected]>
Reviewed-by: Huacai Chen <[email protected]>

> ---
>  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
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.