Message ID | 20230806101217.164068-1-loic.poulain@linaro.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp877948vqr; Sun, 6 Aug 2023 04:29:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGovxS8u1ys3hqY239+rRf0A7pYBMAMDp5T6gmNV5Q5zAtI8jH/NS5wxogEOmXRrLSlcFg4 X-Received: by 2002:a17:906:1045:b0:99b:ca24:ce33 with SMTP id j5-20020a170906104500b0099bca24ce33mr6436715ejj.31.1691321388971; Sun, 06 Aug 2023 04:29:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691321388; cv=none; d=google.com; s=arc-20160816; b=nULmIIDiP0X933e9nWhQz2Vt92Z12hCN4LXukD4WeZoNuIx5BtQH9TGj9sbzqDakDN DZeDWdsLb9ujXEB7mh3R5i/U0vXou6wtEJBwhsIc4yiQsuTk9uGKbKvHZu7+yUHqHeYy HCgzViJWxg/A6goJ50NhAOGs3CTitZ6UGUqvqHOyU9jwxMEapVbusxJGEmml9Pv4hxAq oPsb08dCwzpnEUi5qt5312rHneRZlaJWH2Dv72NNb/h+nje//CbjyDX+UiwqrJArXMir YQZOQNfkhRtuSYZzQh1HFG5ulM4Esex+B5kPhtQxD0FwNlbzpBeSvjD+PB19EmHnVr39 cexA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=stuJqaNoc8+CyrTaBzMymqInJJyNxuySrxbp3ccLMSM=; fh=KWidD4uKWkUIXFqknUCCQrhJ4TUzlQ0FPfGGxYKhhd8=; b=nu0wgSWTXpEDESdEp2PyuGejzZO16jurKz1yJigLECmGyV4wDEWWzbCxAy3/IR50za NiraTM0yAGn8dp+2Rxigdf+M3+5r3b0W0jet5VwE+rHZ4Kr/bvQ4i0Y8+RAxPGbxrFDg r+hYIvVbH56pAhcm888N+3J1t/vhmKruBCGdoLD6r+CUOHq+4/WS46nkPAa0CUGVTBwu htzAfXFd8gHWULy1Sz+XWE8kZmNI4GeO3/7SH5qdmcurf0cyUU9JQ1HN86X2eR6yNm5L xCjzOnwo0pcgMh60kad5vp0oF9aaQhZqhvAnOkk0QUj6dLCkPRZE6dTHm7/Hf8wSQv3W DbjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BvUibkjX; 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=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y23-20020a170906559700b009888665e53fsi3621661ejp.190.2023.08.06.04.29.24; Sun, 06 Aug 2023 04:29:48 -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=@linaro.org header.s=google header.b=BvUibkjX; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230258AbjHFKM0 (ORCPT <rfc822;david.simonyants@gmail.com> + 99 others); Sun, 6 Aug 2023 06:12:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229780AbjHFKMY (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 6 Aug 2023 06:12:24 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 344EB19A6 for <linux-kernel@vger.kernel.org>; Sun, 6 Aug 2023 03:12:23 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3fe4ad22e36so18557615e9.2 for <linux-kernel@vger.kernel.org>; Sun, 06 Aug 2023 03:12:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691316741; x=1691921541; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=stuJqaNoc8+CyrTaBzMymqInJJyNxuySrxbp3ccLMSM=; b=BvUibkjXpSn53ss6d2zWo3GHot1opOycwPZLmgg5RX03G6KJzC2uUYMo7Ej1fmktPN n1TE2pKhI+mHYJfzop9rxOhvuDM81/U6vmE74ewiMKl4X4FSfQQvHEqlqh7fcZ/L2r03 scb0mhJCHjZcxPW4ammn5glclltGIvkWPapubBJM+ds7HjObw6hRGkM3+ggBs8XG6q0+ PU9DnBiea1oKKox9Bnv/vj7cY78J3oljrMclWguKcWyoJ/8znocnA20Wt4StxGjiyzJD +/I3T+OIJTtL+u3qaY0bBofAHKSmP5yohxv+ffm4YZOKDzwEuhBmVakVqfrFZkZfF7MY MhwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691316741; x=1691921541; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=stuJqaNoc8+CyrTaBzMymqInJJyNxuySrxbp3ccLMSM=; b=OMYaNnz0oHVBEwkovaZJ4M73zYs6VQszt8AJlR880cdN7Sk3Whh3BLN1m3We6TUnJT hwoOBhn4ACv8T2Gv9QYBllSELgnh3WOUvDp+ZubQsPLWrdPBRzWCJh8NuaSZvAQZC7yX e9pKzd72zb6Gh3qBB4XvexEoPX59bYhF+r6W5Evcas3DSLto3uG+r4xXZKursLmfS7vW 7RwHH7mswhk6941VUyauuueGuw3Z11bkGBCL6H+x6127mRa67GEZR4jcdpNLovag2eTf dFGw7PmDvaKExwbVbggT+8PVfSSXcjQZo4kXCd5Jq+qoqOOe+Giz2PNzkYB6ZVSuAlGF PYRA== X-Gm-Message-State: AOJu0Yw2Fg80NeCLVla48PqlAtxJRGqjUJN3QsuNxP00aato+KiiySkZ HpENUfLR/x3IYHyWd/Ruix4evHypBdb2wVVCLMw= X-Received: by 2002:a7b:cc99:0:b0:3fe:1f98:deb7 with SMTP id p25-20020a7bcc99000000b003fe1f98deb7mr4690456wma.35.1691316741571; Sun, 06 Aug 2023 03:12:21 -0700 (PDT) Received: from loic-ThinkPad-T470p.. ([2a01:e0a:82c:5f0:2a5f:dd16:fb77:b314]) by smtp.gmail.com with ESMTPSA id a14-20020adfed0e000000b003177f57e79esm7209115wro.88.2023.08.06.03.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Aug 2023 03:12:20 -0700 (PDT) From: Loic Poulain <loic.poulain@linaro.org> To: brauner@kernel.org, viro@zeniv.linux.org.uk, corbet@lwn.net Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, hch@infradead.org, rdunlap@infradead.org, Loic Poulain <loic.poulain@linaro.org> Subject: [PATCH v3] init: Add support for rootwait timeout parameter Date: Sun, 6 Aug 2023 12:12:17 +0200 Message-Id: <20230806101217.164068-1-loic.poulain@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773479016650544922 X-GMAIL-MSGID: 1773479016650544922 |
Series |
[v3] init: Add support for rootwait timeout parameter
|
|
Commit Message
Loic Poulain
Aug. 6, 2023, 10:12 a.m. UTC
Add an optional timeout arg to 'rootwait' as the maximum time in
seconds to wait for the root device to show up before attempting
forced mount of the root filesystem.
Use case:
In case of device mapper usage for the rootfs (e.g. root=/dev/dm-0),
if the mapper is not able to create the virtual block for any reason
(wrong arguments, bad dm-verity signature, etc), the `rootwait` param
causes the kernel to wait forever. It may however be desirable to only
wait for a given time and then panic (force mount) to cause device reset.
This gives the bootloader a chance to detect the problem and to take some
measures, such as marking the booted partition as bad (for A/B case) or
entering a recovery mode.
In success case, mounting happens as soon as the root device is ready,
unlike the existing 'rootdelay' parameter which performs an unconditional
pause.
Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
---
v2: rebase + reword: add use case example
v3: Use kstrtoint instead of deprecated simple_strtoul
.../admin-guide/kernel-parameters.txt | 4 ++++
init/do_mounts.c | 24 +++++++++++++++++--
2 files changed, 26 insertions(+), 2 deletions(-)
Comments
On 2023-08-06 18:12, Loic Poulain <loic.poulain@linaro.org> wrote: > Add an optional timeout arg to 'rootwait' as the maximum time in > seconds to wait for the root device to show up before attempting > forced mount of the root filesystem. > > Use case: > In case of device mapper usage for the rootfs (e.g. root=/dev/dm-0), > if the mapper is not able to create the virtual block for any reason > (wrong arguments, bad dm-verity signature, etc), the `rootwait` param > causes the kernel to wait forever. It may however be desirable to only > wait for a given time and then panic (force mount) to cause device reset. > This gives the bootloader a chance to detect the problem and to take some > measures, such as marking the booted partition as bad (for A/B case) or > entering a recovery mode. > > In success case, mounting happens as soon as the root device is ready, > unlike the existing 'rootdelay' parameter which performs an unconditional > pause. > > Signed-off-by: Loic Poulain <loic.poulain@linaro.org> > --- > v2: rebase + reword: add use case example > v3: Use kstrtoint instead of deprecated simple_strtoul > > .../admin-guide/kernel-parameters.txt | 4 ++++ > init/do_mounts.c | 24 +++++++++++++++++-- > 2 files changed, 26 insertions(+), 2 deletions(-) > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > index a1457995fd41..387cf9c2a2c5 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -5501,6 +5501,10 @@ > Useful for devices that are detected asynchronously > (e.g. USB and MMC devices). > > + rootwait= [KNL] Maximum time (in seconds) to wait for root device > + to show up before attempting to mount the root > + filesystem. > + > rproc_mem=nn[KMG][@address] > [KNL,ARM,CMA] Remoteproc physical memory block. > Memory area to be used by remote processor image, > diff --git a/init/do_mounts.c b/init/do_mounts.c > index 1aa015883519..98190bf34a9f 100644 > --- a/init/do_mounts.c > +++ b/init/do_mounts.c > @@ -18,6 +18,7 @@ > #include <linux/slab.h> > #include <linux/ramfs.h> > #include <linux/shmem_fs.h> > +#include <linux/ktime.h> > > #include <linux/nfs_fs.h> > #include <linux/nfs_fs_sb.h> > @@ -71,12 +72,25 @@ static int __init rootwait_setup(char *str) > { > if (*str) > return 0; > - root_wait = 1; > + root_wait = -1; > return 1; > } > > __setup("rootwait", rootwait_setup); > > +static int __init rootwait_timeout_setup(char *str) > +{ > + if (kstrtoint(str, 0, &root_wait) || root_wait < 0) { > + pr_warn("ignoring invalid rootwait value\n"); > + /* fallback to indefinite wait */ > + root_wait = -1; Will it be a little better to add the 'fallback to infinite wait' message into pr_wran as well? > + } > + > + return 1; > +} > + > +__setup("rootwait=", rootwait_timeout_setup); > + > static char * __initdata root_mount_data; > static int __init root_data_setup(char *str) > { > @@ -384,14 +398,20 @@ void __init mount_root(char *root_device_name) > /* wait for any asynchronous scanning to complete */ > static void __init wait_for_root(char *root_device_name) > { > + const ktime_t end = ktime_add_ms(ktime_get_raw(), root_wait * MSEC_PER_SEC); > + > if (ROOT_DEV != 0) > return; > > pr_info("Waiting for root device %s...\n", root_device_name); > > while (!driver_probe_done() || > - early_lookup_bdev(root_device_name, &ROOT_DEV) < 0) > + early_lookup_bdev(root_device_name, &ROOT_DEV) < 0) { Seems like one indent issue here? > msleep(5); > + if (root_wait > 0 && ktime_after(ktime_get_raw(), end)) > + break; > + } > + > async_synchronize_full(); > > } > -- > 2.34.1 Regards. Liang Li
On Sun, Aug 06, 2023 at 12:12:17PM +0200, Loic Poulain wrote: > Add an optional timeout arg to 'rootwait' as the maximum time in > seconds to wait for the root device to show up before attempting > forced mount of the root filesystem. > > Use case: > In case of device mapper usage for the rootfs (e.g. root=/dev/dm-0), > if the mapper is not able to create the virtual block for any reason > (wrong arguments, bad dm-verity signature, etc), the `rootwait` param > causes the kernel to wait forever. It may however be desirable to only > wait for a given time and then panic (force mount) to cause device reset. > This gives the bootloader a chance to detect the problem and to take some > measures, such as marking the booted partition as bad (for A/B case) or > entering a recovery mode. > > In success case, mounting happens as soon as the root device is ready, > unlike the existing 'rootdelay' parameter which performs an unconditional > pause. > > Signed-off-by: Loic Poulain <loic.poulain@linaro.org> > --- > v2: rebase + reword: add use case example > v3: Use kstrtoint instead of deprecated simple_strtoul > > .../admin-guide/kernel-parameters.txt | 4 ++++ > init/do_mounts.c | 24 +++++++++++++++++-- > 2 files changed, 26 insertions(+), 2 deletions(-) > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > index a1457995fd41..387cf9c2a2c5 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -5501,6 +5501,10 @@ > Useful for devices that are detected asynchronously > (e.g. USB and MMC devices). > > + rootwait= [KNL] Maximum time (in seconds) to wait for root device > + to show up before attempting to mount the root > + filesystem. > + > rproc_mem=nn[KMG][@address] > [KNL,ARM,CMA] Remoteproc physical memory block. > Memory area to be used by remote processor image, > diff --git a/init/do_mounts.c b/init/do_mounts.c > index 1aa015883519..98190bf34a9f 100644 > --- a/init/do_mounts.c > +++ b/init/do_mounts.c > @@ -18,6 +18,7 @@ > #include <linux/slab.h> > #include <linux/ramfs.h> > #include <linux/shmem_fs.h> > +#include <linux/ktime.h> > > #include <linux/nfs_fs.h> > #include <linux/nfs_fs_sb.h> > @@ -71,12 +72,25 @@ static int __init rootwait_setup(char *str) > { > if (*str) > return 0; > - root_wait = 1; > + root_wait = -1; > return 1; > } > > __setup("rootwait", rootwait_setup); > > +static int __init rootwait_timeout_setup(char *str) > +{ > + if (kstrtoint(str, 0, &root_wait) || root_wait < 0) { > + pr_warn("ignoring invalid rootwait value\n"); > + /* fallback to indefinite wait */ > + root_wait = -1; > + } > + > + return 1; > +} > + > +__setup("rootwait=", rootwait_timeout_setup); > + > static char * __initdata root_mount_data; > static int __init root_data_setup(char *str) > { > @@ -384,14 +398,20 @@ void __init mount_root(char *root_device_name) > /* wait for any asynchronous scanning to complete */ > static void __init wait_for_root(char *root_device_name) > { > + const ktime_t end = ktime_add_ms(ktime_get_raw(), root_wait * MSEC_PER_SEC); I'd only initialize @end after the ROOT_DEV check. Also, afaict, this currently allows userspace to overflow, i.e., root_wait=2147483647 ktime_add_ms(..., root_wait(2147483647) * MSEC_PER_SEC(1000)) So idk, you probably want to convert root_wait to ms right away and do sm like (completely untested): static int __init rootwait_timeout_setup(char *str) { int ret, tmp; THIS LINE WILL BREAK COMPILATION if (*str) return 0; /* always fallback to indefinite wait */ root_wait = -1; ret = kstrtoint(str, 0, &tmp)); if (ret || tmp < 0) { pr_warn("ignoring invalid rootwait value\n"); return 1; } if (check_mul_overflow(tmp, MSEC_PER_SEC, &root_wait)) pr_warn("ignoring excessive rootwait value\n"); return 1; }
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index a1457995fd41..387cf9c2a2c5 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -5501,6 +5501,10 @@ Useful for devices that are detected asynchronously (e.g. USB and MMC devices). + rootwait= [KNL] Maximum time (in seconds) to wait for root device + to show up before attempting to mount the root + filesystem. + rproc_mem=nn[KMG][@address] [KNL,ARM,CMA] Remoteproc physical memory block. Memory area to be used by remote processor image, diff --git a/init/do_mounts.c b/init/do_mounts.c index 1aa015883519..98190bf34a9f 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c @@ -18,6 +18,7 @@ #include <linux/slab.h> #include <linux/ramfs.h> #include <linux/shmem_fs.h> +#include <linux/ktime.h> #include <linux/nfs_fs.h> #include <linux/nfs_fs_sb.h> @@ -71,12 +72,25 @@ static int __init rootwait_setup(char *str) { if (*str) return 0; - root_wait = 1; + root_wait = -1; return 1; } __setup("rootwait", rootwait_setup); +static int __init rootwait_timeout_setup(char *str) +{ + if (kstrtoint(str, 0, &root_wait) || root_wait < 0) { + pr_warn("ignoring invalid rootwait value\n"); + /* fallback to indefinite wait */ + root_wait = -1; + } + + return 1; +} + +__setup("rootwait=", rootwait_timeout_setup); + static char * __initdata root_mount_data; static int __init root_data_setup(char *str) { @@ -384,14 +398,20 @@ void __init mount_root(char *root_device_name) /* wait for any asynchronous scanning to complete */ static void __init wait_for_root(char *root_device_name) { + const ktime_t end = ktime_add_ms(ktime_get_raw(), root_wait * MSEC_PER_SEC); + if (ROOT_DEV != 0) return; pr_info("Waiting for root device %s...\n", root_device_name); while (!driver_probe_done() || - early_lookup_bdev(root_device_name, &ROOT_DEV) < 0) + early_lookup_bdev(root_device_name, &ROOT_DEV) < 0) { msleep(5); + if (root_wait > 0 && ktime_after(ktime_get_raw(), end)) + break; + } + async_synchronize_full(); }