Page MenuHomeFreeBSD

pci: Don't try to read cfg registers of non-existing devices
ClosedPublic

Authored by kd on Nov 19 2021, 7:54 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jan 25, 7:34 PM
Unknown Object (File)
Sat, Jan 18, 9:22 PM
Unknown Object (File)
Dec 25 2024, 2:49 AM
Unknown Object (File)
Dec 5 2024, 1:06 AM
Unknown Object (File)
Oct 28 2024, 2:07 AM
Unknown Object (File)
Oct 9 2024, 12:33 AM
Unknown Object (File)
Sep 30 2024, 6:38 AM
Unknown Object (File)
Sep 29 2024, 12:35 AM
Subscribers
None

Details

Summary

Instead of returning 0xffs some controllers, such as Layerscape generate an external exception when someone attempts to read any register of config space of a non-existing device other than PCIR_VENDOR.
This causes a kernel panic.
Fix it by bailing during device enumeration if a device vendor register returns invalid value. (0xffff)
Use this opportunity to replace some hardcoded values with a macro.

I believe that this change won't have any unintended side-effects since it is safe to assume that if vendor == 0xffff -> hdr_type == 0xffff,
which means that we won't accidentally skip enumerating a slot.

Diff Detail

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

Event Timeline

kd requested review of this revision.Nov 19 2021, 7:54 AM
kd created this revision.

Huh, interesting that the newer code (rescan) DTRT.

sys/dev/pci/pci.c
686

While this is fine, we should arguably assert that this never happens as I think we should be catching this case in all the callers? Hmm, I guess we expose this for use by CardBus, so perhaps it is best left as you have changed it. I would be happy if we could check all the callers and assert here instead though, perhaps as a followup.

4145–4147

Just add a blank line before the new comment.

This revision is now accepted and ready to land.Nov 22 2021, 5:58 PM