From nobody Fri May 8 11:30:08 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 41665C433F5 for ; Wed, 4 May 2022 20:41:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378329AbiEDUpc (ORCPT ); Wed, 4 May 2022 16:45:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378322AbiEDUp3 (ORCPT ); Wed, 4 May 2022 16:45:29 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0096E51315 for ; Wed, 4 May 2022 13:41:52 -0700 (PDT) Received: from localhost.localdomain (unknown [80.240.223.29]) by mail.ispras.ru (Postfix) with ESMTPSA id 8C531407625A; Wed, 4 May 2022 20:41:51 +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 v2 1/2] x86: add strlcat() to compressed kernel Date: Wed, 4 May 2022 23:41:22 +0300 Message-Id: <20220504204123.22967-2-baskov@ispras.ru> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504204123.22967-1-baskov@ispras.ru> References: <20220504204123.22967-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 Fri May 8 11:30:08 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 01677C433F5 for ; Wed, 4 May 2022 20:42:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378336AbiEDUpk (ORCPT ); Wed, 4 May 2022 16:45:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378325AbiEDUpb (ORCPT ); Wed, 4 May 2022 16:45:31 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CEF35131D for ; Wed, 4 May 2022 13:41:54 -0700 (PDT) Received: from localhost.localdomain (unknown [80.240.223.29]) by mail.ispras.ru (Postfix) with ESMTPSA id 70DB1407627C; Wed, 4 May 2022 20:41:52 +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 v2 2/2] x86: Parse CONFIG_CMDLINE in compressed kernel Date: Wed, 4 May 2022 23:41:23 +0300 Message-Id: <20220504204123.22967-3-baskov@ispras.ru> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504204123.22967-1-baskov@ispras.ru> References: <20220504204123.22967-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 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..58723983933d 100644 --- a/arch/x86/boot/compressed/cmdline.c +++ b/arch/x86/boot/compressed/cmdline.c @@ -1,22 +1,46 @@ // 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) { fs =3D seg << 4; /* shift it back */ } + typedef unsigned long addr_t; + static inline char rdfs8(addr_t addr) { return *((char *)(fs + addr)); } + #include "../cmdline.c" + +static unsigned long cmd_line_ptr __section(".data"); +#ifdef CONFIG_CMDLINE_BOOL +static char builtin_cmdline[COMMAND_LINE_SIZE] =3D CONFIG_CMDLINE; +#endif + unsigned long get_cmd_line_ptr(void) { - unsigned long cmd_line_ptr =3D boot_params->hdr.cmd_line_ptr; + if (!cmd_line_ptr) { + cmd_line_ptr =3D boot_params->hdr.cmd_line_ptr; + + cmd_line_ptr |=3D (u64)boot_params->ext_cmd_line_ptr << 32; + +#ifdef CONFIG_CMDLINE_BOOL + if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) { + strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); + strlcat(builtin_cmdline, + (char *)cmd_line_ptr, COMMAND_LINE_SIZE); + } =20 - cmd_line_ptr |=3D (u64)boot_params->ext_cmd_line_ptr << 32; + cmd_line_ptr =3D (unsigned long)builtin_cmdline; +#endif + } =20 return cmd_line_ptr; } --=20 2.36.0