Page MenuHomeFreeBSD

linuxkpi: Fix double-cleanup in linux_pci_attach_device() error path
ClosedPublic

Authored by slavash on Tue, Sep 22, 5:50 PM.
Tags
None
Referenced Files
F173741315: D59913.diff
Mon, Sep 28, 1:51 AM
F173714714: D59913.diff
Sun, Sep 27, 9:58 PM
F173685594: D59913.id187461.diff
Sun, Sep 27, 5:36 PM
Unknown Object (File)
Sun, Sep 27, 4:09 AM
Unknown Object (File)
Sat, Sep 26, 10:27 PM
Unknown Object (File)
Fri, Sep 25, 2:41 PM
Unknown Object (File)
Fri, Sep 25, 4:38 AM
Unknown Object (File)
Fri, Sep 25, 4:35 AM

Details

Summary

put_device() already triggers lkpi_pci_dev_release(), which removes
pdev from pci_devices, frees pdev->bus, destroys pcie_cap_lock, and
uninits the DMA private data.

Reported by: gallatin
Fixes: 66b25ddf9125 ("LinuxKPI: pci detach: implement a proper detach (release) path")
Sponsored by: NVidia networking
MFC after: 3 days

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Tue, Sep 22, 6:09 PM

I have a full stack up for review for ages for PCI.

What's left starts here and still needs review: https://reviews.freebsd.org/D57430

In D59913#1374986, @bz wrote:

I have a full stack up for review for ages for PCI.

What's left starts here and still needs review: https://reviews.freebsd.org/D57430

Bjoern, so any objections with committing Slava' change for now?

You should add something like:
Originally reported (and tested with D57430): Mark Millard <marklmi@yahoo.com> (current@ July 25 2026)

I guess the fixes line is correct for this one; I added the XXX comment a year ago when other trouble could happen already (and no one cared; like reviews sitting waiting around for months).

It's not "for now". The patch here (using just put_device() [again]) is the follow-up to the stack as indicated in the comment from the review I pointed at; but I never released the full the stack ("first round.." indicating there will be more to come); there was a reason I initially did it manually first; it's good documentation and helps finding inconsistencies; but I guess months later it doesn't matter anymore. I'll just be happy the problem will be gone and I can look into linux_firmware instead. I'll just drop my stuff. So please be my guest.

Oh, I wonder how you can trigger this from the semi-native driver? What was @gallatin 's error case?

In D59913#1375313, @bz wrote:

Oh, I wonder how you can trigger this from the semi-native driver? What was @gallatin 's error case?

My error case was a dead nic panic'ing a system on boot:
panic: page fault
cpuid = 31
time = 13
KDB: stack backtrace:
db_trace_self_wrapper() at db_trace_self_wrapper+0x36/frame 0xffffffff8312bb10
vpanic() at vpanic+0x149/frame 0xffffffff8312bc40
panic() at panic+0x43/frame 0xffffffff8312bca0
trap_pfault() at trap_pfault+0x3a8/frame 0xffffffff8312bd00
calltrap() at calltrap+0x8/frame 0xffffffff8312bd00

  • trap 0xc, rip = 0xffffffff80b0ef2e, rsp = 0xffffffff8312bdd0, rbp = 0xffffffff8312bdf0 ---

lkpi_pci_dev_release() at lkpi_pci_dev_release+0xde/frame 0xffffffff8312bdf0
linux_kobject_release() at linux_kobject_release+0x48/frame 0xffffffff8312be10
linux_pci_attach_device() at linux_pci_attach_device+0x397/frame 0xffffffff8312be70
device_attach() at device_attach+0x407/frame 0xffffffff8312bec0
pci_driver_added() at pci_driver_added+0x102/frame 0xffffffff8312bf10
devclass_driver_added() at devclass_driver_added+0x29/frame 0xffffffff8312bf40
devclass_add_driver() at devclass_add_driver+0x11e/frame 0xffffffff8312bf80
_linux_pci_register_driver() at _linux_pci_register_driver+0xcc/frame 0xffffffff8312bfb0
init() at init+0x12/frame 0xffffffff8312bfd0
mi_startup() at mi_startup+0xb5/frame 0xffffffff8312bff0
KDB: enter: panic
[ thread pid 0 tid 100000 ]
Stopped at kdb_enter+0x33: movq $0,0xecd002(%rip)
db>

This was reproduced and fix developed by introducing an artificial failure into the driver initialization path.