diff options
author | Jordan Crouse <jcrouse@codeaurora.org> | 2016-05-03 14:11:03 -0600 |
---|---|---|
committer | Kyle Yan <kyan@codeaurora.org> | 2016-05-26 15:26:48 -0700 |
commit | d16c4eb6879a0cf677144fbfa2621670252f629a (patch) | |
tree | 1cd9fad7d7358c3e0ad9bfcd11e63b90ea2aea3b /drivers/gpu | |
parent | eb2c3035ea0e6556fa7a411198662ab1739c8b6c (diff) |
msm: kgsl: Defer adding the mem entry to a process
If we add the mem entry pointer in the process mem_idr too early
other threads can do operations on the entry by guessing the ID
or GPU address before the object gets returned by the creating
operation.
Allocate an ID for the object but don't assign the pointer until
right before the creating function returns ensuring that another
operation can't access it until it is ready.
CRs-Fixed: 1002974
Change-Id: Ic0dedbadc0dd2125bd2a7bcc152972c0555e07f8
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Diffstat (limited to 'drivers/gpu')
-rw-r--r-- | drivers/gpu/msm/kgsl.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/drivers/gpu/msm/kgsl.c b/drivers/gpu/msm/kgsl.c index 51dc781b2bd4..2563591f376e 100644 --- a/drivers/gpu/msm/kgsl.c +++ b/drivers/gpu/msm/kgsl.c @@ -388,6 +388,17 @@ kgsl_mem_entry_untrack_gpuaddr(struct kgsl_process_private *process, kgsl_mmu_put_gpuaddr(pagetable, &entry->memdesc); } +/* Commit the entry to the process so it can be accessed by other operations */ +static void kgsl_mem_entry_commit_process(struct kgsl_mem_entry *entry) +{ + if (!entry) + return; + + spin_lock(&entry->priv->mem_lock); + idr_replace(&entry->priv->mem_idr, entry, entry->id); + spin_unlock(&entry->priv->mem_lock); +} + /** * kgsl_mem_entry_attach_process - Attach a mem_entry to its owner process * @entry: the memory entry @@ -418,7 +429,8 @@ kgsl_mem_entry_attach_process(struct kgsl_mem_entry *entry, idr_preload(GFP_KERNEL); spin_lock(&process->mem_lock); - id = idr_alloc(&process->mem_idr, entry, 1, 0, GFP_NOWAIT); + /* Allocate the ID but don't attach the pointer just yet */ + id = idr_alloc(&process->mem_idr, NULL, 1, 0, GFP_NOWAIT); spin_unlock(&process->mem_lock); idr_preload_end(); @@ -2317,6 +2329,7 @@ long kgsl_ioctl_gpuobj_import(struct kgsl_device_private *dev_priv, trace_kgsl_mem_map(entry, fd); + kgsl_mem_entry_commit_process(entry); return 0; unmap: @@ -2580,6 +2593,7 @@ long kgsl_ioctl_map_user_mem(struct kgsl_device_private *dev_priv, trace_kgsl_mem_map(entry, param->fd); + kgsl_mem_entry_commit_process(entry); return result; error_attach: @@ -2971,6 +2985,7 @@ static struct kgsl_mem_entry *gpumem_alloc_entry( entry->memdesc.size); trace_kgsl_mem_alloc(entry); + kgsl_mem_entry_commit_process(entry); return entry; err: kfree(entry); |