dma-buf: Move BUG_ON from _add_shared_fence to _add_shared_inplace
authorMichel Dänzer <michel.daenzer@amd.com>
Wed, 4 Jul 2018 15:14:05 +0000 (17:14 +0200)
committerSumit Semwal <sumit.semwal@linaro.org>
Mon, 16 Jul 2018 14:50:37 +0000 (20:20 +0530)
commit7f43ef9f0d98abbc0eb5e697628ec06756bf60a9
treee1427219f16792cbf6d4c0dab26b1255a336e4c2
parent3273fc63e1ed4866fe10a582f4203f2aa142b216
dma-buf: Move BUG_ON from _add_shared_fence to _add_shared_inplace

Fixes the BUG_ON spuriously triggering under the following
circumstances:

* reservation_object_reserve_shared is called with shared_count ==
  shared_max - 1, so obj->staged is freed in preparation of an in-place
  update.

* reservation_object_add_shared_fence is called with the first fence,
  after which shared_count == shared_max.

* reservation_object_add_shared_fence is called with a follow-up fence
  from the same context.

In the second reservation_object_add_shared_fence call, the BUG_ON
triggers. However, nothing bad would happen in
reservation_object_add_shared_inplace, since both fences are from the
same context, so they only occupy a single slot.

Prevent this by moving the BUG_ON to where an overflow would actually
happen (e.g. if a buggy caller didn't call
reservation_object_reserve_shared before).

v2:
* Fix description of breaking scenario (Christian König)
* Add bugzilla reference

Cc: stable@vger.kernel.org
Bugzilla: https://bugs.freedesktop.org/106418
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> # v1
Reviewed-by: Christian König <christian.koenig@amd.com> # v1
Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20180704151405.10357-1-michel@daenzer.net
drivers/dma-buf/reservation.c