Message ID | 20230726143348.724611-1-arnd@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp481665vqo; Wed, 26 Jul 2023 08:30:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlGX2ZXdoHDF03WMmPA2Ub7B5A9Oy99gLm4DVMlBO+lyIQSv5/JVc+myl+unpMpmV/dM+QvE X-Received: by 2002:aa7:d68b:0:b0:51e:d4b:3c9d with SMTP id d11-20020aa7d68b000000b0051e0d4b3c9dmr1721783edr.23.1690385436578; Wed, 26 Jul 2023 08:30:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690385436; cv=none; d=google.com; s=arc-20160816; b=QyMqA7Bdt2grcR/vIEJNVDv3p7E6p0GNrC1MOro9NPrjK0l5+OmfPFYWkEujvnQ8Z/ 6akayfEeYK0IK3rtqGy4nalKCQXKMbk3h1ack1zAgmuQlvQhS6SBXAaFmgK3qW3YWuda kEYO4MQyqrFO9llsgPhqBuhybiU//B9GozcEH1RLQDK1iviXi6Iw/mTfqMG90ndndasM kyC4FUgh9jZtukveMwgUaMOkaJALLsg21fIJYHPlpGNsLOtUR/L+fjKY19DFnxCBIkUq MlDznUV8vi5EgxKDAAApRXXdhHvz+FdgOHVNn27hzc2SLtFiCenMo2ZJHjMm4AK+NdRB NmAQ== 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=4mFK5qoCXP9JtDYRNk3t77ifXx6ru5b/iK3u6uj1NnM=; fh=jCNCnJb0vlgJBLq6EchMHK/bvLCunFFX9uU7RF+wh9Y=; b=KsV59bxeA9IqqQNNp0B6aRi7Xz27zbzo3vYE8bmIzPXYUtn/9Vz4W4VSiY+TOGjab0 c00rlOq8+0JmLybSb6cNy7jcq0WtYYYn4xysjqXzjXaJiTQ34YwCbJkmHATiRUTVqUKW kqtsXrjJYBupgjYMCm/EL+ub7L7uVSFkFhY8s1NmIzu0Kzq5LYC07ZPwO5jZlBqFSrP5 VD1rUpE1wKOVDXI6fcH3cOaTt3WsWvczf9zkjbvuksQNYFDmX+JwQxzl9wnfDwkpCraR oqoMbPEN/fMhCZg8Utgd30TF6sVgMt3FJ1E15S7UKwGYfO00Mm5/1qfGmxnwDrg7RqKY +I+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XNg1U7w5; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w22-20020aa7da56000000b005217c6c827dsi10018375eds.231.2023.07.26.08.30.11; Wed, 26 Jul 2023 08:30:36 -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=XNg1U7w5; 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 S234138AbjGZOd7 (ORCPT <rfc822;kloczko.tomasz@gmail.com> + 99 others); Wed, 26 Jul 2023 10:33:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234050AbjGZOd5 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 26 Jul 2023 10:33:57 -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 71240E78 for <linux-kernel@vger.kernel.org>; Wed, 26 Jul 2023 07:33:56 -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 05F6261AF5 for <linux-kernel@vger.kernel.org>; Wed, 26 Jul 2023 14:33:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03551C433C8; Wed, 26 Jul 2023 14:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690382035; bh=yKI834690DMfFD3Ac39aSv3ombGoauP68gOWLlcu20s=; h=From:To:Cc:Subject:Date:From; b=XNg1U7w5Y5IoEainF926JUZdgDhOH2KC2ks7NYx3Ht3eEWO/YSwA+LWn9s4QJdYs2 nAS/tWayqxr9CUeHMlUYWe44DKWSXL64RbhSvfkmrZkhU9cm7SEWkQ61cF7BqIlRQh k8CTzF/BwopObku3vHmJ6RKqCM/AbSxphYOaVjJt0Fl6xWfnwCZo5Ue3geQYkohWa1 b/KmkF2vY1F+v07WsiBM1/f9EJbSnhthzCqHhAA7snCX4ZYAhrJ9moI+ksQMIC2Zfr 7x2HDxkOEXrkmh39WU4Tq1aNe79vHtNyg9YSNZ3kX3+ZT0FF3+8w5z8IDFVul7Maef 76iDM6Rf6eqiQ== From: Arnd Bergmann <arnd@kernel.org> To: "Paul E. McKenney" <paulmck@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de>, Andrew Morton <akpm@linux-foundation.org>, Kees Cook <keescook@chromium.org>, "Peter Zijlstra (Intel)" <peterz@infradead.org>, Sami Tolvanen <samitolvanen@google.com>, Alexey Dobriyan <adobriyan@gmail.com>, Masahiro Yamada <masahiroy@kernel.org>, Josh Poimboeuf <jpoimboe@kernel.org>, "ndesaulniers@google.com" <ndesaulniers@google.com>, linux-kernel@vger.kernel.org Subject: [PATCH] init: keep boot_command_line after init Date: Wed, 26 Jul 2023 16:33:21 +0200 Message-Id: <20230726143348.724611-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772497599261835006 X-GMAIL-MSGID: 1772497599261835006 |
Series |
init: keep boot_command_line after init
|
|
Commit Message
Arnd Bergmann
July 26, 2023, 2:33 p.m. UTC
From: Arnd Bergmann <arnd@arndb.de> The boot command line is not available after the init section gets discarded, so adding a permanent reference to it causes a link time warning: WARNING: modpost: vmlinux: section mismatch in reference: cmdline_load_proc_show+0x2 (section: .text) -> boot_command_line (section: .init.data) ERROR: modpost: Section mismatches detected. Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them. Change it to __ro_after_init to prevent it from getting freed. Fixes: cf9eca90a3397 ("fs/proc: Add /proc/cmdline_load for boot loader arguments") Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- include/linux/init.h | 2 +- init/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Comments
On Wed, Jul 26, 2023 at 7:33 AM Arnd Bergmann <arnd@kernel.org> wrote: > > From: Arnd Bergmann <arnd@arndb.de> > > The boot command line is not available after the init section gets discarded, > so adding a permanent reference to it causes a link time warning: > > WARNING: modpost: vmlinux: section mismatch in reference: cmdline_load_proc_show+0x2 (section: .text) -> boot_command_line (section: .init.data) cmdline_load_proc_show is probably inlined, but should it also be marked __init? It's lone call site seems to be __init AFAICT. Thanks for the patch! Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> > ERROR: modpost: Section mismatches detected. > Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them. > > Change it to __ro_after_init to prevent it from getting freed. > > Fixes: cf9eca90a3397 ("fs/proc: Add /proc/cmdline_load for boot loader arguments") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > include/linux/init.h | 2 +- > init/main.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/include/linux/init.h b/include/linux/init.h > index 9a5973324072b..4e97a7a29a4d7 100644 > --- a/include/linux/init.h > +++ b/include/linux/init.h > @@ -143,7 +143,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 c946ab87783a1..981170da0b1cd 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.39.2 >
On Wed, Jul 26, 2023, at 18:25, Nick Desaulniers wrote: > On Wed, Jul 26, 2023 at 7:33 AM Arnd Bergmann <arnd@kernel.org> wrote: >> >> From: Arnd Bergmann <arnd@arndb.de> >> >> The boot command line is not available after the init section gets discarded, >> so adding a permanent reference to it causes a link time warning: >> >> WARNING: modpost: vmlinux: section mismatch in reference: cmdline_load_proc_show+0x2 (section: .text) -> boot_command_line (section: .init.data) > > cmdline_load_proc_show is probably inlined, but should it also be > marked __init? It's lone call site seems to be __init AFAICT. > No, that's not what it does: cmdline_load_proc_show() is called when someone reads /proc/cmdline_load from userspace. It's only the function that creates this procfs file that is __init, but the call happens later. Arnd
On Wed, Jul 26, 2023 at 07:02:55PM +0200, Arnd Bergmann wrote: > On Wed, Jul 26, 2023, at 18:25, Nick Desaulniers wrote: > > On Wed, Jul 26, 2023 at 7:33 AM Arnd Bergmann <arnd@kernel.org> wrote: > >> > >> From: Arnd Bergmann <arnd@arndb.de> > >> > >> The boot command line is not available after the init section gets discarded, > >> so adding a permanent reference to it causes a link time warning: > >> > >> WARNING: modpost: vmlinux: section mismatch in reference: cmdline_load_proc_show+0x2 (section: .text) -> boot_command_line (section: .init.data) > > > > cmdline_load_proc_show is probably inlined, but should it also be > > marked __init? It's lone call site seems to be __init AFAICT. > > > > No, that's not what it does: cmdline_load_proc_show() is called > when someone reads /proc/cmdline_load from userspace. It's only > the function that creates this procfs file that is __init, but the > call happens later. Thank you all! I have declared a tie between Stephen Rothwell and Arnd Bergmann for this fix. Please let me know if you are uncomfortable with these changes being squashed into the original with your guys' Co-developed-by. I also added Nick's Reviewed-by, please see below. Thanx, Paul ------------------------------------------------------------------------ commit de2f542cfbec295ac0f9b6a832d7b3ba20df391f Author: Paul E. McKenney <paulmck@kernel.org> Date: Fri Jul 21 16:05:38 2023 -0700 fs/proc: Add /proc/cmdline_load for boot loader arguments 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. 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. Co-developed-by: Stephen Rothwell <sfr@canb.auug.org.au> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au> Co-developed-by: Arnd Bergmann <arnd@kernel.org> Signed-off-by: Arnd Bergmann <arnd@kernel.org> Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: <linux-fsdevel@vger.kernel.org> 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 <linux/init.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> +#include <asm/setup.h> #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..c42a277db2da 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -112,6 +112,9 @@ #define __REFCONST .section ".ref.rodata", "a" #ifndef __ASSEMBLY__ + +#include <linux/cache.h> + /* * Used for initialization calls.. */ @@ -143,7 +146,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[] __ro_after_init; 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;
diff --git a/include/linux/init.h b/include/linux/init.h index 9a5973324072b..4e97a7a29a4d7 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -143,7 +143,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 c946ab87783a1..981170da0b1cd 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;