[libvirt] [PATCH] pciSharesBusWithActive fails to find multiple devices on bus

The first conditional is always true which means the iterator will never find another device on the same bus. if (dev->domain != check->domain || dev->bus != check->bus || ----> (check->slot == check->slot && check->function == check->function)) <----- The goal of that check is to verify that the device is either: in a different pci domain on a different bus is the same identical device This means libvirt may issue a secondary bus reset when there are devices on that bus that actively in use by the host or another guest. Not good. Fix the typo. Cc: Alex Williamson <alex.williamson@redhat.com> Cc: Don Dutile <ddutile@redhat.com> Cc: Chris Lalancette <clalance@redhat.com> Signed-off-by: Chris Wright <chrisw@redhat.com> --- src/util/pci.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util/pci.c b/src/util/pci.c index b2e1673..6d0ca24 100644 --- a/src/util/pci.c +++ b/src/util/pci.c @@ -446,10 +446,11 @@ pciSharesBusWithActive(pciDevice *dev, pciDevice *check, void *data) { pciDeviceList *activeDevs = data; + /* Different domain, different bus, or simply identical device */ if (dev->domain != check->domain || dev->bus != check->bus || - (check->slot == check->slot && - check->function == check->function)) + (dev->slot == check->slot && + dev->function == check->function)) return 0; if (activeDevs && !pciDeviceListFind(activeDevs, check))

On 07/22/2010 05:01 PM, Chris Wright wrote:
The first conditional is always true which means the iterator will never find another device on the same bus.
if (dev->domain != check->domain || dev->bus != check->bus || ----> (check->slot == check->slot && check->function == check->function)) <-----
Ouch. ACK to the patch. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On Thu, Jul 22, 2010 at 05:17:35PM -0600, Eric Blake wrote:
On 07/22/2010 05:01 PM, Chris Wright wrote:
The first conditional is always true which means the iterator will never find another device on the same bus.
if (dev->domain != check->domain || dev->bus != check->bus || ----> (check->slot == check->slot && check->function == check->function)) <-----
Ouch. ACK to the patch.
Hmm, GCC should have warned about this if we had -Wlogical-op in our flags -Wlogical-op Warn when a logical operator is suspicously always evaluating to true or false Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Thu, Jul 22, 2010 at 04:01:53PM -0700, Chris Wright wrote:
The first conditional is always true which means the iterator will never find another device on the same bus.
if (dev->domain != check->domain || dev->bus != check->bus || ----> (check->slot == check->slot && check->function == check->function)) <-----
The goal of that check is to verify that the device is either:
in a different pci domain on a different bus is the same identical device
This means libvirt may issue a secondary bus reset when there are devices on that bus that actively in use by the host or another guest. Not good. Fix the typo.
Oops ! Good catch, pushed, thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/
participants (4)
-
Chris Wright
-
Daniel P. Berrange
-
Daniel Veillard
-
Eric Blake