Page MenuHomeFreeBSD

Reliably return PCI_GETCONF_LAST_DEVICE from PCIOCGETCONF.
ClosedPublic

Authored by jhb on Aug 8 2016, 9:04 PM.

Details

Summary

Reliably return PCI_GETCONF_LAST_DEVICE from PCIOCGETCONF.

Previously the loop in PCIIOCGETCONF would terminate as soon as it
found enough matches. Now it will continue iterating through the
PCI device list and only terminate if it finds another matching device
for which it has no room to store a conf structure. This means that
PCI_GETCONF_LAST_DEVICE is reliably returned when the number of
matching devices is equal to the number of slots in the matches
buffer. For example, if a program requests the conf structure for a
single PCI function with a specified domain/bus/slot/function it will
now get PCI_GETCONF_LAST_DEVICE instead of PCI_GETCONF_MORE_DEVS.

While here, simplify the loop conditional a bit more by explicitly
breaking out of the loop if copyout() fails and removing a redundant
i < pci_numdevs check.

Test Plan
  • Invoke PCIOCGETCONF with a pattern to match a single PCI function and a matches buffer with 1 conf structure.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

jhb retitled this revision from to Reliably return PCI_GETCONF_LAST_DEVICE from PCIOCGETCONF..
jhb updated this object.
jhb edited the test plan for this revision. (Show Details)
jhb added a reviewer: imp.

So it does look like we document the current behavior. I suppose in theory code could decide to accept the MORE_DEVS and not do a followup call to verify it got LAST_DEVICE with a match count of 0 to avoid having to walk to the end of the list. However, that seems a bit sloppy to me. I think these semantics make more sense.

This revision is now accepted and ready to land.Aug 9 2016, 2:25 PM
imp edited edge metadata.
This revision was automatically updated to reflect the committed changes.