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,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 46271C433E0 for ; Thu, 25 Feb 2021 13:55:35 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C898B64DE8 for ; Thu, 25 Feb 2021 13:55:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C898B64DE8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Subject:To:From: Message-ID:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Mncxi7auI9zx/ik5DoBGrxTTUfLWNP7FZBp4cFL1y6w=; b=hRE/XzzLXNtanM6wSqnTuFbCP A/q1PJSZsKL4+iKRTZuHa/mpm+F/dNDzT36SwkCOtNJCssHffo3uBS+ZGgXdf5ND7bofo+Px2WQz+ oMF4fZvfDAJyx49768TSD5EdsHpWfhs1SBIcSFxln5efOu3eHHse+7+Mpc7QgvD4AhUmUU7hSg52a zSS9mZXD/IcopeL5rzqIL82g+1V6oUj00/9651/zzxWmPX/BiinN0YMbj3Si+YUnKv/yCEcMrS6Cn E3fTMkQQbBHJogCSsG9xhr3mP4/6xNFXl4gxeU8xaSXEA4KXdzhgEmmtjBEPFjR2QE0V484J0lREw c3mCD31Xg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lFH5i-0004wF-MT; Thu, 25 Feb 2021 13:54:06 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lFH5f-0004vD-FR for linux-arm-kernel@lists.infradead.org; Thu, 25 Feb 2021 13:54:04 +0000 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 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") 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210225_085403_726383_4B1E9190 X-CRM114-Status: GOOD ( 27.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Herring , kernel-team@android.com, Arnd Bergmann , devicetree@vger.kernel.org, Greg Kroah-Hartman , Doug Anderson , linux-kernel@vger.kernel.org, Tyler Hicks , Palmer Dabbelt , Catalin Marinas , Max Uvarov , Frank Rowand , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel