Commit 6fc96216 authored by Suman Anna's avatar Suman Anna Committed by Hari Kanigeri

SYSLINK: ipc - heapbuf bug fixes

This patch fixes the bugs found during heapbuf sample validation.
The following are the main changes.
	- object creation attributes are assigned conditionally
		based on the create flag passed in _heapbuf_create
	- object lock has been commented out.
	- gt_traces are removed.

These fixes does not resolve the issues seen with heapbuf_destroy
in the sample.
Signed-off-by: default avatarArun M G <arunmg@ti.com>
parent 51f0d3d0
...@@ -114,8 +114,6 @@ struct heapbuf_obj { ...@@ -114,8 +114,6 @@ struct heapbuf_obj {
*/ */
int heapbuf_get_config(struct heap_config *cfgparams) int heapbuf_get_config(struct heap_config *cfgparams)
{ {
gt_1trace(heapbuf_debugmask, GT_ENTER, "heapbuf_get_config:\n"
"cfgparams: %x \n", cfgparams);
BUG_ON(cfgparams == NULL); BUG_ON(cfgparams == NULL);
if (heapbuf_state.nshandle == NULL) if (heapbuf_state.nshandle == NULL)
...@@ -139,8 +137,6 @@ int heapbuf_setup(const struct heap_config *config) ...@@ -139,8 +137,6 @@ int heapbuf_setup(const struct heap_config *config)
void *nshandle = NULL; void *nshandle = NULL;
s32 retval = 0; s32 retval = 0;
gt_1trace(heapbuf_debugmask, GT_ENTER, "heapbuf_setup:\n"
"config: %x \n", config);
BUG_ON(config == NULL); BUG_ON(config == NULL);
if (config->max_name_len == 0 || if (config->max_name_len == 0 ||
...@@ -159,8 +155,10 @@ int heapbuf_setup(const struct heap_config *config) ...@@ -159,8 +155,10 @@ int heapbuf_setup(const struct heap_config *config)
params.max_value_len = sizeof(u32); params.max_value_len = sizeof(u32);
params.max_name_len = config->max_name_len; params.max_name_len = config->max_name_len;
nshandle = nameserver_create(HEAPBUF_NAMESERVER, &params); nshandle = nameserver_create(HEAPBUF_NAMESERVER, &params);
if (nshandle == NULL) if (nshandle == NULL) {
retval = -EFAULT;
goto ns_create_fail; goto ns_create_fail;
}
heapbuf_state.nshandle = nshandle; heapbuf_state.nshandle = nshandle;
memcpy(&heapbuf_state.cfg, config, sizeof(struct heap_config)); memcpy(&heapbuf_state.cfg, config, sizeof(struct heap_config));
...@@ -185,8 +183,7 @@ int heapbuf_destroy(void) ...@@ -185,8 +183,7 @@ int heapbuf_destroy(void)
{ {
s32 retval = 0; s32 retval = 0;
struct mutex *lock = NULL; struct mutex *lock = NULL;
/*struct heapbuf_obj *obj = NULL;*/
gt_0trace(heapbuf_debugmask, GT_ENTER, "heapbuf_destroy:\n");
if (WARN_ON(heapbuf_state.nshandle == NULL)) { if (WARN_ON(heapbuf_state.nshandle == NULL)) {
retval = -ENODEV; retval = -ENODEV;
...@@ -195,10 +192,13 @@ int heapbuf_destroy(void) ...@@ -195,10 +192,13 @@ int heapbuf_destroy(void)
#if 0 #if 0
/* Check if any heapbuf instances have not been deleted so far. /* Check if any heapbuf instances have not been deleted so far.
* if not, delete them IS THIS IS SYSLINK IMP ? * if not, delete them or close
*/ */
List_for_each(elem, &heapbuf_state.obj_list) { list_for_each_entry(obj, &heapbuf_state.obj_list, list_elem) {
heapbuf_delete(((struct heapbuf_obj *)(elem))->top); if (obj->owner->proc_id == multiproc_get_id(NULL))
heapbuf_delete(&obj->free_list);
else
heapbuf_close(&obj->free_list);
} }
#endif #endif
...@@ -241,8 +241,6 @@ void heapbuf_params_init(void *handle, ...@@ -241,8 +241,6 @@ void heapbuf_params_init(void *handle,
struct heapbuf_obj *obj = NULL; struct heapbuf_obj *obj = NULL;
struct heap_object *object = NULL; struct heap_object *object = NULL;
gt_2trace(heap_debugmask, GT_6CLASS, "heapbuf_params_init:\n"
"handle: %x, params: %x \n", handle, params);
BUG_ON(params == NULL); BUG_ON(params == NULL);
if (handle == NULL) if (handle == NULL)
...@@ -262,6 +260,10 @@ EXPORT_SYMBOL(heapbuf_params_init); ...@@ -262,6 +260,10 @@ EXPORT_SYMBOL(heapbuf_params_init);
* This will create a new instance of heapbuf module * This will create a new instance of heapbuf module
* This is an internal function as both heapbuf_create * This is an internal function as both heapbuf_create
* and heapbuf_open use the functionality * and heapbuf_open use the functionality
*
* NOTE: The lock to protect the shared memory area
* used by heapbuf is provided by the consumer of
* heapbuf module
*/ */
static void *_heapbuf_create(const struct heapbuf_params *params, static void *_heapbuf_create(const struct heapbuf_params *params,
u32 createflag) u32 createflag)
...@@ -277,8 +279,6 @@ static void *_heapbuf_create(const struct heapbuf_params *params, ...@@ -277,8 +279,6 @@ static void *_heapbuf_create(const struct heapbuf_params *params,
u32 shared_shmbase; u32 shared_shmbase;
void *entry = NULL; void *entry = NULL;
gt_2trace(heap_debugmask, GT_6CLASS, "_heapbuf_create:\n"
"params: %x, createflag: %x \n", params, createflag);
BUG_ON(params == NULL); BUG_ON(params == NULL);
handle = kmalloc(sizeof(struct heap_object), GFP_KERNEL); handle = kmalloc(sizeof(struct heap_object), GFP_KERNEL);
...@@ -305,6 +305,7 @@ static void *_heapbuf_create(const struct heapbuf_params *params, ...@@ -305,6 +305,7 @@ static void *_heapbuf_create(const struct heapbuf_params *params,
listmp_params.shared_addr_size = listmp_params.shared_addr_size =
listmp_sharedmemory_shared_memreq(&listmp_params); listmp_sharedmemory_shared_memreq(&listmp_params);
listmp_params.lock_handle = params->lock_handle; listmp_params.lock_handle = params->lock_handle;
obj->lock_handle = params->lock_handle;
if (createflag == true) if (createflag == true)
obj->free_list = listmp_sharedmemory_create(&listmp_params); obj->free_list = listmp_sharedmemory_create(&listmp_params);
else else
...@@ -314,48 +315,48 @@ static void *_heapbuf_create(const struct heapbuf_params *params, ...@@ -314,48 +315,48 @@ static void *_heapbuf_create(const struct heapbuf_params *params,
retval = -ENOMEM; retval = -ENOMEM;
goto listmp_error; goto listmp_error;
} }
obj->lock_handle = kmalloc(sizeof(struct mutex), GFP_KERNEL);
if (obj->lock_handle == NULL) {
retval = -ENOMEM;
goto gate_create_error;
}
/* Assign the memory with proper cache line padding */ /* Assign the memory with proper cache line padding */
obj->attrs = (struct heapbuf_attrs *) params->shared_addr; obj->attrs = (struct heapbuf_attrs *) params->shared_addr;
obj->attrs->version = HEAPBUF_VERSION; if (createflag == true) {
obj->attrs->num_free_blocks = params->num_blocks; obj->attrs->version = HEAPBUF_VERSION;
obj->attrs->min_free_blocks = params->num_blocks; obj->attrs->num_free_blocks = params->num_blocks;
obj->attrs->block_size = params->block_size; obj->attrs->min_free_blocks = params->num_blocks;
obj->attrs->align = params->align; obj->attrs->block_size = params->block_size;
obj->attrs->num_blocks = params->num_blocks; obj->attrs->align = params->align;
obj->attrs->buf = (char *)((u32 *)(obj->attrs) + obj->attrs->num_blocks = params->num_blocks;
obj->attrs->buf = (char *)((u32 *)(obj->attrs) +
HEAPBUF_CACHESIZE + listmp_params.shared_addr_size); HEAPBUF_CACHESIZE + listmp_params.shared_addr_size);
buf = obj->attrs->buf; buf = obj->attrs->buf;
align = obj->attrs->align; align = obj->attrs->align;
buf = (char *)(((u32)buf + (align - 1)) & ~(align - 1)); buf = (char *)(((u32)buf + (align - 1)) & ~(align - 1));
obj->attrs->buf = buf; obj->attrs->buf = buf;
/* /*
* Split the buffer into blocks that are length * Split the buffer into blocks that are length
* block_size" and add into the free_list Queue * block_size" and add into the free_list Queue
*/ */
for (i = 0; i < obj->attrs->num_blocks; i++) { for (i = 0; i < obj->attrs->num_blocks; i++) {
listmp_put_tail((void *)obj->free_list, listmp_put_tail((struct listmp_object *)
(struct listmp_elem *)buf); obj->free_list,
buf += obj->attrs->block_size; (struct listmp_elem *)buf);
buf += obj->attrs->block_size;
}
} }
/* Populate the params member */ /* Populate the params member */
memcpy(&obj->params, params, sizeof(struct heapbuf_params)); memcpy(&obj->params, params, sizeof(struct heapbuf_params));
if (params->name != NULL) { if (createflag == true) {
obj->params.name = kmalloc(strlen(params->name) + 1, if (params->name != NULL) {
GFP_KERNEL); obj->params.name = kmalloc(strlen(params->name) + 1,
if (obj->params.name == NULL) { GFP_KERNEL);
retval = -ENOMEM; if (obj->params.name == NULL) {
goto name_alloc_error; retval = -ENOMEM;
} goto name_alloc_error;
}
strncpy(obj->params.name, params->name,
strncpy(obj->params.name, params->name,
strlen(params->name) + 1); strlen(params->name) + 1);
}
} }
/* Update processor information */ /* Update processor information */
...@@ -385,16 +386,20 @@ static void *_heapbuf_create(const struct heapbuf_params *params, ...@@ -385,16 +386,20 @@ static void *_heapbuf_create(const struct heapbuf_params *params,
obj->top = handle; obj->top = handle;
} }
/* We will store a shared pointer in the nameserver */ if (createflag == true) {
shmindex = sharedregion_get_index(params->shared_addr); /* We will store a shared pointer in the nameserver */
shared_shmbase = (u32)sharedregion_get_srptr(params->shared_addr, shmindex = sharedregion_get_index(params->shared_addr);
shmindex); shared_shmbase = (u32)sharedregion_get_srptr(
if (obj->params.name != NULL) { params->shared_addr, shmindex);
entry = nameserver_add_uint32(heapbuf_state.nshandle, if (obj->params.name != NULL) {
params->name, entry = nameserver_add_uint32(heapbuf_state.nshandle,
(u32)(params->shared_addr)); params->name,
if (entry == NULL) (u32)(shared_shmbase));
goto ns_add_error; if (entry == NULL) {
retval = -EFAULT;
goto ns_add_error;
}
}
} }
retval = mutex_lock_interruptible(heapbuf_state.list_lock); retval = mutex_lock_interruptible(heapbuf_state.list_lock);
...@@ -415,7 +420,6 @@ proc_attr_alloc_error: ...@@ -415,7 +420,6 @@ proc_attr_alloc_error:
name_alloc_error: /* Fall through */ name_alloc_error: /* Fall through */
listmp_sharedmemory_delete((listmp_sharedmemory_handle *) listmp_sharedmemory_delete((listmp_sharedmemory_handle *)
&obj->free_list); &obj->free_list);
gate_create_error: /* Fall through */
listmp_error: listmp_error:
kfree(obj); kfree(obj);
...@@ -438,10 +442,7 @@ void *heapbuf_create(const struct heapbuf_params *params) ...@@ -438,10 +442,7 @@ void *heapbuf_create(const struct heapbuf_params *params)
u32 size; u32 size;
void *handle = NULL; void *handle = NULL;
gt_1trace(heap_debugmask, GT_6CLASS, "heapbuf_create:\n"
"params: %x \n", params);
BUG_ON(params == NULL); BUG_ON(params == NULL);
if (WARN_ON(heapbuf_state.nshandle == NULL)) { if (WARN_ON(heapbuf_state.nshandle == NULL)) {
retval = -ENODEV; retval = -ENODEV;
goto error; goto error;
...@@ -479,17 +480,12 @@ int heapbuf_delete(void **hphandle) ...@@ -479,17 +480,12 @@ int heapbuf_delete(void **hphandle)
struct heapbuf_params *params = NULL; struct heapbuf_params *params = NULL;
s32 retval = 0; s32 retval = 0;
u16 myproc_id; u16 myproc_id;
struct mutex *lock = NULL;
gt_1trace(heap_debugmask, GT_6CLASS, "heapbuf_delete:\n"
"params: %x \n", params);
BUG_ON(hphandle == NULL); BUG_ON(hphandle == NULL);
if (WARN_ON(heapbuf_state.nshandle == NULL)) { if (WARN_ON(heapbuf_state.nshandle == NULL)) {
retval = -ENODEV; retval = -ENODEV;
goto error; goto error;
} }
handle = (struct heap_object *)(*hphandle); handle = (struct heap_object *)(*hphandle);
if (WARN_ON(handle == NULL)) { if (WARN_ON(handle == NULL)) {
retval = -EINVAL; retval = -EINVAL;
...@@ -498,15 +494,12 @@ int heapbuf_delete(void **hphandle) ...@@ -498,15 +494,12 @@ int heapbuf_delete(void **hphandle)
obj = (struct heapbuf_obj *)handle->obj; obj = (struct heapbuf_obj *)handle->obj;
myproc_id = multiproc_get_id(NULL); myproc_id = multiproc_get_id(NULL);
if (obj->owner->proc_id != myproc_id) { if (obj->owner->proc_id != myproc_id) {
retval = -EPERM; retval = -EPERM;
goto error; goto error;
} }
retval = mutex_lock_interruptible(obj->lock_handle);
if (retval)
goto error;
if (obj->owner->open_count != 1 || obj->remote->open_count != 0) { if (obj->owner->open_count != 1 || obj->remote->open_count != 0) {
retval = -EBUSY; retval = -EBUSY;
goto device_busy_error;; goto device_busy_error;;
...@@ -528,10 +521,6 @@ int heapbuf_delete(void **hphandle) ...@@ -528,10 +521,6 @@ int heapbuf_delete(void **hphandle)
kfree(params->name); kfree(params->name);
} }
lock = obj->lock_handle;
obj->lock_handle = NULL;
mutex_unlock(lock);
kfree(lock);
retval = listmp_sharedmemory_delete(&obj->free_list); retval = listmp_sharedmemory_delete(&obj->free_list);
kfree(obj->owner); kfree(obj->owner);
kfree(obj->remote); kfree(obj->remote);
...@@ -543,7 +532,7 @@ int heapbuf_delete(void **hphandle) ...@@ -543,7 +532,7 @@ int heapbuf_delete(void **hphandle)
ns_remove_error: /* Fall through */ ns_remove_error: /* Fall through */
list_lock_error: /* Fall through */ list_lock_error: /* Fall through */
device_busy_error: device_busy_error:
mutex_unlock(obj->lock_handle); /* mutex_unlock(obj->lock_handle); */
error: error:
printk(KERN_ERR "heapbuf_delete failed status: %x\n", retval); printk(KERN_ERR "heapbuf_delete failed status: %x\n", retval);
...@@ -576,11 +565,6 @@ int heapbuf_open(void **hphandle, ...@@ -576,11 +565,6 @@ int heapbuf_open(void **hphandle,
goto error; goto error;
} }
if (*hphandle == NULL) {
retval = -EINVAL;
goto error;
}
if ((params->name == NULL) && (params->shared_addr == (u32)NULL)) { if ((params->name == NULL) && (params->shared_addr == (u32)NULL)) {
retval = -EINVAL; retval = -EINVAL;
goto error; goto error;
...@@ -637,10 +621,6 @@ int heapbuf_close(void *hphandle) ...@@ -637,10 +621,6 @@ int heapbuf_close(void *hphandle)
struct heapbuf_params *params = NULL; struct heapbuf_params *params = NULL;
s32 retval = 0; s32 retval = 0;
u16 myproc_id = 0; u16 myproc_id = 0;
struct mutex *lock = NULL;
gt_1trace(heapbuf_debugmask, GT_ENTER,
"heapbuf_close:\n hphandle: %x \n", hphandle);
if (WARN_ON(heapbuf_state.nshandle == NULL)) { if (WARN_ON(heapbuf_state.nshandle == NULL)) {
retval = -EINVAL; retval = -EINVAL;
...@@ -662,27 +642,19 @@ int heapbuf_close(void *hphandle) ...@@ -662,27 +642,19 @@ int heapbuf_close(void *hphandle)
if ((obj->remote->proc_id == myproc_id) if ((obj->remote->proc_id == myproc_id)
&& (obj->remote->open_count == 0)) { && (obj->remote->open_count == 0)) {
list_del(&obj->list_elem); list_del(&obj->list_elem);
retval = mutex_lock_interruptible(obj->lock_handle);
if (retval)
goto error;
params = (struct heapbuf_params *)&obj->params; params = (struct heapbuf_params *)&obj->params;
if (params->name != NULL) { if (params->name != NULL) {
retval = nameserver_remove(heapbuf_state.nshandle, retval = nameserver_remove(heapbuf_state.nshandle,
params->name); params->name);
if (unlikely(retval != 0)) if (unlikely(retval != 0))
goto error; goto error;
} }
kfree(params->name); kfree(params->name);
} }
lock = obj->lock_handle; listmp_sharedmemory_close((listmp_sharedmemory_handle *)
obj->lock_handle = NULL; obj->free_list);
mutex_unlock(lock);
kfree(lock);
listmp_sharedmemory_delete((listmp_sharedmemory_handle *)
&obj->free_list);
kfree(obj->owner); kfree(obj->owner);
kfree(obj->remote); kfree(obj->remote);
kfree(obj); kfree(obj);
...@@ -710,11 +682,6 @@ void *heapbuf_alloc(void *hphandle, u32 size, u32 align) ...@@ -710,11 +682,6 @@ void *heapbuf_alloc(void *hphandle, u32 size, u32 align)
char *block = NULL; char *block = NULL;
s32 retval = 0; s32 retval = 0;
gt_3trace(heapbuf_debugmask, GT_ENTER,
"heapbuf_free:\n"
"hphandle: %x, size: %x, align: %x\n",
hphandle, size, align);
if (WARN_ON(heapbuf_state.nshandle == NULL)) if (WARN_ON(heapbuf_state.nshandle == NULL))
goto error; goto error;
...@@ -770,11 +737,6 @@ int heapbuf_free(void *hphandle, void *block, u32 size) ...@@ -770,11 +737,6 @@ int heapbuf_free(void *hphandle, void *block, u32 size)
struct heapbuf_obj *obj = NULL; struct heapbuf_obj *obj = NULL;
s32 retval = 0; s32 retval = 0;
gt_3trace(heapbuf_debugmask, GT_ENTER,
"heapbuf_free:\n"
"hphandle: %x, block: %x, size: %x\n",
hphandle, block, size);
if (WARN_ON(heapbuf_state.nshandle == NULL)) { if (WARN_ON(heapbuf_state.nshandle == NULL)) {
retval = -EINVAL; retval = -EINVAL;
goto error; goto error;
...@@ -819,11 +781,7 @@ int heapbuf_get_stats(void *hphandle, struct memory_stats *stats) ...@@ -819,11 +781,7 @@ int heapbuf_get_stats(void *hphandle, struct memory_stats *stats)
u32 block_size; u32 block_size;
s32 retval = 0; s32 retval = 0;
gt_2trace(heapbuf_debugmask, GT_ENTER,
"heapbuf_get_stats:\n"
"hphandle: %x, stats: %x\n", hphandle, stats);
BUG_ON(stats == NULL); BUG_ON(stats == NULL);
if (WARN_ON(heapbuf_state.nshandle == NULL)) { if (WARN_ON(heapbuf_state.nshandle == NULL)) {
retval = -EINVAL; retval = -EINVAL;
goto error; goto error;
...@@ -870,11 +828,7 @@ int heapbuf_get_extended_stats(void *hphandle, ...@@ -870,11 +828,7 @@ int heapbuf_get_extended_stats(void *hphandle,
struct heapbuf_obj *obj = NULL; struct heapbuf_obj *obj = NULL;
s32 retval = 0; s32 retval = 0;
gt_2trace(heapbuf_debugmask, GT_ENTER,
"heapbuf_get_extended_stats:\n"
"hphandle: %x, stats: %x\n", hphandle, stats);
BUG_ON(stats == NULL); BUG_ON(stats == NULL);
if (WARN_ON(heapbuf_state.nshandle == NULL)) { if (WARN_ON(heapbuf_state.nshandle == NULL)) {
retval = -EINVAL; retval = -EINVAL;
goto error; goto error;
...@@ -932,10 +886,7 @@ int heapbuf_shared_memreq(const struct heapbuf_params *params) ...@@ -932,10 +886,7 @@ int heapbuf_shared_memreq(const struct heapbuf_params *params)
s32 retval = 0; s32 retval = 0;
listmp_sharedmemory_params listmp_params; listmp_sharedmemory_params listmp_params;
gt_1trace(heapbuf_debugmask, GT_ENTER,
"heapbuf_sharedmemreq", params);
BUG_ON(params == NULL); BUG_ON(params == NULL);
retval = params->num_blocks * params->block_size; retval = params->num_blocks * params->block_size;
listmp_sharedmemory_params_init(NULL, &listmp_params); listmp_sharedmemory_params_init(NULL, &listmp_params);
retval += listmp_sharedmemory_shared_memreq(&listmp_params); retval += listmp_sharedmemory_shared_memreq(&listmp_params);
......
...@@ -82,6 +82,7 @@ static int heapbuf_ioctl_params_init(struct heapbuf_cmd_args *cargs) ...@@ -82,6 +82,7 @@ static int heapbuf_ioctl_params_init(struct heapbuf_cmd_args *cargs)
u32 size; u32 size;
heapbuf_params_init(cargs->args.params_init.handle, &params); heapbuf_params_init(cargs->args.params_init.handle, &params);
cargs->api_status = 0;
size = copy_to_user(cargs->args.params_init.params, &params, size = copy_to_user(cargs->args.params_init.params, &params,
sizeof(struct heapbuf_params)); sizeof(struct heapbuf_params));
if (size) if (size)
...@@ -149,7 +150,7 @@ exit: ...@@ -149,7 +150,7 @@ exit:
*/ */
static int heapbuf_ioctl_delete(struct heapbuf_cmd_args *cargs) static int heapbuf_ioctl_delete(struct heapbuf_cmd_args *cargs)
{ {
cargs->api_status = heapbuf_delete(cargs->args.delete.handle); cargs->api_status = heapbuf_delete(&cargs->args.delete.handle);
return 0; return 0;
} }
......
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