On Mon, Jan 09, 2023 at 04:02:33PM -0600, Linus Torvalds wrote: > On Mon, Jan 9, 2023 at 10:29 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote: > > > > I ran into a ton of casting trouble when compiling kernel/fork.c which > > uses this_cpu_cmpxchg() on a pointer type and the compiler hates casting > > pointers to an integer that is not the exact same size. > > Ahh. Yeah - not because that code needs or wants the 128-bit case, but > because the macro expands to all sizes in a switch statement, so the > compiler sees all the cases even if only one is then statically > picked. > > So the silly casts are for all the cases that never matter. > > Annoying. Yes, very. This seems to compile (and boot). Let me go update the others and push it out for the robots to have a go. #define percpu_cmpxchg128_op(size, qual, _var, _oval, _nval) \ ({ \ union { \ typeof(_var) full; \ struct { \ u64 low, high; \ }; \ } old__, new__; \ \ old__.full = _oval; \ new__.full = _nval; \ \ asm qual ("cmpxchg16b " __percpu_arg([var]) \ : [var] "+m" (_var), \ "+a" (old__.low), \ "+d" (old__.high) \ : "b" (new__.low), \ "c" (new__.high) \ : "memory"); \ \ old__.full; \ })