Commit b041e788 authored by Tomer Tayar's avatar Tomer Tayar Committed by Oded Gabbay

accel/habanalabs: add helper function to get vm hash node

Add a helper function to search the vm hash for a node with a given
virtual address.
As opposed to the current code, this function explicitly returns NULL
when no node is found, instead of basing on the loop cursor object's
value.
Signed-off-by: default avatarTomer Tayar <ttayar@habana.ai>
Reviewed-by: default avatarOded Gabbay <ogabbay@kernel.org>
Reviewed-by: default avatarStanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
Signed-off-by: default avatarOded Gabbay <ogabbay@kernel.org>
parent d1bae819
...@@ -1266,6 +1266,18 @@ static int map_device_va(struct hl_ctx *ctx, struct hl_mem_in *args, u64 *device ...@@ -1266,6 +1266,18 @@ static int map_device_va(struct hl_ctx *ctx, struct hl_mem_in *args, u64 *device
return rc; return rc;
} }
/* Should be called while the context's mem_hash_lock is taken */
static struct hl_vm_hash_node *get_vm_hash_node_locked(struct hl_ctx *ctx, u64 vaddr)
{
struct hl_vm_hash_node *hnode;
hash_for_each_possible(ctx->mem_hash, hnode, node, vaddr)
if (vaddr == hnode->vaddr)
return hnode;
return NULL;
}
/** /**
* unmap_device_va() - unmap the given device virtual address. * unmap_device_va() - unmap the given device virtual address.
* @ctx: pointer to the context structure. * @ctx: pointer to the context structure.
...@@ -1281,10 +1293,10 @@ static int unmap_device_va(struct hl_ctx *ctx, struct hl_mem_in *args, ...@@ -1281,10 +1293,10 @@ static int unmap_device_va(struct hl_ctx *ctx, struct hl_mem_in *args,
{ {
struct hl_vm_phys_pg_pack *phys_pg_pack = NULL; struct hl_vm_phys_pg_pack *phys_pg_pack = NULL;
u64 vaddr = args->unmap.device_virt_addr; u64 vaddr = args->unmap.device_virt_addr;
struct hl_vm_hash_node *hnode = NULL;
struct asic_fixed_properties *prop; struct asic_fixed_properties *prop;
struct hl_device *hdev = ctx->hdev; struct hl_device *hdev = ctx->hdev;
struct hl_userptr *userptr = NULL; struct hl_userptr *userptr = NULL;
struct hl_vm_hash_node *hnode;
struct hl_va_range *va_range; struct hl_va_range *va_range;
enum vm_type *vm_type; enum vm_type *vm_type;
bool is_userptr; bool is_userptr;
...@@ -1294,15 +1306,10 @@ static int unmap_device_va(struct hl_ctx *ctx, struct hl_mem_in *args, ...@@ -1294,15 +1306,10 @@ static int unmap_device_va(struct hl_ctx *ctx, struct hl_mem_in *args,
/* protect from double entrance */ /* protect from double entrance */
mutex_lock(&ctx->mem_hash_lock); mutex_lock(&ctx->mem_hash_lock);
hash_for_each_possible(ctx->mem_hash, hnode, node, (unsigned long)vaddr) hnode = get_vm_hash_node_locked(ctx, vaddr);
if (vaddr == hnode->vaddr)
break;
if (!hnode) { if (!hnode) {
mutex_unlock(&ctx->mem_hash_lock); mutex_unlock(&ctx->mem_hash_lock);
dev_err(hdev->dev, dev_err(hdev->dev, "unmap failed, no mem hnode for vaddr 0x%llx\n", vaddr);
"unmap failed, no mem hnode for vaddr 0x%llx\n",
vaddr);
return -EINVAL; return -EINVAL;
} }
...@@ -1782,10 +1789,7 @@ static struct hl_vm_hash_node *memhash_node_export_get(struct hl_ctx *ctx, u64 a ...@@ -1782,10 +1789,7 @@ static struct hl_vm_hash_node *memhash_node_export_get(struct hl_ctx *ctx, u64 a
/* get the memory handle */ /* get the memory handle */
mutex_lock(&ctx->mem_hash_lock); mutex_lock(&ctx->mem_hash_lock);
hash_for_each_possible(ctx->mem_hash, hnode, node, (unsigned long)addr) hnode = get_vm_hash_node_locked(ctx, addr);
if (addr == hnode->vaddr)
break;
if (!hnode) { if (!hnode) {
mutex_unlock(&ctx->mem_hash_lock); mutex_unlock(&ctx->mem_hash_lock);
dev_dbg(hdev->dev, "map address %#llx not found\n", addr); dev_dbg(hdev->dev, "map address %#llx not found\n", addr);
......
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