All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: Simon Glass <sjg@chromium.org>
Cc: U-Boot Mailing List <u-boot@lists.denx.de>,
	Eddie James <eajames@linux.ibm.com>,
	Fabrice Gasnier <fabrice.gasnier@foss.st.com>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Marek Vasut <marex@denx.de>,
	Mattijs Korpershoek <mkorpershoek@baylibre.com>,
	Patrice Chotard <patrice.chotard@foss.st.com>,
	Patrick Delaunay <patrick.delaunay@foss.st.com>,
	Safae Ouajih <souajih@baylibre.com>
Subject: Re: [PATCH v4 05/12] usb: Avoid unbinding devices in use by bootflows
Date: Mon, 13 Nov 2023 00:30:03 +0100	[thread overview]
Message-ID: <43EF5E14-0AE3-456A-B9D4-67B8F4405555@gmx.de> (raw)
In-Reply-To: <CAPnjgZ3wEzHNqzpsF1zU6U4WBAm=oMYEzRRR-UuqDEwXB24rLw@mail.gmail.com>



Am 12. November 2023 22:20:50 MEZ schrieb Simon Glass <sjg@chromium.org>:
>Hi Heinrich,
>
>On Sun, 12 Nov 2023 at 13:32, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>>
>>
>>
>> Am 12. November 2023 21:02:42 MEZ schrieb Simon Glass <sjg@chromium.org>:
>> >When a USB device is unbound, it causes any bootflows attached to it to
>> >be removed, via a call to bootdev_clear_bootflows() from
>> >bootdev_pre_unbind(). This obviously makes it impossible to boot the
>> >bootflow.
>> >
>> >However, when booting a bootflow that relies on USB, usb_stop() is
>> >called, which unbinds the device. For EFI, this happens in
>> >efi_exit_boot_services() which means that the bootflow disappears
>> >before it is finished with.
>>
>> After ExitBootServices() no driver of U-Boot can be used as the operating system is in charge.
>>
>> Any bootflow inside U-Boot is terminated by definition when reaching ExitBootServices.
>>
>> >
>> >There is no need to unbind all the USB devices just to quiesce them.
>> >Add a new usb_pause() call which removes them but leaves them bound.
>>
>> As U-Boot must not access any device after ExitBootServices() it is unclear to me what you want to achieve.
>
>I can't remember exactly what is needed from the bootflow, but
>something is. Perhaps the kernel, or the cmdline, or fdt? It would
>have been better if I had mentioned this explicitly,  But then this
>patch has been sitting around for ages...
>
>In any case, the intent of exit-boot-services is not to free all the
>memory used, since some of it may have been used to hold data that the
>app continues to use.

The EFI application reads the memory map and receives an ID which it passes to ExitBootServiced() after this point any memory not marked as EFI runtime can be used by the EFI app. This includes the memory that harbors the U-Boot USB drivers. Therefore no drivers can be used here.

Starting the EFI app via StartImage() must  terminate any running U-Boot "boot flow".

After ExitBootServices() the EFI application cannot return to U-Boot except for SetVirtualAdressMspsetting which relocates the EFI runtime.

Bootflows and U-Boot drivers have no meaning after ExitBootServices().



>
>Also there is U-Boot code between when the devices are unbound and
>when U-Boot actually exits back to the app.
>
>This hang was 100% repeatable on brya (an x86 Chromebook) and it took
>quite a while to find.

We need a better understanding of the problem that you experience to find an adequate solution. Why does removing all devices lead to hanging the system?

Best regards

Heinrich

