On Sun, Mar 3, 2024 at 9:21 PM Uros Bizjak <ubizjak@xxxxxxxxx> wrote: > > On Sun, Mar 3, 2024 at 9:10 PM Thomas Gleixner <tglx@xxxxxxxxxxxxx> wrote: > > > > On Sun, Mar 03 2024 at 20:03, Uros Bizjak wrote: > > > On Sun, Mar 3, 2024 at 5:31 PM Thomas Gleixner <tglx@xxxxxxxxxxxxx> wrote: > > >> I did not follow the __set_gs work closely, so I don't know whether Uros > > >> ever tried to actually mark the per CPU variable __set_gs right away, > > >> which would obviously catch the above 'foo' nonsense. > > > > > > No, because [1]: > > > > > > "gcc does not provide a way to remove segment qualifiers, which is needed > > > to use typeof() to create local instances of the per-cpu variable. For > > > this reason, do not use the segment qualifier for per-cpu variables, and > > > do casting using the segment qualifier instead." > > > > Right. I just figured that out myself when playing with it in user > > space. > > > > That's so sad because it would provide us compiler based __percpu > > validation. > > Unfortunately, the c compiler can't strip qualifiers, so typeof() is > of limited use also when const and volatile qualifiers are used. > Perhaps some extension could be introduced to c standard to provide an > unqualified type, e.g. typeof_unqual(). Oh, there is one in C23 [1]. [1] https://en.cppreference.com/w/c/language/typeof Uros.