radeon: command stream checker for r3xx-r5xx hardware
Subsystems (2)
PATCH 1/1 radeon: command stream checker for r3xx-r5xx hardware
This finish 3D state cs checking for r3xx-r5xx, you will need lastest DDX and mesa as some previously allowed register are now forbidden.
Jerome
Quoted 1 line
From
246cb55f8345bdf3ef071b587b311ab1088280ceMon Sep 17 00:00:00 2001
From: Jerome Glisse <[email protected]>
Date: Wed, 17 Jun 2009 13:28:30 +0200
Subject: [PATCH] radeon: command stream checker for r3xx-r5xx hardware
For security purpose we want to make sure the userspace process doesn't access memory beyond buffer it owns. To achieve this we need to check states the userspace program. For color buffer and zbuffer we check that the clipping register will discard access beyond buffers set as color or zbuffer. For vertex buffer we check that no vertex fetch will happen beyond buffer end. For texture we check various texture states (number of mipmap level, texture size, texture depth, ...) to compute the amount of memory the texture fetcher might access.
The command stream checking impact the performances so far quick benchmark shows an average of 3% decrease in fps of various applications. It can be optimized a bit more by caching result of checking and thus avoid a full recheck if no states changed since last check.
Note that this patch is still incomplete on checking side as it doesn't check 2d rendering states.
--- drivers/gpu/drm/radeon/r100.c | 76 +++-- drivers/gpu/drm/radeon/r300.c | 478 +++++++++++++++++++++++++++++-- drivers/gpu/drm/radeon/r300.h | 36 +++ drivers/gpu/drm/radeon/radeon.h | 9 +- drivers/gpu/drm/radeon/radeon_asic.h | 15 +- drivers/gpu/drm/radeon/radeon_device.c | 4 + drivers/gpu/drm/radeon/rv515.c | 58 ++++ 7 files changed, 611 insertions(+), 65 deletions(-) create mode 100644 drivers/gpu/drm/radeon/r300.h
drivers/gpu/drm/radeon/r100.c +45 -31
@@ -644,7 +644,7 @@ int r100_cp_reset(struct radeon_device *rdev)*/ int r100_cs_parse_packet0 (struct radeon_cs_parser *p,struct radeon_cs_packet *pkt, -unsigned *auth,unsigned n, +const unsigned *auth,unsigned n,radeon_packet0_check_t check) {unsigned reg;
@@ -654,6 +654,10 @@ int r100_cs_parse_packet0(struct radeon_cs_parser *p, idx = pkt->idx +1 ; reg = pkt->reg; +/* Check that register fall into register range +* determined by the number of entry (n) in the +* safe register bitmap. +*/ if (pkt->one_reg_wr) {if ((reg >>7 ) > n) {return -EINVAL ;
@@ -683,24 +687,6 @@ int r100_cs_parse_packet0(struct radeon_cs_parser *p,return 0 ; } -int r100_cs_parse_packet3 (struct radeon_cs_parser *p, -struct radeon_cs_packet *pkt, -unsigned *auth,unsigned n, -radeon_packet3_check_t check) -{ -unsigned i, m; - -if ((pkt->opcode >>5 ) > n) { -return -EINVAL ; - } - i = pkt->opcode >>5 ; - m =1 << (pkt->opcode &31 ); -if (auth[i] & m) { -return check (p, pkt); - } -return 0 ; -} -void r100_cs_dump_packet (struct radeon_cs_parser *p,struct radeon_cs_packet *pkt) {
@@ -901,6 +887,25 @@ static int r100_packet0_check(struct radeon_cs_parser *p,return 0 ; } +int r100_cs_track_check_pkt3_indx_buffer (struct radeon_cs_parser *p, +struct radeon_cs_packet *pkt, +struct radeon_object *robj) +{ +struct radeon_cs_chunk *ib_chunk; +unsigned idx; + + ib_chunk = &p->chunks[p->chunk_ib_idx]; + idx = pkt->idx +1 ; +if ((ib_chunk->kdata[idx+2 ] +1 ) >radeon_object_size (robj)) { +DRM_ERROR ("[drm] Buffer too small for PACKET3 INDX_BUFFER " +"(need %u have %lu) !\n" , + ib_chunk->kdata[idx+2 ] +1 , +radeon_object_size (robj)); +return -EINVAL ; + } +return 0 ; +} +static int r100_packet3_check (struct radeon_cs_parser *p,struct radeon_cs_packet *pkt) {
@@ -954,6 +959,10 @@ static int r100_packet3_check(struct radeon_cs_parser *p,return r; } ib[idx+1 ] = ib_chunk->kdata[idx+1 ] + ((u32 )reloc->lobj.gpu_offset); + r =r100_cs_track_check_pkt3_indx_buffer (p, pkt, reloc->robj); +if (r) { +return r; + }break ;case 0x23 :/* FIXME: cleanup */
@@ -999,18 +1008,18 @@ int r100_cs_parse(struct radeon_cs_parser *p) } p->idx += pkt.count +2 ;switch (pkt.type) { -case PACKET_TYPE0 : - r =r100_packet0_check (p, &pkt); -break ; -case PACKET_TYPE2 : -break ; -case PACKET_TYPE3 : - r =r100_packet3_check (p, &pkt); -break ; -default : -DRM_ERROR ("Unknown packet type %d !\n" , - pkt.type); -return -EINVAL ; +case PACKET_TYPE0 : + r =r100_packet0_check (p, &pkt); +break ; +case PACKET_TYPE2 : +break ; +case PACKET_TYPE3 : + r =r100_packet3_check (p, &pkt); +break ; +default : +DRM_ERROR ("Unknown packet type %d !\n" , + pkt.type); +return -EINVAL ; }if (r) {return r;
@@ -1352,6 +1361,11 @@ void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v) } } +int r100_init (struct radeon_device *rdev) +{ +return 0 ; +} +/* * Debugfs info */
drivers/gpu/drm/radeon/r300.c +447 -31
620 lines not on this page · raw message
drivers/gpu/drm/radeon/r300.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Copyright 2008 Advanced Micro Devices, Inc. +* Copyright 2008 Red Hat Inc. +* Copyright 2009 Jerome Glisse. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Authors: Dave Airlie +* Alex Deucher +* Jerome Glisse +*/ +#ifndef R300_H +#define R300_H + +struct r300_asic { +const unsigned *reg_safe_bm; +unsigned reg_safe_bm_size; +}; + +#endif
drivers/gpu/drm/radeon/radeon.h +8 -1
@@ -51,7 +51,7 @@#include "radeon_mode.h" #include "radeon_reg.h" - +#include "r300.h" /* * Modules parameters.
@@ -496,6 +496,7 @@ int r100_debugfs_cp_init(struct radeon_device *rdev);* ASIC specific functions. */ struct radeon_asic { +int (*init)(struct radeon_device *rdev);void (*errata)(struct radeon_device *rdev);void (*vram_info)(struct radeon_device *rdev);int (*gpu_reset)(struct radeon_device *rdev);
@@ -536,6 +537,10 @@ struct radeon_asic {void (*set_clock_gating)(struct radeon_device *rdev,int enable); }; +union radeon_asic_config { +struct r300_asic r300; +}; +/* * IOCTL.
@@ -573,6 +578,7 @@ struct radeon_device {struct drm_device *ddev;struct pci_dev *pdev;/* ASIC */ +union radeon_asic_config config;enum radeon_family family;unsigned long flags;int usec_timeout;
@@ -763,6 +769,7 @@ static inline void radeon_ring_write(struct radeon_device *rdev, uint32_t v)/* * ASICs macro. */ +#define radeon_init (rdev) (rdev)->asic->init((rdev))#define radeon_cs_parse (p) rdev->asic->cs_parse((p))#define radeon_errata (rdev) (rdev)->asic->errata((rdev))#define radeon_vram_info (rdev) (rdev)->asic->vram_info((rdev))
drivers/gpu/drm/radeon/radeon_asic.h +13 -2
@@ -41,6 +41,7 @@ void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);/* * r100,rv100,rs100,rv200,rs200,r200,rv250,rs300,rv280 */ +int r100_init (struct radeon_device *rdev);uint32_t r100_mm_rreg (struct radeon_device *rdev,uint32_t reg);void r100_mm_wreg (struct radeon_device *rdev,uint32_t reg,uint32_t v);void r100_errata (struct radeon_device *rdev);
@@ -72,6 +73,7 @@ int r100_copy_blit(struct radeon_device *rdev, struct radeon_fence *fence);static struct radeon_asic r100_asic = { + .init = &r100_init, .errata = &r100_errata, .vram_info = &r100_vram_info, .gpu_reset = &r100_gpu_reset,
@@ -104,6 +106,7 @@ static struct radeon_asic r100_asic = {/* * r300,r350,rv350,rv380 */ +int r300_init (struct radeon_device *rdev);void r300_errata (struct radeon_device *rdev);void r300_vram_info (struct radeon_device *rdev);int r300_gpu_reset (struct radeon_device *rdev);
@@ -126,6 +129,7 @@ int r300_copy_dma(struct radeon_device *rdev,unsigned num_pages, struct radeon_fence *fence);static struct radeon_asic r300_asic = { + .init = &r300_init, .errata = &r300_errata, .vram_info = &r300_vram_info, .gpu_reset = &r300_gpu_reset,
@@ -162,6 +166,7 @@ void r420_vram_info(struct radeon_device *rdev);int r420_mc_init (struct radeon_device *rdev);void r420_mc_fini (struct radeon_device *rdev);static struct radeon_asic r420_asic = { + .init = &r300_init, .errata = &r420_errata, .vram_info = &r420_vram_info, .gpu_reset = &r300_gpu_reset,
@@ -205,6 +210,7 @@ int rs400_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr);uint32_t rs400_mc_rreg (struct radeon_device *rdev,uint32_t reg);void rs400_mc_wreg (struct radeon_device *rdev,uint32_t reg,uint32_t v);static struct radeon_asic rs400_asic = { + .init = &r300_init, .errata = &rs400_errata, .vram_info = &rs400_vram_info, .gpu_reset = &r300_gpu_reset,
@@ -249,6 +255,7 @@ int rs600_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr);uint32_t rs600_mc_rreg (struct radeon_device *rdev,uint32_t reg);void rs600_mc_wreg (struct radeon_device *rdev,uint32_t reg,uint32_t v);static struct radeon_asic rs600_asic = { + .init = &r300_init, .errata = &rs600_errata, .vram_info = &rs600_vram_info, .gpu_reset = &r300_gpu_reset,
@@ -288,6 +295,7 @@ void rs690_mc_fini(struct radeon_device *rdev);uint32_t rs690_mc_rreg (struct radeon_device *rdev,uint32_t reg);void rs690_mc_wreg (struct radeon_device *rdev,uint32_t reg,uint32_t v);static struct radeon_asic rs690_asic = { + .init = &r300_init, .errata = &rs690_errata, .vram_info = &rs690_vram_info, .gpu_reset = &r300_gpu_reset,
@@ -320,6 +328,7 @@ static struct radeon_asic rs690_asic = {/* * rv515 */ +int rv515_init (struct radeon_device *rdev);void rv515_errata (struct radeon_device *rdev);void rv515_vram_info (struct radeon_device *rdev);int rv515_gpu_reset (struct radeon_device *rdev);
@@ -331,6 +340,7 @@ void rv515_ring_start(struct radeon_device *rdev);uint32_t rv515_pcie_rreg (struct radeon_device *rdev,uint32_t reg);void rv515_pcie_wreg (struct radeon_device *rdev,uint32_t reg,uint32_t v);static struct radeon_asic rv515_asic = { + .init = &rv515_init, .errata = &rv515_errata, .vram_info = &rv515_vram_info, .gpu_reset = &rv515_gpu_reset,
@@ -349,7 +359,7 @@ static struct radeon_asic rv515_asic = { .irq_set = &r100_irq_set, .irq_process = &r100_irq_process, .fence_ring_emit = &r300_fence_ring_emit, - .cs_parse = &r100_cs_parse, + .cs_parse = &r300_cs_parse, .copy_blit = &r100_copy_blit, .copy_dma = &r300_copy_dma, .copy = &r100_copy_blit,
@@ -368,6 +378,7 @@ void r520_vram_info(struct radeon_device *rdev);int r520_mc_init (struct radeon_device *rdev);void r520_mc_fini (struct radeon_device *rdev);static struct radeon_asic r520_asic = { + .init = &rv515_init, .errata = &r520_errata, .vram_info = &r520_vram_info, .gpu_reset = &rv515_gpu_reset,
@@ -386,7 +397,7 @@ static struct radeon_asic r520_asic = { .irq_set = &r100_irq_set, .irq_process = &r100_irq_process, .fence_ring_emit = &r300_fence_ring_emit, - .cs_parse = &r100_cs_parse, + .cs_parse = &r300_cs_parse, .copy_blit = &r100_copy_blit, .copy_dma = &r300_copy_dma, .copy = &r100_copy_blit,
drivers/gpu/drm/radeon/radeon_device.c +4 -0
@@ -470,6 +470,10 @@ int radeon_device_init(struct radeon_device *rdev,if (r) {return r; } + r =radeon_init (rdev); +if (r) { +return r; + }/* Report DMA addressing limitation */ r =pci_set_dma_mask (rdev->pdev,DMA_BIT_MASK (32 ));
drivers/gpu/drm/radeon/rv515.c +58 -0
67 lines not on this page · raw message
Signature · 1 line
1.6.2.2