From patchwork Thu Nov 10 13:09:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeniy Baskov X-Patchwork-Id: 1444 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp137893wru; Thu, 10 Nov 2022 05:10:22 -0800 (PST) X-Google-Smtp-Source: AMsMyM7s5FkpB5xmGy8Wk+Gw3gVgf7x9WJ52/m7ntgPjLX2WMIPW/KIPXrertWFbX0PijDFSkCyp X-Received: by 2002:a17:90a:eb0c:b0:213:8ff3:a46a with SMTP id j12-20020a17090aeb0c00b002138ff3a46amr71618706pjz.158.1668085822071; Thu, 10 Nov 2022 05:10:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668085822; cv=none; d=google.com; s=arc-20160816; b=xAnVeJ/L55d9D9bKklNym1A/4FODo0AFU8YvoGJid2Wauuhya4fyRhIvlGnVMn58CD G4ZMGMWBoGWYT3xMRGpZRVWImE0oJzjnBvOqUq8iMFBRmgPDKPerNN8CzRYcDznx9TUS KCshbhscD1RUqdM8ar2SjTw0q7LCFuRt/pZ0Lzm8PF6oERy2LZHQedhaO5ZLeTaDFF0u 6xauE1c5nrL2uY0I+EVDVm/QSlMbvLorFJIHQXUTX6+hX6w4Uhnaoex27DRpTvg/NBxQ FmrGpagAELO0qb2cXM0MjewXJ01Cz4cseiPzBTv46EM13XwFU47n0se/AjTjBNwM3duX 3UHw== 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 :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=QKRldkNPYPt/lxrJmQHe3NOj7qGdMmBSfUtKl9GPzw0=; b=ST90fW+o6X/r4d834iEHiQpPVFGd4/uMmelzSXiBir8OZ+/r7i51HmlJiMYpSu1kKg 7834/LgLDVxkbjlDGWj8fQ5klep7uSIeKLQcx2oWCiqj8s+qhgcIr4mgtM6vLea9skd6 Ldozym7KVu4IlkSugbUS7YyvLkCGtp/0o3awFxLbRtP1eZo+VbUdoW/fiNYLPxENZo9J JwhhzMogzyOvWxvrd7rHGbr8AVfteT/unHvyeIgP6w1VfBIZ74jcZKcIJH8jvAJhP9HK i4SQUzK2Tis/iC3/QHBagYePqr9b9KvJIy3INCro2RDgf1Qac1WND+93VbMYkOO8ws1+ VQEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=iT+2QmtC; 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 pg8-20020a17090b1e0800b00205f9df1f32si3994525pjb.25.2022.11.10.05.09.59; Thu, 10 Nov 2022 05:10:22 -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=iT+2QmtC; 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 S230339AbiKJNJs (ORCPT + 99 others); Thu, 10 Nov 2022 08:09:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229836AbiKJNJj (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 009A2303 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 61F0C419E9C7; Thu, 10 Nov 2022 13:09:35 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 61F0C419E9C7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1668085775; bh=QKRldkNPYPt/lxrJmQHe3NOj7qGdMmBSfUtKl9GPzw0=; h=From:To:Cc:Subject:Date:From; b=iT+2QmtCgDQ1V/+kmlqRxiafacUM+NOZ+OEApljYS0R24EJrHu7IgAD1LebefH/RR kFQGsVPF38EyRh6+ZMLeekY7m5BIqqV9hXvkMlvuJzsLFyvY+q2irSOCH//lECcFoD FGCpKgkUqLNI2KO718Xe7oICZTMyn4qFdrAPqANk= 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 0/5] Parse CONFIG_CMDLINE in compressed kernel Date: Thu, 10 Nov 2022 16:09:28 +0300 Message-Id: X-Mailer: git-send-email 2.37.4 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?1749114759086992313?= X-GMAIL-MSGID: =?utf-8?q?1749114759086992313?= 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. Changes in v2: * Compute resulting cmdline string once if needed and then reuse it. Store concatenation result in a static buffer. * Add strlcat() to compressed kernel to simplify the code. Changes in v3: v2 had a bug: cmd_line_ptr was set to a pointer to a buffer inside a kernel before kernel relocation, that makes this pointer invalid. * Replace the pointer by a boolean variable to avoid storing a pointer, since it becomes invalid during kernel relocation. Changes in v4: * Use better wording for commit messages. * Add buffer overflow check to strlcat(). * Factor out common logic of cmdline resolving into helper function. Changes in v5: * Use strscpy() instead of strlcpy(). Changes in v6: * Remove superfluous new line. * Rename resolve_cmdline() to cmdline_prepare(). * Move shared/setup-cmdline.h to shared/cmdline.h Changes in v7: * Replace #ifdef with IS_ENABLED() in cmdline_prepare() for consistency. Changes in v8: * Remove the need to use special initial value for command line result variable and put all logic in one function to improve the clarity of the code. One #ifdef is still required for the initial value of builtin cmdline in case iti is not defined to enable the use of IS_ENABLED in cmdline_prapare(), since it is more readable. Evgeniy Baskov (5): x86/boot: Add strlcat() and strscpy() to compressed kernel x86: Add cmdline_prepare() helper x86/setup: Use cmdline_prepare() in setup.c x86/boot: Use cmdline_prapare() in compressed kernel x86/boot: Remove no longer needed includes arch/x86/boot/compressed/cmdline.c | 24 +++++++++++- arch/x86/boot/compressed/ident_map_64.c | 4 -- arch/x86/boot/compressed/kaslr.c | 4 -- arch/x86/boot/compressed/misc.h | 1 + arch/x86/boot/compressed/string.c | 50 +++++++++++++++++++++++++ arch/x86/include/asm/shared/cmdline.h | 35 +++++++++++++++++ arch/x86/kernel/setup.c | 20 ++-------- arch/x86/purgatory/purgatory.c | 1 + 8 files changed, 112 insertions(+), 27 deletions(-) create mode 100644 arch/x86/include/asm/shared/cmdline.h