From 6dedd04ff8ae25a9b4d83d7e53ba9009a2266c30 Mon Sep 17 00:00:00 2001 From: riastradh Date: Sun, 27 Jul 2014 14:02:48 +0000 Subject: [PATCH] Linux work is queued in intr context, so block intrs when locking. (Yes, this getting out of hand.) --- sys/external/bsd/drm2/linux/linux_work.c | 29 ++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/sys/external/bsd/drm2/linux/linux_work.c b/sys/external/bsd/drm2/linux/linux_work.c index 2310e601a989..d38007211188 100644 --- a/sys/external/bsd/drm2/linux/linux_work.c +++ b/sys/external/bsd/drm2/linux/linux_work.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_work.c,v 1.5 2014/07/25 16:15:12 riastradh Exp $ */ +/* $NetBSD: linux_work.c,v 1.6 2014/07/27 14:02:48 riastradh Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.5 2014/07/25 16:15:12 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.6 2014/07/27 14:02:48 riastradh Exp $"); #include #include @@ -281,24 +281,49 @@ linux_wq_barrier(struct work_struct *work) * * We use __cpu_simple_lock(9) rather than mutex(9) because Linux code * does not destroy work, so there is nowhere to call mutex_destroy. + * + * XXX This is getting out of hand... Really, work items shouldn't + * have locks in them at all; instead the workqueues should. */ static void linux_work_lock_init(struct work_struct *work) { + __cpu_simple_lock_init(&work->w_lock); } static void linux_work_lock(struct work_struct *work) { + struct cpu_info *ci; + int cnt, s; + + /* XXX Copypasta of MUTEX_SPIN_SPLRAISE. */ + s = splvm(); + ci = curcpu(); + cnt = ci->ci_mtx_count--; + __insn_barrier(); + if (cnt == 0) + ci->ci_mtx_oldspl = s; + __cpu_simple_lock(&work->w_lock); } static void linux_work_unlock(struct work_struct *work) { + struct cpu_info *ci; + int s; + __cpu_simple_unlock(&work->w_lock); + + /* XXX Copypasta of MUTEX_SPIN_SPLRESTORE. */ + ci = curcpu(); + s = ci->ci_mtx_oldspl; + __insn_barrier(); + if (++ci->ci_mtx_count == 0) + splx(s); } static bool __diagused