Simon Horman
2009-May-29 06:56 UTC
[Xen-devel] [patch] qemu-xen: hot-plug PCI devices at boot-time
Currently there are two interfaces to pass-through PCI devices: 1. A method driven through per-device xenstore entries that is used at boot-time 2. An event-based method used for hot-plug. This seems somewhat redundant and makes extending the code cumbersome and prone to error - often the change needs to be made twice, in two different ways. This patch removes support for the boot-time protocol from qemu-xen. There is a companion patch for xend which uses the hot-plug protocol at boot time. Cc: Edwin Zhai <edwin.zhai@intel.com> Cc: Masaki Kanno <kanno.masaki@jp.fujitsu.com> Signed-off-by: Simon Horman <horms@verge.net.au> --- hw/pass-through.c | 61 +---------------------------------------------------- hw/pc.c | 11 +++------ hw/pci.h | 2 - vl.c | 3 -- xenstore.c | 58 -------------------------------------------------- 5 files changed, 7 insertions(+), 128 deletions(-) Index: ioemu-remote/hw/pass-through.c ==================================================================--- ioemu-remote.orig/hw/pass-through.c 2009-05-29 16:39:06.000000000 +1000 +++ ioemu-remote/hw/pass-through.c 2009-05-29 16:44:24.000000000 +1000 @@ -4035,16 +4035,9 @@ int power_off_php_slot(int php_slot) return unregister_real_device(php_slot); } -int pt_init(PCIBus *e_bus, const char *direct_pci) +int pt_init(PCIBus *e_bus) { - int seg, b, d, f, s, status = -1; - struct pt_dev *pt_dev; struct pci_access *pci_access; - char *vslots; - char slot_str[8]; - char *direct_pci_head = NULL; - char *direct_pci_p = NULL; - char *opt; /* Initialize libpci */ pci_access = pci_alloc(); @@ -4060,56 +4053,6 @@ int pt_init(PCIBus *e_bus, const char *d dpci_infos.pci_access = pci_access; dpci_infos.e_bus = e_bus; - if ( !direct_pci || strlen(direct_pci) == 0 ) { - return 0; - } - - if ( !(direct_pci_head = direct_pci_p = strdup(direct_pci)) ) - return 0; - - /* The minimal format of direct_pci: xxxx:xx:xx.x-xxxx:xx:xx.x-... It may - * be even longer considering the per-device opts(see the parsing for - * ''/local/domain/0/backend/pci/XX/YY/opts-ZZ'' in - * xenstore_parse_domain_config(). - * - * The format of vslots(virtual pci slots of all pass-through devs): - * 0xXX;0xXX;... (see the code below). - * - * We''re sure the length of direct_pci is bigger than that of vslots. - */ - vslots = qemu_mallocz(strlen(direct_pci) + 1); - if ( vslots == NULL ) - { - status = -1; - goto err; - } - - /* Assign given devices to guest */ - while ( next_bdf(&direct_pci_p, &seg, &b, &d, &f, &opt, &s) ) - { - /* Register real device with the emulated bus */ - pt_dev = register_real_device(e_bus, "DIRECT PCI", s, - b, d, f, PT_MACHINE_IRQ_AUTO, pci_access, opt); - if ( pt_dev == NULL ) - { - PT_LOG("Error: Registration failed (%02x:%02x.%x)\n", b, d, f); - goto err; - } - - /* Record the virtual slot info */ - sprintf(slot_str, "0x%02x;", PCI_SLOT(pt_dev->dev.devfn)); - - strcat(vslots, slot_str); - } - - /* Write virtual slots info to xenstore for Control panel use */ - xenstore_write_vslots(vslots); - - status = 0; -err: - qemu_free(vslots); - free(direct_pci_head); - - return status; + return 0; } Index: ioemu-remote/hw/pc.c ==================================================================--- ioemu-remote.orig/hw/pc.c 2009-05-29 16:39:06.000000000 +1000 +++ ioemu-remote/hw/pc.c 2009-05-29 16:44:24.000000000 +1000 @@ -787,8 +787,7 @@ static void pc_init1(ram_addr_t ram_size const char *boot_device, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, - int pci_enabled, const char *cpu_model, - const char *direct_pci) + int pci_enabled, const char *cpu_model) { char buf[1024]; int ret, linux_boot, i; @@ -1017,7 +1016,7 @@ vga_bios_error: */ if ( pci_enabled ) { - rc = pt_init(pci_bus, direct_pci); + rc = pt_init(pci_bus); if ( rc < 0 ) { fprintf(logfile, "Error: Initialization failed for pass-through devices\n"); @@ -1205,8 +1204,7 @@ static void pc_init_pci(ram_addr_t ram_s { pc_init1(ram_size, vga_ram_size, boot_device, kernel_filename, kernel_cmdline, - initrd_filename, 1, cpu_model, - direct_pci); + initrd_filename, 1, cpu_model); } static void pc_init_isa(ram_addr_t ram_size, int vga_ram_size, @@ -1219,8 +1217,7 @@ static void pc_init_isa(ram_addr_t ram_s { pc_init1(ram_size, vga_ram_size, boot_device, kernel_filename, kernel_cmdline, - initrd_filename, 0, cpu_model, - direct_pci); + initrd_filename, 0, cpu_model); } /* set CMOS shutdown status register (index 0xF) as S3_resume(0xFE) Index: ioemu-remote/hw/pci.h ==================================================================--- ioemu-remote.orig/hw/pci.h 2009-05-29 16:39:06.000000000 +1000 +++ ioemu-remote/hw/pci.h 2009-05-29 16:44:24.000000000 +1000 @@ -337,6 +337,6 @@ PCIBus *sh_pci_register_bus(pci_set_irq_ qemu_irq *pic, int devfn_min, int nirq); /* pass-through.c */ -int pt_init(PCIBus *e_bus, const char *direct_pci_opt); +int pt_init(PCIBus *e_bus); #endif Index: ioemu-remote/vl.c ==================================================================--- ioemu-remote.orig/vl.c 2009-05-29 16:39:06.000000000 +1000 +++ ioemu-remote/vl.c 2009-05-29 16:44:24.000000000 +1000 @@ -5829,9 +5829,6 @@ int main(int argc, char **argv, char **e } } - if (strlen(direct_pci_str) > 0) - direct_pci = direct_pci_str; - machine->init(ram_size, vga_ram_size, boot_devices, kernel_filename, kernel_cmdline, initrd_filename, cpu_model, direct_pci); Index: ioemu-remote/xenstore.c ==================================================================--- ioemu-remote.orig/xenstore.c 2009-05-29 16:39:06.000000000 +1000 +++ ioemu-remote/xenstore.c 2009-05-29 16:44:24.000000000 +1000 @@ -301,10 +301,8 @@ static const char *xenstore_get_guest_uu return already_computed; } -#define DIRECT_PCI_STR_LEN 512 #define PT_PCI_MSITRANSLATE_DEFAULT 1 #define PT_PCI_POWER_MANAGEMENT_DEFAULT 0 -char direct_pci_str[DIRECT_PCI_STR_LEN]; int direct_pci_msitranslate; int direct_pci_power_mgmt; void xenstore_parse_domain_config(int hvm_domid) @@ -566,62 +564,6 @@ void xenstore_parse_domain_config(int hv goto out; num = atoi(params); - for ( i = 0; i < num; i++ ) { - if (pasprintf(&buf, "/local/domain/0/backend/pci/%u/%u/dev-%d", - hvm_domid, pci_devid, i) != -1) { - free(dev); - dev = xs_read(xsh, XBT_NULL, buf, &len); - - if ( strlen(dev) + strlen(direct_pci_str) > DIRECT_PCI_STR_LEN - 1) { - fprintf(stderr, "qemu: too many pci pass-through devices\n"); - memset(direct_pci_str, 0, DIRECT_PCI_STR_LEN); - goto out; - } - - - /* append to direct_pci_str */ - if ( !dev ) - continue; - - strcat(direct_pci_str, dev); - - if (pasprintf(&buf, "/local/domain/0/backend/pci/%u/%u/vslot-%d", - hvm_domid, pci_devid, i) != -1) { - free(dev); - dev = xs_read(xsh, XBT_NULL, buf, &len); - } - if ( dev ) { - if (strlen(dev) + strlen(direct_pci_str) > - DIRECT_PCI_STR_LEN - 2) { - fprintf(stderr, "qemu: too many pci pass-through " - "devices\n"); - memset(direct_pci_str, 0, DIRECT_PCI_STR_LEN); - goto out; - } - strcat(direct_pci_str, "@"); - strcat(direct_pci_str, dev); - } - - - if (pasprintf(&buf, "/local/domain/0/backend/pci/%u/%u/opts-%d", - hvm_domid, pci_devid, i) != -1) { - free(dev); - dev = xs_read(xsh, XBT_NULL, buf, &len); - } - if ( dev ) { - if ( strlen(dev) + strlen(direct_pci_str) > DIRECT_PCI_STR_LEN - 2) { - fprintf(stderr, "qemu: too many pci pass-through devices\n"); - memset(direct_pci_str, 0, DIRECT_PCI_STR_LEN); - goto out; - } - strcat(direct_pci_str, ","); - strcat(direct_pci_str, dev); - } - - strcat(direct_pci_str, "-"); - } - } - /* get the pci pass-through parameter */ if (pasprintf(&buf, "/local/domain/0/backend/pci/%u/%u/msitranslate", hvm_domid, pci_devid) != -1) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Jackson
2009-May-29 14:43 UTC
Re: [Xen-devel] [patch] qemu-xen: hot-plug PCI devices at boot-time
Simon Horman writes ("[Xen-devel] [patch] qemu-xen: hot-plug PCI devices at boot-time"):> This patch removes support for the boot-time protocol from qemu-xen.Thanks for this. I think it would probably make sense for me to hold off applying this patch to qemu-xen for a few days to a week, to make the version skew possibilities more comfortable ? Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Simon Horman
2009-May-30 03:03 UTC
Re: [Xen-devel] [patch] qemu-xen: hot-plug PCI devices at boot-time
On Fri, May 29, 2009 at 03:43:27PM +0100, Ian Jackson wrote:> Simon Horman writes ("[Xen-devel] [patch] qemu-xen: hot-plug PCI devices at boot-time"): > > This patch removes support for the boot-time protocol from qemu-xen. > > Thanks for this. I think it would probably make sense for me to hold > off applying this patch to qemu-xen for a few days to a week, to make > the version skew possibilities more comfortable ?Hi Ian, that sounds fine, though I think that the xend portion will also need to be held off as xend sendign hot-plug events for deices that xen-qemu has already inserted through the pt_init() code would cause an error. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2009-May-30 09:28 UTC
Re: [Xen-devel] [patch] qemu-xen: hot-plug PCI devices at boot-time
On 30/05/2009 04:03, "Simon Horman" <horms@verge.net.au> wrote:>> Thanks for this. I think it would probably make sense for me to hold >> off applying this patch to qemu-xen for a few days to a week, to make >> the version skew possibilities more comfortable ? > > Hi Ian, > > that sounds fine, though I think that the xend portion will also need to be > held off as xend sendign hot-plug events for deices that xen-qemu has > already inserted through the pt_init() code would cause an error.Then the qemu patch needs to be applied now, and PCI hotplug is probably temporarily broken righ tnow (since the xend patches are applied). Also we should start using QEMU_TAG in xen-untable.hg so that any checkout of xen-unstable will also build against a matching qemu. That will get us bisection capability back again. We''ll sort this out next week. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Simon Horman
2009-Jun-01 03:10 UTC
[Xen-devel] [patch] qemu-xen: pass-through: non-idempotent __insert_to_pci_slot()
As of "qemu-xen: hot-plug PCI devices at boot-time" register_real_dev() no longer needs to call __insert_to_pci_slot() and thus there is no need for __insert_to_pci_slot() to be idempotent. This is because register_real_dev()''s now only has one caller, power_on_php_slot(), which always passes a valid e_slot to register_real_dev(). Cc: Masaki Kanno <kanno.masaki@jp.fujitsu.com> Cc: Edwin Zhai <edwin.zhai@intel.com> Signed-off-by: Simon Horman <horms@verge.net.au> --- This patch requires "qemu-xen: hot-plug PCI devices at boot-time" Index: ioemu-remote/hw/pass-through.c ==================================================================--- ioemu-remote.orig/hw/pass-through.c 2009-06-01 12:49:24.000000000 +1000 +++ ioemu-remote/hw/pass-through.c 2009-06-01 13:02:24.000000000 +1000 @@ -914,9 +914,6 @@ static int __insert_to_pci_slot(int bus, if ( !test_pci_slot(slot) && !pci_devfn_in_use(e_bus, PCI_DEVFN(slot, 0)) ) goto found; - if ( pci_slot_match(bus, dev, func, slot) ) - /* The slot is already here, just return */ - return slot; return -2; } @@ -3778,12 +3775,6 @@ static struct pt_dev * register_real_dev pci_fill_info(pci_dev, PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES); pt_libpci_fixup(pci_dev); - e_slot = __insert_to_pci_slot(r_bus, r_dev, r_func, e_slot, NULL); - if ( e_slot < 0 ) { - PT_LOG("Error: no free virtual PCI slot\n"); - return NULL; - } - msi_translate = direct_pci_msitranslate; power_mgmt = direct_pci_power_mgmt; while (opt) { _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Simon Horman
2009-Jun-01 03:11 UTC
[Xen-devel] [patch] qemu-xen: pass-through: only parse single BDFs.
As of "qemu-xen: hot-plug PCI devices at boot-time", the BDF string that is parsed always contains a single bdf, not multiple bdf''s delimited by a ''-''. Cc: Masaki Kanno <kanno.masaki@jp.fujitsu.com> Cc: Edwin Zhai <edwin.zhai@intel.com> Signed-off-by: Simon Horman <horms@verge.net.au> --- This patch requires "qemu-xen: hot-plug PCI devices at boot-time" Index: ioemu-remote/hw/pass-through.c ==================================================================--- ioemu-remote.orig/hw/pass-through.c 2009-06-01 12:49:30.000000000 +1000 +++ ioemu-remote/hw/pass-through.c 2009-06-01 12:52:16.000000000 +1000 @@ -825,11 +825,11 @@ static int token_value(char *token) return strtol(token, NULL, 16); } -static int next_bdf(char **str, int *seg, int *bus, int *dev, int *func, - char **opt, int *vslot) +static int parse_bdf(char **str, int *seg, int *bus, int *dev, int *func, + char **opt, int *vslot) { char *token, *endptr; - const char *delim = ":.-"; + const char *delim = ":."; if ( !(*str) || ( !strchr(*str, '':'') && !strchr(*str, ''.'')) ) @@ -945,7 +945,7 @@ int insert_to_pci_slot(char *bdf_slt) int seg, bus, dev, func, slot; char *opt; - if ( !next_bdf(&bdf_slt, &seg, &bus, &dev, &func, &opt, &slot) ) + if ( !parse_bdf(&bdf_slt, &seg, &bus, &dev, &func, &opt, &slot) ) { return -1; } @@ -976,7 +976,7 @@ int bdf_to_slot(char *bdf_str) int seg, bus, dev, func, slot, i; char *opt; - if ( !next_bdf(&bdf_str, &seg, &bus, &dev, &func, &opt, &slot)) + if ( !parse_bdf(&bdf_str, &seg, &bus, &dev, &func, &opt, &slot)) { return -1; } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel