[PATCH v3 08/15] efi/libstub: arm64: Use struct efi_image_info to access image properties

Ard Biesheuvel ardb at kernel.org
Mon Nov 16 11:33:20 PST 2026



On Mon, 16 Nov 2026, at 19:52, Jason Gunthorpe wrote:
>> [ ... 53 lines skipped ... ]
>> @@ -22,23 +21,23 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
>>  				 efi_handle_t image_handle,
>>  				 const struct efi_image_info **image_info)
>>  {
>> -	unsigned long kernel_size, kernel_codesize, kernel_memsize;
>> +	unsigned long kernel_base	= efistub_kernel_base(*image_info);
>> +	unsigned long kernel_size	= efistub_kernel_size(*image_info);
>> +	unsigned long kernel_codesize	= efistub_kernel_codesize(*image_info);
>> +	unsigned long kernel_memsize	= efistub_kernel_memsize(*image_info);
>>  	efi_status_t status;
>>  
>> -	if (image->image_base != _text) {
>> +	if (image->image_base != (void *)kernel_base) {
>>  		efi_err("FIRMWARE BUG: efi_loaded_image_t::image_base has bogus value\n");
>> -		image->image_base = _text;
>> +		image->image_base = (void *)kernel_base;
>>  	}
>>  
>> -	if (!IS_ALIGNED((u64)_text, SEGMENT_ALIGN))
>> +	if (!IS_ALIGNED(kernel_base, SEGMENT_ALIGN))
>>  		efi_err("FIRMWARE BUG: kernel image not aligned on %dk boundary\n",
>>  			SEGMENT_ALIGN >> 10);
>>  
>> -	kernel_size = _edata - _text;
>> -	kernel_codesize = __inittext_end - _text;
>> -	kernel_memsize = kernel_size + (_end - _edata);
>>  	*reserve_size = kernel_memsize;
>> -	*image_addr = (unsigned long)_text;
>> +	*image_addr = kernel_base;
>>  
>>  	status = efi_kaslr_relocate_kernel(image_addr, reserve_addr,
>>  					   reserve_size, kernel_size,
>
> There is a further consolidation here, the two places that call
> efi_kaslr_relocate_kernel() get the args from image_info, so we could
> just pass image_info directly and remove the duplicated extraction and
> extra parameters.
>
> It could then handle the image_info adjustment too instead of open
> coding it twice.
>

Indeed.

> I wonder if riscv should have the segment_align and image_base checks
> too? Maybe the whole function is just a call to
> efi_kaslr_relocate_kernel() ?
>

IIRC they were added specifically for RedHat's spectacularly buggy
GRUB fork at the the time, so maybe by now we can just remove those.

>> [ ... 9 lines skipped ... ]
>> -asmlinkage void primary_entry(void);
>> -
>> -unsigned long primary_entry_offset(void)
>> -{
>> -	/*
>> -	 * When built as part of the kernel, the EFI stub cannot branch to the
>> -	 * kernel proper via the image header, as the PE/COFF header is
>> -	 * strictly not part of the in-memory presentation of the image, only
>> -	 * of the file representation. So instead, we need to jump to the
>> -	 * actual entrypoint in the .text region of the image.
>> -	 */
>> -	return (char *)primary_entry - _text;
>> -}
>
> I think this hunk belongs to the previous patch which removed the
> caller?
>

Indeed.

> Anyhow, the logic looks fine to me
>
> Reviewed-by: Jason Gunthorpe <jgg at nvidia.com>
>

Thanks.



More information about the linux-riscv mailing list