Commit 97bc402d authored by Daniel Borkmann's avatar Daniel Borkmann Committed by David S. Miller

bpf, mlx5: fix mlx5e_create_rq taking reference on prog

In mlx5e_create_rq(), when creating a new queue, we call bpf_prog_add() but
without checking the return value. bpf_prog_add() can fail since 92117d84
("bpf: fix refcnt overflow"), so we really must check it. Take the reference
right when we assign it to the rq from priv->xdp_prog, and just drop the
reference on error path. Destruction in mlx5e_destroy_rq() looks good, though.

Fixes: 86994156 ("net/mlx5e: XDP fast RX drop bpf programs support")
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f81a8a02
...@@ -513,7 +513,13 @@ static int mlx5e_create_rq(struct mlx5e_channel *c, ...@@ -513,7 +513,13 @@ static int mlx5e_create_rq(struct mlx5e_channel *c,
rq->channel = c; rq->channel = c;
rq->ix = c->ix; rq->ix = c->ix;
rq->priv = c->priv; rq->priv = c->priv;
rq->xdp_prog = priv->xdp_prog;
rq->xdp_prog = priv->xdp_prog ? bpf_prog_inc(priv->xdp_prog) : NULL;
if (IS_ERR(rq->xdp_prog)) {
err = PTR_ERR(rq->xdp_prog);
rq->xdp_prog = NULL;
goto err_rq_wq_destroy;
}
rq->buff.map_dir = DMA_FROM_DEVICE; rq->buff.map_dir = DMA_FROM_DEVICE;
if (rq->xdp_prog) if (rq->xdp_prog)
...@@ -590,12 +596,11 @@ static int mlx5e_create_rq(struct mlx5e_channel *c, ...@@ -590,12 +596,11 @@ static int mlx5e_create_rq(struct mlx5e_channel *c,
rq->page_cache.head = 0; rq->page_cache.head = 0;
rq->page_cache.tail = 0; rq->page_cache.tail = 0;
if (rq->xdp_prog)
bpf_prog_add(rq->xdp_prog, 1);
return 0; return 0;
err_rq_wq_destroy: err_rq_wq_destroy:
if (rq->xdp_prog)
bpf_prog_put(rq->xdp_prog);
mlx5_wq_destroy(&rq->wq_ctrl); mlx5_wq_destroy(&rq->wq_ctrl);
return err; return err;
......
...@@ -696,6 +696,7 @@ struct bpf_prog *bpf_prog_inc(struct bpf_prog *prog) ...@@ -696,6 +696,7 @@ struct bpf_prog *bpf_prog_inc(struct bpf_prog *prog)
{ {
return bpf_prog_add(prog, 1); return bpf_prog_add(prog, 1);
} }
EXPORT_SYMBOL_GPL(bpf_prog_inc);
static struct bpf_prog *__bpf_prog_get(u32 ufd, enum bpf_prog_type *type) static struct bpf_prog *__bpf_prog_get(u32 ufd, enum bpf_prog_type *type)
{ {
......
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