Index: sys/external/bsd/drm2/include/linux/ww_mutex.h =================================================================== RCS file: /cvsroot/src/sys/external/bsd/drm2/include/linux/ww_mutex.h,v retrieving revision 1.6 diff -p -u -r1.6 ww_mutex.h --- sys/external/bsd/drm2/include/linux/ww_mutex.h 13 Sep 2014 00:33:45 -0000 1.6 +++ sys/external/bsd/drm2/include/linux/ww_mutex.h 14 Sep 2014 23:33:46 -0000 @@ -51,6 +51,7 @@ struct ww_acquire_ctx { unsigned wwx_acquired; bool wwx_acquire_done; struct rb_node wwx_rb_node; + struct lwp *wwx_owner; }; static inline int @@ -95,12 +96,17 @@ ww_acquire_init(struct ww_acquire_ctx *c ctx->wwx_ticket = atomic_inc_64_nv(&class->wwc_ticket); ctx->wwx_acquired = 0; ctx->wwx_acquire_done = false; + ctx->wwx_owner = curlwp; } static inline void ww_acquire_done(struct ww_acquire_ctx *ctx) { + KASSERTMSG((ctx->wwx_owner == curlwp), + "ctx %p owned by %p, not self (%p)", ctx, ctx->wwx_owner, curlwp); + printf("%s: ctx %p acquired %u\n", __func__, ctx, ctx->wwx_acquired); + ctx->wwx_acquire_done = true; } @@ -108,9 +114,13 @@ static inline void ww_acquire_fini(struct ww_acquire_ctx *ctx) { + KASSERTMSG((ctx->wwx_owner == curlwp), + "ctx %p owned by %p, not self (%p)", ctx, ctx->wwx_owner, curlwp); KASSERTMSG((ctx->wwx_acquired == 0), "ctx %p still holds %u locks", ctx, ctx->wwx_acquired); + ctx->wwx_acquired = ~0U; /* Fail if called again. */ + ctx->wwx_owner = NULL; } struct ww_mutex { @@ -349,7 +359,10 @@ ww_mutex_lock(struct ww_mutex *mutex, st return 0; } + KASSERTMSG((ctx->wwx_owner == curlwp), + "ctx %p owned by %p, not self (%p)", ctx, ctx->wwx_owner, curlwp); KASSERT(!ctx->wwx_acquire_done); + KASSERT(ctx->wwx_acquired != ~0U); mutex_enter(&mutex->wwm_lock); retry: switch (mutex->wwm_state) { @@ -373,6 +386,8 @@ retry: switch (mutex->wwm_state) { } KASSERT(mutex->wwm_state == WW_CTX); KASSERT(mutex->wwm_u.ctx != NULL); + KASSERT((mutex->wwm_u.ctx == ctx) || + (mutex->wwm_u.ctx->wwx_owner != curlwp)); if (mutex->wwm_u.ctx == ctx) { /* * We already own it. Yes, this can happen correctly @@ -416,7 +431,10 @@ ww_mutex_lock_interruptible(struct ww_mu if (ctx == NULL) return ww_mutex_lock_noctx_sig(mutex); + KASSERTMSG((ctx->wwx_owner == curlwp), + "ctx %p owned by %p, not self (%p)", ctx, ctx->wwx_owner, curlwp); KASSERT(!ctx->wwx_acquire_done); + KASSERT(ctx->wwx_acquired != ~0U); mutex_enter(&mutex->wwm_lock); retry: switch (mutex->wwm_state) { @@ -444,6 +462,8 @@ retry: switch (mutex->wwm_state) { } KASSERT(mutex->wwm_state == WW_CTX); KASSERT(mutex->wwm_u.ctx != NULL); + KASSERT((mutex->wwm_u.ctx == ctx) || + (mutex->wwm_u.ctx->wwx_owner != curlwp)); if (mutex->wwm_u.ctx == ctx) { /* * We already own it. Yes, this can happen correctly @@ -491,7 +511,10 @@ ww_mutex_lock_slow(struct ww_mutex *mute return; } + KASSERTMSG((ctx->wwx_owner == curlwp), + "ctx %p owned by %p, not self (%p)", ctx, ctx->wwx_owner, curlwp); KASSERT(!ctx->wwx_acquire_done); + KASSERT(ctx->wwx_acquired != ~0U); mutex_enter(&mutex->wwm_lock); retry: switch (mutex->wwm_state) { @@ -515,6 +538,8 @@ retry: switch (mutex->wwm_state) { } KASSERT(mutex->wwm_state == WW_CTX); KASSERT(mutex->wwm_u.ctx != NULL); + KASSERTMSG((mutex->wwm_u.ctx->wwx_owner != curlwp), + "locking against myself: %p", curlwp); /* * Owned by another party, of any priority. Ask that party to * wake us when it's done. @@ -537,7 +562,10 @@ ww_mutex_lock_slow_interruptible(struct if (ctx == NULL) return ww_mutex_lock_noctx_sig(mutex); + KASSERTMSG((ctx->wwx_owner == curlwp), + "ctx %p owned by %p, not self (%p)", ctx, ctx->wwx_owner, curlwp); KASSERT(!ctx->wwx_acquire_done); + KASSERT(ctx->wwx_acquired != ~0U); mutex_enter(&mutex->wwm_lock); retry: switch (mutex->wwm_state) { @@ -565,6 +593,8 @@ retry: switch (mutex->wwm_state) { } KASSERT(mutex->wwm_state == WW_CTX); KASSERT(mutex->wwm_u.ctx != NULL); + KASSERTMSG((mutex->wwm_u.ctx->wwx_owner != curlwp), + "locking against myself: %p", curlwp); /* * Owned by another party, of any priority. Ask that party to * wake us when it's done. @@ -615,6 +645,11 @@ ww_mutex_unlock(struct ww_mutex *mutex) break; case WW_CTX: KASSERT(mutex->wwm_u.ctx != NULL); + KASSERTMSG((mutex->wwm_u.ctx->wwx_owner == curlwp), + "ww_mutex %p ctx %p held by %p, not by self (%p)", + mutex, mutex->wwm_u.ctx, mutex->wwm_u.ctx->wwx_owner, + curlwp); + KASSERT(mutex->wwm_u.ctx->wwx_acquired != ~0U); mutex->wwm_u.ctx->wwx_acquired--; mutex->wwm_u.ctx = NULL; /*