From: Alex Williamson <alex.williamson@redhat.com>
To: Daniel Oram <daniel.oram@gmail.com>
Cc: qemu-devel@nongnu.org, Auger Eric <eric.auger@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
Eric Blake <eblake@redhat.com>,
ehabkost@redhat.com, marcandre.lureau@redhat.com,
pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH 1/1] Fix assert when get default PCI address property used by vfio-pci
Date: Wed, 9 Nov 2016 12:38:49 -0700 [thread overview]
Message-ID: <20161109123849.6de6a693@t450s.home> (raw)
In-Reply-To: <46a04f3ac5b60b26d2eff291e30747cd2c591233.1478712729.git.daniel.oram@gmail.com>
On Wed, 9 Nov 2016 18:36:20 +0000
Daniel Oram <daniel.oram@gmail.com> 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 <daniel.oram@gmail.com>
> ---
> 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 <alex.williamson@redhat.com>
Can anyone take this for 2.8? Thanks,
Alex
prev parent reply other threads:[~2016-11-09 19:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-09 18:36 [Qemu-devel] [PATCH 0/1] vfio-pci: fix assert fail in host property if unused Daniel Oram
2016-11-09 18:36 ` [Qemu-devel] [PATCH 1/1] Fix assert when get default PCI address property used by vfio-pci Daniel Oram
2016-11-09 19:38 ` Alex Williamson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161109123849.6de6a693@t450s.home \
--to=alex.williamson@redhat.com \
--cc=armbru@redhat.com \
--cc=daniel.oram@gmail.com \
--cc=eblake@redhat.com \
--cc=ehabkost@redhat.com \
--cc=eric.auger@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).