Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/external/bsd/drm2/linux drm: Make sure to check read tic...



details:   https://anonhg.NetBSD.org/src/rev/1496aa625a73
branches:  trunk
changeset: 1028901:1496aa625a73
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 12:26:22 2021 +0000

description:
drm: Make sure to check read ticket after reading shared fences.

Not entirely sure it was a bug not to do that, but let's make it easy
to prove that we got a consistent snapshot of the whole picture.

diffstat:

 sys/external/bsd/drm2/linux/linux_dma_resv.c |  22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)

diffs (67 lines):

diff -r 9fca0ab70750 -r 1496aa625a73 sys/external/bsd/drm2/linux/linux_dma_resv.c
--- a/sys/external/bsd/drm2/linux/linux_dma_resv.c      Sun Dec 19 12:26:13 2021 +0000
+++ b/sys/external/bsd/drm2/linux/linux_dma_resv.c      Sun Dec 19 12:26:22 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_dma_resv.c,v 1.13 2021/12/19 12:26:13 riastradh Exp $    */
+/*     $NetBSD: linux_dma_resv.c,v 1.14 2021/12/19 12:26:22 riastradh Exp $    */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_dma_resv.c,v 1.13 2021/12/19 12:26:13 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_dma_resv.c,v 1.14 2021/12/19 12:26:22 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/poll.h>
@@ -813,10 +813,14 @@
                 * and record the number of elements.  Could safely use
                 * memcpy here, because even if we race with a writer
                 * it'll invalidate the read ticket and we'll start
-                * ove, but atomic_load in a loop will pacify kcsan.
+                * over, but atomic_load in a loop will pacify kcsan.
                 */
                for (i = 0; i < shared_count; i++)
                        shared[i] = atomic_load_relaxed(&list->shared[i]);
+
+               /* If anything changed while we were copying, restart.  */
+               if (!dma_resv_read_valid(robj, &ticket))
+                       goto restart;
        }
 
        /* If there is an exclusive fence, grab it.  */
@@ -910,6 +914,10 @@
                        dst_list->shared[dst_list->shared_count++] = fence;
                        fence = NULL;
                }
+
+               /* If anything changed while we were copying, restart.  */
+               if (!dma_resv_read_valid(src_robj, &read_ticket))
+                       goto restart;
        }
 
        /* Get the exclusive fence.  */
@@ -1031,6 +1039,10 @@
                        if (!signaled)
                                goto out;
                }
+
+               /* If anything changed while we were testing, restart.  */
+               if (!dma_resv_read_valid(robj, &ticket))
+                       goto restart;
        }
 
        /* If there is an exclusive fence, test it.  */
@@ -1114,6 +1126,10 @@
                        dma_fence_put(fence);
                        fence = NULL;
                }
+
+               /* If anything changed while we were testing, restart.  */
+               if (!dma_resv_read_valid(robj, &ticket))
+                       goto restart;
        }
 
        /* If there is an exclusive fence, test it.  */



Home | Main Index | Thread Index | Old Index