Re: [PATCH 2/3] x86/fpu: Remove the thread::fpu pointer

From: Ingo Molnar
Date: Sat Jun 08 2024 - 03:26:48 EST



* Ingo Molnar <mingo@xxxxxxxxxx> wrote:

>
> * Ingo Molnar <mingo@xxxxxxxxxx> wrote:
>
> >
> > * Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
> >
> > > On 06/05, Ingo Molnar wrote:
> > > >
> > > > @@ -591,13 +591,11 @@ int fpu_clone(struct task_struct *dst, unsigned long clone_flags, bool minimal,
> > > > * This is safe because task_struct size is a multiple of cacheline size.
> > > > */
> > > > struct fpu *dst_fpu = (void *)dst + sizeof(*dst);
> > > > - struct fpu *src_fpu = current->thread.fpu;
> > > > + struct fpu *src_fpu = x86_task_fpu(current);
> > >
> > > I think this patch can also change
> > >
> > > struct fpu *dst_fpu = (void *)dst + sizeof(*dst);
> > >
> > > above to use x86_task_fpu(dst).
> >
> > Yeah, so I'd prefer to keep it open coded, because of the comment and the
> > debug check makes a lot more sense if the pointer calculation is visible:
>
> On a second thought I changed it to your suggested variant:
>
> struct fpu *src_fpu = x86_task_fpu(current);
> struct fpu *dst_fpu = x86_task_fpu(dst);
>
> because you are right, it's in fact easier to read this way.

On a third thought, while more readable, this doesn't work in practice with
the current scheme, because x86_task_fpu() gets called on kthreads in
fpu_clone(), which trips up the new debugging code.

We could resolve it by special-casing PF_KTHREAD here too, but that weakens
the whole readability argument. I'll leave it as-is for now.

Thanks,

Ingo