mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 17:36:20 +03:00
gpu: nvgpu: specify DMA_TO_DEVICE direction to map_attachment for RO maps
nvgpu does map attachment with DMA_BIDIRECTIONAL direction for buffers irrespective of the GPU mapping type. nvmap will allow map attachment with only DMA_TO_DEVICE direction for RO buffers for secure buffer access. nvgpu does RO GPU mapping if the buffer is RO for CPU or user requests to map as RO. In both cases the dma_buf map attachment should be done with DMA_TO_DEVICE direction as the intent for accessing the SGT is reading from GPU. Also, map the gpfifo buffer as read_only as it is intended to be read only. The userd buffer is accessed by the GPU through iova and is not GMMU mapped. Bug 200731819 Change-Id: Ifc60973f298f7cacab16c5dedecbb40c5f33ed1d Signed-off-by: Sagar Kamble <skamble@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2539312 Tested-by: mobile promotions <svcmobile_promotions@nvidia.com> Reviewed-by: Deepak Nibade <dnibade@nvidia.com> Reviewed-by: Vijayakumar Subbu <vsubbu@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
committed by
mobile promotions
parent
7e1f9b8b19
commit
e099f8b1fd
@@ -1149,7 +1149,7 @@ __releases(&l->cde_app->mutex)
|
||||
nvgpu_log(g, gpu_dbg_cde, "surface=0x%p scatterBuffer=0x%p",
|
||||
surface, scatter_buffer);
|
||||
sgt = nvgpu_mm_pin(dev_from_gk20a(g), compbits_scatter_buf,
|
||||
&attachment);
|
||||
&attachment, DMA_BIDIRECTIONAL);
|
||||
if (IS_ERR(sgt)) {
|
||||
nvgpu_err(g,
|
||||
"mm_pin failed");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved.
|
||||
* Copyright (c) 2017-2021, 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,
|
||||
@@ -135,7 +135,8 @@ struct gk20a_dmabuf_priv *gk20a_dma_buf_get_drvdata(
|
||||
}
|
||||
|
||||
struct sg_table *nvgpu_mm_pin(struct device *dev,
|
||||
struct dma_buf *dmabuf, struct dma_buf_attachment **attachment)
|
||||
struct dma_buf *dmabuf, struct dma_buf_attachment **attachment,
|
||||
enum dma_data_direction direction)
|
||||
{
|
||||
struct gk20a *g = get_gk20a(dev);
|
||||
struct dma_buf_attachment *attach = NULL;
|
||||
@@ -148,7 +149,7 @@ struct sg_table *nvgpu_mm_pin(struct device *dev,
|
||||
return ERR_CAST(attach);
|
||||
}
|
||||
|
||||
sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
|
||||
sgt = dma_buf_map_attachment(attach, direction);
|
||||
if (IS_ERR(sgt)) {
|
||||
dma_buf_detach(dmabuf, attach);
|
||||
nvgpu_err(g, "Failed to map attachment (err = %ld)!",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved.
|
||||
* Copyright (c) 2017-2021, 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,
|
||||
@@ -99,7 +99,8 @@ struct gk20a_dmabuf_priv {
|
||||
|
||||
struct sg_table *nvgpu_mm_pin(struct device *dev,
|
||||
struct dma_buf *dmabuf,
|
||||
struct dma_buf_attachment **attachment);
|
||||
struct dma_buf_attachment **attachment,
|
||||
enum dma_data_direction direction);
|
||||
|
||||
void nvgpu_mm_unpin(struct device *dev,
|
||||
struct dma_buf *dmabuf,
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/dma-buf.h>
|
||||
#include <linux/dma-direction.h>
|
||||
|
||||
#include <nvgpu/trace.h>
|
||||
#include <uapi/linux/nvgpu.h>
|
||||
|
||||
@@ -439,7 +441,7 @@ int nvgpu_usermode_buf_from_dmabuf(struct gk20a *g, int dmabuf_fd,
|
||||
goto put_dmabuf;
|
||||
}
|
||||
|
||||
sgt = nvgpu_mm_pin(dev, dmabuf, &attachment);
|
||||
sgt = nvgpu_mm_pin(dev, dmabuf, &attachment, DMA_TO_DEVICE);
|
||||
if (IS_ERR(sgt)) {
|
||||
nvgpu_err(g, "Failed to pin dma_buf!");
|
||||
err = PTR_ERR(sgt);
|
||||
@@ -528,7 +530,7 @@ static int nvgpu_channel_alloc_usermode_buffers(struct nvgpu_channel *c,
|
||||
}
|
||||
|
||||
c->usermode_gpfifo.gpu_va = nvgpu_gmmu_map(c->vm, &c->usermode_gpfifo,
|
||||
c->usermode_gpfifo.size, 0, gk20a_mem_flag_none,
|
||||
c->usermode_gpfifo.size, 0, gk20a_mem_flag_read_only,
|
||||
false, c->usermode_gpfifo.aperture);
|
||||
|
||||
if (c->usermode_gpfifo.gpu_va == 0) {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
#include <linux/dma-buf.h>
|
||||
#include <linux/dma-direction.h>
|
||||
#include <linux/scatterlist.h>
|
||||
#include <uapi/linux/nvgpu.h>
|
||||
|
||||
@@ -265,7 +266,10 @@ int nvgpu_vm_map_linux(struct vm_gk20a *vm,
|
||||
return err;
|
||||
}
|
||||
|
||||
sgt = nvgpu_mm_pin(dev, dmabuf, &attachment);
|
||||
sgt = nvgpu_mm_pin(dev, dmabuf, &attachment,
|
||||
(buffer_rw_mode == gk20a_mem_flag_read_only) ||
|
||||
(map_access_requested == NVGPU_VM_MAP_ACCESS_READ_ONLY) ?
|
||||
DMA_TO_DEVICE : DMA_BIDIRECTIONAL);
|
||||
if (IS_ERR(sgt)) {
|
||||
nvgpu_warn(g, "Failed to pin dma_buf!");
|
||||
return PTR_ERR(sgt);
|
||||
|
||||
Reference in New Issue
Block a user