From patchwork Wed Jul 26 15:22:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 126470 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp495589vqo; Wed, 26 Jul 2023 08:55:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlEh6Q1H4iOKsXGT8EviGOaqMeNjp4WSZpkzZLGV1feTwwKGM+zz1/6t3BQpZTGr4ZbHNsEC X-Received: by 2002:a05:6a00:1a0e:b0:668:753a:b150 with SMTP id g14-20020a056a001a0e00b00668753ab150mr2303748pfv.21.1690386948194; Wed, 26 Jul 2023 08:55:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690386948; cv=none; d=google.com; s=arc-20160816; b=agW4q/tbGg9HrNdmMkNXKUp9tre7XfcMy3fWbMZNFjNl0cSz7/un+60/XVPFfAZsuj JOtiOfTkpFnkmsPS7OiM3mBJnkT80a7v213Xe7wu+4aUVOThs3JrW3pfL8AkZF0cTrMs 5OXRQR9CsPzLTyUNUt34qRaHcZ0nTzn+OUYzKW0Ofx5seoQXcw0wWA+CPXobHIQ+oxo2 as5VJF+OcUPIAC9FhKKPuJCq8RvKY1BOzntx8lNJFYitpUWmuBhQwD8xIJK2xEaIPDYZ ygwkYeu11IvOXjaZ5Doc3p0LUdDp+sdZ+8rl6GZpAmwI7u2yh7Ytz0zgiZGoy9Or+Wnb Ooag== 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=xiyxJQtngIitM6NvDkSmtJp7dkYh2m7KhsJ3ZxlyPB8=; fh=HIDZXiyhjTd0NmLJTac/xtwLzCjcnxL1q7LuuiFTJOk=; b=id33gi+nGM7B2pD8UKKwWgysNXZnZn0c56Hrev1MsCSzcgoURSCe1GYkFUN64pCsqb NZXL3e/3JiXqRE6X4L+aCPwTI+MvWEkk8vbb30VdyBxOsBhCalYaUzNiBwVVPF2QJrd/ 9QG/waVwT9BKQswpPbcg+7e4c7OcXWt7k9qH/DZW73dOumWgASeRskzP5IfLhHfAEc4j +t9N2NlTJFkpUr3SLD0mClrWM5sDczkILdPwcVUxro1nSLQYHLN0aUC6mHOJRKRVaeuB LJph2q/DqC0q2EN6gtKvOpuIJvA41myAxEGwY6gWpsn9Z7jZBSW6F/W46xcbxXRv0hHI F0Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pHxhaa21; 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 m9-20020a654389000000b0056381977278si11650267pgp.667.2023.07.26.08.55.34; Wed, 26 Jul 2023 08:55: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=pHxhaa21; 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 S234244AbjGZPWq (ORCPT + 99 others); Wed, 26 Jul 2023 11:22:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233905AbjGZPWm (ORCPT ); Wed, 26 Jul 2023 11:22:42 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 789CD19B5 for ; Wed, 26 Jul 2023 08:22:40 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-3176a439606so2063054f8f.3 for ; Wed, 26 Jul 2023 08:22:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690384959; x=1690989759; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xiyxJQtngIitM6NvDkSmtJp7dkYh2m7KhsJ3ZxlyPB8=; b=pHxhaa21ySaf/Q0o5VjvoZfUVtqSmxNF4ePZCZmuGxVj0og38x9F6VbWo41eaRBbqt JcXRT9vpP/Rd6UNAFG1iq6Fdqa+L4N/0n2uSyPAlu0rJnQZFkFwR9HF5rg6xrC+YxMs9 jUBQa5ZCVQUwECT6kyV37bwh0EexSgz2SmcLdu8TwLep1qhqafMXz9pmipYc8Pt3p8yy FbM/3ESOxbO3X0jM2FeYcvpj+JHMjZAPxPLghDQlkP164edn2HqasQrz3WW/DSlmAhmf TN5eMZKmHpYfkC6/1GMDu0c0mZVPw1Vg2pFb89aTmbo3nXmrIdjt0ct7jigRI+eS6pkG kHiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690384959; x=1690989759; 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=xiyxJQtngIitM6NvDkSmtJp7dkYh2m7KhsJ3ZxlyPB8=; b=bho+V9Stzffjqi0qpN0TxpJN/Nj9veLFDFCF0itGDV8cDPhqKKvWyL+V+tgzlJENhL v0fIoY1uRZS+g3LGGFFPyvQfeb4uj5GMBUeStgsjUjqzYdC1OH3G5IHDxBKhKmm8wlxA 4l2ykmO30dNeiWv3iaE8qlJaLTC0y9LhdYIbklUjTb9D6VDy6dXfN54EgZanf2hoGwQK sL2sCPwYFHSDmGJIcPilAS3zPnmiJQP+0sPdY5aSYNSaG+7nGNWcSQKNbV1LeJZyFggr ImlZ0FcCfp7GwXG6sxBEc2hOoXLTB3iNwbxEi0GWzQVwNKodyxtHEPuvvKMX6K+1oEWs 8uMw== X-Gm-Message-State: ABy/qLaz09UNO7JbS6bNrFPvKvcgTcxEkqtYV3cgO9j4tyrImORzOt/7 rBgS2N+Sj5t2Z2lei66NMqf72m5NipnPsWJRzcY= X-Received: by 2002:adf:f452:0:b0:317:6623:e33f with SMTP id f18-20020adff452000000b003176623e33fmr1955488wrp.14.1690384958593; Wed, 26 Jul 2023 08:22:38 -0700 (PDT) Received: from loic-ThinkPad-T470p.. ([2a01:e0a:82c:5f0:8c06:4c96:5858:e8ab]) by smtp.gmail.com with ESMTPSA id k8-20020a5d4288000000b003176a4394d7sm6356032wrq.24.2023.07.26.08.22.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 08:22:38 -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, Loic Poulain Subject: [PATCH v2] init: Add support for rootwait timeout parameter Date: Wed, 26 Jul 2023 17:22:32 +0200 Message-Id: <20230726152232.932288-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,T_SCC_BODY_TEXT_LINE,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772499184872688645 X-GMAIL-MSGID: 1772499184872688645 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 .../admin-guide/kernel-parameters.txt | 4 ++++ init/do_mounts.c | 19 +++++++++++++++++-- 2 files changed, 21 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..118f2bbe7b38 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -71,12 +72,20 @@ 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) +{ + root_wait = simple_strtoul(str, NULL, 0); + return 1; +} + +__setup("rootwait=", rootwait_timeout_setup); + static char * __initdata root_mount_data; static int __init root_data_setup(char *str) { @@ -384,14 +393,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(); }