From: Anthony Liguori <anthony@codemonkey.ws>
To: Julien Grall <julien.grall@citrix.com>
Cc: xen-devel@lists.xensource.com, qemu-devel@nongnu.org,
Stefano.Stabellini@eu.citrix.com, julian.pidancet@citrix.com
Subject: Re: [Qemu-devel] [QEMU][RFC PATCH 4/6] xen-pci: Register PCI in Xen
Date: Thu, 22 Mar 2012 14:58:52 -0500 [thread overview]
Message-ID: <4F6B847C.8080402@codemonkey.ws> (raw)
In-Reply-To: <5071f24e827d5948ed3de7f53991b148b4ef38e9.1332430835.git.julien.grall@citrix.com>
On 03/22/2012 11:01 AM, Julien Grall wrote:
> QEMU will now register PCI in Xen. It will usefull to forward
> IO config space to the right QEMU.
>
> Before to register a PCI device, QEMU will check with XenStore if it is
> autorized to register the PCI associate to a given BDF.
>
> Signed-off-by: Julien Grall<julien.grall@citrix.com>
As a general rule, any time you call to XenStore from QEMU, you're doing
something wrong.
You should explicitly launch QEMU with the PCI devices that you want it to have.
If there are platform devices you don't want it to have, then you need to
construct a machine that lacks those devices.
Random hooks in non-Xen code that call into XenStore are always wrong.
Regards,
Anthony Liguori
> ---
> hw/pci.c | 6 +++++
> xen-all.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 76 insertions(+), 0 deletions(-)
>
> diff --git a/hw/pci.c b/hw/pci.c
> index bf046bf..4df4449 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -31,6 +31,7 @@
> #include "loader.h"
> #include "range.h"
> #include "qmp-commands.h"
> +#include "xen.h"
>
> //#define DEBUG_PCI
> #ifdef DEBUG_PCI
> @@ -764,6 +765,11 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
> pci_dev->devfn = devfn;
> pstrcpy(pci_dev->name, sizeof(pci_dev->name), name);
> pci_dev->irq_state = 0;
> +
> + if (xen_enabled()&& xen_register_pcidev(pci_dev)) {
> + return NULL;
> + }
> +
> pci_config_alloc(pci_dev);
>
> pci_config_set_vendor_id(pci_dev->config, pc->vendor_id);
> diff --git a/xen-all.c b/xen-all.c
> index 366bafe..2f5405c 100644
> --- a/xen-all.c
> +++ b/xen-all.c
> @@ -107,6 +107,76 @@ void xen_piix3_set_irq(void *opaque, int irq_num, int level)
> irq_num& 3, level);
> }
>
> +static uint32_t str_to_bdf(const char *str)
> +{
> + /* We assume that bdf is valid */
> + char *buf;
> + uint32_t bdf;
> + uint32_t tmp;
> +
> + bdf = strtol(str,&buf, 16);
> + buf++;
> +
> + str = buf;
> + tmp = strtol(str,&buf, 16);
> + bdf = (bdf<< 16) | (tmp<< 11);
> + buf++;
> +
> + str = buf;
> + tmp = strtol(str,&buf, 16);
> + bdf = bdf | (tmp<< 8);
> +
> + return bdf;
> +}
> +
> +int xen_register_pcidev(PCIDevice *pci_dev)
> +{
> + struct xs_handle *xs = NULL;
> + uint32_t bdf = 0;
> + uint32_t allowed_bdf = 0;
> + char **dir;
> + char path[50];
> + unsigned int nb;
> + unsigned int i;
> + unsigned int len;
> + char *str;
> + int rc = 0;
> +
> +
> + /* Fix : missing bus id to be more generic */
> + bdf |= pci_dev->devfn<< 8;
> +
> + xs = xs_open(0);
> + if (!xs) {
> + fprintf(stderr, "pci_register: Unable to open xenstore\n");
> + return 1;
> + }
> +
> + snprintf(path, sizeof (path), "/local/domain/%u/image/dms/%u/pci",
> + xen_domid, xen_dmid);
> +
> + dir = xs_directory(xs, XBT_NULL, path,&nb);
> + if (dir) {
> + for (i = 0; i< nb; i++) {
> + snprintf(path, sizeof (path), "/local/domain/%u/image/dms/%u/pci/%s",
> + xen_domid, xen_dmid, dir[i]);
> + str = xs_read(xs, XBT_NULL, path,&len);
> + allowed_bdf = str_to_bdf(str);
> + free(str);
> + if (bdf == allowed_bdf)
> + {
> + rc = xc_hvm_register_pcidev(xen_xc, xen_domid, serverid, bdf);
> + break;
> + }
> + }
> + free(dir);
> + }
> +
> + xs_close(xs);
> +
> + return rc;
> +}
> +
> void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
> {
> int i;
next prev parent reply other threads:[~2012-03-22 19:59 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-22 16:01 [Qemu-devel] [QEMU][RFC PATCH 0/6] QEMU disaggregation Julien Grall
2012-03-22 16:01 ` [Qemu-devel] [QEMU][RFC PATCH 1/6] option: Add -xen-dmid Julien Grall
2012-03-22 17:36 ` Jan Kiszka
2012-03-23 10:42 ` Stefano Stabellini
2012-03-22 16:01 ` [Qemu-devel] [QEMU][RFC PATCH 2/6] xen: Add functions to register PCI and IO in Xen Julien Grall
2012-03-23 10:44 ` Stefano Stabellini
2012-03-22 16:01 ` [Qemu-devel] [QEMU][RFC PATCH 3/6] memory: Add xen memory hook Julien Grall
2012-03-22 17:44 ` Jan Kiszka
2012-03-23 15:08 ` Julien Grall
2012-03-23 16:37 ` Jan Kiszka
2012-03-25 10:44 ` Avi Kivity
2012-03-26 11:01 ` Stefano Stabellini
2012-03-26 11:02 ` Avi Kivity
2012-03-26 11:24 ` Julien Grall
2012-03-26 13:13 ` Avi Kivity
2012-03-23 16:47 ` Anthony Liguori
2012-03-22 16:01 ` [Qemu-devel] [QEMU][RFC PATCH 4/6] xen-pci: Register PCI in Xen Julien Grall
2012-03-22 17:47 ` Jan Kiszka
2012-03-22 19:58 ` Anthony Liguori [this message]
2012-03-23 11:02 ` Stefano Stabellini
2012-03-25 12:09 ` Avi Kivity
2012-03-26 11:45 ` Stefano Stabellini
2012-03-26 11:57 ` Avi Kivity
2012-03-26 12:20 ` Stefano Stabellini
2012-03-26 12:33 ` Avi Kivity
2012-03-26 13:56 ` Stefano Stabellini
2012-03-22 16:01 ` [Qemu-devel] [QEMU][RFC PATCH 5/6] xen-io: Handle the new ioreq type IOREQ_TYPE_PCI_CONFIG Julien Grall
2012-03-22 16:01 ` [Qemu-devel] [QEMU][RFC PATCH 6/6] xen: handle qemu disaggregation Julien Grall
2012-03-23 11:07 ` Stefano Stabellini
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=4F6B847C.8080402@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=Stefano.Stabellini@eu.citrix.com \
--cc=julian.pidancet@citrix.com \
--cc=julien.grall@citrix.com \
--cc=qemu-devel@nongnu.org \
--cc=xen-devel@lists.xensource.com \
/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).