[RESEND PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation

WANG Rui posted 2 patches 1 month, 2 weeks ago
drivers/firmware/efi/libstub/loongarch.c | 5 +++++
drivers/firmware/efi/libstub/relocate.c  | 1 +
2 files changed, 6 insertions(+)
[RESEND PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation
Posted by WANG Rui 1 month, 2 weeks ago
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
Re: [RESEND PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation
Posted by Ard Biesheuvel 1 month, 2 weeks ago

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
Re: [RESEND PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation
Posted by Ard Biesheuvel 1 month, 2 weeks ago

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)
Re: [RESEND PATCH v2 0/2] efi/libstub: Ensure instruction cache coherency after kernel relocation
Posted by Huacai Chen 1 month, 2 weeks ago
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)
>