From patchwork Thu Nov 10 13:09:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeniy Baskov X-Patchwork-Id: 18122 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp137825wru; Thu, 10 Nov 2022 05:10:13 -0800 (PST) X-Google-Smtp-Source: AMsMyM7IoqjFywLC10/FmobLCaii/Lj4HJxPqxfnpIT5j5kw0x+T56Eq2JgfpHsYUlAmmPRlywI9 X-Received: by 2002:a17:902:f546:b0:186:c6d7:6556 with SMTP id h6-20020a170902f54600b00186c6d76556mr63659920plf.109.1668085813134; Thu, 10 Nov 2022 05:10:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668085813; cv=none; d=google.com; s=arc-20160816; b=R3Y0CL7+TaSmJMoK0azXsbFF6HuqOnpYW/yZRhVMq5K+u3SaRVDyYLFHEY8P/lhX/G hhKNTMEso0zNaHT91j4hF6e6uitHstVoAE0Ej3GjltzX2E07GvoKNDSlX0bUSbxR0xh2 RaliQlrXtbEN/tbsB+forADwhLs5+wym5Yr3uI/c2mXdkpm2b0wdKIkI7m77vse4VrqR 7V5H+s+ol49Gpw1RuYESAMjxfd+Agt4PbAz0L3QMjm6DUPJZxWfE5c0u2xdj36VmaSR8 jA/poAPHxGidhFYarBfXtyWBvnJfr/VeW2aPXSL3aHc92gerIPjWyNCvP3n57kTcCXps oWmQ== 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=LhB34PvVQmEmAHSgcIjFt8cb9vXQe9ZNmveaYWGCLFg=; b=oAn/mH61QQ8eVEIUdqeIDeI10J07fnDkJnhdCj5mXqb3hROO+OmdeCWokES0FFkTWz 5DBOHHbrxkwadcb/mtPnsN2PAx/8OcTXpytDTmf7CiGVmSCqVqyjLUun+PhLRjf73h08 w0EUg9z8gi7BFnedTSZDd5TkrBxCgp6+7r1abZKz/tY/3ONetvEz8D5ga//YYSjYskdg FyiywK3UWu1aD4TURcyilRzuuJ+07tLEZJ3d+220dNkSc3dLerNO4800j7+irL6yMQ33 7V5YY2xFqv3pWzfqni8LnfnbOZLqM+z1U3yQefPqJDAE1NbaEIXj1amwwL2fi30aYjf/ 6oTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=JotLW5cT; 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 22-20020a631356000000b0046fe2432570si20484904pgt.390.2022.11.10.05.09.56; Thu, 10 Nov 2022 05:10:13 -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=JotLW5cT; 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 S230291AbiKJNJo (ORCPT + 99 others); Thu, 10 Nov 2022 08:09:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbiKJNJj (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 0278212AA2 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 8DCEC419E9E9; Thu, 10 Nov 2022 13:09:35 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 8DCEC419E9E9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1668085775; bh=LhB34PvVQmEmAHSgcIjFt8cb9vXQe9ZNmveaYWGCLFg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JotLW5cTg/KfF0EyW60fIU3JsvmBWiXWZVTRPATEISShL6URLYSSH6Eh3DAyoKR3B fN9uT9GOp4ooNWOW/EJrjdQsIiqsim/sE+pYDRYdb/z/7ow2L2EvYvJ1C4/IpAQ6Kq UwATpAahCAdspwlzdZhwjjWFQ+rIVUvjomPsZnL4= 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 1/5] x86/boot: Add strlcat() and strscpy() to compressed kernel Date: Thu, 10 Nov 2022 16:09:29 +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?1749114749322723592?= X-GMAIL-MSGID: =?utf-8?q?1749114749322723592?= These functions simplify the code of command line concatenation helper and reduce the probability of mistakes. Use simpler implementation of strscpy than used in it kernel itself to avoid code bloat in compressed kernel. Signed-off-by: Evgeniy Baskov --- arch/x86/boot/compressed/string.c | 50 +++++++++++++++++++++++++++++++ arch/x86/purgatory/purgatory.c | 1 + 2 files changed, 51 insertions(+) diff --git a/arch/x86/boot/compressed/string.c b/arch/x86/boot/compressed/string.c index 81fc1eaa3229..5c193fa0a09b 100644 --- a/arch/x86/boot/compressed/string.c +++ b/arch/x86/boot/compressed/string.c @@ -40,6 +40,56 @@ static void *____memcpy(void *dest, const void *src, size_t n) } #endif +size_t strlcat(char *dest, const char *src, size_t count) +{ + size_t dsize = strlen(dest); + size_t len = strlen(src); + size_t res = dsize + len; + + /* This would be a bug */ + if (dsize >= count) + error("strlcat(): destination too big\n"); + + dest += dsize; + count -= dsize; + if (len >= count) + len = count-1; + memcpy(dest, src, len); + dest[len] = 0; + return res; +} + +/* Don't include word-at-a-time code path in compressed kernel for simplicity */ +size_t strscpy(char *dest, const char *src, size_t count) +{ + long res = 0; + + if (count == 0) + return -E2BIG; + + if (count > INT_MAX) { + warn("strscpy(): Count is too big"); + return -E2BIG; + } + + while (count) { + char c; + + c = src[res]; + dest[res] = c; + if (!c) + return res; + res++; + count--; + } + + /* Hit buffer length without finding a NUL; force NUL-termination. */ + if (res) + dest[res-1] = '\0'; + + return -E2BIG; +} + void *memset(void *s, int c, size_t n) { int i; diff --git a/arch/x86/purgatory/purgatory.c b/arch/x86/purgatory/purgatory.c index 7558139920f8..65f0cedb65ae 100644 --- a/arch/x86/purgatory/purgatory.c +++ b/arch/x86/purgatory/purgatory.c @@ -57,3 +57,4 @@ void purgatory(void) * arch/x86/boot/compressed/string.c */ void warn(const char *msg) {} +void error(char *m) {} 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 */ From patchwork Thu Nov 10 13:09:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeniy Baskov X-Patchwork-Id: 18126 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp147527wru; Thu, 10 Nov 2022 05:29:35 -0800 (PST) X-Google-Smtp-Source: AMsMyM4cJvcPmR3/3iAfl0OT6paudhl3SRpKsX2gZVfhxOXcIwWjhpu6Lf9U5dS4pH2XfOmdJGcm X-Received: by 2002:a65:458a:0:b0:46f:33df:46b0 with SMTP id o10-20020a65458a000000b0046f33df46b0mr54667486pgq.564.1668086975356; Thu, 10 Nov 2022 05:29:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668086975; cv=none; d=google.com; s=arc-20160816; b=xCJDUUkh9pQ27KE5ac7vBRh/9Fcyl81/9OYWPgW5ufaEo2ANDBtwDkSY56dWTlgBHL esCrz0FIBilaXjdYEUsDOzBkLDB7Z8F3igecVCdCYU3cPSRisbAOl4rT/n3oa5Der1fM mAeIEAAPjK+UmFqFUv+RBIg3/zxkkeSK7oDrkJWtE8FwcNr/cp1IMjKlIq83L1dLuuMe Jc3Alwq2s0zIv4Ox9op9snuIgWZh6+IxDeH9t7UXnd7gkjJmf+nl0UFNPiTLkhuQZ/Sf 6USMX5sTX0yGqDuW6gPECFMllzCyB4Dx0kXUa28vzAM9wUDK8kaolSZhfSsyfKKX+tNw b+JQ== 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=IMZzqDsGqe80LCdtrLJ2hWF1Y/2kWqXMkN9RKfL+9hU=; b=hb39VHi2iSk1PBT2XoEWRS1SgJb9GFRYSqr16pgE8wuWPUX4fhftrAH8fTNOx+cR96 cC326q6mT+6DxH6iUrKMfHtw/ldMlDQmpLZZwrMPIIB5M/BbhSoc3i8EMs5S5HM7c+aX l47kyhm8ai7Nq7PUzpfR2h4OJ6SSI7qmKNfmtSlpeut/ngU90wJaGNqmHOYSPaCdJeDo BvbeDh7yXb5/7Jy5+olWuiqkCLOEUWcQXqVqdwQmyt3NyLuySRVBfvF8ifJalF2mje+W KV094NEOos68LOPiXdgIXvRfCiKoR8oQVF29jTrWCVG93fObx4jpR5945JXjtBN0XysQ QiCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=AtC3FqEa; 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 z196-20020a6333cd000000b004227041e9d2si21473172pgz.405.2022.11.10.05.29.20; Thu, 10 Nov 2022 05:29:35 -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=AtC3FqEa; 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 S230376AbiKJNJx (ORCPT + 99 others); Thu, 10 Nov 2022 08:09:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230224AbiKJNJj (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 024A710FCE 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 EC73E40737B7; Thu, 10 Nov 2022 13:09:35 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru EC73E40737B7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1668085776; bh=IMZzqDsGqe80LCdtrLJ2hWF1Y/2kWqXMkN9RKfL+9hU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AtC3FqEayeP++jRNm0DOfsflkG9yKFxgY7kxZXP5Vsfa04ihWpLyzL3oarSwkGdCm SSCH8fxSb9/D+yVyySJIxiiB7Rh+znkLG3fa/lY/epl6gaDnJ8pAqpU7Qd5Tcgy8Op +q7rcqoCc5cyOo0bwOCIOQGkzQoKO7Q7jnTpNWfY= 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 3/5] x86/setup: Use cmdline_prepare() in setup.c Date: Thu, 10 Nov 2022 16:09:31 +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?1749115968382632167?= X-GMAIL-MSGID: =?utf-8?q?1749115968382632167?= Use a common helper function for command line resolving in arch/x86/kernel/setup.c for code unification. Signed-off-by: Evgeniy Baskov --- arch/x86/kernel/setup.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index aacaa96f0195..f23a49f62b71 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -168,9 +169,6 @@ unsigned long saved_video_mode; #define RAMDISK_LOAD_FLAG 0x4000 static char __initdata command_line[COMMAND_LINE_SIZE]; -#ifdef CONFIG_CMDLINE_BOOL -static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE; -#endif #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) struct edd edd; @@ -970,20 +968,8 @@ void __init setup_arch(char **cmdline_p) bss_resource.start = __pa_symbol(__bss_start); bss_resource.end = __pa_symbol(__bss_stop)-1; -#ifdef CONFIG_CMDLINE_BOOL -#ifdef CONFIG_CMDLINE_OVERRIDE - strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); -#else - if (builtin_cmdline[0]) { - /* append boot loader cmdline to builtin */ - strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); - strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE); - strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); - } -#endif -#endif - - strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE); + cmdline_prepare(command_line, boot_command_line); + strscpy(boot_command_line, command_line, COMMAND_LINE_SIZE); *cmdline_p = command_line; /* From patchwork Thu Nov 10 13:09:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeniy Baskov X-Patchwork-Id: 18123 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp137867wru; Thu, 10 Nov 2022 05:10:20 -0800 (PST) X-Google-Smtp-Source: AMsMyM50PI8/xjHaiKyDvqEBibJyjuOnfqYNbptD68g+/zO3M1yl4M5deRSTshhXPjaLv3rYJtjt X-Received: by 2002:a17:90a:f2cb:b0:213:9afa:d13a with SMTP id gt11-20020a17090af2cb00b002139afad13amr65256900pjb.180.1668085819706; Thu, 10 Nov 2022 05:10:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668085819; cv=none; d=google.com; s=arc-20160816; b=Ysjm6Zx1GUrdJ+GrsxaR5SrEcVwpt7rqsC4GQ0b974VHe90Y8ww2rgxlci77VSm2TQ q01TNcW/KAqm3QMrjl6todS2Qk1qGMOLbwrH6bpbJBYLNYNO26zysKucIzvzteB1pluq yUH7TsesKHlupaO0S++VI1vYiUnOc+NfiZg7/wakNUZmObVjmZCthdtSEfcGLOYy6XjE Y3+e1U/R334AZ3fVqPHXk7exmz0RV1ONiufsqNNSyJGstmipyxEI0W+9Gc46i7eh+A3F YEr+E2G8bxk1ZyXNrHRjB4Bbpul/AQkHCMD/4+e7LFF5vCQTjV1hFfaWjlLY220QGuaK V4cQ== 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=8C0m+nikY+hKoEP6Ez5Q8u9vl0RUFjErqLyUvRmpH6Q=; b=MSuZtuDqiLzyJsR7ydA6lLnqBk6EPHrAR9LXEV5SKEEcFO3X9GFgXQYObaDozZnsHj 9oMW6O5qJQ0c/Thxi2O1bXFyOYlWaSkY52JAoyPXFS5vNIDd4PqZPG1gqc6AXmvuqyrt MOeHfVkK6jkrsy7zq4/RAuUsXVHhHqB6dF+yUlmqKoDI/DOBtGOlu+BhDRgAOg1zmP85 V/pLgXGdSCE8ZnlIjRlv1a0WMgyrHXizDnlBLMsV280ORRqsWT5Rm/ASZCet+HR4PLRS YXSGlYMkYSBuxQwBp6bym+WXLzz9vvjVV/m06g6875EyfsgNBWM01pDcNW4FYgWhO7+p jLpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=ZYwUalCb; 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 l125-20020a632583000000b0046fbe60adc5si21262092pgl.510.2022.11.10.05.10.00; Thu, 10 Nov 2022 05:10:19 -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=ZYwUalCb; 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 S230347AbiKJNJv (ORCPT + 99 others); Thu, 10 Nov 2022 08:09:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230238AbiKJNJj (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 0264C12A89 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 1B85D40737BB; Thu, 10 Nov 2022 13:09:36 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 1B85D40737BB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1668085776; bh=8C0m+nikY+hKoEP6Ez5Q8u9vl0RUFjErqLyUvRmpH6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZYwUalCb2nXd9lnjaqKwRXntRhcitVOzWlSmiJzHB5wCOn6y7U4B/c9YUkVuH7zxT BpA2vKgZurcsqZQK1gvVBNh/lFmv3JdwFnD+BtfGm7IU5kiAVH2pswTXc2ROiOl6u6 3EthC7c8acYuGdY1iKyQrGrl1vAfutJ2lPdA2QkE= 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 4/5] x86/boot: Use cmdline_prapare() in compressed kernel Date: Thu, 10 Nov 2022 16:09:32 +0300 Message-Id: <290b33437bc94c32fce2e13c0599eab5e1cc3132.1668082601.git.baskov@ispras.ru> 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?1749114756171095968?= X-GMAIL-MSGID: =?utf-8?q?1749114756171095968?= CONFIG_CMDLINE_BOOL and CONFIG_CMDLINE_OVERRIDE were ignored during options lookup in compressed kernel, including earlyprintk option, so it was impossible to get earlyprintk messages from that stage of boot process via command line provided at compile time. Being able to enable earlyprintk via compile-time option might be desirable for booting on systems with broken UEFI command line arguments via EFISTUB. Use a common helper function to handle CONFIG_CMDLINE_* in compressed kernel. Place command_line_init explicitly in '.data' section since it is used before '.bss' section is zeroed and it is expected to be equal to zero. Signed-off-by: Evgeniy Baskov --- arch/x86/boot/compressed/cmdline.c | 24 ++++++++++++++++++++++-- arch/x86/boot/compressed/misc.h | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/arch/x86/boot/compressed/cmdline.c b/arch/x86/boot/compressed/cmdline.c index f1add5d85da9..53ad259ee441 100644 --- a/arch/x86/boot/compressed/cmdline.c +++ b/arch/x86/boot/compressed/cmdline.c @@ -12,6 +12,15 @@ static inline char rdfs8(addr_t addr) return *((char *)(fs + addr)); } #include "../cmdline.c" + +static char command_line[COMMAND_LINE_SIZE] __section(".data"); +static bool command_line_init __section(".data"); + +/* + * This always returns runtime command line and does not account for built-in + * command line, so this should not be used for cmdline parsing. + * Use get_cmdline() instead. + */ unsigned long get_cmd_line_ptr(void) { unsigned long cmd_line_ptr = boot_params->hdr.cmd_line_ptr; @@ -20,11 +29,22 @@ unsigned long get_cmd_line_ptr(void) return cmd_line_ptr; } + +static inline unsigned long get_cmdline(void) +{ + if (!command_line_init) { + cmdline_prepare(command_line, (char *)get_cmd_line_ptr()); + command_line_init = 1; + } + + return (unsigned long)command_line; +} + int cmdline_find_option(const char *option, char *buffer, int bufsize) { - return __cmdline_find_option(get_cmd_line_ptr(), option, buffer, bufsize); + return __cmdline_find_option(get_cmdline(), option, buffer, bufsize); } int cmdline_find_option_bool(const char *option) { - return __cmdline_find_option_bool(get_cmd_line_ptr(), option); + return __cmdline_find_option_bool(get_cmdline(), option); } diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h index 62208ec04ca4..5bf1357c054c 100644 --- a/arch/x86/boot/compressed/misc.h +++ b/arch/x86/boot/compressed/misc.h @@ -26,6 +26,7 @@ #include #include #include +#include #include "tdx.h" From patchwork Thu Nov 10 13:09:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeniy Baskov X-Patchwork-Id: 18125 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp144023wru; Thu, 10 Nov 2022 05:21:45 -0800 (PST) X-Google-Smtp-Source: AMsMyM5TrpgT47U959a4b1aA461le/2dpt8fYsnHbyMx5XfexHjo+hTLJf3SfG1YQHv28rAIiGGI X-Received: by 2002:a17:907:724c:b0:7ad:8f76:1fb8 with SMTP id ds12-20020a170907724c00b007ad8f761fb8mr60069135ejc.582.1668086505738; Thu, 10 Nov 2022 05:21:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668086505; cv=none; d=google.com; s=arc-20160816; b=gvT8j1jDsP97964Pkn6tgBzGSKtTXP7e3HTbJizo2W/o/M6sImsUUaDlIiyVWZE89R 0XcHw5919BaF4UiePTyB/LrLTxRDEWxyrP4HCm5xQAtEDTab1Fa8xbdmBY1o6zqPbrc5 coNBl5kgDXvuPrxFBu0bEhOH5wWKy4sThC2t4hFCoE68a0RIujJExCtPODWmCidaBlcH M0dDjHdA58dD+bC1lhpu3kX5KvZRhPapl7iPOgLJ1chisaVyaK5k+90hxaJ0lk29UzlA OUv0j1aX/WXzjgGm4LzRybcset0yrrSxNNv4AsLPob82vBTXG4nCpFH6GV4Pja1oyNsl ddww== 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=N1WZT1IJDM73ZsyG84S81mPHKV67S3tkyKPRC/z42gw=; b=pf0B4Xvj+WbNWpax73j//C12ahXq6OHBBwWlr4AuYfilvpRmUI2xZ5Uaoot/QQ/nfv RjSaot9FuuQtGLIcuAoZuohakCto54HDXt4bXgpXYb4FD5/CSuNsw1ZRqoysar/WNW/J k2uwHm/F5E7NfRSEqfIBnviBoSUN3kqL2gb7qCFvakkS/VKtqIQzG4+p1BWxBAGWlUhj z5b+g8d9ZjMe1pPFqAp04RKn1KWWC6RPCFj6p7Cen/2kHSsf+2iaA2o5exnJSqOuvglt OYo7f9puCIZZ1z4tMZX73nxKtL+GicQDgwwLYVYSYhOQZ0pRQhvlqSSX3de0g2IoV2Gz iPyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=iiLSxfjX; 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 sb40-20020a1709076da800b0078df185078esi18000978ejc.663.2022.11.10.05.21.06; Thu, 10 Nov 2022 05:21:45 -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=iiLSxfjX; 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 S230387AbiKJNJ4 (ORCPT + 99 others); Thu, 10 Nov 2022 08:09:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230258AbiKJNJl (ORCPT ); Thu, 10 Nov 2022 08:09:41 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14C14D2CC for ; Thu, 10 Nov 2022 05:09:41 -0800 (PST) Received: from localhost.localdomain (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id 426FB40737BD; Thu, 10 Nov 2022 13:09:36 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 426FB40737BD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1668085776; bh=N1WZT1IJDM73ZsyG84S81mPHKV67S3tkyKPRC/z42gw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iiLSxfjXO8lmJK0aHfC+1TUkc9KawXGuDJILvzbimNPJr10M6/Ub56ctVwTJ+rVeB urQqsyF7Uk17UufFw4hxrZmx9vmCP27todN0ywfZReWjUQ/MYc+8u9QN3Ksr8O9vic lWLtW8JBp9q0BOVupxMyC0DWrET5WtqDU7xIKrqg= 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 5/5] x86/boot: Remove no longer needed includes Date: Thu, 10 Nov 2022 16:09:33 +0300 Message-Id: <52749526f69c73902eaf608f4b544b5060e6e6d9.1668082601.git.baskov@ispras.ru> 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?1749115475633061221?= X-GMAIL-MSGID: =?utf-8?q?1749115475633061221?= x86/incldue/asm/shared/cmdline.h header already provides COMMAND_LINE_SIZE definition. Signed-off-by: Evgeniy Baskov --- arch/x86/boot/compressed/ident_map_64.c | 4 ---- arch/x86/boot/compressed/kaslr.c | 4 ---- 2 files changed, 8 deletions(-) diff --git a/arch/x86/boot/compressed/ident_map_64.c b/arch/x86/boot/compressed/ident_map_64.c index d4a314cc50d6..fdfe0e5f5cb0 100644 --- a/arch/x86/boot/compressed/ident_map_64.c +++ b/arch/x86/boot/compressed/ident_map_64.c @@ -33,10 +33,6 @@ #define __PAGE_OFFSET __PAGE_OFFSET_BASE #include "../../mm/ident_map.c" -#define _SETUP -#include /* For COMMAND_LINE_SIZE */ -#undef _SETUP - extern unsigned long get_cmd_line_ptr(void); /* Used by PAGE_KERN* macros: */ diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c index e476bcbd9b42..b73a4d45f8d7 100644 --- a/arch/x86/boot/compressed/kaslr.c +++ b/arch/x86/boot/compressed/kaslr.c @@ -32,10 +32,6 @@ #include #include -#define _SETUP -#include /* For COMMAND_LINE_SIZE */ -#undef _SETUP - extern unsigned long get_cmd_line_ptr(void); /* Simplified build-specific string for starting entropy. */