fix for IB & fence association
Subsystems (2)
Attached is 2 patch which fix quite bad issue in radeon kms code for IB allocation and for fence association to ttm object. They should fix race. I am still in the process of testing them, i want to give the opportunity to others to test them too (Dave don't apply them yet :))
Cheers,
Jerome
Quoted 1 line
From
5a9d7c4a4fa16bfe3148f161989411b4fe2bed77Mon Sep 17 00:00:00 2001
From: Jerome Glisse <[email protected]>
Date: Mon, 15 Feb 2010 14:06:11 +0100
Subject: [PATCH 1/2] drm/radeon/kms: fix indirect buffer management
There is 3 different distinct states for an indirect buffer (IB) :
1- free with no fence
2- free with a fence
3- non free (fence doesn't matter)
Previous code mixed case 2 & 3 in a single one leading to possible catastrophique failure. This patch rework the handling and properly separate each case. So when you get ib we set the ib as non free and fence status doesn't matter. Fence become active (ie has a meaning for the ib code) once the ib is scheduled or free. This patch also get rid of the alloc bitmap as it was overkill, we know go through IB pool list like in a ring buffer as the oldest IB is the first one the will be free.
Fix :
https://bugs.freedesktop.org/show_bug.cgi?id=26438
and likely other bugs.
--- drivers/gpu/drm/radeon/radeon.h | 6 ++- drivers/gpu/drm/radeon/radeon_ring.c | 97 +++++++++++++-------------------- 2 files changed, 42 insertions(+), 61 deletions(-)
drivers/gpu/drm/radeon/radeon.h +4 -2
@@ -97,6 +97,7 @@ extern int radeon_audio;* symbol; */ #define RADEON_MAX_USEC_TIMEOUT 100000/* 100 ms */ +/* RADEON_IB_POOL_SIZE must be a power of 2 */ #define RADEON_IB_POOL_SIZE 16#define RADEON_DEBUGFS_MAX_NUM_FILES 32#define RADEONFB_CONN_LIMIT 4
@@ -374,8 +375,9 @@ struct radeon_ib {unsigned long idx;uint64_t gpu_addr;struct radeon_fence *fence; -uint32_t *ptr; +uint32_t *ptr;uint32_t length_dw; +bool free; };/*
@@ -389,7 +391,7 @@ struct radeon_ib_pool {struct list_head bogus_ib;struct radeon_ib ibs[RADEON_IB_POOL_SIZE ];bool ready; -DECLARE_BITMAP (alloc_bm,RADEON_IB_POOL_SIZE ); +unsigned head_id; };struct radeon_cp {
drivers/gpu/drm/radeon/radeon_ring.c +38 -59
146 lines not on this page · raw message
Signature · 1 line
1.6.6
Quoted 1 line
From
afec0d2ff7ce6c8569201cc852ce914403b6979bMon Sep 17 00:00:00 2001
From: Jerome Glisse <[email protected]>
Date: Mon, 15 Feb 2010 14:14:50 +0100
Subject: [PATCH 2/2] drm/radeon/kms: fix bo's fence association
Previous code did associate fence to bo before the fence was emited and it also didn't lock protected access to ttm sync_obj member. Both of this flaw leads to possible race between different code path. This patch fix this by associating fence only once the fence is emitted and properly lock protect access to sync_obj member of ttm.
Fix:
https://bugs.freedesktop.org/show_bug.cgi?id=26438
and likely similar others bugs
--- drivers/gpu/drm/radeon/radeon_cs.c | 10 +++----- drivers/gpu/drm/radeon/radeon_object.c | 36 +++++++++++++------------------ drivers/gpu/drm/radeon/radeon_object.h | 4 +- 3 files changed, 21 insertions(+), 29 deletions(-)
drivers/gpu/drm/radeon/radeon_cs.c +4 -6
@@ -86,7 +86,7 @@ int radeon_cs_parser_relocs(struct radeon_cs_parser *p) &p->validated); } } -return radeon_bo_list_validate (&p->validated, p->ib->fence); +return radeon_bo_list_validate (&p->validated); }int radeon_cs_parser_init (struct radeon_cs_parser *p,void *data)
@@ -189,12 +189,10 @@ static void radeon_cs_parser_fini(struct radeon_cs_parser *parser, int error) {unsigned i; -if (error && parser->ib) { -radeon_bo_list_unvalidate (&parser->validated, - parser->ib->fence); - }else { -radeon_bo_list_unreserve (&parser->validated); +if (!error && parser->ib) { +radeon_bo_list_fence (&parser->validated, parser->ib->fence); } +radeon_bo_list_unreserve (&parser->validated);for (i =0 ; i < parser->nrelocs; i++) {if (parser->relocs[i].gobj) {mutex_lock (&parser->rdev->ddev->struct_mutex);
drivers/gpu/drm/radeon/radeon_object.c +15 -21
@@ -306,11 +306,10 @@ void radeon_bo_list_unreserve(struct list_head *head) } } -int radeon_bo_list_validate (struct list_head *head,void *fence) +int radeon_bo_list_validate (struct list_head *head) {struct radeon_bo_list *lobj;struct radeon_bo *bo; -struct radeon_fence *old_fence =NULL ;int r; r =radeon_bo_list_reserve (head);
@@ -334,32 +333,27 @@ int radeon_bo_list_validate(struct list_head *head, void *fence) } lobj->gpu_offset =radeon_bo_gpu_offset (bo); lobj->tiling_flags = bo->tiling_flags; -if (fence) { - old_fence = (struct radeon_fence *)bo->tbo.sync_obj; - bo->tbo.sync_obj =radeon_fence_ref (fence); - bo->tbo.sync_obj_arg =NULL ; - } -if (old_fence) { -radeon_fence_unref (&old_fence); - } }return 0 ; } -void radeon_bo_list_unvalidate (struct list_head *head,void *fence) +void radeon_bo_list_fence (struct list_head *head,void *fence) {struct radeon_bo_list *lobj; -struct radeon_fence *old_fence; - -if (fence) -list_for_each_entry (lobj, head, list) { - old_fence =to_radeon_fence (lobj->bo->tbo.sync_obj); -if (old_fence == fence) { - lobj->bo->tbo.sync_obj =NULL ; -radeon_fence_unref (&old_fence); - } +struct radeon_bo *bo; +struct radeon_fence *old_fence =NULL ; + +list_for_each_entry (lobj, head, list) { + bo = lobj->bo; +spin_lock (&bo->tbo.lock); + old_fence = (struct radeon_fence *)bo->tbo.sync_obj; + bo->tbo.sync_obj =radeon_fence_ref (fence); + bo->tbo.sync_obj_arg =NULL ; +spin_unlock (&bo->tbo.lock); +if (old_fence) { +radeon_fence_unref (&old_fence); } -radeon_bo_list_unreserve (head); + } } int radeon_bo_fbdev_mmap(struct radeon_bo *bo,
drivers/gpu/drm/radeon/radeon_object.h +2 -2
@@ -156,8 +156,8 @@ extern void radeon_bo_list_add_object(struct radeon_bo_list *lobj, struct list_head *head);extern int radeon_bo_list_reserve (struct list_head *head);extern void radeon_bo_list_unreserve (struct list_head *head); -extern int radeon_bo_list_validate (struct list_head *head,void *fence); -extern void radeon_bo_list_unvalidate (struct list_head *head,void *fence); +extern int radeon_bo_list_validate (struct list_head *head); +extern void radeon_bo_list_fence (struct list_head *head,void *fence);extern int radeon_bo_fbdev_mmap (struct radeon_bo *bo,struct vm_area_struct *vma); extern int radeon_bo_set_tiling_flags(struct radeon_bo *bo,
Signature · 1 line
1.6.6
------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel