Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1392602pxb; Sat, 23 Apr 2022 05:33:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/vFI07+cyEOH5upKf/QPG8w3EVY2jKcGq9O0w9IMr2f+yhFoizU70vbLKxsT5aWl2F4+r X-Received: by 2002:a17:907:62aa:b0:6e0:f208:b869 with SMTP id nd42-20020a17090762aa00b006e0f208b869mr8051487ejc.270.1650717190843; Sat, 23 Apr 2022 05:33:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650717190; cv=none; d=google.com; s=arc-20160816; b=YbW3yFPMcec43Pkwwm1fYGsp/tiAxZLtjw1b6kevaFk+Ji7JXnXWUNHsKKRVmbI3jB r7JgAzLhz2mX1ZV7BL3+Pk9PfDzDQPqn1YFWpwVSm56iabJA2A6apsfJ1Q6nuZDtmfTr rQIZUNDjE+uuChkZ5EGDuxXvyoKLGNhCilM8HYaOdSd5tUTLOyjioNU2YbVgnvSjumeP htRR2I9RdoA7977Du4eUmL1dIDiWBXcV78UlZ3M4M2vhgpCGDB5dWuKGdNDe1B9eA4MY k9vZ/OQfpoL+fBcc/5lUOACU5ImvfERKn54g630HPn/KYvUD934llwhQrSpg6pIef/7A wfnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=9tEABhHPLdbb/U7q9ZbhGXPyRjuxdRV60qM4AkqCbUw=; b=lT5ZxMq7wxkTkWFwEk2AFAuBBBgtJnur2uh5yO0aqb9SwjZHqeUFV9ys+gaOrzloPm xHpi57n4YsgJtJQVVW/3qrpsZHM6xy8rtyH2z7+g7jCWO7t9OkGK/H6hduFtdHyjXnYm qgYEZrYTPwgo+FOAXfxCJYVxFZ77ojeK0/bHdciS5RwLvZDTF5j5/x3D5Z9otxe5fe/r ZRHH8DkrSeRDhXmLLPpyu9uDhjyYG6rvSPufbLZl0ZhPPrxuJRU+bmdAXRZ+cMv02Gj6 YiChzDayJlipBKNvytje2OZkf4KCxCRmcbY5r+EY2q11tKHEMfssmX3LilLFWt17Y0K8 kwjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=jfc8iT+3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y22-20020a1709064b1600b006df76385cb6si9041948eju.342.2022.04.23.05.32.47; Sat, 23 Apr 2022 05:33:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=jfc8iT+3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233955AbiDWIRM (ORCPT + 99 others); Sat, 23 Apr 2022 04:17:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230032AbiDWIRJ (ORCPT ); Sat, 23 Apr 2022 04:17:09 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00585106DDE for ; Sat, 23 Apr 2022 01:14:10 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id d15so15780748pll.10 for ; Sat, 23 Apr 2022 01:14:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9tEABhHPLdbb/U7q9ZbhGXPyRjuxdRV60qM4AkqCbUw=; b=jfc8iT+31p81mRPfrmKor5PkEPSt3Wvm51DwbLgVcwpJfnqQeQ3gE35ejaN5xt1v62 Ljtt28LtLFOVZTkKK5GF0TgpLdrQBo8JS9jxB4e60aw4IxVBJPgZhiRM4ObJekeIkv7Y aIdI65XzVDqie4Q0wxSvh9eZPouaP1zij1318= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=9tEABhHPLdbb/U7q9ZbhGXPyRjuxdRV60qM4AkqCbUw=; b=CjcXKdXWhKu15mprDUKYKybexCopI+LYOzGH5jNdWpVyZsEW0wv5u4qWG9b8h1UjBJ mcpD5ejmw2e4g6XDgn15nEIwGmVg0O2bJzmLg+xs25vsr9Hr+4jHXuHKF2aONwGBZAtD JIZ7c6PCZniLz1TR2EXqkHlnB2NLecxVoJRRYVqTjk0gzLmwR0QSkIgF4clJpTKKyTv6 0RsM89uLkzUAMufaqSj6EmI05DMhBvYxKI35kfuNLC5B0DX9SJn7bIvZxAOSmYkYVASU jzzfB6O5U7tZcACl0jmXmKbZNHcefymm0onL1HJwS1w1h1RKFH1com7gRkg7zhEbdCD7 FHxQ== X-Gm-Message-State: AOAM530Nmk/AXieBKuZJPZgPwr+LnkLzcFO8RyMbzboUSMyxfcXM2GuX y8joMQ/Km99xZo2DCOH09FGFTufzhS2of0ROxR6YPQ== X-Received: by 2002:a17:90a:94c2:b0:1d9:3fbd:bbe1 with SMTP id j2-20020a17090a94c200b001d93fbdbbe1mr561231pjw.59.1650701650360; Sat, 23 Apr 2022 01:14:10 -0700 (PDT) MIME-Version: 1.0 References: <20220406154631.277107-1-fabio.aiuto@amarulasolutions.com> In-Reply-To: <20220406154631.277107-1-fabio.aiuto@amarulasolutions.com> From: Michael Nazzareno Trimarchi Date: Sat, 23 Apr 2022 10:13:59 +0200 Message-ID: Subject: Re: [PATCH v3] md: dm-init: Wait devices if it's not find on first adpet To: Fabio Aiuto Cc: agk@redhat.com, snitzer@kernel.org, dm-devel@redhat.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi all On Wed, Apr 6, 2022 at 5:46 PM Fabio Aiuto wrote: > > From: Michael Trimarchi > > The device driver can be deferrable and can be a race during > the dm-init early. We need to wait all the probe are really finished > in a loop as is done in do_mounts. This is was tested on kernel 5.4 > but code seems was not changed since that time > Any follow up? Michael > 003: imx8mq-usb-phy 381f0040.usb-phy: 381f0040.usb-phy supply vbus not found, using dummy regulator > 003: imx8mq-usb-phy 382f0040.usb-phy: 382f0040.usb-phy supply vbus not found, using dummy regulator > 003: imx-cpufreq-dt imx-cpufreq-dt: cpu speed grade 5 mkt segment 0 supported-hw 0x20 0x1 > 003: caam-dma caam-dma: caam dma support with 2 job rings > 000: hctosys: unable to open rtc device (rtc0) > 000: device-mapper: init: waiting for all devices to be available before creating mapped devices > 002: device-mapper: table: 254:0: verity: Data device lookup failed > 002: device-mapper: ioctl: error adding target to table > 002: crng init done > 003: of_cfs_init > 003: of_cfs_init: OK > 003: Waiting for root device /dev/dm-0... > 001: mmc2: new HS400 Enhanced strobe MMC card at address 0001 > 001: mmcblk2: mmc2:0001 IB2916 14.6 GiB > 001: mmcblk2boot0: mmc2:0001 IB2916 partition 1 4.00 MiB > 001: mmcblk2boot1: mmc2:0001 IB2916 partition 2 4.00 MiB > 001: mmcblk2rpmb: mmc2:0001 IB2916 partition 3 4.00 MiB, chardev (249:0) > 001: mmcblk2: p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 > 001: VSD_3V3: disabling > > with the patch > > 003: device-mapper: init: waiting for all devices to be available before creating mapped devices > > 000: device-mapper: table: 254:0: verity: Data device lookup failed > 000: device-mapper: ioctl: error adding target to table > 002: crng init done > 003: device-mapper: init: waiting for all devices to be available before creating mapped devices > 003: device-mapper: table: 254:0: verity: Data device lookup failed > 003: device-mapper: ioctl: error adding target to table > 003: device-mapper: init: waiting for all devices to be available before creating mapped devices > 000: device-mapper: table: 254:0: verity: Data device lookup failed > 000: device-mapper: ioctl: error adding target to table > 002: device-mapper: init: waiting for all devices to be available before creating mapped devices > 002: device-mapper: table: 254:0: verity: Data device lookup failed > 002: device-mapper: ioctl: error adding target to table > 000: device-mapper: init: waiting for all devices to be available before creating mapped devices > 000: device-mapper: table: 254:0: verity: Data device lookup failed > 000: device-mapper: ioctl: error adding target to table > 003: mmc2: new HS400 Enhanced strobe MMC card at address 0001 > 003: mmcblk2: mmc2:0001 DG4016 14.7 GiB > 003: mmcblk2boot0: mmc2:0001 DG4016 partition 1 4.00 MiB > 003: mmcblk2boot1: mmc2:0001 DG4016 partition 2 4.00 MiB > 003: mmcblk2rpmb: mmc2:0001 DG4016 partition 3 4.00 MiB, chardev (249:0) > 003: mmcblk2: p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 > 002: device-mapper: init: waiting for all devices to be available before creating mapped devices > 003: device-mapper: verity: sha256 using implementation "sha256-caam" > 000: device-mapper: ioctl: dm-0 (rootfs) is ready > > Wait loop is limited to 10 at the moment for our use case showed no > more than 4 loops before successfully find data device. > > Signed-off-by: Michael Trimarchi > Signed-off-by: Fabio Aiuto > --- > Changes from v1: > - limit the loop to 10 iterations > - change variable names > - check only for -ENODEV failures > > Changes from v2: > - use a limit in seconds (not in retry > number) > - add a parameter > - update docs > > .../admin-guide/device-mapper/dm-init.rst | 13 +++++++++++ > drivers/md/dm-init.c | 23 +++++++++++++++++-- > 2 files changed, 34 insertions(+), 2 deletions(-) > > diff --git a/Documentation/admin-guide/device-mapper/dm-init.rst b/Documentation/admin-guide/device-mapper/dm-init.rst > index e5242ff17e9b..5c2f2bf1db03 100644 > --- a/Documentation/admin-guide/device-mapper/dm-init.rst > +++ b/Documentation/admin-guide/device-mapper/dm-init.rst > @@ -123,3 +123,16 @@ Other examples (per target): > 0 1638400 verity 1 8:1 8:2 4096 4096 204800 1 sha256 > fb1a5a0f00deb908d8b53cb270858975e76cf64105d412ce764225d53b8f3cfd > 51934789604d1b92399c52e7cb149d1b3a1b74bbbcb103b2a0aaacbed5c08584 > + > +Delay for waiting deferred probes of block devices > +================================================== > + > +Sometimes the late initcall starting the early creation of mapped > +devices, starts too early. A loop waiting for probing of block > +devices has been added; the default maximum delay is 1 second but > +it can be set through the following kernel command:: > + > + dm-mod.delay= > + > +This allows the procedure to retry the creation of a mapped device > +after a short wait (5 msecs). > diff --git a/drivers/md/dm-init.c b/drivers/md/dm-init.c > index b0c45c6ebe0b..f4c5b4a46001 100644 > --- a/drivers/md/dm-init.c > +++ b/drivers/md/dm-init.c > @@ -7,7 +7,9 @@ > * This file is released under the GPLv2. > */ > > +#include > #include > +#include > #include > #include > #include > @@ -18,8 +20,10 @@ > #define DM_MAX_DEVICES 256 > #define DM_MAX_TARGETS 256 > #define DM_MAX_STR_SIZE 4096 > +#define DM_DEFAULT_MAX_PROBE_DELAY 1 > > static char *create; > +static int delay = DM_DEFAULT_MAX_PROBE_DELAY; > > /* > * Format: dm-mod.create=,,,,[,
+][;,,,,
[,
+]+] > @@ -267,6 +271,8 @@ static int __init dm_init_init(void) > LIST_HEAD(devices); > char *str; > int r; > + int loopcnt = delay * 1000 / 5; > + bool devnotfound = false; > > if (!create) > return 0; > @@ -275,6 +281,7 @@ static int __init dm_init_init(void) > DMERR("Argument is too big. Limit is %d", DM_MAX_STR_SIZE); > return -EINVAL; > } > +retry: > str = kstrndup(create, DM_MAX_STR_SIZE, GFP_KERNEL); > if (!str) > return -ENOMEM; > @@ -287,13 +294,23 @@ static int __init dm_init_init(void) > wait_for_device_probe(); > > list_for_each_entry(dev, &devices, list) { > - if (dm_early_create(&dev->dmi, dev->table, > - dev->target_args_array)) > + r = dm_early_create(&dev->dmi, dev->table, dev->target_args_array); > + if (r == -ENODEV) { > + devnotfound = true; > break; > + } > } > + > out: > kfree(str); > dm_setup_cleanup(&devices); > + if (devnotfound && loopcnt) { > + msleep(5); > + devnotfound = false; > + loopcnt--; > + goto retry; > + } > + > return r; > } > > @@ -301,3 +318,5 @@ late_initcall(dm_init_init); > > module_param(create, charp, 0); > MODULE_PARM_DESC(create, "Create a mapped device in early boot"); > +module_param(delay, int, 0); > +MODULE_PARM_DESC(delay, "Max delay to wait for data/hash device probe in seconds"); > -- > 2.30.2 >