Bug 283027 - LinuxKPI PCI -- kernel panic: malloc(M_WAITOK) with sleeping prohibited
Summary: LinuxKPI PCI -- kernel panic: malloc(M_WAITOK) with sleeping prohibited
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 15.0-CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Bjoern A. Zeeb
URL:
Keywords: crash
Depends on:
Blocks: 802.11, LinuxKPI, linuxkpi_wlan
  Show dependency tree / graph
 
Reported: 2024-11-28 17:35 UTC by devnull
Modified: 2026-01-16 19:59 UTC (History)
5 users (show)

See Also:
bz: mfc-stable14+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description devnull freebsd_committer freebsd_triage 2024-11-28 17:35:21 UTC
From bug 283015 comment 2 for the iwlwifi kernel panic with GENERIC-NODEBUG: 

> … I can boot GENERIC and then aim to reproduce the panic …

With GENERIC, I encountered a different panic when the OS woke from sleep: 


root@mowa219-gjp4-zbook-freebsd:/var/crash # su grahamperrin
% ls -hlnrt /var/crash | tail -n 7
-rw-r--r--  1 0 0  954K Nov 27 10:15 core.txt.10
-rw-r--r--  1 0 0    3B Nov 28 09:52 bounds
-rw-------  1 0 0  444B Nov 28 09:52 info.11
-rw-------  1 0 0  2.7G Nov 28 09:53 vmcore.11
lrwxr-xr-x  1 0 0    7B Nov 28 09:53 info.last -> info.11
lrwxr-xr-x  1 0 0    9B Nov 28 09:53 vmcore.last -> vmcore.11
-rw-r--r--  1 0 0  690K Nov 28 09:53 core.txt.11
% uname -abvKU
FreeBSD mowa219-gjp4-zbook-freebsd 15.0-CURRENT FreeBSD 15.0-CURRENT main-n273894-45d108ee147c GENERIC amd64 1500028 1500028 279c10d4900a60aac40d63a41d483479870f3144
% grep -B 4 -A 1 ifconfig_wlan1 /etc/rc.conf

wlans_iwlwifi0="wlan1"
create_args_wlan1="wlanmode sta country GB regdomain etsi"
# create_args_wlan1="country GB regdomain etsi"
ifconfig_wlan1="WPA DHCP"

% exit
exit
root@mowa219-gjp4-zbook-freebsd:/var/crash # cat info.11
Dump header from device: /dev/ada1p2
  Architecture: amd64
  Architecture Version: 2
  Dump Length: 2880442368
  Blocksize: 512
  Compression: none
  Dumptime: 2024-11-28 09:45:01 +0000
  Hostname: mowa219-gjp4-zbook-freebsd
  Magic: FreeBSD Kernel Dump
  Version String: FreeBSD 15.0-CURRENT main-n273894-45d108ee147c GENERIC
  Panic String: malloc(M_WAITOK) with sleeping prohibited
  Dump Parity: 2687204117
  Bounds: 11
  Dump Status: good
root@mowa219-gjp4-zbook-freebsd:/var/crash # 


base 45d108ee147cc8776a659578da585b31a0ba5643 (2024-11-27 14:30:52 +0000) at the time of the panic.

I did not take a photograph. If I recall correctly, the screen froze with a (red) arrow pointer on a dark/blank background before the lock screen appeared. The pointer that I normally see with Plasma.

Re: <https://old.reddit.com/r/freebsd/comments/1go058m/debugacpiresume_beep_beep_the_speaker_on_resume/lxk6pg0/>, in bug 283015 and in this bug there was silence (no debug beep).
Comment 1 Mark Johnston freebsd_committer freebsd_triage 2024-11-29 16:27:39 UTC
When reporting a kernel panic, please attach the corresponding core.txt file.  Alternately, paste the stack trace from that file, as was done in bug 282878 for example.  Otherwise it's impossible to see where the kernel crashed.
Comment 2 devnull freebsd_committer freebsd_triage 2024-11-30 01:54:37 UTC
Thank you, 

