summaryrefslogtreecommitdiff
path: root/drivers/video
diff options
context:
space:
mode:
authorKrishna Reddy <vdumpa@nvidia.com>2013-01-16 11:24:38 -0800
committerMrutyunjay Sawant <msawant@nvidia.com>2013-03-05 04:09:40 -0800
commit1fe084380011d0fb337610da84b1dc7212b53a01 (patch)
treeb5889420bf5988a47f3595765356d312f835b191 /drivers/video
parent0a3f30d5718d0d8930a07d282455f36d2ffc2865 (diff)
video: tegra: nvmap: protect usecount variable from race conditions
make usecount variable atomic to avoid race conditions in nvmap_usecount_dec(). optimize away usecount variable when carveout compaction is disabled. Bug 1215506 Bug 1245282 Change-Id: I570bcc258e578ace2b1e8151c027fcd4cf559bda Signed-off-by: Krishna Reddy <vdumpa@nvidia.com> Reviewed-on: http://git-master/r/191753 (cherry picked from commit 5e4a61657d75b0364e5ec7d584856f808df96a7f) Reviewed-on: http://git-master/r/195796 (cherry picked from commit 4981c18988f8155f3fb0283a14851390ada51d0f) Reviewed-on: http://git-master/r/205676 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Kirill Artamonov <kartamonov@nvidia.com>
Diffstat (limited to 'drivers/video')
-rw-r--r--drivers/video/tegra/nvmap/nvmap.h6
-rw-r--r--drivers/video/tegra/nvmap/nvmap_dev.c8
-rw-r--r--drivers/video/tegra/nvmap/nvmap_heap.c17
3 files changed, 18 insertions, 13 deletions
diff --git a/drivers/video/tegra/nvmap/nvmap.h b/drivers/video/tegra/nvmap/nvmap.h
index abed7ccaae5d..05b7de695233 100644
--- a/drivers/video/tegra/nvmap/nvmap.h
+++ b/drivers/video/tegra/nvmap/nvmap.h
@@ -84,7 +84,11 @@ struct nvmap_handle {
struct rb_node node; /* entry on global handle tree */
atomic_t ref; /* reference count (i.e., # of duplications) */
atomic_t pin; /* pin count */
- unsigned int usecount; /* how often is used */
+#ifdef CONFIG_NVMAP_CARVEOUT_COMPACTOR
+ atomic_t usecount; /* holds map count on carveout handle and is
+ used to avoid relocation during
+ carveout compaction */
+#endif
unsigned long flags;
size_t size; /* padded (as-allocated) size */
size_t orig_size; /* original (as-requested) size */
diff --git a/drivers/video/tegra/nvmap/nvmap_dev.c b/drivers/video/tegra/nvmap/nvmap_dev.c
index 2545cb4ed346..9b289ca8a5aa 100644
--- a/drivers/video/tegra/nvmap/nvmap_dev.c
+++ b/drivers/video/tegra/nvmap/nvmap_dev.c
@@ -926,8 +926,7 @@ static void nvmap_vma_open(struct vm_area_struct *vma)
BUG_ON(!priv);
atomic_inc(&priv->count);
- if(priv->handle)
- nvmap_usecount_inc(priv->handle);
+ nvmap_usecount_inc(priv->handle);
}
static void nvmap_vma_close(struct vm_area_struct *vma)
@@ -935,10 +934,7 @@ static void nvmap_vma_close(struct vm_area_struct *vma)
struct nvmap_vma_priv *priv = vma->vm_private_data;
if (priv) {
- if (priv->handle) {
- BUG_ON(priv->handle->usecount == 0);
- nvmap_usecount_dec(priv->handle);
- }
+ nvmap_usecount_dec(priv->handle);
if (!atomic_dec_return(&priv->count)) {
if (priv->handle)
nvmap_handle_put(priv->handle);
diff --git a/drivers/video/tegra/nvmap/nvmap_heap.c b/drivers/video/tegra/nvmap/nvmap_heap.c
index a334f8e01800..3812eb5b72f6 100644
--- a/drivers/video/tegra/nvmap/nvmap_heap.c
+++ b/drivers/video/tegra/nvmap/nvmap_heap.c
@@ -721,7 +721,7 @@ static struct nvmap_heap_block *do_heap_relocate_listblock(
if (atomic_read(&handle->pin))
goto fail;
/* abort if block is mapped */
- if (handle->usecount)
+ if (atomic_read(&handle->usecount))
goto fail;
if (fast) {
@@ -842,19 +842,24 @@ static void nvmap_heap_compact(struct nvmap_heap *heap,
void nvmap_usecount_inc(struct nvmap_handle *h)
{
- if (h->alloc && !h->heap_pgalloc) {
+#ifdef CONFIG_NVMAP_CARVEOUT_COMPACTOR
+ if (h && !h->heap_pgalloc) {
mutex_lock(&h->lock);
- h->usecount++;
+ atomic_inc(&h->usecount);
mutex_unlock(&h->lock);
- } else {
- h->usecount++;
}
+#endif
}
void nvmap_usecount_dec(struct nvmap_handle *h)
{
- h->usecount--;
+#ifdef CONFIG_NVMAP_CARVEOUT_COMPACTOR
+ if (h && !h->heap_pgalloc) {
+ BUG_ON(atomic_read(&h->usecount) == 0);
+ atomic_dec(&h->usecount);
+ }
+#endif
}
/* nvmap_heap_alloc: allocates a block of memory of len bytes, aligned to