All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme-fabrics: error out to unlock the mutex
@ 2023-06-02  5:37 Chaitanya Kulkarni
  2023-06-02  5:42 ` Julia Lawall
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Chaitanya Kulkarni @ 2023-06-02  5:37 UTC (permalink / raw)
  To: linux-nvme
  Cc: kbusch, axboe, hch, sagi, Chaitanya Kulkarni, kernel test robot,
	Julia Lawall

Currently, in the nvmf_host_add() function, if the nvmf_host_alloc()
call failed to allocate memory for the host, the code would directly
return -ENOMEM without unlocking the nvmf_hosts_mutex. This could
lead to potential issues with mutex synchronization.

Fix that error handling mechanism by jumping to the out_unlock label
when nvmf_host_alloc() fails. This ensures that the mutex is unlocked
before returning the error code. The updated code enhances avoids
possible deadlocks.

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Julia Lawall <julia.lawall@inria.fr>
Closes: https://lore.kernel.org/r/202306020909.MTUEBeIa-lkp@intel.com/
Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/nvme/host/fabrics.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index b1fa27b60917..c4345d1d98aa 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -92,8 +92,10 @@ static struct nvmf_host *nvmf_host_add(const char *hostnqn, uuid_t *id)
 	}
 
 	host = nvmf_host_alloc(hostnqn, id);
-	if (!host)
-		return ERR_PTR(-ENOMEM);
+	if (!host) {
+		host = ERR_PTR(-ENOMEM);
+		goto out_unlock;
+	}
 
 	list_add_tail(&host->list, &nvmf_hosts);
 out_unlock:
-- 
2.40.0



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

* Re: [PATCH] nvme-fabrics: error out to unlock the mutex
  2023-06-02  5:37 [PATCH] nvme-fabrics: error out to unlock the mutex Chaitanya Kulkarni
@ 2023-06-02  5:42 ` Julia Lawall
  2023-06-02 15:03 ` Christoph Hellwig
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Julia Lawall @ 2023-06-02  5:42 UTC (permalink / raw)
  To: Chaitanya Kulkarni
  Cc: linux-nvme, kbusch, axboe, hch, sagi, kernel test robot, Julia Lawall



On Thu, 1 Jun 2023, Chaitanya Kulkarni wrote:

> Currently, in the nvmf_host_add() function, if the nvmf_host_alloc()
> call failed to allocate memory for the host, the code would directly
> return -ENOMEM without unlocking the nvmf_hosts_mutex. This could
> lead to potential issues with mutex synchronization.
>
> Fix that error handling mechanism by jumping to the out_unlock label
> when nvmf_host_alloc() fails. This ensures that the mutex is unlocked
> before returning the error code. The updated code enhances avoids
> possible deadlocks.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Julia Lawall <julia.lawall@inria.fr>
> Closes: https://lore.kernel.org/r/202306020909.MTUEBeIa-lkp@intel.com/
> Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
> ---
>  drivers/nvme/host/fabrics.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
> index b1fa27b60917..c4345d1d98aa 100644
> --- a/drivers/nvme/host/fabrics.c
> +++ b/drivers/nvme/host/fabrics.c
> @@ -92,8 +92,10 @@ static struct nvmf_host *nvmf_host_add(const char *hostnqn, uuid_t *id)
>  	}
>
>  	host = nvmf_host_alloc(hostnqn, id);
> -	if (!host)
> -		return ERR_PTR(-ENOMEM);
> +	if (!host) {
> +		host = ERR_PTR(-ENOMEM);
> +		goto out_unlock;
> +	}
>
>  	list_add_tail(&host->list, &nvmf_hosts);
>  out_unlock:

Looks good, thanks.

Reviewed-by: Julia Lawall <julia.lawall@inria.fr>



> --
> 2.40.0
>
>


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

* Re: [PATCH] nvme-fabrics: error out to unlock the mutex
  2023-06-02  5:37 [PATCH] nvme-fabrics: error out to unlock the mutex Chaitanya Kulkarni
  2023-06-02  5:42 ` Julia Lawall
@ 2023-06-02 15:03 ` Christoph Hellwig
  2023-06-04  0:38 ` Max Gurtovoy
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2023-06-02 15:03 UTC (permalink / raw)
  To: Chaitanya Kulkarni
  Cc: linux-nvme, kbusch, axboe, hch, sagi, kernel test robot, Julia Lawall

On Thu, Jun 01, 2023 at 10:37:13PM -0700, Chaitanya Kulkarni wrote:
>  	host = nvmf_host_alloc(hostnqn, id);
> -	if (!host)
> -		return ERR_PTR(-ENOMEM);
> +	if (!host) {
> +		host = ERR_PTR(-ENOMEM);
> +		goto out_unlock;
> +	}

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


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

