Skip to content

Commit d260987

Browse files
Jerome Glisseairlied
authored andcommitted
drm/radeon: fix tiling and command stream checking on evergreen v3
Fix regresson since the introduction of command stream checking on evergreen (thread referenced below). Issue is cause by ddx allocating bo with formula width*height*bpp while programming the GPU command stream with ALIGN(height, 8). In some case (where page alignment does not hide the extra size bo should be according to height alignment) the kernel will reject the command stream. This patch reprogram the command stream to slice - 1 (slice is a derivative value from height) which avoid rejecting the command stream while keeping the value of command stream checking from a security point of view. This patch also fix wrong computation of layer size for 2D tiled surface. Which should fix issue when 2D color tiling is enabled. This dump the radeon KMS_DRIVER_MINOR so userspace can know if they are on a fixed kernel or not. https://lkml.org/lkml/2012/6/3/80 https://bugs.freedesktop.org/show_bug.cgi?id=50892 https://bugs.freedesktop.org/show_bug.cgi?id=50857 !!! STABLE need a custom version of this patch for 3.4 !!! v2: actually bump the minor version and add comment about stable v3: do compute the height the ddx was trying to use [airlied: drop left over debug] Signed-off-by: Jerome Glisse <jglisse@redhat.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent cfaf025 commit d260987

2 files changed

Lines changed: 47 additions & 5 deletions

File tree

‎drivers/gpu/drm/radeon/evergreen_cs.c‎

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct evergreen_cs_track {
5252
u32 cb_color_view[12];
5353
u32 cb_color_pitch[12];
5454
u32 cb_color_slice[12];
55+
u32 cb_color_slice_idx[12];
5556
u32 cb_color_attrib[12];
5657
u32 cb_color_cmask_slice[8];/* unused */
5758
u32 cb_color_fmask_slice[8];/* unused */
@@ -127,12 +128,14 @@ static void evergreen_cs_track_init(struct evergreen_cs_track *track)
127128
track->cb_color_info[i] = 0;
128129
track->cb_color_view[i] = 0xFFFFFFFF;
129130
track->cb_color_pitch[i] = 0;
130-
track->cb_color_slice[i] = 0;
131+
track->cb_color_slice[i] = 0xfffffff;
132+
track->cb_color_slice_idx[i] = 0;
131133
}
132134
track->cb_target_mask = 0xFFFFFFFF;
133135
track->cb_shader_mask = 0xFFFFFFFF;
134136
track->cb_dirty = true;
135137

