From 74d90b33f8490adcee2026ece18d8411d93b6a39 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 22 Sep 2017 14:02:40 +0100 Subject: [PATCH] [efi] Inhibit our driver Start() method during disconnection attempts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some HP BIOSes (observed with a Z840) seem to attempt to connect our drivers in the middle of our call to DisconnectController(). The precise chain of events is unclear, but the symptom is that we see several calls to our Supported() and Start() methods, followed by a system lock-up. Work around this dubious BIOS behaviour by explicitly failing calls to our Start() method while we are in the middle of attempting to disconnect drivers. Reported-by: Jordan Wright Debugged-by: Adrian Lucrèce Céleste Debugged-by: Christian Nilsson Tested-by: Jordan Wright Signed-off-by: Michael Brown --- src/interface/efi/efi_driver.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/interface/efi/efi_driver.c b/src/interface/efi/efi_driver.c index 2cefed2f..de0f61f9 100644 --- a/src/interface/efi/efi_driver.c +++ b/src/interface/efi/efi_driver.c @@ -44,6 +44,9 @@ static EFI_DRIVER_BINDING_PROTOCOL efi_driver_binding; /** List of controlled EFI devices */ static LIST_HEAD ( efi_devices ); +/** We are currently disconnecting drivers */ +static int efi_driver_disconnecting; + /** * Find EFI device * @@ -159,6 +162,14 @@ efi_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused, goto err_already_started; } + /* Do nothing if we are currently disconnecting drivers */ + if ( efi_driver_disconnecting ) { + DBGC ( device, "EFIDRV %s refusing to start during " + "disconnection\n", efi_handle_name ( device ) ); + efirc = EFI_NOT_READY; + goto err_disconnecting; + } + /* Open device path */ if ( ( efirc = bs->OpenProtocol ( device, &efi_device_path_protocol_guid, @@ -220,6 +231,7 @@ efi_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused, efi_image_handle, device ); } err_open_path: + err_disconnecting: err_already_started: return efirc; } @@ -411,6 +423,7 @@ static int efi_driver_connect ( EFI_HANDLE device ) { DBGC2_EFI_PROTOCOLS ( device, device ); DBGC ( device, "EFIDRV %s disconnecting existing drivers\n", efi_handle_name ( device ) ); + efi_driver_disconnecting = 1; if ( ( efirc = bs->DisconnectController ( device, NULL, NULL ) ) != 0 ) { rc = -EEFI ( efirc ); @@ -419,6 +432,7 @@ static int efi_driver_connect ( EFI_HANDLE device ) { strerror ( rc ) ); /* Ignore the error and attempt to connect our drivers */ } + efi_driver_disconnecting = 0; DBGC2 ( device, "EFIDRV %s after disconnecting:\n", efi_handle_name ( device ) ); DBGC2_EFI_PROTOCOLS ( device, device ); @@ -450,9 +464,11 @@ static int efi_driver_disconnect ( EFI_HANDLE device ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; /* Disconnect our driver */ + efi_driver_disconnecting = 1; bs->DisconnectController ( device, efi_driver_binding.DriverBindingHandle, NULL ); + efi_driver_disconnecting = 0; return 0; }