Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5016855rwb; Mon, 31 Jul 2023 16:50:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlGg2BX0RvJgxazPJ8bdp+EPmt7Yo4bGaIWO9qJu7JeKUhBZPAmHoJO1aesxwQZiPIlcU6G2 X-Received: by 2002:a17:906:3281:b0:993:f90b:e549 with SMTP id 1-20020a170906328100b00993f90be549mr904717ejw.37.1690847438676; Mon, 31 Jul 2023 16:50:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690847438; cv=none; d=google.com; s=arc-20160816; b=jJrXpVSsZUx17c5CdPqEliPt2GyQH8fGj/btuQuUy7M+MbVjQG7JXLQJU4PgHZ1W0w 8gxOpDU7tEGp38NIwNHC13fKsgKL4BzNjGBuq/xd90GL0zkhCddYh5zJ1Rw/dbdUUjrH Oj+PsZ1mNB0qop53G0ANKTeh+XJYA1TrNAJ54OaOjYPbbalogU4wpU1b6FewJ+9LWxvI EpVHQ8H4fOHy3gYk9wnINvn74j0NhB3XDXGDLrmY2mhhrWWx5CMoCOyRbxFM3EmLbNDJ KaId4jpqwGh/USsXCwj4/QwDD96Lebm3rNsbElEPOfjnbWMe4Skt5iY3WO8LStw7JFOt TFaw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dVMT2ijxWluKHx67l2A4C2YfRFWvzAmQJ/fWaFEzZyI=; fh=AkK3OhFYrntX3nM7XONux9RIBji9qN4PtFg2wcvi8k8=; b=V+Yfvpjx0COW9fCpEcPJhCnykL4ZShrZQMSmhS/j26VDlbshg0cI+08iLSaE71k6kq ejCVYrT6EHiuXQsCxBLBMvP17QomLmm1n5a/p4oG0fPQ25uxlCpEE5L5PCongNokAWfS KMLxVbyBxEgfvtEVToNSKZrI6Y1CyqyV5hslzsHIOwXN/EkqmIb+fpVkI9icDmoVvbQW iz5SjEDtdx+ZrqxXiKqsc2YttTnJa/MW90QpFMclBUriE1NooCQsbfBmKGqIqKyiUy7L JEfK+cj3vxTlHPlsby1fNSCQTU2p2DH9SZMZ9BRrjy9czYV1J3AnDRAp1yrq3mGvGSxD qIiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QLJjIaah; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b2-20020a1709065e4200b0099bd0461710si7063306eju.482.2023.07.31.16.50.14; Mon, 31 Jul 2023 16:50:38 -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=@kernel.org header.s=k20201202 header.b=QLJjIaah; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231322AbjGaXbq (ORCPT + 99 others); Mon, 31 Jul 2023 19:31:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230154AbjGaXbf (ORCPT ); Mon, 31 Jul 2023 19:31:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67C7DB0; Mon, 31 Jul 2023 16:31:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ED6CD61344; Mon, 31 Jul 2023 23:31:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B9CBC433C8; Mon, 31 Jul 2023 23:31:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690846292; bh=oBlm+F0ijC5y9fHYb2ho/VBeeyMvwj2PDTDIl0glh0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QLJjIaah3/akgIa59dh1oK+umdaeOkJa7PujX/sI4ogfjwWtneSQt8NYmf2LiITM1 tQ+Y3GPbMMKGw4odgc/2a9Ikw2j0fvzKhbYSIzGAvu9ecI6tQSB0n6XnxTRC5T7/iB v5PJrDo/8ZtGZGr64a+vulEx0oSH1nLnMtwC6PUQlP3CYYqa0yCe1FJ892NTUsCfod 8k//LrxEdlfLTDR078y69GN1kwj002Ol2TaUPj/HKH7tIG4fqcY6GIVgwZ7+zpo2fD CIgbi0YcxHint6U3kVnSZEuOKfQy/TvAv7yiO8x/vj13c2gCaRux+Nr5gQ4lcy+fai I3nLu02nMS5mw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id DC2CBCE1066; Mon, 31 Jul 2023 16:31:31 -0700 (PDT) From: "Paul E. McKenney" To: akpm@linux-foundation.org, adobriyan@gmail.com, mhiramat@kernel.org Cc: arnd@kernel.org, ndesaulniers@google.com, paulmck@kernel.org, sfr@canb.auug.org.au, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [PATCH RFC v2 bootconfig 2/3] fs/proc: Add /proc/cmdline_load for boot loader arguments Date: Mon, 31 Jul 2023 16:31:29 -0700 Message-Id: <20230731233130.424913-2-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 In kernels built with CONFIG_BOOT_CONFIG_FORCE=y, /proc/cmdline will show all kernel boot parameters, both those supplied by the boot loader and those embedded in the kernel image. This works well for those who just want to see all of the kernel boot parameters, but is not helpful to those who need to see only those parameters supplied by the boot loader. This is especially important when these parameters are presented to the boot loader by automation that might gather them from diverse sources. It is also useful when booting the next kernel via kexec(), in which case it is necessary to supply only those kernel command-line arguments from the boot loader, and most definitely not those that were embedded into the current kernel. Therefore, provide a /proc/cmdline_load file that shows only those kernel boot parameters supplied by the boot loader. Why put this in /proc? Because it is quite similar to /proc/cmdline, so it makes sense to put it in the same place that /proc/cmdline is located. [ sfr: Apply kernel test robot feedback. ] [ paulmck: Apply Randy Dunlap feedback. ] Co-developed-by: Stephen Rothwell Signed-off-by: Stephen Rothwell Co-developed-by: Arnd Bergmann Signed-off-by: Arnd Bergmann Signed-off-by: Paul E. McKenney Reviewed-by: Nick Desaulniers Acked-by: Masami Hiramatsu (Google) Cc: Andrew Morton Cc: Alexey Dobriyan Cc: --- Documentation/filesystems/proc.rst | 1 + fs/proc/cmdline.c | 13 +++++++++++++ include/linux/init.h | 3 ++- init/main.c | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index 75a8c899ebcc..c2aee55248a8 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -688,6 +688,7 @@ files are there, and which are missing. bus Directory containing bus specific information cmdline Kernel command line, both from bootloader and embedded in the kernel image. + cmdline_load Kernel command line obtained from kernel image (6.6) cpuinfo Info about the CPU devices Available devices (block and character) dma Used DMS channels diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c index a6f76121955f..1d0ef9d2949d 100644 --- a/fs/proc/cmdline.c +++ b/fs/proc/cmdline.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "internal.h" static int cmdline_proc_show(struct seq_file *m, void *v) @@ -12,6 +13,13 @@ static int cmdline_proc_show(struct seq_file *m, void *v) return 0; } +static int cmdline_load_proc_show(struct seq_file *m, void *v) +{ + seq_puts(m, boot_command_line); + seq_putc(m, '\n'); + return 0; +} + static int __init proc_cmdline_init(void) { struct proc_dir_entry *pde; @@ -19,6 +27,11 @@ static int __init proc_cmdline_init(void) pde = proc_create_single("cmdline", 0, NULL, cmdline_proc_show); pde_make_permanent(pde); pde->size = saved_command_line_len + 1; + if (IS_ENABLED(CONFIG_BOOT_CONFIG_FORCE)) { + pde = proc_create_single("cmdline_load", 0, NULL, cmdline_load_proc_show); + pde_make_permanent(pde); + pde->size = strnlen(boot_command_line, COMMAND_LINE_SIZE) + 1; + } return 0; } fs_initcall(proc_cmdline_init); diff --git a/include/linux/init.h b/include/linux/init.h index 266c3e1640d4..29e75bbe7984 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -112,6 +112,7 @@ #define __REFCONST .section ".ref.rodata", "a" #ifndef __ASSEMBLY__ + /* * Used for initialization calls.. */ @@ -143,7 +144,7 @@ struct file_system_type; /* Defined in init/main.c */ extern int do_one_initcall(initcall_t fn); -extern char __initdata boot_command_line[]; +extern char boot_command_line[]; extern char *saved_command_line; extern unsigned int saved_command_line_len; extern unsigned int reset_devices; diff --git a/init/main.c b/init/main.c index ad920fac325c..2121685c479a 100644 --- a/init/main.c +++ b/init/main.c @@ -135,7 +135,7 @@ EXPORT_SYMBOL(system_state); void (*__initdata late_time_init)(void); /* Untouched command line saved by arch-specific code. */ -char __initdata boot_command_line[COMMAND_LINE_SIZE]; +char boot_command_line[COMMAND_LINE_SIZE] __ro_after_init; /* Untouched saved command line (eg. for /proc) */ char *saved_command_line __ro_after_init; unsigned int saved_command_line_len __ro_after_init; -- 2.40.1