From patchwork Sun Aug 13 08:23:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 135022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp2119235vqi; Sun, 13 Aug 2023 02:53:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQm8l9P+A3owiZX9Myf0PTCyFIden++17p4WZAX5VoR9ue6p0w4qKRol85Gpdne2P+D/m8 X-Received: by 2002:aa7:d390:0:b0:522:15c4:b5ba with SMTP id x16-20020aa7d390000000b0052215c4b5bamr5188080edq.3.1691920390111; Sun, 13 Aug 2023 02:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691920390; cv=none; d=google.com; s=arc-20160816; b=GIu1SGJsYnKRVO7ZZyz+niM2iPNpGoeo5QbrsUbrnEonIqtY9ijCKXokbtAKrH2TXJ Lt5/ypG9zWRePdUlQE+5tRVosa0Wres2iDTdRwxBpzPaRtjli9SbOlOq8fy5+Rc3WodH h3P2xKMlqXsVNnRj82S0f797PzWwOkVj5n0fYhGwvwHx33MVf5F1XxRPbNFiZL7Sfkge YpBXKv+pLOSaJI9tfY1+bvuAXF7zZZJN84E2vnG/s8jaoWdNkXOVG/Q36uTc8zeyZA/0 eFZRJvzuHL3lejrZBjePET2Mj27Do5w44tA9HaDPC+kkV9i/b1Es6rjqyI2r0i1GzCvA 4Wgw== 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=VZM/b5Pej16mPyKc+Kl8IzPyaWchqEJykmJSB7R8QxY=; fh=KWidD4uKWkUIXFqknUCCQrhJ4TUzlQ0FPfGGxYKhhd8=; b=NNP+3EQx/GuM6dg2gLeLQic7/H/WqmAiC/9yG99PI/VTsASLFNm1d0M/W3rSCFuGvL pq3DrSaZtxxRGx9NYf3pX0XOzu0yYDMbaPrUqFq8NEUAkz21Xbi3m2DeKo/P5IP+rlfD o02HbrVxab6CUZNe3bMFc+dhFQgmayFLHhfng2GaCJXgPer+wYS785RT0OSweguBVCmR NL494zWQlWaI6vC3dV00Sy/ANOHPPE3raNBKyg6+lI+AzlzW5012VCMDtozRRnPCyizR ohezLto2I4J0lLfhUd4QVoT7Xcjj2DrRseI7a5h3QzAlOCfAb0GrLPsb4VbIm4spGuZi hwBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ewmkr7AF; 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 n10-20020a05640206ca00b005232ea6a33fsi6016923edy.18.2023.08.13.02.52.47; Sun, 13 Aug 2023 02:53: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=@linaro.org header.s=google header.b=Ewmkr7AF; 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 S230384AbjHMIXz (ORCPT + 99 others); Sun, 13 Aug 2023 04:23:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbjHMIXy (ORCPT ); Sun, 13 Aug 2023 04:23:54 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88D9910FE for ; Sun, 13 Aug 2023 01:23:56 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3fe8a158fcbso16497025e9.2 for ; Sun, 13 Aug 2023 01:23:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691915035; x=1692519835; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=VZM/b5Pej16mPyKc+Kl8IzPyaWchqEJykmJSB7R8QxY=; b=Ewmkr7AF7MNqSpuZkHq/Y4c5NCdWW9p+Fc1hm2GYmFQmYDt7K8M3kFQ62C12zb0tvl AbAerJCN4HYZd4DOFtyWh3Q7jNkGqk9aX6idham7z1TeYyEmOpIrYudXMnh42Obiq9wa YTha5qrZx+r933REfvtYvkwVdE3mcPtmjhs2GgpfLSeuG8d8Vfu9dOt9CGK6FLS1iUSm 6hrIbrXrRl+KO0XPqAOsLpnID9uUyuv5oyMF2nn/7Vu03RTzc91SZaLWRYNkDaHHPLIt BXEb91rEsywUr7G7ihLXN7R12umwmy6Pemp1pZ6SxMLzORjpY6Rg9+9CnSpdRupP3LMU E6rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691915035; x=1692519835; 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=VZM/b5Pej16mPyKc+Kl8IzPyaWchqEJykmJSB7R8QxY=; b=Qn/c+whcEgn8rzx5vI28/bSNqWxQ5jXljebm1tzXFRperQrARxKf1BMp6mJs0gujNB Sx0LOWgVKUmBnqhpJco0YtObEgsvh1H3NQyjot2YrfjWGWBuw+2zcQ2LlT9F6LxcSUE4 xWjPMZ7ObUwAXHJ9qqeemCSm2l541x6zrm0Qr+xCsCVLvwf//eF6oROZbb0uMgW7vLLK ac4hC4DTYRBwT6JBOQaJKuz9FOXm55byWD8/t80FvWe11RVIh8JQV1EUwiDzScLNEoPN AqGsB2SUvSQsaoYtsv+9UBHawhZVJ29aZnOYO6ECyIdV/1hAd4ufNZohoZtZMGob/D/1 uTKA== X-Gm-Message-State: AOJu0Yy9Ex/psX+nPoai2mHlAmrCXxbKmyU2sGZPIRgJZ3h5TH6gyljI i6xmk9/BVegJUxOgFg9FwqRNQSbjsN5DgRNJ+0Q= X-Received: by 2002:a05:600c:2487:b0:3fe:1d13:4663 with SMTP id 7-20020a05600c248700b003fe1d134663mr5044165wms.1.1691915034606; Sun, 13 Aug 2023 01:23:54 -0700 (PDT) Received: from loic-ThinkPad-T470p.. ([2a01:e0a:82c:5f0:92a5:d57e:294f:f41a]) by smtp.gmail.com with ESMTPSA id n5-20020a05600c294500b003fbaade0735sm13495057wmd.19.2023.08.13.01.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Aug 2023 01:23:53 -0700 (PDT) From: Loic Poulain 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 Subject: [PATCH v4] init: Add support for rootwait timeout parameter Date: Sun, 13 Aug 2023 10:23:49 +0200 Message-Id: <20230813082349.513386-1-loic.poulain@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774107114549263946 X-GMAIL-MSGID: 1774107114549263946 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 --- v2: rebase + reword: add use case example v3: Use kstrtoint instead of deprecated simple_strtoul v4: Handle mult overflow when converting sec to ms Initialize end ktime after ROOT_DEV check .../admin-guide/kernel-parameters.txt | 4 ++ init/do_mounts.c | 38 ++++++++++++++++++- 2 files changed, 40 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..5dfd30b13f48 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -71,12 +72,37 @@ 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) +{ + int sec; + + if (kstrtoint(str, 0, &sec) || sec < 0) { + pr_warn("ignoring invalid rootwait value\n"); + goto ignore; + } + + if (check_mul_overflow(sec, MSEC_PER_SEC, &root_wait)) { + pr_warn("ignoring excessive rootwait value\n"); + goto ignore; + } + + return 1; + +ignore: + /* 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 +410,22 @@ 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) { + ktime_t end; + if (ROOT_DEV != 0) return; pr_info("Waiting for root device %s...\n", root_device_name); + end = ktime_add_ms(ktime_get_raw(), root_wait); + 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(); }