> -----Original Message-----
> From: Intel-wired-lan <[email protected]> On Behalf
> Of Przemek Kitszel
> Sent: Monday, March 23, 2026 2:22 PM
> To: Jiri Pirko <[email protected]>; [email protected]; Jakub
> Kicinski <[email protected]>
> Cc: Kitszel, Przemyslaw <[email protected]>; Eric Dumazet
> <[email protected]>; [email protected]; Simon Horman
> <[email protected]>; Nguyen, Anthony L <[email protected]>;
> Paolo Abeni <[email protected]>; David S. Miller <[email protected]>
> Subject: [Intel-wired-lan] [PATCH net-next] devlink: unify
> devlink_shd_get_priv() into devlink_priv()
> 
> Unify access API to shared devlink priv data with normal devlink.
> 
> Thanks to Jiri Piro, we now have ability to create shared devlink
Piro -> Pirko


> instances [1]. Introduction series have added usege of those for mlx,
usege -> usage


> but without priv data attached to the shared devlink.
> 
> Current API makes it possible to access shared devlink instance's priv
> data:
> 
>       void *devlink_shd_get_priv(struct devlink *devlink);
> 
> but it is easy to to forget (especially during rebase from "before
easy to to forget -> easy to forget


> shared devlinks" era) and call:
> 
>       void *devlink_priv(struct devlink *devlink);
> 
> which even has the same signature, so it's hard to catch the error.
> 
> New proposed API unifies both calls into one, without any increase in
> the observerd struct size. (Alternative could be to store additional
observerd -> observed


> pointer, set during devlink_alloc).
> 
> Unexport the less convenient API call.
> 
> [1] commit 411ad0605875 ("Merge branch 'devlink-introduce-shared-
> devlink-instance-for-pfs-on-same-chip'")
> [1] https://lore.kernel.org/all/20260312100407.551173-1-
> [email protected]
> 
> Signed-off-by: Przemek Kitszel <[email protected]>
> ---
> sorry that I have not mentioned it during [1] review, it got obvious
> for me only after working with the code
> ---
>  net/devlink/devl_internal.h |  4 ++++
>  net/devlink/core.c          |  3 +++
>  net/devlink/sh_dev.c        | 11 ++++++++---
>  3 files changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h
> index 7dfb7cdd2d23..abbe308ee9bd 100644
> --- a/net/devlink/devl_internal.h
> +++ b/net/devlink/devl_internal.h
> @@ -58,6 +58,7 @@ struct devlink {
>       struct mutex lock;
>       struct lock_class_key lock_key;
>       u8 reload_failed:1;
> +     u8 is_shd:1;
>       refcount_t refcount;
>       struct rcu_work rwork;
>       struct devlink_rel *rel;
> @@ -72,6 +73,9 @@ struct devlink *__devlink_alloc(const struct
> devlink_ops *ops, size_t priv_size,
>                               struct net *net, struct device *dev,
>                               const struct device_driver *dev_driver);
> 
> +/* Get private data from shared devlink instance */ void
> +*devlink_shd_get_priv(struct devlink *devlink);
> +
>  #define devl_warn(devlink, format, args...)                          \
>       do {                                                            \
>               if ((devlink)->dev)                                     \
> diff --git a/net/devlink/core.c b/net/devlink/core.c index
> eeb6a71f5f56..4c97e2e2c073 100644
> --- a/net/devlink/core.c
> +++ b/net/devlink/core.c
> @@ -232,6 +232,9 @@ int devlink_rel_devlink_handle_put(struct sk_buff
> *msg, struct devlink *devlink,
> 
>  void *devlink_priv(struct devlink *devlink)  {
> +     if (devlink->is_shd)
> +             return devlink_shd_get_priv(devlink);
I'm afraid it can cause recursion, if you didn't modify the function:
void *devlink_shd_get_priv(struct devlink *devlink)
{
    struct devlink_shd *shd = devlink_priv(devlink);

> +
>       return &devlink->priv;
>  }

...

>       if (refcount_dec_and_test(&shd->refcount))
>               devlink_shd_destroy(shd);
>       mutex_unlock(&shd_mutex);
> @@ -159,4 +165,3 @@ void *devlink_shd_get_priv(struct devlink
> *devlink)
> 
>       return shd->priv;
>  }
> -EXPORT_SYMBOL_GPL(devlink_shd_get_priv);
> --
> 2.39.3

Reply via email to