[PATCH v4 1/2] kho: add KHOSER_COPY_TYPE(UN)SAFE for phys copy

tarunsahu at google.com tarunsahu at google.com
Tue Jun 23 02:57:36 PDT 2026


Mike Rapoport <rppt at kernel.org> writes:

> On Mon, 22 Jun 2026 22:57:35 +0000, Tarun Sahu <tarunsahu at google.com> wrote:
>> Adding KHOSER_COPY_TYPESAFE and KHOSER_COPY_TYPEUNSAFE to copy one
>> serializeable pointer to another. It basically allows copy of phys val
>> of the serializeable pointer.
>
> Please update the commit message :)
>
>>
>>
>> diff --git a/include/linux/kho/abi/kexec_handover.h b/include/linux/kho/abi/kexec_handover.h
>> index 5e2eb8519bda..c1b61d875dcc 100644
>> --- a/include/linux/kho/abi/kexec_handover.h
>> +++ b/include/linux/kho/abi/kexec_handover.h
>> @@ -139,6 +139,17 @@
>>  		(typeof((s).ptr))((s).phys ? phys_to_virt((s).phys) : NULL); \
>>  	})
>>  
>> +/* Copies one serializable pointer to another. */
>> +#define KHOSER_COPY_PTR(dest, src) \
>> +	({ \
>> +		static_assert( \
>> +			__builtin_types_compatible_p(typeof((dest).ptr), typeof((src).ptr)) || \
>> +			__builtin_types_compatible_p(typeof((dest).ptr), void *) || \
>> +			__builtin_types_compatible_p(typeof((src).ptr), void *), \
>> +			"pointer type mismatch in KHOSER_COPY_PTR" \
>> +		); \
>> +		(dest).phys = (src).phys; \
>> +	})
>
> I'd suggest declaring local variables for the pointers and verifying
> their compatibility. E.g.
>
> 	({								\
> 		typeof((dest).ptr) __dst;				\
> 		typeof((src).ptr) __src;				\
> 		static_assert(						\
> 			__builtin_types_compatible_p(__dst, __src)) ||	\
> 			__builtin_types_compatible_p(__dst, void *) ||	\
> 			__builtin_types_compatible_p(__src, void *),	\
> 			"pointer type mismatch in KHOSER_COPY_PTR"	\
> 		); \
> 		(dest).phys = (src).phys; \
> 	})
>
> IMO it's easier to decipher this way.

Okay, Will update in next revision.
Thanks for reviewing.


~Tarun
>
> -- 
> Sincerely yours,
> Mike.



More information about the kexec mailing list