Re: [PATCH v3] random: remove early archrandom abstraction

From: Jason A. Donenfeld
Date: Tue Nov 01 2022 - 07:55:20 EST


Hi Catalin,

On Tue, Nov 1, 2022 at 12:39 PM Catalin Marinas <catalin.marinas@xxxxxxx> wrote:
> > +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.

Not sure that part matters much?

> It's also set to 'false' before
> system_capabilities_finalized() (once the full SMP is enabled).

Right, so there's still a "hole", where we'll ball back to
cpus_have_final_cap(), which might return false. In practice I don't
think this matters much. But it's still not perfect.

>
> 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;

That'd be fine. Of course that introduces a different sort of "hole",
when it's called from preemptable context. But again, that doesn't
matter in practice. So I'll send you a v4 doing that for you to ack.

I'm going to structure it like this, though:

static __always_inline bool __cpu_has_rng(void)
{
if (!system_capabilities_finalized() && !preemptible())
return __early_cpu_has_rndr();
return cpus_have_const_cap(ARM64_HAS_RNG);
}

Because cpus_have_const_cap() itself has a fallback mode before
system_capabilities_finalized() is true, where it checks a big
bitmask. So that seems like a better fallback than `false`, in case it
happens to be true.

Jason