From patchwork Wed Sep 13 23:51:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Landley X-Patchwork-Id: 813668 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xsz4j0q70z9s81 for ; Thu, 14 Sep 2017 09:53:09 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=landley-net.20150623.gappssmtp.com header.i=@landley-net.20150623.gappssmtp.com header.b="hjSi+apB"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xsz4h6nXLzDrHr for ; Thu, 14 Sep 2017 09:53:08 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=landley-net.20150623.gappssmtp.com header.i=@landley-net.20150623.gappssmtp.com header.b="hjSi+apB"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=landley.net (client-ip=2607:f8b0:400d:c0d::242; helo=mail-qt0-x242.google.com; envelope-from=rob@landley.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=landley-net.20150623.gappssmtp.com header.i=@landley-net.20150623.gappssmtp.com header.b="hjSi+apB"; dkim-atps=neutral Received: from mail-qt0-x242.google.com (mail-qt0-x242.google.com [IPv6:2607:f8b0:400d:c0d::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3xsz2t1Q0LzDqjK for ; Thu, 14 Sep 2017 09:51:33 +1000 (AEST) Received: by mail-qt0-x242.google.com with SMTP id q8so1060267qtb.1 for ; Wed, 13 Sep 2017 16:51:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=landley-net.20150623.gappssmtp.com; s=20150623; h=to:cc:references:from:subject:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=sgiatQGf2QF/QOUexQsGyItzQPpolb+WTzFT+waHLnk=; b=hjSi+apBY44mlS8PcX2UlaH72WY0vFmWjWqayhe1hIa48K0NZxDZZb7aKtYhu/Gv2A lvqXgvN/4XUqqkPsPuPsQAZMTbZlMG1tGlzGGcAct3iM3tuQGDrZpTku2udczZj6hYjD gZ8q5AKZg0Dhk2c8GS20qqbWLWx/k15dRkLe1N0bw1JFEbMkKbiVf0ptPvrHqqoTqtHO tUMTH6SMPJkRrQeUZBq5t/wUR80/eohZZL0FJ8gTDENshe07tMzOLLxSC9M9TjOwdfXi HSnjHCm+AS+UmV1VyRCpmkIY6XRKKKRkxI23Ff/cxGYxFnBNsZVX/zq1xDuBRMCcua+l U2Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=sgiatQGf2QF/QOUexQsGyItzQPpolb+WTzFT+waHLnk=; b=D8WK2R1oV38EoIchfGhRBviIxUh4Tz2VVbisTNWsRK5wEAA768v7RvG1sNpX3vHsBn PGYeGQfLmgYBnsR+U8HNPF7ameRBi5ZLFizNvGHgOpmNElDKYtOLHhc39d+LiY+5/AAy taEAZnG4TY7SZZaX+VM9nxgDG+eOXY+7ZNY0LjAUeVRpYZKnq70R7gWZaIqqsDuPv9TU gchFvvWK6QDbfXWDb2yd/Y8iSDw71TVxiJPqV+tia0x4DSiC4ghy7QUxaGLe34LRDEDL 3fPqV6UUytL66/fYBWYAfDMOW0AcX7neb8oPMGIX3TH9chzdnwO7cxPZynf6KJAJVWiM mZGg== X-Gm-Message-State: AHPjjUgbpqOqLZAb9YzkYlGOfdhPl2Ft6h6B3GRVaLgCqUNNUdTUWR1k M0WcvfScYo72L2ef X-Google-Smtp-Source: AOwi7QAMx+znzEfXXdZqMCa5wjDg6xsdrhzAkS1cIDLec9WuvLFR4sVPx6UZc+s3xZ5UGjtyw0IGhQ== X-Received: by 10.237.53.23 with SMTP id a23mr31108841qte.125.1505346690657; Wed, 13 Sep 2017 16:51:30 -0700 (PDT) Received: from [192.168.43.158] ([172.58.99.214]) by smtp.googlemail.com with ESMTPSA id d205sm10267038qke.56.2017.09.13.16.51.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Sep 2017 16:51:29 -0700 (PDT) To: Michael Ellerman , Stephen Rothwell References: <1495700957.9020.43.camel@abdul.in.ibm.com> <8760gp9jjl.fsf@concordia.ellerman.id.au> <20170526072437.46499fbd@canb.auug.org.au> <87a7e82d-0af5-7f9e-6bd6-7e28b238e866@landley.net> <87r2z86ykt.fsf@concordia.ellerman.id.au> From: Rob Landley Subject: [PATCH v3] Make initramfs honor CONFIG_DEVTMPFS_MOUNT Message-ID: <4aa9cb26-f868-0720-e5c8-3c4e08afad20@landley.net> Date: Wed, 13 Sep 2017 18:51:25 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <87r2z86ykt.fsf@concordia.ellerman.id.au> Content-Language: en-US X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sachinp , mhocko@suse.com, peterz@infradead.org, viresh.kumar@linaro.org, Benjamin Tissoires , mingo@kernel.org, lokeshvutla@ti.com, Abdul Haleem , linux-input@vger.kernel.org, thomas.lendacky@amd.com, lauraa@codeaurora.org, keescook@chromium.org, Jiri Kosina , rostedt@goodmis.org, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, tglx@linutronix.de, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, tj@kernel.org, Andrew Morton , linuxppc-dev Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Rob Landley Make initramfs honor CONFIG_DEVTMPFS_MOUNT, and move /dev/console open after devtmpfs mount. Add workaround for Debian bug that was copied by Ubuntu. Signed-off-by: Rob Landley --- v2 discussion: http://lkml.iu.edu/hypermail/linux/kernel/1705.2/05611.html drivers/base/Kconfig | 14 ++++---------- fs/namespace.c | 14 ++++++++++++++ init/main.c | 15 +++++++++------ 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig index f046d21..97352d4 100644 --- a/drivers/base/Kconfig +++ b/drivers/base/Kconfig @@ -48,16 +48,10 @@ config DEVTMPFS_MOUNT bool "Automount devtmpfs at /dev, after the kernel mounted the rootfs" depends on DEVTMPFS help - This will instruct the kernel to automatically mount the - devtmpfs filesystem at /dev, directly after the kernel has - mounted the root filesystem. The behavior can be overridden - with the commandline parameter: devtmpfs.mount=0|1. - This option does not affect initramfs based booting, here - the devtmpfs filesystem always needs to be mounted manually - after the rootfs is mounted. - With this option enabled, it allows to bring up a system in - rescue mode with init=/bin/sh, even when the /dev directory - on the rootfs is completely empty. + Automatically mount devtmpfs at /dev on the root filesystem, which + lets the system to come up in rescue mode with [rd]init=/bin/sh. + Override with devtmpfs.mount=0 on the commandline. Initramfs can + create a /dev dir as needed, other rootfs needs the mount point. config STANDALONE bool "Select only drivers that don't need compile-time external firmware" diff --git a/fs/namespace.c b/fs/namespace.c index f8893dc..06057d7 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2417,7 +2417,21 @@ static int do_add_mount(struct mount *newmnt, struct path *path, int mnt_flags) err = -EBUSY; if (path->mnt->mnt_sb == newmnt->mnt.mnt_sb && path->mnt->mnt_root == path->dentry) + { + if (IS_ENABLED(CONFIG_DEVTMPFS_MOUNT) && + !strcmp(path->mnt->mnt_sb->s_type->name, "devtmpfs")) + { + /* Debian's kernel config enables DEVTMPFS_MOUNT, then + its initramfs setup script tries to mount devtmpfs + again, and if the second mount-over-itself fails + the script overmounts a tmpfs on /dev to hide the + existing contents, then boot fails with empty /dev. */ + printk(KERN_WARNING "Debian bug workaround for devtmpfs overmount."); + + err = 0; + } goto unlock; + } err = -EINVAL; if (d_is_symlink(newmnt->mnt.mnt_root)) diff --git a/init/main.c b/init/main.c index 0ee9c686..0d8e5ec 100644 --- a/init/main.c +++ b/init/main.c @@ -1065,12 +1065,6 @@ static noinline void __init kernel_init_freeable(void) do_basic_setup(); - /* Open the /dev/console on the rootfs, this should never fail */ - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) - pr_err("Warning: unable to open an initial console.\n"); - - (void) sys_dup(0); - (void) sys_dup(0); /* * check if there is an early userspace init. If yes, let it do all * the work @@ -1082,8 +1076,17 @@ static noinline void __init kernel_init_freeable(void) if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) { ramdisk_execute_command = NULL; prepare_namespace(); + } else if (IS_ENABLED(CONFIG_DEVTMPFS_MOUNT)) { + sys_mkdir("/dev", 0755); + devtmpfs_mount("/dev"); } + /* Open the /dev/console on the rootfs, this should never fail */ + if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) + pr_err("Warning: unable to open an initial console.\n"); + (void) sys_dup(0); + (void) sys_dup(0); + /* * Ok, we have completed the initial bootup, and * we're essentially up and running. Get rid of the