Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp871524ybl; Fri, 10 Jan 2020 08:06:55 -0800 (PST) X-Google-Smtp-Source: APXvYqy3nE9GCk7arBmBhlHs5ofV3MNJL4qyMfNSy3KTc0KXowf30XGz8ygpXkdRGhZ+Sk2ye21A X-Received: by 2002:aca:4d4f:: with SMTP id a76mr2857237oib.26.1578672415796; Fri, 10 Jan 2020 08:06:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578672415; cv=none; d=google.com; s=arc-20160816; b=mRLDgPL+SuMYI/8XdvHVyrVZ4F6uhu5aTrAl8VVmzYdLOfJJv+JfC4Hy1RT+D4SgxC 8nfnSvqQQF5JqLtX36FqyD0gQV9qeZb25z+4TGAM3DUYtQwA1juCynU9FIPscQQDJ0GN lrXc8WXmlW8CmXfVLaU8uxW4gyMHZb41MGvrdv18QAbRU/OPtloq4vQRxbpCRVkhD2hg h2HDziTW5ZjRmhTQDETDwRIJQ5dPHi6QjrBUksUhl3HhI/ekD9KxrsDzkZlzRBw8Q556 ed31wsiyZ3xUkfPGFsMlrYCSWZg3/rZ8n88QnYJjhkfCO/gvD1LczHmyBlBva3T9HqME cuQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cJ6zAb+MTR0vtU+1xVnxSEXnrY/eQs9W0iEUThxhQ1s=; b=xvOP4bqHtJL2i2yE7cke1uiOfxRO0DuZqOTNifv6KqWGyhYvC3OMSP6XAlcVxMTFN/ chNi4NaoCx9bpVyoqoiWm/JxssNund7mCDo0dB3g8yD4/HXLw+R//OiXJaj7HZ6U5dxn brqlsST6uH1ikWkPWqZH4O389FZDArAg9i6sFMxAR9vimpd5rZmFmRvo0AVwIMEGEvgQ 2yz3ldwvWcAhNLfPYc4sTTX/Np5I27YGZEI2Hl4IT+1hOphTMgFTgYCMqd8nY3eunX28 lWa6jdSYK0YFB0ZNyAvQ/FT1qVBnL5pH2uXA1uBm5pdlCeseKa4hrPILEl089i3mXEsJ kYzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Tm4YirPp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r4si1574578otq.188.2020.01.10.08.06.37; Fri, 10 Jan 2020 08:06:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Tm4YirPp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728746AbgAJQFD (ORCPT + 99 others); Fri, 10 Jan 2020 11:05:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:53350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728480AbgAJQFC (ORCPT ); Fri, 10 Jan 2020 11:05:02 -0500 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A197921744; Fri, 10 Jan 2020 16:04:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578672301; bh=nJeju4Tk+OsPhG56SdDEOENLWLwKqszJfvAVxMqqJIU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tm4YirPpLf6vykani18lUfMmshBZVUnvYc1BthQjXk98pFH+9QPxfr2q7RRbphUV5 R/vBdFgvoBnbeLaXutdWcVv2ml0ur/8UW9D+PlwX6B5Ojf17cEMTJ/aFzNNTjjRMk5 wP+pgtqjTalhN1LdhogCIeHNj8vCy6qh1BSD7EH0= From: Masami Hiramatsu To: Steven Rostedt Cc: Ingo Molnar , Frank Rowand , Randy Dunlap , Namhyung Kim , Tim Bird , Jiri Olsa , Arnaldo Carvalho de Melo , Tom Zanussi , Rob Herring , Andrew Morton , Thomas Gleixner , Greg Kroah-Hartman , Alexey Dobriyan , Jonathan Corbet , Linus Torvalds , linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 08/22] bootconfig: init: Allow admin to use bootconfig for init command line Date: Sat, 11 Jan 2020 01:04:55 +0900 Message-Id: <157867229521.17873.654222294326542349.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <157867220019.17873.13377985653744804396.stgit@devnote2> References: <157867220019.17873.13377985653744804396.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since the current kernel command line is too short to describe long and many options for init (e.g. systemd command line options), this allows admin to use boot config for init command line. All init command line under "init." keywords will be passed to init. For example, init.systemd { unified_cgroup_hierarchy = 1 debug_shell default_timeout_start_sec = 60 } Signed-off-by: Masami Hiramatsu --- init/main.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/init/main.c b/init/main.c index c0017d9d16e7..dd7da62d99a5 100644 --- a/init/main.c +++ b/init/main.c @@ -139,6 +139,8 @@ char *saved_command_line; static char *static_command_line; /* Untouched extra command line */ static char *extra_command_line; +/* Extra init arguments */ +static char *extra_init_args; static char *execute_command; static char *ramdisk_execute_command; @@ -372,6 +374,8 @@ static void __init setup_boot_config(void) pr_info("Load boot config: %d bytes\n", size); /* keys starting with "kernel." are passed via cmdline */ extra_command_line = xbc_make_cmdline("kernel"); + /* Also, "init." keys are init arguments */ + extra_init_args = xbc_make_cmdline("init"); } } #else @@ -507,16 +511,18 @@ static inline void smp_prepare_cpus(unsigned int maxcpus) { } */ static void __init setup_command_line(char *command_line) { - size_t len, xlen = 0; + size_t len, xlen = 0, ilen = 0; if (extra_command_line) xlen = strlen(extra_command_line); + if (extra_init_args) + ilen = strlen(extra_init_args) + 4; /* for " -- " */ len = xlen + strlen(boot_command_line) + 1; - saved_command_line = memblock_alloc(len, SMP_CACHE_BYTES); + saved_command_line = memblock_alloc(len + ilen, SMP_CACHE_BYTES); if (!saved_command_line) - panic("%s: Failed to allocate %zu bytes\n", __func__, len); + panic("%s: Failed to allocate %zu bytes\n", __func__, len + ilen); static_command_line = memblock_alloc(len, SMP_CACHE_BYTES); if (!static_command_line) @@ -533,6 +539,22 @@ static void __init setup_command_line(char *command_line) } strcpy(saved_command_line + xlen, boot_command_line); strcpy(static_command_line + xlen, command_line); + + if (ilen) { + /* + * Append supplemental init boot args to saved_command_line + * so that user can check what command line options passed + * to init. + */ + len = strlen(saved_command_line); + if (!strstr(boot_command_line, " -- ")) { + strcpy(saved_command_line + len, " -- "); + len += 4; + } else + saved_command_line[len++] = ' '; + + strcpy(saved_command_line + len, extra_init_args); + } } /* @@ -759,6 +781,9 @@ asmlinkage __visible void __init start_kernel(void) if (!IS_ERR_OR_NULL(after_dashes)) parse_args("Setting init args", after_dashes, NULL, 0, -1, -1, NULL, set_init_arg); + if (extra_init_args) + parse_args("Setting extra init args", extra_init_args, + NULL, 0, -1, -1, NULL, set_init_arg); /* * These use large bootmem allocations and must precede