Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753111AbcKIJp7 (ORCPT ); Wed, 9 Nov 2016 04:45:59 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36400 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751615AbcKIJpx (ORCPT ); Wed, 9 Nov 2016 04:45:53 -0500 Date: Wed, 9 Nov 2016 17:45:46 +0800 From: Zhiyi Sun To: Daniel Borkmann Cc: bblanco@plumgrid.com, Tariq Toukan , Yishai Hadas , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, alexei.starovoitov@gmail.com Subject: Re: [PATCH] net/mlx4_en: Fix bpf_prog_add ref_cnt in mlx4 Message-ID: <20161109094546.jtmzc4xwtaavzcnt@ubuntu> References: <20161109073544.jbufjqn7y7oa6ptg@ubuntu> <5822E6DB.40204@iogearbox.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5822E6DB.40204@iogearbox.net> User-Agent: Mutt/1.6.2-neo (2016-08-21) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2179 Lines: 52 On Wed, Nov 09, 2016 at 10:05:31AM +0100, Daniel Borkmann wrote: > On 11/09/2016 08:35 AM, Zhiyi Sun wrote: > > There are rx_ring_num queues. Each queue will load xdp prog. So > > bpf_prog_add() should add rx_ring_num to ref_cnt. > > > > Signed-off-by: Zhiyi Sun > > Your analysis looks incorrect to me. Please elaborate in more detail why > you think current code is buggy ... > Yes, you are correct. My patch is incorrect. It is not a bug. > Call path is dev_change_xdp_fd(), which does bpf_prog_get_type() on the > fd. This already takes a ref and only drops it in case of error. Thus > in mlx4_xdp_set(), you only need priv->rx_ring_num - 1 refs for the rest > of the rings, so that dropping refs from old_prog makes sure we release > it again. Looks correct to me (maybe a comment would have helped there). > I thought mlx4's code is incorrect because in mlx5's driver, function mlx5e_xdp_set() calls a pair of bpf_prog_add/put, the number of add and put to the refs are same. I didn't notice that one "add" has been called in its calller. So, it seems that mlx5's code is incorrect, right? > > drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c > > index 12c99a2..d25e150 100644 > > --- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c > > +++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c > > @@ -2650,7 +2650,7 @@ static int mlx4_xdp_set(struct net_device *dev, struct bpf_prog *prog) > > */ > > if (priv->xdp_ring_num == xdp_ring_num) { > > if (prog) { > > - prog = bpf_prog_add(prog, priv->rx_ring_num - 1); > > + prog = bpf_prog_add(prog, priv->rx_ring_num); > > if (IS_ERR(prog)) > > return PTR_ERR(prog); > > } > > @@ -2680,7 +2680,7 @@ static int mlx4_xdp_set(struct net_device *dev, struct bpf_prog *prog) > > } > > > > if (prog) { > > - prog = bpf_prog_add(prog, priv->rx_ring_num - 1); > > + prog = bpf_prog_add(prog, priv->rx_ring_num); > > if (IS_ERR(prog)) > > return PTR_ERR(prog); > > } > > >