(In reply to Mark Johnston from comment #1)

> … please attach the corresponding core.txt file.  Alternately, paste 
> the stack trace …

I have not yet examined the file, in detail, to tell how much should be removed before publication. 

At a glance: at one of the stack backtraces should be OK, however (off-topic from this particular bug report) I'd like to understand and interpret things more thoroughly before disclosure. 

<https://tinyurl.com/backtrace-content>

In the meantime, from what's below I assume that iwlwifi(4) is a factor. 

…
panic: malloc(M_WAITOK) with sleeping prohibited
cpuid = 0
time = 1732787101
KDB: stack backtrace:
db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame ⋯
vpanic() at vpanic+0x136/frame ⋯
panic() at panic+0x43/frame ⋯
malloc_dbg() at malloc_dbg+0xc2/frame ⋯
malloc() at malloc+0x2c/frame ⋯
lkpinew_pci_dev() at lkpinew_pci_dev+0x20/frame ⋯
iwl_trans_pcie_dump_regs() at iwl_trans_pcie_dump_regs+0x5c8/frame ⋯
__iwl_trans_pcie_grab_nic_access() at __iwl_trans_pcie_grab_nic_access+0xfd/frame ⋯
iwl_trans_pcie_grab_nic_access() at iwl_trans_pcie_grab_nic_access+0x16/frame ⋯
iwl_read_prph() at iwl_read_prph+0x12/frame ⋯
iwl_txq_log_scd_error() at iwl_txq_log_scd_error+0x8c/frame ⋯
iwl_txq_stuck_timer() at iwl_txq_stuck_timer+0x95/frame ⋯
softclock_call_cc() at softclock_call_cc+0x19b/frame ⋯
softclock_thread() at softclock_thread+0xc6/frame ⋯
fork_exit() at fork_exit+0x82/frame ⋯
fork_trampoline() at fork_trampoline+0xe/frame ⋯
--- trap 0, rip = 0, rsp = 0, rbp = 0 ---
KDB: enter: panic
…
Comment 3 Bjoern A. Zeeb freebsd_committer freebsd_triage 2024-11-30 23:47:26 UTC
How do you provoke this?  Still "on resume"?

Also please post the PCI IDs of the iwlwifi card please.
Comment 4 devnull freebsd_committer freebsd_triage 2024-12-01 09:40:41 UTC
Thank you, 

(In reply to Bjoern A. Zeeb from comment #3)

Yes, resume. 

Comment 0 mentioned: 

* the panic occurring when the OS woke from sleep

* the silence (no debug beep). 

There would have been a simple press of the power button either on the computer (HP ZBook 17 G2) or its HP dock (to which three L2ARC devices were connected, if that's relevant). I most often use the button on the computer, not on the dock.

From the time of the dump (09:45), I'm fairly certain that the wake was at work, after sleeping the OS at home. 

Bug 283015 comment 1 has the result of a probe for the same computer. 

8086:08b1:8086:c060 is at <https://bsd-hardware.info/?probe=c8d95da1f8#pci:8086-08b1-8086-c060>.

HTH

For now, I reverted to iwm(4), mostly because I must avoid disruptions such as kernel panics during working hours. 

Less selfishly, iwlwifi(4) _is_ amongst my priorities for the community, so if you think that there'll be benefit from me reproducing the issue, I might aim to do so by travelling elsewhere.
Comment 5 John Baldwin freebsd_committer freebsd_triage 2024-12-06 18:06:03 UTC
We can't allocate a new PCI device on the fly here from a callout.  The new PCI device being allocated is probably for the parent PCI-e root port which iwl_trans_pcie_dump_regs() tries to access here:

	/* Print parent device registers next */
	if (!pdev->bus->self)
		goto out;

	pdev = pdev->bus->self;

I think structurally what should be happening is that instead of allocating the LinuxKPI shim device for the PCI bridge on the fly, we should allocate LinuxKPI shim devices for the full PCI hierarchy down to any device while it is attached to a LinuxKPI driver.
Comment 6 Bjoern A. Zeeb freebsd_committer freebsd_triage 2024-12-07 01:57:27 UTC
(In reply to John Baldwin from comment #5)

While that (LinuxKPI PCI tree alloc) is probably true the problem here is that suspend/resume is not supported as such yet for iwlwifi and this is a secondary issue given we should probably never hit that code path.

I adding the see-also;  the wifi device needs to be gone before suspend (that's essentially what net80211 would do just without fully driving state for LinuxKPI to my memory and we need to handle it there too).
Comment 7 Bjoern A. Zeeb freebsd_committer freebsd_triage 2025-03-13 23:38:23 UTC
(In reply to John Baldwin from comment #5)

I've hit this problem now on an iwlwifi 9xxx card in a different context;  I'll have a look at this.

The bridge we already deal with btw.  It's indeed the root port it goes to a few lines later:

        /* Print root port AER registers */
        pos = 0;
        pdev = pcie_find_root_port(pdev);


I'll re-title the problem to LinuxKPI as the problem itself has nothing to do with wireless per-se and move the Block up the tree a bit (though that still is wireless and not LinuxKPI but at least it is closer to the truth).
Comment 8 Bjoern A. Zeeb freebsd_committer freebsd_triage 2025-08-24 07:27:59 UTC
There is a patch for this in https://reviews.freebsd.org/D52069 which needs review.
Comment 9 commit-hook freebsd_committer freebsd_triage 2025-09-05 23:29:18 UTC
A commit in branch main references this bug:

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

commit bbeeb585315645db20118ef349a4e3dc83b148cc
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2025-09-04 20:22:00 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2025-09-05 23:24:14 +0000

    LinuxKPI: pci: allocate entire pci_dev hiereachy up to root port on attach

    In linux_pci_attach_device() allocate a LinuxKPI pci_dev for each device in
    the hierarchy up to the root port[1] as we cannot do that later on demand
    as we may be in a context where we may not sleep.

    Take special care of DRM as there is a non-PCI device in the chain which
    needs to be skipped.

    iwlwifi(4) can hit this case called from a callout.

    While here leave a comment sa the cleanup order of
    linux_pci_attach_device() needs correction seperately.

    Sponsored by:   The FreeBSD Foundation (initially)
    PR:             283027
    Suggested by:   jhb [1]
    MFC after:      3 days
    Reviewed by:    dumbbell
    Differential Revision:  https://reviews.freebsd.org/D52069

 sys/compat/linuxkpi/common/src/linux_pci.c | 47 +++++++++++++++++++++++++-----
 1 file changed, 40 insertions(+), 7 deletions(-)
Comment 10 commit-hook freebsd_committer freebsd_triage 2025-09-29 23:17:55 UTC
A commit in branch main references this bug:

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

commit 123c2dc6e15a62ceba3469caf0f1a6801214a7d3
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2025-09-29 21:29:17 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2025-09-29 23:16:18 +0000

    Reapply "LinuxKPI: pci: allocate entire pci_dev hiereachy up to root port on attach"

    In linux_pci_attach_device() allocate a LinuxKPI pci_dev for each device in
    the hierarchy up to the root port[1] as we cannot do that later on demand
    as we may be in a context where we may not sleep.

    Take special care of DRM as there is a non-PCI device in the chain which
    needs to be skipped.

    iwlwifi(4) can hit this case called from a callout.

    While here leave a comment sa the cleanup order of
    linux_pci_attach_device() needs correction seperately.

    This reverts commit 3860afe99ec39b9942967941181f28f27f3fc548.

    Sponsored by:   The FreeBSD Foundation (initially)
    PR:             283027
    PR:             289647
    Suggested by:   jhb [1]
    MFC after:      3 days
    Reviewed by:    dumbbell
    Differential Revision:  https://reviews.freebsd.org/D52069

 sys/compat/linuxkpi/common/src/linux_pci.c | 47 +++++++++++++++++++++++++-----
 1 file changed, 40 insertions(+), 7 deletions(-)
Comment 11 commit-hook freebsd_committer freebsd_triage 2025-09-30 22:21:54 UTC
A commit in branch stable/15 references this bug:

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

commit d8972ad2f6e7113d779d4ec975ce32552030b2a3
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2025-09-04 20:22:00 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2025-09-30 21:45:28 +0000

    LinuxKPI: pci: allocate entire pci_dev hiereachy up to root port on attach

    In linux_pci_attach_device() allocate a LinuxKPI pci_dev for each device in
    the hierarchy up to the root port[1] as we cannot do that later on demand
    as we may be in a context where we may not sleep.

    Take special care of DRM as there is a non-PCI device in the chain which
    needs to be skipped.

    iwlwifi(4) can hit this case called from a callout.

    While here leave a comment as the cleanup order of
    linux_pci_attach_device() needs correction seperately.

    Sponsored by:   The FreeBSD Foundation (initially)
    PR:             283027
    PR:             289647
    Suggested by:   jhb [1]
    Reviewed by:    dumbbell
    Differential Revision:  https://reviews.freebsd.org/D52069

    (cherry picked from commit bbeeb585315645db20118ef349a4e3dc83b148cc)
    (cherry picked from commit 3860afe99ec39b9942967941181f28f27f3fc548)
    (cherry picked from commit 123c2dc6e15a62ceba3469caf0f1a6801214a7d3)

 sys/compat/linuxkpi/common/src/linux_pci.c | 47 +++++++++++++++++++++++++-----
 1 file changed, 40 insertions(+), 7 deletions(-)
Comment 12 commit-hook freebsd_committer freebsd_triage 2026-01-16 19:42:31 UTC
A commit in branch stable/14 references this bug:

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

commit 2f4700c4dc1598c1b99996412a932764d5cbac45
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2025-09-04 20:22:00 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2026-01-16 19:37:50 +0000

    LinuxKPI: pci: allocate entire pci_dev hiereachy up to root port on attach

    In linux_pci_attach_device() allocate a LinuxKPI pci_dev for each device in
    the hierarchy up to the root port[1] as we cannot do that later on demand
    as we may be in a context where we may not sleep.

    Take special care of DRM as there is a non-PCI device in the chain which
    needs to be skipped.

    iwlwifi(4) can hit this case called from a callout.

    While here leave a comment as the cleanup order of
    linux_pci_attach_device() needs correction seperately.

    Sponsored by:   The FreeBSD Foundation (initially)
    PR:             283027
    PR:             289647
    Suggested by:   jhb [1]
    Reviewed by:    dumbbell
    Differential Revision:  https://reviews.freebsd.org/D52069

    (cherry picked from commit bbeeb585315645db20118ef349a4e3dc83b148cc)
    (cherry picked from commit 3860afe99ec39b9942967941181f28f27f3fc548)
    (cherry picked from commit 123c2dc6e15a62ceba3469caf0f1a6801214a7d3)
    (cherry picked from commit d8972ad2f6e7113d779d4ec975ce32552030b2a3)

 sys/compat/linuxkpi/common/src/linux_pci.c | 47 +++++++++++++++++++++++++-----
 1 file changed, 40 insertions(+), 7 deletions(-)
Comment 13 Bjoern A. Zeeb freebsd_committer freebsd_triage 2026-01-16 19:59:51 UTC
This should be fixed in all relevant branches.
If it still happens after the MFC dates, please re-open.