Commit f2daa2d9 authored by Yuri Nudelman's avatar Yuri Nudelman Committed by Greg Kroah-Hartman

habanalabs: add topic to memory manager buffer

Currently, buffers from multiple flows pass through the same infra.
This way, in logs, we are unable to distinguish between buffers that
came from separate flows.
To address this problem, add a "topic" to buffer behavior
descriptor - a string identifier that will be used to identify in logs
the flow this buffer relates to.
Signed-off-by: default avatarYuri Nudelman <ynudelman@habana.ai>
Reviewed-by: default avatarOded Gabbay <ogabbay@kernel.org>
Signed-off-by: default avatarOded Gabbay <ogabbay@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c3780338
...@@ -319,6 +319,7 @@ static int hl_cb_mmap(struct hl_mmap_mem_buf *buf, ...@@ -319,6 +319,7 @@ static int hl_cb_mmap(struct hl_mmap_mem_buf *buf,
} }
static struct hl_mmap_mem_buf_behavior cb_behavior = { static struct hl_mmap_mem_buf_behavior cb_behavior = {
.topic = "CB",
.mem_id = HL_MMAP_TYPE_CB, .mem_id = HL_MMAP_TYPE_CB,
.alloc = hl_cb_mmap_mem_alloc, .alloc = hl_cb_mmap_mem_alloc,
.release = hl_cb_mmap_mem_release, .release = hl_cb_mmap_mem_release,
......
...@@ -731,6 +731,7 @@ struct hl_mem_mgr { ...@@ -731,6 +731,7 @@ struct hl_mem_mgr {
/** /**
* struct hl_mmap_mem_buf_behavior - describes unified memory manager buffer behavior * struct hl_mmap_mem_buf_behavior - describes unified memory manager buffer behavior
* @topic: string identifier used for logging
* @mem_id: memory type identifier, embedded in the handle and used to identify * @mem_id: memory type identifier, embedded in the handle and used to identify
* the memory type by handle. * the memory type by handle.
* @alloc: callback executed on buffer allocation, shall allocate the memory, * @alloc: callback executed on buffer allocation, shall allocate the memory,
...@@ -739,6 +740,7 @@ struct hl_mem_mgr { ...@@ -739,6 +740,7 @@ struct hl_mem_mgr {
* @release: callback executed on release, must free the resources used by the buffer * @release: callback executed on release, must free the resources used by the buffer
*/ */
struct hl_mmap_mem_buf_behavior { struct hl_mmap_mem_buf_behavior {
const char *topic;
u64 mem_id; u64 mem_id;
int (*alloc)(struct hl_mmap_mem_buf *buf, gfp_t gfp, void *args); int (*alloc)(struct hl_mmap_mem_buf *buf, gfp_t gfp, void *args);
......
...@@ -2141,6 +2141,7 @@ static int hl_ts_alloc_buf(struct hl_mmap_mem_buf *buf, gfp_t gfp, void *args) ...@@ -2141,6 +2141,7 @@ static int hl_ts_alloc_buf(struct hl_mmap_mem_buf *buf, gfp_t gfp, void *args)
} }
static struct hl_mmap_mem_buf_behavior hl_ts_behavior = { static struct hl_mmap_mem_buf_behavior hl_ts_behavior = {
.topic = "TS",
.mem_id = HL_MMAP_TYPE_TS_BUFF, .mem_id = HL_MMAP_TYPE_TS_BUFF,
.mmap = hl_ts_mmap, .mmap = hl_ts_mmap,
.alloc = hl_ts_alloc_buf, .alloc = hl_ts_alloc_buf,
......
...@@ -162,7 +162,8 @@ hl_mmap_mem_buf_alloc(struct hl_mem_mgr *mmg, ...@@ -162,7 +162,8 @@ hl_mmap_mem_buf_alloc(struct hl_mem_mgr *mmg,
spin_unlock(&mmg->lock); spin_unlock(&mmg->lock);
if (rc < 0) { if (rc < 0) {
dev_err(mmg->dev, dev_err(mmg->dev,
"Failed to allocate IDR for a new buffer, rc=%d\n", rc); "%s: Failed to allocate IDR for a new buffer, rc=%d\n",
behavior->topic, rc);
goto free_buf; goto free_buf;
} }
...@@ -173,8 +174,8 @@ hl_mmap_mem_buf_alloc(struct hl_mem_mgr *mmg, ...@@ -173,8 +174,8 @@ hl_mmap_mem_buf_alloc(struct hl_mem_mgr *mmg,
rc = buf->behavior->alloc(buf, gfp, args); rc = buf->behavior->alloc(buf, gfp, args);
if (rc) { if (rc) {
dev_err(mmg->dev, "Failure in buffer alloc callback %d\n", dev_err(mmg->dev, "%s: Failure in buffer alloc callback %d\n",
rc); behavior->topic, rc);
goto remove_idr; goto remove_idr;
} }
...@@ -253,8 +254,8 @@ int hl_mem_mgr_mmap(struct hl_mem_mgr *mmg, struct vm_area_struct *vma, ...@@ -253,8 +254,8 @@ int hl_mem_mgr_mmap(struct hl_mem_mgr *mmg, struct vm_area_struct *vma,
user_mem_size = vma->vm_end - vma->vm_start; user_mem_size = vma->vm_end - vma->vm_start;
if (user_mem_size != ALIGN(buf->mappable_size, PAGE_SIZE)) { if (user_mem_size != ALIGN(buf->mappable_size, PAGE_SIZE)) {
dev_err(mmg->dev, dev_err(mmg->dev,
"Memory mmap failed, mmap VM size 0x%llx != 0x%llx allocated physical mem size\n", "%s: Memory mmap failed, mmap VM size 0x%llx != 0x%llx allocated physical mem size\n",
user_mem_size, buf->mappable_size); buf->behavior->topic, user_mem_size, buf->mappable_size);
rc = -EINVAL; rc = -EINVAL;
goto put_mem; goto put_mem;
} }
...@@ -266,8 +267,8 @@ int hl_mem_mgr_mmap(struct hl_mem_mgr *mmg, struct vm_area_struct *vma, ...@@ -266,8 +267,8 @@ int hl_mem_mgr_mmap(struct hl_mem_mgr *mmg, struct vm_area_struct *vma,
if (!access_ok((void __user *)(uintptr_t)vma->vm_start, if (!access_ok((void __user *)(uintptr_t)vma->vm_start,
user_mem_size)) { user_mem_size)) {
#endif #endif
dev_err(mmg->dev, "user pointer is invalid - 0x%lx\n", dev_err(mmg->dev, "%s: User pointer is invalid - 0x%lx\n",
vma->vm_start); buf->behavior->topic, vma->vm_start);
rc = -EINVAL; rc = -EINVAL;
goto put_mem; goto put_mem;
...@@ -275,7 +276,8 @@ int hl_mem_mgr_mmap(struct hl_mem_mgr *mmg, struct vm_area_struct *vma, ...@@ -275,7 +276,8 @@ int hl_mem_mgr_mmap(struct hl_mem_mgr *mmg, struct vm_area_struct *vma,
if (atomic_cmpxchg(&buf->mmap, 0, 1)) { if (atomic_cmpxchg(&buf->mmap, 0, 1)) {
dev_err(mmg->dev, dev_err(mmg->dev,
"Memory mmap failed, already mmaped to user\n"); "%s, Memory mmap failed, already mmaped to user\n",
buf->behavior->topic);
rc = -EINVAL; rc = -EINVAL;
goto put_mem; goto put_mem;
} }
...@@ -328,14 +330,17 @@ void hl_mem_mgr_fini(struct hl_mem_mgr *mmg) ...@@ -328,14 +330,17 @@ void hl_mem_mgr_fini(struct hl_mem_mgr *mmg)
{ {
struct hl_mmap_mem_buf *buf; struct hl_mmap_mem_buf *buf;
struct idr *idp; struct idr *idp;
const char *topic;
u32 id; u32 id;
idp = &mmg->handles; idp = &mmg->handles;
idr_for_each_entry(idp, buf, id) { idr_for_each_entry(idp, buf, id) {
topic = buf->behavior->topic;
if (hl_mmap_mem_buf_put(buf) != 1) if (hl_mmap_mem_buf_put(buf) != 1)
dev_err(mmg->dev, dev_err(mmg->dev,
"Buff handle %u for CTX is still alive\n", id); "%s: Buff handle %u for CTX is still alive\n",
topic, id);
} }
/* TODO: can it happen that some buffer is still in use at this point? */ /* TODO: can it happen that some buffer is still in use at this point? */
......
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