From 4a94c135f062ab41bc99376aa1a4bd64d33e47d9 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Wed, 8 Mar 2017 17:07:45 -0800 Subject: gpu: nvgpu: Use new kmem API functions (channel) Use the new kmem API functions in the channel and channel related code. Also delete the usage of kasprintf() since that must be paired with a kfree(). Since the kasprintf() doesn't use the nvgpu kmem machinery (and is Linux specific) instead use a small buffer statically allocated on the stack. Bug 1799159 Bug 1823380 Change-Id: Ied0183f57372632264e55608f56539861cc0f24f Signed-off-by: Alex Waterman Reviewed-on: http://git-master/r/1318312 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/gk20a/channel_gk20a.c | 58 ++++++++++++---------------- drivers/gpu/nvgpu/gk20a/channel_sync_gk20a.c | 24 ++++++------ drivers/gpu/nvgpu/gk20a/fifo_gk20a.c | 57 ++++++++++++++------------- drivers/gpu/nvgpu/gk20a/sched_gk20a.c | 23 +++++------ drivers/gpu/nvgpu/gk20a/tsg_gk20a.c | 17 ++++---- 5 files changed, 87 insertions(+), 92 deletions(-) (limited to 'drivers') diff --git a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c index c09539ff..26fbd66e 100644 --- a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -1244,7 +1243,7 @@ int gk20a_channel_release(struct inode *inode, struct file *filp) channel_release: gk20a_put(g); - kfree(filp->private_data); + nvgpu_kfree(g, filp->private_data); filp->private_data = NULL; return 0; } @@ -1390,7 +1389,7 @@ static int __gk20a_channel_open(struct gk20a *g, struct file *filp, s32 runlist_ trace_gk20a_channel_open(dev_name(g->dev)); - priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv = nvgpu_kzalloc(g, sizeof(*priv)); if (!priv) { err = -ENOMEM; goto free_ref; @@ -1421,7 +1420,7 @@ static int __gk20a_channel_open(struct gk20a *g, struct file *filp, s32 runlist_ return 0; fail_busy: - kfree(priv); + nvgpu_kfree(g, priv); free_ref: gk20a_put(g); return err; @@ -1446,7 +1445,7 @@ int gk20a_channel_open_ioctl(struct gk20a *g, int err; int fd; struct file *file; - char *name; + char name[64]; s32 runlist_id = args->in.runlist_id; err = get_unused_fd_flags(O_RDWR); @@ -1454,15 +1453,10 @@ int gk20a_channel_open_ioctl(struct gk20a *g, return err; fd = err; - name = kasprintf(GFP_KERNEL, "nvhost-%s-fd%d", - dev_name(g->dev), fd); - if (!name) { - err = -ENOMEM; - goto clean_up; - } + snprintf(name, sizeof(name), "nvhost-%s-fd%d", + dev_name(g->dev), fd); file = anon_inode_getfile(name, g->channel.cdev.ops, NULL, O_RDWR); - kfree(name); if (IS_ERR(file)) { err = PTR_ERR(file); goto clean_up; @@ -1609,7 +1603,7 @@ static void free_priv_cmdbuf(struct channel_gk20a *c, if (channel_gk20a_is_prealloc_enabled(c)) memset(e, 0, sizeof(struct priv_cmd_entry)); else - kfree(e); + nvgpu_kfree(c->g, e); } static int channel_gk20a_alloc_job(struct channel_gk20a *c, @@ -1635,8 +1629,8 @@ static int channel_gk20a_alloc_job(struct channel_gk20a *c, err = -EAGAIN; } } else { - *job_out = kzalloc(sizeof(struct channel_gk20a_job), - GFP_KERNEL); + *job_out = nvgpu_kzalloc(c->g, + sizeof(struct channel_gk20a_job)); if (!*job_out) err = -ENOMEM; } @@ -1659,7 +1653,7 @@ static void channel_gk20a_free_job(struct channel_gk20a *c, job->wait_cmd = wait_cmd; job->incr_cmd = incr_cmd; } else - kfree(job); + nvgpu_kfree(c->g, job); } void channel_gk20a_joblist_lock(struct channel_gk20a *c) @@ -1757,7 +1751,8 @@ static int channel_gk20a_prealloc_resources(struct channel_gk20a *c, */ size = sizeof(struct channel_gk20a_job); if (num_jobs <= ULONG_MAX / size) - c->joblist.pre_alloc.jobs = vzalloc(num_jobs * size); + c->joblist.pre_alloc.jobs = nvgpu_vzalloc(c->g, + num_jobs * size); if (!c->joblist.pre_alloc.jobs) { err = -ENOMEM; goto clean_up; @@ -1770,7 +1765,7 @@ static int channel_gk20a_prealloc_resources(struct channel_gk20a *c, */ size = sizeof(struct priv_cmd_entry); if (num_jobs <= ULONG_MAX / (size << 1)) - entries = vzalloc((num_jobs << 1) * size); + entries = nvgpu_vzalloc(c->g, (num_jobs << 1) * size); if (!entries) { err = -ENOMEM; goto clean_up_joblist; @@ -1799,9 +1794,9 @@ static int channel_gk20a_prealloc_resources(struct channel_gk20a *c, return 0; clean_up_priv_cmd: - vfree(entries); + nvgpu_vfree(c->g, entries); clean_up_joblist: - vfree(c->joblist.pre_alloc.jobs); + nvgpu_vfree(c->g, c->joblist.pre_alloc.jobs); clean_up: memset(&c->joblist.pre_alloc, 0, sizeof(c->joblist.pre_alloc)); return err; @@ -1809,8 +1804,8 @@ clean_up: static void channel_gk20a_free_prealloc_resources(struct channel_gk20a *c) { - vfree(c->joblist.pre_alloc.jobs[0].wait_cmd); - vfree(c->joblist.pre_alloc.jobs); + nvgpu_vfree(c->g, c->joblist.pre_alloc.jobs[0].wait_cmd); + nvgpu_vfree(c->g, c->joblist.pre_alloc.jobs); gk20a_free_fence_pool(c); /* @@ -2910,8 +2905,8 @@ static int gk20a_submit_prepare_syncs(struct channel_gk20a *c, } if (!pre_alloc_enabled) - job->wait_cmd = kzalloc(sizeof(struct priv_cmd_entry), - GFP_KERNEL); + job->wait_cmd = nvgpu_kzalloc(g, + sizeof(struct priv_cmd_entry)); if (!job->wait_cmd) { err = -ENOMEM; @@ -2951,8 +2946,7 @@ static int gk20a_submit_prepare_syncs(struct channel_gk20a *c, goto clean_up_wait_cmd; } if (!pre_alloc_enabled) - job->incr_cmd = kzalloc(sizeof(struct priv_cmd_entry), - GFP_KERNEL); + job->incr_cmd = nvgpu_kzalloc(g, sizeof(struct priv_cmd_entry)); if (!job->incr_cmd) { err = -ENOMEM; @@ -3520,7 +3514,7 @@ static int gk20a_event_id_release(struct inode *inode, struct file *filp) nvgpu_mutex_destroy(&event_id_data->lock); gk20a_put(g); - kfree(event_id_data); + nvgpu_kfree(g, event_id_data); filp->private_data = NULL; return 0; @@ -3588,7 +3582,7 @@ static int gk20a_channel_event_id_enable(struct channel_gk20a *ch, int err = 0; int local_fd; struct file *file; - char *name; + char name[64]; struct gk20a_event_id_data *event_id_data; g = gk20a_get(ch->g); @@ -3608,18 +3602,16 @@ static int gk20a_channel_event_id_enable(struct channel_gk20a *ch, goto free_ref; local_fd = err; - name = kasprintf(GFP_KERNEL, "nvgpu-event%d-fd%d", - event_id, local_fd); - + snprintf(name, sizeof(name), "nvgpu-event%d-fd%d", + event_id, local_fd); file = anon_inode_getfile(name, &gk20a_event_id_ops, NULL, O_RDWR); - kfree(name); if (IS_ERR(file)) { err = PTR_ERR(file); goto clean_up; } - event_id_data = kzalloc(sizeof(*event_id_data), GFP_KERNEL); + event_id_data = nvgpu_kzalloc(ch->g, sizeof(*event_id_data)); if (!event_id_data) { err = -ENOMEM; goto clean_up_file; diff --git a/drivers/gpu/nvgpu/gk20a/channel_sync_gk20a.c b/drivers/gpu/nvgpu/gk20a/channel_sync_gk20a.c index b4870c33..11448094 100644 --- a/drivers/gpu/nvgpu/gk20a/channel_sync_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/channel_sync_gk20a.c @@ -19,6 +19,7 @@ #include #include +#include #include "channel_sync_gk20a.h" #include "gk20a.h" @@ -339,7 +340,7 @@ static void gk20a_channel_syncpt_destroy(struct gk20a_channel_sync *s) container_of(s, struct gk20a_channel_syncpt, ops); nvhost_syncpt_set_min_eq_max_ext(sp->host1x_pdev, sp->id); nvhost_syncpt_put_ref_ext(sp->host1x_pdev, sp->id); - kfree(sp); + nvgpu_kfree(sp->c->g, sp); } static struct gk20a_channel_sync * @@ -348,7 +349,7 @@ gk20a_channel_syncpt_create(struct channel_gk20a *c) struct gk20a_channel_syncpt *sp; char syncpt_name[32]; - sp = kzalloc(sizeof(*sp), GFP_KERNEL); + sp = nvgpu_kzalloc(c->g, sizeof(*sp)); if (!sp) return NULL; @@ -361,7 +362,7 @@ gk20a_channel_syncpt_create(struct channel_gk20a *c) sp->id = nvhost_get_syncpt_host_managed(sp->host1x_pdev, c->hw_chid, syncpt_name); if (!sp->id) { - kfree(sp); + nvgpu_kfree(c->g, sp); gk20a_err(c->g->dev, "failed to get free syncpt"); return NULL; } @@ -464,12 +465,13 @@ void gk20a_channel_cancel_pending_sema_waits(struct gk20a *g) list_del_init(&work->entry); /* - * Only kfree() work if the cancel is successful. Otherwise it's - * in use by the gk20a_channel_semaphore_launcher() code. + * Only nvgpu_kfree() work if the cancel is successful. + * Otherwise it's in use by the + * gk20a_channel_semaphore_launcher() code. */ ret = sync_fence_cancel_async(work->fence, &work->waiter); if (ret == 0) - kfree(work); + nvgpu_kfree(g, work); } } @@ -503,7 +505,7 @@ static void gk20a_channel_semaphore_launcher( sync_fence_put(fence); nvgpu_semaphore_release(w->sema); nvgpu_semaphore_put(w->sema); - kfree(w); + nvgpu_kfree(g, w); } #endif @@ -706,7 +708,7 @@ static int gk20a_channel_semaphore_wait_fd( goto clean_up_sync_fence; } - w = kzalloc(sizeof(*w), GFP_KERNEL); + w = nvgpu_kzalloc(c->g, sizeof(*w)); if (!w) { err = -ENOMEM; goto clean_up_priv_cmd; @@ -766,7 +768,7 @@ clean_up_sema: nvgpu_semaphore_put(w->sema); nvgpu_semaphore_put(w->sema); clean_up_worker: - kfree(w); + nvgpu_kfree(c->g, w); clean_up_priv_cmd: gk20a_free_priv_cmdbuf(c, entry); clean_up_sync_fence: @@ -917,7 +919,7 @@ static void gk20a_channel_semaphore_destroy(struct gk20a_channel_sync *s) /* The sema pool is cleaned up by the VM destroy. */ sema->pool = NULL; - kfree(sema); + nvgpu_kfree(sema->c->g, sema); } static struct gk20a_channel_sync * @@ -930,7 +932,7 @@ gk20a_channel_semaphore_create(struct channel_gk20a *c) if (WARN_ON(!c->vm)) return NULL; - sema = kzalloc(sizeof(*sema), GFP_KERNEL); + sema = nvgpu_kzalloc(c->g, sizeof(*sema)); if (!sema) return NULL; sema->c = c; diff --git a/drivers/gpu/nvgpu/gk20a/fifo_gk20a.c b/drivers/gpu/nvgpu/gk20a/fifo_gk20a.c index 2fa939b9..b390daa4 100644 --- a/drivers/gpu/nvgpu/gk20a/fifo_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/fifo_gk20a.c @@ -18,7 +18,6 @@ */ #include -#include #include #include #include @@ -27,6 +26,7 @@ #include #include +#include #include "gk20a.h" #include "debug_gk20a.h" @@ -483,10 +483,10 @@ void gk20a_fifo_delete_runlist(struct fifo_gk20a *f) gk20a_gmmu_free(g, &runlist->mem[i]); } - kfree(runlist->active_channels); + nvgpu_kfree(g, runlist->active_channels); runlist->active_channels = NULL; - kfree(runlist->active_tsgs); + nvgpu_kfree(g, runlist->active_tsgs); runlist->active_tsgs = NULL; nvgpu_mutex_destroy(&runlist->mutex); @@ -495,7 +495,7 @@ void gk20a_fifo_delete_runlist(struct fifo_gk20a *f) memset(f->runlist_info, 0, (sizeof(struct fifo_runlist_info_gk20a) * f->max_runlists)); - kfree(f->runlist_info); + nvgpu_kfree(g, f->runlist_info); f->runlist_info = NULL; f->max_runlists = 0; } @@ -538,8 +538,8 @@ static void gk20a_remove_fifo_support(struct fifo_gk20a *f) } - vfree(f->channel); - vfree(f->tsg); + nvgpu_vfree(g, f->channel); + nvgpu_vfree(g, f->tsg); if (g->ops.mm.is_bar1_supported(g)) gk20a_gmmu_unmap_free(&g->mm.bar1.vm, &f->userd); else @@ -547,11 +547,11 @@ static void gk20a_remove_fifo_support(struct fifo_gk20a *f) gk20a_fifo_delete_runlist(f); - kfree(f->pbdma_map); + nvgpu_kfree(g, f->pbdma_map); f->pbdma_map = NULL; - kfree(f->engine_info); + nvgpu_kfree(g, f->engine_info); f->engine_info = NULL; - kfree(f->active_engines_list); + nvgpu_kfree(g, f->active_engines_list); f->active_engines_list = NULL; #ifdef CONFIG_DEBUG_FS nvgpu_mutex_acquire(&f->profile.lock); @@ -654,8 +654,9 @@ static int init_runlist(struct gk20a *g, struct fifo_gk20a *f) gk20a_dbg_fn(""); f->max_runlists = g->ops.fifo.eng_runlist_base_size(); - f->runlist_info = kzalloc(sizeof(struct fifo_runlist_info_gk20a) * - f->max_runlists, GFP_KERNEL); + f->runlist_info = nvgpu_kzalloc(g, + sizeof(struct fifo_runlist_info_gk20a) * + f->max_runlists); if (!f->runlist_info) goto clean_up_runlist; @@ -666,14 +667,14 @@ static int init_runlist(struct gk20a *g, struct fifo_gk20a *f) runlist = &f->runlist_info[runlist_id]; runlist->active_channels = - kzalloc(DIV_ROUND_UP(f->num_channels, BITS_PER_BYTE), - GFP_KERNEL); + nvgpu_kzalloc(g, DIV_ROUND_UP(f->num_channels, + BITS_PER_BYTE)); if (!runlist->active_channels) goto clean_up_runlist; runlist->active_tsgs = - kzalloc(DIV_ROUND_UP(f->num_channels, BITS_PER_BYTE), - GFP_KERNEL); + nvgpu_kzalloc(g, DIV_ROUND_UP(f->num_channels, + BITS_PER_BYTE)); if (!runlist->active_tsgs) goto clean_up_runlist; @@ -905,16 +906,14 @@ static int gk20a_init_fifo_setup_sw(struct gk20a *g) f->userd_entry_size = 1 << ram_userd_base_shift_v(); - f->channel = vzalloc(f->num_channels * sizeof(*f->channel)); - f->tsg = vzalloc(f->num_channels * sizeof(*f->tsg)); - f->pbdma_map = kzalloc(f->num_pbdma * sizeof(*f->pbdma_map), - GFP_KERNEL); - f->engine_info = kzalloc(f->max_engines * sizeof(*f->engine_info), - GFP_KERNEL); - f->active_engines_list = kzalloc(f->max_engines * sizeof(u32), - GFP_KERNEL); + f->channel = nvgpu_vzalloc(g, f->num_channels * sizeof(*f->channel)); + f->tsg = nvgpu_vzalloc(g, f->num_channels * sizeof(*f->tsg)); + f->pbdma_map = nvgpu_kzalloc(g, f->num_pbdma * sizeof(*f->pbdma_map)); + f->engine_info = nvgpu_kzalloc(g, f->max_engines * + sizeof(*f->engine_info)); + f->active_engines_list = nvgpu_kzalloc(g, f->max_engines * sizeof(u32)); - if (!(f->channel && f->pbdma_map && f->engine_info && + if (!(f->channel && f->tsg && f->pbdma_map && f->engine_info && f->active_engines_list)) { err = -ENOMEM; goto clean_up; @@ -977,15 +976,15 @@ clean_up: else gk20a_gmmu_free(g, &f->userd); - vfree(f->channel); + nvgpu_vfree(g, f->channel); f->channel = NULL; - vfree(f->tsg); + nvgpu_vfree(g, f->tsg); f->tsg = NULL; - kfree(f->pbdma_map); + nvgpu_kfree(g, f->pbdma_map); f->pbdma_map = NULL; - kfree(f->engine_info); + nvgpu_kfree(g, f->engine_info); f->engine_info = NULL; - kfree(f->active_engines_list); + nvgpu_kfree(g, f->active_engines_list); f->active_engines_list = NULL; return err; diff --git a/drivers/gpu/nvgpu/gk20a/sched_gk20a.c b/drivers/gpu/nvgpu/gk20a/sched_gk20a.c index a73e7993..6b372489 100644 --- a/drivers/gpu/nvgpu/gk20a/sched_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/sched_gk20a.c @@ -12,7 +12,6 @@ */ #include -#include #include #include #include @@ -24,6 +23,8 @@ #include #include +#include + #include "ctxsw_trace_gk20a.h" #include "gk20a.h" #include "gr_gk20a.h" @@ -154,7 +155,7 @@ static int gk20a_sched_dev_ioctl_get_tsgs_by_pid(struct gk20a_sched_ctrl *sched, return -ENOSPC; } - bitmap = kzalloc(sched->bitmap_size, GFP_KERNEL); + bitmap = nvgpu_kzalloc(sched->g, sched->bitmap_size); if (!bitmap) return -ENOMEM; @@ -172,7 +173,7 @@ static int gk20a_sched_dev_ioctl_get_tsgs_by_pid(struct gk20a_sched_ctrl *sched, bitmap, sched->bitmap_size)) err = -EFAULT; - kfree(bitmap); + nvgpu_kfree(sched->g, bitmap); return err; } @@ -650,15 +651,15 @@ int gk20a_sched_ctrl_init(struct gk20a *g) gk20a_dbg(gpu_dbg_fn | gpu_dbg_sched, "g=%p sched=%p size=%zu", g, sched, sched->bitmap_size); - sched->active_tsg_bitmap = kzalloc(sched->bitmap_size, GFP_KERNEL); + sched->active_tsg_bitmap = nvgpu_kzalloc(g, sched->bitmap_size); if (!sched->active_tsg_bitmap) return -ENOMEM; - sched->recent_tsg_bitmap = kzalloc(sched->bitmap_size, GFP_KERNEL); + sched->recent_tsg_bitmap = nvgpu_kzalloc(g, sched->bitmap_size); if (!sched->recent_tsg_bitmap) goto free_active; - sched->ref_tsg_bitmap = kzalloc(sched->bitmap_size, GFP_KERNEL); + sched->ref_tsg_bitmap = nvgpu_kzalloc(g, sched->bitmap_size); if (!sched->ref_tsg_bitmap) goto free_recent; @@ -672,10 +673,10 @@ int gk20a_sched_ctrl_init(struct gk20a *g) return 0; free_recent: - kfree(sched->recent_tsg_bitmap); + nvgpu_kfree(g, sched->recent_tsg_bitmap); free_active: - kfree(sched->active_tsg_bitmap); + nvgpu_kfree(g, sched->active_tsg_bitmap); return -ENOMEM; } @@ -684,9 +685,9 @@ void gk20a_sched_ctrl_cleanup(struct gk20a *g) { struct gk20a_sched_ctrl *sched = &g->sched_ctrl; - kfree(sched->active_tsg_bitmap); - kfree(sched->recent_tsg_bitmap); - kfree(sched->ref_tsg_bitmap); + nvgpu_kfree(g, sched->active_tsg_bitmap); + nvgpu_kfree(g, sched->recent_tsg_bitmap); + nvgpu_kfree(g, sched->ref_tsg_bitmap); sched->active_tsg_bitmap = NULL; sched->recent_tsg_bitmap = NULL; sched->ref_tsg_bitmap = NULL; diff --git a/drivers/gpu/nvgpu/gk20a/tsg_gk20a.c b/drivers/gpu/nvgpu/gk20a/tsg_gk20a.c index 270fed85..21b50700 100644 --- a/drivers/gpu/nvgpu/gk20a/tsg_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/tsg_gk20a.c @@ -22,6 +22,8 @@ #include #include +#include + #include "gk20a.h" #include @@ -257,7 +259,7 @@ static int gk20a_tsg_event_id_enable(struct tsg_gk20a *tsg, int err = 0; int local_fd; struct file *file; - char *name; + char name[64]; struct gk20a_event_id_data *event_id_data; struct gk20a *g; @@ -278,18 +280,17 @@ static int gk20a_tsg_event_id_enable(struct tsg_gk20a *tsg, goto free_ref; local_fd = err; - name = kasprintf(GFP_KERNEL, "nvgpu-event%d-fd%d", - event_id, local_fd); + snprintf(name, sizeof(name), "nvgpu-event%d-fd%d", + event_id, local_fd); file = anon_inode_getfile(name, &gk20a_event_id_ops, NULL, O_RDWR); - kfree(name); if (IS_ERR(file)) { err = PTR_ERR(file); goto clean_up; } - event_id_data = kzalloc(sizeof(*event_id_data), GFP_KERNEL); + event_id_data = nvgpu_kzalloc(tsg->g, sizeof(*event_id_data)); if (!event_id_data) { err = -ENOMEM; goto clean_up_file; @@ -428,7 +429,7 @@ int gk20a_tsg_open(struct gk20a *g, struct file *filp) gk20a_dbg(gpu_dbg_fn, "tsg: %s", dev_name(dev)); - priv = kmalloc(sizeof(*priv), GFP_KERNEL); + priv = nvgpu_kmalloc(g, sizeof(*priv)); if (!priv) { err = -ENOMEM; goto free_ref; @@ -436,7 +437,7 @@ int gk20a_tsg_open(struct gk20a *g, struct file *filp) tsg = acquire_unused_tsg(&g->fifo); if (!tsg) { - kfree(priv); + nvgpu_kfree(g, priv); err = -ENOMEM; goto free_ref; } @@ -533,7 +534,7 @@ int gk20a_tsg_dev_release(struct inode *inode, struct file *filp) struct tsg_gk20a *tsg = priv->tsg; kref_put(&tsg->refcount, gk20a_tsg_release); - kfree(priv); + nvgpu_kfree(tsg->g, priv); return 0; } -- cgit v1.2.2