radeon/kms: fix dma relocation checking
Subsystems (2)
PATCH 1/2 radeon/kms: fix dma relocation checking
From: Jerome Glisse <[email protected]>
We were checking the index against the size of the relocation buffer instead of against the last index. This fix kernel segfault when userspace submit ill formated command stream/relocation buffer pair.
--- drivers/gpu/drm/radeon/r600_cs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/radeon/r600_cs.c +3 -3
@@ -2561,16 +2561,16 @@ int r600_dma_cs_next_reloc(struct radeon_cs_parser *p,struct radeon_cs_chunk *relocs_chunk;unsigned idx; + *cs_reloc =NULL ;if (p->chunk_relocs_idx ==-1 ) {DRM_ERROR ("No relocation chunk !\n" );return -EINVAL ; } - *cs_reloc =NULL ; relocs_chunk = &p->chunks[p->chunk_relocs_idx]; idx = p->dma_reloc_idx; -if (idx >= relocs_chunk->length_dw) { +if (idx >= p->nrelocs) {DRM_ERROR ("Relocs at %d after relocations chunk end %d !\n" , - idx, relocs_chunk->length_dw); + idx, p->nrelocs);return -EINVAL ; } *cs_reloc = p->relocs_ptr[idx];
Signature · 1 line
1.7.11.7
PATCH 2/2 radeon/kms: cleanup async dma packet checking
From: Jerome Glisse <[email protected]>
This simplify and cleanup the async dma checking.
--- drivers/gpu/drm/radeon/evergreen.c | 16 +- drivers/gpu/drm/radeon/evergreen_cs.c | 807 +++++++++++++++++----------------- drivers/gpu/drm/radeon/evergreend.h | 29 +- 3 files changed, 417 insertions(+), 435 deletions(-)
drivers/gpu/drm/radeon/evergreen.c +8 -8
@@ -3223,14 +3223,14 @@ void evergreen_dma_fence_ring_emit(struct radeon_device *rdev,struct radeon_ring *ring = &rdev->ring[fence->ring];u64 addr = rdev->fence_drv[fence->ring].gpu_addr;/* write the fence */ -radeon_ring_write (ring,DMA_PACKET (DMA_PACKET_FENCE ,0 ,0 ,0 )); +radeon_ring_write (ring,DMA_PACKET (DMA_PACKET_FENCE ,0 ,0 ));radeon_ring_write (ring, addr &0xfffffffc );radeon_ring_write (ring, (upper_32_bits (addr) &0xff ));radeon_ring_write (ring, fence->seq);/* generate an interrupt */ -radeon_ring_write (ring,DMA_PACKET (DMA_PACKET_TRAP ,0 ,0 ,0 )); +radeon_ring_write (ring,DMA_PACKET (DMA_PACKET_TRAP ,0 ,0 ));/* flush HDP */ -radeon_ring_write (ring,DMA_PACKET (DMA_PACKET_SRBM_WRITE ,0 ,0 ,0 )); +radeon_ring_write (ring,DMA_PACKET (DMA_PACKET_SRBM_WRITE ,0 ,0 ));radeon_ring_write (ring, (0xf <<16 ) |HDP_MEM_COHERENCY_FLUSH_CNTL );radeon_ring_write (ring,1 ); }
@@ -3253,7 +3253,7 @@ void evergreen_dma_ring_ib_execute(struct radeon_device *rdev,while ((next_rptr &7 ) !=5 ) next_rptr++; next_rptr +=3 ; -radeon_ring_write (ring,DMA_PACKET (DMA_PACKET_WRITE ,0 ,0 ,1 )); +radeon_ring_write (ring,DMA_PACKET (DMA_PACKET_WRITE ,0 ,1 ));radeon_ring_write (ring, ring->next_rptr_gpu_addr &0xfffffffc );radeon_ring_write (ring,upper_32_bits (ring->next_rptr_gpu_addr) &0xff );radeon_ring_write (ring, next_rptr);
@@ -3263,8 +3263,8 @@ void evergreen_dma_ring_ib_execute(struct radeon_device *rdev,* Pad as necessary with NOPs. */ while ((ring->wptr &7 ) !=5 ) -radeon_ring_write (ring,DMA_PACKET (DMA_PACKET_NOP ,0 ,0 ,0 )); -radeon_ring_write (ring,DMA_PACKET (DMA_PACKET_INDIRECT_BUFFER ,0 ,0 ,0 )); +radeon_ring_write (ring,DMA_PACKET (DMA_PACKET_NOP ,0 ,0 )); +radeon_ring_write (ring,DMA_PACKET (DMA_PACKET_INDIRECT_BUFFER ,0 ,0 ));radeon_ring_write (ring, (ib->gpu_addr &0xFFFFFFE0 ));radeon_ring_write (ring, (ib->length_dw <<12 ) | (upper_32_bits (ib->gpu_addr) &0xFF ));
@@ -3323,7 +3323,7 @@ int evergreen_copy_dma(struct radeon_device *rdev,if (cur_size_in_dw >0xFFFFF ) cur_size_in_dw =0xFFFFF ; size_in_dw -= cur_size_in_dw; -radeon_ring_write (ring,DMA_PACKET (DMA_PACKET_COPY ,0 ,0 , cur_size_in_dw)); +radeon_ring_write (ring,DMA_PACKET (DMA_PACKET_COPY ,0 , cur_size_in_dw));radeon_ring_write (ring, dst_offset &0xfffffffc );radeon_ring_write (ring, src_offset &0xfffffffc );radeon_ring_write (ring,upper_32_bits (dst_offset) &0xff );
@@ -3431,7 +3431,7 @@ static int evergreen_startup(struct radeon_device *rdev) ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX ]; r =radeon_ring_init (rdev, ring, ring->ring_size,R600_WB_DMA_RPTR_OFFSET ,DMA_RB_RPTR ,DMA_RB_WPTR , -2 ,0x3fffc ,DMA_PACKET (DMA_PACKET_NOP ,0 ,0 ,0 )); +2 ,0x3fffc ,DMA_PACKET (DMA_PACKET_NOP ,0 ,0 ));if (r)return r;
drivers/gpu/drm/radeon/evergreen_cs.c +393 -414
872 lines not on this page · raw message
drivers/gpu/drm/radeon/evergreend.h +16 -13
@@ -924,20 +924,23 @@#define CAYMAN_DMA1_CNTL 0xd82c/* async DMA packets */ -#define DMA_PACKET (cmd, t, s, n) ((((cmd) & 0xF) << 28) | \ - (((t) & 0x1) << 23) | \ - (((s) & 0x1) << 22) | \ - (((n) & 0xFFFFF) << 0)) +#define DMA_PACKET (cmd, sub_cmd, n) ((((cmd) & 0xF) << 28) | \ + (((sub_cmd) & 0xFF) << 20) |\ + (((n) & 0xFFFFF) << 0)) +#define GET_DMA_CMD (h) (((h) & 0xf0000000) >> 28) +#define GET_DMA_COUNT (h) ((h) & 0x000fffff) +#define GET_DMA_SUB_CMD (h) (((h) & 0x0ff00000) >> 20) +/* async DMA Packet types */ -#define DMA_PACKET_WRITE 0x2 -#define DMA_PACKET_COPY 0x3 -#define DMA_PACKET_INDIRECT_BUFFER 0x4 -#define DMA_PACKET_SEMAPHORE 0x5 -#define DMA_PACKET_FENCE 0x6 -#define DMA_PACKET_TRAP 0x7 -#define DMA_PACKET_SRBM_WRITE 0x9 -#define DMA_PACKET_CONSTANT_FILL 0xd -#define DMA_PACKET_NOP 0xf +#define DMA_PACKET_WRITE 0x2 +#define DMA_PACKET_COPY 0x3 +#define DMA_PACKET_INDIRECT_BUFFER 0x4 +#define DMA_PACKET_SEMAPHORE 0x5 +#define DMA_PACKET_FENCE 0x6 +#define DMA_PACKET_TRAP 0x7 +#define DMA_PACKET_SRBM_WRITE 0x9 +#define DMA_PACKET_CONSTANT_FILL 0xd +#define DMA_PACKET_NOP 0xf/* PCIE link stuff */ #define PCIE_LC_TRAINING_CNTL 0xa1/* PCIE_P */
Signature · 1 line
1.7.11.7
Quoted 7 lines · On Wed, Jan 9, 2013 at 4:40 PM, <[email protected]> wrote:
From: Jerome Glisse <[email protected]>
We were checking the index against the size of the relocation buffer instead of against the last index. This fix kernel segfault when userspace submit ill formated command stream/relocation buffer pair.
Signed-off-by Jerome Glisse <[email protected]>
Added to my -fixes queue. thanks!
Alex