From 61ef5a58744d22e65d3ad7c3a04a2521d0ccb6af Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Tue, 15 Aug 2017 11:16:07 -0700 Subject: gpu: nvgpu: Deterministic submit fix Fix some simple pointer arithmetic errors in the deterministic submit path. The lockless allocator was doing a subtraction to determine the correct offset of the element to free. However, this subtraction was using the base address and a numeric offset - not a pointer offset. Thus the difference computed was in bytes not in elements of the block size. The fix is simple: just divide by the block size. Also this modifies the debugging statement a bit so that a bit more information is printed at more useful times. Lastly, a pointer to numeric cast was fixed in the fence code. Change-Id: I514724205f1b73805b21e979481a13ac689f3482 Signed-off-by: Alex Waterman Reviewed-on: https://git-master.nvidia.com/r/1538905 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: svccoveritychecker Reviewed-by: Aingara Paramakuru Reviewed-by: svc-mobile-coverity Reviewed-by: Konsta Holtta GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/common/mm/lockless_allocator.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'drivers/gpu/nvgpu/common') diff --git a/drivers/gpu/nvgpu/common/mm/lockless_allocator.c b/drivers/gpu/nvgpu/common/mm/lockless_allocator.c index 944b4b0f..2a569efd 100644 --- a/drivers/gpu/nvgpu/common/mm/lockless_allocator.c +++ b/drivers/gpu/nvgpu/common/mm/lockless_allocator.c @@ -66,12 +66,16 @@ static u64 nvgpu_lockless_alloc(struct nvgpu_allocator *a, u64 len) if (ret == head) { addr = pa->base + head * pa->blk_size; atomic_inc(&pa->nr_allocs); - alloc_dbg(a, "Alloc node # %d @ addr 0x%llx\n", head, - addr); break; } head = ACCESS_ONCE(pa->head); } + + if (addr) + alloc_dbg(a, "Alloc node # %d @ addr 0x%llx\n", head, addr); + else + alloc_dbg(a, "Alloc failed!\n"); + return addr; } @@ -81,7 +85,9 @@ static void nvgpu_lockless_free(struct nvgpu_allocator *a, u64 addr) int head, ret; u64 cur_idx; - cur_idx = addr - pa->base; + cur_idx = (addr - pa->base) / pa->blk_size; + + alloc_dbg(a, "Free node # %llu @ addr 0x%llx\n", cur_idx, addr); while (1) { head = ACCESS_ONCE(pa->head); @@ -89,7 +95,6 @@ static void nvgpu_lockless_free(struct nvgpu_allocator *a, u64 addr) ret = cmpxchg(&pa->head, head, cur_idx); if (ret == head) { atomic_dec(&pa->nr_allocs); - alloc_dbg(a, "Free node # %llu\n", cur_idx); break; } } -- cgit v1.2.2