linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] mlx5: Use refcount_t for refcount
@ 2019-08-06  1:59 Chuhong Yuan
  2019-08-06 20:40 ` Saeed Mahameed
  0 siblings, 1 reply; 4+ messages in thread
From: Chuhong Yuan @ 2019-08-06  1:59 UTC (permalink / raw)
  Cc: Leon Romanovsky, Doug Ledford, Jason Gunthorpe, Saeed Mahameed,
	David S . Miller, linux-rdma, linux-kernel, netdev, Chuhong Yuan

Reference counters are preferred to use refcount_t instead of
atomic_t.
This is because the implementation of refcount_t can prevent
overflows and detect possible use-after-free.
So convert atomic_t ref counters to refcount_t.

Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
---
Changes in v3:
  - Merge v2 patches together.

 drivers/infiniband/hw/mlx5/srq_cmd.c         | 6 +++---
 drivers/net/ethernet/mellanox/mlx5/core/qp.c | 6 +++---
 include/linux/mlx5/driver.h                  | 3 ++-
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/infiniband/hw/mlx5/srq_cmd.c b/drivers/infiniband/hw/mlx5/srq_cmd.c
index b0d0687c7a68..8fc3630a9d4c 100644
--- a/drivers/infiniband/hw/mlx5/srq_cmd.c
+++ b/drivers/infiniband/hw/mlx5/srq_cmd.c
@@ -86,7 +86,7 @@ struct mlx5_core_srq *mlx5_cmd_get_srq(struct mlx5_ib_dev *dev, u32 srqn)
 	xa_lock(&table->array);
 	srq = xa_load(&table->array, srqn);
 	if (srq)
-		atomic_inc(&srq->common.refcount);
+		refcount_inc(&srq->common.refcount);
 	xa_unlock(&table->array);
 
 	return srq;
@@ -592,7 +592,7 @@ int mlx5_cmd_create_srq(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
 	if (err)
 		return err;
 
-	atomic_set(&srq->common.refcount, 1);
+	refcount_set(&srq->common.refcount, 1);
 	init_completion(&srq->common.free);
 
 	err = xa_err(xa_store_irq(&table->array, srq->srqn, srq, GFP_KERNEL));
@@ -675,7 +675,7 @@ static int srq_event_notifier(struct notifier_block *nb,
 	xa_lock(&table->array);
 	srq = xa_load(&table->array, srqn);
 	if (srq)
-		atomic_inc(&srq->common.refcount);
+		refcount_inc(&srq->common.refcount);
 	xa_unlock(&table->array);
 
 	if (!srq)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/qp.c b/drivers/net/ethernet/mellanox/mlx5/core/qp.c
index b8ba74de9555..7b44d1e49604 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/qp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/qp.c
@@ -53,7 +53,7 @@ mlx5_get_rsc(struct mlx5_qp_table *table, u32 rsn)
 
 	common = radix_tree_lookup(&table->tree, rsn);
 	if (common)
-		atomic_inc(&common->refcount);
+		refcount_inc(&common->refcount);
 
 	spin_unlock_irqrestore(&table->lock, flags);
 
@@ -62,7 +62,7 @@ mlx5_get_rsc(struct mlx5_qp_table *table, u32 rsn)
 
 void mlx5_core_put_rsc(struct mlx5_core_rsc_common *common)
 {
-	if (atomic_dec_and_test(&common->refcount))
+	if (refcount_dec_and_test(&common->refcount))
 		complete(&common->free);
 }
 
@@ -209,7 +209,7 @@ static int create_resource_common(struct mlx5_core_dev *dev,
 	if (err)
 		return err;
 
-	atomic_set(&qp->common.refcount, 1);
+	refcount_set(&qp->common.refcount, 1);
 	init_completion(&qp->common.free);
 	qp->pid = current->pid;
 
diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h
index 0e6da1840c7d..5b56f343ce87 100644
--- a/include/linux/mlx5/driver.h
+++ b/include/linux/mlx5/driver.h
@@ -47,6 +47,7 @@
 #include <linux/interrupt.h>
 #include <linux/idr.h>
 #include <linux/notifier.h>
+#include <linux/refcount.h>
 
 #include <linux/mlx5/device.h>
 #include <linux/mlx5/doorbell.h>
@@ -398,7 +399,7 @@ enum mlx5_res_type {
 
 struct mlx5_core_rsc_common {
 	enum mlx5_res_type	res;
-	atomic_t		refcount;
+	refcount_t		refcount;
 	struct completion	free;
 };
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] mlx5: Use refcount_t for refcount
  2019-08-06  1:59 [PATCH v3] mlx5: Use refcount_t for refcount Chuhong Yuan
@ 2019-08-06 20:40 ` Saeed Mahameed
  2019-08-07  3:17   ` Leon Romanovsky
  0 siblings, 1 reply; 4+ messages in thread
From: Saeed Mahameed @ 2019-08-06 20:40 UTC (permalink / raw)
  To: hslester96; +Cc: linux-rdma, linux-kernel, netdev, davem, jgg, leon, dledford

On Tue, 2019-08-06 at 09:59 +0800, Chuhong Yuan wrote:
> Reference counters are preferred to use refcount_t instead of
> atomic_t.
> This is because the implementation of refcount_t can prevent
> overflows and detect possible use-after-free.
> So convert atomic_t ref counters to refcount_t.
> 
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> ---
> Changes in v3:
>   - Merge v2 patches together.
> 
>  drivers/infiniband/hw/mlx5/srq_cmd.c         | 6 +++---
>  drivers/net/ethernet/mellanox/mlx5/core/qp.c | 6 +++---
>  include/linux/mlx5/driver.h                  | 3 ++-
>  3 files changed, 8 insertions(+), 7 deletions(-)
> 

LGTM, Leon, let me know if you are happy with this version, 
this should go to mlx5-next.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] mlx5: Use refcount_t for refcount
  2019-08-06 20:40 ` Saeed Mahameed
