qemu-xen: hot-plug PCI devices at boot-time
PATCH 1/1 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.
---
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(-)
hw/pass-through.c +2 -59
@@ -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 ; }
hw/pc.c +4 -7
@@ -787,8 +787,7 @@ static void pc_init1(ram_addr_t ram_sizeconst 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)
hw/pci.h +1 -1
@@ -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
vl.c +0 -3
@@ -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);
xenstore.c +0 -58
72 lines not on this page · raw message
Simon Horman writes ("[Xen-devel] [patch] qemu-xen: hot-plug PCI devices at boot-time"):
Quoted 1 line
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.
Quoted 6 lines · Ian Jackson
Simon Horman writes ("[Xen-devel] [patch] qemu-xen: hot-plug PCI devices at boot-time"):
Quoted 1 line
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.
Quoted 9 lines · Simon Horman
Quoted 3 lines
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
PATCH 1/1 qemu-xen: pass-through: non-idempotent __insert_to_pci_slot()
In reply to Simon HormanAs 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().
---
This patch requires "qemu-xen: hot-plug PCI devices at boot-time"
hw/pass-through.c +0 -9
@@ -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_devpci_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) {
PATCH 1/1 qemu-xen: pass-through: only parse single BDFs.
In reply to Simon HormanAs 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 '-'.
---
This patch requires "qemu-xen: hot-plug PCI devices at boot-time"
hw/pass-through.c +5 -5
@@ -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 ; }