devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Will Deacon <will@kernel.org>
Cc: linux-kernel@vger.kernel.org, Max Uvarov <muvarov@gmail.com>,
	Rob Herring <robh@kernel.org>, Ard Biesheuvel <ardb@kernel.org>,
	Doug Anderson <dianders@chromium.org>,
	Tyler Hicks <tyhicks@linux.microsoft.com>,
	Frank Rowand <frowand.list@gmail.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	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
Date: Thu, 25 Feb 2021 13:53:56 +0000	[thread overview]
Message-ID: <87zgzsz217.wl-maz@kernel.org> (raw)
In-Reply-To: <20210225125921.13147-2-will@kernel.org>

On Thu, 25 Feb 2021 12:59:20 +0000,
Will Deacon <will@kernel.org> 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 <maz@kernel.org>
> Fixes: 33200303553d ("arm64: cpufeature: Add an early command-line cpufeature override facility")
> Signed-off-by: Will Deacon <will@kernel.org>
> ---
>  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 <maz@kernel.org>

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.

  reply	other threads:[~2021-02-25 13:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-25 12:59 [PATCH 0/2] Fix CMDLINE_EXTEND handling for FDT "bootargs" Will Deacon
2021-02-25 12:59 ` [PATCH 1/2] arm64: cpufeatures: Fix handling of CONFIG_CMDLINE for idreg overrides Will Deacon
2021-02-25 13:53   ` Marc Zyngier [this message]
2021-02-25 14:04     ` Will Deacon
2021-02-25 12:59 ` [PATCH 2/2] of/fdt: Append bootloader arguments when CMDLINE_EXTEND=y Will Deacon
2021-02-25 14:08   ` Marc Zyngier
2021-03-01 14:19 ` [PATCH 0/2] Fix CMDLINE_EXTEND handling for FDT "bootargs" Rob Herring
2021-03-01 14:41   ` Will Deacon
2021-03-01 17:26     ` Rob Herring
2021-03-01 17:45       ` Christophe Leroy
2021-03-02 14:56         ` Rob Herring
2021-03-02 15:16           ` Christophe Leroy
2021-03-02 17:12       ` Daniel Walker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zgzsz217.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=catalin.marinas@arm.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dianders@chromium.org \
    --cc=frowand.list@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-team@android.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=muvarov@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=robh@kernel.org \
    --cc=tyhicks@linux.microsoft.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).