Bug 289204 - Numa with 4 domains often fails to boot (zfs related)
Summary: Numa with 4 domains often fails to boot (zfs related)
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 14.3-RELEASE
Hardware: amd64 Any
: --- Affects Only Me
Assignee: Konstantin Belousov
URL:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2025-08-31 07:59 UTC by Peter Much
Modified: 2025-09-16 13:35 UTC (History)
3 users (show)

See Also:
linimon: mfc-stable15?
linimon: mfc-stable14?


Attachments
procstat -kka (846.40 KB, text/plain)
2025-09-05 21:41 UTC, Peter Much
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Much 2025-08-31 07:59:55 UTC
The system gets stuck after starting multiuser boot.

The cause in /etc/rc.d/zpool when invoking
"zpool import -c <cachefile> -a -N":
zpool doesn't return and doesn't compute.

procstat -kk shows this stack for that zpool process:

mi_switch+0xc3 _sleep+0x205 g_waitidle+0x7c ast_handler+0x8b
thread_dtor+0x24 uma_zfree_arg+0x1f0 thread_reap_domain+0x265
thread_count_inc+0x24 thread_alloc+0x16 kthread_add+0xb1
kproc_kthread_add+0xb5 zvol_os_create_minor+0x278
zvol_create_minors_recursive+0xe6 spa_import+0x692
zfs_ioc_pool_import+0xb3 zfsdev_ioctl_common+0x567 zfsdev_ioctl+0x12b
devfs_ioctl+0xd1

When manually importing the pools one by one, the problem happens at
about every 10th pool (there are more than ten here), apparently randomly.

This is 14.3-RELEASE with zpool 2.2.7
Similar never happened with any 13.x release.

Also it does not happen with 2 or none numa domains: these boot okay.

Machine is ASUS Z10PA-D8 with two E5-2660-v3 chips.
The machine runs in Cluster-on-Die mode to separately utilize
the two memory controllers of the E5-2660 v3; this gets presented
to the OS as separate Numa domains, which makes a total of four.
Comment 1 Mark Johnston freebsd_committer freebsd_triage 2025-09-05 16:50:05 UTC
Are you able to obtain `procstat -kka` output for the whole system when it hangs like this?
Comment 2 Peter Much 2025-09-05 21:41:12 UTC
Created attachment 263539 [details]
procstat -kka
Comment 3 Mark Johnston freebsd_committer freebsd_triage 2025-09-07 16:11:47 UTC
Hmm, so we have:

  163 115114 zpool               -                   mi_switch+0xc3 _sleep+0x205 g_waitidle+0x7c ast_handler+0x8b thread_dtor+0x24 uma_zfree_arg+0x1f0 thread_reap_domain+0x265 thread_count_inc+0x24 thread_alloc+0x16 kthread_add+0xb1 kproc_kthread_add+0xb5 zvol_os_create_minor+0x278 zvol_create_minors_recursive+0xe6 spa_import+0x692 zfs_ioc_pool_import+0xb3 zfsdev_ioctl_common+0x567 zfsdev_ioctl+0x12b devfs_ioctl+0xd1 

and

   13 100264 geom                g_event             mi_switch+0xc3 _sx_xlock_hard+0x4ef g_run_events+0x86 fork_exit+0x86 fork_trampoline+0xe 

