From: Mark Kettenis <mark.kettenis@xs4all.nl>
To: Simon Glass <sjg@chromium.org>
Cc: xypron.glpk@gmx.de, ilias.apalodimas@linaro.org,
trini@konsulko.com, neil.armstrong@linaro.org, jonas@kwiboo.se,
christian@kohlschutter.com, j@jannau.net, u-boot@lists.denx.de
Subject: Re: [PATCH v2 3/4] efi_loader: Move device-removal later in exit-boot-services
Date: Mon, 07 Apr 2025 14:22:56 +0200 [thread overview]
Message-ID: <87tt70w47z.fsf@bloch.sibelius.xs4all.nl> (raw)
In-Reply-To: <CAFLszTh7BXFvG_q9tMiCmrLZzsQY6uEqQo62wXBBfsPkObO=3g@mail.gmail.com> (message from Simon Glass on Mon, 7 Apr 2025 22:49:05 +1200)
> From: Simon Glass <sjg@chromium.org>
> Date: Mon, 7 Apr 2025 22:49:05 +1200
Hi Simon,
Since I brought up the same objection as Heinrich...
> Hi Heinrich,
>
> On Mon, 7 Apr 2025 at 19:55, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> >
> > On 07.04.25 03:35, Simon Glass wrote:
> > > This removal should be the last thing done, so that U-Boot does no more
> > > memory allocations afterwards, thus avoiding potentially allocating
> > > memory which has been freed by a device that fails to de-activate its
> > > DMA.
> >
> > The EFI application that is calling ExitBootServices() has been reading
> > the EFI memory map with GetMemoryMap() before. This is checked by
> > comparing the MapKey parameter.
> >
> > Whatever allocations are done or not in ExitBootServices() is not
> > visible to the EFI application.
> >
> > DMA has to be stopped in all cases.
>
> Yes, DMA must be stopped.
>
> >
> > I don't understand the virtue of the proposed change.
>
> It is described in the next two paragraphs:
>
> >
> > Best regards
> >
> > Heinrich
> >
> > >
> > > Of course, devices should be marked with DM_FLAG_ACTIVE_DMA or
> > > DM_FLAG_OS_PREPARE but this change is good practice, in any case.
I disagree. Stopping DMA is early as possible is good practice.
> > > It also matches the code in announce_and_cleanup(), which we should at
> > > some point unify with EFI_LOADER
As far as I can see there is nothing that happens in between the old
location and your new location in efi_exit_boot_services() that
matches anything that is done in announce_and_cleanup().
> See above. Also, what do you think about unifying with
> announce_and_cleanup() ?
>
> Regards,
> Simon
>
>
> > >
> > > So move the code and add a comment.
> > >
> > > Note that the TCG2 log is updated after this call, but I cannot see any
> > > allocations there.
> > >
> > > Reported-by: Christian Kohlschütter <christian@kohlschutter.com>
> > > Link: https://lore.kernel.org/u-boot/C101B675-EEE6-44CB-8A44-83F72182FBD6@kohlschutter.com/
> > >
> > > Signed-off-by: Simon Glass <sjg@chromium.org>
> > > ---
> > >
> > > (no changes since v1)
> > >
> > > lib/efi_loader/efi_boottime.c | 21 +++++++++++++--------
> > > 1 file changed, 13 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
> > > index ffe43accd1e..e525662f82f 100644
> > > --- a/lib/efi_loader/efi_boottime.c
> > > +++ b/lib/efi_loader/efi_boottime.c
> > > @@ -2250,14 +2250,6 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,
> > > list_del(&evt->link);
> > > }
> > >
> > > - if (!efi_st_keep_devices) {
> > > - bootm_disable_interrupts();
> > > - if (IS_ENABLED(CONFIG_USB_DEVICE))
> > > - udc_disconnect();
> > > - board_quiesce_devices();
> > > - dm_remove_devices_active();
> > > - }
> > > -
> > > /* Patch out unsupported runtime function */
> > > efi_runtime_detach();
> > >
> > > @@ -2279,6 +2271,19 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,
> > > /* Give the payload some time to boot */
> > > efi_set_watchdog(0);
> > > schedule();
> > > +
> > > + /*
> > > + * this should be the last thing done, to avoid memory allocations
> > > + * between removing devices and the OS taking over
> > > + */
> > > + if (!efi_st_keep_devices) {
> > > + bootm_disable_interrupts();
> > > + if (IS_ENABLED(CONFIG_USB_DEVICE))
> > > + udc_disconnect();
> > > + board_quiesce_devices();
> > > + dm_remove_devices_active();
> > > + }
> > > +
> > > out:
> > > if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) {
> > > if (ret != EFI_SUCCESS)
> >
>
next prev parent reply other threads:[~2025-04-07 12:23 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-07 1:35 [PATCH v2 0/4] dm: net: Assorted patches related to networking and DMA Simon Glass
2025-04-07 1:35 ` [PATCH v2 1/4] designware: Use the remove() method with related drivers Simon Glass
2025-04-07 7:31 ` neil.armstrong
2025-04-07 1:35 ` [PATCH v2 2/4] net: designware: Mark drivers as having active DMA Simon Glass
2025-04-07 7:31 ` neil.armstrong
2025-04-07 1:35 ` [PATCH v2 3/4] efi_loader: Move device-removal later in exit-boot-services Simon Glass
2025-04-07 7:54 ` Heinrich Schuchardt
2025-04-07 10:49 ` Simon Glass
2025-04-07 12:22 ` Mark Kettenis [this message]
2025-04-07 1:35 ` [PATCH v2 4/4] dm: core: Rename dm_remove_devices_active() Simon Glass
2025-04-07 7:56 ` Heinrich Schuchardt
2025-04-07 10:49 ` Simon Glass
2025-04-07 13:30 ` Tom Rini
2025-04-07 15:23 ` 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=87tt70w47z.fsf@bloch.sibelius.xs4all.nl \
--to=mark.kettenis@xs4all.nl \
--cc=christian@kohlschutter.com \
--cc=ilias.apalodimas@linaro.org \
--cc=j@jannau.net \
--cc=jonas@kwiboo.se \
--cc=neil.armstrong@linaro.org \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.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.