Re: [PATCH 1/3] arm64: cpufeature: Fix the type of no FP/SIMD capability

From: Ard Biesheuvel
Date: Tue Oct 15 2019 - 09:11:49 EST


On Tue, 15 Oct 2019 at 15:03, Suzuki K Poulose <suzuki.poulose@xxxxxxx> wrote:
>
>
>
> On 15/10/2019 11:30, Ard Biesheuvel wrote:
> > On Tue, 15 Oct 2019 at 12:25, Dave Martin <Dave.Martin@xxxxxxx> wrote:
> >>
> >> On Mon, Oct 14, 2019 at 06:57:30PM +0200, Ard Biesheuvel wrote:
> >>> On Mon, 14 Oct 2019 at 17:50, Dave P Martin <Dave.Martin@xxxxxxx> wrote:
> >>>>
> >>>> On Mon, Oct 14, 2019 at 04:45:40PM +0100, Suzuki K Poulose wrote:
> >>>>>
> >>>>>
> >>>>> On 14/10/2019 15:52, Dave Martin wrote:
> >>>>>>
...
> >>>>>> I'm now wondering what happens if anything tries to use kernel-mode NEON
> >>>>>> before SVE is initialised -- which doesn't happen until cpufeatures
> >>>>>> configures the system features.
> >>>>>>
> >>>>>> I don't think your proposed change makes anything worse here, but it may
> >>>>>> need looking into.
> >>>>>
> >>>>> We could throw in a WARN_ON() in kernel_neon() to make sure that the SVE
> >>>>> is initialised ?
> >>>>
> >>>> Could do, at least as an experiment.
> >>>>
> >>>> Ard, do you have any thoughts on this?
> >>>>
> >>>
> >>> All in-kernel NEON code checks whether the NEON is usable, so I'd
> >>> expect that check to return 'false' if it is too early in the boot for
> >>> the NEON to be used at all.
> >>
> >> My concern is that the check may be done once, at probe time, for crypto
> >> drivers. If probing happens before system_supports_fpsimd() has
> >> stabilised, we may be stuck with the wrong probe decision.
> >>
> >> So: are crypto drivers and kernel_mode_neon() users definitely only
> >> probed _after_ all early CPUs are up?
> >>
> >
> > Isn't SMP already up when initcalls are processed?
>
> Not all of them. Booting with initcall_debug=1 shows the following :
>
> --
>
> // trimmed //
>
...
> [ 0.027033] initcall dummy_timer_register+0x0/0x54 returned 0 after 0 usecs
>
>
> [ 0.035949] Detected PIPT I-cache on CPU1
>
> [ 0.036049] CPU1: found redistributor 1 region 0:0x000000002f120000
> [ 0.036082] CPU1: Booted secondary processor [410fd0f0]
> [ 0.048049] Detected PIPT I-cache on CPU2
>
> [ 0.048149] CPU2: found redistributor 2 region 0:0x000000002f140000
> [ 0.048168] CPU2: Booted secondary processor [410fd0f0]
> [ 0.060249] Detected PIPT I-cache on CPU3
>
> [ 0.060349] CPU3: found redistributor 3 region 0:0x000000002f160000
> [ 0.060402] CPU3: Booted secondary processor [410fd0f0]
> [ 0.060620] Brought up 4 CPUs
> [ 0.060949] SMP: Total of 4 processors activated.
>
>

These are all early initcalls, which are actually documented as
running before SMP, and before 'pure' initcalls, which should only be
used to initialize global variables that cannot be initialized
statically. So I think we can safely disregard these as uses of kernel
mode NEON we should care about.

But I would still expect may_use_simd() to return the right value
here, independently of the logic that reasons about whether we have a
NEON in the first place.