Skip to contentSkip to conversation

drm/radeon/kms: forbid big bo allocation (fdo 31708) v3

PATCH In review [email protected] 4 participants 5 messages Dec 3, 2010 – Dec 9, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/radeon/kms: forbid big bo allocation (fdo 31708) v3

From: Jerome Glisse <[email protected]>

Forbid allocating buffer bigger than visible VRAM or GTT, also properly set lpfn field.

v2 - use max macro
- silence warning
v3 - don't explicitly set range limit
- use min macro

Cc stable <[email protected]>
---
 drivers/gpu/drm/radeon/radeon_object.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_object.c +11 -2
index 1d06774..a598d00 100644
@@ -69,7 +69,7 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
 	u32 c = 0;
 
 	rbo->placement.fpfn = 0;
-	rbo->placement.lpfn = rbo->rdev->mc.active_vram_size >> PAGE_SHIFT;
+	rbo->placement.lpfn = 0;
 	rbo->placement.placement = rbo->placements;
 	rbo->placement.busy_placement = rbo->placements;
 	if (domain & RADEON_GEM_DOMAIN_VRAM)
@@ -91,7 +91,8 @@ int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj,
 {
 	struct radeon_bo *bo;
 	enum ttm_bo_type type;
-	int page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT;
+	unsigned long page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT;
+	unsigned long max_size = 0;
 	int r;
 
 	if (unlikely(rdev->mman.bdev.dev_mapping == NULL)) {
@@ -104,6 +105,14 @@ int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj,
 	}
 	*bo_ptr = NULL;
 
+	/* maximun bo size is the minimun btw visible vram and gtt size */
+	max_size = min(rdev->mc.visible_vram_size, rdev->mc.gtt_size);
+	if ((page_align << PAGE_SHIFT) >= max_size) {
+		printk(KERN_WARNING "%s:%d alloc size %ldM bigger than %ldMb limit\n",
+			__func__, __LINE__, page_align  >> (20 - PAGE_SHIFT), max_size >> 20);
+		return -ENOMEM;
+	}
+
 retry:
 	bo = kzalloc(sizeof(struct radeon_bo), GFP_KERNEL);
 	if (bo == NULL)
Signature · 1 line
1.7.3.2
#1 lore raw
Quoted 22 lines · On Fre, 2010-12-03 at 16:38 -0500, [email protected] wrote:

From: Jerome Glisse <[email protected]>

Forbid allocating buffer bigger than visible VRAM or GTT, also properly set lpfn field.

v2 - use max macro
- silence warning
v3 - don't explicitly set range limit
- use min macro

Cc stable <[email protected]>
---
 drivers/gpu/drm/radeon/radeon_object.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_object.c +0 -0
index 1d06774..a598d00 100644

drivers/gpu/drm/radeon/radeon_object.c int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj, · line 95

Quoted 6 lines
drivers/gpu/drm/radeon/radeon_object.c +2 -1
@@ -91,7 +91,8 @@ int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj,
 {
 	struct radeon_bo *bo;
 	enum ttm_bo_type type;
-	int page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT;
+	unsigned long page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT;
+	unsigned long max_size = 0;

The initialization of max_size is superfluous.

drivers/gpu/drm/radeon/radeon_object.c int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj, · line 114

Quoted 11 lines
drivers/gpu/drm/radeon/radeon_object.c +7 -0
@@ -104,6 +105,14 @@ int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj,
 	}
 	*bo_ptr = NULL;
 
+	/* maximun bo size is the minimun btw visible vram and gtt size */
+	max_size = min(rdev->mc.visible_vram_size, rdev->mc.gtt_size);
+	if ((page_align << PAGE_SHIFT) >= max_size) {
+		printk(KERN_WARNING "%s:%d alloc size %ldM bigger than %ldMb limit\n",
+			__func__, __LINE__, page_align  >> (20 - PAGE_SHIFT), max_size >> 20);
+		return -ENOMEM;
+	}

Still not sure this simple minimum is quite the right solution... e.g. if GTT is larger than visible VRAM, what's the problem with having a BO that fits in GTT but not in visible VRAM? On systems with 8 MB of VRAM, this will effectively limit the maximum texture size to 2048x1024.

(That's ignoring the fact that userspace can't use the full size of GTT or VRAM due to the BOs pinned to visible VRAM and the ring and indirect buffers at the start of GTT)

P.S. I think it's better not to submit patches to [email protected] while they're being reviewed. Once a patch lands in mainline, the Cc:
[email protected] tag in the commit message will cause it to be queued for the stable branch(es).

Signature · 11 lines
Earthling Michel Dänzer           |                http://www.vmware.com
Libre software enthusiast         |          Debian, X and DRI developer





_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer
#2 lore raw

2010/12/9 Michel Dänzer <[email protected]>:

Quoted 37 lines · On Fre, 2010-12-03 at 16:38 -0500, [email protected] wrote:
Quoted 22 lines

From: Jerome Glisse <[email protected]>

Forbid allocating buffer bigger than visible VRAM or GTT, also properly set lpfn field.

v2 - use max macro
   - silence warning
v3 - don't explicitly set range limit
   - use min macro

Cc stable <[email protected]>

---
 drivers/gpu/drm/radeon/radeon_object.c |   13 +++++++++++--

 1 files changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_object.c +0 -0
index 1d06774..a598d00 100644

drivers/gpu/drm/radeon/radeon_object.c int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj, · line 95

Quoted 6 lines
drivers/gpu/drm/radeon/radeon_object.c +2 -1
@@ -91,7 +91,8 @@ int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj,
  {
       struct radeon_bo *bo;
       enum ttm_bo_type type;
-     int page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT;
+     unsigned long page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT;
+     unsigned long max_size = 0;

The initialization of max_size is superfluous.

Quoted 4 lines
drivers/gpu/drm/radeon/radeon_object.c +0 -0
@@ -104,6 +105,14 @@ int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj,
       }
       *bo_ptr = NULL;
 
Quoted 12 lines

drivers/gpu/drm/radeon/radeon_object.c int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj, · line 114

Quoted 7 lines
drivers/gpu/drm/radeon/radeon_object.c +7 -0
+     /* maximun bo size is the minimun btw visible vram and gtt size */
+     max_size = min(rdev->mc.visible_vram_size, rdev->mc.gtt_size);
+     if ((page_align << PAGE_SHIFT) >= max_size) {
+             printk(KERN_WARNING "%s:%d alloc size %ldM bigger than %ldMb limit\n",
+                     __func__, __LINE__, page_align  >> (20 - PAGE_SHIFT), max_size >> 20);
+             return -ENOMEM;
+     }

Still not sure this simple minimum is quite the right solution... e.g. if GTT is larger than visible VRAM, what's the problem with having a BO that fits in GTT but not in visible VRAM? On systems with 8 MB of VRAM, this will effectively limit the maximum texture size to 2048x1024.

Just wondering if such a card exists, the only 8MB cards I know are pre-r100, I think a 16MB M6 is the lowest one I can find.

and yeah no cc'ing just leave it in the patch, though Itihnk git send email can do it automagically.

Dave.

#3 lore raw
Quoted 40 lines · Dave Airlie

2010/12/9 Michel Dänzer <[email protected]>:

Quoted 26 lines · On Fre, 2010-12-03 at 16:38 -0500, [email protected] wrote:
Quoted 25 lines

From: Jerome Glisse <[email protected]>

Forbid allocating buffer bigger than visible VRAM or GTT, also properly set lpfn field.

v2 - use max macro
- silence warning
v3 - don't explicitly set range limit
- use min macro

Cc stable <[email protected]>
---
 drivers/gpu/drm/radeon/radeon_object.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_object.c +0 -0
index 1d06774..a598d00 100644
@@ -104,6 +105,14 @@ int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj,
      }
      *bo_ptr = NULL;
 
