Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp417906pxb; Thu, 25 Feb 2021 06:08:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJzk7G976yU+hV/b89r9Y8E4S8YrLGitTSL0pmeMLkb5jPgr5zR3QFRWjWIcUim/NHLbr4Ei X-Received: by 2002:aa7:d5c4:: with SMTP id d4mr3042353eds.49.1614262107368; Thu, 25 Feb 2021 06:08:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614262107; cv=none; d=google.com; s=arc-20160816; b=lHQWJPVqN/VoPCVIUeHt9lNwFBnZ6n5e7LlpztOLj8Wx+leD2YnQuoFCN+c9seQx0K prk0vHxhtEeb11TmiWaQq7rUm3wOlkYiVM97uOI+Yn6xVgBZWQPZl8eixnZK49FvNYIt F+Ao6C3rEGFdMp5JlA/JZvmPrKeQxabBnW+zA8QQCsWv7WjJuAXWd2+CXPucgko/Pwdl zcozS1bfFQPE1qiKWtCofC9e7lAJ4HyMNI3KiLDVAurAhnWzjjpWf8NDsXxTkcGUsXaC grHRqR71KITYQF7zUj7jJ/weqj4owUYHZSSuRkMiZhbNPoNBGqTbAlyKFrzAhhlvG+IX iHDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=uvnEdWsIQTfUTdX4QI1QawGr0qrN2+pMUUl3n/H5E5A=; b=gImlMltQTZcjnqOVESjAbnQLbBArJUont2K56xGOqzqIlJGSpI1envhkhH53bpJIB4 557AwVdyqI0X/TSxLxsRo3SXl3MUcBss1Vn87xvzJvCXPvSKjzaDWhPj62nbmijZX4AH cQVEEJZb5J/NKUFFuM+BpOnrasaHOwfEF1UeC519OtjfH8aPBpigMbMQ/9HlQn52WkwN DfLQlk83rSthm3nTaptq29oxKBnuJFJQZtVcUnnNKk2k8W7pkfFSZKmDbhDjaIUjDvd+ 2gzCyO1gT2ibzjl5lzm35ZOIzfs4h8+ogYlu06S4re1/liiE+skuM9YAHqGIWMljgW4w O4IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ajwGja5m; 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 r22si3173263edp.172.2021.02.25.06.08.04; Thu, 25 Feb 2021 06:08:27 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ajwGja5m; 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 S231978AbhBYOFI (ORCPT + 99 others); Thu, 25 Feb 2021 09:05:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:45430 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229800AbhBYOFH (ORCPT ); Thu, 25 Feb 2021 09:05:07 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id F026464F10; Thu, 25 Feb 2021 14:04:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614261865; bh=ZzbiSO0LdphYU9+gCAqnHrrBWjpkRFL5HzaqbcKijYQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ajwGja5mim9LQAOngcHGPFoYR/V0G1HRZdQ8UywAL2SZcAagocp47a/U8UbtT6uJz SKEdR8zhLSmwNjFLAebeKLtzmRBq0MacIteXK2QHwEXDbejskT2HAnozZ9I/b/G7DO mnHoX2cKReMMx6sIigZwGO+cIp8nE3bjxumR8HoDGK45WNzORNp6E98N8m3H/j+mXM pbnseAzBHRQBcz7KVSluoYSRk82nxabkwq2CWGpHY8wt7ZbJLldWLXJADbpF8G68h5 daiF7AdsGff4sya4oMOdLxGaqvtlnFsKRe3P5zK8mM92btDshSc8ZgEHGjAiU6tpK4 SE+jSDXO0EpDQ== Date: Thu, 25 Feb 2021 14:04:19 +0000 From: Will Deacon To: Marc Zyngier 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 Message-ID: <20210225140419.GB13297@willie-the-truck> References: <20210225125921.13147-1-will@kernel.org> <20210225125921.13147-2-will@kernel.org> <87zgzsz217.wl-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87zgzsz217.wl-maz@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 25, 2021 at 01:53:56PM +0000, Marc Zyngier wrote: > 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. Yes, with one gotcha: when CONFIG_CMDLINE is "", I don't think any of the CONFIG_CMDLINE_* are set, but the behaviour ends up being the same as CMDLINE_FROM_BOOTLOADER. > > > + __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? No, I don't think so. There isn't a "kaslr" or "nonokaslr", so the ordering doesn't matter afaict. > Reviewed-by: Marc Zyngier Cheers! Will