2020-04-29 17:43:23

by Arvind Sankar

[permalink] [raw]
Subject: [PATCH 02/10] efi: Add a helper function to split 64-bit values

In several places 64-bit values need to be split up into two 32-bit
fields, in order to be backward-compatible with the old 32-bit ABIs.

Instead of open-coding this, add a helper function to set a 64-bit value
as two 32-bit fields.

Signed-off-by: Arvind Sankar <[email protected]>
---
drivers/firmware/efi/libstub/efistub.h | 7 ++++++
drivers/firmware/efi/libstub/gop.c | 6 ++---
drivers/firmware/efi/libstub/x86-stub.c | 32 +++++++++++--------------
3 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index 5ff63230a1f1..e8aa70ba08d5 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -87,6 +87,13 @@ extern const efi_system_table_t *efi_system_table;
((handle = efi_get_handle_at((array), i)) || true); \
i++)

+static inline
+void efi_set_u64_split(u64 data, u32 *lo, u32 *hi)
+{
+ *lo = lower_32_bits(data);
+ *hi = upper_32_bits(data);
+}
+
/*
* Allocation types for calls to boottime->allocate_pages.
*/
diff --git a/drivers/firmware/efi/libstub/gop.c b/drivers/firmware/efi/libstub/gop.c
index 216327d0b034..64cee0febae0 100644
--- a/drivers/firmware/efi/libstub/gop.c
+++ b/drivers/firmware/efi/libstub/gop.c
@@ -422,7 +422,6 @@ static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto,
efi_graphics_output_protocol_t *gop;
efi_graphics_output_protocol_mode_t *mode;
efi_graphics_output_mode_info_t *info;
- efi_physical_addr_t fb_base;

gop = find_gop(proto, size, handles);

@@ -442,9 +441,8 @@ static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto,
si->lfb_width = info->horizontal_resolution;
si->lfb_height = info->vertical_resolution;

- fb_base = efi_table_attr(mode, frame_buffer_base);
- si->lfb_base = lower_32_bits(fb_base);
- si->ext_lfb_base = upper_32_bits(fb_base);
+ efi_set_u64_split(efi_table_attr(mode, frame_buffer_base),
+ &si->lfb_base, &si->ext_lfb_base);
if (si->ext_lfb_base)
si->capabilities |= VIDEO_CAPABILITY_64BIT_BASE;

diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
index d4bafd7f6f9f..677b5a1e0543 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -408,9 +408,8 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
if (!cmdline_ptr)
goto fail;

- hdr->cmd_line_ptr = (unsigned long)cmdline_ptr;
- /* Fill in upper bits of command line address, NOP on 32 bit */
- boot_params->ext_cmd_line_ptr = (u64)(unsigned long)cmdline_ptr >> 32;
+ efi_set_u64_split((u64)cmdline_ptr,
+ &hdr->cmd_line_ptr, &boot_params->ext_cmd_line_ptr);

hdr->ramdisk_image = 0;
hdr->ramdisk_size = 0;
@@ -427,10 +426,10 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
ULONG_MAX);
if (status != EFI_SUCCESS)
goto fail2;
- hdr->ramdisk_image = ramdisk_addr & 0xffffffff;
- hdr->ramdisk_size = ramdisk_size & 0xffffffff;
- boot_params->ext_ramdisk_image = (u64)ramdisk_addr >> 32;
- boot_params->ext_ramdisk_size = (u64)ramdisk_size >> 32;
+ efi_set_u64_split(ramdisk_addr, &hdr->ramdisk_image,
+ &boot_params->ext_ramdisk_image);
+ efi_set_u64_split(ramdisk_size, &hdr->ramdisk_size,
+ &boot_params->ext_ramdisk_size);
}
}

@@ -639,17 +638,14 @@ static efi_status_t exit_boot_func(struct efi_boot_memmap *map,
: EFI32_LOADER_SIGNATURE;
memcpy(&p->efi->efi_loader_signature, signature, sizeof(__u32));

- p->efi->efi_systab = (unsigned long)efi_system_table;
+ efi_set_u64_split((u64)efi_system_table,
+ &p->efi->efi_systab, &p->efi->efi_systab_hi);
p->efi->efi_memdesc_size = *map->desc_size;
p->efi->efi_memdesc_version = *map->desc_ver;
- p->efi->efi_memmap = (unsigned long)*map->map;
+ efi_set_u64_split((u64)*map->map,
+ &p->efi->efi_memmap, &p->efi->efi_memmap_hi);
p->efi->efi_memmap_size = *map->map_size;

-#ifdef CONFIG_X86_64
- p->efi->efi_systab_hi = (unsigned long)efi_system_table >> 32;
- p->efi->efi_memmap_hi = (unsigned long)*map->map >> 32;
-#endif
-
return EFI_SUCCESS;
}

