pci, virtio, acpi: fixes for 2.6
The following changes since commit 7acbff99c6c285b3070bf0e768d56f511e2bf346:
Update version for v2.6.0-rc1 release (2016-04-05 21:53:18 +0100)
are available in the git repository at:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
for you to fetch changes up to 2e4278b534997d8f33a6e8b7923c168f5e5c89c7:
hw/pci-bridge: Add missing unref in case register-bus fails (2016-04-07 19:57:33 +0300)
----------------------------------------------------------------
pci, virtio, acpi: fixes for 2.6
Fixes all over the place. Most notably, fixes migration for systems with pci express bridges, and random crashes observed with virtio blk and scsi dataplane.
----------------------------------------------------------------
Dr. David Alan Gilbert (1):
Migration: Add i82801b11 migration data
Gerd Hoffmann (1):
Sort the fw_cfg file list
Marcel Apfelbaum (1):
tests/bios-tables-test: fix assert
Michael S. Tsirkin (4):
pci-testdev: fast mmio support
xen: piix reuse pci generic class init function
virtio: add aio handler
virtio-blk: use aio handler for data plane
Paolo Bonzini (5):
virtio: make virtio_queue_notify_vq static
virtio-blk: fix disabled mode
virtio-scsi: fix disabled mode
virtio-scsi: use aio handler for data plane
virtio: merge virtio_queue_aio_set_host_notifier_handler with virtio_queue_set_aio
Pavel Butsykin (1):
virtio-balloon: reset the statistic timer to load device
Stefan Weil (1):
acpi: Add missing GCC_FMT_ATTR
Wei Jiangang (1):
hw/pci-bridge: Add missing unref in case register-bus fails
include/hw/acpi/aml-build.h | 3 +- include/hw/boards.h | 3 +- include/hw/loader.h | 2 + include/hw/nvram/fw_cfg.h | 8 +++ include/hw/virtio/virtio-blk.h | 3 + include/hw/virtio/virtio-scsi.h | 7 +- include/hw/virtio/virtio.h | 4 +- hw/block/dataplane/virtio-blk.c | 23 +++++-- hw/block/virtio-blk.c | 29 +++++--- hw/core/loader.c | 14 ++++ hw/i386/pc.c | 4 ++ hw/i386/pc_piix.c | 1 + hw/i386/pc_q35.c | 1 + hw/ide/piix.c | 14 +--- hw/misc/pci-testdev.c | 7 +- hw/nvram/fw_cfg.c | 131 +++++++++++++++++++++++++++++++++--- hw/pci-bridge/i82801b11.c | 9 +++ hw/pci-bridge/pci_expander_bridge.c | 8 ++- hw/scsi/virtio-scsi-dataplane.c | 47 ++++++++++--- hw/scsi/virtio-scsi.c | 69 ++++++++++++------- hw/virtio/virtio-balloon.c | 4 ++ hw/virtio/virtio.c | 39 ++++++++--- tests/bios-tables-test.c | 2 +- vl.c | 10 ++- tests/Makefile | 2 +- 25 files changed, 352 insertions(+), 92 deletions(-)
[Qemu-devel] [PULL 01/15] acpi: Add missing GCC_FMT_ATTR
From: Stefan Weil <[email protected]>
This fixes a compiler warning when compiling with -Wextra.
--- include/hw/acpi/aml-build.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/hw/acpi/aml-build.h +2 -1
@@ -369,6 +369,7 @@ build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets, const char *oem_id, const char *oem_table_id); int -build_append_named_dword (GArray *array,const char *name_format, ...); +build_append_named_dword(GArray *array, const char *name_format, ...) +GCC_FMT_ATTR(2, 3);#endif
Signature · 1 line
MST
[Qemu-devel] [PULL 02/15] pci-testdev: fast mmio support
In reply to Michael S. TsirkinTeach PCI testdev to use fast MMIO when kvm makes it available.
Before:
mmio-wildcard-eventfd:pci-mem 2271
After:
mmio-wildcard-eventfd:pci-mem 1218
--- hw/misc/pci-testdev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
hw/misc/pci-testdev.c +6 -1
@@ -239,6 +239,7 @@ static void pci_testdev_realize(PCIDevice *pci_dev, Error **errp)uint8_t *pci_conf;char *name;int r, i; +bool fastmmio =kvm_ioeventfd_any_length_enabled (); pci_conf = pci_dev->config;
@@ -261,8 +262,12 @@ static void pci_testdev_realize(PCIDevice *pci_dev, Error **errp)memcpy (test->hdr->name, name,strlen (name) +1 );g_free (name); test->hdr->offset =cpu_to_le32 (IOTEST_SIZE (i) + i *IOTEST_ACCESS_WIDTH ); - test->size =IOTEST_ACCESS_WIDTH ; test->match_data =strcmp (IOTEST_TEST (i),"wildcard-eventfd" ); +if (fastmmio &&IOTEST_IS_MEM (i) && !test->match_data) { + test->size =0 ; + }else { + test->size =IOTEST_ACCESS_WIDTH ; + } test->hdr->test = i; test->hdr->data = test->match_data ?IOTEST_DATAMATCH :IOTEST_NOMATCH ; test->hdr->width =IOTEST_ACCESS_WIDTH ;
Signature · 1 line
MST
[Qemu-devel] [PULL 04/15] Sort the fw_cfg file list
In reply to Michael S. TsirkinFrom: Gerd Hoffmann <[email protected]>
Entries are inserted in filename order instead of being appended to the end in case sorting is enabled.
This will avoid any future issues of moving the file creation around, it doesn't matter what order they are created now, the will always be in filename order.
Added machine type handling for compatibility. This was a fairly complex change, this will preserve the order of fw_cfg for older versions no matter what order the firmware files actually come in. A list is kept of the correct legacy order and the entries will be inserted based upon their order in the list. Except that some entries are ordered (in a specific area of the list) based upon what order they appear on the command line. Special handling is added for those entries.
--- include/hw/boards.h | 3 +- include/hw/loader.h | 2 + include/hw/nvram/fw_cfg.h | 8 +++ hw/core/loader.c | 14 +++++ hw/i386/pc.c | 4 ++ hw/i386/pc_piix.c | 1 + hw/i386/pc_q35.c | 1 + hw/nvram/fw_cfg.c | 131 +++++++++++++++++++++++++++++++++++++++++++--- vl.c | 10 +++- tests/Makefile | 2 +- 10 files changed, 164 insertions(+), 12 deletions(-)
include/hw/boards.h +2 -1
@@ -108,7 +108,8 @@ struct MachineClass { no_cdrom:1, no_sdcard:1, has_dynamic_sysbus:1, - pci_allow_0_address:1; + pci_allow_0_address:1, + legacy_fw_cfg_order:1;int is_default;const char *default_machine_opts;const char *default_boot_order;
include/hw/loader.h +2 -0
@@ -128,6 +128,8 @@ int rom_add_elf_program(const char *name, void *data, size_t datasize, size_t romsize, hwaddr addr);int rom_check_and_register_reset (void );void rom_set_fw (FWCfgState *f); +void rom_set_order_override (int order); +void rom_reset_order_override (void );int rom_copy (uint8_t *dest,hwaddr addr,size_t size);void *rom_ptr (hwaddr addr);void hmp_info_roms (Monitor *mon,const QDict *qdict);
include/hw/nvram/fw_cfg.h +8 -0
@@ -11,6 +11,14 @@ typedef struct FWCfgFile {char name[FW_CFG_MAX_FILE_PATH ]; } FWCfgFile; +#define FW_CFG_ORDER_OVERRIDE_VGA 70 +#define FW_CFG_ORDER_OVERRIDE_NIC 80 +#define FW_CFG_ORDER_OVERRIDE_USER 100 +#define FW_CFG_ORDER_OVERRIDE_DEVICE 110 + +void fw_cfg_set_order_override (FWCfgState *fw_cfg,int order); +void fw_cfg_reset_order_override (FWCfgState *fw_cfg); + typedef struct FWCfgFiles { uint32_t count; FWCfgFile f[];
hw/core/loader.c +14 -0
@@ -1053,6 +1053,20 @@ void rom_set_fw(FWCfgState *f) fw_cfg = f; } +void rom_set_order_override (int order) +{ +if (!fw_cfg) +return ; +fw_cfg_set_order_override (fw_cfg, order); +} + +void rom_reset_order_override (void ) +{ +if (!fw_cfg) +return ; +fw_cfg_reset_order_override (fw_cfg); +} +static Rom *find_rom (hwaddr addr) {Rom *rom;
hw/i386/pc.c +4 -0
@@ -1406,6 +1406,7 @@ DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus) {DeviceState *dev =NULL ; +rom_set_order_override (FW_CFG_ORDER_OVERRIDE_VGA );if (pci_bus) {PCIDevice *pcidev =pci_vga_init (pci_bus); dev = pcidev ? &pcidev->qdev :NULL ;
@@ -1413,6 +1414,7 @@ DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus)ISADevice *isadev =isa_vga_init (isa_bus); dev = isadev ?DEVICE (isadev) :NULL ; } +rom_reset_order_override ();return dev; }
@@ -1541,6 +1543,7 @@ void pc_nic_init(ISABus *isa_bus, PCIBus *pci_bus) {int i; +rom_set_order_override (FW_CFG_ORDER_OVERRIDE_NIC );for (i =0 ; i < nb_nics; i++) {NICInfo *nd = &nd_table[i];
@@ -1550,6 +1553,7 @@ void pc_nic_init(ISABus *isa_bus, PCIBus *pci_bus)pci_nic_init_nofail (nd, pci_bus,"e1000" ,NULL ); } } +rom_reset_order_override (); }void pc_pci_device_init (PCIBus *pci_bus)
hw/i386/pc_piix.c +1 -0
@@ -434,6 +434,7 @@ static void pc_i440fx_2_5_machine_options(MachineClass *m) m->alias =NULL ; m->is_default =0 ; pcmc->save_tsc_khz = false; + m->legacy_fw_cfg_order =1 ;SET_MACHINE_COMPAT (m,PC_COMPAT_2_5 ); }
hw/i386/pc_q35.c +1 -0
@@ -298,6 +298,7 @@ static void pc_q35_2_5_machine_options(MachineClass *m)pc_q35_2_6_machine_options (m); m->alias =NULL ; pcmc->save_tsc_khz = false; + m->legacy_fw_cfg_order =1 ;SET_MACHINE_COMPAT (m,PC_COMPAT_2_5 ); }
hw/nvram/fw_cfg.c +123 -8
174 lines not on this page · raw message
vl.c +8 -2
@@ -2297,8 +2297,9 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)gchar *buf;size_t size;const char *name, *file, *str; +FWCfgState *fw_cfg = (FWCfgState *) opaque; -if (opaque ==NULL ) { +if (fw_cfg ==NULL ) {error_report ("fw_cfg device not available" );return -1 ; }
@@ -2332,7 +2333,10 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)return -1 ; } } -fw_cfg_add_file ((FWCfgState *)opaque, name, buf, size); +/* For legacy, keep user files in a specific global order. */ +fw_cfg_set_order_override (fw_cfg,FW_CFG_ORDER_OVERRIDE_USER ); +fw_cfg_add_file (fw_cfg, name, buf, size); +fw_cfg_reset_order_override (fw_cfg);return 0 ; }
@@ -4535,10 +4539,12 @@ int main(int argc, char **argv, char **envp)igd_gfx_passthru ();/* init generic devices */ +rom_set_order_override (FW_CFG_ORDER_OVERRIDE_DEVICE );if (qemu_opts_foreach (qemu_find_opts ("device" ), device_init_func,NULL ,NULL )) {exit (1 ); } +rom_reset_order_override ();/* Did we create any drives that we failed to create a device for? */ drive_check_orphaned ();
tests/Makefile +1 -1
@@ -83,7 +83,7 @@ check-unit-y += tests/test-crypto-cipher$(EXESUF) check-unit-y += tests/test-crypto-secret$(EXESUF) check-unit-$(CONFIG_GNUTLS) += tests/test-crypto-tlscredsx509$(EXESUF) check-unit-$(CONFIG_GNUTLS) += tests/test-crypto-tlssession$(EXESUF) -check-unit-$(CONFIG_LINUX) += tests/test-qga$(EXESUF) +#check-unit-$(CONFIG_LINUX) += tests/test-qga$(EXESUF) check-unit-y += tests/test-timed-average$(EXESUF) check-unit-y += tests/test-io-task$(EXESUF) check-unit-y += tests/test-io-channel-socket$(EXESUF)
Signature · 1 line
MST
[Qemu-devel] [PULL 03/15] xen: piix reuse pci generic class init function
In reply to Michael S. Tsirkinpiix3_ide_xen_class_init is identical to piix3_ide_class_init except it's buggy as it does not set exit and does not disable hotplug properly.
Switch to the generic one.
--- hw/ide/piix.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)
hw/ide/piix.c +1 -13
@@ -258,22 +258,10 @@ static const TypeInfo piix3_ide_info = { .class_init = piix3_ide_class_init, }; -static void piix3_ide_xen_class_init (ObjectClass *klass,void *data) -{ -DeviceClass *dc =DEVICE_CLASS (klass); -PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); - - k->realize = pci_piix_ide_realize; - k->vendor_id =PCI_VENDOR_ID_INTEL ; - k->device_id =PCI_DEVICE_ID_INTEL_82371SB_1 ; - k->class_id =PCI_CLASS_STORAGE_IDE ; -set_bit (DEVICE_CATEGORY_STORAGE , dc->categories); -} -static const TypeInfo piix3_ide_xen_info = { .name ="piix3-ide-xen" , .parent =TYPE_PCI_IDE , - .class_init = piix3_ide_xen_class_init, + .class_init = piix3_ide_class_init, };static void piix4_ide_class_init (ObjectClass *klass,void *data)
Signature · 1 line
MST
[Qemu-devel] [PULL 05/15] Migration: Add i82801b11 migration data
In reply to Michael S. TsirkinFrom: "Dr. David Alan Gilbert" <[email protected]>
The i82801b11 bridge didn't have a vmsd and thus didn't send any migration data, including that of its parent PCIBridge object. The symptom being if the guest used any devices behind the bridge the guest crashed (mostly with various interrupt related issues).
Note: This will cause migration from old qemus that used this device to explicitly fail during migration as opposed to the guest crashing.
--- hw/pci-bridge/i82801b11.c | 9 +++++++++ 1 file changed, 9 insertions(+)
hw/pci-bridge/i82801b11.c +9 -0
@@ -78,6 +78,14 @@ err_bridge:return rc; } +static const VMStateDescription i82801b11_bridge_dev_vmstate = { + .name ="i82801b11_bridge" , + .fields = (VMStateField []) { +VMSTATE_PCI_DEVICE (parent_obj, PCIBridge), +VMSTATE_END_OF_LIST () + } +}; +static void i82801b11_bridge_class_init (ObjectClass *klass,void *data) {PCIDeviceClass *k =PCI_DEVICE_CLASS (klass);
@@ -89,6 +97,7 @@ static void i82801b11_bridge_class_init(ObjectClass *klass, void *data) k->revision =ICH9_D2P_A2_REVISION ; k->init = i82801b11_bridge_initfn; k->config_write = pci_bridge_write_config; + dc->vmsd = &i82801b11_bridge_dev_vmstate;set_bit (DEVICE_CATEGORY_BRIDGE , dc->categories); }
Signature · 1 line
MST
[Qemu-devel] [PULL 06/15] virtio-balloon: reset the statistic timer to load device
In reply to Michael S. TsirkinFrom: Pavel Butsykin <[email protected]>
If before loading snapshot we had set the timer of statistics, then after applying snapshot the expiry time would be irrelevant for the restored state of the virtual clocks. A simple fix is just to restart the timer after loading snapshot.
For the user it may look like a long delay of statistics update after switch to the snapshot.
--- hw/virtio/virtio-balloon.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/virtio/virtio-balloon.c +4 -0
@@ -426,6 +426,10 @@ static int virtio_balloon_load_device(VirtIODevice *vdev, QEMUFile *f, s->num_pages =qemu_get_be32 (f); s->actual =qemu_get_be32 (f); + +if (balloon_stats_enabled (s)) { +balloon_stats_change_timer (s, s->stats_poll_interval); + }return 0 ; }
Signature · 1 line
MST
[Qemu-devel] [PULL 07/15] tests/bios-tables-test: fix assert
In reply to Michael S. TsirkinFrom: Marcel Apfelbaum <[email protected]>
Newer iasl does not add the aml file name to the Definition Block. See acpica tools commit 1ecbb3d5:
"Emit the AMLFilename as a zero-length string. Allows the compiler to create
the name later -- making it easier to rename the parent ASL (DSL) file."
That causes an assert in acpi tests:
tests/bios-tables-test.c:455:normalize_asl: assertion failed: (block_name)
Fix it by striping the start of the definition block line until the first comma. The block name is always the first parameter and
the grammar does not allow comma in between, so it is safe.
--- tests/bios-tables-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/bios-tables-test.c +1 -1
@@ -432,7 +432,7 @@ static bool load_asl(GArray *sdts, AcpiSdtTable *sdt)#define COMMENT_END "*/"#define DEF_BLOCK "DefinitionBlock (" -#define BLOCK_NAME_END ".aml" +#define BLOCK_NAME_END ","static GString *normalize_asl (gchar *asl_code) {
Signature · 1 line
MST
[Qemu-devel] [PULL 08/15] virtio: make virtio_queue_notify_vq static
In reply to Michael S. TsirkinFrom: Paolo Bonzini <[email protected]>
--- include/hw/virtio/virtio.h | 1 - hw/virtio/virtio.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-)
include/hw/virtio/virtio.h +0 -1
@@ -252,7 +252,6 @@ void virtio_queue_set_host_notifier_fd_handler(VirtQueue *vq, bool assign, bool set_handler);void virtio_queue_aio_set_host_notifier_handler (VirtQueue *vq,AioContext *ctx,bool assign,bool set_handler); -void virtio_queue_notify_vq (VirtQueue *vq);void virtio_irq (VirtQueue *vq);VirtQueue *virtio_vector_first_queue (VirtIODevice *vdev,uint16_t vector);VirtQueue *virtio_vector_next_queue (VirtQueue *vq);
hw/virtio/virtio.c +1 -1
@@ -1088,7 +1088,7 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align)virtio_queue_update_rings (vdev, n); } -void virtio_queue_notify_vq (VirtQueue *vq) +static void virtio_queue_notify_vq (VirtQueue *vq) {if (vq->vring.desc && vq->handle_output) {VirtIODevice *vdev = vq->vdev;
Signature · 1 line
MST
[Qemu-devel] [PULL 09/15] virtio-blk: fix disabled mode
In reply to Michael S. TsirkinFrom: Paolo Bonzini <[email protected]>
We must not call virtio_blk_data_plane_notify if dataplane is
disabled: we would hit a segmentation fault in notify_guest_bh as s->guest_notifier has not been setup and is NULL.
--- include/hw/virtio/virtio-blk.h | 1 + hw/block/dataplane/virtio-blk.c | 7 +++---- hw/block/virtio-blk.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
include/hw/virtio/virtio-blk.h +1 -0
@@ -53,6 +53,7 @@ typedef struct VirtIOBlock {unsigned short sector_mask;bool original_wce;VMChangeStateEntry *change; +bool dataplane_disabled;bool dataplane_started;struct VirtIOBlockDataPlane *dataplane; } VirtIOBlock;
hw/block/dataplane/virtio-blk.c +3 -4
@@ -29,7 +29,6 @@struct VirtIOBlockDataPlane {bool starting;bool stopping; -bool disabled;VirtIOBlkConf *conf;
@@ -234,7 +233,7 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s) fail_host_notifier: k->set_guest_notifiers (qbus->parent,1 , false); fail_guest_notifiers: - s->disabled = true; + vblk->dataplane_disabled = true; s->starting = false; vblk->dataplane_started = true; }
@@ -251,8 +250,8 @@ void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s) }/* Better luck next time. */ -if (s->disabled) { - s->disabled = false; +if (vblk->dataplane_disabled) { + vblk->dataplane_disabled = false; vblk->dataplane_started = false;return ; }
hw/block/virtio-blk.c +1 -1
@@ -54,7 +54,7 @@ static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status)stb_p (&req->in->status, status);virtqueue_push (s->vq, &req->elem, req->in_len); -if (s->dataplane) { +if (s->dataplane_started && !s->dataplane_disabled) {virtio_blk_data_plane_notify (s->dataplane); }else {virtio_notify (vdev, s->vq);
Signature · 1 line
MST
[Qemu-devel] [PULL 10/15] virtio-scsi: fix disabled mode
In reply to Michael S. TsirkinFrom: Paolo Bonzini <[email protected]>
Add two missing checks for s->dataplane_fenced. In one case, QEMU would skip injecting an IRQ due to a write to an uninitialized EventNotifier's file descriptor.
In the second case, the dataplane_disabled field was used by mistake; in fact after fixing this occurrence it is completely unused.
--- include/hw/virtio/virtio-scsi.h | 1 - hw/scsi/virtio-scsi.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-)
include/hw/virtio/virtio-scsi.h +0 -1
@@ -91,7 +91,6 @@ typedef struct VirtIOSCSI {bool dataplane_started;bool dataplane_starting;bool dataplane_stopping; -bool dataplane_disabled;bool dataplane_fenced;Error *blocker;uint32_t host_features;
hw/scsi/virtio-scsi.c +2 -2
@@ -68,7 +68,7 @@ static void virtio_scsi_complete_req(VirtIOSCSIReq *req)qemu_iovec_from_buf (&req->resp_iov,0 , &req->resp, req->resp_size);virtqueue_push (vq, &req->elem, req->qsgl.size + req->resp_iov.size); -if (s->dataplane_started) { +if (s->dataplane_started && !s->dataplane_fenced) {virtio_scsi_dataplane_notify (vdev, req); }else {virtio_notify (vdev, vq);
@@ -773,7 +773,7 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev,VirtIOSCSI *s =VIRTIO_SCSI (vdev);SCSIDevice *sd =SCSI_DEVICE (dev); -if (s->ctx && !s->dataplane_disabled) { +if (s->ctx && !s->dataplane_fenced) {VirtIOSCSIBlkChangeNotifier *insert_notifier, *remove_notifier;if (blk_op_is_blocked (sd->conf.blk,BLOCK_OP_TYPE_DATAPLANE , errp)) {
Signature · 1 line
MST
[Qemu-devel] [PULL 11/15] virtio: add aio handler
In reply to Michael S. TsirkinIn addition to handling IO in vcpu thread and in io thread, blk dataplane introduces yet another mode: handling it by AioContext.
Currently, this reuses the same handler as previous modes, which triggers races as these were not designed to be reentrant. Add instead a separate handler just for aio; this will make it possible to disable regular handlers when dataplane is active.
--- include/hw/virtio/virtio.h | 3 +++ hw/virtio/virtio.c | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-)
include/hw/virtio/virtio.h +3 -0
@@ -142,6 +142,9 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,void (*handle_output)(VirtIODevice *, VirtQueue *)); +void virtio_set_queue_aio (VirtQueue *vq, +void (*handle_output)(VirtIODevice *,VirtQueue *)); +void virtio_del_queue (VirtIODevice *vdev,int n);void *virtqueue_alloc_element (size_t sz,unsigned out_num,unsigned in_num);
hw/virtio/virtio.c +32 -4
@@ -96,6 +96,7 @@ struct VirtQueueuint16_t vector;void (*handle_output)(VirtIODevice *vdev,VirtQueue *vq); +void (*handle_aio_output)(VirtIODevice *vdev,VirtQueue *vq);VirtIODevice *vdev;EventNotifier guest_notifier;EventNotifier host_notifier;
@@ -1088,6 +1089,16 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align)virtio_queue_update_rings (vdev, n); } +static void virtio_queue_notify_aio_vq (VirtQueue *vq) +{ +if (vq->vring.desc && vq->handle_aio_output) { +VirtIODevice *vdev = vq->vdev; + +trace_virtio_queue_notify (vdev, vq - vdev->vq, vq); + vq->handle_aio_output (vdev, vq); + } +} +static void virtio_queue_notify_vq (VirtQueue *vq) {if (vq->vring.desc && vq->handle_output) {
@@ -1143,10 +1154,19 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size, vdev->vq[i].vring.num_default = queue_size; vdev->vq[i].vring.align =VIRTIO_PCI_VRING_ALIGN ; vdev->vq[i].handle_output = handle_output; + vdev->vq[i].handle_aio_output =NULL ;return &vdev->vq[i]; } +void virtio_set_queue_aio (VirtQueue *vq, +void (*handle_output)(VirtIODevice *,VirtQueue *)) +{ +assert (vq->handle_output); + + vq->handle_aio_output = handle_output; +} +void virtio_del_queue (VirtIODevice *vdev,int n) {if (n <0 || n >=VIRTIO_QUEUE_MAX ) {
@@ -1780,11 +1800,11 @@ EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq)return &vq->guest_notifier; } -static void virtio_queue_host_notifier_read (EventNotifier *n) +static void virtio_queue_host_notifier_aio_read (EventNotifier *n) {VirtQueue *vq =container_of (n, VirtQueue, host_notifier);if (event_notifier_test_and_clear (n)) { -virtio_queue_notify_vq (vq); +virtio_queue_notify_aio_vq (vq); } }
@@ -1793,14 +1813,22 @@ void virtio_queue_aio_set_host_notifier_handler(VirtQueue *vq, AioContext *ctx, {if (assign && set_handler) {aio_set_event_notifier (ctx, &vq->host_notifier, true, - virtio_queue_host_notifier_read); + virtio_queue_host_notifier_aio_read); }else {aio_set_event_notifier (ctx, &vq->host_notifier, true,NULL ); }if (!assign) {/* Test and clear notifier before after disabling event, * in case poll callback didn't have time to run. */ -virtio_queue_host_notifier_read (&vq->host_notifier); +virtio_queue_host_notifier_aio_read (&vq->host_notifier); + } +} + +static void virtio_queue_host_notifier_read (EventNotifier *n) +{ +VirtQueue *vq =container_of (n, VirtQueue, host_notifier); +if (event_notifier_test_and_clear (n)) { +virtio_queue_notify_vq (vq); } }
Signature · 1 line
MST
[Qemu-devel] [PULL 13/15] virtio-scsi: use aio handler for data plane
In reply to Michael S. TsirkinFrom: Paolo Bonzini <[email protected]>
In addition to handling IO in vcpu thread and in io thread, dataplane introduces yet another mode: handling it by AioContext.
This reuses the same handler as previous modes, which triggers races as these were not designed to be reentrant. Use a separate handler just for aio, and disable regular handlers when dataplane is active.
--- include/hw/virtio/virtio-scsi.h | 6 ++-- hw/scsi/virtio-scsi-dataplane.c | 43 ++++++++++++++++++++++++--- hw/scsi/virtio-scsi.c | 65 ++++++++++++++++++++++++++++------------- 3 files changed, 86 insertions(+), 28 deletions(-)
include/hw/virtio/virtio-scsi.h +3 -3
@@ -139,9 +139,9 @@ void virtio_scsi_common_realize(DeviceState *dev, Error **errp, HandleOutput cmd);void virtio_scsi_common_unrealize (DeviceState *dev,Error **errp); -void virtio_scsi_handle_ctrl_req (VirtIOSCSI *s,VirtIOSCSIReq *req); -bool virtio_scsi_handle_cmd_req_prepare (VirtIOSCSI *s,VirtIOSCSIReq *req); -void virtio_scsi_handle_cmd_req_submit (VirtIOSCSI *s,VirtIOSCSIReq *req); +void virtio_scsi_handle_event_vq (VirtIOSCSI *s,VirtQueue *vq); +void virtio_scsi_handle_cmd_vq (VirtIOSCSI *s,VirtQueue *vq); +void virtio_scsi_handle_ctrl_vq (VirtIOSCSI *s,VirtQueue *vq);void virtio_scsi_init_req (VirtIOSCSI *s,VirtQueue *vq,VirtIOSCSIReq *req);void virtio_scsi_free_req (VirtIOSCSIReq *req); void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
hw/scsi/virtio-scsi-dataplane.c +39 -4
77 lines not on this page · raw message
hw/scsi/virtio-scsi.c +44 -21
125 lines not on this page · raw message
Signature · 1 line
MST
[Qemu-devel] [PULL 15/15] hw/pci-bridge: Add missing unref in case register-bus fails
In reply to Michael S. TsirkinFrom: Wei Jiangang <[email protected]>
The error paths after a successful qdev_create/pci_bus_new should contain a object_unref/object_unparent. pxb_dev_init_common() did not yet, so add it.
--- hw/pci-bridge/pci_expander_bridge.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
hw/pci-bridge/pci_expander_bridge.c +7 -1
@@ -249,7 +249,7 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)PCI_HOST_BRIDGE (ds)->bus = bus;if (pxb_register_bus (dev, bus)) { -return -EINVAL ; + goto err_register_bus; }qdev_init_nofail (ds);
@@ -263,6 +263,12 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie) pxb_dev_list =g_list_insert_sorted (pxb_dev_list, pxb, pxb_compare);return 0 ; + +err_register_bus: +object_unref (OBJECT (bds)); +object_unparent (OBJECT (bus)); +object_unref (OBJECT (ds)); +return -EINVAL ; }static int pxb_dev_initfn (PCIDevice *dev)
Signature · 1 line
MST
[Qemu-devel] [PULL 12/15] virtio-blk: use aio handler for data plane
In reply to Michael S. TsirkinIn addition to handling IO in vcpu thread and in io thread, dataplane introduces yet another mode: handling it by AioContext.
This reuses the same handler as previous modes, which triggers races as these were not designed to be reentrant. Use a separate handler just for aio, and disable regular handlers when dataplane is active.
--- include/hw/virtio/virtio-blk.h | 2 ++ hw/block/dataplane/virtio-blk.c | 13 +++++++++++++ hw/block/virtio-blk.c | 27 +++++++++++++++++---------- 3 files changed, 32 insertions(+), 10 deletions(-)
include/hw/virtio/virtio-blk.h +2 -0
@@ -86,4 +86,6 @@ void virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb);void virtio_blk_submit_multireq (BlockBackend *blk,MultiReqBuffer *mrb); +void virtio_blk_handle_vq (VirtIOBlock *s,VirtQueue *vq); +#endif
hw/block/dataplane/virtio-blk.c +13 -0
@@ -184,6 +184,17 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s)g_free (s); } +static void virtio_blk_data_plane_handle_output (VirtIODevice *vdev, +VirtQueue *vq) +{ +VirtIOBlock *s = (VirtIOBlock *)vdev; + +assert (s->dataplane); +assert (s->dataplane_started); + +virtio_blk_handle_vq (s, vq); +} +/* Context: QEMU global mutex held */ void virtio_blk_data_plane_start (VirtIOBlockDataPlane *s) {
@@ -226,6 +237,7 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)/* Get this show started by hooking up our callbacks */ aio_context_acquire (s->ctx); +virtio_set_queue_aio (s->vq, virtio_blk_data_plane_handle_output);virtio_queue_aio_set_host_notifier_handler (s->vq, s->ctx, true, true);aio_context_release (s->ctx);return ;
@@ -262,6 +274,7 @@ void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s)/* Stop notifications for new requests from guest */ virtio_queue_aio_set_host_notifier_handler (s->vq, s->ctx, false, false); +virtio_set_queue_aio (s->vq,NULL );/* Drain and switch bs back to the QEMU main loop */ blk_set_aio_context (s->conf->conf.blk,qemu_get_aio_context ());
hw/block/virtio-blk.c +17 -10
@@ -578,20 +578,11 @@ void virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb) } } -static void virtio_blk_handle_output (VirtIODevice *vdev,VirtQueue *vq) +void virtio_blk_handle_vq (VirtIOBlock *s,VirtQueue *vq) { -VirtIOBlock *s =VIRTIO_BLK (vdev);VirtIOBlockReq *req;MultiReqBuffer mrb = {}; -/* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start -* dataplane here instead of waiting for .set_status(). -*/ -if (s->dataplane && !s->dataplane_started) { -virtio_blk_data_plane_start (s->dataplane); -return ; - } -blk_io_plug (s->blk);while ((req =virtio_blk_get_request (s))) {
@@ -605,6 +596,22 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)blk_io_unplug (s->blk); } +static void virtio_blk_handle_output (VirtIODevice *vdev,VirtQueue *vq) +{ +VirtIOBlock *s = (VirtIOBlock *)vdev; + +if (s->dataplane) { +/* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start +* dataplane here instead of waiting for .set_status(). +*/ +virtio_blk_data_plane_start (s->dataplane); +if (!s->dataplane_disabled) { +return ; + } + } +virtio_blk_handle_vq (s, vq); +} +static void virtio_blk_dma_restart_bh (void *opaque) {VirtIOBlock *s = opaque;
Signature · 1 line
MST
[Qemu-devel] [PULL 14/15] virtio: merge virtio_queue_aio_set_host_notifier_handler with virtio_queue_set_aio
In reply to Michael S. TsirkinFrom: Paolo Bonzini <[email protected]>
Eliminating the reentrancy is actually a nice thing that we can do with the API that Michael proposed, so let's make it first class. This also hides the complex assign/set_handler conventions from callers of virtio_queue_aio_set_host_notifier_handler, which in fact was always called with assign=true.
--- include/hw/virtio/virtio.h | 6 ++---- hw/block/dataplane/virtio-blk.c | 7 +++---- hw/scsi/virtio-scsi-dataplane.c | 12 ++++-------- hw/virtio/virtio.c | 17 +++++------------ 4 files changed, 14 insertions(+), 28 deletions(-)
include/hw/virtio/virtio.h +2 -4
@@ -142,9 +142,6 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,void (*handle_output)(VirtIODevice *, VirtQueue *)); -void virtio_set_queue_aio (VirtQueue *vq, -void (*handle_output)(VirtIODevice *,VirtQueue *)); -void virtio_del_queue (VirtIODevice *vdev,int n);void *virtqueue_alloc_element (size_t sz,unsigned out_num,unsigned in_num);
@@ -254,7 +251,8 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq);void virtio_queue_set_host_notifier_fd_handler (VirtQueue *vq,bool assign,bool set_handler);void virtio_queue_aio_set_host_notifier_handler (VirtQueue *vq,AioContext *ctx, -bool assign,bool set_handler); +void (*fn)(VirtIODevice *, +VirtQueue *));void virtio_irq (VirtQueue *vq);VirtQueue *virtio_vector_first_queue (VirtIODevice *vdev,uint16_t vector);VirtQueue *virtio_vector_next_queue (VirtQueue *vq);
hw/block/dataplane/virtio-blk.c +3 -4
@@ -237,8 +237,8 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)/* Get this show started by hooking up our callbacks */ aio_context_acquire (s->ctx); -virtio_set_queue_aio (s->vq, virtio_blk_data_plane_handle_output); -virtio_queue_aio_set_host_notifier_handler (s->vq, s->ctx, true, true); +virtio_queue_aio_set_host_notifier_handler (s->vq, s->ctx, + virtio_blk_data_plane_handle_output);aio_context_release (s->ctx);return ;
@@ -273,8 +273,7 @@ void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s)aio_context_acquire (s->ctx);/* Stop notifications for new requests from guest */ -virtio_queue_aio_set_host_notifier_handler (s->vq, s->ctx, false, false); -virtio_set_queue_aio (s->vq,NULL ); +virtio_queue_aio_set_host_notifier_handler (s->vq, s->ctx,NULL );/* Drain and switch bs back to the QEMU main loop */ blk_set_aio_context (s->conf->conf.blk,qemu_get_aio_context ());
hw/scsi/virtio-scsi-dataplane.c +4 -8
@@ -81,8 +81,7 @@ static int virtio_scsi_vring_init(VirtIOSCSI *s, VirtQueue *vq, int n,return rc; } -virtio_queue_aio_set_host_notifier_handler (vq, s->ctx, true, true); -virtio_set_queue_aio (vq, fn); +virtio_queue_aio_set_host_notifier_handler (vq, s->ctx, fn);return 0 ; }
@@ -99,13 +98,10 @@ static void virtio_scsi_clear_aio(VirtIOSCSI *s)VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (s);int i; -virtio_queue_aio_set_host_notifier_handler (vs->ctrl_vq, s->ctx, false, false); -virtio_set_queue_aio (vs->ctrl_vq,NULL ); -virtio_queue_aio_set_host_notifier_handler (vs->event_vq, s->ctx, false, false); -virtio_set_queue_aio (vs->event_vq,NULL ); +virtio_queue_aio_set_host_notifier_handler (vs->ctrl_vq, s->ctx,NULL ); +virtio_queue_aio_set_host_notifier_handler (vs->event_vq, s->ctx,NULL );for (i =0 ; i < vs->conf.num_queues; i++) { -virtio_queue_aio_set_host_notifier_handler (vs->cmd_vqs[i], s->ctx, false, false); -virtio_set_queue_aio (vs->cmd_vqs[i],NULL ); +virtio_queue_aio_set_host_notifier_handler (vs->cmd_vqs[i], s->ctx,NULL ); } }
hw/virtio/virtio.c +5 -12
@@ -1159,14 +1159,6 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,return &vdev->vq[i]; } -void virtio_set_queue_aio (VirtQueue *vq, -void (*handle_output)(VirtIODevice *,VirtQueue *)) -{ -assert (vq->handle_output); - - vq->handle_aio_output = handle_output; -} -void virtio_del_queue (VirtIODevice *vdev,int n) {if (n <0 || n >=VIRTIO_QUEUE_MAX ) {
@@ -1809,18 +1801,19 @@ static void virtio_queue_host_notifier_aio_read(EventNotifier *n) }void virtio_queue_aio_set_host_notifier_handler (VirtQueue *vq,AioContext *ctx, -bool assign,bool set_handler) +void (*handle_output)(VirtIODevice *, +VirtQueue *)) { -if (assign && set_handler) { +if (handle_output) { + vq->handle_aio_output = handle_output;aio_set_event_notifier (ctx, &vq->host_notifier, true, virtio_queue_host_notifier_aio_read); }else {aio_set_event_notifier (ctx, &vq->host_notifier, true,NULL ); - } -if (!assign) {/* Test and clear notifier before after disabling event, * in case poll callback didn't have time to run. */ virtio_queue_host_notifier_aio_read (&vq->host_notifier); + vq->handle_aio_output =NULL ; } }
Signature · 1 line
MST
Peter Maydell
AppliedQuoted 15 lines · Michael S. Tsirkin
The following changes since commit
7acbff99c6c285b3070bf0e768d56f511e2bf346:Update version for v2.6.0-rc1 release (2016-04-05 21:53:18 +0100)
are available in the git repository at:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.gittags/for_upstreamfor you to fetch changes up to
2e4278b534997d8f33a6e8b7923c168f5e5c89c7:hw/pci-bridge: Add missing unref in case register-bus fails (2016-04-07 19:57:33 +0300)
----------------------------------------------------------------
pci, virtio, acpi: fixes for 2.6
Quoted 7 lines
Fixes all over the place. Most notably, fixes migration for systems with pci express bridges, and random crashes observed with virtio blk and scsi dataplane.
Signed-off-by Michael S. Tsirkin <[email protected]>----------------------------------------------------------------
Applied, thanks.
-- PMM