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: Sprinkle assertions about f...



details:   https://anonhg.NetBSD.org/src/rev/f9bf9c278c9a
branches:  trunk
changeset: 1028839:f9bf9c278c9a
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 12:10:51 2021 +0000

description:
drm: Sprinkle assertions about fence lifetime.

diffstat:

 sys/external/bsd/drm2/include/linux/dma-fence.h |   3 +-
 sys/external/bsd/drm2/linux/linux_dma_fence.c   |  44 +++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 4 deletions(-)

diffs (171 lines):

diff -r 97671d2687fa -r f9bf9c278c9a sys/external/bsd/drm2/include/linux/dma-fence.h
--- a/sys/external/bsd/drm2/include/linux/dma-fence.h   Sun Dec 19 12:10:42 2021 +0000
+++ b/sys/external/bsd/drm2/include/linux/dma-fence.h   Sun Dec 19 12:10:51 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dma-fence.h,v 1.14 2021/12/19 12:02:40 riastradh Exp $ */
+/*     $NetBSD: dma-fence.h,v 1.15 2021/12/19 12:10:51 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -59,6 +59,7 @@
 
        TAILQ_HEAD(, dma_fence_cb)      f_callbacks;
        kcondvar_t                      f_cv;
+       uint64_t                        f_magic;
 };
 
 #define        DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT        0
diff -r 97671d2687fa -r f9bf9c278c9a sys/external/bsd/drm2/linux/linux_dma_fence.c
--- a/sys/external/bsd/drm2/linux/linux_dma_fence.c     Sun Dec 19 12:10:42 2021 +0000
+++ b/sys/external/bsd/drm2/linux/linux_dma_fence.c     Sun Dec 19 12:10:51 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_dma_fence.c,v 1.23 2021/12/19 12:09:51 riastradh Exp $   */
+/*     $NetBSD: linux_dma_fence.c,v 1.24 2021/12/19 12:10:51 riastradh Exp $   */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_dma_fence.c,v 1.23 2021/12/19 12:09:51 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_dma_fence.c,v 1.24 2021/12/19 12:10:51 riastradh Exp $");
 
 #include <sys/atomic.h>
 #include <sys/condvar.h>
@@ -43,6 +43,9 @@
 #include <linux/sched.h>
 #include <linux/spinlock.h>
 
+#define        FENCE_MAGIC_GOOD        0x607ba424048c37e5ULL
+#define        FENCE_MAGIC_BAD         0x7641ca721344505fULL
+
 /*
  * linux_dma_fence_trace
  *
@@ -57,12 +60,16 @@
  *
  *     True if fence has a positive reference count.  True after
  *     dma_fence_init; after the last dma_fence_put, this becomes
- *     false.
+ *     false.  The fence must have been initialized and must not have
+ *     been destroyed.
  */
 static inline bool __diagused
 dma_fence_referenced_p(struct dma_fence *fence)
 {
 
+       KASSERTMSG(fence->f_magic != FENCE_MAGIC_BAD, "fence %p", fence);
+       KASSERTMSG(fence->f_magic == FENCE_MAGIC_GOOD, "fence %p", fence);
+
        return kref_referenced_p(&fence->refcount);
 }
 
@@ -86,6 +93,10 @@
        fence->error = 0;
        TAILQ_INIT(&fence->f_callbacks);
        cv_init(&fence->f_cv, "dmafence");
