All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leonro@nvidia.com>
To: Saeed Mahameed <saeed@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, <netdev@vger.kernel.org>,
	Tariq Toukan <tariqt@nvidia.com>, Shay Drory <shayd@nvidia.com>,
	Parav Pandit <parav@nvidia.com>,
	Saeed Mahameed <saeedm@nvidia.com>
Subject: Re: [net-next 06/12] net/mlx5: Refcount mlx5_irq with integer
Date: Thu, 12 Aug 2021 10:13:11 +0300	[thread overview]
Message-ID: <YRTKBw/q57G3erd9@unreal> (raw)
In-Reply-To: <20210811181658.492548-7-saeed@kernel.org>

On Wed, Aug 11, 2021 at 11:16:52AM -0700, Saeed Mahameed wrote:
> From: Shay Drory <shayd@nvidia.com>
> 
> Currently, all access to mlx5 IRQs are done undere a lock. Hance, there
> isn't a reason to have kref in struct mlx5_irq.
> Switch it to integer.

Please fix spelling errors.

> 
> Signed-off-by: Shay Drory <shayd@nvidia.com>
> Reviewed-by: Parav Pandit <parav@nvidia.com>
> Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
> ---
>  .../net/ethernet/mellanox/mlx5/core/pci_irq.c | 65 +++++++++++++------
>  1 file changed, 44 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c b/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c
> index 717b9f1850ac..60bfcad1873c 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c
> @@ -32,7 +32,7 @@ struct mlx5_irq {
>  	cpumask_var_t mask;
>  	char name[MLX5_MAX_IRQ_NAME];
>  	struct mlx5_irq_pool *pool;
> -	struct kref kref;
> +	int refcount;

refcount has special meaning and semantics in the kernel.

>  	u32 index;
>  	int irqn;
>  };
> @@ -138,9 +138,8 @@ int mlx5_set_msix_vec_count(struct mlx5_core_dev *dev, int function_id,
>  	return ret;
>  }
>  
> -static void irq_release(struct kref *kref)
> +static void irq_release(struct mlx5_irq *irq)
>  {
> -	struct mlx5_irq *irq = container_of(kref, struct mlx5_irq, kref);
>  	struct mlx5_irq_pool *pool = irq->pool;
>  
>  	xa_erase(&pool->irqs, irq->index);
> @@ -159,10 +158,31 @@ static void irq_put(struct mlx5_irq *irq)
>  	struct mlx5_irq_pool *pool = irq->pool;
>  
>  	mutex_lock(&pool->lock);
> -	kref_put(&irq->kref, irq_release);
> +	irq->refcount--;
> +	if (!irq->refcount)
> +		irq_release(irq);
>  	mutex_unlock(&pool->lock);
>  }
>  
> +static int irq_get_locked(struct mlx5_irq *irq)
> +{
> +	lockdep_assert_held(&irq->pool->lock);
> +	if (WARN_ON_ONCE(!irq->refcount))
> +		return 0;
> +	irq->refcount++;
> +	return 1;
> +}
> +
> +static int irq_get(struct mlx5_irq *irq)
> +{
> +	int err;
> +
> +	mutex_lock(&irq->pool->lock);
> +	err = irq_get_locked(irq);
> +	mutex_unlock(&irq->pool->lock);
> +	return err;
> +}

From not deep-dive review, all this "irq->pool->lock" is wrong.
The idea that you lock pool to change one entry can't be right.

So, I would invest time to clean locking here instead of removing kref.

Thanks

  reply	other threads:[~2021-08-12  7:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-11 18:16 [pull request][net-next 00/12] mlx5 updates 2021-08-11 Saeed Mahameed
2021-08-11 18:16 ` [net-next 01/12] net/mlx5: Fix typo in comments Saeed Mahameed
2021-08-12 11:50   ` patchwork-bot+netdevbpf
2021-08-11 18:16 ` [net-next 02/12] net/mlx5: Fix inner TTC table creation Saeed Mahameed
2021-08-11 18:16 ` [net-next 03/12] net/mlx5: Delete impossible dev->state checks Saeed Mahameed
2021-08-11 18:16 ` [net-next 04/12] net/mlx5: Align mlx5_irq structure Saeed Mahameed
2021-08-11 18:16 ` [net-next 05/12] net/mlx5: Change SF missing dedicated MSI-X err message to dbg Saeed Mahameed
2021-08-12  7:07   ` Leon Romanovsky
2021-08-11 18:16 ` [net-next 06/12] net/mlx5: Refcount mlx5_irq with integer Saeed Mahameed
2021-08-12  7:13   ` Leon Romanovsky [this message]
2021-08-11 18:16 ` [net-next 07/12] net/mlx5: SF, use recent sysfs api Saeed Mahameed
2021-08-11 18:16 ` [net-next 08/12] net/mlx5: Reorganize current and maximal capabilities to be per-type Saeed Mahameed
2021-08-11 18:16 ` [net-next 09/12] net/mlx5: Allocate individual capability Saeed Mahameed
2021-08-11 18:16 ` [net-next 10/12] net/mlx5: Initialize numa node for all core devices Saeed Mahameed
2021-08-11 18:16 ` [net-next 11/12] net/mlx5: Fix variable type to match 64bit Saeed Mahameed
2021-08-11 18:16 ` [net-next 12/12] net/mlx5e: Make use of netdev_warn() Saeed Mahameed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YRTKBw/q57G3erd9@unreal \
    --to=leonro@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=parav@nvidia.com \
    --cc=saeed@kernel.org \
    --cc=saeedm@nvidia.com \
    --cc=shayd@nvidia.com \
    --cc=tariqt@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.