@@ -785,10 +781,10 @@ unsigned long efi_main(efi_handle_t handle,

status = efi_load_initrd_dev_path(&addr, &size, ULONG_MAX);
if (status == EFI_SUCCESS) {
- hdr->ramdisk_image = (u32)addr;
- hdr->ramdisk_size = (u32)size;
- boot_params->ext_ramdisk_image = (u64)addr >> 32;
- boot_params->ext_ramdisk_size = (u64)size >> 32;
+ efi_set_u64_split(addr, &hdr->ramdisk_image,
+ &boot_params->ext_ramdisk_image);
+ efi_set_u64_split(size, &hdr->ramdisk_size,
+ &boot_params->ext_ramdisk_size);
} else if (status != EFI_NOT_FOUND) {
efi_printk("efi_load_initrd_dev_path() failed!\n");
goto fail;
--
2.26.2


2020-04-29 23:54:18

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 02/10] efi: Add a helper function to split 64-bit values

Hi Arvind,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on efi/next]
[also build test WARNING on next-20200429]
[cannot apply to v5.7-rc3]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Arvind-Sankar/efi-some-cleanups-refactoring-for-efi-next/20200430-051025
base: https://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git next
config: i386-defconfig (attached as .config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce:
# save the attached .config to linux build tree
make ARCH=i386

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <[email protected]>

All warnings (new ones prefixed by >>):

drivers/firmware/efi/libstub/x86-stub.c: In function 'efi_pe_entry':
>> drivers/firmware/efi/libstub/x86-stub.c:411:20: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
efi_set_u64_split((u64)cmdline_ptr,
^
drivers/firmware/efi/libstub/x86-stub.c: In function 'exit_boot_func':
drivers/firmware/efi/libstub/x86-stub.c:641:20: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
efi_set_u64_split((u64)efi_system_table,
^
drivers/firmware/efi/libstub/x86-stub.c:645:20: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
efi_set_u64_split((u64)*map->map,
^

vim +411 drivers/firmware/efi/libstub/x86-stub.c

343
344 void __noreturn efi_stub_entry(efi_handle_t handle,
345 efi_system_table_t *sys_table_arg,
346 struct boot_params *boot_params);
347
348 /*
349 * Because the x86 boot code expects to be passed a boot_params we
350 * need to create one ourselves (usually the bootloader would create
351 * one for us).
352 */
353 efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
354 efi_system_table_t *sys_table_arg)
355 {
356 struct boot_params *boot_params;
357 struct setup_header *hdr;
358 efi_loaded_image_t *image;
359 void *image_base;
360 efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID;
361 int options_size = 0;
362 efi_status_t status;
363 char *cmdline_ptr;
364 unsigned long ramdisk_addr;
365 unsigned long ramdisk_size;
366
367 efi_system_table = sys_table_arg;
368
369 /* Check if we were booted by the EFI firmware */
370 if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
371 efi_exit(handle, EFI_INVALID_PARAMETER);
372
373 status = efi_bs_call(handle_protocol, handle, &proto, (void **)&image);
374 if (status != EFI_SUCCESS) {
375 efi_printk("Failed to get handle for LOADED_IMAGE_PROTOCOL\n");
376 efi_exit(handle, status);
377 }
378
379 image_base = efi_table_attr(image, image_base);
380 image_offset = (void *)startup_32 - image_base;
381
382 status = efi_allocate_pages(sizeof(struct boot_params),
383 (unsigned long *)&boot_params, ULONG_MAX);
384 if (status != EFI_SUCCESS) {
385 efi_printk("Failed to allocate lowmem for boot params\n");
386 efi_exit(handle, status);
387 }
388
389 memset(boot_params, 0x0, sizeof(struct boot_params));
390
391 hdr = &boot_params->hdr;
392
393 /* Copy the second sector to boot_params */
394 memcpy(&hdr->jump, image_base + 512, 512);
395
396 /*
397 * Fill out some of the header fields ourselves because the
398 * EFI firmware loader doesn't load the first sector.
399 */
400 hdr->root_flags = 1;
401 hdr->vid_mode = 0xffff;
402 hdr->boot_flag = 0xAA55;
403
404 hdr->type_of_loader = 0x21;
405
406 /* Convert unicode cmdline to ascii */
407 cmdline_ptr = efi_convert_cmdline(image, &options_size, ULONG_MAX);
408 if (!cmdline_ptr)
409 goto fail;
410
> 411 efi_set_u64_split((u64)cmdline_ptr,
412 &hdr->cmd_line_ptr, &boot_params->ext_cmd_line_ptr);
413
414 hdr->ramdisk_image = 0;
415 hdr->ramdisk_size = 0;
416
417 if (efi_is_native()) {
418 status = efi_parse_options(cmdline_ptr);
419 if (status != EFI_SUCCESS)
420 goto fail2;
421
422 if (!efi_noinitrd) {
423 status = efi_load_initrd(image, &ramdisk_addr,
424 &ramdisk_size,
425 hdr->initrd_addr_max,
426 ULONG_MAX);
427 if (status != EFI_SUCCESS)
428 goto fail2;
429 efi_set_u64_split(ramdisk_addr, &hdr->ramdisk_image,
430 &boot_params->ext_ramdisk_image);
431 efi_set_u64_split(ramdisk_size, &hdr->ramdisk_size,
432 &boot_params->ext_ramdisk_size);
433 }
434 }
435
436 efi_stub_entry(handle, sys_table_arg, boot_params);
437 /* not reached */
438
439 fail2:
440 efi_free(options_size, (unsigned long)cmdline_ptr);
441 fail:
442 efi_free(sizeof(struct boot_params), (unsigned long)boot_params);
443
444 efi_exit(handle, status);
445 }
446

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (5.43 kB)
.config.gz (27.73 kB)
Download all attachments