Bug 289184 - lock order reversal between tcphash (tcp_usrreq.c:1529) and in6_ifaddr_lock (in6_src.c:301)
Summary: lock order reversal between tcphash (tcp_usrreq.c:1529) and in6_ifaddr_lock (...
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 15.0-CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-net (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-08-30 11:11 UTC by Gordon Bergling
Modified: 2026-02-26 17:44 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gordon Bergling freebsd_committer freebsd_triage 2025-08-30 11:11:53 UTC
I see this lock order reversal since a while now on a 15.0-PRERELEASE. It happens immediately after boot.

lock order reversal:
 1st 0xfffffe00039d6a00 tcphash (tcphash, sleep mutex) @ /storage/freebsd/src/current/sys/netinet/tcp_usrreq.c:1529
 2nd 0xffffffff81edd1d0 in6_ifaddr_lock (in6_ifaddr_lock, rm) @ /storage/freebsd/src/current/sys/netinet6/in6_src.c:301
lock order tcphash -> in6_ifaddr_lock attempted at:
#0 0xffffffff80bff201 at witness_checkorder+0xbe1
#1 0xffffffff80b80f79 at _rm_rlock_debug+0x129
#2 0xffffffff80dd6fe7 at in6_selectsrc+0x447
#3 0xffffffff80dd6b51 at in6_selectsrc_socket+0x41
#4 0xffffffff80dd4641 at in6_pcbconnect+0x291
#5 0xffffffff80db7177 at tcp6_connect+0xb7
#6 0xffffffff80db4af5 at tcp6_usr_connect+0x2f5
#7 0xffffffff80c3fa80 at soconnectat+0xc0
#8 0xffffffff80c47cd1 at kern_connectat+0xe1
#9 0xffffffff80c47bc1 at sys_connect+0x81
#10 0xffffffff810daba1 at amd64_syscall+0x451
#11 0xffffffff810ac4bb at fast_syscall_common+0xf8

System is a virtual machine running under VMWare if that matters.
Comment 1 Jonathan T. Looney freebsd_committer freebsd_triage 2025-09-12 19:36:36 UTC
(In reply to Gordon Bergling from comment #0)
I can't reproduce that locally, but I think that lock order is correct.

Can you try running with the below patch? Hopefully, this will find the place where the other lock order is used.

diff --git a/sys/kern/subr_witness.c b/sys/kern/subr_witness.c
index a65c3ca128d9..047366679adb 100644
--- a/sys/kern/subr_witness.c
+++ b/sys/kern/subr_witness.c
@@ -566,6 +566,12 @@ static struct witness_order_list_entry order_lists[] = {
        { "tcp", &lock_class_mtx_sleep },
        { "so_snd", &lock_class_mtx_sleep },
        { NULL, NULL },
+       /*
+        * IPv6 Addr
+        */
+       { "tcphash", &lock_class_mtx_sleep },
+       { "in6_ifaddr_lock", &lock_class_rm },
+       { NULL, NULL },
        /*
         * BPF
         */
Comment 2 Gordon Bergling freebsd_committer freebsd_triage 2025-10-24 08:27:03 UTC
On a 16-CURRENt from today this LOR doesn't happened anymore. Can't say exactly when it was fixed, since I haven't looked at for a while.
Comment 3 Jonathan T. Looney freebsd_committer freebsd_triage 2025-12-06 19:54:48 UTC
bz@ just reproduced this (see https://lists.freebsd.org/archives/freebsd-net/2025-December/008045.html), so I am going to commit explicit lock ordering to try to catch the correct culprit.
Comment 4 commit-hook freebsd_committer freebsd_triage 2025-12-06 19:59:48 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=3f10e5985044001a68761995474f1100aca648e1

commit 3f10e5985044001a68761995474f1100aca648e1
Author:     Jonathan T. Looney <jtl@FreeBSD.org>
AuthorDate: 2025-12-05 17:34:31 +0000
Commit:     Jonathan T. Looney <jtl@FreeBSD.org>
CommitDate: 2025-12-06 19:58:46 +0000

    ip6: Add explicit lock order information to catch LOR

    Over the past several years, we have had sporadic reports of a lock
    order reversal between the tcphash lock and the in6_ifaddr_lock.
    These seems to be hard to reproduce reliably, and the WITNESS backtrace
    points to code which uses the correct locking order.

    This commit adds the correct lock order explicitly to help us detect
    the call stack which uses the incorrect locking order.

    PR:             289184
    Reported by:    bz, gbe
    Reviewed by:    bz, glebius
    Differential Revision:  https://reviews.freebsd.org/D54088

 sys/kern/subr_witness.c | 6 ++++++
 1 file changed, 6 insertions(+)
Comment 5 paul vixie 2025-12-28 21:34:41 UTC
similar LOR involving tcphash, 16-CURRENT as of this date (2025-12-28):

wlock order reversal:
 1st 0xfffff8000c4ed5e0 so_rcv (so_rcv, sleep mutex) @ /home/vixie/scratch/freebsd-src/sys/kern/uipc_socket.c:1429
 2nd 0xfffffe00c36cda10 tcphash (tcphash, sleep mutex) @ /home/vixie/scratch/freebsd-src/sys/netinet/tcp_usrreq.c:440
lock order so_rcv -> tcphash attempted at:
#0 0xffffffff80c0f23[Starting cron.]1 at witness_checkorder+0xbe1
#1 0xffffffff80b71011 at __mtx_lock_flags+0x91
#2 0xffffffff80dc555b at tcp6_usr_listen+0xfb
#3 0xffffffff80c4ec61 at solisten+0x41
#4 0xffffffff80c576ff at kern_listen+0x6f
#5 0xffffffff810f1a19 at amd64_syscall+0x169
#6 0xffffffff810c007b at fast_syscall_common+0xf8

it's happening at startup time, see the [Starting cron.] message which i placed brackets around. restarting cron doesn't re-trigger. nor restarting sshd which was started just prior.
Comment 6 Jonathan T. Looney freebsd_committer freebsd_triage 2026-01-12 18:42:00 UTC
(In reply to paul vixie from comment #5)
> similar LOR involving tcphash, 16-CURRENT as of this date (2025-12-28):

Thanks! Is this reliably reproducable?
Comment 7 Jonathan T. Looney freebsd_committer freebsd_triage 2026-01-12 19:11:43 UTC
(In reply to paul vixie from comment #5)

Also, if this does happen again, can you capture the output of "sysctl debug.witness.fullgraph"?

Thanks!
Comment 8 yuan.mei 2026-02-26 17:44:23 UTC
(In reply to Gordon Bergling from comment #0)
I also encountered this in 15-stable, and it is reliably reproducible.

+lock order reversal:
+ 1st 0xfffffe00c4489a00 tcphash (tcphash, sleep mutex) @ /usr/src/sys/netinet/tcp_usrreq.c:1529
+ 2nd 0xffffffff822e8ae0 in6_ifaddr_lock (in6_ifaddr_lock, rm) @ /usr/src/sys/netinet6/in6_src.c:293
+lock order tcphash -> in6_ifaddr_lock attempted at:
+#0 0xffffffff80c0eb21 at witness_checkorder+0xbe1
+#1 0xffffffff80b8dc79 at _rm_rlock_debug+0x129
+#2 0xffffffff80de61fd at in6_selectsrc+0x3fd
+#3 0xffffffff80de5d9d at in6_selectsrc_socket+0x6d
+#4 0xffffffff80de3861 at in6_pcbconnect+0x291
+#5 0xffffffff80dc6877 at tcp6_connect+0xb7
+#6 0xffffffff80dc41f5 at tcp6_usr_connect+0x2f5
+#7 0xffffffff80c4f500 at soconnectat+0xc0
+#8 0xffffffff80c577d1 at kern_connectat+0xe1
+#9 0xffffffff80c576c1 at sys_connect+0x81
+#10 0xffffffff810eb979 at amd64_syscall+0x169
+#11 0xffffffff810bd36b at fast_syscall_common+0xf8