Skip to contentSkip to conversation

dma-buf/resv: fix exclusive fence get

PATCH In review Qiang Yu 4 participants 8 messages Sep 22, 2019 – Oct 10, 2019

Subsystems (2)
lore
Share & tools
lore

Qiang Yu

author
#0 lore raw

PATCH 1/1 dma-buf/resv: fix exclusive fence get

This causes kernel crash when testing lima driver.

Cc Christian König <[email protected]>
Fixes b8c036dfc66f ("dma-buf: simplify reservation_object_get_fences_rcu a bit")
---
 drivers/dma-buf/dma-resv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/dma-resv.c +1 -1
index 42a8f3f11681..709002515550 100644
@@ -471,7 +471,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,
 	if (pfence_excl)
 		*pfence_excl = fence_excl;
 	else if (fence_excl)
-		shared[++shared_count] = fence_excl;
+		shared[shared_count++] = fence_excl;
 
 	if (!shared_count) {
 		kfree(shared);
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw

Quoting Qiang Yu (2019-09-22 08:49:00)

Quoted 14 lines

This causes kernel crash when testing lima driver.

Cc Christian König <[email protected]>
Fixes b8c036dfc66f ("dma-buf: simplify reservation_object_get_fences_rcu a bit")
---
 drivers/dma-buf/dma-resv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/dma-resv.c +0 -0
index 42a8f3f11681..709002515550 100644

drivers/dma-buf/dma-resv.c int dma_resv_get_fences_rcu(struct dma_resv *obj, · line 474

Quoted 5 lines
drivers/dma-buf/dma-resv.c +1 -1
@@ -471,7 +471,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,
        if (pfence_excl)
                *pfence_excl = fence_excl;
        else if (fence_excl)
-               shared[++shared_count] = fence_excl;
+               shared[shared_count++] = fence_excl;

Oops.

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

#2 lore raw

Quoting Chris Wilson (2019-09-22 13:17:19)

Quoted 23 lines

Quoting Qiang Yu (2019-09-22 08:49:00)

Quoted 14 lines

This causes kernel crash when testing lima driver.

Cc Christian König <[email protected]>
Fixes b8c036dfc66f ("dma-buf: simplify reservation_object_get_fences_rcu a bit")
---
 drivers/dma-buf/dma-resv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/dma-resv.c +0 -0
index 42a8f3f11681..709002515550 100644

drivers/dma-buf/dma-resv.c int dma_resv_get_fences_rcu(struct dma_resv *obj, · line 474

Quoted 5 lines
drivers/dma-buf/dma-resv.c +1 -1
@@ -471,7 +471,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,
        if (pfence_excl)
                *pfence_excl = fence_excl;
        else if (fence_excl)
-               shared[++shared_count] = fence_excl;
+               shared[shared_count++] = fence_excl;

Oops.

Quoted 1 line

Applied, thanks for the fix.
-Chris
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author
#3 lore raw

Hi Chris,

This fix has been pushed to drm-misc-next for a while. But Linux 5.4-rc kernels still does not have this fix.
Should it be also pushed to drm-misc-fixes?

Thanks,
Qiang

Quoted 25 lines · Chris Wilson

Quoting Chris Wilson (2019-09-22 13:17:19)

Quoted 23 lines

Quoting Qiang Yu (2019-09-22 08:49:00)

Quoted 14 lines

This causes kernel crash when testing lima driver.

Cc Christian König <[email protected]>
Fixes b8c036dfc66f ("dma-buf: simplify reservation_object_get_fences_rcu a bit")
---
 drivers/dma-buf/dma-resv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/dma-resv.c +0 -0
index 42a8f3f11681..709002515550 100644

drivers/dma-buf/dma-resv.c int dma_resv_get_fences_rcu(struct dma_resv *obj, · line 474

Quoted 5 lines
drivers/dma-buf/dma-resv.c +1 -1
@@ -471,7 +471,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,
        if (pfence_excl)
                *pfence_excl = fence_excl;
        else if (fence_excl)
-               shared[++shared_count] = fence_excl;
+               shared[shared_count++] = fence_excl;

Oops.

Quoted 4 lines
Quoted 1 line

Applied, thanks for the fix.
-Chris

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

#4 lore raw

Hi Qiang,

oh, good point. Yes it certainly should.

Looks like I accidentally pushed it to the wrong branch.

Thanks,
Christian.

Am 10.10.19 um 16:27 schrieb Qiang Yu:

Quoted 6 lines

Hi Chris,

This fix has been pushed to drm-misc-next for a while. But Linux 5.4-rc kernels still does not have this fix.
Should it be also pushed to drm-misc-fixes?

Quoted 31 lines

Thanks,
Qiang

Quoted 26 lines · Chris Wilson

Quoting Chris Wilson (2019-09-22 13:17:19)

Quoted 22 lines

Quoting Qiang Yu (2019-09-22 08:49:00)

Quoted 14 lines

This causes kernel crash when testing lima driver.

Cc Christian König <[email protected]>
Fixes b8c036dfc66f ("dma-buf: simplify reservation_object_get_fences_rcu a bit")
---
  drivers/dma-buf/dma-resv.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/dma-resv.c +0 -0
index 42a8f3f11681..709002515550 100644

drivers/dma-buf/dma-resv.c int dma_resv_get_fences_rcu(struct dma_resv *obj, · line 474

Quoted 5 lines
drivers/dma-buf/dma-resv.c +1 -1
@@ -471,7 +471,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,
         if (pfence_excl)
                 *pfence_excl = fence_excl;
         else if (fence_excl)
-               shared[++shared_count] = fence_excl;
+               shared[shared_count++] = fence_excl;

Oops.

Quoted 1 line

Applied, thanks for the fix.
-Chris

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

#5 lore raw
In reply to Qiang Yu
Quoted 6 lines · Qiang Yu

This causes kernel crash when testing lima driver.

Cc Christian König <[email protected]>
Fixes b8c036dfc66f ("dma-buf: simplify reservation_object_get_fences_rcu a bit")

Selftest for this would be lovely, now that the basic infrastructure is in place ...
-Daniel

Quoted 24 lines
---
 drivers/dma-buf/dma-resv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/dma-resv.c +1 -2
index 42a8f3f11681..709002515550 100644
@@ -471,7 +471,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,
        if (pfence_excl)
                *pfence_excl = fence_excl;
        else if (fence_excl)
-               shared[++shared_count] = fence_excl;
+               shared[shared_count++] = fence_excl;
 
        if (!shared_count) {
                kfree(shared);
--

2.17.1

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

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw

Am 30.09.19 um 09:22 schrieb Daniel Vetter:

Quoted 8 lines · Qiang Yu
Quoted 5 lines

This causes kernel crash when testing lima driver.

Cc Christian König <[email protected]>
Fixes b8c036dfc66f ("dma-buf: simplify reservation_object_get_fences_rcu a bit")

Selftest for this would be lovely, now that the basic infrastructure is in place ...

What do you have in mind? I wouldn't even know where to start to write an unit test for this.

Christian.

Quoted 22 lines

-Daniel

Quoted 20 lines
---
  drivers/dma-buf/dma-resv.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/dma-resv.c +1 -2
index 42a8f3f11681..709002515550 100644
@@ -471,7 +471,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,
         if (pfence_excl)
                 *pfence_excl = fence_excl;
         else if (fence_excl)
-               shared[++shared_count] = fence_excl;
+               shared[shared_count++] = fence_excl;
 
         if (!shared_count) {
                 kfree(shared);
--

2.17.1

Quoted 6 lines
Quoted 4 lines

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

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

#7 lore raw
Quoted 4 lines · Christian

Am 30.09.19 um 09:22 schrieb Daniel Vetter:

Quoted 3 lines · Qiang Yu
Quoted 2 lines

This causes kernel crash when testing lima driver.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Cc Christian König <[email protected]>
Fixes b8c036dfc66f ("dma-buf: simplify reservation_object_get_fences_rcu a bit")

Selftest for this would be lovely, now that the basic infrastructure is in place ...

What do you have in mind? I wouldn't even know where to start to write an unit test for this.

1. set a few fences (both excl + shared) in a dma_resv
2. get them
3. check that we got them all
4. notice that the exlusive fence isn't actually in the array (because we increment the index before storing, so the exclusive fence ended past the array). For robustness the test should check that the fences are listed in any order, not just the one the current implementation gives you.

I guess the actual crash happens when we're unlucky and overflow the allocation, which is probably more rare. But KASAN should help catch that too (run that in your CI if you don't do that yet, it's pretty impressive).

Or am I totally misunderstanding what's going wrong here? -Daniel

Quoted 32 lines

Christian.

Quoted 28 lines

-Daniel

Quoted 24 lines
---
  drivers/dma-buf/dma-resv.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/dma-resv.c +1 -2
index 42a8f3f11681..709002515550 100644
@@ -471,7 +471,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,
         if (pfence_excl)
                 *pfence_excl = fence_excl;
         else if (fence_excl)
-               shared[++shared_count] = fence_excl;
+               shared[shared_count++] = fence_excl;
 
         if (!shared_count) {
                 kfree(shared);
--

2.17.1

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

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel