Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp408482pxb; Thu, 25 Feb 2021 05:56:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBT6hoQF89Co89L2zCnNGcDZ5zTgnXbMxJD8lSWfy7ci51tYrG0hkpjQg84lTx/wu58U/p X-Received: by 2002:a17:907:b16:: with SMTP id h22mr2647918ejl.393.1614261374334; Thu, 25 Feb 2021 05:56:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614261374; cv=none; d=google.com; s=arc-20160816; b=YG8J3IOu2Xmo86QQPGhm5tL4Bc/mBq+oODrajMfxAPoXbVd4/+mCsNb8kZwF7x8jIJ qCe0Yb+DlunPv+KjTV4dcrGrSRZ6MAnJblCAFe4RyjbaIo97ALamDB8dggLkDp/VY5uR +poLJ6RwvJVNLd8ksOWetFvoeGo2L4seVhSZa6mucZ8vrFOiayg0X3A0e70ncNqzSAwz nQWpFm7NYVRLmpiR3rMaJfg4k4IejRa/ex0QvoQ1FHSFGgRBKw0B6zZzUp3xX0a+t+nE 88yHW9WYBNCh+KWBREjQ2anUxySa17Yw3o87L04yF0k0ABtTkBXQRQiLRaObKpPDavSi aSgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date; bh=bhAnzkkVXYejjHxOjnMyIm3O4an9TS9Xw8+jlMYV4vA=; b=ujxpKkXUuREU5BQPCwJRWshTT3W8n/priZ+dM0symkaaEIgkU0Tjlbwf26zk41bFyy RCt2/F/A6fka1baRYsJqKCx1x0+TC9G+H9ULkjzKDbX8ydb9mqDaTu14ACwlVag9+9Ie pY32qmnzg51Ahxzb3GyobPUARd0XHeGC8TznP7UXevt1cpsDdg+9rY7oLgvua2vDX+UF W73flySkjcCiTjcP462mkYs4OjyLGsD65sOa2u+y4oUmysJph7t3rjz4DmlnTvaL7PKH elKklXsEwWSJ4JSWXA32XM//a+sgtD821IYGFmqp+7THzmNzMUfysbL4O9EcyemGJLn0 VE2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g19si3478796ejz.742.2021.02.25.05.55.51; Thu, 25 Feb 2021 05:56:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231414AbhBYNyn (ORCPT + 99 others); Thu, 25 Feb 2021 08:54:43 -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.