From ded9241b1daa351c5e350a26df0eb1ce1bd7357c Mon Sep 17 00:00:00 2001 From: Sagar Kamble Date: Wed, 5 Feb 2020 16:23:40 +0530 Subject: [PATCH] gpu: nvgpu: detach previous attachment on re-mapping If the dmabuf attachment is not stored in the dmabuf priv data, on re-mapping the buffer, new attachment is prepared and the same is detached on finding existing mapping. Prior attachment is not detached in nvgpu_vm_find_mapping. However mapped_buffer stores the recent attachment that is detached. Hence on last unmap it will result in NULL access. Hence, detach the attachment stored in mapped_buffer in nvgpu_vm_find_mapping. Bug 2834141 Change-Id: I0c3c0b1c684b4984dba4f39edb8610b94961291e Signed-off-by: Sagar Kamble Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2290313 Tested-by: Debarshi Dutta Tested-by: mobile promotions Reviewed-by: Debarshi Dutta Reviewed-by: Lakshmanan M Reviewed-by: Vaibhav Kachore Reviewed-by: mobile promotions --- drivers/gpu/nvgpu/os/linux/vm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/nvgpu/os/linux/vm.c b/drivers/gpu/nvgpu/os/linux/vm.c index e5c469282..50ee59c89 100644 --- a/drivers/gpu/nvgpu/os/linux/vm.c +++ b/drivers/gpu/nvgpu/os/linux/vm.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -155,7 +155,8 @@ struct nvgpu_mapped_buf *nvgpu_vm_find_mapping(struct vm_gk20a *vm, * If we find the mapping here then that means we have mapped it already * and the prior pin and get must be undone. */ - gk20a_mm_unpin(os_buf->dev, os_buf->dmabuf, os_buf->attachment, + gk20a_mm_unpin(os_buf->dev, os_buf->dmabuf, + mapped_buffer->os_priv.attachment, mapped_buffer->os_priv.sgt); dma_buf_put(os_buf->dmabuf);