Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4526654rdb; Tue, 12 Dec 2023 01:56:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IFOkahdS2aqB2ek/iFLcujSFk/VmaaQj10I/HK2gNTY+96LR7K5Z5ms/kSGQc170NviZ6QW X-Received: by 2002:a05:6808:23c1:b0:3b9:21ac:7369 with SMTP id bq1-20020a05680823c100b003b921ac7369mr7842494oib.56.1702374984472; Tue, 12 Dec 2023 01:56:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702374984; cv=none; d=google.com; s=arc-20160816; b=PjMb8q3yXS7oBJtm7x9b8LC/BAX7g+cEfgh23jhUEccVV315cjPW4KPHfqE+6wrDbH vi2IlzDxHi9/aasy11I8UjKP6wEoxVS38EiS57XQV0sTD1caPkU7NqHgRYlUk6T6aR5S fEeye5VXdBXx56LSDuXQo0pRucUqHE1lNw+MIhwYn9HY9pv2VzfWIjWximWuPmIXc6rM LloJffU95u7bJFLvoeBzPfk7cob8w1Jf8PCRSmnnWzQKTab3ZBPR4fWhRD3H6RrBf/Hf cKJB2sAwV4AiBDWGWYgmAwuRnC4anKCYAEzlI4ewfF4Trac9GwyGiyT1u7RznbHkOBhG wvKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Nyfk96sOlBmBMhz4g3EbLUeiQ2dr4xILEPg932k6vO0=; fh=YBRpMQCWk6GZ4QoLvJCmsUFfEfw5JwNNcqqAz6J2R5A=; b=v0gRwtwR2achM1iFfqEt1rii7LT1UjSERStBQBDI6iL+MFkekZU0O+96t2V1z4+jmp iImxbQBHMuM827xVGbAQvrtF3ddOHq5p+K+eZ47cxKQk/cxPRvqJBEGB1YwIH+HF8323 cqCkM5rDlFFKbSVarOfcvUKBUD+yracjPq4KMFW3T6C084MD3gdJiTj+0Rvn43I092fo UFyb1KtH/VqhC/eyMMGVyZ8nKea8QBXZnqpB2gYTwxlMLV2dqJOpSdJ+G6L2AUyhiKGM 0O+EI1L4Cyw4Bn+FUh3vR4CmWac8qDF1iKEHSj7Kkl1jCvKxRSS9XpxWgVTC90F88EpA 7PAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GaIWa+5H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id x1-20020a056a00188100b006cb63513372si7698682pfh.12.2023.12.12.01.56.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 01:56:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GaIWa+5H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 444E580B8DD8; Tue, 12 Dec 2023 01:56:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231538AbjLLJz5 (ORCPT + 99 others); Tue, 12 Dec 2023 04:55:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231409AbjLLJzk (ORCPT ); Tue, 12 Dec 2023 04:55:40 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B44A8E8 for ; Tue, 12 Dec 2023 01:55:46 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F21D0C433C9; Tue, 12 Dec 2023 09:55:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702374946; bh=BQ3BLgzy5Ip8VA406gPgErfyBqjO7GKw1h33a58SXak=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=GaIWa+5HO/3tpLiJqVwkGHTCi5qex7zNQtWyU4PNsBQHsBUXpZiC58dM58/LuVX9M 3KYhJvHlIErYbprY2t/ZIQdSN24vOxlX96Gu3j5Vsob+RNTV7HvBd/GqXzWBO1rbHS +fptPBUY/B659L07EdnvJZlKKaWEPZKzyflncHVy9B0yV3Mga6SkgQCm6mkbPCKuTj yHvq/q+Z6JJ5SUPZ7eWqris9Lr2tgx05rXVcX1JI+U71pywzW5La2G3JbS3Mh4BaP6 CAfNzwoKJnlNgxSPhhLU4BIAhIsvivVpvYv7gfpL33fkNXxFl+0ggMkNW944Q7639c 1ukJgDrhcSQOw== Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2c9f7fe6623so68549541fa.3; Tue, 12 Dec 2023 01:55:45 -0800 (PST) X-Gm-Message-State: AOJu0YyVmvG/JvkMoiAs2cLVq6+oLnmG/LqcL8JcIMZpzSy+GPYZiFuA MSWYzvqpuOK6DCVOoEdM7c6KqVdizVKRI1PXmGs= X-Received: by 2002:a2e:a99a:0:b0:2cb:30c8:2c09 with SMTP id x26-20020a2ea99a000000b002cb30c82c09mr1515293ljq.54.1702374944140; Tue, 12 Dec 2023 01:55:44 -0800 (PST) MIME-Version: 1.0 References: <20231110013817.2378507-1-danielwa@cisco.com> <20231110013817.2378507-6-danielwa@cisco.com> In-Reply-To: <20231110013817.2378507-6-danielwa@cisco.com> From: Ard Biesheuvel Date: Tue, 12 Dec 2023 10:55:33 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 5/8] drivers: firmware: efi: libstub: enable generic commandline To: Daniel Walker Cc: Will Deacon , Christophe Leroy , Rob Herring , Daniel Gimpelevich , Andrew Morton , Pratyush Brahma , Tomas Mudrunka , Sean Anderson , x86@kernel.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, xe-linux-external@cisco.com, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Dec 2023 01:56:21 -0800 (PST) On Fri, 10 Nov 2023 at 02:39, Daniel Walker wrote: > > This adds code to handle the generic command line changes. > The efi code appears that it doesn't benefit as much from this design > as it could. > > For example, if you had a prepend command line with "nokaslr" then > you might be helpful to re-enable it in the boot loader or dts, > but there appears to be no way to re-enable kaslr or some of the > other options. > > The efi command line handling is incorrect. x86 and arm have an append > system however the efi code prepends the command line. > > For example, you could have a non-upgradable bios which sends > > efi=disable_early_pci_dma > > This hypothetically could have been set because early pci dma caused > issues on early versions of the product. > > Then later the early pci dma was made to work and the company desired > to start using it. To override the bios you could set the CONFIG_CMDLINE > to, > > efi=no_disable_early_pci_dma > > then parsing would normally start with the bios command line, then move > to the CONFIG_CMDLINE and you would end up with early pci dma turned on. > > however, current efi code keeps early pci dma off because the bios > arguments always override the built in. > > Per my reading this is different from the main body of x86, arm, and > arm64. > > The generic command line provides both append and prepend, so it > alleviates this issue if it's used. However not all architectures use > it. > > It would be desirable to allow the efi stub to have it's builtin command > line to be modified after compile, but I don't see a feasible way to do > that currently. > > Cc: xe-linux-external@cisco.com > Signed-off-by: Daniel Walker There are quite some 'might be's and 'hypothetical's in this commit log. Is there an actual use case that you are addressing here? Without that, this looks like unnecessary churn to me, tbh. Note that this code executes in the context of platform firmware, which may be old and buggy so we should be cautious about making unnecessary changes here. > --- > .../firmware/efi/libstub/efi-stub-helper.c | 29 +++++++++++++++++++ > drivers/firmware/efi/libstub/efi-stub.c | 9 ++++++ > drivers/firmware/efi/libstub/efistub.h | 1 + > drivers/firmware/efi/libstub/x86-stub.c | 14 +++++++-- > 4 files changed, 51 insertions(+), 2 deletions(-) > > diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c > index bfa30625f5d0..952fa2cdff51 100644 > --- a/drivers/firmware/efi/libstub/efi-stub-helper.c > +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c > @@ -11,6 +11,7 @@ > > #include > #include > +#include > #include > #include > > @@ -29,6 +30,34 @@ bool __pure __efi_soft_reserve_enabled(void) > return !efi_nosoftreserve; > } > > +/** > + * efi_handle_cmdline() - handle adding in built-in parts of the command line > + * @cmdline: kernel command line > + * > + * Add in the generic parts of the commandline and start the parsing of the > + * command line. > + * > + * Return: status code > + */ > +efi_status_t efi_handle_builtin_cmdline(char const *cmdline) > +{ > + efi_status_t status = EFI_SUCCESS; > + > + if (sizeof(CMDLINE_STATIC_PREPEND) > 1) > + status |= efi_parse_options(CMDLINE_STATIC_PREPEND); > + > + if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) > + status |= efi_parse_options(cmdline); > + > + if (sizeof(CMDLINE_STATIC_APPEND) > 1) > + status |= efi_parse_options(CMDLINE_STATIC_APPEND); > + > + if (status != EFI_SUCCESS) > + efi_err("Failed to parse options\n"); > + > + return status; > +} > + > /** > * efi_parse_options() - Parse EFI command line options > * @cmdline: kernel command line > diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c > index f9c1e8a2bd1d..770abe95c0ee 100644 > --- a/drivers/firmware/efi/libstub/efi-stub.c > +++ b/drivers/firmware/efi/libstub/efi-stub.c > @@ -127,6 +127,14 @@ efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_ptr) > return EFI_OUT_OF_RESOURCES; > } > > +#ifdef CONFIG_GENERIC_CMDLINE > + status = efi_handle_builtin_cmdline(cmdline); > + if (status != EFI_SUCCESS) { > + goto fail_free_cmdline; > + } > +#endif > + > +#ifdef CONFIG_CMDLINE > if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || > IS_ENABLED(CONFIG_CMDLINE_FORCE) || > cmdline_size == 0) { > @@ -144,6 +152,7 @@ efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_ptr) > goto fail_free_cmdline; > } > } > +#endif > > *cmdline_ptr = cmdline; > return EFI_SUCCESS; > diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h > index 212687c30d79..1ac6631905c5 100644 > --- a/drivers/firmware/efi/libstub/efistub.h > +++ b/drivers/firmware/efi/libstub/efistub.h > @@ -996,6 +996,7 @@ efi_status_t efi_relocate_kernel(unsigned long *image_addr, > unsigned long alignment, > unsigned long min_addr); > > +efi_status_t efi_handle_builtin_cmdline(char const *cmdline); > efi_status_t efi_parse_options(char const *cmdline); > > void efi_parse_option_graphics(char *option); > diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c > index 9d5df683f882..273a8a9c8bbb 100644 > --- a/drivers/firmware/efi/libstub/x86-stub.c > +++ b/drivers/firmware/efi/libstub/x86-stub.c > @@ -847,6 +847,8 @@ void __noreturn efi_stub_entry(efi_handle_t handle, > struct setup_header *hdr = &boot_params->hdr; > const struct linux_efi_initrd *initrd = NULL; > unsigned long kernel_entry; > + unsigned long cmdline_paddr = ((u64)hdr->cmd_line_ptr | > + ((u64)boot_params->ext_cmd_line_ptr << 32)); > efi_status_t status; > > boot_params_pointer = boot_params; > @@ -877,6 +879,14 @@ void __noreturn efi_stub_entry(efi_handle_t handle, > goto fail; > } > > +#ifdef CONFIG_GENERIC_CMDLINE > + status = efi_handle_builtin_cmdline((char *)cmdline_paddr); > + if (status != EFI_SUCCESS) { > + efi_err("Failed to parse options\n"); > + goto fail; > + } > +#else /* CONFIG_GENERIC_CMDLINE */ > + > #ifdef CONFIG_CMDLINE_BOOL > status = efi_parse_options(CONFIG_CMDLINE); > if (status != EFI_SUCCESS) { > @@ -885,8 +895,6 @@ void __noreturn efi_stub_entry(efi_handle_t handle, > } > #endif > if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) { > - unsigned long cmdline_paddr = ((u64)hdr->cmd_line_ptr | > - ((u64)boot_params->ext_cmd_line_ptr << 32)); > status = efi_parse_options((char *)cmdline_paddr); > if (status != EFI_SUCCESS) { > efi_err("Failed to parse options\n"); > @@ -894,6 +902,8 @@ void __noreturn efi_stub_entry(efi_handle_t handle, > } > } > > +#endif > + > status = efi_decompress_kernel(&kernel_entry); > if (status != EFI_SUCCESS) { > efi_err("Failed to decompress kernel\n"); > -- > 2.39.2 > >