__get_user_8 / __put_user_8

Andrew Jones ajones at ventanamicro.com
Wed Jan 31 05:35:20 PST 2024


Hi all,

I'm looking for thoughts on riscv32 __get_user_8's and __put_user_8's use
of the typeof(x-x) trick. The trick is nifty because it ensures we use an
integer type of correct size and sign when x is an integer type, but use
ptrdiff_t when x is a pointer, which avoids warnings about casting a
pointer to/from an integer of a different size. However, sparse complains
about this because restricted types get reduced to integers for the
arithmetic and there's nowhere to insert a __force. Furthermore, while
__get_user_8's ptrdiff_t cast looks fine, I'm not sure we want
__put_user_8 to sign-extend the 32-bit pointer before storing it in the
64-bit memory region (as its ptrdiff_t cast will do). Arguments can
probably be made for sign-extending, though, one of which being "it's
always been like that".

Anyway, I looked at x86's and arm's __inttype() and tried to consider
doing something similar, but I didn't see any foolproof way to apply a
cast of typeof(x) on everything except pointers, which makes me inclined
to leave things as they are and just let sparse complain.

Thanks,
drew



More information about the linux-riscv mailing list