Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp200722lqe; Fri, 5 Apr 2024 19:11:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWHzCOFx5GnG8XMmJlRmaocqRxgDrvkJQCwLBaQvhqmL5hPaPrGvm7tWsSW8WbkJ7GuRAmPx9idQvAmqfUpoc+7ZRE0UX6J9d0dKJtPvg== X-Google-Smtp-Source: AGHT+IE6ZhExjRZ+WMMDmXm5OPXYgoerjRM3EY3NmzNlRJQMsjwBrAvocfSDZgpbQ8Olddy2n08z X-Received: by 2002:a17:906:f90a:b0:a51:763e:b788 with SMTP id lc10-20020a170906f90a00b00a51763eb788mr1922538ejb.40.1712369486808; Fri, 05 Apr 2024 19:11:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712369486; cv=pass; d=google.com; s=arc-20160816; b=sjyL/cdmcF6XYlaf9K2hX5CslV6r2IkbamlNPpY4pnS6hav7kRI/8Ir8o9+P32QL4K GSd40WihmJGV/xIli9yAGpDRInJvrz1ZsHWTW45NjU1NY0oow2nAu9A/M/sV9fmAbDCy VnuYRlyUGxy8t8yXCzzCUxks4zEbmtU+45tUxwOyQpG4zbD8DIjGXh+Hj5IOYHtQsCdS 1MRiB0vMEeeufZNQgKgp9a99v/zfkprPaueV6OxRIaHC5tJGGczB9Je2WiWib7hb4fCq a9xOYR7J3H6Yo2ezCusJWi4nRBCxiCuw2hv37senwqioWCJGUKgbSOuFXvQSx+5YKLSO 2DHA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=TaghrqhW4wCTNGWz8ZR2vx8uydkQoJhpyMarLrlp9YQ=; fh=H2ylL3SvDCM76vzZ7/icTZ5oB0qSOEPH8SLx3YwWBi8=; b=KkyUHPafAVND0NYrif+hl9mg+dcIKMkNjDqF1p9MZTtBSeBzcHz3puSrKa+VYb2hIY Tfuq7OWuQc/B7p30/CAMdztn2GDupPqQGoBDIg6J3rRtwqH6Sxje/8gHNnxR5Dl+Zvby q5Gm+HFYEQDXj5forxvK0+EG26WR/afEquLqWva35/kFrwAXkl4YxOxGwCIos6zJMwGW p+kxFnJ+ECGDqeqmIRJRO0kxVc3zt1XkDTbhPa6V3qAAwxL5Ax4ri/Xk3oFu80oIE/z/ 9xG0Lm6+HpAorR82w7nyXzhGtE94fwIoVs5EKN4Zll//D+JUTVszQlmdobOoyncXVNgd +adA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="WTDe2/4V"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-133769-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133769-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id jg30-20020a170907971e00b00a4e689c3873si1303872ejc.669.2024.04.05.19.11.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 19:11:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-133769-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="WTDe2/4V"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-133769-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133769-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 5EACF1F21736 for ; Sat, 6 Apr 2024 02:11:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3FC3A13ACC; Sat, 6 Apr 2024 02:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WTDe2/4V" 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 1719618C05; Sat, 6 Apr 2024 02:11:12 +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=1712369473; cv=none; b=q0rIykbrafDmWFZyVWcZTYiXctj+jbjemG6zDUOR3cHEx+r4VSvzJDgfdrkQW7JEWsR4rE8qGVv/36xKnzOXBHqcY3ojBkW4hAL80NluNdp6joG4aCmadILDDwLdZkfjeOSlStcprQPCW1yTiIe8pXFNdbNKFp5sR0hwgqz+sWc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712369473; c=relaxed/simple; bh=woMNEmi6/hdqBt/ao3V3KF+oBgqA0BZosVdoyoMgMlw=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=EqHtYsrUySSQGjFYqFJBk2bUmPP92PbP7HBEOnimiqjBBz/EWpv2w4FgwtDbslRCC6MJtnLU1BzsEu8HqYueIEWK82NDCAAETfpWkzeBSEIbFHG+CWiq/vMary9YCrBLytE0LclYgzRZaUvApCqPWIGWAwRhRnYI05cZdGJg6C4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WTDe2/4V; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3EBADC433F1; Sat, 6 Apr 2024 02:11:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712369472; bh=woMNEmi6/hdqBt/ao3V3KF+oBgqA0BZosVdoyoMgMlw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=WTDe2/4VIPUO/C87oUFuAJXVUnZxMdlJm2sSe0GZ7m4sdl0dVFrgQbk1GYjvtdOXR jAWs43pSwskzmbf60/yAV/VgnozM93x+D+ixfXANyBxy6TyMpBrlNR0HafpJpBSbYT v4xEJrVrogQphsDM1icApNa6Xi8Qw/vZVqMOc1k+J7rIK0Igz8ioTkwZFQJyaoThQN GXTBiixQkC3jTo9GyfbbpE0Nda8LP4MyYMTNwwqviS+/lDGPhMf0S0PiDrn/gre7Ve 5XpwC9WIoCyEF+mtAVuOQnaoDcoYOgF2wXBsF9hlxfhELdsKyC9bbUB9nI8LWPd862 yMJeTXKsfTxtw== Date: Sat, 6 Apr 2024 11:11:08 +0900 From: Masami Hiramatsu (Google) To: paulmck@kernel.org 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: <20240406111108.e9a8b8c4cb8f44a8fb95b541@kernel.org> In-Reply-To: References: <20240404085522.63bf8cce6f961c07c8ce3f17@kernel.org> <26d56fa5-2c95-46da-8268-35642f857d6d@paulmck-laptop> <20240405102324.b7bb9fa052754d352cd2708e@kernel.org> <20240405115745.9b95679aa3ac516995d4d885@kernel.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit 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. 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) { ------------------------------------------------------------------------ Thank you, > > ------------------------------------------------------------------------ > > diff --git a/fs/proc/bootconfig.c b/fs/proc/bootconfig.c > index e5635a6b127b0..7d2520378f5f2 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 (bootconfig_is_present() && 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..ef70d1b381421 100644 > --- a/include/linux/bootconfig.h > +++ b/include/linux/bootconfig.h > @@ -10,6 +10,7 @@ > #ifdef __KERNEL__ > #include > #include > +int bootconfig_is_present(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..720a669b1493d 100644 > --- a/init/main.c > +++ b/init/main.c > @@ -1572,3 +1572,8 @@ static noinline void __init kernel_init_freeable(void) > > integrity_load_keys(); > } > + > +int bootconfig_is_present(void) > +{ > + return bootconfig_found || IS_ENABLED(CONFIG_BOOT_CONFIG_FORCE); > +} > > ------------------------------------------------------------------------ > > Give or take placement of the bootconfig_is_present() function's > declaration and definition. > > Thanx, Paul > > Thanx, Paul > > > Thank you, > > > > > > > Thank you, > > > > > > > > > > > Thanx, Paul > > > > > > > > > Thank you! > > > > > > > > > > > > > > > > > diff --git a/fs/proc/bootconfig.c b/fs/proc/bootconfig.c > > > > > > index 902b326e1e560..e5635a6b127b0 100644 > > > > > > --- a/fs/proc/bootconfig.c > > > > > > +++ b/fs/proc/bootconfig.c > > > > > > @@ -62,12 +62,12 @@ static int __init copy_xbc_key_value_list(char *dst, size_t size) > > > > > > break; > > > > > > dst += ret; > > > > > > } > > > > > > - if (ret >= 0 && boot_command_line[0]) { > > > > > > - ret = snprintf(dst, rest(dst, end), "# Parameters from bootloader:\n# %s\n", > > > > > > - boot_command_line); > > > > > > - if (ret > 0) > > > > > > - dst += ret; > > > > > > - } > > > > > > + } > > > > > > + if (ret >= 0 && boot_command_line[0]) { > > > > > > + ret = snprintf(dst, rest(dst, end), "# Parameters from bootloader:\n# %s\n", > > > > > > + boot_command_line); > > > > > > + if (ret > 0) > > > > > > + dst += ret; > > > > > > } > > > > > > out: > > > > > > kfree(key); > > > > > > > > > > > > > > > -- > > > > > Masami Hiramatsu (Google) > > > > > > > > > -- > > > Masami Hiramatsu (Google) > > > > > > -- > > Masami Hiramatsu (Google) -- Masami Hiramatsu (Google)