Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2381315ybh; Sun, 4 Aug 2019 23:56:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqzgyptFvlt0XNsswENruYN6TTr6Ufdxqsv8DLnTGZ6Id/YWtGpNw44rHcZT3lxFOlsTevo0 X-Received: by 2002:a62:8f91:: with SMTP id n139mr31328595pfd.48.1564988215914; Sun, 04 Aug 2019 23:56:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564988215; cv=none; d=google.com; s=arc-20160816; b=Hsx1nOx7Yv7CDirPxOFUZsaJPGppkvOlHrdAOCbW9NvUgzFNP+JUVfUt1ygnA6/GuH WvxeL2+eJDCA+0C89T+OtS/BcgNcvoC9FD15bJ6IaFFkyoYn9MtS/C3/BT4PuCVIbT7o mFeWhZckYQMo25WjMG29I9BtwTpxfTb9YaHZJxZijNW5nymqh61AEdfcx0oM4GWHvqI2 ItAsPAW8oUrBwLf5fRy8dgBmbjgtbQvRk3j/wYP29h9NBo70NT8DetY1xOU0vZKcUBK4 tvnIHKKrGsaF6KuxRIYtvvzPecQNb7LKqR9/Uxy83v8wLxvHx/xqhLydzSnuydBl58iJ lObw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=2vcIiINY4WBP+S4p7ZvCljxe/AGpBFsXIl5B5dC7+jY=; b=y/bYObY8LCwA6vWlHevEcoYbToupheMOgRUFCWd0oMDUQrC3nXBjTRj3H2ciR6CBZV +hIWr4P6DGZBJmFegM/l1Q3M1WtCb46xMZ7fsRpzvYNUrvmV/N6U2WF7XVJdd23u4MwZ XSN7qHGO3CINRn/cKmciX/UhDjyoBJl5vNprT06OUeE2TRkGtg4t6YcS9sVVH2mb6Q1z f3jDrNcTPJCl3jntQXkn+tygn9aeXvvxAB6pTL5fWdVI3jfNXNBSRcKMQcF0YCUfBriM RCqNEP5Ch53giQ7F9E803f6ZWMFIN13XATvhqBgIxNIarN9UbW1rBWLfaxOFk3Le6rZ3 ZFOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IGZvj4Ig; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x2si43747787pgp.475.2019.08.04.23.56.40; Sun, 04 Aug 2019 23:56:55 -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=@gmail.com header.s=20161025 header.b=IGZvj4Ig; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727497AbfHEGzs (ORCPT + 99 others); Mon, 5 Aug 2019 02:55:48 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:40929 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726587AbfHEGzs (ORCPT ); Mon, 5 Aug 2019 02:55:48 -0400 Received: by mail-ed1-f67.google.com with SMTP id k8so77600679eds.7; Sun, 04 Aug 2019 23:55:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2vcIiINY4WBP+S4p7ZvCljxe/AGpBFsXIl5B5dC7+jY=; b=IGZvj4IgmpHw+kKQTtY8eeb5E9cDO3t0ezYt8tkNMicugTeGnGIQ7+XxTUdxszd8qU tm0/jRpIWihYTtvPPiWRHkiXFnslsPz1U67otEH+hSX2gDtw38tvjxjKw5jXUVcAjbji Sef3EjUl9wORFtI68cJqtqXCtFhbVd/9o40ndI8II/QaM2ZbHB/ovA1T/1GaxbBLovhZ mZYpjg3DTgTBOsTyoboXlxBwe8Bw4f5hzg6Mk4zpTsbzrBMD9vkv3wGQDNLoNVRmZQA2 1YnwyBDVkjAJADw/cf4V3UdeDkSn/7+P2BCV9sPKO8aKKZVwfYO616s2KRVRpi9zCh2a 6hjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2vcIiINY4WBP+S4p7ZvCljxe/AGpBFsXIl5B5dC7+jY=; b=cbnsYt/4M/WVyV/1eKUhBXBDqXrDo0Vh2mS3eevPaQOEfoaNgb1pEqc2vYrCyzM5lU KBSK73B4sSrP4o8Yuwy69+kzXxwaHPqPGKg53U/ZTO+ERa/HL8UXLCdd7woDEAyaQzcA +vqyeNedM0r5a2X5cqFHk9r3uGlcTlBh6P3NpsUSH+0+iM3NGNfrjTshJjqHJFB8E8z7 9LmvblKMNb2kjbk4SIGo++vbq+SltIbVPq01UOJ28YcU6dF2kFtI5m2YQbdVVuNoGMJa JmLqfkaGW3/oiL9J895mzR7SkV8GuKQm0b661OxGi7ofZ89QELtBBP0rL8XqKpIXSyJa NGBg== X-Gm-Message-State: APjAAAV5BZbLVlG5RVdErLWZ3RMr1JKu72aR3YYoBRNuGhiAblo0ZzSA /i3c4/iq0IN+nOt1KHvTumwo9gAnJJDeHe6nHqfAb+MIvRs= X-Received: by 2002:aa7:cf8e:: with SMTP id z14mr131881877edx.40.1564988145755; Sun, 04 Aug 2019 23:55:45 -0700 (PDT) MIME-Version: 1.0 References: <20190802164828.20243-1-hslester96@gmail.com> <20190804125858.GJ4832@mtr-leonro.mtl.com> <20190805061320.GN4832@mtr-leonro.mtl.com> In-Reply-To: <20190805061320.GN4832@mtr-leonro.mtl.com> From: Chuhong Yuan Date: Mon, 5 Aug 2019 14:55:34 +0800 Message-ID: Subject: Re: [PATCH v2] net/mlx5e: Use refcount_t for refcount To: Leon Romanovsky Cc: Saeed Mahameed , "David S . Miller" , Netdev , linux-rdma@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 5, 2019 at 2:13 PM Leon Romanovsky wrote: > > 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 for your explanation! I will pay attention to this point in similar cases. But it seems that the semantic of refcount is not always as clear as here... Regards, Chuhong > 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 > > > >