From nobody Sun May 10 09:13:43 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0DB0C433F5 for ; Thu, 5 May 2022 10:32:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355877AbiEEKgb (ORCPT ); Thu, 5 May 2022 06:36:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355879AbiEEKg2 (ORCPT ); Thu, 5 May 2022 06:36:28 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4D6941631 for ; Thu, 5 May 2022 03:32:47 -0700 (PDT) Received: from localhost.localdomain (unknown [80.240.223.29]) by mail.ispras.ru (Postfix) with ESMTPSA id A897440755E9; Thu, 5 May 2022 10:32:43 +0000 (UTC) From: Baskov Evgeniy To: Borislav Petkov Cc: Baskov Evgeniy , Thomas Gleixner , Ingo Molnar , Dave Hansen , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/2] x86: Add strlcat() to compressed kernel Date: Thu, 5 May 2022 13:32:23 +0300 Message-Id: <20220505103224.21667-2-baskov@ispras.ru> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220505103224.21667-1-baskov@ispras.ru> References: <20220505103224.21667-1-baskov@ispras.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" strlcat() simplifies the code of command line concatenation and reduces the probability of mistakes. Signed-off-by: Baskov Evgeniy diff --git a/arch/x86/boot/compressed/string.c b/arch/x86/boot/compressed/s= tring.c index 81fc1eaa3229..b0635539b6f6 100644 --- a/arch/x86/boot/compressed/string.c +++ b/arch/x86/boot/compressed/string.c @@ -40,6 +40,21 @@ static void *____memcpy(void *dest, const void *src, siz= e_t n) } #endif =20 +size_t strlcat(char *dest, const char *src, size_t count) +{ + size_t dsize =3D strlen(dest); + size_t len =3D strlen(src); + size_t res =3D dsize + len; + + dest +=3D dsize; + count -=3D dsize; + if (len >=3D count) + len =3D count-1; + memcpy(dest, src, len); + dest[len] =3D 0; + return res; +} + void *memset(void *s, int c, size_t n) { int i; --=20 2.36.0 From nobody Sun May 10 09:13:43 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81DDAC433EF for ; Thu, 5 May 2022 10:33:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355933AbiEEKgf (ORCPT ); Thu, 5 May 2022 06:36:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355849AbiEEKg2 (ORCPT ); Thu, 5 May 2022 06:36:28 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D1D61F61B for ; Thu, 5 May 2022 03:32:47 -0700 (PDT) Received: from localhost.localdomain (unknown [80.240.223.29]) by mail.ispras.ru (Postfix) with ESMTPSA id 6816A40755F6; Thu, 5 May 2022 10:32:44 +0000 (UTC) From: Baskov Evgeniy To: Borislav Petkov Cc: Baskov Evgeniy , Thomas Gleixner , Ingo Molnar , Dave Hansen , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/2] x86: Parse CONFIG_CMDLINE in compressed kernel Date: Thu, 5 May 2022 13:32:24 +0300 Message-Id: <20220505103224.21667-3-baskov@ispras.ru> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220505103224.21667-1-baskov@ispras.ru> References: <20220505103224.21667-1-baskov@ispras.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" CONFIG_CMDLINE, CONFIG_CMDLINE_BOOL, and CONFIG_CMDLINE_OVERRIDE were ignored during options lookup in compressed kernel. Parse CONFIG_CMDLINE-related options correctly in compressed kernel code. cmd_line_ptr_init is explicitly placed in .data section since it is used and expected to be equal to zero before .bss section is cleared. Signed-off-by: Baskov Evgeniy diff --git a/arch/x86/boot/compressed/cmdline.c b/arch/x86/boot/compressed/= cmdline.c index f1add5d85da9..261f53ad395a 100644 --- a/arch/x86/boot/compressed/cmdline.c +++ b/arch/x86/boot/compressed/cmdline.c @@ -1,6 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 #include "misc.h" =20 +#define COMMAND_LINE_SIZE 2048 + static unsigned long fs; static inline void set_fs(unsigned long seg) { @@ -12,12 +14,32 @@ static inline char rdfs8(addr_t addr) return *((char *)(fs + addr)); } #include "../cmdline.c" + +#ifdef CONFIG_CMDLINE_BOOL +static char builtin_cmdline[COMMAND_LINE_SIZE] =3D CONFIG_CMDLINE; +static bool builtin_cmdline_init __section(".data"); +#endif + unsigned long get_cmd_line_ptr(void) { unsigned long cmd_line_ptr =3D boot_params->hdr.cmd_line_ptr; - cmd_line_ptr |=3D (u64)boot_params->ext_cmd_line_ptr << 32; =20 +#ifdef CONFIG_CMDLINE_BOOL + if (!builtin_cmdline_init) { + if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) { + strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); + strlcat(builtin_cmdline, + (char *)cmd_line_ptr, + COMMAND_LINE_SIZE); + } + + builtin_cmdline_init =3D 1; + } + + cmd_line_ptr =3D (unsigned long)builtin_cmdline; +#endif + return cmd_line_ptr; } int cmdline_find_option(const char *option, char *buffer, int bufsize) --=20 2.36.0