Last qemu merge broke device assignment hotplug. Call qemu_pci_hot_assign_device in pci_device_hot_add for hot assign device, and add the command for it. for example hot assign 01:00.0, can use following command: pci_add pci_addr=auto host host=01:00.0 Signed-off-by: Weidong Han <weidong.han@xxxxxxxxx> --- qemu/hw/device-hotplug.c | 37 ------------------------------------- qemu/hw/pci-hotplug.c | 35 +++++++++++++++++++++++++++++++++++ qemu/monitor.c | 2 +- 3 files changed, 36 insertions(+), 38 deletions(-) diff --git a/qemu/hw/device-hotplug.c b/qemu/hw/device-hotplug.c index ae72a00..782b6b4 100644 --- a/qemu/hw/device-hotplug.c +++ b/qemu/hw/device-hotplug.c @@ -30,49 +30,12 @@ #include "pci.h" #include "pc.h" #include "console.h" -#include "device-assignment.h" #include "config.h" #include "virtio-blk.h" #define PCI_BASE_CLASS_STORAGE 0x01 #define PCI_BASE_CLASS_NETWORK 0x02 -#ifdef USE_KVM_DEVICE_ASSIGNMENT -static PCIDevice *qemu_system_hot_assign_device(const char *opts, int bus_nr) -{ - PCIBus *pci_bus; - AssignedDevInfo *adev; - PCIDevice *ret; - - pci_bus = pci_find_bus(bus_nr); - if (!pci_bus) { - term_printf ("Can't find pci_bus %d\n", bus_nr); - return NULL; - } - adev = add_assigned_device(opts); - if (adev == NULL) { - term_printf ("Error adding device; check syntax\n"); - return NULL; - } - - ret = init_assigned_device(adev, pci_bus); - if (ret == NULL) { - term_printf("Failed to assign device\n"); - free_assigned_device(adev); - return NULL; - } - - term_printf("Registered host PCI device %02x:%02x.%1x " - "(\"%s\") as guest device %02x:%02x.%1x\n", - adev->bus, adev->dev, adev->func, adev->name, - pci_bus_num(pci_bus), (ret->devfn >> 3) & 0x1f, - adev->func); - - return ret; -} - -#endif /* USE_KVM_DEVICE_ASSIGNMENT */ - int add_init_drive(const char *opts) { int drive_opt_idx, drive_idx; diff --git a/qemu/hw/pci-hotplug.c b/qemu/hw/pci-hotplug.c index 6286764..8c76453 100644 --- a/qemu/hw/pci-hotplug.c +++ b/qemu/hw/pci-hotplug.c @@ -31,6 +31,7 @@ #include "console.h" #include "block_int.h" #include "virtio-blk.h" +#include "device-assignment.h" #if defined(TARGET_I386) || defined(TARGET_X86_64) static PCIDevice *qemu_pci_hot_add_nic(PCIBus *pci_bus, const char *opts) @@ -127,6 +128,36 @@ static PCIDevice *qemu_pci_hot_add_storage(PCIBus *pci_bus, const char *opts) return opaque; } +#ifdef USE_KVM_DEVICE_ASSIGNMENT +static PCIDevice *qemu_pci_hot_assign_device(PCIBus *pci_bus, const char *opts) +{ + AssignedDevInfo *adev; + PCIDevice *ret; + + adev = add_assigned_device(opts); + if (adev == NULL) { + term_printf ("Error adding device; check syntax\n"); + return NULL; + } + + ret = init_assigned_device(adev, pci_bus); + if (ret == NULL) { + term_printf("Failed to assign device\n"); + free_assigned_device(adev); + return NULL; + } + + term_printf("Registered host PCI device %02x:%02x.%1x " + "(\"%s\") as guest device %02x:%02x.%1x\n", + adev->bus, adev->dev, adev->func, adev->name, + pci_bus_num(pci_bus), (ret->devfn >> 3) & 0x1f, + adev->func); + + return ret; +} + +#endif /* USE_KVM_DEVICE_ASSIGNMENT */ + void pci_device_hot_add(const char *pci_addr, const char *type, const char *opts) { PCIDevice *dev = NULL; @@ -149,6 +180,10 @@ void pci_device_hot_add(const char *pci_addr, const char *type, const char *opts dev = qemu_pci_hot_add_nic(pci_bus, opts); else if (strcmp(type, "storage") == 0) dev = qemu_pci_hot_add_storage(pci_bus, opts); +#ifdef USE_KVM_DEVICE_ASSIGNMENT + else if (strcmp(type, "host") == 0) + dev = qemu_pci_hot_assign_device(pci_bus, opts); +#endif /* USE_KVM_DEVICE_ASSIGNMENT */ else term_printf("invalid type: %s\n", type); diff --git a/qemu/monitor.c b/qemu/monitor.c index 2699b6f..a4a6eb4 100644 --- a/qemu/monitor.c +++ b/qemu/monitor.c @@ -1545,7 +1545,7 @@ static const term_cmd_t term_cmds[] = { "[,cyls=c,heads=h,secs=s[,trans=t]]\n" "[snapshot=on|off][,cache=on|off]", "add drive to PCI storage controller" }, - { "pci_add", "sss", pci_device_hot_add, "pci_addr=auto|[[<domain>:]<bus>:]<slot> nic|storage [[vlan=n][,macaddr=addr][,model=type]] [file=file][,if=type][,bus=nr]...", "hot-add PCI device" }, + { "pci_add", "sss", pci_device_hot_add, "pci_addr=auto|[[<domain>:]<bus>:]<slot> nic|storage|host [[vlan=n][,macaddr=addr][,model=type]] [file=file][,if=type][,bus=nr]... [host=02:00.0[,name=string][,dma=none]", "hot-add PCI device" }, { "pci_del", "s", pci_device_hot_remove, "pci_addr=[[<domain>:]<bus>:]<slot>", "hot remove PCI device" }, { "host_net_add", "ss", net_host_device_add, "[tap,user,socket,vde] options", "add host VLAN client" }, -- 1.6.0.4
Attachment:
0003-kvm-qemu-fix-hot-assign-device.patch
Description: 0003-kvm-qemu-fix-hot-assign-device.patch