Commit 71c5e55e authored by Omer Shpigelman's avatar Omer Shpigelman Committed by Oded Gabbay

habanalabs: skip VA block list update in reset flow

Reduce context close time by skipping the VA block free list update in
order to avoid hard reset with open contexts.
Reset with open contexts can potentially lead to a kernel crash as the
generic pool of the MMU hops is destroyed while it is not empty because
some unmap operations are not done.
The commit affect mainly when running on simulator.
Signed-off-by: default avatarOmer Shpigelman <oshpigelman@habana.ai>
Reviewed-by: default avatarOded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: default avatarOded Gabbay <oded.gabbay@gmail.com>
parent 1b98d8b2
...@@ -993,17 +993,19 @@ static int map_device_va(struct hl_ctx *ctx, struct hl_mem_in *args, ...@@ -993,17 +993,19 @@ static int map_device_va(struct hl_ctx *ctx, struct hl_mem_in *args,
* *
* @ctx : current context * @ctx : current context
* @vaddr : device virtual address to unmap * @vaddr : device virtual address to unmap
* @ctx_free : true if in context free flow, false otherwise.
* *
* This function does the following: * This function does the following:
* - Unmap the physical pages related to the given virtual address * - Unmap the physical pages related to the given virtual address
* - return the device virtual block to the virtual block list * - return the device virtual block to the virtual block list
*/ */
static int unmap_device_va(struct hl_ctx *ctx, u64 vaddr) static int unmap_device_va(struct hl_ctx *ctx, u64 vaddr, bool ctx_free)
{ {
struct hl_device *hdev = ctx->hdev; struct hl_device *hdev = ctx->hdev;
struct hl_vm_phys_pg_pack *phys_pg_pack = NULL; struct hl_vm_phys_pg_pack *phys_pg_pack = NULL;
struct hl_vm_hash_node *hnode = NULL; struct hl_vm_hash_node *hnode = NULL;
struct hl_userptr *userptr = NULL; struct hl_userptr *userptr = NULL;
struct hl_va_range *va_range;
enum vm_type_t *vm_type; enum vm_type_t *vm_type;
bool is_userptr; bool is_userptr;
int rc; int rc;
...@@ -1029,6 +1031,7 @@ static int unmap_device_va(struct hl_ctx *ctx, u64 vaddr) ...@@ -1029,6 +1031,7 @@ static int unmap_device_va(struct hl_ctx *ctx, u64 vaddr)
if (*vm_type == VM_TYPE_USERPTR) { if (*vm_type == VM_TYPE_USERPTR) {
is_userptr = true; is_userptr = true;
va_range = &ctx->host_va_range;
userptr = hnode->ptr; userptr = hnode->ptr;
rc = init_phys_pg_pack_from_userptr(ctx, userptr, rc = init_phys_pg_pack_from_userptr(ctx, userptr,
&phys_pg_pack); &phys_pg_pack);
...@@ -1040,6 +1043,7 @@ static int unmap_device_va(struct hl_ctx *ctx, u64 vaddr) ...@@ -1040,6 +1043,7 @@ static int unmap_device_va(struct hl_ctx *ctx, u64 vaddr)
} }
} else if (*vm_type == VM_TYPE_PHYS_PACK) { } else if (*vm_type == VM_TYPE_PHYS_PACK) {
is_userptr = false; is_userptr = false;
va_range = &ctx->dram_va_range;
phys_pg_pack = hnode->ptr; phys_pg_pack = hnode->ptr;
} else { } else {
dev_warn(hdev->dev, dev_warn(hdev->dev,
...@@ -1065,12 +1069,18 @@ static int unmap_device_va(struct hl_ctx *ctx, u64 vaddr) ...@@ -1065,12 +1069,18 @@ static int unmap_device_va(struct hl_ctx *ctx, u64 vaddr)
mutex_unlock(&ctx->mmu_lock); mutex_unlock(&ctx->mmu_lock);
if (add_va_block(hdev, /*
is_userptr ? &ctx->host_va_range : &ctx->dram_va_range, * No point in maintaining the free VA block list if the context is
vaddr, * closing as the list will be freed anyway
vaddr + phys_pg_pack->total_size - 1)) */
dev_warn(hdev->dev, "add va block failed for vaddr: 0x%llx\n", if (!ctx_free) {
rc = add_va_block(hdev, va_range, vaddr,
vaddr + phys_pg_pack->total_size - 1);
if (rc)
dev_warn(hdev->dev,
"add va block failed for vaddr: 0x%llx\n",
vaddr); vaddr);
}
atomic_dec(&phys_pg_pack->mapping_cnt); atomic_dec(&phys_pg_pack->mapping_cnt);
kfree(hnode); kfree(hnode);
...@@ -1202,8 +1212,8 @@ int hl_mem_ioctl(struct hl_fpriv *hpriv, void *data) ...@@ -1202,8 +1212,8 @@ int hl_mem_ioctl(struct hl_fpriv *hpriv, void *data)
break; break;
case HL_MEM_OP_UNMAP: case HL_MEM_OP_UNMAP:
rc = unmap_device_va(ctx, rc = unmap_device_va(ctx, args->in.unmap.device_virt_addr,
args->in.unmap.device_virt_addr); false);
break; break;
default: default:
...@@ -1650,7 +1660,7 @@ void hl_vm_ctx_fini(struct hl_ctx *ctx) ...@@ -1650,7 +1660,7 @@ void hl_vm_ctx_fini(struct hl_ctx *ctx)
dev_dbg(hdev->dev, dev_dbg(hdev->dev,
"hl_mem_hash_node of vaddr 0x%llx of asid %d is still alive\n", "hl_mem_hash_node of vaddr 0x%llx of asid %d is still alive\n",
hnode->vaddr, ctx->asid); hnode->vaddr, ctx->asid);
unmap_device_va(ctx, hnode->vaddr); unmap_device_va(ctx, hnode->vaddr, true);
} }
spin_lock(&vm->idr_lock); spin_lock(&vm->idr_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment