* [PATCH] drm/ttm: fix fence locking in ttm_buffer_object_transfer, 2nd try
@ 2013-01-14 10:03 Daniel Vetter
2013-01-14 10:09 ` Maarten Lankhorst
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Vetter @ 2013-01-14 10:03 UTC (permalink / raw)
To: DRI Development; +Cc: Daniel Vetter, Jerome Glisse
This fixes up
commit e8e89622ed361c46bf90ba4828e685a8b603f7e5
Author: Daniel Vetter <daniel.vetter@ffwll.ch>
Date: Tue Dec 18 22:25:11 2012 +0100
drm/ttm: fix fence locking in ttm_buffer_object_transfer
which leaves behind a might_sleep in atomic context, since the
fence_lock spinlock is held over a kmalloc(GFP_KERNEL) call. The fix
is to revert the above commit and only take the lock where we need it,
around the call to ->sync_obj_ref.
Reported-by: Dave Airlie <airlied@gmail.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
drivers/gpu/drm/ttm/ttm_bo_util.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index d73d6e3..d4bb792 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -441,7 +441,9 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
fbo->vm_node = NULL;
atomic_set(&fbo->cpu_writers, 0);
+ spin_unlock(&bdev->fence_lock);
fbo->sync_obj = driver->sync_obj_ref(bo->sync_obj);
+ spin_lock(&bdev->fence_lock);
kref_init(&fbo->list_kref);
kref_init(&fbo->kref);
fbo->destroy = &ttm_transfered_destroy;
@@ -654,13 +656,11 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
*/
set_bit(TTM_BO_PRIV_FLAG_MOVING, &bo->priv_flags);
-
- /* ttm_buffer_object_transfer accesses bo->sync_obj */
- ret = ttm_buffer_object_transfer(bo, &ghost_obj);
spin_unlock(&bdev->fence_lock);
if (tmp_obj)
driver->sync_obj_unref(&tmp_obj);
+ ret = ttm_buffer_object_transfer(bo, &ghost_obj);
if (ret)
return ret;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] drm/ttm: fix fence locking in ttm_buffer_object_transfer, 2nd try
2013-01-14 10:03 [PATCH] drm/ttm: fix fence locking in ttm_buffer_object_transfer, 2nd try Daniel Vetter
@ 2013-01-14 10:09 ` Maarten Lankhorst
2013-01-14 14:08 ` Daniel Vetter
0 siblings, 1 reply; 4+ messages in thread
From: Maarten Lankhorst @ 2013-01-14 10:09 UTC (permalink / raw)
To: Daniel Vetter; +Cc: Jerome Glisse, DRI Development
Op 14-01-13 11:03, Daniel Vetter schreef:
> This fixes up
>
> commit e8e89622ed361c46bf90ba4828e685a8b603f7e5
> Author: Daniel Vetter <daniel.vetter@ffwll.ch>
> Date: Tue Dec 18 22:25:11 2012 +0100
>
> drm/ttm: fix fence locking in ttm_buffer_object_transfer
>
> which leaves behind a might_sleep in atomic context, since the
> fence_lock spinlock is held over a kmalloc(GFP_KERNEL) call. The fix
> is to revert the above commit and only take the lock where we need it,
> around the call to ->sync_obj_ref.
>
> Reported-by: Dave Airlie <airlied@gmail.com>
> Cc: Jerome Glisse <jglisse@redhat.com>
> Cc: Maarten Lankhorst <maarten.lankhorst@canonical.com>
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
> drivers/gpu/drm/ttm/ttm_bo_util.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index d73d6e3..d4bb792 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -441,7 +441,9 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
> fbo->vm_node = NULL;
> atomic_set(&fbo->cpu_writers, 0);
>
> + spin_unlock(&bdev->fence_lock);
> fbo->sync_obj = driver->sync_obj_ref(bo->sync_obj);
> + spin_lock(&bdev->fence_lock);
> kref_init(&fbo->list_kref);
> kref_init(&fbo->kref);
> fbo->destroy = &ttm_transfered_destroy;
Methinks you messed up spin_lock and spin_unlock here.
> @@ -654,13 +656,11 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
> */
>
> set_bit(TTM_BO_PRIV_FLAG_MOVING, &bo->priv_flags);
> -
> - /* ttm_buffer_object_transfer accesses bo->sync_obj */
> - ret = ttm_buffer_object_transfer(bo, &ghost_obj);
> spin_unlock(&bdev->fence_lock);
> if (tmp_obj)
> driver->sync_obj_unref(&tmp_obj);
>
> + ret = ttm_buffer_object_transfer(bo, &ghost_obj);
> if (ret)
> return ret;
>
~Maarten
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] drm/ttm: fix fence locking in ttm_buffer_object_transfer, 2nd try
2013-01-14 10:09 ` Maarten Lankhorst
@ 2013-01-14 14:08 ` Daniel Vetter
2013-01-14 15:09 ` Maarten Lankhorst
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Vetter @ 2013-01-14 14:08 UTC (permalink / raw)
To: DRI Development; +Cc: Daniel Vetter, Jerome Glisse
This fixes up
commit e8e89622ed361c46bf90ba4828e685a8b603f7e5
Author: Daniel Vetter <daniel.vetter@ffwll.ch>
Date: Tue Dec 18 22:25:11 2012 +0100
drm/ttm: fix fence locking in ttm_buffer_object_transfer
which leaves behind a might_sleep in atomic context, since the
fence_lock spinlock is held over a kmalloc(GFP_KERNEL) call. The fix
is to revert the above commit and only take the lock where we need it,
around the call to ->sync_obj_ref.
v2: Fixup things noticed by Maarten Lankhorst:
- Brown paper bag locking bug.
- No need for kzalloc if we clear the entire thing on the next line.
- check for bo->sync_obj (totally unlikely race, but still someone
else could have snuck in) and clear fbo->sync_obj if it's cleared
already.
Reported-by: Dave Airlie <airlied@gmail.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
drivers/gpu/drm/ttm/ttm_bo_util.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index d73d6e3..544e407 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -422,7 +422,7 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
struct ttm_bo_device *bdev = bo->bdev;
struct ttm_bo_driver *driver = bdev->driver;
- fbo = kzalloc(sizeof(*fbo), GFP_KERNEL);
+ fbo = kmalloc(sizeof(*fbo), GFP_KERNEL);
if (!fbo)
return -ENOMEM;
@@ -441,7 +441,12 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
fbo->vm_node = NULL;
atomic_set(&fbo->cpu_writers, 0);
- fbo->sync_obj = driver->sync_obj_ref(bo->sync_obj);
+ spin_lock(&bdev->fence_lock);
+ if (bo->sync_obj)
+ fbo->sync_obj = driver->sync_obj_ref(bo->sync_obj);
+ else
+ fbo->sync_obj = NULL;
+ spin_unlock(&bdev->fence_lock);
kref_init(&fbo->list_kref);
kref_init(&fbo->kref);
fbo->destroy = &ttm_transfered_destroy;
@@ -654,13 +659,11 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
*/
set_bit(TTM_BO_PRIV_FLAG_MOVING, &bo->priv_flags);
-
- /* ttm_buffer_object_transfer accesses bo->sync_obj */
- ret = ttm_buffer_object_transfer(bo, &ghost_obj);
spin_unlock(&bdev->fence_lock);
if (tmp_obj)
driver->sync_obj_unref(&tmp_obj);
+ ret = ttm_buffer_object_transfer(bo, &ghost_obj);
if (ret)
return ret;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] drm/ttm: fix fence locking in ttm_buffer_object_transfer, 2nd try
2013-01-14 14:08 ` Daniel Vetter
@ 2013-01-14 15:09 ` Maarten Lankhorst
0 siblings, 0 replies; 4+ messages in thread
From: Maarten Lankhorst @ 2013-01-14 15:09 UTC (permalink / raw)
To: Daniel Vetter; +Cc: Jerome Glisse, DRI Development
Op 14-01-13 15:08, Daniel Vetter schreef:
> This fixes up
>
> commit e8e89622ed361c46bf90ba4828e685a8b603f7e5
> Author: Daniel Vetter <daniel.vetter@ffwll.ch>
> Date: Tue Dec 18 22:25:11 2012 +0100
>
> drm/ttm: fix fence locking in ttm_buffer_object_transfer
>
> which leaves behind a might_sleep in atomic context, since the
> fence_lock spinlock is held over a kmalloc(GFP_KERNEL) call. The fix
> is to revert the above commit and only take the lock where we need it,
> around the call to ->sync_obj_ref.
>
> v2: Fixup things noticed by Maarten Lankhorst:
> - Brown paper bag locking bug.
> - No need for kzalloc if we clear the entire thing on the next line.
> - check for bo->sync_obj (totally unlikely race, but still someone
> else could have snuck in) and clear fbo->sync_obj if it's cleared
> already.
>
> Reported-by: Dave Airlie <airlied@gmail.com>
> Cc: Jerome Glisse <jglisse@redhat.com>
> Cc: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
> drivers/gpu/drm/ttm/ttm_bo_util.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index d73d6e3..544e407 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -422,7 +422,7 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
> struct ttm_bo_device *bdev = bo->bdev;
> struct ttm_bo_driver *driver = bdev->driver;
>
> - fbo = kzalloc(sizeof(*fbo), GFP_KERNEL);
> + fbo = kmalloc(sizeof(*fbo), GFP_KERNEL);
> if (!fbo)
> return -ENOMEM;
>
> @@ -441,7 +441,12 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
> fbo->vm_node = NULL;
> atomic_set(&fbo->cpu_writers, 0);
>
> - fbo->sync_obj = driver->sync_obj_ref(bo->sync_obj);
> + spin_lock(&bdev->fence_lock);
> + if (bo->sync_obj)
> + fbo->sync_obj = driver->sync_obj_ref(bo->sync_obj);
> + else
> + fbo->sync_obj = NULL;
> + spin_unlock(&bdev->fence_lock);
> kref_init(&fbo->list_kref);
> kref_init(&fbo->kref);
> fbo->destroy = &ttm_transfered_destroy;
> @@ -654,13 +659,11 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
> */
>
> set_bit(TTM_BO_PRIV_FLAG_MOVING, &bo->priv_flags);
> -
> - /* ttm_buffer_object_transfer accesses bo->sync_obj */
> - ret = ttm_buffer_object_transfer(bo, &ghost_obj);
> spin_unlock(&bdev->fence_lock);
> if (tmp_obj)
> driver->sync_obj_unref(&tmp_obj);
>
> + ret = ttm_buffer_object_transfer(bo, &ghost_obj);
> if (ret)
> return ret;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-01-14 15:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-14 10:03 [PATCH] drm/ttm: fix fence locking in ttm_buffer_object_transfer, 2nd try Daniel Vetter
2013-01-14 10:09 ` Maarten Lankhorst
2013-01-14 14:08 ` Daniel Vetter
2013-01-14 15:09 ` Maarten Lankhorst
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.