Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2346484ybh; Sun, 4 Aug 2019 23:14:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqws354VN17nt1eas+FviO6/0Wn60QxwPBqbe3Ox/5PUwT7uzVSOgB5xcLNpJ/HmpXQrwx87 X-Received: by 2002:a17:902:2bc5:: with SMTP id l63mr147626640plb.30.1564985654945; Sun, 04 Aug 2019 23:14:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564985654; cv=none; d=google.com; s=arc-20160816; b=WMQlAHf5m2mUnLkKl70mh9mOW33nEZ5xo+IXypkE8A70duwd0H98/X/xCcZqxIObcM P+Bh0G/XOarRlE+uS/oZZGaY2See7roQjgFtZPfnqxh9CeMJbGkBJE7Q6eR4Pv64vAcO qsmXNIjJZ94bFLDdKFKD318/D6q2ML84pgNM7UK1vEY4LHpayuoa8MrTKFz0H++SymT3 MwYK1T1ytPi9QL3iGLKQxvc52MAc5fBUolp1iAwsLGhOkd2nmgIe7F1NSe+2u4qSNLYT NJgr69UkvJBowxUPcwgHtVXRVRMvyoqeV4MrRCRj1cEd0opmjD5KQikBwsE6ap+OQL4e KlDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=YkJPJbbjxHPdWoOl6y+2JUsOnGzg96K+XYE2gglO1fg=; b=B6Xm7kGdVA9G178+C4W+v2DkWkhaRbxR9SmfIKq3y3+zUih6qTAfC6G5d6dQmJwM4z 6RSk2LGcYFWu88vFLkLtiGNrAeB//gTeGXqhZGa1XRmEzHheeUd8/pGDbIAiYqORx3Il dsrCyWb3/qr+ocNRpDSgBpoyLTxz4F1jeckhzbnpJ6n7SOkvHIxttECV1N8UVp1DVWt7 c8wygtiMlk7OXp4f+h78JNLY66Wupryrz30D+odMI6cf4SqITZHPy8zX4wX1FrwgVV5F Q8fFbNbS9kWXlSfJNtfmaBj9O8n/V0WVUuYOT7j3mJKS2/oCbDbI8nym5V1aKcPh9tCb IPJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2TbYzjm3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x6si26704836pgq.473.2019.08.04.23.13.59; Sun, 04 Aug 2019 23:14:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2TbYzjm3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727249AbfHEGN0 (ORCPT + 99 others); Mon, 5 Aug 2019 02:13:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:46720 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725976AbfHEGN0 (ORCPT ); Mon, 5 Aug 2019 02:13:26 -0400 Received: from localhost (unknown [77.137.115.125]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 11EEB206C1; Mon, 5 Aug 2019 06:13:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564985604; bh=DEza7LipQz/yKwMh3a7hoO43mdHVY4vPsu+c7eOpmmc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=2TbYzjm38SOUrCNApTPuG9DfijA4/lcG5skmEv6yuQ6p5TbrxWoHMyk9AxcdpV9Pr 2WNAdl3jPIYDLzg//Qs492WC4fmMd8P8DlMV7nkUFZn8G0kKuc1QLC5nM5WQqKXOIB uz+gUCFUNXjkFp0BZ6Oo52sRGUdFl1yZvavpuXz4= Date: Mon, 5 Aug 2019 09:13:20 +0300 From: Leon Romanovsky To: Chuhong Yuan Cc: Saeed Mahameed , "David S . Miller" , Netdev , linux-rdma@vger.kernel.org, LKML Subject: Re: [PATCH v2] net/mlx5e: Use refcount_t for refcount Message-ID: <20190805061320.GN4832@mtr-leonro.mtl.com> References: <20190802164828.20243-1-hslester96@gmail.com> <20190804125858.GJ4832@mtr-leonro.mtl.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.0 (2019-05-25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Aug 04, 2019 at 10:44:47PM +0800, Chuhong Yuan wrote: > On Sun, Aug 4, 2019 at 8:59 PM Leon Romanovsky wrote: > > > > On Sat, Aug 03, 2019 at 12:48:28AM +0800, Chuhong Yuan wrote: > > > refcount_t is better for reference counters since its > > > implementation can prevent overflows. > > > So convert atomic_t ref counters to refcount_t. > > > > I'm not thrilled to see those automatic conversion patches, especially > > for flows which can't overflow. There is nothing wrong in using atomic_t > > type of variable, do you have in mind flow which will cause to overflow? > > > > Thanks > > I have to say that these patches are not done automatically... > Only the detection of problems is done by a script. > All conversions are done manually. Even worse, you need to audit usage of atomic_t and replace there it can overflow. > > I am not sure whether the flow can cause an overflow. It can't. > But I think it is hard to ensure that a data path is impossible > to have problems in any cases including being attacked. It is not data path, and I doubt that such conversion will be allowed in data paths without proving that no performance regression is introduced. > > So I think it is better to do this minor revision to prevent > potential risk, just like we have done in mlx5/core/cq.c. mlx5/core/cq.c is a different beast, refcount there means actual users of CQ which are limited in SW, so in theory, they have potential to be overflown. It is not the case here, there your are adding new port. There is nothing wrong with atomic_t. Thanks > > Regards, > Chuhong > > > > > > > Signed-off-by: Chuhong Yuan > > > --- > > > Changes in v2: > > > - Add #include. > > > > > > drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.c | 9 +++++---- > > > 1 file changed, 5 insertions(+), 4 deletions(-) > > > > > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.c > > > index b9d4f4e19ff9..148b55c3db7a 100644 > > > --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.c > > > +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.c > > > @@ -32,6 +32,7 @@ > > > > > > #include > > > #include > > > +#include > > > #include > > > #include > > > #include "mlx5_core.h" > > > @@ -48,7 +49,7 @@ struct mlx5_vxlan { > > > > > > struct mlx5_vxlan_port { > > > struct hlist_node hlist; > > > - atomic_t refcount; > > > + refcount_t refcount; > > > u16 udp_port; > > > }; > > > > > > @@ -113,7 +114,7 @@ int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port) > > > > > > vxlanp = mlx5_vxlan_lookup_port(vxlan, port); > > > if (vxlanp) { > > > - atomic_inc(&vxlanp->refcount); > > > + refcount_inc(&vxlanp->refcount); > > > return 0; > > > } > > > > > > @@ -137,7 +138,7 @@ int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port) > > > } > > > > > > vxlanp->udp_port = port; > > > - atomic_set(&vxlanp->refcount, 1); > > > + refcount_set(&vxlanp->refcount, 1); > > > > > > spin_lock_bh(&vxlan->lock); > > > hash_add(vxlan->htable, &vxlanp->hlist, port); > > > @@ -170,7 +171,7 @@ int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port) > > > goto out_unlock; > > > } > > > > > > - if (atomic_dec_and_test(&vxlanp->refcount)) { > > > + if (refcount_dec_and_test(&vxlanp->refcount)) { > > > hash_del(&vxlanp->hlist); > > > remove = true; > > > } > > > -- > > > 2.20.1 > > >