Re: [PATCH v2 07/11] x86/percpu/64: Use relative percpu offsets

From: Uros Bizjak
Date: Fri Oct 27 2023 - 02:09:24 EST


On Fri, Oct 27, 2023 at 4:09 AM Brian Gerst <brgerst@xxxxxxxxx> wrote:
>
> On Thu, Oct 26, 2023 at 2:47 PM Uros Bizjak <ubizjak@xxxxxxxxx> wrote:
> >
> > On Thu, Oct 26, 2023 at 6:01 PM Brian Gerst <brgerst@xxxxxxxxx> wrote:
> > >
> > > The percpu section is currently linked at virtual address 0, because
> > > older compilers hardcoded the stack protector canary value at a fixed
> > > offset from the start of the GS segment. Now that the canary is a
> > > normal percpu variable, the percpu section can be linked normally.
> > > This means that x86-64 will calculate percpu offsets like most other
> > > architectures, as the delta between the initial percpu address and the
> > > dynamically allocated memory.
> >
> > The comments above MSR_GS_BASE setup should be reviewed or removed. I
> > don't think they need to be set up to access stack canary, they are
> > just clearing MSR now.
>
> GSBASE is deliberately set to zero offset on SMP for boot because we
> want any percpu accesses (including stack protector) to use the
> initial percpu area until the full percpu memory is allocated. It's
> possible that more stack protector checks could sneak back into the
> early boot code, and after the conversion to relative percpu offsets
> they would work properly again. I just didn't reenable them because
> they are unnecessary that early.

Thanks for the explanation, perhaps this non-obvious fact should be
mentioned in the comment .

Thanks,
Uros.

> Brian Gerst