Re: [PATCH 2/2 v2] efi_loader: Disable devices before handing over control

2020-10-22 Thread Heinrich Schuchardt
On 10/22/20 12:04 AM, Ilias Apalodimas wrote:
> U-Boot Driver Model is supposed to remove devices with either
> DM_REMOVE_ACTIVE_DMA or DM_REMOVE_OS_PREPARE flags set, before exiting.
> Our bootm command does that by explicitly calling calling
> "dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);" and we also disable any
> USB devices.
>
> The EFI equivalent is doing none of those at the moment. As a result
> probing an fTPM driver now renders it unusable in Linux. During our
> (*probe) callback we open a session with OP-TEE, which is supposed to
> close with our (*remove) callback. Since the (*remove) is never called,
> once we boot into Linux and try to probe the device again we are getting
> a busy error response. Moreover all uclass (*preremove) functions won't
> run.
>
> So let's fix this by mimicking what bootm does and disconnect devices
> when efi_exit_boot_services() is called.
>
> Signed-off-by: Ilias Apalodimas 

Reviewed-by: Heinrich Schuchardt 


Re: [PATCH 2/2 v2] efi_loader: Disable devices before handing over control

2020-10-21 Thread Ilias Apalodimas
+cc Mark


On Thu, 22 Oct 2020 at 01:04, Ilias Apalodimas
 wrote:
>
> U-Boot Driver Model is supposed to remove devices with either
> DM_REMOVE_ACTIVE_DMA or DM_REMOVE_OS_PREPARE flags set, before exiting.
> Our bootm command does that by explicitly calling calling
> "dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);" and we also disable any
> USB devices.
>
> The EFI equivalent is doing none of those at the moment. As a result
> probing an fTPM driver now renders it unusable in Linux. During our
> (*probe) callback we open a session with OP-TEE, which is supposed to
> close with our (*remove) callback. Since the (*remove) is never called,
> once we boot into Linux and try to probe the device again we are getting
> a busy error response. Moreover all uclass (*preremove) functions won't
> run.
>
> So let's fix this by mimicking what bootm does and disconnect devices
> when efi_exit_boot_services() is called.
>
> Signed-off-by: Ilias Apalodimas 
> ---
> changes since v1:
> - Add a patch sorting the .h files inclusions
> - Fix compilation errors for sandbox_spl_defconfig
> - TravisCI: https://travis-ci.com/github/apalos/u-boot/builds/191447335
>  lib/efi_loader/efi_boottime.c | 6 ++
>  1 file changed, 6 insertions(+)
>
> diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
> index 2896c3ea5aa8..b26ac9fbfc79 100644
> --- a/lib/efi_loader/efi_boottime.c
> +++ b/lib/efi_loader/efi_boottime.c
> @@ -8,6 +8,8 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -15,6 +17,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>
> @@ -1993,7 +1996,10 @@ static efi_status_t EFIAPI 
> efi_exit_boot_services(efi_handle_t image_handle,
> list_del(>link);
> }
>
> +   if IS_ENABLED(CONFIG_USB_DEVICE)
> +   udc_disconnect();
> board_quiesce_devices();
> +   dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
>
> /* Patch out unsupported runtime function */
> efi_runtime_detach();
> --
> 2.28.0
>


[PATCH 2/2 v2] efi_loader: Disable devices before handing over control

2020-10-21 Thread Ilias Apalodimas
U-Boot Driver Model is supposed to remove devices with either
DM_REMOVE_ACTIVE_DMA or DM_REMOVE_OS_PREPARE flags set, before exiting.
Our bootm command does that by explicitly calling calling
"dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);" and we also disable any
USB devices.

The EFI equivalent is doing none of those at the moment. As a result
probing an fTPM driver now renders it unusable in Linux. During our
(*probe) callback we open a session with OP-TEE, which is supposed to
close with our (*remove) callback. Since the (*remove) is never called,
once we boot into Linux and try to probe the device again we are getting
a busy error response. Moreover all uclass (*preremove) functions won't
run.

So let's fix this by mimicking what bootm does and disconnect devices
when efi_exit_boot_services() is called.

Signed-off-by: Ilias Apalodimas 
---
changes since v1:
- Add a patch sorting the .h files inclusions
- Fix compilation errors for sandbox_spl_defconfig
- TravisCI: https://travis-ci.com/github/apalos/u-boot/builds/191447335
 lib/efi_loader/efi_boottime.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index 2896c3ea5aa8..b26ac9fbfc79 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -8,6 +8,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -15,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -1993,7 +1996,10 @@ static efi_status_t EFIAPI 
efi_exit_boot_services(efi_handle_t image_handle,
list_del(>link);
}
 
+   if IS_ENABLED(CONFIG_USB_DEVICE)
+   udc_disconnect();
board_quiesce_devices();
+   dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
 
/* Patch out unsupported runtime function */
efi_runtime_detach();
-- 
2.28.0