lsefi: fixed memory leaks
PATCH v4 1/2 lsefi: fixed memory leaks
--- grub-core/commands/efi/lsefi.c | 4 ++++ 1 file changed, 4 insertions(+)
grub-core/commands/efi/lsefi.c +4 -0
@@ -136,8 +136,12 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)), (unsigned) protocols[j]->data4[7]); } +if (protocols) +grub_efi_free_pool (protocols); } +grub_free (handles); +return 0 ; }
Signature · 1 line
2.37.2
PATCH v4 2/2 efi: new 'eficonnect' command
When efi.quickboot is enabled on VMWare (which is the default for hardware release 16 and later), it may happen that not all EFI devices are connected. Due to this, browsing the devices in make_devices() just fails to find devices, in particular disks or partitions for a given disk.
This typically happens when network booting, then trying to chainload to local disk (this is used in deployment tools such as Red Hat Satellite), which is done through using the following grub.cfg snippet:
-------- 8< ---------------- 8< ---------------- 8< -------- unset prefix
search --file --set=prefix /EFI/redhat/grubx64.efi
if [ -n "$prefix" ]; then
chainloader ($prefix)/EFI/redhat/grubx64/efi
...
-------- 8< ---------------- 8< ---------------- 8< --------
With efi.quickboot, none of the devices are connected, causing "search" to fail. Sometimes devices are connected but not the partition of the disk matching $prefix, causing partition to not be found by "chainloader".
This patch introduces a new "eficonnect pciroot|scsi|all" command whic recursively connects all EFI devices starting from a given controller type:
- if 'pciroot' is specified, recursion is performed for all PCI root handles
- if 'scsi' is specified, recursion is performed for all SCSI I/O handles (recommended usage to avoid connecting unwanted handles which may impact Grub performances)
- if 'all' is specified, recursion is performed on all handles (not recommended since it may heavily impact Grub performances)
Typical grub.cfg snippet would then be:
-------- 8< ---------------- 8< ---------------- 8< -------- eficonnect scsi
unset prefix
search --file --set=prefix /EFI/redhat/grubx64.efi if [ -n "$prefix" ]; then
chainloader ($prefix)/EFI/redhat/grubx64/efi
...
-------- 8< ---------------- 8< ---------------- 8< --------
The code is easily extensible to handle other arguments in the future if needed.
--- NEWS | 5 +- grub-core/Makefile.core.def | 6 + grub-core/commands/efi/eficonnect.c | 211 ++++++++++++++++++++++++++++ grub-core/commands/efi/lsefi.c | 1 + grub-core/disk/efi/efidisk.c | 13 ++ grub-core/kern/efi/efi.c | 13 ++ include/grub/efi/disk.h | 2 + include/grub/efi/efi.h | 5 + 8 files changed, 255 insertions(+), 1 deletion(-) create mode 100644 grub-core/commands/efi/eficonnect.c
NEWS +4 -1
@@ -12,6 +12,9 @@ New in 2.06: * BootHole and BootHole2 fixes. * ...and tons of other fixes and cleanups... +* New/improved platform support: + * New `eficonnect' command on EFI platforms. + New in 2.04: * GCC 8 and 9 support.
@@ -98,7 +101,7 @@ New in 2.02: * Prefer pmtimer for TSC calibration. * New/improved platform support: - * New `efifwsetup' and `lsefi' commands on EFI platforms. + * New `efifwsetup', `lsefi' commands on EFI platforms. * New `cmosdump' and `cmosset' commands on platforms with CMOS support. * New command `pcidump' for PCI platforms. * Improve opcode parsing in ACPI halt implementation.
grub-core/Makefile.core.def +6 -0
@@ -819,6 +819,12 @@ module = { enable = efi; }; +module = { + name = eficonnect; + efi = commands/efi/eficonnect.c; + enable = efi; +}; + module = { name = blocklist; common = commands/blocklist.c;
grub-core/commands/efi/eficonnect.c new file +211 -0
211 lines not on this page · raw message
grub-core/commands/efi/lsefi.c +1 -0
@@ -19,6 +19,7 @@#include <grub/mm.h> #include <grub/misc.h> #include <grub/efi/api.h> +#include <grub/efi/disk.h> #include <grub/efi/edid.h> #include <grub/efi/pci.h> #include <grub/efi/efi.h>
grub-core/disk/efi/efidisk.c +13 -0
@@ -396,6 +396,19 @@ enumerate_disks (void)free_devices (devices); } +void +grub_efidisk_reenumerate_disks (void ) +{ +free_devices (fd_devices); +free_devices (hd_devices); +free_devices (cd_devices); + fd_devices =0 ; + hd_devices =0 ; + cd_devices =0 ; + +enumerate_disks (); +} +static int grub_efidisk_iterate (grub_disk_dev_iterate_hook_t hook,void *hook_data,grub_disk_pull_t pull)
grub-core/kern/efi/efi.c +13 -0
@@ -95,6 +95,19 @@ grub_efi_locate_handle (grub_efi_locate_search_type_t search_type,return buffer; } +grub_efi_status_t +grub_efi_connect_controller (grub_efi_handle_t controller_handle, +grub_efi_handle_t *driver_image_handle, +grub_efi_device_path_protocol_t *remaining_device_path, +grub_efi_boolean_t recursive) +{ +grub_efi_boot_services_t *b; + + b = grub_efi_system_table->boot_services; +return efi_call_4 (b->connect_controller, controller_handle, + driver_image_handle, remaining_device_path, recursive); +} +void * grub_efi_open_protocol (grub_efi_handle_t handle, grub_efi_guid_t *protocol,
include/grub/efi/disk.h +2 -0
@@ -27,6 +27,8 @@ grub_efi_handle_tEXPORT_FUNC (grub_efidisk_get_device_handle) (grub_disk_t disk);char *EXPORT_FUNC (grub_efidisk_get_device_name ) (grub_efi_handle_t *handle); +void EXPORT_FUNC (grub_efidisk_reenumerate_disks ) (void ); +void grub_efidisk_init (void );void grub_efidisk_fini (void );
include/grub/efi/efi.h +5 -0
@@ -32,6 +32,11 @@ EXPORT_FUNC(grub_efi_locate_handle) (grub_efi_locate_search_type_t search_type, grub_efi_guid_t *protocol, void *search_key, grub_efi_uintn_t *num_handles); +grub_efi_status_t +EXPORT_FUNC (grub_efi_connect_controller ) (grub_efi_handle_t controller_handle, +grub_efi_handle_t *driver_image_handle, +grub_efi_device_path_protocol_t *remaining_device_path, +grub_efi_boolean_t recursive);void *EXPORT_FUNC (grub_efi_open_protocol ) (grub_efi_handle_t handle,grub_efi_guid_t *protocol,grub_efi_uint32_t attributes);
Signature · 1 line
2.37.2
Re: [PATCH v4 2/2] efi: new 'eficonnect' command
Quoted 42 lines · Renaud Métrich
When efi.quickboot is enabled on VMWare (which is the default for hardware release 16 and later), it may happen that not all EFI devices are connected. Due to this, browsing the devices in
make_devices()just fails to find devices, in particular disks or partitions for a given disk.
This typically happens when network booting, then trying to chainload to local disk (this is used in deployment tools such as Red Hat Satellite), which is done through using the following grub.cfg snippet:
-------- 8< ---------------- 8< ---------------- 8< -------- unset prefix
search --file --set=prefix /EFI/redhat/grubx64.efi
if [ -n "$prefix" ]; then
chainloader ($prefix)/EFI/redhat/grubx64/efi
...
-------- 8< ---------------- 8< ---------------- 8< --------With efi.quickboot, none of the devices are connected, causing "search" to fail. Sometimes devices are connected but not the partition of the disk matching $prefix, causing partition to not be found by "chainloader".
This patch introduces a new "eficonnect pciroot|scsi|all" command whic recursively connects all EFI devices starting from a given controller type:
- if 'pciroot' is specified, recursion is performed for all PCI root handles
- if 'scsi' is specified, recursion is performed for all SCSI I/O handles (recommended usage to avoid connecting unwanted handles which may impact Grub performances)
- if 'all' is specified, recursion is performed on all handles (not recommended since it may heavily impact Grub performances)Typical grub.cfg snippet would then be:
-------- 8< ---------------- 8< ---------------- 8< -------- eficonnect scsi
unset prefix
search --file --set=prefix /EFI/redhat/grubx64.efi if [ -n "$prefix" ]; then
chainloader ($prefix)/EFI/redhat/grubx64/efi
...
-------- 8< ---------------- 8< ---------------- 8< --------
Quoted 2 lines
The code is easily extensible to handle other arguments in the future if needed.
(The first patch doesn't apply to upstream - I assume it was sent by accident?)
I wanted to call out here that we're already shipping this command in RHEL under the name in previous versions (i.e., connectefi). Renaud, you probably know better than I do how much difficulty would be involved in changing that for customers, so I'll defer to you on whether that's okay.
Be well,
--Robbie
Quoted 10 lines · On Thu, 1 Sep 2022 09:28:53 +0200 Renaud Métrich <[email protected]> wrote:
Signed-off-by Renaud Métrich <[email protected]>--- grub-core/commands/efi/lsefi.c | 4 ++++ 1 file changed, 4 insertions(+)grub-core/commands/efi/lsefi.c +0
-0
grub-core/commands/efi/lsefi.c grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)), · line 140
Quoted 5 lines
grub-core/commands/efi/lsefi.c +2
-0@@ -136,8 +136,12 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)), (unsigned) protocols[j]->data4[7]); } +if (protocols) +grub_efi_free_pool (protocols);
This has the same issue that Daniel mentioned on a prior version of this series, namely that GRUB has no function named grub_efi_free_pool(). I think it would be a good idea to add one though. In the future, I recommend rebasing your patches onto the GRUB master branch before submitting patches to the list. It appears as though you're still using a branch with Redhat specific patches on it.
Glenn
Quoted 7 lines
grub-core/commands/efi/lsefi.c +2
-0} +grub_free (handles); +return 0 ; }