Re: [RFC][PATCH 11/12] slub: Replace cmpxchg_double()

From
Peter Zijlstra <peterz@infradead.org>
Date
2023-01-10 10:29:24
Also in
linux-arch, linux-crypto, linux-iommu, linux-mm, linux-s390, lkml
Reply to
Linus Torvalds, 2023-01-09
On Mon, Jan 09, 2023 at 04:02:33PM -0600, Linus Torvalds wrote:
On Mon, Jan 9, 2023 at 10:29 AM Peter Zijlstra [off-list ref] wrote:
quoted
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;							\
})
Thread (57 messages) 57 messages, 15 authors, last reply 2023-01-12
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help