video: tegra: nvmap: Fix iovm_commit accounting issue.
vdumpa [Thu, 9 Jun 2011 00:42:19 +0000 (17:42 -0700)]
Bug 835748

Original-Change-Id: I67766cc94496162816cbef4689fa806553d6edfa
Reviewed-on: http://git-master/r/35792
Reviewed-by: Yu-Huan Hsu <yhsu@nvidia.com>
Reviewed-by: Krishna Reddy <vdumpa@nvidia.com>
Tested-by: Krishna Reddy <vdumpa@nvidia.com>

Rebase-Id: Ree8a45408d5763ec8db2cc4072add4c347326f99

drivers/video/tegra/nvmap/nvmap_handle.c

index 0c77e8a..21f50b1 100644 (file)
@@ -266,13 +266,15 @@ static void alloc_handle(struct nvmap_client *client,
 
        } else if (type & __NVMAP_HEAP_IOVMM) {
                size_t reserved = PAGE_ALIGN(h->size);
-               int commit;
+               int commit = 0;
                int ret;
 
                /* increment the committed IOVM space prior to allocation
                 * to avoid race conditions with other threads simultaneously
                 * allocating. */
-               commit = atomic_add_return(reserved, &client->iovm_commit);
+               if (!client->super)
+                       commit = atomic_add_return(reserved,
+                                                  &client->iovm_commit);
 
                if (commit < client->iovm_limit)
                        ret = handle_page_alloc(client, h, false);
@@ -283,7 +285,8 @@ static void alloc_handle(struct nvmap_client *client,
                        h->heap_pgalloc = true;
                        h->alloc = true;
                } else {
-                       atomic_sub(reserved, &client->iovm_commit);
+                       if (!client->super)
+                               atomic_sub(reserved, &client->iovm_commit);
                }
 
        } else if (type & NVMAP_HEAP_SYSMEM) {
@@ -441,7 +444,7 @@ void nvmap_free_handle_id(struct nvmap_client *client, unsigned long id)
        pins = atomic_read(&ref->pin);
        rb_erase(&ref->node, &client->handle_refs);
 
-       if (h->alloc && h->heap_pgalloc && !h->pgalloc.contig)
+       if (h->alloc && h->heap_pgalloc && !h->pgalloc.contig && !client->super)
                atomic_sub(h->size, &client->iovm_commit);
 
        if (h->alloc && !h->heap_pgalloc) {