mirror of
https://github.com/torvalds/linux
synced 2024-11-05 18:23:50 +00:00
bpf: offload: add priv field for drivers
Currently bpf_offload_dev does not have any priv pointer, forcing the drivers to work backwards from the netdev in program metadata. This is not great given programs are conceptually associated with the offload device, and it means one or two unnecessary deferences. Add a priv pointer to bpf_offload_dev. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:
parent
ebbed0f46e
commit
dd27c2e3d0
5 changed files with 16 additions and 8 deletions
|
@ -465,7 +465,7 @@ static int nfp_bpf_init(struct nfp_app *app)
|
|||
app->ctrl_mtu = nfp_bpf_ctrl_cmsg_mtu(bpf);
|
||||
}
|
||||
|
||||
bpf->bpf_dev = bpf_offload_dev_create(&nfp_bpf_dev_ops);
|
||||
bpf->bpf_dev = bpf_offload_dev_create(&nfp_bpf_dev_ops, bpf);
|
||||
err = PTR_ERR_OR_ZERO(bpf->bpf_dev);
|
||||
if (err)
|
||||
goto err_free_neutral_maps;
|
||||
|
|
|
@ -185,8 +185,6 @@ static void nfp_prog_free(struct nfp_prog *nfp_prog)
|
|||
|
||||
static int nfp_bpf_verifier_prep(struct bpf_prog *prog)
|
||||
{
|
||||
struct nfp_net *nn = netdev_priv(prog->aux->offload->netdev);
|
||||
struct nfp_app *app = nn->app;
|
||||
struct nfp_prog *nfp_prog;
|
||||
int ret;
|
||||
|
||||
|
@ -197,7 +195,7 @@ static int nfp_bpf_verifier_prep(struct bpf_prog *prog)
|
|||
|
||||
INIT_LIST_HEAD(&nfp_prog->insns);
|
||||
nfp_prog->type = prog->type;
|
||||
nfp_prog->bpf = app->priv;
|
||||
nfp_prog->bpf = bpf_offload_dev_priv(prog->aux->offload->offdev);
|
||||
|
||||
ret = nfp_prog_prepare(nfp_prog, prog->insnsi, prog->len);
|
||||
if (ret)
|
||||
|
|
|
@ -248,7 +248,7 @@ static int nsim_bpf_create_prog(struct netdevsim *ns, struct bpf_prog *prog)
|
|||
|
||||
static int nsim_bpf_verifier_prep(struct bpf_prog *prog)
|
||||
{
|
||||
struct netdevsim *ns = netdev_priv(prog->aux->offload->netdev);
|
||||
struct netdevsim *ns = bpf_offload_dev_priv(prog->aux->offload->offdev);
|
||||
|
||||
if (!ns->bpf_bind_accept)
|
||||
return -EOPNOTSUPP;
|
||||
|
@ -589,7 +589,8 @@ int nsim_bpf_init(struct netdevsim *ns)
|
|||
if (IS_ERR_OR_NULL(ns->sdev->ddir_bpf_bound_progs))
|
||||
return -ENOMEM;
|
||||
|
||||
ns->sdev->bpf_dev = bpf_offload_dev_create(&nsim_bpf_dev_ops);
|
||||
ns->sdev->bpf_dev = bpf_offload_dev_create(&nsim_bpf_dev_ops,
|
||||
ns);
|
||||
err = PTR_ERR_OR_ZERO(ns->sdev->bpf_dev);
|
||||
if (err)
|
||||
return err;
|
||||
|
|
|
@ -773,8 +773,9 @@ int bpf_map_offload_get_next_key(struct bpf_map *map,
|
|||
bool bpf_offload_prog_map_match(struct bpf_prog *prog, struct bpf_map *map);
|
||||
|
||||
struct bpf_offload_dev *
|
||||
bpf_offload_dev_create(const struct bpf_prog_offload_ops *ops);
|
||||
bpf_offload_dev_create(const struct bpf_prog_offload_ops *ops, void *priv);
|
||||
void bpf_offload_dev_destroy(struct bpf_offload_dev *offdev);
|
||||
void *bpf_offload_dev_priv(struct bpf_offload_dev *offdev);
|
||||
int bpf_offload_dev_netdev_register(struct bpf_offload_dev *offdev,
|
||||
struct net_device *netdev);
|
||||
void bpf_offload_dev_netdev_unregister(struct bpf_offload_dev *offdev,
|
||||
|
|
|
@ -35,6 +35,7 @@ static DECLARE_RWSEM(bpf_devs_lock);
|
|||
struct bpf_offload_dev {
|
||||
const struct bpf_prog_offload_ops *ops;
|
||||
struct list_head netdevs;
|
||||
void *priv;
|
||||
};
|
||||
|
||||
struct bpf_offload_netdev {
|
||||
|
@ -669,7 +670,7 @@ void bpf_offload_dev_netdev_unregister(struct bpf_offload_dev *offdev,
|
|||
EXPORT_SYMBOL_GPL(bpf_offload_dev_netdev_unregister);
|
||||
|
||||
struct bpf_offload_dev *
|
||||
bpf_offload_dev_create(const struct bpf_prog_offload_ops *ops)
|
||||
bpf_offload_dev_create(const struct bpf_prog_offload_ops *ops, void *priv)
|
||||
{
|
||||
struct bpf_offload_dev *offdev;
|
||||
int err;
|
||||
|
@ -688,6 +689,7 @@ bpf_offload_dev_create(const struct bpf_prog_offload_ops *ops)
|
|||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
offdev->ops = ops;
|
||||
offdev->priv = priv;
|
||||
INIT_LIST_HEAD(&offdev->netdevs);
|
||||
|
||||
return offdev;
|
||||
|
@ -700,3 +702,9 @@ void bpf_offload_dev_destroy(struct bpf_offload_dev *offdev)
|
|||
kfree(offdev);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(bpf_offload_dev_destroy);
|
||||
|
||||
void *bpf_offload_dev_priv(struct bpf_offload_dev *offdev)
|
||||
{
|
||||
return offdev->priv;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(bpf_offload_dev_priv);
|
||||
|
|
Loading…
Reference in a new issue