[Intel-gfx] [PATCH] Fix system lockup when a client tries to allocate a huge BO

Simon Farnsworth simon.farnsworth at onelan.com
Mon Jul 6 11:55:25 CEST 2009


Chris Wilson wrote:
> On Mon, 2009-07-06 at 10:10 +0100, Simon Farnsworth wrote:
>> Eric Anholt wrote:
>>> Anyway, we could just cap allocations at aperture size and avoid any
>>> trickiness.  There's no reason to allow a BO to be allocated that won't
>>> fit in the GPU, right?
>>>
>> Sounds very reasonable; how do I code that?
> 
> I think adding a defensive guard to bo_alloc of
>   if(size > bufmgr->gtt_size) return NULL;
> would be the first step -- which for now also ensures that size will be
> less than ULONG_MAX/2.

Something like:
>From f379163937f0f27a155a5f238ae41e37f9d110e3 Mon Sep 17 00:00:00 2001
From: Simon Farnsworth <simon.farnsworth at onelan.co.uk>
Date: Mon, 6 Jul 2009 10:53:09 +0100
Subject: [PATCH] Limit BO allocations to fit within the GTT

There's no point allowing you to allocate BOs that won't fit inside
the GTT - the GPU will be unable to operate on them.
---
 libdrm/intel/intel_bufmgr_gem.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/libdrm/intel/intel_bufmgr_gem.c
b/libdrm/intel/intel_bufmgr_gem.c
index 556bcf2..3cfc235 100644
--- a/libdrm/intel/intel_bufmgr_gem.c
+++ b/libdrm/intel/intel_bufmgr_gem.c
@@ -347,6 +347,10 @@ drm_intel_gem_bo_alloc_internal(drm_intel_bufmgr
*bufmgr, const char *name,
     int alloc_from_cache = 0;
     unsigned long bo_size;

+    /* Don't try and allocate BOs that can't be mapped by the GPU. */
+    if (size > bufmgr->gtt_size)
+       return NULL;
+
     /* Round the allocated size up to a power of two number of pages. */
     bo_size = 1 << logbase2(size);
     if (bo_size < page_size)


> However the fix I think Eric is alluding to is this:

I'm not seeing how this protects us against large allocations from
elsewhere (e.g. Mesa)?

>>From aae30a03aba0fbe33ca51f052aaa8d57ebcb9eaf Mon Sep 17 00:00:00 2001
> From: Chris Wilson <chris at chris-wilson.co.uk>
> Date: Thu, 2 Jul 2009 14:31:49 +0100
> Subject: [PATCH] Limit bo pixmap to hw constraints
> 
> ---
>  src/i830_uxa.c |   10 +++++++++-
>  1 files changed, 9 insertions(+), 1 deletions(-)
> 
> diff --git a/src/i830_uxa.c b/src/i830_uxa.c
> index eb35014..c472824 100644
> --- a/src/i830_uxa.c
> +++ b/src/i830_uxa.c
> @@ -592,7 +592,7 @@ i830_uxa_create_pixmap (ScreenPtr screen, int w, int h, int depth, unsigned usag
>      ScrnInfoPtr scrn = xf86Screens[screen->myNum];
>      I830Ptr i830 = I830PTR(scrn);
>      dri_bo *bo;
> -    int stride;
> +    int max_size, stride;
>      PixmapPtr pixmap;
>      
>      if (w > 32767 || h > 32767)
> @@ -601,6 +601,14 @@ i830_uxa_create_pixmap (ScreenPtr screen, int w, int h, int depth, unsigned usag
>      if (usage == CREATE_PIXMAP_USAGE_GLYPH_PICTURE)
>  	return fbCreatePixmap (screen, w, h, depth, usage);
>  
> +    if (IS_I965G(i830))
> +	max_size = 8192;
> +    else
> +	max_size = 2048;
> +
> +    if (w > max_size || h > max_size)
> +	return fbCreatePixmap (screen, w, h, depth, usage);
> +
>      pixmap = fbCreatePixmap (screen, 0, 0, depth, usage);
>  
>      if (w && h)


-- 
Simon Farnsworth




More information about the Intel-gfx mailing list