Re: [PATCH v10 04/28] x86/fpu/xstate: Modify address finders to handle both static and dynamic buffers

From: Bae, Chang Seok
Date: Sun Oct 03 2021 - 18:35:53 EST


On Oct 1, 2021, at 06:15, Thomas Gleixner <tglx@xxxxxxxxxxxxx> wrote:
> On Wed, Aug 25 2021 at 08:53, Chang S. Bae wrote:
>
>> Have all the functions finding XSTATE address take a struct fpu * pointer
>> in preparation for dynamic state buffer support.
>>
>> init_fpstate is a special case, which is indicated by a null pointer
>> parameter to get_xsave_addr() and __raw_xsave_addr().
>
> Same comment vs. subject. Prepare ...

How about:
"Prepare address finders to handle dynamic features"

>> + if (fpu)
>> + xsave = &fpu->state.xsave;
>> + else
>> + xsave = &init_fpstate.xsave;
>> +
>> + return xsave + xstate_comp_offsets[xfeature_nr];
>
> So you have the same conditionals and the same comments vs. that NULL
> pointer oddity how many times now all over the place?
>
> That can be completely avoided:
>
> Patch 1:
>
> -union fpregs_state init_fpstate __ro_after_init;
> +static union fpregs_state init_fpstate __ro_after_init;
> +struct fpu init_fpu = { .state = &init_fpstate } __ro_after_init;
>
> and make all users of init_fpstate access it through init_fpu.
>
> Patches 2..N which change arguments from fpregs_state to fpu:
>
> - fun(init_fpu->state);
> + fun(&init_fpu);
>
> Patch M which adds state_mask:
>
> @fpu__init_system_xstate()
> + init_fpu.state_mask = xfeatures_mask_all;
>
> Hmm?

Okay, a NULL pointer is odd and it as an argument should be avoided. Defining
a separate struct fpu for the initial state can make every function expect a
valid struct fpu pointer.

I think that the patch set will have such order (once [1] is dropped out) of,
- patch1 (new): a cleanup patch for fpstate_init_xstate() in patch1
- patch2 (new): the above init_fpu goes into this, and
- patch3-5: changes arguments to fpu,
- patch6 (new): finally patch 6 to add ->state_mask and ->state_size.


Thanks,
Chang

[1] https://lore.kernel.org/lkml/20210825155413.19673-2-chang.seok.bae@xxxxxxxxx/