All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Alex Graf <agraf@csgraf.de>,
	 Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	U-Boot Mailing List <u-boot@lists.denx.de>
Subject: Re: [RFC 00/22] efi_loader: more tightly integrate UEFI disks to device model
Date: Sun, 10 Oct 2021 08:14:00 -0600	[thread overview]
Message-ID: <CAPnjgZ0ZOX98aVBtEyKaYPjcc6qMVGTLfqpPbgVrKFgaKFnswQ@mail.gmail.com> (raw)
In-Reply-To: <20211001050228.55183-1-takahiro.akashi@linaro.org>

Hi Takahiro,

On Thu, 30 Sept 2021 at 23:02, AKASHI Takahiro
<takahiro.akashi@linaro.org> wrote:
>
> The purpose of this RPC is to reignite the discussion about how UEFI
> subystem would best be integrated into U-Boot device model.
> In the past, I poposed a couple of patch series, the latest one[1],
> while Heinrich revealed his idea[2], and the approach taken here is
> something between them, with a focus on block device handlings.
>
> # The code is a PoC and not well tested yet.
>
> Disks in UEFI world:
> ====================
> In general in UEFI world, accessing to any device is performed through
> a 'protocol' interface which are installed to (or associated with) the device's
> UEFI handle (or an opaque pointer to UEFI object data). Protocols are
> implemented by either the UEFI system itself or UEFI drivers.
>
> For block IO's, it is a device which has EFI_BLOCK_IO_PROTOCOL (efi_disk
> hereafter). Currently, every efi_disk may have one of two origins:
> a.U-Boot's block devices or related partitions
>   (lib/efi_loader/efi_disk.c)
> b.UEFI objects which are implemented as a block device by UEFI drivers.
>   (lib/efi_driver/efi_block_device.c)
>
> All the efi_diskss as (a) will be enumelated and created only once at UEFI
> subsystem initialization (efi_disk_register()), which is triggered by
> first executing one of UEFI-related U-Boot commands, like "bootefi",
> "setenv -e" or "efidebug".
> EFI_BLOCK_IO_PROTOCOL is implemented by UEFI system using blk_desc(->ops)
> in the corresponding udevice(UCLASS_BLK).
>
> On the other hand, efi_disk as (b) will be created each time UEFI boot
> services' connect_controller() is executed in UEFI app which, as a (device)
> controller, gives the method to access the device's data,
> ie. EFI_BLOCK_IO_PROTOCOL.
>
> >>> more details >>>
> Internally, connect_controller() search for UEFI driver that can support
> this controller/protocol, 'efi_block' driver(UCLASS_EFI) in this case,
> then calls the driver's 'bind' interface, which eventually installs
> the controller's EFI_BLOCK_IO_PROTOCOL to efi_disk object.
> 'efi_block' driver also create a corresponding udevice(UCLASS_BLK) for
>   * creating additional partitions efi_disk's, and
>   * supporting a file system (EFI_SIMPLE_FILE_SYSTEM_PROTOCOL) on it.
> <<< <<<
>
> Issues:
> =======
> 1. While an efi_disk represents a device equally for either a whole disk
>    or a partition in UEFI world, the device model treats only a whole
>    disk as a real block device or udevice(UCLASS_BLK).
>
> 2. efi_disk holds and makes use of "blk_desc" data even though blk_desc
>    in plat_data is supposed to be private and not to be accessed outside
>    the device model.
>    # This issue, though, exists for all the implmenetation of U-Boot
>    # file systems as well.

Yes, this was a migration convenience and we should be able to unpick it now.

However we still have SPL_BLK so need to consider whether we can drop that.

>
> For efi_disk(a),
> 3. A block device can be enumelated dynamically by 'scanning' a device bus
>    in U-Boot, but UEFI subsystem is not able to update efi_disks accordingly.
>    For examples,
>     => scsi rescan; efidebug devices
>     => usb start; efidebug devices ... (A)
>    (A) doesn't show any usb devices detected.
>
>     => scsi rescan; efidebug boot add -b 0 TEST scsi 0:1 ...
>     => scsi rescan ... (B)
>     => bootefi bootmgr ... (C)
>    (C) may de-reference a bogus blk_desc pointer which has been freed by (B).
>    (Please note that "scsi rescan" removes all udevices/blk_desc and then
>     re-create them even if nothing is changed on a bus.)

This is something your series will help with.