+
+#ifdef DIAGNOSTIC
+       fence->f_magic = FENCE_MAGIC_GOOD;
+#endif
 }
 
 /*
@@ -102,6 +113,8 @@
     spinlock_t *lock, unsigned context, unsigned seqno)
 {
 
+       KASSERTMSG(fence->f_magic != FENCE_MAGIC_BAD, "fence %p", fence);
+       KASSERTMSG(fence->f_magic == FENCE_MAGIC_GOOD, "fence %p", fence);
        KASSERT(kref_read(&fence->refcount) == 0 ||
            kref_read(&fence->refcount) == 1);
        KASSERT(TAILQ_EMPTY(&fence->f_callbacks));
@@ -129,6 +142,10 @@
 
        KASSERT(!dma_fence_referenced_p(fence));
 
+#ifdef DIAGNOSTIC
+       fence->f_magic = FENCE_MAGIC_BAD;
+#endif
+
        KASSERT(TAILQ_EMPTY(&fence->f_callbacks));
        cv_destroy(&fence->f_cv);
 }
@@ -194,6 +211,10 @@
 dma_fence_is_later(struct dma_fence *a, struct dma_fence *b)
 {
 
+       KASSERTMSG(a->f_magic != FENCE_MAGIC_BAD, "fence %p", a);
+       KASSERTMSG(a->f_magic == FENCE_MAGIC_GOOD, "fence %p", a);
+       KASSERTMSG(b->f_magic != FENCE_MAGIC_BAD, "fence %p", b);
+       KASSERTMSG(b->f_magic == FENCE_MAGIC_GOOD, "fence %p", b);
        KASSERTMSG(a->context == b->context, "incommensurate fences"
            ": %u @ %p =/= %u @ %p", a->context, a, b->context, b);
 
@@ -232,6 +253,9 @@
 dma_fence_get(struct dma_fence *fence)
 {
 
+       KASSERTMSG(fence->f_magic != FENCE_MAGIC_BAD, "fence %p", fence);
+       KASSERTMSG(fence->f_magic == FENCE_MAGIC_GOOD, "fence %p", fence);
+
        if (fence)
                kref_get(&fence->refcount);
        return fence;
@@ -249,6 +273,8 @@
 {
 
        __insn_barrier();
+       KASSERTMSG(fence->f_magic != FENCE_MAGIC_BAD, "fence %p", fence);
+       KASSERTMSG(fence->f_magic == FENCE_MAGIC_GOOD, "fence %p", fence);
        if (!kref_get_unless_zero(&fence->refcount))
                return NULL;
        return fence;
@@ -297,6 +323,7 @@
        }
 
        /* Success!  */
+       KASSERT(dma_fence_referenced_p(fence));
        return fence;
 }
 
@@ -538,6 +565,8 @@
 dma_fence_set_error(struct dma_fence *fence, int error)
 {
 
+       KASSERTMSG(fence->f_magic != FENCE_MAGIC_BAD, "fence %p", fence);
+       KASSERTMSG(fence->f_magic == FENCE_MAGIC_GOOD, "fence %p", fence);
        KASSERT(!(fence->flags & (1u << DMA_FENCE_FLAG_SIGNALED_BIT)));
        KASSERTMSG(error >= -ELAST, "%d", error);
        KASSERTMSG(error < 0, "%d", error);
@@ -557,6 +586,9 @@
 {
        int ret;
 
+       KASSERTMSG(fence->f_magic != FENCE_MAGIC_BAD, "fence %p", fence);
+       KASSERTMSG(fence->f_magic == FENCE_MAGIC_GOOD, "fence %p", fence);
+
        spin_lock(fence->lock);
        if (!dma_fence_is_signaled_locked(fence)) {
                ret = 0;
@@ -945,6 +977,9 @@
 __dma_fence_signal(struct dma_fence *fence)
 {
 
+       KASSERTMSG(fence->f_magic != FENCE_MAGIC_BAD, "fence %p", fence);
+       KASSERTMSG(fence->f_magic == FENCE_MAGIC_GOOD, "fence %p", fence);
+
        if (test_and_set_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
                return false;
 
@@ -962,6 +997,9 @@
 {
        struct dma_fence_cb *fcb, *next;
 
+       KASSERTMSG(fence->f_magic != FENCE_MAGIC_BAD, "fence %p", fence);
+       KASSERTMSG(fence->f_magic == FENCE_MAGIC_GOOD, "fence %p", fence);
+
        spin_lock(fence->lock);
 
        KASSERT(fence->flags & DMA_FENCE_FLAG_SIGNALED_BIT);



Home | Main Index | Thread Index | Old Index