[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZXwnqqsFPDhRUNBy@nanopsycho>
Date: Fri, 15 Dec 2023 11:17:14 +0100
From: Jiri Pirko <jiri@...nulli.us>
To: Jakub Kicinski <kuba@...nel.org>
Cc: netdev@...r.kernel.org, pabeni@...hat.com, davem@...emloft.net,
edumazet@...gle.com, jacob.e.keller@...el.com, jhs@...atatu.com,
johannes@...solutions.net, andriy.shevchenko@...ux.intel.com,
amritha.nambiar@...el.com, sdf@...gle.com, horms@...nel.org,
przemyslaw.kitszel@...el.com
Subject: Re: [patch net-next v7 5/9] genetlink: introduce per-sock family
private storage
Fri, Dec 15, 2023 at 04:23:58AM CET, kuba@...nel.org 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;
>
Powered by blists - more mailing lists