Commit eb1dba0e authored by Maarten Maathuis's avatar Maarten Maathuis Committed by Ben Skeggs

drm/nv50: align size of buffer object to the right boundaries.

- In the current situation the padding that is added is dangerous to write
  to, userspace could potentially overwrite parts of another bo.
- Depth and stencil buffers are supposed to be large enough in general so
  the waste of memory should be acceptable.
- Alternatives are hiding the padding from users or splitting vram into 2
  zones.
Signed-off-by: default avatarMaarten Maathuis <madman2003@gmail.com>
Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent 5025b431
...@@ -65,8 +65,10 @@ nouveau_bo_fixup_align(struct drm_device *dev, ...@@ -65,8 +65,10 @@ nouveau_bo_fixup_align(struct drm_device *dev,
/* /*
* Some of the tile_flags have a periodic structure of N*4096 bytes, * Some of the tile_flags have a periodic structure of N*4096 bytes,
* align to to that as well as the page size. Overallocate memory to * align to to that as well as the page size. Align the size to the
* avoid corruption of other buffer objects. * appropriate boundaries. This does imply that sizes are rounded up
* 3-7 pages, so be aware of this and do not waste memory by allocating
* many small buffers.
*/ */
if (dev_priv->card_type == NV_50) { if (dev_priv->card_type == NV_50) {
uint32_t block_size = nouveau_mem_fb_amount(dev) >> 15; uint32_t block_size = nouveau_mem_fb_amount(dev) >> 15;
...@@ -77,22 +79,20 @@ nouveau_bo_fixup_align(struct drm_device *dev, ...@@ -77,22 +79,20 @@ nouveau_bo_fixup_align(struct drm_device *dev,
case 0x2800: case 0x2800:
case 0x4800: case 0x4800:
case 0x7a00: case 0x7a00:
*size = roundup(*size, block_size);
if (is_power_of_2(block_size)) { if (is_power_of_2(block_size)) {
*size += 3 * block_size;
for (i = 1; i < 10; i++) { for (i = 1; i < 10; i++) {
*align = 12 * i * block_size; *align = 12 * i * block_size;
if (!(*align % 65536)) if (!(*align % 65536))
break; break;
} }
} else { } else {
*size += 6 * block_size;
for (i = 1; i < 10; i++) { for (i = 1; i < 10; i++) {
*align = 8 * i * block_size; *align = 8 * i * block_size;
if (!(*align % 65536)) if (!(*align % 65536))
break; break;
} }
} }
*size = roundup(*size, *align);
break; break;
default: default:
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment