Subject: Re: [patch net-next v7 5/9] genetlink: introduce per-sock family private storage

From: Jiri Pirko <[email-masked]>
Date: Fri, 15 Dec 2023 11:17:14 +0100

Fri, Dec 15, 2023 at 04:23:58AM CET, [email-masked] wrote:
>On Thu, 14 Dec 2023 19:15:45 +0100 Jiri Pirko wrote:
>> - converted family->sock_priv_list to family->sock_privs xarray
>>   and use it to store the per-socket privs, use sock pointer as
>>   an xarrar index. This made the code much simpler
>
>Nice! 
>
>FWIW I think I remember Willy saying that storing pointers in xarray is
>comparatively inefficient / slow, but we can cross that bridge later.
>
>> +void *__genl_sk_priv_get(struct genl_family *family, struct sock *sk)
>> +{
>> +	if (WARN_ON_ONCE(!family->sock_privs))
>> +		return NULL;
>> +	return xa_load(family->sock_privs, (unsigned long) sk);
>> +}
>> +
>> +/**
>> + * genl_sk_priv_get - Get family private pointer for socket
>> + *
>> + * @family: family
>> + * @sk: socket
>> + *
>> + * Lookup a private memory for a Generic netlink family and specified socket.
>> + * Allocate the private memory in case it was not already done.
>> + *
>> + * Return: valid pointer on success, otherwise negative error value
>> + * encoded by ERR_PTR().
>
>nit: probably better if __genl_sk_priv_get() returned an error pointer
>     if family is broken, save ourselves the bot-generated "fixes"..

Wait, let me make your suggestion clear. Do you suggest to remove the
WARN_ON_ONCE from __genl_sk_priv_get() as well?

To put it in code:
void *__genl_sk_priv_get(struct genl_family *family, struct sock *sk)
{
	if (WARN_ON_ONCE(!family->sock_privs))
		return ERR_PTR(-EINVAL);
	return xa_load(family->sock_privs, (unsigned long) sk);
}
OR:
void *__genl_sk_priv_get(struct genl_family *family, struct sock *sk)
{
	if (!family->sock_privs)
		return ERR_PTR(-EINVAL);
	return xa_load(family->sock_privs, (unsigned long) sk);
}
?

Thanks!

>
>> + */
>> +void *genl_sk_priv_get(struct genl_family *family, struct sock *sk)
>> +{
>> +	void *priv, *old_priv;
>> +
>> +	priv = __genl_sk_priv_get(family, sk);
>> +	if (priv)
>> +		return priv;
>