Message ID | b81fa524589ff21002a501f0b4cddf41b53f640f.1668082601.git.baskov@ispras.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp137796wru; Thu, 10 Nov 2022 05:10:10 -0800 (PST) X-Google-Smtp-Source: AMsMyM6Hp+sRfFe9RVedfanaGJf0oGl2nrVBGhgkxEFWWGq4MqlRIwYsbru8lphKvon780YMoyVr X-Received: by 2002:a05:6a00:1394:b0:56d:2237:c1b0 with SMTP id t20-20020a056a00139400b0056d2237c1b0mr62646442pfg.5.1668085810468; Thu, 10 Nov 2022 05:10:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668085810; cv=none; d=google.com; s=arc-20160816; b=n9zHsoga20/ocwU5wS7qBdP+WcJ1P674voYH2mdl+hLSdemSu92oiu4s+hFVw68Vpj pE//odOdOAt3sVny5+uM3WJzt8rh4arXvvclLLVuziHcR6sRgxcpujbFAU8UB62Xc3B9 UI7a5dLNdlKTM1ILHht5Lrn10ywzzB6Yb6zzm+c3XhElDC9LuePwdnGvE70uJ6mZqOeH bbWnGV01WLdq+iTuveJpghtf8aZsfCo+vDi1EdSi3DSqmcZEmZjCelN20QUV1/lwmZxl gzmqVLVjNFqqeDvVpFX+m7Y0EgVNqDNrNM+1Q/ZRzRR8JLovCtzKaPVyLucpBumRr1IF GWJw== 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:dkim-filter; bh=6OlZriUDEchZQUeQ2XzXlu3cfcV0g8cSmETlWS2PYDY=; b=KZNINqPFHnBfYuMjNDahgZQUx9xpgdzMPCg3MwPcTeFpo4uPr+dMnkL3xxa95xGAOc YpdIo+yQlA2SdcqzJbpFa3trVtxizZch2JYAGFQcf8MNnE3ulcodCTeVLD4pxptWBjXj 5YcOh3CzVOHOWOp5CD+sR/qWxX7tBGRCGI8VQaMjiu8QSg2g+0HSNiDrt59hXTlZiDGE hseCdb/csp4VDyT1ifZ//R0HJoh4R2t3PCU7AMSUwwgKgbYQL0pvoj3o1jD8OGrJ9Pf/ 5095zao3YdrXDI+mkQ4MWdk45hqzQ2zRD6/YSeGcrp+fSEy0XDiPoG+mA1b2hc7yRKev WwBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=BMMzJMwJ; 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=ispras.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bn21-20020a056a02031500b0043aa67c7d8esi22278573pgb.738.2022.11.10.05.09.53; Thu, 10 Nov 2022 05:10:10 -0800 (PST) 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=@ispras.ru header.s=default header.b=BMMzJMwJ; 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=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230248AbiKJNJl (ORCPT <rfc822;winker.wchi@gmail.com> + 99 others); Thu, 10 Nov 2022 08:09:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230236AbiKJNJj (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 10 Nov 2022 08:09:39 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02108DEA7 for <linux-kernel@vger.kernel.org>; Thu, 10 Nov 2022 05:09:37 -0800 (PST) Received: from localhost.localdomain (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id B2F12400CBDC; Thu, 10 Nov 2022 13:09:35 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru B2F12400CBDC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1668085775; bh=6OlZriUDEchZQUeQ2XzXlu3cfcV0g8cSmETlWS2PYDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BMMzJMwJ6/GWHOaIHVHdezI4S7X5VjnVFWu/SquSMh4+1dWK3VU5LHyM9/fOlhtYU 9Ehq40EffgfYY16qzn6W8wxcmJLuwSzam3XjoIYfG1Rh+MGl1mKW1w2XTeF231JGY2 gdFeXndLQRZdw1gLIeBzlD4YBoRDQ3B6X73ZIp7I= From: Evgeniy Baskov <baskov@ispras.ru> To: Borislav Petkov <bp@alien8.de> Cc: Evgeniy Baskov <baskov@ispras.ru>, Dave Hansen <dave.hansen@linux.intel.com>, Ingo Molnar <mingo@redhat.com>, Thomas Gleixner <tglx@linutronix.de>, linux-kernel@vger.kernel.org, x86@kernel.org, Alexey Khoroshilov <khoroshilov@ispras.ru> Subject: [PATCH v8 2/5] x86: Add cmdline_prepare() helper Date: Thu, 10 Nov 2022 16:09:30 +0300 Message-Id: <b81fa524589ff21002a501f0b4cddf41b53f640f.1668082601.git.baskov@ispras.ru> X-Mailer: git-send-email 2.37.4 In-Reply-To: <cover.1668082601.git.baskov@ispras.ru> References: <cover.1668082601.git.baskov@ispras.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749114746743852529?= X-GMAIL-MSGID: =?utf-8?q?1749114746743852529?= |
Series |
Parse CONFIG_CMDLINE in compressed kernel
|
|
Commit Message
Evgeniy Baskov
Nov. 10, 2022, 1:09 p.m. UTC
Command line needs to be combined in both compressed and uncompressed
kernel from built-in and boot command line strings, which requires
non-trivial logic depending on CONFIG_CMDLINE_BOOL and
CONFIG_CMDLINE_OVERRIDE.
Add a helper function to avoid code duplication.
Signed-off-by: Evgeniy Baskov <baskov@ispras.ru>
---
arch/x86/include/asm/shared/cmdline.h | 35 +++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
create mode 100644 arch/x86/include/asm/shared/cmdline.h
Comments
On Thu, Nov 10, 2022 at 04:09:30PM +0300, Evgeniy Baskov wrote: > Command line needs to be combined in both compressed and uncompressed > kernel from built-in and boot command line strings, which requires > non-trivial logic depending on CONFIG_CMDLINE_BOOL and > CONFIG_CMDLINE_OVERRIDE. > > Add a helper function to avoid code duplication. > > Signed-off-by: Evgeniy Baskov <baskov@ispras.ru> > --- > arch/x86/include/asm/shared/cmdline.h | 35 +++++++++++++++++++++++++++ > 1 file changed, 35 insertions(+) > create mode 100644 arch/x86/include/asm/shared/cmdline.h > > diff --git a/arch/x86/include/asm/shared/cmdline.h b/arch/x86/include/asm/shared/cmdline.h > new file mode 100644 > index 000000000000..01736d66028d > --- /dev/null > +++ b/arch/x86/include/asm/shared/cmdline.h > @@ -0,0 +1,35 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > + > +#ifndef _ASM_X86_SETUP_CMDLINE_H > +#define _ASM_X86_SETUP_CMDLINE_H > + > +#define _SETUP > +#include <asm/setup.h> /* For COMMAND_LINE_SIZE */ > +#undef _SETUP > + > +#include <linux/string.h> > + > +#ifdef CONFIG_CMDLINE_BOOL > +#define BUILTIN_COMMAND_LINE CONFIG_CMDLINE > +#else > +#define BUILTIN_COMMAND_LINE "" > +#endif > + > +static inline void cmdline_prepare(char *dst, const char *boot_command_line) > +{ > + if (!IS_ENABLED(CONFIG_CMDLINE_BOOL)) { > + strscpy(dst, boot_command_line, COMMAND_LINE_SIZE); > + } else { > + strscpy(dst, BUILTIN_COMMAND_LINE, COMMAND_LINE_SIZE); > + /* > + * Append boot loader cmdline to builtin, if it exists > + * and should not be overriden. > + */ > + if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE) && boot_command_line[0]) { > + strlcat(dst, " ", COMMAND_LINE_SIZE); > + strlcat(dst, boot_command_line, COMMAND_LINE_SIZE); > + } You keep changing what I'm suggesting and the next patch has a strscpy() outside of the function. When I say it should be all concentrated in one function, I really mean it. So now it is my turn: I'll do it how I think it should be done and you can review it.
On Mon, Nov 14, 2022 at 03:28:55PM +0100, Borislav Petkov wrote: > So now it is my turn: I'll do it how I think it should be done and you > can review it. Ok, here are two patches as a reply to this message. I was able to test them as much as I can in a VM here but I'd need more details/testing in your configuration with earlyprintk as a builtin cmdline. cmdline_prepare() has grown a bit hairy in the end but I've tried hard to comment what happens there so that it is clear for the future. The main goal being to concentrate all command line strings processing in that function and not have it spread around the tree. And yes, there are more cleanups possible. In the compressed stage I'm using the cmdline which is in boot_params as source and destination to basically add only the builtin cmdline. In kernel proper the boot_command_line comes from generic code and that is a whole another way of crazy in itself when I look at init/main.c And as previously stated - the goal is to have everything in one place and documented as good as possible so that trying to figure out how command line parsing is done doesn't send you on grepping spree around the tree. Suggestions how to simplify this even more are always welcome, ofc. Thx.
diff --git a/arch/x86/include/asm/shared/cmdline.h b/arch/x86/include/asm/shared/cmdline.h new file mode 100644 index 000000000000..01736d66028d --- /dev/null +++ b/arch/x86/include/asm/shared/cmdline.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _ASM_X86_SETUP_CMDLINE_H +#define _ASM_X86_SETUP_CMDLINE_H + +#define _SETUP +#include <asm/setup.h> /* For COMMAND_LINE_SIZE */ +#undef _SETUP + +#include <linux/string.h> + +#ifdef CONFIG_CMDLINE_BOOL +#define BUILTIN_COMMAND_LINE CONFIG_CMDLINE +#else +#define BUILTIN_COMMAND_LINE "" +#endif + +static inline void cmdline_prepare(char *dst, const char *boot_command_line) +{ + if (!IS_ENABLED(CONFIG_CMDLINE_BOOL)) { + strscpy(dst, boot_command_line, COMMAND_LINE_SIZE); + } else { + strscpy(dst, BUILTIN_COMMAND_LINE, COMMAND_LINE_SIZE); + /* + * Append boot loader cmdline to builtin, if it exists + * and should not be overriden. + */ + if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE) && boot_command_line[0]) { + strlcat(dst, " ", COMMAND_LINE_SIZE); + strlcat(dst, boot_command_line, COMMAND_LINE_SIZE); + } + } +} + +#endif /* _ASM_X86_SETUP_CMDLINE_H */