so it seems we have a deadlock since something is calling g_waitidle() with the GEOM topology lock held.
Comment 4 Mark Johnston freebsd_committer freebsd_triage 2025-09-07 16:18:55 UTC
The TDA_GEOM event sets ASTR_KCLEAR so ast_kclear() will potentially invoke g_waitidle(), but this is not safe in arbitrary contexts.  Is this a regression from commit c6d31b8306eb7?  I am not sure why it is necessary to set ASTR_KCLEAR there.  Prior to that commit we did not call g_waitidle() when tearing down a thread; only the UFS softdep AST cleanup was done.
Comment 5 Konstantin Belousov freebsd_committer freebsd_triage 2025-09-08 03:45:37 UTC
(In reply to Mark Johnston from comment #4)
Not clearing TDP_GEOM from the exiting thread is arguably the bug.
Why should a code be allowed to trigger event and then forget about it
if the thread is exiting, but forced to wait for idle if thread is returning
to userspace?  It is rather arbitrary.

Might be the wait for idle should occur earlier, indeed.  I think it must
happen in the running context of the thread before it is no longer runnable
due to exit.

https://reviews.freebsd.org/D52421
Comment 6 Mark Johnston freebsd_committer freebsd_triage 2025-09-08 12:58:45 UTC
(In reply to Konstantin Belousov from comment #5)
Suppose the thread created some GEOM, and there is some asynchronous initialization path which creates /dev/foo etc. for the new GEOM.  Then we want that initialization to finish before further system calls are executed, to avoid races.  For kernel threads this is not really a problem, so perhaps we should only schedule the AST for user threads.

Peter, are you able to test the patch? https://reviews.freebsd.org/D52421
Comment 7 Mark Johnston freebsd_committer freebsd_triage 2025-09-08 13:02:02 UTC
(In reply to Mark Johnston from comment #6)
Oh, I'm not sure if this patch will fix the deadlock.  Suppose some kernel-only thread has TDP_GEOM set and then exited.  The patch will not clear the corresponding AST, kern_thr_exit() is used only by user threads I believe.

Might be, TDA_GEOM simply doesn't need ASTR_KCLEAR set?
Comment 8 Konstantin Belousov freebsd_committer freebsd_triage 2025-09-08 13:45:47 UTC
(In reply to Mark Johnston from comment #7)
If a kernel thread sets TDP_GEOM and does not exit, there is absolutely no
mechanism that an AST handler is called for it at all.

Instead of adding some call to wait for ast in kthread exit path, I think
we should avoid setting TDP_GEOM for kthread at all.
Comment 9 commit-hook freebsd_committer freebsd_triage 2025-09-09 03:07:04 UTC
A commit in branch main references this bug:

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

commit b0474e14895908f45c64158b0e558236923b8eb2
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-09-08 13:46:08 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-09-09 02:51:08 +0000

    geom: only set TDP_GEOM for user threads

    For kernel threads, ASTs are not handled at all, so there is no reason
    to expect that g_waitidle() would be called through AST scheduling.

    PR:     289204
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D52421

 sys/geom/geom_event.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Comment 10 commit-hook freebsd_committer freebsd_triage 2025-09-09 03:07:10 UTC
A commit in branch main references this bug:

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

commit f51d7d5139a76d225c9f537bd948525ababdef0c
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-09-08 03:43:09 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-09-09 02:51:08 +0000

    kern_thr_exit(): clear kASTs in advance

    PR:     289204
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D52421

 sys/kern/kern_thr.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
Comment 11 Peter Much 2025-09-12 14:57:26 UTC
Sorry for the delayed reaction; I was on travel.

Patch from comment #9 solves my issue.

Cordial thanks for the quick help!
Comment 12 commit-hook freebsd_committer freebsd_triage 2025-09-16 02:50:30 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=1234bd1b7213c253ad7730ee2cef642d0aab234e

commit 1234bd1b7213c253ad7730ee2cef642d0aab234e
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-09-08 13:46:08 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-09-16 02:45:12 +0000

    geom: only set TDP_GEOM for user threads

    PR:     289204

    (cherry picked from commit b0474e14895908f45c64158b0e558236923b8eb2)

 sys/geom/geom_event.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Comment 13 commit-hook freebsd_committer freebsd_triage 2025-09-16 02:50:32 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=7140a4790cbc6c897673276299a1bc3ad63dc3f8

commit 7140a4790cbc6c897673276299a1bc3ad63dc3f8
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-09-08 03:43:09 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-09-16 02:45:12 +0000

    kern_thr_exit(): clear kASTs in advance

    PR:     289204

    (cherry picked from commit f51d7d5139a76d225c9f537bd948525ababdef0c)

 sys/kern/kern_thr.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
Comment 14 commit-hook freebsd_committer freebsd_triage 2025-09-16 02:51:34 UTC
A commit in branch stable/14 references this bug:

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

commit a1dcf2fc8f327c5d492278f14c07380b7170fc68
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-09-08 13:46:08 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-09-16 02:44:24 +0000

    geom: only set TDP_GEOM for user threads

    PR:     289204

    (cherry picked from commit b0474e14895908f45c64158b0e558236923b8eb2)

 sys/geom/geom_event.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Comment 15 commit-hook freebsd_committer freebsd_triage 2025-09-16 02:51:36 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=594982a69714150ccf8616ffbce65fecab70ec03

commit 594982a69714150ccf8616ffbce65fecab70ec03
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-09-08 03:43:09 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-09-16 02:44:24 +0000

    kern_thr_exit(): clear kASTs in advance

    PR:     289204

    (cherry picked from commit f51d7d5139a76d225c9f537bd948525ababdef0c)

 sys/kern/kern_thr.c | 11 +++++++++++
 1 file changed, 11 insertions(+)