>
> For efi_disk(b),
> 4. A controller (handle), combined with efi_block driver, has no
>    corresponding udevice as a parent of efi_disks in DM tree, unlike, say,
>    a scsi controller, even though it provides methods for block io perations.

Can we just create a udevice?

> 5. There is no way supported to remove efi_disk's even after
>    disconnect_controller() is called.
>

Do we want to remove disks? I don't really understand the context, but
if EFI wants to forget about a disk, that should not affect the rest
of U-Boot.

>
> My approach in this RFC:
> ========================
> Due to functional differences in semantics, it would be difficult
> to identify "udevice" structure as a handle in UEFI world. Instead, we will
> have to somehow maintain a relationship between a udevice and a handle.
>
> 1-1. add a dedicated uclass, UCLASS_PARTITION, for partitions
>    Currently, the uclass for paritions is not a UCLASS_BLK.
>    It can be possible to define partitions as UCLASS_BLK
>    (with IF_TYPE_PARTION?), but
>    I'm afraid that it may introduce some chaos since udevice(UCLASS_BLK)
>    is tightly coupled with 'struct blk_desc' data which is still used
>    as a "structure to a whole disk" in a lot of interfaces.
>    (I hope that you understand what it means.)
>
>    In DM tree, a UCLASS_PARTITON instance has a UCLASS_BLK parent:
>    For instance,
>        UCLASS_SCSI  --- UCLASS_BLK       --- UCLASS_PARTITION
>                          (IF_TYPE_SCSI)        |
>                           +- struct blk_desc   +- struct disk_part
>                           +- scsi_blk_ops      +- blk_part_ops

Seems right to me. But I think a partition should also have a BLK
child, so that only block devices can be read/written. In fact,
perhaps a partition should be a child of the media device (e.g. MMC),
not of the BLK device? That might make more sense.

>
> 1-2. create partition udevices in the context of device_probe()
>    part_init() is already called in blk_post_probe(). See the commit
>    d0851c893706 ("blk: Call part_init() in the post_probe() method").
>    Why not enumelate partitions as well in there.

Sounds reasonable.

>
> 2. add new block access interfaces, which takes "udevice" as a target device,
>    in U-Boot and use those functions to implement efi_disk operations
>    (i.e. EFI_BLOCK_IO_PROTOCOL).

Nice.

>
> 3-1. maintain a bi-directional link by adding
>    - a UEFI handle pointer in "struct udevice"
>    - a udevice pointer in UEFI handle (in fact, in "struct efi_disk_obj")

We should generalise the API here, but otherwise seems right. See my
comment on the patch.

>
> 3-2. use device model's post_probe/pre_remove hook to synchronize the lifetime
>    of efi_disk objects in UEFI world with the device model.

We should add an event mechanism to generalise this a bit. See my
comment on the patch.

>
> 4. I have no answer to issue(4) and (5) yet.

See above.

>
>
> Patchs:
> =======
> For easy understandings, patches may be categorized into seperate groups
> of changes.
>
> Patch#1-#9: DM: create udevices for partitions
> Patch#11,#12: UEFI: use udevice interfaces
> Patch#13-#16: UEFI: sync up with the device model for adding
> Patch#17-#19: UEFI: sync up with the device model for removing
>   For removal case, we may need more consideration since removing handles
>   unconditionally may end up breaking integrity of handles
>   (some may still be held and referenced to by a UEFI app).
> Patch#20-#22: UEFI: align efi_driver with changes by the integration
>

This looks great to me and is the first real step I have seen to
actually solving the problem of all this duplication.

I think we need a few more DM APIs as I suggest in a few of the
patches. I am happy to help with these if you like.

I wonder if it is possible to get some version of at least part of
this code applied in this merge window? It helps to set things on a
much better direction.

I also worry that continuing to develop the EFI impl while it is such
a sorry state is adding to the difficulty of fixing it up.

Regards,
Simon


