Re: [PATCH 1/1] headers/deps: x86/fpu: Make task_struct::thread constant size
From: Oleg Nesterov
Date: Tue Mar 26 2024 - 17:56:37 EST
On 03/26, Ingo Molnar wrote:
>
> * Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
>
> > > +static struct fpu x86_init_fpu __read_mostly;
> > > +
> > > static void __init fpu__init_system_early_generic(void)
> > > {
> > > + {
> > > + int this_cpu = smp_processor_id();
> > > +
> > > + fpstate_reset(&x86_init_fpu);
> > > + current->thread.fpu = &x86_init_fpu;
> > > + per_cpu(fpu_fpregs_owner_ctx, this_cpu) = &x86_init_fpu;
> > > + x86_init_fpu.last_cpu = this_cpu;
> > > + }
> >
> > Can't x86_init_fpu be declared inside the block above?
>
> As a function-local static? I think globals are better defined in a visible
> fashion, not hidden among local variables where they are easy to overlook.
OK, but please see below.
> Yeah. Something like the delta patch below?
LGTM. And the whole patch too, although I don't think I can review it ;)
but... Ingo, let me ask 2 stupid questions.
1. Can you split this patch? I mean, 1/2 should add something like
struct fpu *x86_task_fpu(struct task_struct *task)
{
return &target->thread.fpu;
}
somewhere in arch/x86/include and update all the users of ->thread.fpu
to use the new helper. No functional changes.
This way 2/2 which actually turns .fpu into a pointer will be MUCH simpler.
2. Now, 2/2 should change the new helper above to
return target->thread.fpu;
But! why do we need the thread_struct.fpu pointer at all? Can't we simply have
struct fpu *x86_task_fpu(struct task_struct *task)
{
return (void *)task + sizeof(*task);
}
? This is what fpu_clone() (with your patch) does anyway.
Yes, this needs some changes:
- exit_thread() - trivial
- arch_dup_task_struct() clears thread.fpu, but I guess this is unnecessary
- fpu_clone() initializes dst->thread.fpu, no longer needed
- finally, fpu__init_system_early_generic() which initializes the
init_task.thread.fpu pointer.
But this doesn't look difficult? Although I don't understand the magic in
arch/x86/kernel/vmlinux.lds.S ...
Oleg.