Commit e1740fb6 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

nfp: add nfp_reprs_get_locked() helper

The write side of repr tables is always done under pf->lock.
Add a helper to dereference repr table pointers under protection
of that lock.
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: default avatarDirk van der Merwe <dirk.vandermerwe@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bcc93a23
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
*/ */
#include <linux/bug.h> #include <linux/bug.h>
#include <linux/lockdep.h>
#include <linux/rcupdate.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -98,14 +100,20 @@ nfp_app_ctrl_msg_alloc(struct nfp_app *app, unsigned int size, gfp_t priority) ...@@ -98,14 +100,20 @@ nfp_app_ctrl_msg_alloc(struct nfp_app *app, unsigned int size, gfp_t priority)
return skb; return skb;
} }
struct nfp_reprs *
nfp_reprs_get_locked(struct nfp_app *app, enum nfp_repr_type type)
{
return rcu_dereference_protected(app->reprs[type],
lockdep_is_held(&app->pf->lock));
}
struct nfp_reprs * struct nfp_reprs *
nfp_app_reprs_set(struct nfp_app *app, enum nfp_repr_type type, nfp_app_reprs_set(struct nfp_app *app, enum nfp_repr_type type,
struct nfp_reprs *reprs) struct nfp_reprs *reprs)
{ {
struct nfp_reprs *old; struct nfp_reprs *old;
old = rcu_dereference_protected(app->reprs[type], old = nfp_reprs_get_locked(app, type);
lockdep_is_held(&app->pf->lock));
rcu_assign_pointer(app->reprs[type], reprs); rcu_assign_pointer(app->reprs[type], reprs);
return old; return old;
......
...@@ -384,6 +384,8 @@ static inline struct net_device *nfp_app_repr_get(struct nfp_app *app, u32 id) ...@@ -384,6 +384,8 @@ static inline struct net_device *nfp_app_repr_get(struct nfp_app *app, u32 id)
struct nfp_app *nfp_app_from_netdev(struct net_device *netdev); struct nfp_app *nfp_app_from_netdev(struct net_device *netdev);
struct nfp_reprs *
nfp_reprs_get_locked(struct nfp_app *app, enum nfp_repr_type type);
struct nfp_reprs * struct nfp_reprs *
nfp_app_reprs_set(struct nfp_app *app, enum nfp_repr_type type, nfp_app_reprs_set(struct nfp_app *app, enum nfp_repr_type type,
struct nfp_reprs *reprs); struct nfp_reprs *reprs);
......
...@@ -424,9 +424,7 @@ int nfp_reprs_resync_phys_ports(struct nfp_app *app) ...@@ -424,9 +424,7 @@ int nfp_reprs_resync_phys_ports(struct nfp_app *app)
struct nfp_repr *repr; struct nfp_repr *repr;
int i; int i;
old_reprs = old_reprs = nfp_reprs_get_locked(app, NFP_REPR_TYPE_PHYS_PORT);
rcu_dereference_protected(app->reprs[NFP_REPR_TYPE_PHYS_PORT],
lockdep_is_held(&app->pf->lock));
if (!old_reprs) if (!old_reprs)
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment