From patchwork Thu Nov 10 13:09:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeniy Baskov X-Patchwork-Id: 18121 Return-Path: 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 + 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 ); 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 ; 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 To: Borislav Petkov Cc: Evgeniy Baskov , Dave Hansen , Ingo Molnar , Thomas Gleixner , linux-kernel@vger.kernel.org, x86@kernel.org, Alexey Khoroshilov Subject: [PATCH v8 2/5] x86: Add cmdline_prepare() helper Date: Thu, 10 Nov 2022 16:09:30 +0300 Message-Id: X-Mailer: git-send-email 2.37.4 In-Reply-To: References: MIME-Version: 1.0 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: 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?= 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 --- 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 /* For COMMAND_LINE_SIZE */ +#undef _SETUP + +#include + +#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 */