linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] habanalabs: fix double unlock on error in map_device_va()
@ 2022-05-25 12:25 Dan Carpenter
  2022-06-05 10:05 ` Oded Gabbay
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2022-05-25 12:25 UTC (permalink / raw)
  To: Oded Gabbay, Ohad Sharabi
  Cc: Arnd Bergmann, Greg Kroah-Hartman, Yuri Nudelman, Ofir Bitton,
	farah kassabri, Tomer Tayar, linux-kernel, kernel-janitors

If hl_mmu_prefetch_cache_range() fails then this code calls
mutex_unlock(&ctx->mmu_lock) when it's no longer holding the mutex.

Fixes: 9e495e24003e ("habanalabs: do MMU prefetch as deferred work")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/misc/habanalabs/common/memory.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/habanalabs/common/memory.c b/drivers/misc/habanalabs/common/memory.c
index 663dd7e589d4..d5e6500f8a1f 100644
--- a/drivers/misc/habanalabs/common/memory.c
+++ b/drivers/misc/habanalabs/common/memory.c
@@ -1245,16 +1245,16 @@ static int map_device_va(struct hl_ctx *ctx, struct hl_mem_in *args, u64 *device
 	rc = map_phys_pg_pack(ctx, ret_vaddr, phys_pg_pack);
 	if (rc) {
 		dev_err(hdev->dev, "mapping page pack failed for handle %u\n", handle);
+		mutex_unlock(&ctx->mmu_lock);
 		goto map_err;
 	}
 
 	rc = hl_mmu_invalidate_cache_range(hdev, false, *vm_type | MMU_OP_SKIP_LOW_CACHE_INV,
 				ctx->asid, ret_vaddr, phys_pg_pack->total_size);
+	mutex_unlock(&ctx->mmu_lock);
 	if (rc)
 		goto map_err;
 
-	mutex_unlock(&ctx->mmu_lock);
-
 	/*
 	 * prefetch is done upon user's request. it is performed in WQ as and so can
 	 * be outside the MMU lock. the operation itself is already protected by the mmu lock
@@ -1283,8 +1283,6 @@ static int map_device_va(struct hl_ctx *ctx, struct hl_mem_in *args, u64 *device
 	return rc;
 
 map_err:
-	mutex_unlock(&ctx->mmu_lock);
-
 	if (add_va_block(hdev, va_range, ret_vaddr,
 				ret_vaddr + phys_pg_pack->total_size - 1))
 		dev_warn(hdev->dev,
-- 
2.35.1


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

* Re: [PATCH] habanalabs: fix double unlock on error in map_device_va()
  2022-05-25 12:25 [PATCH] habanalabs: fix double unlock on error in map_device_va() Dan Carpenter
@ 2022-06-05 10:05 ` Oded Gabbay
  0 siblings, 0 replies; 2+ messages in thread
From: Oded Gabbay @ 2022-06-05 10:05 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Ohad Sharabi, Arnd Bergmann, Greg Kroah-Hartman, Yuri Nudelman,
	Ofir Bitton, farah kassabri, Tomer Tayar,
	Linux-Kernel@Vger. Kernel. Org, kernel-janitors

On Wed, May 25, 2022 at 3:25 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> If hl_mmu_prefetch_cache_range() fails then this code calls
> mutex_unlock(&ctx->mmu_lock) when it's no longer holding the mutex.
>
> Fixes: 9e495e24003e ("habanalabs: do MMU prefetch as deferred work")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/misc/habanalabs/common/memory.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/misc/habanalabs/common/memory.c b/drivers/misc/habanalabs/common/memory.c
> index 663dd7e589d4..d5e6500f8a1f 100644
> --- a/drivers/misc/habanalabs/common/memory.c
> +++ b/drivers/misc/habanalabs/common/memory.c
> @@ -1245,16 +1245,16 @@ static int map_device_va(struct hl_ctx *ctx, struct hl_mem_in *args, u64 *device
>         rc = map_phys_pg_pack(ctx, ret_vaddr, phys_pg_pack);
>         if (rc) {
>                 dev_err(hdev->dev, "mapping page pack failed for handle %u\n", handle);
> +               mutex_unlock(&ctx->mmu_lock);
>                 goto map_err;
>         }
>
>         rc = hl_mmu_invalidate_cache_range(hdev, false, *vm_type | MMU_OP_SKIP_LOW_CACHE_INV,
>                                 ctx->asid, ret_vaddr, phys_pg_pack->total_size);
> +       mutex_unlock(&ctx->mmu_lock);
>         if (rc)
>                 goto map_err;
>
> -       mutex_unlock(&ctx->mmu_lock);
> -
>         /*
>          * prefetch is done upon user's request. it is performed in WQ as and so can
>          * be outside the MMU lock. the operation itself is already protected by the mmu lock
> @@ -1283,8 +1283,6 @@ static int map_device_va(struct hl_ctx *ctx, struct hl_mem_in *args, u64 *device
>         return rc;
>
>  map_err:
> -       mutex_unlock(&ctx->mmu_lock);
> -
>         if (add_va_block(hdev, va_range, ret_vaddr,
>                                 ret_vaddr + phys_pg_pack->total_size - 1))
>                 dev_warn(hdev->dev,
> --
> 2.35.1
>

Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Applied to -next.
Thanks,
Oded

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

end of thread, other threads:[~2022-06-05 10:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-25 12:25 [PATCH] habanalabs: fix double unlock on error in map_device_va() Dan Carpenter
2022-06-05 10:05 ` Oded Gabbay

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).