Quoted 12 lines

drivers/gpu/drm/radeon/radeon_object.c int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj, · line 114

Quoted 7 lines
drivers/gpu/drm/radeon/radeon_object.c +7 -0
+     /* maximun bo size is the minimun btw visible vram and gtt size */
+     max_size = min(rdev->mc.visible_vram_size, rdev->mc.gtt_size);
+     if ((page_align << PAGE_SHIFT) >= max_size) {
+             printk(KERN_WARNING "%s:%d alloc size %ldM bigger than %ldMb limit\n",
+                     __func__, __LINE__, page_align  >> (20 - PAGE_SHIFT), max_size >> 20);
+             return -ENOMEM;
+     }

Still not sure this simple minimum is quite the right solution... e.g. if GTT is larger than visible VRAM, what's the problem with having a BO that fits in GTT but not in visible VRAM? On systems with 8 MB of VRAM, this will effectively limit the maximum texture size to 2048x1024.

Quoted 2 lines

Just wondering if such a card exists, the only 8MB cards I know are pre-r100, I think a 16MB M6 is the lowest one I can find.

From r100_vram_init_sizes():

                rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
                /* Some production boards of m6 will report 0
                 * if it's 8 MB
                 */
                if (rdev->mc.real_vram_size == 0) {
                        rdev->mc.real_vram_size = 8192 * 1024;
                        WREG32(RADEON_CONFIG_MEMSIZE, rdev->mc.real_vram_size);
                }
