<div dir="ltr"><div dir="ltr">Hi Sean<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Sep 9, 2022 at 10:12 PM Sean Anderson <<a href="mailto:sean.anderson@seco.com">sean.anderson@seco.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I ran into this issue today. This patch fixes things, so<br>
<br>
Tested-by: Sean Anderson <<a href="mailto:sean.anderson@seco.com" target="_blank">sean.anderson@seco.com</a>><br>
<br>
However, I think the implementation leaves a bit to be desired...<br>
<br>
On 4/6/22 11:46 AM, Fabio Aiuto wrote:<br>
> From: Michael Trimarchi <<a href="mailto:michael@amarulasolutions.com" target="_blank">michael@amarulasolutions.com</a>><br>
> <br>
> The device driver can be deferrable and can be a race during<br>
> the dm-init early. We need to wait all the probe are really finished<br>
> in a loop as is done in do_mounts. This is was tested on kernel 5.4<br>
> but code seems was not changed since that time<br>
> <br></blockquote><div><br></div><div>Ok, I know, I was waiting for some feedback. I will try to rework</div><div><br></div><div>Michael</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> 003: imx8mq-usb-phy 381f0040.usb-phy: 381f0040.usb-phy supply vbus not found, using dummy regulator<br>
> 003: imx8mq-usb-phy 382f0040.usb-phy: 382f0040.usb-phy supply vbus not found, using dummy regulator<br>
> 003: imx-cpufreq-dt imx-cpufreq-dt: cpu speed grade 5 mkt segment 0 supported-hw 0x20 0x1<br>
> 003: caam-dma caam-dma: caam dma support with 2 job rings<br>
> 000: hctosys: unable to open rtc device (rtc0)<br>
> 000: device-mapper: init: waiting for all devices to be available before creating mapped devices<br>
> 002: device-mapper: table: 254:0: verity: Data device lookup failed<br>
> 002: device-mapper: ioctl: error adding target to table<br>
> 002: crng init done<br>
> 003: of_cfs_init<br>
> 003: of_cfs_init: OK<br>
> 003: Waiting for root device /dev/dm-0...<br>
> 001: mmc2: new HS400 Enhanced strobe MMC card at address 0001<br>
> 001: mmcblk2: mmc2:0001 IB2916 14.6 GiB<br>
> 001: mmcblk2boot0: mmc2:0001 IB2916 partition 1 4.00 MiB<br>
> 001: mmcblk2boot1: mmc2:0001 IB2916 partition 2 4.00 MiB<br>
> 001: mmcblk2rpmb: mmc2:0001 IB2916 partition 3 4.00 MiB, chardev (249:0)<br>
> 001: mmcblk2: p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11<br>
> 001: VSD_3V3: disabling<br>
> <br>
> with the patch<br>
> <br>
> 003: device-mapper: init: waiting for all devices to be available before creating mapped devices<br>
> <br>
> 000: device-mapper: table: 254:0: verity: Data device lookup failed<br>
> 000: device-mapper: ioctl: error adding target to table<br>
> 002: crng init done<br>
> 003: device-mapper: init: waiting for all devices to be available before creating mapped devices<br>
> 003: device-mapper: table: 254:0: verity: Data device lookup failed<br>
> 003: device-mapper: ioctl: error adding target to table<br>
> 003: device-mapper: init: waiting for all devices to be available before creating mapped devices<br>
> 000: device-mapper: table: 254:0: verity: Data device lookup failed<br>
> 000: device-mapper: ioctl: error adding target to table<br>
> 002: device-mapper: init: waiting for all devices to be available before creating mapped devices<br>
> 002: device-mapper: table: 254:0: verity: Data device lookup failed<br>
> 002: device-mapper: ioctl: error adding target to table<br>
> 000: device-mapper: init: waiting for all devices to be available before creating mapped devices<br>
> 000: device-mapper: table: 254:0: verity: Data device lookup failed<br>
> 000: device-mapper: ioctl: error adding target to table<br>
<br>
For example, we repeatedly print these errors, even though there is not<br>
really an error condition. Additionally, we still loop even if (e.g.)<br>
there is a syntax error in the dm-mod.create parameter. It also<br>
introduces similar problems to rootdelay, where you have to choose a<br>
suitable maximum value.<br>
<br>
I would much rather see something closer to rootwait (as implemented in<br>
prepare_namespace). To do that, I think it is better to modify<br>
dm_get_device or dm_get_dev_t, which are closer to the source of the<br>
error. One issue is that these functions are not just called from<br>
dm_early_create, but also at runtime. So we can't just blindly start<br>
waiting for devices to show up if they don't exist and dm-mod.wait (or<br>
whatever) is missing. We could solve this by introducing a variable<br>
which is cleared at the end of dm_early_create. I think that solution is<br>
OK. We could also modify dm_early_create to pass a parameter to<br>
dm_table_add_target which indicates that the target is being created<br>
"early." However, I think this would be fairly disruptive to existing<br>
code.<br>
<br>
--Sean<br>
<br>
> 003: mmc2: new HS400 Enhanced strobe MMC card at address 0001<br>
> 003: mmcblk2: mmc2:0001 DG4016 14.7 GiB<br>
> 003: mmcblk2boot0: mmc2:0001 DG4016 partition 1 4.00 MiB<br>
> 003: mmcblk2boot1: mmc2:0001 DG4016 partition 2 4.00 MiB<br>
> 003: mmcblk2rpmb: mmc2:0001 DG4016 partition 3 4.00 MiB, chardev (249:0)<br>
> 003: mmcblk2: p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11<br>
> 002: device-mapper: init: waiting for all devices to be available before creating mapped devices<br>
> 003: device-mapper: verity: sha256 using implementation "sha256-caam"<br>
> 000: device-mapper: ioctl: dm-0 (rootfs) is ready<br>
> <br>
> Wait loop is limited to 10 at the moment for our use case showed no<br>
> more than 4 loops before successfully find data device.<br>
> <br>
> Signed-off-by: Michael Trimarchi <<a href="mailto:michael@amarulasolutions.com" target="_blank">michael@amarulasolutions.com</a>><br>
> Signed-off-by: Fabio Aiuto <<a href="mailto:fabio.aiuto@amarulasolutions.com" target="_blank">fabio.aiuto@amarulasolutions.com</a>><br>
> ---<br>
> Changes from v1:<br>
> - limit the loop to 10 iterations<br>
> - change variable names<br>
> - check only for -ENODEV failures<br>
> <br>
> Changes from v2:<br>
> - use a limit in seconds (not in retry<br>
> number)<br>
> - add a parameter<br>
> - update docs<br>
> <br>
> .../admin-guide/device-mapper/dm-init.rst | 13 +++++++++++<br>
> drivers/md/dm-init.c | 23 +++++++++++++++++--<br>
> 2 files changed, 34 insertions(+), 2 deletions(-)<br>
> <br>
> diff --git a/Documentation/admin-guide/device-mapper/dm-init.rst b/Documentation/admin-guide/device-mapper/dm-init.rst<br>
> index e5242ff17e9b..5c2f2bf1db03 100644<br>
> --- a/Documentation/admin-guide/device-mapper/dm-init.rst<br>
> +++ b/Documentation/admin-guide/device-mapper/dm-init.rst<br>
> @@ -123,3 +123,16 @@ Other examples (per target):<br>
> 0 1638400 verity 1 8:1 8:2 4096 4096 204800 1 sha256<br>
> fb1a5a0f00deb908d8b53cb270858975e76cf64105d412ce764225d53b8f3cfd<br>
> 51934789604d1b92399c52e7cb149d1b3a1b74bbbcb103b2a0aaacbed5c08584<br>
> +<br>
> +Delay for waiting deferred probes of block devices<br>
> +==================================================<br>
> +<br>
> +Sometimes the late initcall starting the early creation of mapped<br>
> +devices, starts too early. A loop waiting for probing of block<br>
> +devices has been added; the default maximum delay is 1 second but<br>
> +it can be set through the following kernel command::<br>
> +<br>
> + dm-mod.delay=<seconds><br>
> +<br>
> +This allows the procedure to retry the creation of a mapped device<br>
> +after a short wait (5 msecs).<br>
> diff --git a/drivers/md/dm-init.c b/drivers/md/dm-init.c<br>
> index b0c45c6ebe0b..f4c5b4a46001 100644<br>
> --- a/drivers/md/dm-init.c<br>
> +++ b/drivers/md/dm-init.c<br>
> @@ -7,7 +7,9 @@<br>
> * This file is released under the GPLv2.<br>
> */<br>
> <br>
> +#include <linux/async.h><br>
> #include <linux/ctype.h><br>
> +#include <linux/delay.h><br>
> #include <linux/device.h><br>
> #include <linux/device-mapper.h><br>
> #include <linux/init.h><br>
> @@ -18,8 +20,10 @@<br>
> #define DM_MAX_DEVICES 256<br>
> #define DM_MAX_TARGETS 256<br>
> #define DM_MAX_STR_SIZE 4096<br>
> +#define DM_DEFAULT_MAX_PROBE_DELAY 1<br>
> <br>
> static char *create;<br>
> +static int delay = DM_DEFAULT_MAX_PROBE_DELAY;<br>
> <br>
> /*<br>
> * Format: dm-mod.create=<name>,<uuid>,<minor>,<flags>,<table>[,<table>+][;<name>,<uuid>,<minor>,<flags>,<table>[,<table>+]+]<br>
> @@ -267,6 +271,8 @@ static int __init dm_init_init(void)<br>
> LIST_HEAD(devices);<br>
> char *str;<br>
> int r;<br>
> + int loopcnt = delay * 1000 / 5;<br>
> + bool devnotfound = false;<br>
> <br>
> if (!create)<br>
> return 0;<br>
> @@ -275,6 +281,7 @@ static int __init dm_init_init(void)<br>
> DMERR("Argument is too big. Limit is %d", DM_MAX_STR_SIZE);<br>
> return -EINVAL;<br>
> }<br>
> +retry:<br>
> str = kstrndup(create, DM_MAX_STR_SIZE, GFP_KERNEL);<br>
> if (!str)<br>
> return -ENOMEM;<br>
> @@ -287,13 +294,23 @@ static int __init dm_init_init(void)<br>
> wait_for_device_probe();<br>
> <br>
> list_for_each_entry(dev, &devices, list) {<br>
> - if (dm_early_create(&dev->dmi, dev->table,<br>
> - dev->target_args_array))<br>
> + r = dm_early_create(&dev->dmi, dev->table, dev->target_args_array);<br>
> + if (r == -ENODEV) {<br>
> + devnotfound = true;<br>
> break;<br>
> + }<br>
> }<br>
> +<br>
> out:<br>
> kfree(str);<br>
> dm_setup_cleanup(&devices);<br>
> + if (devnotfound && loopcnt) {<br>
> + msleep(5);<br>
> + devnotfound = false;<br>
> + loopcnt--;<br>
> + goto retry;<br>
> + }<br>
> +<br>
> return r;<br>
> }<br>
> <br>
> @@ -301,3 +318,5 @@ late_initcall(dm_init_init);<br>
> <br>
> module_param(create, charp, 0);<br>
> MODULE_PARM_DESC(create, "Create a mapped device in early boot");<br>
> +module_param(delay, int, 0);<br>
> +MODULE_PARM_DESC(delay, "Max delay to wait for data/hash device probe in seconds");<br>
> <br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Michael Nazzareno Trimarchi<br>Co-Founder & Chief Executive Officer<br>M. +39 347 913 2170<br><a href="mailto:michael@amarulasolutions.com" target="_blank">michael@amarulasolutions.com</a><br>__________________________________<br><div><br></div><div>Amarula Solutions BV</div>Joop Geesinkweg 125, 1114 AB, Amsterdam, NL<br>T. +31 (0)85 111 9172<br><a href="mailto:info@amarulasolutions.com" target="_blank">info@amarulasolutions.com</a><br><a href="http://www.amarulasolutions.com" target="_blank">www.amarulasolutions.com</a><br></div></div></div>