Skip to content

Commit

Permalink
sx: unset td_wantedlock around going to sleep
Browse files Browse the repository at this point in the history
Otherwise it can crash in sleepq_wait_sig -> sleepq_catch_signals ->
sig_ast_checksusp -> thread_suspend_check due to a mutex acquire.

Reported by:	pho
Sponsored by:	Rubicon Communications, LLC ("Netgate")
  • Loading branch information
mjguzik committed Oct 23, 2023
1 parent 7b2ab18 commit c35f527
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sys/kern/kern_sx.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,10 +854,17 @@ _sx_xlock_hard(struct sx *sx, uintptr_t x, int opts LOCK_FILE_LINE_ARG_DEF)
sleepq_add(&sx->lock_object, NULL, sx->lock_object.lo_name,
SLEEPQ_SX | ((opts & SX_INTERRUPTIBLE) ?
SLEEPQ_INTERRUPTIBLE : 0), SQ_EXCLUSIVE_QUEUE);
/*
* Hack: this can land in thread_suspend_check which will
* conditionally take a mutex, tripping over an assert if a
* lock we are waiting for is set.
*/
THREAD_CONTENTION_DONE(&sx->lock_object);
if (!(opts & SX_INTERRUPTIBLE))
sleepq_wait(&sx->lock_object, 0);
else
error = sleepq_wait_sig(&sx->lock_object, 0);
THREAD_CONTENTION_DONE(&sx->lock_object);
#ifdef KDTRACE_HOOKS
sleep_time += lockstat_nsecs(&sx->lock_object);
sleep_cnt++;
Expand Down Expand Up @@ -1209,10 +1216,17 @@ _sx_slock_hard(struct sx *sx, int opts, uintptr_t x LOCK_FILE_LINE_ARG_DEF)
sleepq_add(&sx->lock_object, NULL, sx->lock_object.lo_name,
SLEEPQ_SX | ((opts & SX_INTERRUPTIBLE) ?
SLEEPQ_INTERRUPTIBLE : 0), SQ_SHARED_QUEUE);
/*
* Hack: this can land in thread_suspend_check which will
* conditionally take a mutex, tripping over an assert if a
* lock we are waiting for is set.
*/
THREAD_CONTENTION_DONE(&sx->lock_object);
if (!(opts & SX_INTERRUPTIBLE))
sleepq_wait(&sx->lock_object, 0);
else
error = sleepq_wait_sig(&sx->lock_object, 0);
THREAD_CONTENDS_ON_LOCK(&sx->lock_object);
#ifdef KDTRACE_HOOKS
sleep_time += lockstat_nsecs(&sx->lock_object);
sleep_cnt++;
Expand Down

0 comments on commit c35f527

Please sign in to comment.