Re: [PATCH v4 1/7] x86/fsgsbase/64: Introduce FS/GS base helper functions

From: Andy Lutomirski
Date: Fri Jun 22 2018 - 10:51:46 EST


On Fri, Jun 22, 2018 at 7:28 AM Thomas Gleixner <tglx@xxxxxxxxxxxxx> wrote:
>
> On Wed, 20 Jun 2018, Chang S. Bae wrote:
> > +void write_fsbase(unsigned long fsbase)
> > +{
> > + /* set the selector to 0 to not confuse __switch_to */
>
> 'to not confuse __switch_to' is not that helpful of a comment as it
> requires to stare into __switch_to to figure out what might get confused
> there. Please write it out why this needs to be done in technical terms.
>
> > + loadseg(FS, 0);
> > + wrmsrl(MSR_FS_BASE, fsbase);
> > +}
> > +
> > +void write_inactive_gsbase(unsigned long gsbase)
> > +{
> > + /* set the selector to 0 to not confuse __switch_to */
>
> Ditto
>
> > + loadseg(GS, 0);
> > + wrmsrl(MSR_KERNEL_GS_BASE, gsbase);
> > +}
> > +
> > +unsigned long read_task_fsbase(struct task_struct *task)
> > +{
> > + unsigned long fsbase;
> > +
> > + if (task == current) {
> > + fsbase = read_fsbase();
> > + } else {
> > + /*
> > + * XXX: This will not behave as expected if called
> > + * if fsindex != 0. This preserves an existing bug
> > + * that will be fixed.
>
> I'm late to this party, but let me ask the obvious question:
>
> Why is the existing bug not fixed as the first patch in the series?

IIRC that was how I did it in the old version of this code. I think
it did it because it was less messy to fix the bug after cleaning up
the code, but I could be remembering wrong.