freedreno: make cmdstream bo's read-only to GPU
authorRob Clark <robdclark@gmail.com>
Wed, 9 Jan 2019 18:03:43 +0000 (13:03 -0500)
committerRob Clark <robdclark@gmail.com>
Thu, 10 Jan 2019 19:21:39 +0000 (14:21 -0500)
If nothing else, this will make problems with cmdstream getting blit
over with pixels easier to track down (ie. faults when it first happens
rather than strange failures later from corrupted cmdstream when a
stateobj is later reused).

(NOTE this somewhat depends on the kernel supporting the flag, and the
iommu implementation.  But the worst case is just that the cmdstream
ends up writeable as before.)

Signed-off-by: Rob Clark <robdclark@gmail.com>
src/freedreno/drm/msm_bo.c
src/freedreno/drm/msm_ringbuffer_sp.c

index fd9955ea8051f4c12d93bd523e6b30a5593f34dc..da2609903c12b762faeb396d2dbf50141fd45bd5 100644 (file)
@@ -166,6 +166,9 @@ int msm_bo_new_handle(struct fd_device *dev,
        if (flags & DRM_FREEDRENO_GEM_SCANOUT)
                req.flags |= MSM_BO_SCANOUT;
 
+       if (flags & DRM_FREEDRENO_GEM_GPUREADONLY)
+               req.flags |= MSM_BO_GPU_READONLY;
+
        ret = drmCommandWriteRead(dev->fd, DRM_MSM_GEM_NEW,
                        &req, sizeof(req));
        if (ret)
index 228740d783b2e4c89158cd3e0efdb227487600c5..2b8f531721e69801ede501123306e47ffa188a74 100644 (file)
@@ -186,8 +186,8 @@ msm_submit_suballoc_ring_bo(struct fd_submit *submit,
 
        if (!suballoc_bo) {
                // TODO possibly larger size for streaming bo?
-               msm_ring->ring_bo = fd_bo_new_ring(
-                               submit->pipe->dev, 0x8000, 0);
+               msm_ring->ring_bo = fd_bo_new_ring(submit->pipe->dev,
+                               0x8000, DRM_FREEDRENO_GEM_GPUREADONLY);
                msm_ring->offset = 0;
        } else {
                msm_ring->ring_bo = fd_bo_ref(suballoc_bo);
@@ -225,7 +225,8 @@ msm_submit_sp_new_ringbuffer(struct fd_submit *submit, uint32_t size,
                        size = INIT_SIZE;
 
                msm_ring->offset = 0;
-               msm_ring->ring_bo = fd_bo_new_ring(submit->pipe->dev, size, 0);
+               msm_ring->ring_bo = fd_bo_new_ring(submit->pipe->dev, size,
+                               DRM_FREEDRENO_GEM_GPUREADONLY);
        }
 
        if (!msm_ringbuffer_sp_init(msm_ring, size, flags))
@@ -375,7 +376,8 @@ msm_ringbuffer_sp_grow(struct fd_ringbuffer *ring, uint32_t size)
        finalize_current_cmd(ring);
 
        fd_bo_del(msm_ring->ring_bo);
-       msm_ring->ring_bo = fd_bo_new_ring(pipe->dev, size, 0);
+       msm_ring->ring_bo = fd_bo_new_ring(pipe->dev, size,
+                       DRM_FREEDRENO_GEM_GPUREADONLY);
 
        ring->start = fd_bo_map(msm_ring->ring_bo);
        ring->end = &(ring->start[size/4]);
@@ -558,7 +560,8 @@ msm_ringbuffer_sp_new_object(struct fd_pipe *pipe, uint32_t size)
 
        msm_ring->u.pipe = pipe;
        msm_ring->offset = 0;
-       msm_ring->ring_bo = fd_bo_new_ring(pipe->dev, size, 0);
+       msm_ring->ring_bo = fd_bo_new_ring(pipe->dev, size,
+                       DRM_FREEDRENO_GEM_GPUREADONLY);
        msm_ring->base.refcnt = 1;
 
        return msm_ringbuffer_sp_init(msm_ring, size, _FD_RINGBUFFER_OBJECT);