[libvirt] [PATCH] Force FLR on for buggy SR-IOV devices.

Some buggy PCI devices actually support FLR, but forget to advertise that fact in their PCI config space. However, Virtual Functions on SR-IOV devices are *required* to support FLR by the spec, so force has_flr on if this is a virtual function. Signed-off-by: Chris Lalancette <clalance@redhat.com> --- src/util/pci.c | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-) diff --git a/src/util/pci.c b/src/util/pci.c index c45b179..4bfad2c 100644 --- a/src/util/pci.c +++ b/src/util/pci.c @@ -385,6 +385,7 @@ pciDetectFunctionLevelReset(pciDevice *dev) { uint32_t caps; uint8_t pos; + char *path; /* The PCIe Function Level Reset capability allows * individual device functions to be reset without @@ -413,6 +414,27 @@ pciDetectFunctionLevelReset(pciDevice *dev) } } + /* there are some buggy devices that do support FLR, but forget to + * advertise that fact in their capabilities. However, FLR is *required* + * to be present for virtual functions (VFs), so if we see that this + * device is a VF, we just assume FLR works + */ + + if (virAsprintf(&path, PCI_SYSFS "devices/%s/physfn", dev->name) < 0) { + VIR_ERROR("Failed to allocate memory when checking FLR for device %s", + dev->id); + return 0; + } + + if (virFileExists(path)) { + VIR_FREE(path); + VIR_DEBUG("%s %s: buggy device didn't advertise FLR, but is a VF; forcing flr on", + dev->id, dev->name); + return 1; + } + + VIR_FREE(path); + VIR_DEBUG("%s %s: no FLR capability found", dev->id, dev->name); return 0; -- 1.7.1.1

* Chris Lalancette (clalance@redhat.com) wrote:
Some buggy PCI devices actually support FLR, but forget to advertise that fact in their PCI config space. However, Virtual Functions on SR-IOV devices are *required* to support FLR by the spec, so force has_flr on if this is a virtual function.
Right, and if it's not entirely clear here...this allows the kernel to deal with device specific quirks.
Signed-off-by: Chris Lalancette <clalance@redhat.com>
Acked-by: Chris Wright <chrisw@redhat.com>

On 07/23/2010 01:21 PM, Chris Lalancette wrote:
Some buggy PCI devices actually support FLR, but forget to advertise that fact in their PCI config space. However, Virtual Functions on SR-IOV devices are *required* to support FLR by the spec, so force has_flr on if this is a virtual function.
+ + if (virAsprintf(&path, PCI_SYSFS "devices/%s/physfn", dev->name)< 0) {
Weird spacing around <
+ VIR_ERROR("Failed to allocate memory when checking FLR for device %s", + dev->id);
If this fails, it is likely that other code will run out of memory soon, too. Why not just call the standard git OOM handler here? -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 07/23/2010 09:34 PM, Eric Blake wrote:
+ if (virAsprintf(&path, PCI_SYSFS "devices/%s/physfn", dev->name)< 0) {
Weird spacing around <
No, instead you are suffering from https://bugzilla.mozilla.org/show_bug.cgi?id=571502 :( Paolo

On 07/23/10 - 01:34:23PM, Eric Blake wrote:
On 07/23/2010 01:21 PM, Chris Lalancette wrote:
Some buggy PCI devices actually support FLR, but forget to advertise that fact in their PCI config space. However, Virtual Functions on SR-IOV devices are *required* to support FLR by the spec, so force has_flr on if this is a virtual function.
+ + if (virAsprintf(&path, PCI_SYSFS "devices/%s/physfn", dev->name)< 0) {
Weird spacing around <
Yeah, I think Paolo is right, this might be a thunderbird bug. It looks OK in the original patch I sent.
+ VIR_ERROR("Failed to allocate memory when checking FLR for device %s", + dev->id);
If this fails, it is likely that other code will run out of memory soon, too. Why not just call the standard git OOM handler here?
I could go either way on this one. Up until now we only ever returned 0 or 1 from this function, but with the memory allocation, we can also have -1 (for failure). I guess I'll re-code it to return -1, and then I can use virOOMError here. Thanks for the review. -- Chris Lalancette
participants (4)
-
Chris Lalancette
-
Chris Wright
-
Eric Blake
-
Paolo Bonzini