mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-04 12:52:15 +00:00
CURSIG() calls functions that acquire sleep mutexes, so it is not a good
idea to be holding the sched_lock while we are calling it. As such, release sched_lock before calling CURSIG() in msleep() and mawait() and reacquire it after CURSIG() returns. Submitted by: witness
This commit is contained in:
parent
930a65fe47
commit
95de685572
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=68804
@ -477,12 +477,15 @@ msleep(ident, mtx, priority, wmesg, timo)
|
||||
"msleep caught: proc %p (pid %d, %s), schedlock %p",
|
||||
p, p->p_pid, p->p_comm, (void *) sched_lock.mtx_lock);
|
||||
p->p_flag |= P_SINTR;
|
||||
mtx_exit(&sched_lock, MTX_SPIN);
|
||||
if ((sig = CURSIG(p))) {
|
||||
mtx_enter(&sched_lock, MTX_SPIN);
|
||||
if (p->p_wchan)
|
||||
unsleep(p);
|
||||
p->p_stat = SRUN;
|
||||
goto resume;
|
||||
}
|
||||
mtx_enter(&sched_lock, MTX_SPIN);
|
||||
if (p->p_wchan == 0) {
|
||||
catch = 0;
|
||||
goto resume;
|
||||
@ -507,10 +510,13 @@ msleep(ident, mtx, priority, wmesg, timo)
|
||||
ktrcsw(p->p_tracep, 0, 0);
|
||||
#endif
|
||||
rval = EWOULDBLOCK;
|
||||
mtx_exit(&sched_lock, MTX_SPIN);
|
||||
goto out;
|
||||
}
|
||||
} else if (timo)
|
||||
untimeout(endtsleep, (void *)p, thandle);
|
||||
mtx_exit(&sched_lock, MTX_SPIN);
|
||||
|
||||
if (catch && (sig != 0 || (sig = CURSIG(p)))) {
|
||||
#ifdef KTRACE
|
||||
if (KTRPOINT(p, KTR_CSW))
|
||||
@ -523,7 +529,6 @@ msleep(ident, mtx, priority, wmesg, timo)
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
mtx_exit(&sched_lock, MTX_SPIN);
|
||||
#ifdef KTRACE
|
||||
if (KTRPOINT(p, KTR_CSW))
|
||||
ktrcsw(p->p_tracep, 0, 0);
|
||||
@ -643,12 +648,15 @@ mawait(struct mtx *mtx, int priority, int timo)
|
||||
|
||||
if (catch) {
|
||||
p->p_flag |= P_SINTR;
|
||||
mtx_exit(&sched_lock, MTX_SPIN);
|
||||
if ((sig = CURSIG(p))) {
|
||||
mtx_enter(&sched_lock, MTX_SPIN);
|
||||
if (p->p_wchan)
|
||||
unsleep(p);
|
||||
p->p_stat = SRUN;
|
||||
goto resume;
|
||||
}
|
||||
mtx_enter(&sched_lock, MTX_SPIN);
|
||||
if (p->p_wchan == NULL) {
|
||||
catch = 0;
|
||||
goto resume;
|
||||
@ -674,6 +682,8 @@ mawait(struct mtx *mtx, int priority, int timo)
|
||||
}
|
||||
} else if (timo)
|
||||
untimeout(endtsleep, (void *)p, thandle);
|
||||
mtx_exit(&sched_lock, MTX_SPIN);
|
||||
|
||||
if (catch && (sig != 0 || (sig = CURSIG(p)))) {
|
||||
#ifdef KTRACE
|
||||
if (KTRPOINT(p, KTR_CSW))
|
||||
@ -700,6 +710,7 @@ mawait(struct mtx *mtx, int priority, int timo)
|
||||
p->p_stats->p_ru.ru_nvcsw++;
|
||||
mi_switch();
|
||||
}
|
||||
mtx_exit(&sched_lock, MTX_SPIN);
|
||||
splx(s);
|
||||
}
|
||||
|
||||
@ -712,8 +723,6 @@ mawait(struct mtx *mtx, int priority, int timo)
|
||||
p->p_asleep.as_priority = 0;
|
||||
|
||||
out:
|
||||
mtx_exit(&sched_lock, MTX_SPIN);
|
||||
|
||||
if (mtx != NULL) {
|
||||
mtx_enter(mtx, MTX_DEF);
|
||||
WITNESS_RESTORE(mtx, mtx);
|
||||
|
Loading…
Reference in New Issue
Block a user