On Sun, Mar 3, 2024 at 9:24 PM Uros Bizjak <ubizjak@xxxxxxxxx> wrote: > > 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 FYI: gcc-14 compiles this testcase: --cut here-- __seg_gs int a; __typeof_unqual__(a) b; int foo (void) { return a; } int bar (void) { return b; } --cut here-- to (gcc -O2): foo: movl %gs:a(%rip), %eax ret bar: movl b(%rip), %eax ret So, it *does* strip the __seg_gs qualifier here. Uros.