Message ID | 71f06765c4ba16dcd71cbf78e877619948f04ed9.1478777270.git.daniel.oram@gmail.com |
---|---|
State | New |
Headers | show |
On Thu, Nov 10, 2016 at 12:42:07PM +0000, Daniel Oram wrote: > Allow the PCIHostDeviceAddress structure to work as the host property > in vfio-pci when it has it's default value of all fields set to ~0. In > this form the property indicates a non-existant device but given the > field bit sizes gets asserted as excess (and invalid) precision > overflows the string buffer. The BDF of an invalid device > "FFFF:FF:FF.F" is returned instead. > > Signed-off-by: Daniel Oram <daniel.oram@gmail.com> > Reviewed-by: Alex Williamson <alex.williamson@redhat.com> Applied to machine-next after removing trailing-spaces detected by checkpatch.pl. Thanks.
On Tue, 15 Nov 2016 16:01:52 -0200 Eduardo Habkost <ehabkost@redhat.com> wrote: > On Thu, Nov 10, 2016 at 12:42:07PM +0000, Daniel Oram wrote: > > Allow the PCIHostDeviceAddress structure to work as the host property > > in vfio-pci when it has it's default value of all fields set to ~0. In > > this form the property indicates a non-existant device but given the > > field bit sizes gets asserted as excess (and invalid) precision > > overflows the string buffer. The BDF of an invalid device > > "FFFF:FF:FF.F" is returned instead. > > > > Signed-off-by: Daniel Oram <daniel.oram@gmail.com> > > Reviewed-by: Alex Williamson <alex.williamson@redhat.com> > > Applied to machine-next after removing trailing-spaces detected > by checkpatch.pl. Thanks. Thanks for grabbing this, Eduardo. Alex
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 311af6d..ed0d5b0 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -705,13 +705,21 @@ static void get_pci_host_devaddr(Object *obj, Visitor *v, const char *name, DeviceState *dev = DEVICE(obj); Property *prop = opaque; PCIHostDeviceAddress *addr = qdev_get_prop_ptr(dev, prop); - char buffer[] = "xxxx:xx:xx.x"; + char buffer[] = "ffff:ff:ff.f"; char *p = buffer; int rc = 0; - - rc = snprintf(buffer, sizeof(buffer), "%04x:%02x:%02x.%d", - addr->domain, addr->bus, addr->slot, addr->function); - assert(rc == sizeof(buffer) - 1); + + /* + * Catch "invalid" device reference from vfio-pci and allow the + * default buffer representing the non-existant device to be used. + */ + if (~addr->domain || ~addr->bus || ~addr->slot || ~addr->function) { + + rc = snprintf(buffer, sizeof(buffer), "%04x:%02x:%02x.%0d", + addr->domain, addr->bus, addr->slot, addr->function); + assert(rc == sizeof(buffer) - 1); + } + visit_type_str(v, name, &p, errp); }