Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1554223lqe; Mon, 8 Apr 2024 12:18:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV9MMFjrppsJeY3BbFr1vhJBtA+XK4IAvCprUWvj9VjMdEB3Xz2sANOCcG6uZp9w4ClMVuK21/jnufCsKEcEW75ipEX9AApizNMq4DAGg== X-Google-Smtp-Source: AGHT+IEYcgewpMKo6MzoNp81EFIv5qpZ+KxjOX8UoCxv4sxckR4+DQZWnHb9eQ+bBgZt3kfS94nb X-Received: by 2002:a05:620a:cca:b0:78d:6a12:e78c with SMTP id b10-20020a05620a0cca00b0078d6a12e78cmr1643893qkj.76.1712603910479; Mon, 08 Apr 2024 12:18:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712603910; cv=pass; d=google.com; s=arc-20160816; b=ByAcdxTqRXA3lVn5wl2CtfBUsn3zAaLEyFBwpMtNmuhtz44J4k9gsyuBiYg7dJOirg iKoNSzP9cv8Aiq3z0k01amAIHpnQdjeD0ahHSkUSbtdQif8Ww3sWgCKSZgGrAMopML3A GkCidq4oSYngRXvFaZMdd5XPQNzPEQxQa58jGMFcdQJHo4P8O4o5EsmI8GBL0qEyaEBR fHZhYa1CArBUu7SSNkHyODUb2b2+i3OMHD75zwo+tluPoyWbajUMy1gjDbF+i5hZUNVK PduJ0N2zLBxYEnmYMQwsHhSZJIDYN3Tj8wh8MJ2/8yLIlMJWwoSaH0Dcs/NuCXN45b06 l16w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=axe6iwtuUQWfdEGoH5UnuFalkniY3SmJp4zhexGF/Ho=; fh=E2vn5j0GUpbUnXxrwWUfGoiLiG7FX1rjoGTw/zrp8Jc=; b=w9eTbywdpVLr0Uk/NV/XlU08WUF1V3AUT9mUdoYjGxEclMDtx9jJZ3vK2TtW+xp8/T 2La4ErnNl2KMVmEbJQxcO12oNZOCWLMKEFPvN1dLREkdNErtZs8FxM0iur7qxMnhsEVF wTlTS46sv+p7+X1E3GY6WlCX8v2Ja7xf47le7aiBlKz7U/7pw+yKwUkW+fakXOkP3EbQ w4atgoPGX6I2lqvO7VnIHKAJ0qvNT4zT7hM34ZwKQ47ncooYVslhuLjbME4uoNEmUuNG H+68NzkAgReVKM3fZt+jPIa3J2tAAefnQjDMODZheglzi3EXOaGlQMZ00rNR/vGZmW6V TWbQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hYHJJqTC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-135866-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135866-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z3-20020a05620a08c300b0078d5fd94411si4725199qkz.394.2024.04.08.12.18.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 12:18:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135866-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hYHJJqTC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-135866-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135866-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 227F01C215E2 for ; Mon, 8 Apr 2024 19:18:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F8B714535A; Mon, 8 Apr 2024 19:18:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hYHJJqTC" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 091471DA3A; Mon, 8 Apr 2024 19:18:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712603900; cv=none; b=okBLbGI0bN5sijUMGym7xcSYt0mNDak8KD4sh+EI/G4u/ZO7fCdEX8hBaV00QJIwwBriBJWt5AgKR1e/u4QJTbq+EBRLgJHWmvo0wWEqBY5eEB+RIX8yDRk9XxgZPPf7ZKcoi0viuv+16YT3EfF+NDAf4x7jOvkbGwfsFWnZD50= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712603900; c=relaxed/simple; bh=uTL1RCFqXuZrvuMFNTFaPljJBiS4C9X8lbpI85lnIQ0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uOOuU+Ln5QtkFKcIiupwc6TpAxupj/L/aT852+7JqnYDQR7ibg7cDzmUGSmoF6xYYTKt/Va8iGjhXtJlQJv9MTmrVI+Nt8MsACB0trRkOcCGorfnzVI7sGP9u9N5+vbTXstfBemd9ddUyveCQ8TVl9UPdcKn0rY06RTfZFza5Io= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hYHJJqTC; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95872C433C7; Mon, 8 Apr 2024 19:18:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712603899; bh=uTL1RCFqXuZrvuMFNTFaPljJBiS4C9X8lbpI85lnIQ0=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=hYHJJqTC/eATgYbXiyZA5cRVECP+jC0W5FFUbj758Kt14LQd4PsZOlfSFaYGhi9r+ XLEpetPas53xQzLEgQ2ZyizueOX1zqPz9j6Nkf0Vjyf2IXYt68hQQnPYwemSL11Gzl rxHuLwvU+AAt3ZStaRpmK46Q+SCBXqjW7cqHH0AU2BEzjM2zVMCa2LoPaexA3G9myq MWrhNFuUP9jnr/gesNCa93tK/ghdiH0HumDwgmha1+SxdPLkiedGZ708euXg1kN+v+ 13DIatbypQajnMGqE62giAAE+GAtzr5ih5y8XzadP4nfkLbe8tvZvJpukpMjpk2L2W XH3xJAq3I636g== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 2AEBECE126C; Mon, 8 Apr 2024 12:18:19 -0700 (PDT) Date: Mon, 8 Apr 2024 12:18:19 -0700 From: "Paul E. McKenney" To: Masami Hiramatsu Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Zhenhua Huang Subject: Re: [PATCH fs/proc/bootconfig] remove redundant comments from /proc/bootconfig Message-ID: Reply-To: paulmck@kernel.org References: <20240404085522.63bf8cce6f961c07c8ce3f17@kernel.org> <26d56fa5-2c95-46da-8268-35642f857d6d@paulmck-laptop> <20240405102324.b7bb9fa052754d352cd2708e@kernel.org> <20240405115745.9b95679aa3ac516995d4d885@kernel.org> <20240406111108.e9a8b8c4cb8f44a8fb95b541@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240406111108.e9a8b8c4cb8f44a8fb95b541@kernel.org> On Sat, Apr 06, 2024 at 11:11:08AM +0900, Masami Hiramatsu wrote: > On Thu, 4 Apr 2024 21:25:41 -0700 > "Paul E. McKenney" wrote: > > > On Fri, Apr 05, 2024 at 11:57:45AM +0900, Masami Hiramatsu wrote: > > > On Fri, 5 Apr 2024 10:23:24 +0900 > > > Masami Hiramatsu (Google) wrote: > > > > > > > On Thu, 4 Apr 2024 10:43:14 -0700 > > > > "Paul E. McKenney" wrote: > > > > > > > > > On Thu, Apr 04, 2024 at 08:55:22AM +0900, Masami Hiramatsu wrote: > > > > > > On Wed, 3 Apr 2024 12:16:28 -0700 > > > > > > "Paul E. McKenney" wrote: > > > > > > > > > > > > > commit 717c7c894d4b ("fs/proc: Add boot loader arguments as comment to > > > > > > > /proc/bootconfig") adds bootloader argument comments into /proc/bootconfig. > > > > > > > > > > > > > > /proc/bootconfig shows boot_command_line[] multiple times following > > > > > > > every xbc key value pair, that's duplicated and not necessary. > > > > > > > Remove redundant ones. > > > > > > > > > > > > > > Output before and after the fix is like: > > > > > > > key1 = value1 > > > > > > > *bootloader argument comments* > > > > > > > key2 = value2 > > > > > > > *bootloader argument comments* > > > > > > > key3 = value3 > > > > > > > *bootloader argument comments* > > > > > > > ... > > > > > > > > > > > > > > key1 = value1 > > > > > > > key2 = value2 > > > > > > > key3 = value3 > > > > > > > *bootloader argument comments* > > > > > > > ... > > > > > > > > > > > > > > Fixes: 717c7c894d4b ("fs/proc: Add boot loader arguments as comment to /proc/bootconfig") > > > > > > > Signed-off-by: Zhenhua Huang > > > > > > > Signed-off-by: Paul E. McKenney > > > > > > > Cc: Masami Hiramatsu > > > > > > > Cc: > > > > > > > Cc: > > > > > > > > > > > > OOps, good catch! Let me pick it. > > > > > > > > > > > > Acked-by: Masami Hiramatsu (Google) > > > > > > > > > > Thank you, and I have applied your ack and pulled this into its own > > > > > bootconfig.2024.04.04a. > > > > > > > > > > My guess is that you will push this via your own tree, and so I will > > > > > drop my copy as soon as yours hits -next. > > > > > > > > Thanks! I would like to make PR this soon as bootconfig fixes for v6.9-rc2. > > > > > > Hmm I found that this always shows the command line comment in > > > /proc/bootconfig even without "bootconfig" option. > > > I think that is easier for user-tools but changes the behavior and > > > a bit redundant. > > > > > > We should skip showing this original argument comment if bootconfig is > > > not initialized (no "bootconfig" in cmdline) as it is now. > > > > So something like this folded into that patch? > > Hm, I expected just checking it in the loop as below. > > ------------------------------------------------------------------------ > diff --git a/fs/proc/bootconfig.c b/fs/proc/bootconfig.c > index e5635a6b127b..98e0780f7e07 100644 > --- a/fs/proc/bootconfig.c > +++ b/fs/proc/bootconfig.c > @@ -27,6 +27,7 @@ static int __init copy_xbc_key_value_list(char *dst, size_t size) > { > struct xbc_node *leaf, *vnode; > char *key, *end = dst + size; > + bool empty = true; > const char *val; > char q; > int ret = 0; > @@ -62,8 +63,9 @@ static int __init copy_xbc_key_value_list(char *dst, size_t size) > break; > dst += ret; > } > + empty = false; > } > - if (ret >= 0 && boot_command_line[0]) { > + if (!empty && ret >= 0 && boot_command_line[0]) { > ret = snprintf(dst, rest(dst, end), "# Parameters from bootloader:\n# %s\n", > boot_command_line); > if (ret > 0) > > ------------------------------------------------------------------------ > > The difference is checking "bootconfig" cmdline option or checking > the "bootconfig" is actually empty. So the behaviors are different > when the "bootconfig" is specified but there is no bootconfig data. Ah, understood, the point is to avoid the comment in cases where its content would be identical to /proc/cmdline. > Another idea is to check whether the cmdline is actually updated by > bootconfig and show original one only if it is updated. > (I think this fits the purpose of the original patch better.) > > ------------------------------------------------------------------------ > diff --git a/fs/proc/bootconfig.c b/fs/proc/bootconfig.c > index e5635a6b127b..95d6a231210c 100644 > --- a/fs/proc/bootconfig.c > +++ b/fs/proc/bootconfig.c > @@ -10,6 +10,9 @@ > #include > #include > > +/* defined in main/init.c */ > +bool __init cmdline_has_extra_options(void); > + > static char *saved_boot_config; > > static int boot_config_proc_show(struct seq_file *m, void *v) > @@ -63,7 +66,7 @@ static int __init copy_xbc_key_value_list(char *dst, size_t size) > dst += ret; > } > } > - if (ret >= 0 && boot_command_line[0]) { > + if (cmdline_has_extra_options() && ret >= 0 && boot_command_line[0]) { > ret = snprintf(dst, rest(dst, end), "# Parameters from bootloader:\n# %s\n", > boot_command_line); > if (ret > 0) > diff --git a/init/main.c b/init/main.c > index 2ca52474d0c3..881f6230ee59 100644 > --- a/init/main.c > +++ b/init/main.c > @@ -487,6 +487,11 @@ static int __init warn_bootconfig(char *str) > > early_param("bootconfig", warn_bootconfig); > > +bool __init cmdline_has_extra_options(void) > +{ > + return extra_command_line || extra_init_args; > +} > + > /* Change NUL term back to "=", to make "param" the whole string. */ > static void __init repair_env_string(char *param, char *val) > { > ------------------------------------------------------------------------ This one looks good to me! I had to move the declaration from /fs/proc/bootconfig.c to include/linux/bootconfig.h in order to avoid a build error. (The build system wants the declaration and definition to be visible as a cross-check.) Does the resulting patch below work for you? Thanx, Paul ------------------------------------------------------------------------ commit 8d95b50c523fba7133368650b3b5f71b169c76b5 Author: Masami Hiramatsu Date: Mon Apr 8 12:10:38 2024 -0700 fs/proc: Skip bootloader comment if no embedded kernel parameters If the "bootconfig" kernel command-line argument was specified or if the kernel was built with CONFIG_BOOT_CONFIG_FORCE, but if there are no embedded kernel parameter, omit the "# Parameters from bootloader:" comment from the /proc/bootconfig file. This will cause automation to fall back to the /proc/cmdline file, which will be identical to the comment in this no-embedded-kernel-parameters case. Signed-off-by: Masami Hiramatsu Signed-off-by: Paul E. McKenney diff --git a/fs/proc/bootconfig.c b/fs/proc/bootconfig.c index e5635a6b127b0..87dcaae32ff87 100644 --- a/fs/proc/bootconfig.c +++ b/fs/proc/bootconfig.c @@ -63,7 +63,7 @@ static int __init copy_xbc_key_value_list(char *dst, size_t size) dst += ret; } } - if (ret >= 0 && boot_command_line[0]) { + if (cmdline_has_extra_options() && ret >= 0 && boot_command_line[0]) { ret = snprintf(dst, rest(dst, end), "# Parameters from bootloader:\n# %s\n", boot_command_line); if (ret > 0) diff --git a/include/linux/bootconfig.h b/include/linux/bootconfig.h index ca73940e26df8..e5ee2c694401e 100644 --- a/include/linux/bootconfig.h +++ b/include/linux/bootconfig.h @@ -10,6 +10,7 @@ #ifdef __KERNEL__ #include #include +bool __init cmdline_has_extra_options(void); #else /* !__KERNEL__ */ /* * NOTE: This is only for tools/bootconfig, because tools/bootconfig will diff --git a/init/main.c b/init/main.c index 2ca52474d0c30..881f6230ee59e 100644 --- a/init/main.c +++ b/init/main.c @@ -487,6 +487,11 @@ static int __init warn_bootconfig(char *str) early_param("bootconfig", warn_bootconfig); +bool __init cmdline_has_extra_options(void) +{ + return extra_command_line || extra_init_args; +} + /* Change NUL term back to "=", to make "param" the whole string. */ static void __init repair_env_string(char *param, char *val) {