All of lore.kernel.org
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Will Deacon <will@kernel.org>,
	Ard Biesheuvel <ardb@kernel.org>,
	Jean-Philippe Brucker <jean-philippe@linaro.org>
Subject: Re: [PATCH v3] random: remove early archrandom abstraction
Date: Tue, 1 Nov 2022 11:39:11 +0000	[thread overview]
Message-ID: <Y2EFX5wGsjLwtO8j@arm.com> (raw)
In-Reply-To: <20221031102840.85621-1-Jason@zx2c4.com>

On Mon, Oct 31, 2022 at 11:28:40AM +0100, Jason A. Donenfeld wrote:
> Catalin - Though this touches arm64's archrandom.h, I intend to take
> this through the random.git tree, if that's okay. I have other patches
> that will build off of this one. -Jason

I'm fine with the patch going through your tree but I have a comment
below.

> diff --git a/arch/arm64/include/asm/archrandom.h b/arch/arm64/include/asm/archrandom.h
> index 109e2a4454be..4b0f28730ab2 100644
> --- a/arch/arm64/include/asm/archrandom.h
> +++ b/arch/arm64/include/asm/archrandom.h
> @@ -58,6 +58,20 @@ static inline bool __arm64_rndrrs(unsigned long *v)
>  	return ok;
>  }
>  
> +static inline bool __early_cpu_has_rndr(void)
> +{
> +	/* Open code as we run prior to the first call to cpufeature. */
> +	unsigned long ftr = read_sysreg_s(SYS_ID_AA64ISAR0_EL1);
> +	return (ftr >> ID_AA64ISAR0_EL1_RNDR_SHIFT) & 0xf;
> +}
> +
> +static __always_inline bool __cpu_has_rng(void)
> +{
> +	if (!system_capabilities_finalized() && early_boot_irqs_disabled)
> +		return __early_cpu_has_rndr();
> +	return cpus_have_const_cap(ARM64_HAS_RNG);
> +}

I'm not sure about using early_boot_irqs_disabled, it is described as a
debug helper. It's also set to 'false' before
system_capabilities_finalized() (once the full SMP is enabled).

Would something like this work:

	if (system_capabilities_finalized())
		return cpus_have_final_cap(ARM64_HAS_RNG);
	if (!preemptible())
		return __early_cpu_has_rndr();
	return false;

We also have a this_cpu_has_cap() function, though it's likely more
expensive than the hand-coded __early_cpu_has_rndr() (if we care about
performance here).

-- 
Catalin

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Catalin Marinas <catalin.marinas@arm.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Will Deacon <will@kernel.org>,
	Ard Biesheuvel <ardb@kernel.org>,
	Jean-Philippe Brucker <jean-philippe@linaro.org>
Subject: Re: [PATCH v3] random: remove early archrandom abstraction
Date: Tue, 1 Nov 2022 11:39:11 +0000	[thread overview]
Message-ID: <Y2EFX5wGsjLwtO8j@arm.com> (raw)
In-Reply-To: <20221031102840.85621-1-Jason@zx2c4.com>

On Mon, Oct 31, 2022 at 11:28:40AM +0100, Jason A. Donenfeld wrote:
> Catalin - Though this touches arm64's archrandom.h, I intend to take
> this through the random.git tree, if that's okay. I have other patches
> that will build off of this one. -Jason

I'm fine with the patch going through your tree but I have a comment
below.

> diff --git a/arch/arm64/include/asm/archrandom.h b/arch/arm64/include/asm/archrandom.h
> index 109e2a4454be..4b0f28730ab2 100644
> --- a/arch/arm64/include/asm/archrandom.h
> +++ b/arch/arm64/include/asm/archrandom.h
> @@ -58,6 +58,20 @@ static inline bool __arm64_rndrrs(unsigned long *v)
>  	return ok;
>  }
>  
> +static inline bool __early_cpu_has_rndr(void)
> +{
> +	/* Open code as we run prior to the first call to cpufeature. */
> +	unsigned long ftr = read_sysreg_s(SYS_ID_AA64ISAR0_EL1);
> +	return (ftr >> ID_AA64ISAR0_EL1_RNDR_SHIFT) & 0xf;
> +}
> +
> +static __always_inline bool __cpu_has_rng(void)
> +{
> +	if (!system_capabilities_finalized() && early_boot_irqs_disabled)
> +		return __early_cpu_has_rndr();
> +	return cpus_have_const_cap(ARM64_HAS_RNG);
> +}

I'm not sure about using early_boot_irqs_disabled, it is described as a
debug helper. It's also set to 'false' before
system_capabilities_finalized() (once the full SMP is enabled).

Would something like this work:

	if (system_capabilities_finalized())
		return cpus_have_final_cap(ARM64_HAS_RNG);
	if (!preemptible())
		return __early_cpu_has_rndr();
	return false;

We also have a this_cpu_has_cap() function, though it's likely more
expensive than the hand-coded __early_cpu_has_rndr() (if we care about
performance here).

-- 
Catalin

  reply	other threads:[~2022-11-01 11:47 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-28 23:40 [PATCH] random: remove early archrandom abstraction Jason A. Donenfeld
2022-10-28 23:40 ` Jason A. Donenfeld
2022-10-30 17:30 ` Catalin Marinas
2022-10-30 17:30   ` Catalin Marinas
2022-10-30 21:07   ` Jason A. Donenfeld
2022-10-30 21:07     ` Jason A. Donenfeld
2022-10-30 21:21     ` [PATCH v2] " Jason A. Donenfeld
2022-10-30 21:21       ` Jason A. Donenfeld
2022-10-31 10:28       ` [PATCH v3] " Jason A. Donenfeld
2022-10-31 10:28         ` Jason A. Donenfeld
2022-11-01 11:39         ` Catalin Marinas [this message]
2022-11-01 11:39           ` Catalin Marinas
2022-11-01 11:54           ` Jason A. Donenfeld
2022-11-01 11:54             ` Jason A. Donenfeld
2022-11-01 11:56             ` [PATCH v4] " Jason A. Donenfeld
2022-11-01 11:56               ` Jason A. Donenfeld
2022-11-01 12:25               ` [PATCH v5] " Jason A. Donenfeld
2022-11-01 12:25                 ` Jason A. Donenfeld
2022-11-01 12:36                 ` Mark Rutland
2022-11-01 12:36                   ` Mark Rutland
2022-11-01 13:02                   ` Jason A. Donenfeld
2022-11-01 13:02                     ` Jason A. Donenfeld
2022-11-01 13:07                     ` Mark Rutland
2022-11-01 13:07                       ` Mark Rutland
2022-11-01 14:05                 ` Catalin Marinas
2022-11-01 14:05                   ` Catalin Marinas

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=Y2EFX5wGsjLwtO8j@arm.com \
    --to=catalin.marinas@arm.com \
    --cc=Jason@zx2c4.com \
    --cc=ardb@kernel.org \
    --cc=jean-philippe@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.