Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp731502rwb; Thu, 27 Jul 2023 21:45:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlEKmMkTYOD0BzQ9IEnxD2OOIf0XP2uihvwuLcAxr9RvJ4qGuVK/u49fdFj50+8Fzz/6o5NG X-Received: by 2002:a2e:87d4:0:b0:2b5:80e0:f18e with SMTP id v20-20020a2e87d4000000b002b580e0f18emr773091ljj.3.1690519543688; Thu, 27 Jul 2023 21:45:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690519543; cv=none; d=google.com; s=arc-20160816; b=GMaYlDuUClshlwlTip9xLGJz6DfvzhyIu9zfEpBv0QKJfwOp2e4peCXy/T3Ia3r41Y +72sUMmrJkhovt6d74udyWm954irXpN1vUAuLYyjMtJBowPQQGkBuzi7NLTBejb5p/T3 iMaLYVO9Tcg3qICCrP26aPtOv7Vm2ROTpWTK+Pe3Dp4i/TCRX3wz+wS/WyIsq86QuS8A K0YF/pk9n7m7FO9jDBOkh9gmyB6RGfuHw4BbVmPtPm2r1eidg/RFMPKP8GCwToWM1kLn VkRyPtav+FrZCDEb9sNK5p2qXWZXyVEX4yDEjTHLMOYNemFdOyD4HcHZv5ZPcK81+10M 00yA== 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=+4UUdaPWBFfKtztfHDrqFAKTs/9//dZOzk3251vEiGo=; fh=AkK3OhFYrntX3nM7XONux9RIBji9qN4PtFg2wcvi8k8=; b=JBP0f9uqka9pR5wqkysp05WC9K068EXdlQIlI3BmmCrszlwZJAdQ8za63jHp/LGToq iDFFeODRaQyQO9/GmicI9Sey1U9W8IClctLTnhTSG+v4lPrC7yjNjAxzyULSnEai9vQb vJhC3GvpeZllD09o2J1Wt++LmCzpK7USILobB1DkcDjaEv8hJmIJUOXLmfpZaqVppTvM uQ8Sz+pvRfhSXQBeI9+v3aftK8ADIZEuBWCZBf/0Hm2zFXK+B2e9d2OLCAm65Hf5idi7 C9W7+Kz7Fk3lpY2oG4ABYgTsasTcFE7wA7f84a6qNshX7IzDiFUvNcc7M2QdtqlOYB8z YcdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JnDMASVV; 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 v11-20020aa7dbcb000000b005227d29788csi1920064edt.352.2023.07.27.21.45.19; Thu, 27 Jul 2023 21:45:43 -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=JnDMASVV; 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 S233192AbjG1DhL (ORCPT + 99 others); Thu, 27 Jul 2023 23:37:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233168AbjG1DhG (ORCPT ); Thu, 27 Jul 2023 23:37:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 188222D54; Thu, 27 Jul 2023 20:37:04 -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 9BD8C61F71; Fri, 28 Jul 2023 03:37:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEDF5C433C8; Fri, 28 Jul 2023 03:37:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690515423; bh=CKy8nc2se/qVw6CL5KyA7b+klhxeNbXYszAes8MV3fU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JnDMASVVExqHsoZ/eDZPVcK83cOGguCZ6ebknWUvkE480wI3iqMhOLZMGSyDeLFc8 YvkNyZ9+1kn3XSDI2NNSMR8kwhNvl8NgwucKiFDis4FPWcBai1rQLR5U15uxCP8jG+ CM8OIhxm+LGeIyHYgKiVtNw6zeDLT5AOc6lkn1wfU1sAMSB3jp3o4BgL6G4Wuz634d CEBObpQKS1RF2jWmN/r6M71gqtRJL3J8iUIy0Xt5eFcLoAXyjBUCUNx+RzAuToq1vE khOvQDVaMnHibgnAG1ZazDQQp3kWECQi23IRktU30AXaYO6ZEsC+vE15l6qjEDa8lm 810cbulZExkWw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 8A0EFCE0069; Thu, 27 Jul 2023 20:37:02 -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 bootconfig] 2/2] fs/proc: Add /proc/cmdline_image for embedded arguments Date: Thu, 27 Jul 2023 20:37:01 -0700 Message-Id: <20230728033701.817094-2-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <197cba95-3989-4d2f-a9f1-8b192ad08c49@paulmck-laptop> References: <197cba95-3989-4d2f-a9f1-8b192ad08c49@paulmck-laptop> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 that were embedded into the kernel image. This is especially important in situations where there are many kernel images for different kernel versions and kernel configurations, all of which opens the door to a great deal of human error. Therefore, provide a /proc/cmdline_image file that shows only those kernel boot parameters that were embedded in the kernel image. The output is in boot-image format, which allows easy reconcilation against the boot-config source file. 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. Signed-off-by: Paul E. McKenney Cc: Andrew Morton Cc: Alexey Dobriyan Cc: Masami Hiramatsu Cc: Signed-off-by: Paul E. McKenney --- fs/proc/cmdline.c | 12 ++++++++++++ include/linux/init.h | 11 ++++++----- init/main.c | 9 +++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c index 1d0ef9d2949d..4ab5223198cb 100644 --- a/fs/proc/cmdline.c +++ b/fs/proc/cmdline.c @@ -20,6 +20,15 @@ static int cmdline_load_proc_show(struct seq_file *m, void *v) return 0; } +static int cmdline_image_proc_show(struct seq_file *m, void *v) +{ +#ifdef CONFIG_BOOT_CONFIG_FORCE + seq_puts(m, saved_bootconfig_string); + seq_putc(m, '\n'); +#endif + return 0; +} + static int __init proc_cmdline_init(void) { struct proc_dir_entry *pde; @@ -31,6 +40,9 @@ static int __init proc_cmdline_init(void) 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; + pde = proc_create_single("cmdline_image", 0, NULL, cmdline_image_proc_show); + pde_make_permanent(pde); + pde->size = strnlen(saved_bootconfig_string, COMMAND_LINE_SIZE) + 1; } return 0; } diff --git a/include/linux/init.h b/include/linux/init.h index 29e75bbe7984..c075983c5015 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -14,7 +14,7 @@ #define __noinitretpoline #endif -/* These macros are used to mark some functions or +/* These macros are used to mark some functions or * initialized data (doesn't apply to uninitialized data) * as `initialization' functions. The kernel can take this * as hint that the function is used only during the initialization @@ -22,7 +22,7 @@ * * Usage: * For functions: - * + * * You should add __init immediately before the function name, like: * * static void __init initme(int x, int y) @@ -148,6 +148,7 @@ extern char boot_command_line[]; extern char *saved_command_line; extern unsigned int saved_command_line_len; extern unsigned int reset_devices; +extern char saved_bootconfig_string[]; /* used by init/main.c */ void setup_arch(char **); @@ -184,7 +185,7 @@ extern void (*late_time_init)(void); extern bool initcall_debug; #endif - + #ifndef MODULE #ifndef __ASSEMBLY__ @@ -192,8 +193,8 @@ extern bool initcall_debug; /* * initcalls are now grouped by functionality into separate * subsections. Ordering inside the subsections is determined - * by link order. - * For backwards compatibility, initcall() puts the call in + * by link order. + * For backwards compatibility, initcall() puts the call in * the device init subsection. * * The `id' arg to __define_initcall() is needed so that multiple initcalls diff --git a/init/main.c b/init/main.c index 2121685c479a..981170da0b1c 100644 --- a/init/main.c +++ b/init/main.c @@ -146,6 +146,11 @@ static char *extra_command_line; /* Extra init arguments */ static char *extra_init_args; +/* Untouched boot-config string */ +#ifdef CONFIG_BOOT_CONFIG_FORCE +char saved_bootconfig_string[COMMAND_LINE_SIZE] __ro_after_init; +#endif + #ifdef CONFIG_BOOT_CONFIG /* Is bootconfig on command line? */ static bool bootconfig_found; @@ -435,6 +440,10 @@ static void __init setup_boot_config(void) return; } +#ifdef CONFIG_BOOT_CONFIG_FORCE + strncpy(saved_bootconfig_string, data, COMMAND_LINE_SIZE); +#endif + if (size >= XBC_DATA_MAX) { pr_err("bootconfig size %ld greater than max size %d\n", (long)size, XBC_DATA_MAX); -- 2.40.1