* Re: [PATCH] nvme-fabrics: error out to unlock the mutex
  2023-06-02  5:37 [PATCH] nvme-fabrics: error out to unlock the mutex Chaitanya Kulkarni
  2023-06-02  5:42 ` Julia Lawall
  2023-06-02 15:03 ` Christoph Hellwig
@ 2023-06-04  0:38 ` Max Gurtovoy
  2023-06-05 22:40 ` Sagi Grimberg
  2023-06-09 15:38 ` Keith Busch
  4 siblings, 0 replies; 6+ messages in thread
From: Max Gurtovoy @ 2023-06-04  0:38 UTC (permalink / raw)
  To: Chaitanya Kulkarni, linux-nvme
  Cc: kbusch, axboe, hch, sagi, kernel test robot, Julia Lawall



On 02/06/2023 8:37, Chaitanya Kulkarni wrote:
> Currently, in the nvmf_host_add() function, if the nvmf_host_alloc()
> call failed to allocate memory for the host, the code would directly
> return -ENOMEM without unlocking the nvmf_hosts_mutex. This could
> lead to potential issues with mutex synchronization.
> 
> Fix that error handling mechanism by jumping to the out_unlock label
> when nvmf_host_alloc() fails. This ensures that the mutex is unlocked
> before returning the error code. The updated code enhances avoids
> possible deadlocks.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Julia Lawall <julia.lawall@inria.fr>
> Closes: https://lore.kernel.org/r/202306020909.MTUEBeIa-lkp@intel.com/
> Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
> ---
>   drivers/nvme/host/fabrics.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
> index b1fa27b60917..c4345d1d98aa 100644
> --- a/drivers/nvme/host/fabrics.c
> +++ b/drivers/nvme/host/fabrics.c
> @@ -92,8 +92,10 @@ static struct nvmf_host *nvmf_host_add(const char *hostnqn, uuid_t *id)
>   	}
>   
>   	host = nvmf_host_alloc(hostnqn, id);
> -	if (!host)
> -		return ERR_PTR(-ENOMEM);
> +	if (!host) {
> +		host = ERR_PTR(-ENOMEM);
> +		goto out_unlock;
> +	}
>   
>   	list_add_tail(&host->list, &nvmf_hosts);
>   out_unlock:

Looks good,
Reviewed-by: Max Gurtovoy <mgurtovoy@nvidia.com>


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

* Re: [PATCH] nvme-fabrics: error out to unlock the mutex
  2023-06-02  5:37 [PATCH] nvme-fabrics: error out to unlock the mutex Chaitanya Kulkarni
                   ` (2 preceding siblings ...)
  2023-06-04  0:38 ` Max Gurtovoy
@ 2023-06-05 22:40 ` Sagi Grimberg
  2023-06-09 15:38 ` Keith Busch
  4 siblings, 0 replies; 6+ messages in thread
From: Sagi Grimberg @ 2023-06-05 22:40 UTC (permalink / raw)
  To: Chaitanya Kulkarni, linux-nvme
  Cc: kbusch, axboe, hch, kernel test robot, Julia Lawall


> Currently, in the nvmf_host_add() function, if the nvmf_host_alloc()
> call failed to allocate memory for the host, the code would directly
> return -ENOMEM without unlocking the nvmf_hosts_mutex. This could
> lead to potential issues with mutex synchronization.
> 
> Fix that error handling mechanism by jumping to the out_unlock label
> when nvmf_host_alloc() fails. This ensures that the mutex is unlocked
> before returning the error code. The updated code enhances avoids
> possible deadlocks.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Julia Lawall <julia.lawall@inria.fr>
> Closes: https://lore.kernel.org/r/202306020909.MTUEBeIa-lkp@intel.com/
> Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>

Can add:
Fixes: f0cebf82004d ("nvme-fabrics: prevent overriding of existing host")

otherwise:
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>


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

* Re: [PATCH] nvme-fabrics: error out to unlock the mutex
  2023-06-02  5:37 [PATCH] nvme-fabrics: error out to unlock the mutex Chaitanya Kulkarni
                   ` (3 preceding siblings ...)
  2023-06-05 22:40 ` Sagi Grimberg
@ 2023-06-09 15:38 ` Keith Busch
  4 siblings, 0 replies; 6+ messages in thread
From: Keith Busch @ 2023-06-09 15:38 UTC (permalink / raw)
  To: Chaitanya Kulkarni
  Cc: linux-nvme, axboe, hch, sagi, kernel test robot, Julia Lawall

Thanks, applied for nvme-6.5.


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

end of thread, other threads:[~2023-06-09 15:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-02  5:37 [PATCH] nvme-fabrics: error out to unlock the mutex Chaitanya Kulkarni
2023-06-02  5:42 ` Julia Lawall
2023-06-02 15:03 ` Christoph Hellwig
2023-06-04  0:38 ` Max Gurtovoy
2023-06-05 22:40 ` Sagi Grimberg
2023-06-09 15:38 ` Keith Busch

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.