>
>Regards,
>Simon
>
>
>>
>> Best regards
>>
>> Heinrich
>>
>> >
>> >This resolves a hang on x86 when booting a distro from USB. This was
>> >found using a device with 4 bootflows, the last of which was USB.
>> >
>> >
>> >Signed-off-by: Simon Glass <sjg@chromium.org>
>> >---
>> >
>> >Changes in v4:
>> >- Don't rename the legacy-USB functions
>> >- Add a bit more detail to the comment
>> >
>> >Changes in v2:
>> >- Add new patch to avoid unbinding devices in use by bootflows
>> >
>> > boot/bootm.c                  |  2 +-
>> > common/usb.c                  |  5 +++++
>> > drivers/usb/host/usb-uclass.c | 14 ++++++++++++--
>> > include/usb.h                 | 21 ++++++++++++++++++++-
>> > 4 files changed, 38 insertions(+), 4 deletions(-)
>> >
>> >diff --git a/boot/bootm.c b/boot/bootm.c
>> >index cb61485c226c..d9c3fa8dad99 100644
>> >--- a/boot/bootm.c
>> >+++ b/boot/bootm.c
>> >@@ -502,7 +502,7 @@ ulong bootm_disable_interrupts(void)
>> >        * updated every 1 ms within the HCCA structure in SDRAM! For more
>> >        * details see the OpenHCI specification.
>> >        */
>> >-      usb_stop();
>> >+      usb_pause();
>> > #endif
>> >       return iflag;
>> > }
>> >diff --git a/common/usb.c b/common/usb.c
>> >index 836506dcd9e9..a486d1c87d4d 100644
>> >--- a/common/usb.c
>> >+++ b/common/usb.c
>> >@@ -144,6 +144,11 @@ int usb_stop(void)
>> >       return 0;
>> > }
>> >
>> >+int usb_pause(void)
>> >+{
>> >+      return usb_stop();
>> >+}
>> >+
>> > /******************************************************************************
>> >  * Detect if a USB device has been plugged or unplugged.
>> >  */
>> >diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c
>> >index a1cd0ad2d669..c26c65d7986b 100644
>> >--- a/drivers/usb/host/usb-uclass.c
>> >+++ b/drivers/usb/host/usb-uclass.c
>> >@@ -173,7 +173,7 @@ int usb_get_max_xfer_size(struct usb_device *udev, size_t *size)
>> >       return ops->get_max_xfer_size(bus, size);
>> > }
>> >
>> >-int usb_stop(void)
>> >+static int usb_finish(bool unbind_all)
>> > {
>> >       struct udevice *bus;
>> >       struct udevice *rh;
>> >@@ -195,7 +195,7 @@ int usb_stop(void)
>> >
>> >               /* Locate root hub device */
>> >               device_find_first_child(bus, &rh);
>> >-              if (rh) {
>> >+              if (rh && unbind_all) {
>> >                       /*
>> >                        * All USB devices are children of root hub.
>> >                        * Unbinding root hub will unbind all of its children.
>> >@@ -222,6 +222,16 @@ int usb_stop(void)
>> >       return err;
>> > }
>> >
>> >+int usb_stop(void)
>> >+{
>> >+      return usb_finish(true);
>> >+}
>> >+
>> >+int usb_pause(void)
>> >+{
>> >+      return usb_finish(false);
>> >+}
>> >+
>> > static void usb_scan_bus(struct udevice *bus, bool recurse)
>> > {
>> >       struct usb_bus_priv *priv;
>> >diff --git a/include/usb.h b/include/usb.h
>> >index 09e3f0cb309c..b964e2e1f6b2 100644
>> >--- a/include/usb.h
>> >+++ b/include/usb.h
>> >@@ -265,7 +265,26 @@ int usb_kbd_deregister(int force);
>> >  */
>> > int usb_init(void);
>> >
>> >-int usb_stop(void); /* stop the USB Controller */
>> >+/**
>> >+ * usb_stop() - stop the USB Controller and unbind all USB controllers/devices
>> >+ *
>> >+ * This unbinds all devices on the USB buses.
>> >+ *
>> >+ * Return: 0 if OK, -ve on error
>> >+ */
>> >+int usb_stop(void);
>> >+
>> >+/**
>> >+ * usb_pause() - stop the USB Controller DMA, etc.
>> >+ *
>> >+ * Note that this does not unbind bus devices, so using usb_init() after this
>> >+ * call is not permitted. This function is only useful just before booting, to
>> >+ * ensure that devices are dormant.
>> >+ *
>> >+ * Return: 0 if OK, -ve on error
>> >+ */
>> >+int usb_pause(void);
>> >+
>> > int usb_detect_change(void); /* detect if a USB device has been (un)plugged */
>> >
>> >

  reply	other threads:[~2023-11-12 23:30 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-12 20:02 [PATCH v4 00/12] Resolve issues with booting distros on x86 Simon Glass
2023-11-12 20:02 ` [PATCH v4 01/12] efi: Correct handling of frame buffer Simon Glass
2023-11-12 20:02 ` [PATCH v4 02/12] bootstd: Refactor mmc prep to allow a different scan Simon Glass
2023-11-12 20:02 ` [PATCH v4 03/12] bootstd: Add a return code to bootflow menu Simon Glass
2023-11-12 20:02 ` [PATCH v4 04/12] x86: coreboot: Add a boot script Simon Glass
2023-11-12 20:02 ` [PATCH v4 05/12] usb: Avoid unbinding devices in use by bootflows Simon Glass
2023-11-12 20:27   ` Heinrich Schuchardt
2023-11-12 21:20     ` Simon Glass
2023-11-12 23:30       ` Heinrich Schuchardt [this message]
2023-11-15 15:50         ` Simon Glass
2023-11-15 16:23           ` Heinrich Schuchardt
2023-11-16  1:29             ` Heinrich Schuchardt
2023-11-16  1:42               ` Simon Glass
2023-11-16  2:01                 ` Heinrich Schuchardt
2023-11-16  2:35                   ` Simon Glass
2023-11-15 15:12   ` Shantur Rathore
2023-11-12 20:02 ` [PATCH v4 06/12] expo: Correct background colour Simon Glass
2023-11-12 20:02 ` [PATCH v4 07/12] video: Correct setting of cursor position Simon Glass
2023-11-12 20:31   ` Anatolij Gustschin
2023-11-12 20:02 ` [PATCH v4 08/12] video: Drop unnecessary truetype operations from SPL Simon Glass
2023-11-12 20:34   ` Anatolij Gustschin
2023-11-12 20:02 ` [PATCH v4 09/12] x86: Enable SSE in 64-bit mode Simon Glass
2023-11-13 22:08   ` Bin Meng
2023-11-13 22:28     ` Simon Glass
2023-11-13 22:59       ` Tom Rini
2023-11-13 23:46         ` Bin Meng
2023-11-13 23:52           ` Tom Rini
2023-11-14  1:49             ` Bin Meng
2023-11-14 16:22               ` Tom Rini
2023-11-15  0:44                 ` Bin Meng
2023-11-15  0:48                   ` Simon Glass
2023-11-15 15:46                     ` Mark Kettenis
2023-11-19 15:27                       ` Simon Glass
2023-11-15  1:38                   ` Tom Rini
2023-11-15  1:40   ` Tom Rini
2023-11-12 20:02 ` [PATCH v4 10/12] x86: coreboot: Enable truetype fonts Simon Glass
2023-11-12 20:02 ` [PATCH v4 11/12] x86: qemu: Expand ROM size Simon Glass
2023-11-12 20:02 ` [PATCH v4 12/12] x86: qemu: Enable truetype fonts Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=43EF5E14-0AE3-456A-B9D4-67B8F4405555@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=eajames@linux.ibm.com \
    --cc=fabrice.gasnier@foss.st.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=marex@denx.de \
    --cc=mkorpershoek@baylibre.com \
    --cc=patrice.chotard@foss.st.com \
    --cc=patrick.delaunay@foss.st.com \
    --cc=sjg@chromium.org \
    --cc=souajih@baylibre.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.