>
> [1] https://lists.denx.de/pipermail/u-boot/2019-February/357923.html
> [2] https://lists.denx.de/pipermail/u-boot/2021-June/452297.html
>
> AKASHI Takahiro (22):
>   scsi: call device_probe() after scanning
>   usb: storage: call device_probe() after scanning
>   mmc: call device_probe() after scanning
>   nvme: call device_probe() after scanning
>   sata: call device_probe() after scanning
>   block: ide: call device_probe() after scanning
>   dm: blk: add UCLASS_PARTITION
>   dm: blk: add a device-probe hook for scanning disk partitions
>   dm: blk: add read/write interfaces with udevice
>   efi_loader: disk: use udevice instead of blk_desc
>   dm: add a hidden link to efi object
>   efi_loader: remove !CONFIG_BLK code from efi_disk
>   efi_loader: disk: a helper function to create efi_disk objects from
>     udevice
>   dm: blk: call efi's device-probe hook
>   efi_loader: cleanup after efi_disk-dm integration
>   efi_loader: add efi_remove_handle()
>   efi_loader: efi_disk: a helper function to delete efi_disk objects
>   dm: blk: call efi's device-removal hook
>   efi_driver: align with efi_disk-dm integration
>   efi_driver: cleanup after efi_disk-dm integration
>   efi_selftest: block device: adjust dp for a test disk
>   (TEST) let dm-tree unchanged after block_io testing is done
>
>  common/usb_storage.c                         |   6 +
>  drivers/ata/dwc_ahsata.c                     |  10 +
>  drivers/ata/fsl_sata.c                       |  11 +
>  drivers/ata/sata_mv.c                        |   9 +
>  drivers/ata/sata_sil.c                       |  12 +
>  drivers/block/blk-uclass.c                   | 249 ++++++++++++++++
>  drivers/block/ide.c                          |   6 +
>  drivers/mmc/mmc-uclass.c                     |   7 +
>  drivers/nvme/nvme.c                          |   6 +
>  drivers/scsi/scsi.c                          |  10 +
>  include/blk.h                                |  15 +
>  include/dm/device.h                          |   4 +
>  include/dm/uclass-id.h                       |   1 +
>  include/efi_loader.h                         |   8 +-
>  lib/efi_driver/efi_block_device.c            |  30 +-
>  lib/efi_loader/efi_boottime.c                |   8 +
>  lib/efi_loader/efi_device_path.c             |  29 ++
>  lib/efi_loader/efi_disk.c                    | 286 ++++++++++---------
>  lib/efi_loader/efi_setup.c                   |   5 -
>  lib/efi_selftest/efi_selftest_block_device.c |  28 +-
>  20 files changed, 566 insertions(+), 174 deletions(-)
>
> --
> 2.33.0
>

  parent reply	other threads:[~2021-10-10 14:14 UTC|newest]

