From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF96CC433EF for ; Thu, 14 Oct 2021 08:03:32 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1D7EC61040 for ; Thu, 14 Oct 2021 08:03:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1D7EC61040 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D9356835CE; Thu, 14 Oct 2021 10:03:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="DJLvYY4P"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 15E7583655; Thu, 14 Oct 2021 10:03:28 +0200 (CEST) Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3CA73835C3 for ; Thu, 14 Oct 2021 10:03:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pj1-x102d.google.com with SMTP id k23so4190780pji.0 for ; Thu, 14 Oct 2021 01:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=9YTMm/kMsZAmM1NaewOQs4l4jdSQA/nJ8RAMAC8FoiQ=; b=DJLvYY4PQeCd36CJdEDlP/swebrYMFSnKZyoU+0Or7x3w7n+R0B9APQvsCysrQHOzo GA1rcXCXnc+sTwltfNPT9MEwoueMb5P8PboM5ReoM/E0KU1+sgNe4BGkvOLiR8OjLfKj Ka5u/glU/hetyDAaQH4BwCr11/na6E9ZKoWdGExH1efI1Uas+4pzQWYCRb6/zL611xHx XHVDCyd6HuksrJd8XCEEcwk77ubBIJTx91OnkR0jeRxfJRETWyyoM7pTts1ja2+kJB2S GaimPfDyY8Fh/fuccl9mRQcRAV7hzA7wEzV1dtmbV1L/WFgCGQQV+eKkGE+8XchsnT9n X4Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=9YTMm/kMsZAmM1NaewOQs4l4jdSQA/nJ8RAMAC8FoiQ=; b=QlUmG2fIGDkprk1j2hr6+PbTErJILCuiYTQzjqOrA3K5q75Ij6aD8d0XGdjmfvDr8q PVgA6baFCiKso5w9p49K0qEHP6dbvAgLON5bF5vSI4VC9BV2zXBAwkexlhsNyR+Rx8LA 9NOEVkmezbOLGXevSYzuCA7KxW6UGW+KuGwbS6y+Mpgg3qkkPqGx52ysTx7lc4SID3IM ggtMSFoBP9XG+brHBGsMHOxUEWMtOxYcLcMhVMAubbR52j2Ndlr2wnel8DSDhZSv3gES FsCCkY4rq0hpyR4l4XhjX8aKvrh2/K9h02W9V/WS12RHHzASZdmGKmaIKESyQkSNHSWM /13g== X-Gm-Message-State: AOAM533OGQErbDMpjJQoykuAk/A873gyFPiloMF+j18go/TQhb7VyjcM +MGTod/r15l3NBFCCDw+1dJnlg== X-Google-Smtp-Source: ABdhPJwG0wwv8S6ljRTJjRP7D5lyTkCYtrTPcP0TPqJE6XbOmg3dvXZpFX2DAA5LSNUkhk/Bsm3XNg== X-Received: by 2002:a17:90b:3144:: with SMTP id ip4mr4713474pjb.23.1634198600799; Thu, 14 Oct 2021 01:03:20 -0700 (PDT) Received: from laputa ([2400:4050:c3e1:100:b150:b763:4751:6e8f]) by smtp.gmail.com with ESMTPSA id l10sm1643896pgn.22.2021.10.14.01.03.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Oct 2021 01:03:20 -0700 (PDT) Date: Thu, 14 Oct 2021 17:03:16 +0900 From: AKASHI Takahiro To: Simon Glass Cc: Tom Rini , Heinrich Schuchardt , U-Boot Mailing List , Alex Graf , Ilias Apalodimas Subject: Re: [RFC 07/22] dm: blk: add UCLASS_PARTITION Message-ID: <20211014080316.GA22860@laputa> Mail-Followup-To: AKASHI Takahiro , Simon Glass , Tom Rini , Heinrich Schuchardt , U-Boot Mailing List , Alex Graf , Ilias Apalodimas References: <20211004032759.GC39720@laputa> <20211008005156.GA34717@laputa> <3455705e-1b04-cf01-3cff-b89f673c5e05@gmx.de> <20211011022925.GE44356@laputa> <64774cd7-2119-347a-4d2b-3715fa2a8029@gmx.de> <20211012151417.GZ7964@bill-the-cat> <20211013013217.GC43695@laputa> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Simon, On Wed, Oct 13, 2021 at 12:05:58PM -0600, Simon Glass wrote: > Hi Takahiro, > > On Tue, 12 Oct 2021 at 19:32, AKASHI Takahiro > wrote: > > > > On Tue, Oct 12, 2021 at 11:14:17AM -0400, Tom Rini wrote: > > > On Mon, Oct 11, 2021 at 10:14:00AM -0600, Simon Glass wrote: > > > > Hi Heinrich, > > > > > > > > On Mon, 11 Oct 2021 at 09:02, Heinrich Schuchardt wrote: > > > > > > > > > > > > > > > > > > > > On 10/11/21 16:54, Simon Glass wrote: > > > > > > Hi Takahiro, > > > > > > > > > > > > On Sun, 10 Oct 2021 at 20:29, AKASHI Takahiro > > > > > > wrote: > > > > > >> > > > > > >> Heinrich, > > > > > >> > > > > > >> On Fri, Oct 08, 2021 at 10:23:52AM +0200, Heinrich Schuchardt wrote: > > > > > >>> > > > > > >>> > > > > > >>> On 10/8/21 02:51, AKASHI Takahiro wrote: > > > > > >>>> On Mon, Oct 04, 2021 at 12:27:59PM +0900, AKASHI Takahiro wrote: > > > > > >>>>> On Fri, Oct 01, 2021 at 11:30:37AM +0200, Heinrich Schuchardt wrote: > > > > > >>>>>> > > > > > >>>>>> > > > > > >>>>>> On 10/1/21 07:01, AKASHI Takahiro wrote: > > > > > >>>>>>> UCLASS_PARTITION device will be created as a child node of > > > > > >>>>>>> UCLASS_BLK device. > > > > > >>>>>>> > > > > > >>>>>>> Signed-off-by: AKASHI Takahiro > > > > > >>>>>>> --- > > > > > >>>>>>> drivers/block/blk-uclass.c | 111 +++++++++++++++++++++++++++++++++++++ > > > > > >>>>>>> include/blk.h | 9 +++ > > > > > >>>>>>> include/dm/uclass-id.h | 1 + > > > > > >>>>>>> 3 files changed, 121 insertions(+) > > > > > >>>>>>> > > > > > >>>>>>> diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c > > > > > >>>>>>> index 83682dcc181a..dd7f3c0fe31e 100644 > > > > > >>>>>>> --- a/drivers/block/blk-uclass.c > > > > > >>>>>>> +++ b/drivers/block/blk-uclass.c > > > > > >>>>>>> @@ -12,6 +12,7 @@ > > > > > >>>>>>> #include > > > > > >>>>>>> #include > > > > > >>>>>>> #include > > > > > >>>>>>> +#include > > > > > >>>>>>> #include > > > > > >>>>>>> #include > > > > > >>>>>>> #include > > > > > >>>>>>> @@ -695,6 +696,44 @@ int blk_unbind_all(int if_type) > > > > > >>>>>>> return 0; > > > > > >>>>>>> } > > > > > >>>>>>> > > > > > >>>>>>> +int blk_create_partitions(struct udevice *parent) > > > > > >>>>>>> +{ > > > > > >>>>>>> + int part, count; > > > > > >>>>>>> + struct blk_desc *desc = dev_get_uclass_plat(parent); > > > > > >>>>>>> + struct disk_partition info; > > > > > >>>>>>> + struct disk_part *part_data; > > > > > >>>>>>> + char devname[32]; > > > > > >>>>>>> + struct udevice *dev; > > > > > >>>>>>> + int ret; > > > > > >>>>>>> + > > > > > >>>>>>> + if (!CONFIG_IS_ENABLED(PARTITIONS) || > > > > > >>>>>>> + !CONFIG_IS_ENABLED(HAVE_BLOCK_DEVICE)) > > > > > >>>>>>> + return 0; > > > > > >>>>>>> + > > > > > >>>>>>> + /* Add devices for each partition */ > > > > > >>>>>>> + for (count = 0, part = 1; part <= MAX_SEARCH_PARTITIONS; part++) { > > > > > >>>>>>> + if (part_get_info(desc, part, &info)) > > > > > >>>>>>> + continue; > > > > > >>>>>>> + snprintf(devname, sizeof(devname), "%s:%d", parent->name, > > > > > >>>>>>> + part); > > > > > >>>>>>> + > > > > > >>>>>>> + ret = device_bind_driver(parent, "blk_partition", > > > > > >>>>>>> + strdup(devname), &dev); > > > > > >>>>>>> + if (ret) > > > > > >>>>>>> + return ret; > > > > > >>>>>>> + > > > > > >>>>>>> + part_data = dev_get_uclass_plat(dev); > > > > > >>>>>>> + part_data->partnum = part; > > > > > >>>>>>> + part_data->gpt_part_info = info; > > > > > >>>>>>> + count++; > > > > > >>>>>>> + > > > > > >>>>>>> + device_probe(dev); > > > > > >>>>>>> + } > > > > > >>>>>>> + debug("%s: %d partitions found in %s\n", __func__, count, parent->name); > > > > > >>>>>>> + > > > > > >>>>>>> + return 0; > > > > > >>>>>>> +} > > > > > >>>>>>> + > > > > > >>>>>>> static int blk_post_probe(struct udevice *dev) > > > > > >>>>>>> { > > > > > >>>>>>> if (IS_ENABLED(CONFIG_PARTITIONS) && > > > > > >>>>>>> @@ -713,3 +752,75 @@ UCLASS_DRIVER(blk) = { > > > > > >>>>>>> .post_probe = blk_post_probe, > > > > > >>>>>>> .per_device_plat_auto = sizeof(struct blk_desc), > > > > > >>>>>>> }; > > > > > >>>>>>> + > > > > > >>>>>>> +static ulong blk_part_read(struct udevice *dev, lbaint_t start, > > > > > >>>>>>> + lbaint_t blkcnt, void *buffer) > > > > > >>>>>>> +{ > > > > > >>>>>>> + struct udevice *parent; > > > > > >>>>>>> + struct disk_part *part; > > > > > >>>>>>> + const struct blk_ops *ops; > > > > > >>>>>>> + > > > > > >>>>>>> + parent = dev_get_parent(dev); > > > > > >>>>>> > > > > > >>>>>> What device type will the parent have if it is a eMMC hardware partition? > > > > > >>>>>> > > > > > >>>>>>> + ops = blk_get_ops(parent); > > > > > >>>>>>> + if (!ops->read) > > > > > >>>>>>> + return -ENOSYS; > > > > > >>>>>>> + > > > > > >>>>>>> + part = dev_get_uclass_plat(dev); > > > > > >>>>>> > > > > > >>>>>> You should check that we do not access the block device past the > > > > > >>>>>> partition end: > > > > > >>>>> > > > > > >>>>> Yes, I will fix all of checks. > > > > > >>>>> > > > > > >>>>>> struct blk_desc *desc = dev_get_uclass_plat(parent); > > > > > >>>>>> if ((start + blkcnt) * desc->blksz < part->gpt_part_info.blksz) > > > > > >>>>>> return -EFAULT. > > > > > >>>>>> > > > > > >>>>>>> + start += part->gpt_part_info.start; > > > > > >>>> > > > > > >>>> A better solution is: > > > > > >>>> if (start >= part->gpt_part_info.size) > > > > > >>>> return 0; > > > > > >>>> > > > > > >>>> if ((start + blkcnt) > part->gpt_part_info.size) > > > > > >>>> blkcnt = part->gpt_part_info.size - start; > > > > > >>>> start += part->gpt_part_info.start; > > > > > >>>> instead of returning -EFAULT. > > > > > >>>> (note that start and blkcnt are in "block".) > > > > > >>> > > > > > >>> What is your motivation to support an illegal access? > > > > > >>> > > > > > >>> We will implement the EFI_BLOCK_IO_PROTOCOL based on this function. The > > > > > >>> ReadBlocks() and WriteBlocks() services must return > > > > > >>> EFI_INVALID_PARAMETER if the read request contains LBAs that are not > > > > > >>> valid. > > > > > >> > > > > > >> I interpreted that 'LBA' was the third parameter to ReadBlocks API, > > > > > >> and that if the starting block is out of partition region, we should > > > > > >> return an error (and if not, we still want to trim IO request to fit > > > > > >> into partition size as other OS's API like linux does). > > > > > >> Do you think it's incorrect? > > > > > > > > > > > > [..] > > > > > > > > > > > > Related to this patch I think that the partition type should be really > > > > > > be a child of the media device: > > > > > > > > > > > > - MMC > > > > > > |- BLK > > > > > > |- PARTITION > > > > > > |- BLK > > > > > > |- PARTITION > > > > > > |- BLK > > > > > > |- PARTITION > > > > > > |- BLK > > > > > > > > > > > > It seems more natural to me that putting the partitions under the > > > > > > top-level BLK device, so that BLK remains a 'terminal' device. > > > > > > > > > > > > The partition uclass is different from BLK, of course. It could > > > > > > contain information about the partition such as its partition number > > > > > > and UUID. > > > > > > > > > > Do you mean hardware partition here? Otherwise I would not know what BLK > > > > > should model. > > > > > > > > I mean that (I think) we should not use BLK to model partitions. A BLK > > > > should just be a block device. > > > > > > > > I don't see any difference between a partition and a hardware > > > > partition. We presumably end up with a hierarchy though. Do we need a > > > > HWPARTITION uclass so we can handle the hardware partitions > > > > differently? > > > > > > Note that for eMMC devices, hardware partitions are different from > > > partition-table partitions. If you boot a system with an eMMC device up > > > in Linux you typically get mmcblkN, mmcblkNboot0, mmcblkNboot1 and > > > mmcblkNrpmb, each of which are hardware partitions. It gets tricky in > > > U-Boot in that you can access each of these with 'mmc dev N M' where M > > > defaults to 0 and is the user partition (mmcblkN), 1/2 are boot0/boot1 > > > and 3 is the rpmb area. The 'mmc' command also allows, when possible > > > and implemented, configuring these partitions, again to the extent > > > allowed, documented and implemented. > > > > Thank you. That is exactly what I tried to mention in my reply > > at "part: call part_init() in blk_get_device_by_str() only for MMC" > > OK so it sounds like we agree that hwpartition and partition are > different things. Yes. Please note, IIUC, that * MMC hw partitions on a device are mapped to one udevice, differentiating them by blk_desc->hwpart. * Each NVME namespace on a device is mapped to a different udevice with a different blk_desc->devnum (and nvme_dev->ns_id). * Each UFS partition (or which is, I suppose, equivalent to scsi LUN) on a device is mapped to a different udevice with a different blk_desc->devnum (and blk_desc->lun). So even though those type of devices have some kind of hardware partitions, they are modelled differently in U-Boot. (Obviously, I might be wrong here as I'm not quite familiar yet.) > > > > ---8<--- > > # On the other hand, we have to explicitly switch "hw partitions" > > # with blk_select_hwpart_devnum() on MMC devices even though we use > > # the *same* udevice(blk_desc). > > --->8--- > > > > The problem with the current U-Boot driver model is that all of "mmcblkN, > > mmcblkNboot0, mmcblkNboot1 and mmcblkNrpmb" will be linked to the same > > udevice. We have to do "mmc dev N M" or call blk_select_hwpart[_devnum]() > > to distinguish them. > > Here's our chance to rethink this. What should the device hierarchy be > for an MMC device? I made a proposal further up the thread. Well, On Mon, Oct 11, 2021 at 11:41:02AM -0600, Simon Glass wrote: > On Mon, 11 Oct 2021 at 10:53, Heinrich Schuchardt wrote: > > >>> [..] > > >>> Related to this patch I think that the partition type should be really > > >>> be a child of the media device: > > >>> > > >>> - MMC > > >>> |- BLK > > >>> |- PARTITION > > >>> |- BLK > > >>> |- PARTITION > > >>> |- BLK > > >>> |- PARTITION > > >>> |- BLK > > >>> > > >>> It seems more natural to me that putting the partitions under the > > >>> top-level BLK device, so that BLK remains a 'terminal' device. > > >>> > > >>> The partition uclass is different from BLK, of course. It could > > >>> contain information about the partition such as its partition number > > >>> and UUID. Yeah, but there is always 1-to-1 mapping between a partition and a block (for a partition), so I still wonder whether it makes sense to model partitions in the way above. Alternatively, the following hierarchy also makes some sense. (This is not what I have in my RFC though.) - MMC |- BLK (whole disk with part=0) |- BLK (partition 1) |- BLK (partition 2) |- BLK (partition 3) or - MMC |- DISK (whole disk) ||- BLK (partition 0) ||- BLK (partition 1) ||- BLK (partition 2) ||- BLK (partition 3) Here MMC: provides read/write operations (via blk_ops) DISK: holds a geometry of a whole disk and other info BLK: partition info (+ blk_ops + geo) (part=0 means a while disk) > > >> Do you mean hardware partition here? Otherwise I would not know what BLK > > >> should model. > > > > > > I mean that (I think) we should not use BLK to model partitions. A BLK > > > should just be a block device. > > > > That is fine. But this implies that a software partition is the child of > > a block partition and not the other way round. So the tree should like: > > > > MMC > > |- BLK (user hardware partition) > > ||- PARTITION 1 (software partition) > > ||- PARTITION 2 (software partition) > > |... > > ||- PARTITION n (software partition) > > |- BLK (rpmb hardware partition) > > |- BLK (boot0 hardware partition) > > |- BLK (boot1 hardware partition) > > I presume you meant to include a BLK device under each PARTITION? > > But anyway, I was more thinking of this: > > MMC > | HWPARTITION rpmb > || BLK whole rpmb > || PARTITION 1 > ||| BLK > || PARTITION 2 > ||| BLK > || PARTITION 3 Do we have any reason to model a RPMB partition as a block device? For linux, at least, mmcblkrpmb looks to be a character device. > ||| BLK > | HWPARTITION boot0 > || BLK > (maybe have PARTITION in here too? I don't know how boot partitions are used on a production system. It's unlikely to have partitions on them given the purpose of "boot" partitions? > | HWPARTITION boot1 > (maybe have PARTITION in here too? > || BLK > > > > > > > > > I don't see any difference between a partition and a hardware > > > partition. We presumably end up with a hierarchy though. Do we need a > > > HWPARTITION uclass so we can handle the hardware partitions > > > differently? > > > > Software partitions are defined and discovered via partition tables. > > Hardware partitions are defined in a hardware specific way. > > > > All software partitions map to HD() device tree nodes in UEFI. > > An MMC device maps to an eMMC() node > > MMC hardware partitions are mapped to Ctrl() nodes by EDK II. We should > > do the same in U-Boot. > > An SD-card maps to an SD() node. > > An NVMe namespace maps to a NVMe() node. > > An SCSI LUN maps to a Scsi() node. > > SCSI channels of multiple channel controllers are mapped to Ctrl() nodes. > > I'm not quite sure about the terminology here. I'm not even talking > about UEFI, really, just how best to model this stuff in U-Boot. In UEFI world, each efi_disk has its own device path to identify the device. For example, here is a text representation of device path for a scsi disk partition: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)/HD(1,GPT,ce86c5a7-b32a-488f-a346-88fe698e0edc,0x22,0x4c2a) which is set to be created from a corresponding udevice (more strictly blkc_desc + part). So the issue Heinrich raised here is a matter of implementation of this conversion (software partitions, and SCSI channels?) as well as a modeling for some device type on U-Boot, i.e. MMC hardware partitions. -Takahiro Akashi > In U-Boot, UCLASS_SCSI should be a SCSI controller, not a device, > right? I'm a little worried it is not modelled correctly. After all, > what is the parent of a SCSI device? > > > > > The simple file protocol is only provided by HD() nodes and not by nodes > > representing hardware partitions. If the whole hardware partition is > > formatted as a file system you would still create a HD() node with > > partition number 0. > > Regards, > Simon --- > > > > > When it comes to UEFI, I hope we can currently support hw partitions > > in this way: > > => efidebug add boot -b 1 FOO mmc 0.1 /foo.bin "" > > (".1" is a key, I have never tried this syntax though.) > > > > But probably its device path won't be properly formatted > > as expected as Heinrich suggested. > > > > -Takahiro Akashi > > > > > > > In terms of modeling, this is akin to how if you use a USB card reader > > > that supports 4 different form-factor cards, you can end up with 4 > > > different devices showing up in Linux (if you have one of the nice card > > > readers that supports multiple cards at once). > > > > > > -- > > > Tom > > > > > > Regards, > Simon