Skip to contentSkip to conversation

drm: vc4: Fix race during binding

PATCH In review Stefan Wahren 2 participants 5 messages Oct 6, 2017 – Oct 8, 2017

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

PATCH 1/1 drm: vc4: Fix race during binding

This fixes the race between vc4_overflow_mem_work and the init of the job lock. Otherwise we could trigger a NULL pointer dereference during VC4 binding.

Fixes d5b1a78a772f ("drm/vc4: Add support for drawing 3D frames.")
---
 drivers/gpu/drm/vc4/vc4_gem.c | 1 -
 drivers/gpu/drm/vc4/vc4_irq.c | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_gem.c +0 -1
index d0c6bfb..47d964f 100644
@@ -1088,7 +1088,6 @@ vc4_gem_init(struct drm_device *dev)
 	INIT_LIST_HEAD(&vc4->render_job_list);
 	INIT_LIST_HEAD(&vc4->job_done_list);
 	INIT_LIST_HEAD(&vc4->seqno_cb_list);
-	spin_lock_init(&vc4->job_lock);
 
 	INIT_WORK(&vc4->hangcheck.reset_work, vc4_reset_work);
 	setup_timer(&vc4->hangcheck.timer,
drivers/gpu/drm/vc4/vc4_irq.c +1 -0
index 7d7af3a..d508d13 100644
@@ -195,6 +195,7 @@ vc4_irq_preinstall(struct drm_device *dev)
 	struct vc4_dev *vc4 = to_vc4_dev(dev);
 
 	init_waitqueue_head(&vc4->job_wait_queue);
+	spin_lock_init(&vc4->job_lock);
 	INIT_WORK(&vc4->overflow_mem_work, vc4_overflow_mem_work);
 
 	/* Clear any pending interrupts someone might have left around
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 29 lines · Stefan Wahren

This fixes the race between vc4_overflow_mem_work and the init of the job lock. Otherwise we could trigger a NULL pointer dereference during VC4 binding.

Fixes d5b1a78a772f ("drm/vc4: Add support for drawing 3D frames.")
---
 drivers/gpu/drm/vc4/vc4_gem.c | 1 -
 drivers/gpu/drm/vc4/vc4_irq.c | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_gem.c +0 -1
index d0c6bfb..47d964f 100644
@@ -1088,7 +1088,6 @@ vc4_gem_init(struct drm_device *dev)
 	INIT_LIST_HEAD(&vc4->render_job_list);
 	INIT_LIST_HEAD(&vc4->job_done_list);
 	INIT_LIST_HEAD(&vc4->seqno_cb_list);
-	spin_lock_init(&vc4->job_lock);
 
 	INIT_WORK(&vc4->hangcheck.reset_work, vc4_reset_work);
 	setup_timer(&vc4->hangcheck.timer,
drivers/gpu/drm/vc4/vc4_irq.c +0 -0
index 7d7af3a..d508d13 100644

drivers/gpu/drm/vc4/vc4_irq.c vc4_irq_preinstall(struct drm_device *dev) · line 201

Quoted 7 lines
drivers/gpu/drm/vc4/vc4_irq.c +1 -0
@@ -195,6 +195,7 @@ vc4_irq_preinstall(struct drm_device *dev)
 	struct vc4_dev *vc4 = to_vc4_dev(dev);
 
 	init_waitqueue_head(&vc4->job_wait_queue);
+	spin_lock_init(&vc4->job_lock);
 	INIT_WORK(&vc4->overflow_mem_work, vc4_overflow_mem_work);
 
 	/* Clear any pending interrupts someone might have left around

Are you sure this is a fix? We don't attach the IRQ handler until V3D bind, and vc4_gem_init happens before component_bind_all(), right?

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

#2 lore raw

Hi Eric,

Quoted 36 lines

Eric Anholt <[email protected]> hat am 6. Oktober 2017 um 21:42 geschrieben:

Quoted 31 lines · Stefan Wahren

This fixes the race between vc4_overflow_mem_work and the init of the job lock. Otherwise we could trigger a NULL pointer dereference during VC4 binding.

Fixes d5b1a78a772f ("drm/vc4: Add support for drawing 3D frames.")
---
 drivers/gpu/drm/vc4/vc4_gem.c | 1 -
 drivers/gpu/drm/vc4/vc4_irq.c | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_gem.c +0 -1
index d0c6bfb..47d964f 100644
@@ -1088,7 +1088,6 @@ vc4_gem_init(struct drm_device *dev)
 	INIT_LIST_HEAD(&vc4->render_job_list);
 	INIT_LIST_HEAD(&vc4->job_done_list);
 	INIT_LIST_HEAD(&vc4->seqno_cb_list);
-	spin_lock_init(&vc4->job_lock);
 
 	INIT_WORK(&vc4->hangcheck.reset_work, vc4_reset_work);
 	setup_timer(&vc4->hangcheck.timer,
drivers/gpu/drm/vc4/vc4_irq.c +0 -0
index 7d7af3a..d508d13 100644
@@ -195,6 +195,7 @@ vc4_irq_preinstall(struct drm_device *dev)
 	struct vc4_dev *vc4 = to_vc4_dev(dev);
 
Quoted 8 lines

drivers/gpu/drm/vc4/vc4_irq.c vc4_irq_preinstall(struct drm_device *dev) · line 201

Quoted 5 lines
drivers/gpu/drm/vc4/vc4_irq.c +1 -0
 	init_waitqueue_head(&vc4->job_wait_queue);
+	spin_lock_init(&vc4->job_lock);
 	INIT_WORK(&vc4->overflow_mem_work, vc4_overflow_mem_work);
 
 	/* Clear any pending interrupts someone might have left around

Are you sure this is a fix? We don't attach the IRQ handler until V3D bind, and vc4_gem_init happens before component_bind_all(), right?

i agree i should have mark it as a RFC. But is it really impossible that vc4_overflow_mem_work is triggered before vc4_gem_init?
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
Quoted 42 lines · Stefan Wahren

Hi Eric,

Quoted 40 lines

Eric Anholt <[email protected]> hat am 6. Oktober 2017 um 21:42 geschrieben:

Quoted 35 lines · Stefan Wahren

This fixes the race between vc4_overflow_mem_work and the init of the job lock. Otherwise we could trigger a NULL pointer dereference during VC4 binding.

Fixes d5b1a78a772f ("drm/vc4: Add support for drawing 3D frames.")
---
 drivers/gpu/drm/vc4/vc4_gem.c | 1 -
 drivers/gpu/drm/vc4/vc4_irq.c | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_gem.c +0 -1
index d0c6bfb..47d964f 100644
@@ -1088,7 +1088,6 @@ vc4_gem_init(struct drm_device *dev)
 	INIT_LIST_HEAD(&vc4->render_job_list);
 	INIT_LIST_HEAD(&vc4->job_done_list);
 	INIT_LIST_HEAD(&vc4->seqno_cb_list);
-	spin_lock_init(&vc4->job_lock);
 
 	INIT_WORK(&vc4->hangcheck.reset_work, vc4_reset_work);
 	setup_timer(&vc4->hangcheck.timer,
drivers/gpu/drm/vc4/vc4_irq.c +1 -0
index 7d7af3a..d508d13 100644
@@ -195,6 +195,7 @@ vc4_irq_preinstall(struct drm_device *dev)
 	struct vc4_dev *vc4 = to_vc4_dev(dev);
 
 	init_waitqueue_head(&vc4->job_wait_queue);
+	spin_lock_init(&vc4->job_lock);
 	INIT_WORK(&vc4->overflow_mem_work, vc4_overflow_mem_work);
 
Quoted 7 lines
Quoted 4 lines

drivers/gpu/drm/vc4/vc4_irq.c vc4_irq_preinstall(struct drm_device *dev) · line 201

Quoted 1 line
drivers/gpu/drm/vc4/vc4_irq.c +0 -0
 	/* Clear any pending interrupts someone might have left around

Are you sure this is a fix? We don't attach the IRQ handler until V3D bind, and vc4_gem_init happens before component_bind_all(), right?

i agree i should have mark it as a RFC. But is it really impossible that vc4_overflow_mem_work is triggered before vc4_gem_init?

As far as I can see, it gets queued from the IRQ handler, the IRQ handler is added during V3D bind, and binding happens after GEM init.

Hmm. If we fail out of component binding and try again, we'll end up doing the job_wait_queue and overflow_mem_work initialization on the same pointer twice. Will that cause any trouble? We cancel any pending work during uninstall (V3D unbind path), but does drm_irq_uninstall() make sure that the irq handler has finished?

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

#4 lore raw
Quoted 56 lines

Eric Anholt <[email protected]> hat am 8. Oktober 2017 um 19:09 geschrieben:

Quoted 42 lines · Stefan Wahren

Hi Eric,

Quoted 40 lines

Eric Anholt <[email protected]> hat am 6. Oktober 2017 um 21:42 geschrieben:

Quoted 35 lines · Stefan Wahren

This fixes the race between vc4_overflow_mem_work and the init of the job lock. Otherwise we could trigger a NULL pointer dereference during VC4 binding.

Fixes d5b1a78a772f ("drm/vc4: Add support for drawing 3D frames.")
---
 drivers/gpu/drm/vc4/vc4_gem.c | 1 -
 drivers/gpu/drm/vc4/vc4_irq.c | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_gem.c +0 -1
index d0c6bfb..47d964f 100644
@@ -1088,7 +1088,6 @@ vc4_gem_init(struct drm_device *dev)
 	INIT_LIST_HEAD(&vc4->render_job_list);
 	INIT_LIST_HEAD(&vc4->job_done_list);
 	INIT_LIST_HEAD(&vc4->seqno_cb_list);
-	spin_lock_init(&vc4->job_lock);
 
 	INIT_WORK(&vc4->hangcheck.reset_work, vc4_reset_work);
 	setup_timer(&vc4->hangcheck.timer,
drivers/gpu/drm/vc4/vc4_irq.c +1 -0
index 7d7af3a..d508d13 100644
@@ -195,6 +195,7 @@ vc4_irq_preinstall(struct drm_device *dev)
 	struct vc4_dev *vc4 = to_vc4_dev(dev);
 
 	init_waitqueue_head(&vc4->job_wait_queue);
+	spin_lock_init(&vc4->job_lock);
 	INIT_WORK(&vc4->overflow_mem_work, vc4_overflow_mem_work);
 
Quoted 7 lines
Quoted 4 lines

drivers/gpu/drm/vc4/vc4_irq.c vc4_irq_preinstall(struct drm_device *dev) · line 201

Quoted 1 line
drivers/gpu/drm/vc4/vc4_irq.c +0 -0
 	/* Clear any pending interrupts someone might have left around

Are you sure this is a fix? We don't attach the IRQ handler until V3D bind, and vc4_gem_init happens before component_bind_all(), right?

i agree i should have mark it as a RFC. But is it really impossible that vc4_overflow_mem_work is triggered before vc4_gem_init?

Quoted 8 lines

As far as I can see, it gets queued from the IRQ handler, the IRQ handler is added during V3D bind, and binding happens after GEM init.

Hmm. If we fail out of component binding and try again, we'll end up doing the job_wait_queue and overflow_mem_work initialization on the same pointer twice. Will that cause any trouble? We cancel any pending work during uninstall (V3D unbind path), but does drm_irq_uninstall() make sure that the irq handler has finished?

I cannot see an issue.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel