From af95d14bb08850ed449eebae227faca800747108 Mon Sep 17 00:00:00 2001 From: Shih-hsin Li Date: Tue, 7 May 2019 16:34:01 -0700 Subject: gpu: nvgpu: fix synchronization in nvgpu_vm_map The mapping early returned from nvgpu_vm_map might already be unmapped during channel clean up. Increase refcount of an already mapped buffer inside the scope of update_gmmu_lock mutex to avoid this race. Bug 200494150 Change-Id: I66d9272e42c40cd3aae7ba3bb8106ec37691bf8e Signed-off-by: Shih-hsin Li Reviewed-on: https://git-master.nvidia.com/r/2114163 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Deepak Nibade Reviewed-by: Alex Waterman Reviewed-by: Vinayak Pane Reviewed-by: Daniel Fu Reviewed-by: svc-mobile-coverity GVS: Gerrit_Virtual_Submit Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/mm/vm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'drivers/gpu/nvgpu/common/mm/vm.c') diff --git a/drivers/gpu/nvgpu/common/mm/vm.c b/drivers/gpu/nvgpu/common/mm/vm.c index 7f0b3d10..4e221500 100644 --- a/drivers/gpu/nvgpu/common/mm/vm.c +++ b/drivers/gpu/nvgpu/common/mm/vm.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2019, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -873,12 +873,13 @@ struct nvgpu_mapped_buf *nvgpu_vm_map(struct vm_gk20a *vm, map_addr, flags, map_key_kind); - nvgpu_mutex_release(&vm->update_gmmu_lock); if (mapped_buffer) { nvgpu_ref_get(&mapped_buffer->ref); + nvgpu_mutex_release(&vm->update_gmmu_lock); return mapped_buffer; } + nvgpu_mutex_release(&vm->update_gmmu_lock); } /* -- cgit v1.2.2