From: Alex Williamson <alex.williamson@redhat.com>
To: Cao jin <caoj.fnst@cn.fujitsu.com>
Cc: chen.fan.fnst@cn.fujitsu.com, izumi.taku@jp.fujitsu.com,
qemu-devel@nongnu.org, mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH v4 05/10] vfio: extending function vfio_pci_host_match to support mask func number
Date: Mon, 21 Mar 2016 15:39:54 -0600 [thread overview]
Message-ID: <20160321153954.3727457f@t450s.home> (raw)
In-Reply-To: <1458554926-7844-6-git-send-email-caoj.fnst@cn.fujitsu.com>
On Mon, 21 Mar 2016 18:08:41 +0800
Cao jin <caoj.fnst@cn.fujitsu.com> wrote:
> From: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
>
> Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
> ---
> hw/vfio/pci.c | 29 ++++++++++++++++++++---------
> 1 file changed, 20 insertions(+), 9 deletions(-)
>
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index 0516d94..8842b7f 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -2060,14 +2060,25 @@ static void vfio_pci_post_reset(VFIOPCIDevice *vdev)
> vfio_intx_enable(vdev);
> }
>
> -static bool vfio_pci_host_match(PCIHostDeviceAddress *addr, const char *name)
> +#define HOST_CMP_FUNC_MASK (1 << 0)
> +static bool vfio_pci_host_match(PCIHostDeviceAddress *addr, const char *name,
> + uint8_t mask)
> {
> - char tmp[13];
> + PCIHostDeviceAddress tmp;
>
> - sprintf(tmp, "%04x:%02x:%02x.%1x", addr->domain,
> - addr->bus, addr->slot, addr->function);
> + if (strlen(name) != 12) {
> + return false;
> + }
> +
> + if (sscanf(name, "%04x:%02x:%02x.%1x", &tmp.domain,
> + &tmp.bus, &tmp.slot, &tmp.function) != 4) {
> + return false;
> + }
>
> - return (strcmp(tmp, name) == 0);
> + return (tmp.domain == addr->domain && tmp.bus == addr->bus &&
> + tmp.slot == addr->slot &&
> + ((mask & HOST_CMP_FUNC_MASK) ?
> + 1 : (tmp.function == addr->function)));
> }
I'd probably go for something like:
static int vfio_pci_name_to_addr(const char *name, PCIHostDeviceAddress *addr)
{
if (strlen(name) != 12 ||
sscanf(name, "%04x:%02x:%02x.%1x", &addr->domain,
&addr->bus, &addr->slot, &addr->function) != 4 ) {
return -EINVAL;
}
return 0;
}
static bool vfio_pci_host_match(PCIHostDeviceAddress *addr, const char *name)
{
PCIHostDeviceAddress tmp;
if (vfio_pci_name_to_addr(name, &tmp)) {
return false;
}
return (tmp.domain == addr->domain && tmp.bus == addr->bus &&
tmp.slot == addr->slot && tmp.function == addr->function);
}
Then a _slot version that avoids skips the function comparison. The
mask argument doesn't make much sense for such a simple function when
the code duplication is trivial.
next prev parent reply other threads:[~2016-03-21 21:40 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-21 10:08 [Qemu-devel] [PATCH v4 00/10] vfio-pci: pass the aer error to guest, part2 Cao jin
2016-03-21 10:08 ` [Qemu-devel] [PATCH v4 01/10] vfio: extract vfio_get_hot_reset_info as a single function Cao jin
2016-03-21 10:08 ` [Qemu-devel] [PATCH v4 02/10] vfio: squeeze out vfio_pci_do_hot_reset for support bus reset Cao jin
2016-03-21 10:08 ` [Qemu-devel] [PATCH v4 03/10] vfio: add pcie extended capability support Cao jin
2016-03-21 10:08 ` [Qemu-devel] [PATCH v4 04/10] vfio: add aer support for vfio device Cao jin
2016-03-21 10:08 ` [Qemu-devel] [PATCH v4 05/10] vfio: extending function vfio_pci_host_match to support mask func number Cao jin
2016-03-21 21:39 ` Alex Williamson [this message]
2016-03-21 10:08 ` [Qemu-devel] [PATCH v4 06/10] vfio: add check host bus reset is support or not Cao jin
2016-03-21 21:40 ` Alex Williamson
2016-03-22 10:02 ` Chen Fan
2016-03-22 16:04 ` Alex Williamson
2016-03-21 10:08 ` [Qemu-devel] [PATCH v4 07/10] vfio: add check aer functionality for hotplug device Cao jin
2016-03-21 21:40 ` Alex Williamson
2016-03-21 10:08 ` [Qemu-devel] [PATCH v4 08/10] vfio: vote the function 0 to do host bus reset when aer occurred Cao jin
2016-03-21 21:40 ` Alex Williamson
2016-03-22 10:14 ` Chen Fan
2016-03-22 16:07 ` Alex Williamson
2016-03-23 6:25 ` Chen Fan
2016-03-23 6:25 ` Chen Fan
2016-03-21 10:08 ` [Qemu-devel] [PATCH v4 09/10] vfio-pci: pass the aer error to guest Cao jin
2016-03-21 10:08 ` [Qemu-devel] [PATCH v4 10/10] vfio: add 'aer' property to expose aercap Cao jin
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=20160321153954.3727457f@t450s.home \
--to=alex.williamson@redhat.com \
--cc=caoj.fnst@cn.fujitsu.com \
--cc=chen.fan.fnst@cn.fujitsu.com \
--cc=izumi.taku@jp.fujitsu.com \
--cc=mst@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).