Thread overview: 157+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-01  5:01 [RFC 00/22] efi_loader: more tightly integrate UEFI disks to device model AKASHI Takahiro
2021-10-01  5:01 ` [RFC 01/22] part: call part_init() in blk_get_device_by_str() only for MMC AKASHI Takahiro
2021-10-01  6:41   ` Heinrich Schuchardt
2021-10-01  7:56     ` Heinrich Schuchardt
2021-10-04  3:13     ` AKASHI Takahiro
2021-10-01 11:48   ` Peter Robinson
2021-10-04  3:26     ` AKASHI Takahiro
2021-10-11 10:07     ` Heinrich Schuchardt
2021-10-11 14:32       ` Simon Glass
2021-10-11 15:08         ` Heinrich Schuchardt
2021-10-11 16:14           ` Simon Glass
2021-10-12  3:26             ` AKASHI Takahiro
2021-10-12 13:30               ` Heinrich Schuchardt
2021-10-13  1:50                 ` AKASHI Takahiro
2021-10-12 20:31               ` Simon Glass
2021-10-10 14:14   ` Simon Glass
2021-10-01  5:01 ` [RFC 01/22] scsi: call device_probe() after scanning AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-01  5:01 ` [RFC 02/22] " AKASHI Takahiro
2021-10-01  5:01 ` [RFC 02/22] usb: storage: " AKASHI Takahiro
2021-10-01  5:01 ` [RFC 03/22] mmc: " AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-11  1:10     ` AKASHI Takahiro
2021-10-01  5:01 ` [RFC 03/22] usb: storage: " AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-01  5:01 ` [RFC 04/22] mmc: " AKASHI Takahiro
2021-10-01  5:01 ` [RFC 04/22] nvme: " AKASHI Takahiro
2021-10-01  5:01 ` [RFC 05/22] " AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-01  5:01 ` [RFC 05/22] sata: " AKASHI Takahiro
2021-10-01  5:01 ` [RFC 06/22] block: ide: " AKASHI Takahiro
2021-10-01  5:01 ` [RFC 06/22] sata: " AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-11  1:11     ` AKASHI Takahiro
2021-10-01  5:01 ` [RFC 07/22] block: ide: " AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-11  1:43     ` AKASHI Takahiro
2021-10-11 14:54       ` Simon Glass
2021-10-12  5:53         ` Ilias Apalodimas
2021-10-13  0:35           ` AKASHI Takahiro
2021-10-01  5:01 ` [RFC 07/22] dm: blk: add UCLASS_PARTITION AKASHI Takahiro
2021-10-01  9:30   ` Heinrich Schuchardt
2021-10-04  3:27     ` AKASHI Takahiro
2021-10-08  0:51       ` AKASHI Takahiro
2021-10-08  8:23         ` Heinrich Schuchardt
2021-10-11  2:29           ` AKASHI Takahiro
2021-10-11 14:54             ` Simon Glass
2021-10-11 15:02               ` Heinrich Schuchardt
2021-10-11 16:14                 ` Simon Glass
2021-10-11 16:48                   ` Heinrich Schuchardt
2021-10-11 17:41                     ` Simon Glass
2021-10-12  5:12                       ` AKASHI Takahiro
2021-10-12  6:42                         ` Heinrich Schuchardt
2021-10-12 15:14                   ` Tom Rini
2021-10-13  1:32                     ` AKASHI Takahiro
2021-10-13 18:05                       ` Simon Glass
2021-10-14  8:03                         ` AKASHI Takahiro
2021-10-14 20:55                           ` Simon Glass
2021-10-28  8:52                             ` AKASHI Takahiro
2021-10-28 10:42                               ` Heinrich Schuchardt
2021-10-29  1:45                                 ` Simon Glass
2021-10-29  4:57                                   ` Heinrich Schuchardt
2021-10-29  6:15                                     ` AKASHI Takahiro
2021-10-29 19:21                                       ` Heinrich Schuchardt
2021-10-29 21:17                                         ` Simon Glass
2021-10-30  5:45                                           ` Heinrich Schuchardt
2021-11-01  0:36                                             ` AKASHI Takahiro
2021-11-01  1:15                                               ` Simon Glass
2021-11-01  1:51                                                 ` AKASHI Takahiro
2021-11-01  2:14                                                   ` Simon Glass
2021-11-02  1:42                                                     ` AKASHI Takahiro
2021-11-02  7:38                                                     ` Heinrich Schuchardt
2021-11-05  2:02                                                       ` Simon Glass
2021-11-05  2:49                                                         ` AKASHI Takahiro
2021-11-05 16:12                                                           ` Simon Glass
2021-11-08  4:46                                                             ` AKASHI Takahiro
2021-11-08 18:44                                                               ` Ilias Apalodimas
2021-11-09  0:09                                                                 ` Simon Glass
2021-11-13 18:14                                                                   ` Simon Glass
2021-11-13 18:37                                                                     ` Heinrich Schuchardt
2021-11-13 21:32                                                                       ` Simon Glass
2021-11-15  1:43                                                                         ` AKASHI Takahiro
2021-11-15 19:05                                                                           ` Simon Glass
2021-11-15 19:16                                                                             ` Heinrich Schuchardt
2021-11-15 23:51                                                                               ` AKASHI Takahiro
2021-11-16  0:02                                                                                 ` Heinrich Schuchardt
2021-11-16  3:01                                                                                   ` AKASHI Takahiro
2021-12-03  7:16                                                                                     ` AKASHI Takahiro
2021-12-03 16:06                                                                                       ` Heinrich Schuchardt
2021-12-06  4:18                                                                                         ` AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-12  3:53     ` AKASHI Takahiro
2021-10-01  5:01 ` [RFC 08/22] " AKASHI Takahiro
2021-10-01  9:32   ` Heinrich Schuchardt
2021-10-01  5:02 ` [RFC 08/22] dm: blk: add a device-probe hook for scanning disk partitions AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-01  5:02 ` [RFC 09/22] " AKASHI Takahiro
2021-10-01  5:02 ` [RFC 09/22] dm: blk: add read/write interfaces with udevice AKASHI Takahiro
2021-10-01  5:02 ` [RFC 10/22] " AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-01  5:02 ` [RFC 10/22] efi_loader: disk: use udevice instead of blk_desc AKASHI Takahiro
2021-10-01  5:02 ` [RFC 11/22] dm: add a hidden link to efi object AKASHI Takahiro
2021-10-01  5:02 ` [RFC 11/22] efi_loader: disk: use udevice instead of blk_desc AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-01  5:02 ` [RFC 12/22] dm: add a hidden link to efi object AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-11  6:43     ` AKASHI Takahiro
2021-10-11 14:54       ` Simon Glass
2021-10-11 15:26         ` Heinrich Schuchardt
2021-10-11 16:09           ` Simon Glass
2021-10-12  2:09             ` AKASHI Takahiro
2021-10-12 20:31               ` Simon Glass
2021-10-01  5:02 ` [RFC 12/22] efi_loader: remove !CONFIG_BLK code from efi_disk AKASHI Takahiro
2021-10-01  5:02 ` [RFC 13/22] efi_loader: disk: a helper function to create efi_disk objects from udevice AKASHI Takahiro
2021-10-01  5:02 ` [RFC 13/22] efi_loader: remove !CONFIG_BLK code from efi_disk AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-01  5:02 ` [RFC 14/22] dm: blk: call efi's device-probe hook AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-11  3:15     ` AKASHI Takahiro
2021-10-11 14:54       ` Simon Glass
2021-11-01  3:03         ` Simon Glass
2021-10-01  5:02 ` [RFC 14/22] efi_loader: disk: a helper function to create efi_disk objects from udevice AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-11  6:52     ` AKASHI Takahiro
2021-10-11 14:54       ` Simon Glass
2021-10-12  1:09         ` AKASHI Takahiro
2021-10-12 14:08           ` Simon Glass
2021-10-01  5:02 ` [RFC 15/22] dm: blk: call efi's device-probe hook AKASHI Takahiro
2021-10-01  5:02 ` [RFC 15/22] efi_loader: cleanup after efi_disk-dm integration AKASHI Takahiro
2021-10-01  5:02 ` [RFC 16/22] efi_loader: add efi_remove_handle() AKASHI Takahiro
2021-10-01  5:02 ` [RFC 16/22] efi_loader: cleanup after efi_disk-dm integration AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-01  5:02 ` [RFC 17/22] efi_loader: add efi_remove_handle() AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-01  5:02 ` [RFC 17/22] efi_loader: efi_disk: a helper function to delete efi_disk objects AKASHI Takahiro
2021-10-01  5:02 ` [RFC 18/22] dm: blk: call efi's device-removal hook AKASHI Takahiro
2021-10-01  5:02 ` [RFC 18/22] efi_loader: efi_disk: a helper function to delete efi_disk objects AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-01  5:02 ` [RFC 19/22] dm: blk: call efi's device-removal hook AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-01  5:02 ` [RFC 19/22] efi_driver: align with efi_disk-dm integration AKASHI Takahiro
2021-10-01  5:02 ` [RFC 20/22] " AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-11  7:41     ` AKASHI Takahiro
2021-10-01  5:02 ` [RFC 20/22] efi_driver: cleanup after " AKASHI Takahiro
2021-10-01  5:02 ` [RFC 21/22] " AKASHI Takahiro
2021-10-10 14:14   ` Simon Glass
2021-10-01  5:02 ` [RFC 21/22] efi_selftest: block device: adjust dp for a test disk AKASHI Takahiro
2021-10-01  5:02 ` [RFC 22/22] (TEST) let dm-tree unchanged after block_io testing is done AKASHI Takahiro
2021-10-01  5:02 ` [RFC 22/22] efi_selftest: block device: adjust dp for a test disk AKASHI Takahiro
2021-10-02 14:17   ` Heinrich Schuchardt
2021-10-10 14:14 ` Simon Glass [this message]
2021-10-12 15:00   ` [RFC 00/22] efi_loader: more tightly integrate UEFI disks to device model Tom Rini
2021-10-12 20:31     ` Simon Glass
2021-10-12 21:13       ` Tom Rini
2021-10-12 23:37         ` Simon Glass
2021-10-12 23:40           ` Tom Rini

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=CAPnjgZ0ZOX98aVBtEyKaYPjcc6qMVGTLfqpPbgVrKFgaKFnswQ@mail.gmail.com \
    --to=sjg@chromium.org \
    --cc=agraf@csgraf.de \
    --cc=ilias.apalodimas@linaro.org \
    --cc=takahiro.akashi@linaro.org \
    --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.