🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: muc.lists.freebsd.current
Article #181

Re: ULE: run queue lock deadlock in sched_switch_migrate() + tdq_move()

#181
From: Olivier Certner
Date: Wed, 11 Nov 2026 12:48
77 lines
5040 bytes
--nextPart2531705.bDOn7JOVgO
Content-Transfer-Encoding: 7Bit
Content-Type: text/plain; charset="utf-8"; protected-headers="v1"
From: Olivier Certner <olce@freebsd.org>
Date: Wed, 11 Nov 2026 13:48:56 +0100
Message-ID: <6612379.O1aUxXEVJ6@ravel>
In-Reply-To: <avRQ4kbiSw-xbhzU@kib.kiev.ua>
MIME-Version: 1.0

Hi,

> > - CPU 4: thread T was preempted (ipi_bitmap_handler -> sched_preempt ->
> >   mi_switch -> sched_switch) and is migrating to CPU 12.
> >   sched_switch_migrate() has dropped tdq 4's lock, added T to tdq 12
> >   with td_lock == &blocked_lock, dropped tdq 12's lock, and now spins in
> >   the final TDQ_LOCK(tdq) on tdq 4's lock.
> > - CPU 20: idle thread, tdq_idled() -> tdq_move(from = tdq 12, to = tdq 20).
> >   It holds the tdq 20 and tdq 12 locks and spins in
> >   thread_lock_block_wait(T).
> > - CPU 0: idle thread, statclock -> sched_clock -> sched_balance ->
> >   sched_balance_group -> sched_balance_pair -> tdq_lock_pair().
> >   It holds tdq 4's lock and spins on tdq 20's lock.
> > 
> > T's td_lock can be released only by cpu_switch() on CPU 4, which can run
> > only after CPU 4 gets tdq 4's lock.  So CPU 0 waits for CPU 20, CPU 20 waits
> > for T, and T waits for CPU 0.  Other CPUs then piled up on tdq 20's lock
> > (sched_add from sleepq_timeout) until one of them panicked.

This indeed can happen.
 
> > Ermal proposed to fix (avoid) the issue by not waiting in tdq_move() at all:
> > if the thread is still blocked, return -1, which all callers already handle,
> > since stealing is opportunistic.

Yes, but that decreases efficiency of the "try steal" and it looks like it can be fixed differently.
 
> I can open a review request if it would make discussing and reviewing easier.

In the patch below, `thread_lock_block_wait()` is now superfluous.

Except for trivial things, please always put up scheduler changes under review with the `#scheduler` group as a reviewer.

Thanks and regards.

-- 
Olivier Certner
--nextPart2531705.bDOn7JOVgO
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part.
Content-Transfer-Encoding: 7Bit

-----BEGIN PGP SIGNATURE-----

iQIzBAABCQAdFiEEmNCxHjkosai0LYIujKEwQJceJicFAmr0ZDgACgkQjKEwQJce
JieGaA/+LfOfkBuXuqFD5/wJ3PVfR/7GT3DO60GXvi9ev/a4UCgPn9VsMzlt931q
4dsaiBJATsV7cTu6pPw9XoHHJSZBGVLUOuIAbeq9XTjBmIZNYeJtBP0MfAxU0iDa
0wVAeopNWUYin/tvCnNjwDyOKLhILTv5dgWG/KDETO1Ax1YxjTq5NDhkdow66UA9
6Z2vJfSyqaqzFnY3yyKK+UNiRhJTvPOkxUjMuaxuYYu1qEbY4lFQvTeJpuZOcjuy
g7nwGZ5/eKSfcQpJmwqkhGdtaq5W9/1tElzoGO/nyZz3/iJtemADBdE651r0pnhh
RYv36SnuajJ0O1LGY7XAV1nKHWH/d2X3NVmPJIizZlijGKCZX3TQa6t052nSWiI/
mprJ2WZpFY61GGoWe4AZV+EJDku9xOi+sPJg+t8v3D0Jw9DOydG4Askiz6QROyjb
xKLzwcXmjzfz8EUL4a7zMT8lRNdhoFKktlJkT6PhJkSmG36n45qjKUrzTbq57jl8
71AvVdp1MM01+bRSkk02sU5Z0LxiNlwt/FexQNJZKgr0/D3EJGlTRpLOhATENns3
ins6fO8H6pbAK8Ifcn5+CuG5Kt/OJW8HV2xkmVnQldjUcQh6mTXxwI0BaOUQBogx
Q1TgyXuWaYjWTTDYyeuVhJEUdtk+G2T4tsj/iuShWkFqJSoyCXQ=
=P4zl
-----END PGP SIGNATURE-----

--nextPart2531705.bDOn7JOVgO--





--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID: <6612379.O1aUxXEVJ6@ravel>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!weretis.net!feeder8.news.weretis.net!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail
References: <avRQ4kbiSw-xbhzU@kib.kiev.ua> <>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!weretis.net!feeder8.news.weretis.net!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: Olivier Certner <olce@freebsd.org>
Newsgroups: muc.lists.freebsd.current
Subject: Re: ULE: run queue lock deadlock in sched_switch_migrate() + tdq_move()
Date: Wed, 11 Nov 2026 13:48:56 +0100
Organization: Newsgate at muc.de e.V.
Approved: news-admin@muc.de
Distribution: world
Message-ID: <6612379.O1aUxXEVJ6@ravel>
References: <avRQ4kbiSw-xbhzU@kib.kiev.ua> <>
MIME-Version: 1.0
Content-Type: multipart/signed; boundary="nextPart2531705.bDOn7JOVgO";
 micalg="pgp-sha384"; protocol="application/pgp-signature"
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
	logging-data="29096"; mail-complaints-to="news-admin@muc.de"
X-Original-To: current@mlmmj.nyi.freebsd.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1794401346;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 in-reply-to:in-reply-to:references:references;
	bh=swQmY40jtir6jvpD7ewGTZ48QgeCHsdgFrOYyOobBcs=;
	b=e71WutQmC2wI3ckJ2Pl3F2f24b/iQPKk5EIfCG4KRmsbwmbn5bHnfv5RbPyz4Cl2ZFChn/
	cgllGZ+sjoZgnFPaV2oxAnXXrfcBgC4txlrGVXUYLJgdHOMgFfdHymsD1WyVokUDj3ebT4
	jT5l6AZ+exhOFWbGIS4vo87CUu1PJ5FcusxXqYj2chkLeSYNYYqrnS1johLXWcUfHyn9pf
	gY0Kk8myUitlYwkKLIEEe46NscH9Eg6n+rr+1fXkmcMDKrALxAqR4kqxftrFC3LdTuQkmC
	X0XobeBzoH2zJqVaRSbbPyVZQi8HLdEeqSqKa2N7r179//lS9nvn514Gs6dJIA==
In-Reply-To: <avRQ4kbiSw-xbhzU@kib.kiev.ua>
Precedence: list
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes