Received: from eggs.gnu.org ([2001:4830:134:3::10]:60074) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4Yi0-00027I-CP for qemu-devel@nongnu.org; Wed, 09 Nov 2016 14:38:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c4Yhv-0001Cd-FH for qemu-devel@nongnu.org; Wed, 09 Nov 2016 14:38:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52068) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c4Yhv-0001CZ-A5 for qemu-devel@nongnu.org; Wed, 09 Nov 2016 14:38:51 -0500 Date: Wed, 9 Nov 2016 12:38:49 -0700 From: Alex Williamson Message-ID: <20161109123849.6de6a693@t450s.home> In-Reply-To: <46a04f3ac5b60b26d2eff291e30747cd2c591233.1478712729.git.daniel.oram@gmail.com> References: <46a04f3ac5b60b26d2eff291e30747cd2c591233.1478712729.git.daniel.oram@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/1] Fix assert when get default PCI address property used by vfio-pci List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Daniel Oram Cc: qemu-devel@nongnu.org, Auger Eric , Markus Armbruster , Eric Blake , ehabkost@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com On Wed, 9 Nov 2016 18:36:20 +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. > nit, wrap your commit log at ~70 chars > Signed-off-by: Daniel Oram > --- > hw/core/qdev-properties.c | 18 +++++++++++++----- > 1 file changed, 13 insertions(+), 5 deletions(-) > > 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); > } Works for me, note that slot and function are actually 5 bits and 3 bits respectively, so an address ending in "ff.f" can easily be recognized as invalid to the user, the highest actual address would be "ffff:ff:1f.7". Reviewed-by: Alex Williamson Can anyone take this for 2.8? Thanks, Alex