Signature · 6 lines
Earthling Michel Dänzer           |                http://www.vmware.com
Libre software enthusiast         |          Debian, X and DRI developer
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw
In reply to Dave Airlie

2010/12/9 Dave Airlie <[email protected]>:

Quoted 51 lines

2010/12/9 Michel Dänzer <[email protected]>:

Quoted 37 lines · On Fre, 2010-12-03 at 16:38 -0500, [email protected] wrote:
Quoted 22 lines

From: Jerome Glisse <[email protected]>

Forbid allocating buffer bigger than visible VRAM or GTT, also properly set lpfn field.

v2 - use max macro
   - silence warning
v3 - don't explicitly set range limit
   - use min macro

Cc stable <[email protected]>

---
 drivers/gpu/drm/radeon/radeon_object.c |   13 +++++++++++--

 1 files changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_object.c +0 -0
index 1d06774..a598d00 100644

drivers/gpu/drm/radeon/radeon_object.c int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj, · line 95

Quoted 6 lines
drivers/gpu/drm/radeon/radeon_object.c +2 -1
@@ -91,7 +91,8 @@ int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj,
  {
       struct radeon_bo *bo;
       enum ttm_bo_type type;
-     int page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT;
+     unsigned long page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT;
+     unsigned long max_size = 0;

The initialization of max_size is superfluous.

Quoted 4 lines
drivers/gpu/drm/radeon/radeon_object.c +0 -0
@@ -104,6 +105,14 @@ int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj,
       }
       *bo_ptr = NULL;
 
Quoted 12 lines

drivers/gpu/drm/radeon/radeon_object.c int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj, · line 114

Quoted 7 lines
drivers/gpu/drm/radeon/radeon_object.c +7 -0
+     /* maximun bo size is the minimun btw visible vram and gtt size */
+     max_size = min(rdev->mc.visible_vram_size, rdev->mc.gtt_size);
+     if ((page_align << PAGE_SHIFT) >= max_size) {
+             printk(KERN_WARNING "%s:%d alloc size %ldM bigger than %ldMb limit\n",
+                     __func__, __LINE__, page_align  >> (20 - PAGE_SHIFT), max_size >> 20);
+             return -ENOMEM;
+     }

Still not sure this simple minimum is quite the right solution... e.g. if GTT is larger than visible VRAM, what's the problem with having a BO that fits in GTT but not in visible VRAM? On systems with 8 MB of VRAM, this will effectively limit the maximum texture size to 2048x1024.

Quoted 3 lines

Just wondering if such a card exists, the only 8MB cards I know are pre-r100, I think a 16MB M6 is the lowest one I can find.

I have an 8 MB M6.

Alex

Quoted 9 lines

and yeah no cc'ing just leave it in the patch, though Itihnk git send email can do it automagically.

Dave.
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel