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

From: Jakub Kicinski <[email-masked]>
Date: Thu, 14 Dec 2023 19:23:58 -0800

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"..

> + */
> +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;