138+
track->db_depth_slice = 0xffffffff;
136139
track->db_depth_view = 0xFFFFC000;
137140
track->db_depth_size = 0xFFFFFFFF;
138141
track->db_depth_control = 0xFFFFFFFF;
@@ -250,10 +253,9 @@ static int evergreen_surface_check_2d(struct radeon_cs_parser *p,
250253
{
251254
struct evergreen_cs_track *track = p->track;
252255
unsigned palign, halign, tileb, slice_pt;
256+
unsigned mtile_pr, mtile_ps, mtileb;
253257

254258
tileb = 64 * surf->bpe * surf->nsamples;
255-
palign = track->group_size / (8 * surf->bpe * surf->nsamples);
256-
palign = MAX(8, palign);
257259
slice_pt = 1;
258260
if (tileb > surf->tsplit) {
259261
slice_pt = tileb / surf->tsplit;
@@ -262,7 +264,10 @@ static int evergreen_surface_check_2d(struct radeon_cs_parser *p,
262264
/* macro tile width & height */
263265
palign = (8 * surf->bankw * track->npipes) * surf->mtilea;
264266
halign = (8 * surf->bankh * surf->nbanks) / surf->mtilea;
265-
surf->layer_size = surf->nbx * surf->nby * surf->bpe * slice_pt;
267+
mtileb = (palign / 8) * (halign / 8) * tileb;;
268+
mtile_pr = surf->nbx / palign;
269+
mtile_ps = (mtile_pr * surf->nby) / halign;
270+
surf->layer_size = mtile_ps * mtileb * slice_pt;
266271
surf->base_align = (palign / 8) * (halign / 8) * tileb;
267272
surf->palign = palign;
268273
surf->halign = halign;
@@ -434,6 +439,39 @@ static int evergreen_cs_track_validate_cb(struct radeon_cs_parser *p, unsigned i
434439

435440
offset += surf.layer_size * mslice;
436441
if (offset > radeon_bo_size(track->cb_color_bo[id])) {
442+
/* old ddx are broken they allocate bo with w*h*bpp but
443+
* program slice with ALIGN(h, 8), catch this and patch
444+
* command stream.
445+
*/
446+
if (!surf.mode) {
447+
volatile u32 *ib = p->ib.ptr;
448+
unsigned long tmp, nby, bsize, size, min = 0;
449+
450+
/* find the height the ddx wants */
451+
if (surf.nby > 8) {
452+
min = surf.nby - 8;
453+
}
454+
bsize = radeon_bo_size(track->cb_color_bo[id]);
455+
tmp = track->cb_color_bo_offset[id] << 8;
456+
for (nby = surf.nby; nby > min; nby--) {
457+
size = nby * surf.nbx * surf.bpe * surf.nsamples;
458+
if ((tmp + size * mslice) <= bsize) {
459+
break;
460+
}
461+
}
462+
if (nby > min) {
463+
surf.nby = nby;
464+
slice = ((nby * surf.nbx) / 64) - 1;
465+
if (!evergreen_surface_check(p, &surf, "cb")) {
466+
/* check if this one works */
467+
tmp += surf.layer_size * mslice;
468+
if (tmp <= bsize) {
469+
ib[track->cb_color_slice_idx[id]] = slice;
470+
goto old_ddx_ok;
471+
}
472+
}
473+
}
474+
}
437475
dev_warn(p->dev, "%s:%d cb[%d] bo too small (layer size %d, "
438476
"offset %d, max layer %d, bo size %ld, slice %d)\n",
439477
__func__, __LINE__, id, surf.layer_size,
@@ -446,6 +484,7 @@ static int evergreen_cs_track_validate_cb(struct radeon_cs_parser *p, unsigned i
446484
surf.tsplit, surf.mtilea);
447485
return -EINVAL;
448486
}
487+
old_ddx_ok:
449488

450489
return 0;
451490
}
@@ -1532,6 +1571,7 @@ static int evergreen_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
15321571
case CB_COLOR7_SLICE:
15331572
tmp = (reg - CB_COLOR0_SLICE) / 0x3c;
15341573
track->cb_color_slice[tmp] = radeon_get_ib_value(p, idx);
1574+
track->cb_color_slice_idx[tmp] = idx;
15351575
track->cb_dirty = true;
15361576
break;
15371577
case CB_COLOR8_SLICE:
@@ -1540,6 +1580,7 @@ static int evergreen_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
15401580
case CB_COLOR11_SLICE:
15411581
tmp = ((reg - CB_COLOR8_SLICE) / 0x1c) + 8;
15421582
track->cb_color_slice[tmp] = radeon_get_ib_value(p, idx);
1583+
track->cb_color_slice_idx[tmp] = idx;
15431584
track->cb_dirty = true;
15441585
break;
15451586
case CB_COLOR0_ATTRIB:

‎drivers/gpu/drm/radeon/radeon_drv.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@
5757
* 2.13.0 - virtual memory support, streamout
5858
* 2.14.0 - add evergreen tiling informations
5959
* 2.15.0 - add max_pipes query
60+
* 2.16.0 - fix evergreen 2D tiled surface calculation
6061
*/
6162
#define KMS_DRIVER_MAJOR 2
62-
#define KMS_DRIVER_MINOR 15
63+
#define KMS_DRIVER_MINOR 16
6364
#define KMS_DRIVER_PATCHLEVEL 0
6465
int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags);
6566
int radeon_driver_unload_kms(struct drm_device *dev);

0 commit comments

Comments
 (0)