From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 203B2C433DB for ; Thu, 25 Feb 2021 13:55:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4BAC64F03 for ; Thu, 25 Feb 2021 13:55:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231818AbhBYNyq (ORCPT ); Thu, 25 Feb 2021 08:54:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:41110 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229961AbhBYNym (ORCPT ); Thu, 25 Feb 2021 08:54:42 -0500 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3AD2D64F03; Thu, 25 Feb 2021 13:54:00 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lFH5Z-00FrtX-Ro; Thu, 25 Feb 2021 13:53:58 +0000 Date: Thu, 25 Feb 2021 13:53:56 +0000 Message-ID: <87zgzsz217.wl-maz@kernel.org> From: Marc Zyngier To: Will Deacon Cc: linux-kernel@vger.kernel.org, Max Uvarov , Rob Herring , Ard Biesheuvel , Doug Anderson , Tyler Hicks , Frank Rowand , Arnd Bergmann , Palmer Dabbelt , Greg Kroah-Hartman , Catalin Marinas , kernel-team@android.com, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Subject: Re: [PATCH 1/2] arm64: cpufeatures: Fix handling of CONFIG_CMDLINE for idreg overrides In-Reply-To: <20210225125921.13147-2-will@kernel.org> References: <20210225125921.13147-1-will@kernel.org> <20210225125921.13147-2-will@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: will@kernel.org, linux-kernel@vger.kernel.org, muvarov@gmail.com, robh@kernel.org, ardb@kernel.org, dianders@chromium.org, tyhicks@linux.microsoft.com, frowand.list@gmail.com, arnd@arndb.de, palmer@dabbelt.com, gregkh@linuxfoundation.org, catalin.marinas@arm.com, kernel-team@android.com, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 25 Feb 2021 12:59:20 +0000, Will Deacon wrote: > > The built-in kernel commandline (CONFIG_CMDLINE) can be configured in > three different ways: > > 1. CMDLINE_FORCE: Use CONFIG_CMDLINE instead of any bootloader args > 2. CMDLINE_EXTEND: Append the bootloader args to CONFIG_CMDLINE > 3. CMDLINE_FROM_BOOTLOADER: Only use CONFIG_CMDLINE if there aren't > any bootloader args. > > The early cmdline parsing to detect idreg overrides gets (2) and (3) > slightly wrong: in the case of (2) the bootloader args are parsed first > and in the case of (3) the CMDLINE is always parsed. > > Fix these issues by moving the bootargs parsing out into a helper > function and following the same logic as that used by the EFI stub. > > Cc: Marc Zyngier > Fixes: 33200303553d ("arm64: cpufeature: Add an early command-line cpufeature override facility") > Signed-off-by: Will Deacon > --- > arch/arm64/kernel/idreg-override.c | 44 +++++++++++++++++------------- > 1 file changed, 25 insertions(+), 19 deletions(-) > > diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/idreg-override.c > index dffb16682330..cc071712c6f9 100644 > --- a/arch/arm64/kernel/idreg-override.c > +++ b/arch/arm64/kernel/idreg-override.c > @@ -163,33 +163,39 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases) > } while (1); > } > > -static __init void parse_cmdline(void) > +static __init const u8 *get_bootargs_cmdline(void) > { > - if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) { > - const u8 *prop; > - void *fdt; > - int node; > + const u8 *prop; > + void *fdt; > + int node; > > - fdt = get_early_fdt_ptr(); > - if (!fdt) > - goto out; > + fdt = get_early_fdt_ptr(); > + if (!fdt) > + return NULL; > > - node = fdt_path_offset(fdt, "/chosen"); > - if (node < 0) > - goto out; > + node = fdt_path_offset(fdt, "/chosen"); > + if (node < 0) > + return NULL; > > - prop = fdt_getprop(fdt, node, "bootargs", NULL); > - if (!prop) > - goto out; > + prop = fdt_getprop(fdt, node, "bootargs", NULL); > + if (!prop) > + return NULL; > > - __parse_cmdline(prop, true); > + return strlen(prop) ? prop : NULL; > +} > > - if (!IS_ENABLED(CONFIG_CMDLINE_EXTEND)) > - return; > +static __init void parse_cmdline(void) > +{ > + const u8 *prop = get_bootargs_cmdline(); > + > + if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || > + IS_ENABLED(CONFIG_CMDLINE_FORCE) || > + !prop) { The logic hurts, but I think I grok it now. The last term is actually a reduction of (IS_ENABLED(CONFIG_CMDLINE_FROM_BOOTLOADER) && !prop) and we know for sure that if none of the other two terms are true, then CMDLINE_FROM_BOOTLOADER *must* be enabled. > + __parse_cmdline(CONFIG_CMDLINE, true); > } > > -out: > - __parse_cmdline(CONFIG_CMDLINE, true); > + if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && prop) > + __parse_cmdline(prop, true); > } > > /* Keep checkers quiet */ I don't think we need to backport anything to stable for the nokaslr handling, do we? Otherwise, Reviewed-by: Marc Zyngier Thanks, M. -- Without deviation from the norm, progress is not possible.