On Fri, 2 Oct 2026 20:31:45 -0300 Jason Gunthorpe <[email protected]> wrote:
> There are three possibilities here, each a little different: > - relocating for kaslr, just request extra_size like the zboot flow does > when allocating from EFI > - in place, attempt to allocate from EFI precisely after Image to > confirm nothing weird is there, failing that > - like any other error with the in place EFI location allocate > non-randomly with extra_size included > > Remove the callers' assignments of reserve_size since > efi_kaslr_relocate_kernel() now does it. > > Signed-off-by: Jason Gunthorpe <[email protected]> A couple of trivial comments. Otherwise looks good to me. Reviewed-by: Jonathan Cameron <[email protected]> > diff --git a/drivers/firmware/efi/libstub/kaslr.c > b/drivers/firmware/efi/libstub/kaslr.c > index 4bc963e999eb97..e419f3800af517 100644 > --- a/drivers/firmware/efi/libstub/kaslr.c > +++ b/drivers/firmware/efi/libstub/kaslr.c > @@ -125,16 +164,29 @@ efi_status_t efi_kaslr_relocate_kernel(unsigned long > *image_addr, > } > > if (status != EFI_SUCCESS) { > - if (!check_image_region(*image_addr, kernel_memsize)) { > + bool image_region_ok = > + check_image_region(*image_addr, kernel_memsize); > + > + if (!image_region_ok) { Why this change? I don't particularly mind but seems to be churn that isn't necessarily needed. > efi_err("FIRMWARE BUG: Image BSS overlaps adjacent EFI > memory region\n"); > } else if (IS_ALIGNED(*image_addr, min_kimg_align) && > - (unsigned long)_end < EFI_ALLOC_LIMIT) { > - /* > - * Just execute from wherever we were loaded by the > - * UEFI PE/COFF loader if the placement is suitable. > - */ > - *reserve_size = 0; > - return EFI_SUCCESS; > + (unsigned long)_end + extra_size < EFI_ALLOC_LIMIT) { > + if (!extra_size) { > + /* > + * Just execute from wherever we were loaded by > + * the UEFI PE/COFF loader if the placement is > + * suitable. > + */ > + *reserve_size = 0; > + return EFI_SUCCESS; > + } > + > + status = allocate_image_tail(*image_addr, > + kernel_memsize, extra_size, > + reserve_addr, > + reserve_size); I'd move reserve_size up a line to group it with reserve_addr. > + if (status == EFI_SUCCESS) > + return EFI_SUCCESS; > } > > status = efi_allocate_pages_aligned(*reserve_size, reserve_addr, > diff --git a/drivers/firmware/efi/libstub/riscv-stub.c > b/drivers/firmware/efi/libstub/riscv-stub.c > index 725b634c517919..a88b2d275e5bb0 100644 > --- a/drivers/firmware/efi/libstub/riscv-stub.c > +++ b/drivers/firmware/efi/libstub/riscv-stub.c > @@ -37,7 +37,6 @@ efi_status_t handle_kernel_image(unsigned long *image_addr, > kernel_codesize = __init_text_end - _start; > kernel_memsize = kernel_size + (_end - _edata); > *image_addr = (unsigned long)_start; > - *reserve_size = kernel_memsize; > > status = efi_kaslr_relocate_kernel(image_addr, > reserve_addr, reserve_size,