@ 2019-08-07  3:17   ` Leon Romanovsky
  2019-08-07 18:03     ` Saeed Mahameed
  0 siblings, 1 reply; 4+ messages in thread
From: Leon Romanovsky @ 2019-08-07  3:17 UTC (permalink / raw)
  To: Saeed Mahameed
  Cc: hslester96, linux-rdma, linux-kernel, netdev, davem, jgg, dledford

On Tue, Aug 06, 2019 at 08:40:11PM +0000, Saeed Mahameed wrote:
> On Tue, 2019-08-06 at 09:59 +0800, Chuhong Yuan wrote:
> > Reference counters are preferred to use refcount_t instead of
> > atomic_t.
> > This is because the implementation of refcount_t can prevent
> > overflows and detect possible use-after-free.
> > So convert atomic_t ref counters to refcount_t.
> >
> > Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> > ---
> > Changes in v3:
> >   - Merge v2 patches together.
> >
> >  drivers/infiniband/hw/mlx5/srq_cmd.c         | 6 +++---
> >  drivers/net/ethernet/mellanox/mlx5/core/qp.c | 6 +++---
> >  include/linux/mlx5/driver.h                  | 3 ++-
> >  3 files changed, 8 insertions(+), 7 deletions(-)
> >
>
> LGTM, Leon, let me know if you are happy with this version,
> this should go to mlx5-next.

Thanks,
Acked-by: Leon Romanovsky <leonro@mellanox.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] mlx5: Use refcount_t for refcount
  2019-08-07  3:17   ` Leon Romanovsky
@ 2019-08-07 18:03     ` Saeed Mahameed
  0 siblings, 0 replies; 4+ messages in thread
From: Saeed Mahameed @ 2019-08-07 18:03 UTC (permalink / raw)
  To: leon; +Cc: jgg, dledford, davem, linux-kernel, hslester96, linux-rdma, netdev

On Wed, 2019-08-07 at 06:17 +0300, Leon Romanovsky wrote:
> On Tue, Aug 06, 2019 at 08:40:11PM +0000, Saeed Mahameed wrote:
> > On Tue, 2019-08-06 at 09:59 +0800, Chuhong Yuan wrote:
> > > Reference counters are preferred to use refcount_t instead of
> > > atomic_t.
> > > This is because the implementation of refcount_t can prevent
> > > overflows and detect possible use-after-free.
> > > So convert atomic_t ref counters to refcount_t.
> > > 
> > > Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> > > ---
> > > Changes in v3:
> > >   - Merge v2 patches together.
> > > 
> > >  drivers/infiniband/hw/mlx5/srq_cmd.c         | 6 +++---
> > >  drivers/net/ethernet/mellanox/mlx5/core/qp.c | 6 +++---
> > >  include/linux/mlx5/driver.h                  | 3 ++-
> > >  3 files changed, 8 insertions(+), 7 deletions(-)
> > > 
> > 
> > LGTM, Leon, let me know if you are happy with this version,
> > this should go to mlx5-next.
> 
> Thanks,
> Acked-by: Leon Romanovsky <leonro@mellanox.com>

Applied to mlx5-next.

Thanks !

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-07 18:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-06  1:59 [PATCH v3] mlx5: Use refcount_t for refcount Chuhong Yuan
2019-08-06 20:40 ` Saeed Mahameed
2019-08-07  3:17   ` Leon Romanovsky
2019-08-07 18:03     ` Saeed Mahameed

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).