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: Allow ww_mutex_lock after w...
details: https://anonhg.NetBSD.org/src/rev/d4708dd30534
branches: trunk
changeset: 1029193:d4708dd30534
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sun Dec 26 16:14:34 2021 +0000
description:
drm: Allow ww_mutex_lock after ww_acquire_done if we already hold it.
In other words, if ww_mutex_lock would return -EALREADY, that's OK and
does not warrant an assertion.
PR kern/56557
diffstat:
sys/external/bsd/drm2/linux/linux_ww_mutex.c | 31 ++++++++++++++++++---------
1 files changed, 21 insertions(+), 10 deletions(-)
diffs (108 lines):
diff -r 958872744286 -r d4708dd30534 sys/external/bsd/drm2/linux/linux_ww_mutex.c
--- a/sys/external/bsd/drm2/linux/linux_ww_mutex.c Sun Dec 26 16:08:19 2021 +0000
+++ b/sys/external/bsd/drm2/linux/linux_ww_mutex.c Sun Dec 26 16:14:34 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_ww_mutex.c,v 1.12 2021/12/24 15:25:03 riastradh Exp $ */
+/* $NetBSD: linux_ww_mutex.c,v 1.13 2021/12/26 16:14:34 riastradh Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_ww_mutex.c,v 1.12 2021/12/24 15:25:03 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_ww_mutex.c,v 1.13 2021/12/26 16:14:34 riastradh Exp $");
#include <sys/types.h>
#include <sys/atomic.h>
@@ -108,6 +108,21 @@
ctx->wwx_acquire_done = true;
}
+static void
+ww_acquire_done_check(struct ww_mutex *mutex, struct ww_acquire_ctx *ctx)
+{
+
+ /*
+ * If caller has invoked ww_acquire_done, we must already hold
+ * this mutex.
+ */
+ KASSERT(mutex_owned(&mutex->wwm_lock));
+ KASSERTMSG((!ctx->wwx_acquire_done ||
+ (mutex->wwm_state == WW_CTX && mutex->wwm_u.ctx == ctx)),
+ "ctx %p done acquiring locks, refusing to acquire %p",
+ ctx, mutex);
+}
+
void
ww_acquire_fini(struct ww_acquire_ctx *ctx)
{
@@ -552,8 +567,6 @@
KASSERTMSG((ctx->wwx_owner == curlwp),
"ctx %p owned by %p, not self (%p)", ctx, ctx->wwx_owner, curlwp);
- KASSERTMSG(!ctx->wwx_acquire_done,
- "ctx %p done acquiring locks, can't acquire more", ctx);
KASSERTMSG((ctx->wwx_acquired != ~0U),
"ctx %p finished, can't be used any more", ctx);
KASSERTMSG((ctx->wwx_class == mutex->wwm_class),
@@ -561,6 +574,7 @@
ctx, ctx->wwx_class, mutex, mutex->wwm_class);
mutex_enter(&mutex->wwm_lock);
+ ww_acquire_done_check(mutex, ctx);
retry: switch (mutex->wwm_state) {
case WW_UNLOCKED:
WW_WANTLOCK(mutex);
@@ -673,8 +687,6 @@
KASSERTMSG((ctx->wwx_owner == curlwp),
"ctx %p owned by %p, not self (%p)", ctx, ctx->wwx_owner, curlwp);
- KASSERTMSG(!ctx->wwx_acquire_done,
- "ctx %p done acquiring locks, can't acquire more", ctx);
KASSERTMSG((ctx->wwx_acquired != ~0U),
"ctx %p finished, can't be used any more", ctx);
KASSERTMSG((ctx->wwx_class == mutex->wwm_class),
@@ -682,6 +694,7 @@
ctx, ctx->wwx_class, mutex, mutex->wwm_class);
mutex_enter(&mutex->wwm_lock);
+ ww_acquire_done_check(mutex, ctx);
retry: switch (mutex->wwm_state) {
case WW_UNLOCKED:
WW_WANTLOCK(mutex);
@@ -795,8 +808,6 @@
KASSERTMSG((ctx->wwx_owner == curlwp),
"ctx %p owned by %p, not self (%p)", ctx, ctx->wwx_owner, curlwp);
- KASSERTMSG(!ctx->wwx_acquire_done,
- "ctx %p done acquiring locks, can't acquire more", ctx);
KASSERTMSG((ctx->wwx_acquired != ~0U),
"ctx %p finished, can't be used any more", ctx);
KASSERTMSG((ctx->wwx_acquired == 0),
@@ -807,6 +818,7 @@
ctx, ctx->wwx_class, mutex, mutex->wwm_class);
mutex_enter(&mutex->wwm_lock);
+ ww_acquire_done_check(mutex, ctx);
retry: switch (mutex->wwm_state) {
case WW_UNLOCKED:
mutex->wwm_state = WW_CTX;
@@ -874,8 +886,6 @@
KASSERTMSG((ctx->wwx_owner == curlwp),
"ctx %p owned by %p, not self (%p)", ctx, ctx->wwx_owner, curlwp);
- KASSERTMSG(!ctx->wwx_acquire_done,
- "ctx %p done acquiring locks, can't acquire more", ctx);
KASSERTMSG((ctx->wwx_acquired != ~0U),
"ctx %p finished, can't be used any more", ctx);
KASSERTMSG((ctx->wwx_acquired == 0),
@@ -886,6 +896,7 @@
ctx, ctx->wwx_class, mutex, mutex->wwm_class);
mutex_enter(&mutex->wwm_lock);
+ ww_acquire_done_check(mutex, ctx);
retry: switch (mutex->wwm_state) {
case WW_UNLOCKED:
mutex->wwm_state = WW_CTX;
Home |
Main Index |
Thread Index |
Old Index