From 758cb76e225775ba5ac3dd2cb9415cb40dc83810 Mon Sep 17 00:00:00 2001 From: Konsta Holtta Date: Tue, 11 Sep 2018 14:47:42 +0300 Subject: gpu: nvgpu: add FOREIGN_SGT mem flag Add an internal flag NVGPU_MEM_FLAG_FOREIGN_SGT to specify that the sgt member of an nvgpu_mem must not be freed when the nvgpu_mem is freed. Bug 200145225 Bug 200541476 Change-Id: I044fb91a5f9d148f38fb0cbf63d0cdfd64a070ce Signed-off-by: Konsta Holtta Reviewed-on: https://git-master.nvidia.com/r/1819801 Signed-off-by: Debarshi Dutta (cherry picked from commit 9de6d20abb8fef0cd11c22676846d809ee3f9afc in dev-main) Reviewed-on: https://git-master.nvidia.com/r/2170602 GVS: Gerrit_Virtual_Submit Reviewed-by: Bibek Basu Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h | 9 +++++++++ drivers/gpu/nvgpu/os/linux/linux-dma.c | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'drivers/gpu') diff --git a/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h b/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h index e69274b5..8e62a1d6 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h +++ b/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h @@ -174,6 +174,15 @@ struct nvgpu_mem { * nvgpu_mem in a system specific way. */ #define __NVGPU_MEM_FLAG_NO_DMA (1 << 3) + /* + * Some nvgpu_mem objects act as facades to memory buffers owned by + * someone else. This internal flag specifies that the sgt field is + * "borrowed", and it must not be freed by us. + * + * Of course the caller will have to make sure that the sgt owner + * outlives the nvgpu_mem. + */ +#define NVGPU_MEM_FLAG_FOREIGN_SGT (1 << 4) unsigned long mem_flags; /* diff --git a/drivers/gpu/nvgpu/os/linux/linux-dma.c b/drivers/gpu/nvgpu/os/linux/linux-dma.c index 52987a87..d704b2a4 100644 --- a/drivers/gpu/nvgpu/os/linux/linux-dma.c +++ b/drivers/gpu/nvgpu/os/linux/linux-dma.c @@ -392,8 +392,10 @@ void nvgpu_dma_free_sys(struct gk20a *g, struct nvgpu_mem *mem) if (mem->mem_flags & __NVGPU_MEM_FLAG_NO_DMA) nvgpu_kfree(g, mem->priv.pages); - if (mem->priv.sgt) + if ((mem->mem_flags & NVGPU_MEM_FLAG_FOREIGN_SGT) == 0 && + mem->priv.sgt != NULL) { nvgpu_free_sgtable(g, &mem->priv.sgt); + } dma_dbg_free_done(g, mem->size, "sysmem"); -- cgit v1.2.2