Skip to contentSkip to conversation

virtio, pc: fixes, features

GIT PULL Applied Michael S. Tsirkin 6 participants 41 messages Mar 2, 2017 – Apr 13, 2017

lore
Share & tools
lore
#0 lore raw

The following changes since commit 1e0addb682c3c552fd97480037d4f8ff18e2b87e:

Merge remote-tracking branch 'remotes/sstabellini/tags/xen-20170228-tag' into staging (2017-03-01 20:33:47 +0000)

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 077dd74239a99f6c1e77c5c1aa24cfc7f58cd20c:

hw/pxb-pcie: fix PCI Express hotplug support (2017-03-02 07:31:26 +0200)

----------------------------------------------------------------
virtio, pc: fixes, features

virtio support for region caches broke a bunch of stuff - fixing most of it though it's not ideal. Still pondering the right way to fix it.
New: VM gen ID and hotplug for PXB.

----------------------------------------------------------------
Ben Warren (6):
linker-loader: Add new 'write pointer' command
docs: VM Generation ID device description
ACPI: Add vmgenid blob storage to the build tables
ACPI: Add Virtual Machine Generation ID support
tests: Move reusable ACPI code into a utility file
MAINTAINERS: Add VM Generation ID entries

Cornelia Huck (1):
virtio: guard vring access when setting notification

Igor Mammedov (1):
qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands

Jason Wang (1):
virtio: unbreak virtio-pci with IOMMU after caching ring translations

Marcel Apfelbaum (1):
hw/pxb-pcie: fix PCI Express hotplug support

Michael S. Tsirkin (2):
acpi: simplify _OSC
tests/acpi: update DSDT after last patch

Paolo Bonzini (1):
virtio: check for vring setup in virtio_queue_empty

Stefan Hajnoczi (2):
virtio: invalidate memory in vring_set_avail_event()
virtio: add missing region cache init in virtio_load()

 docs/specs/vmgenid.txt               | 245 +++++++++++++++++++++++++++++++++
 default-configs/i386-softmmu.mak     |   1 +
 default-configs/x86_64-softmmu.mak   |   1 +
 qapi-schema.json                     |  20 +++
 hmp.h                                |   1 +
 include/hw/acpi/acpi_dev_interface.h |   1 +
 include/hw/acpi/aml-build.h          |   1 +
 include/hw/acpi/bios-linker-loader.h |   7 +
 include/hw/acpi/vmgenid.h            |  35 +++++
 tests/acpi-utils.h                   |  94 +++++++++++++
 hmp.c                                |   9 ++
 hw/acpi/aml-build.c                  |   2 +
 hw/acpi/bios-linker-loader.c         |  66 ++++++++-
 hw/acpi/vmgenid.c                    | 258 +++++++++++++++++++++++++++++++++++
 hw/i386/acpi-build.c                 |  24 +++-
 hw/virtio/virtio-pci.c               |   2 +-
 hw/virtio/virtio.c                   |  32 ++++-
 stubs/vmgenid.c                      |   9 ++
 tests/acpi-utils.c                   |  65 +++++++++
 tests/bios-tables-test.c             | 132 ++----------------
 MAINTAINERS                          |  11 ++
 dtc                                  |   2 +-
 hmp-commands-info.hx                 |  14 ++
 hw/acpi/Makefile.objs                |   1 +
 stubs/Makefile.objs                  |   1 +
 tests/Makefile.include               |   2 +-
 tests/acpi-test-data/q35/DSDT        | Bin 7860 -> 7824 bytes
 tests/acpi-test-data/q35/DSDT.bridge | Bin 7877 -> 7841 bytes
 tests/acpi-test-data/q35/DSDT.cphp   | Bin 8323 -> 8287 bytes
 tests/acpi-test-data/q35/DSDT.ipmibt | Bin 7935 -> 7899 bytes
 tests/acpi-test-data/q35/DSDT.memhp  | Bin 9225 -> 9189 bytes
 31 files changed, 902 insertions(+), 134 deletions(-)
 create mode 100644 docs/specs/vmgenid.txt
 create mode 100644 include/hw/acpi/vmgenid.h
 create mode 100644 tests/acpi-utils.h
 create mode 100644 hw/acpi/vmgenid.c
 create mode 100644 stubs/vmgenid.c
 create mode 100644 tests/acpi-utils.c
#1 lore raw

[Qemu-devel] [PULL 01/15] linker-loader: Add new 'write pointer' command

From: Ben Warren <[email protected]>

This is similar to the existing 'add pointer' functionality, but instead of instructing the guest (BIOS or UEFI) to patch memory, it instructs the guest to write the pointer back to QEMU via a writeable fw_cfg file.

---
 include/hw/acpi/bios-linker-loader.h |  7 ++++
 hw/acpi/bios-linker-loader.c         | 66 ++++++++++++++++++++++++++++++++++--
 2 files changed, 70 insertions(+), 3 deletions(-)
include/hw/acpi/bios-linker-loader.h +7 -0
index fa1e5d1..efe17b0 100644
@@ -26,5 +26,12 @@ void bios_linker_loader_add_pointer(BIOSLinker *linker,
                                     const char *src_file,
                                     uint32_t src_offset);
 
+void bios_linker_loader_write_pointer(BIOSLinker *linker,
+                                      const char *dest_file,
+                                      uint32_t dst_patched_offset,
+                                      uint8_t dst_patched_size,
+                                      const char *src_file,
+                                      uint32_t src_offset);
+
 void bios_linker_loader_cleanup(BIOSLinker *linker);
 #endif
hw/acpi/bios-linker-loader.c +63 -3

81 lines not on this page · raw message

Signature · 1 line
MST
#2 lore raw

[Qemu-devel] [PULL 02/15] docs: VM Generation ID device description

In reply to Michael S. Tsirkin

From: Ben Warren <[email protected]>

This patch is based off an earlier version by
Gal Hammer ([email protected])

Requirements section, ASCII diagrams and overall help provided by Laszlo Ersek ([email protected])

---
 docs/specs/vmgenid.txt | 245 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 245 insertions(+)
 create mode 100644 docs/specs/vmgenid.txt
docs/specs/vmgenid.txt new file +245 -0
new file mode 100644
index 0000000..aa9f518
@@ -0,0 +1,245 @@
+VIRTUAL MACHINE GENERATION ID
+=============================
+
+Copyright (C) 2016 Red Hat, Inc.
+Copyright (C) 2017 Skyport Systems, Inc.
+
+This work is licensed under the terms of the GNU GPL, version 2 or later.
+See the COPYING file in the top-level directory.
+
+===
+
+The VM generation ID (vmgenid) device is an emulated device which
+exposes a 128-bit, cryptographically random, integer value identifier,
+referred to as a Globally Unique Identifier, or GUID.
+
+This allows management applications (e.g. libvirt) to notify the guest
+operating system when the virtual machine is executed with a different
+configuration (e.g. snapshot execution or creation from a template).  The
+guest operating system notices the change, and is then able to react as
+appropriate by marking its copies of distributed databases as dirty,
+re-initializing its random number generator etc.
+
+
+Requirements
+------------
+
+These requirements are extracted from the "How to implement virtual machine
+generation ID support in a virtualization platform" section of the
+specification, dated August 1, 2012.
+
+
+The document may be found on the web at:
+  http://go.microsoft.com/fwlink/?LinkId=260709
+
+R1a. The generation ID shall live in an 8-byte aligned buffer.
+
+R1b. The buffer holding the generation ID shall be in guest RAM, ROM, or device
+     MMIO range.
+
+R1c. The buffer holding the generation ID shall be kept separate from areas
+     used by the operating system.
+
+R1d. The buffer shall not be covered by an AddressRangeMemory or
+     AddressRangeACPI entry in the E820 or UEFI memory map.
+
+R1e. The generation ID shall not live in a page frame that could be mapped with
+     caching disabled. (In other words, regardless of whether the generation ID
+     lives in RAM, ROM or MMIO, it shall only be mapped as cacheable.)
+
+R2 to R5. [These AML requirements are isolated well enough in the Microsoft
+          specification for us to simply refer to them here.]
+
+R6. The hypervisor shall expose a _HID (hardware identifier) object in the
+    VMGenId device's scope that is unique to the hypervisor vendor.
+
+
+QEMU Implementation
+-------------------
+
+The above-mentioned specification does not dictate which ACPI descriptor table
+will contain the VM Generation ID device.  Other implementations (Hyper-V and
+Xen) put it in the main descriptor table (Differentiated System Description
+Table or DSDT).  For ease of debugging and implementation, we have decided to
+put it in its own Secondary System Description Table, or SSDT.
+
+The following is a dump of the contents from a running system:
+
+# iasl -p ./SSDT -d /sys/firmware/acpi/tables/SSDT
+
+Intel ACPI Component Architecture
+ASL+ Optimizing Compiler version 20150717-64
+Copyright (c) 2000 - 2015 Intel Corporation
+
+Reading ACPI table from file /sys/firmware/acpi/tables/SSDT - Length
+00000198 (0x0000C6)
+ACPI: SSDT 0x0000000000000000 0000C6 (v01 BOCHS  VMGENID  00000001 BXPC
+00000001)
+Acpi table [SSDT] successfully installed and loaded
+Pass 1 parse of [SSDT]
+Pass 2 parse of [SSDT]
+Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)
+
+Parsing completed
+Disassembly completed
+ASL Output:    ./SSDT.dsl - 1631 bytes
+# cat SSDT.dsl
+/*
+ * Intel ACPI Component Architecture
+ * AML/ASL+ Disassembler version 20150717-64
+ * Copyright (c) 2000 - 2015 Intel Corporation
+ *
+ * Disassembling to symbolic ASL+ operators
+ *
+ * Disassembly of /sys/firmware/acpi/tables/SSDT, Sun Feb  5 00:19:37 2017
+ *
+ * Original Table Header:
+ *     Signature        "SSDT"
+ *     Length           0x000000CA (202)
+ *     Revision         0x01
+ *     Checksum         0x4B
+ *     OEM ID           "BOCHS "
+ *     OEM Table ID     "VMGENID"
+ *     OEM Revision     0x00000001 (1)
+ *     Compiler ID      "BXPC"
+ *     Compiler Version 0x00000001 (1)
+ */
+DefinitionBlock ("/sys/firmware/acpi/tables/SSDT.aml", "SSDT", 1, "BOCHS ",
+"VMGENID", 0x00000001)
+{
+    Name (VGIA, 0x07FFF000)
+    Scope (\_SB)
+    {
+        Device (VGEN)
+        {
+            Name (_HID, "QEMUVGID")  // _HID: Hardware ID
+            Name (_CID, "VM_Gen_Counter")  // _CID: Compatible ID
+            Name (_DDN, "VM_Gen_Counter")  // _DDN: DOS Device Name
+            Method (_STA, 0, NotSerialized)  // _STA: Status
+            {
+                Local0 = 0x0F
+                If ((VGIA == Zero))
+                {
+                    Local0 = Zero
+                }
+
+                Return (Local0)
+            }
+
+            Method (ADDR, 0, NotSerialized)
+            {
+                Local0 = Package (0x02) {}
+                Index (Local0, Zero) = (VGIA + 0x28)
+                Index (Local0, One) = Zero
+                Return (Local0)
+            }
+        }
+    }
+
+    Method (\_GPE._E05, 0, NotSerialized)  // _Exx: Edge-Triggered GPE
+    {
+        Notify (\_SB.VGEN, 0x80) // Status Change
+    }
+}
+
+
+Design Details:
+---------------
+
+Requirements R1a through R1e dictate that the memory holding the
+VM Generation ID must be allocated and owned by the guest firmware,
+in this case BIOS or UEFI.  However, to be useful, QEMU must be able to
+change the contents of the memory at runtime, specifically when starting a
+backed-up or snapshotted image.  In order to do this, QEMU must know the
+address that has been allocated.
+
+The mechanism chosen for this memory sharing is writeable fw_cfg blobs.
+These are data object that are visible to both QEMU and guests, and are
+addressable as sequential files.
+
+More information about fw_cfg can be found in "docs/specs/fw_cfg.txt"
+
+Two fw_cfg blobs are used in this case:
+
+/etc/vmgenid_guid - contains the actual VM Generation ID GUID
+                  - read-only to the guest
+/etc/vmgenid_addr - contains the address of the downloaded vmgenid blob
+                  - writeable by the guest
+
+
+QEMU sends the following commands to the guest at startup:
+
+1. Allocate memory for vmgenid_guid fw_cfg blob.
+2. Write the address of vmgenid_guid into the SSDT (VGIA ACPI variable as
+   shown above in the iasl dump).  Note that this change is not propagated
+   back to QEMU.
+3. Write the address of vmgenid_guid back to QEMU's copy of vmgenid_addr
+   via the fw_cfg DMA interface.
+
+After step 3, QEMU is able to update the contents of vmgenid_guid at will.
+
+Since BIOS or UEFI does not necessarily run when we wish to change the GUID,
+the value of VGIA is persisted via the VMState mechanism.
+
+As spelled out in the specification, any change to the GUID executes an
+ACPI notification.  The exact handler to use is not specified, so the vmgenid
+device uses the first unused one:  \_GPE._E05.
+
+
+Endian-ness Considerations:
+---------------------------
+
+Although not specified in Microsoft's document, it is assumed that the
+device is expected to use little-endian format.
+
+All GUID passed in via command line or monitor are treated as big-endian.
+GUID values displayed via monitor are shown in big-endian format.
+
+
+GUID Storage Format:
+--------------------
+
+In order to implement an OVMF "SDT Header Probe Suppressor", the contents of
+the vmgenid_guid fw_cfg blob are not simply a 128-bit GUID.  There is also
+significant padding in order to align and fill a memory page, as shown in the
+following diagram:
+
++----------------------------------+
+| SSDT with OEM Table ID = VMGENID |
++----------------------------------+
+| ...                              |       TOP OF PAGE
+| VGIA dword object ---------------|-----> +---------------------------+
+| ...                              |       | fw-allocated array for    |
+| _STA method referring to VGIA    |       | "etc/vmgenid_guid"        |
+| ...                              |       +---------------------------+
+| ADDR method referring to VGIA    |       |  0: OVMF SDT Header probe |
+| ...                              |       |     suppressor            |
++----------------------------------+       | 36: padding for 8-byte    |
+                                           |     alignment             |
+                                           | 40: GUID                  |
+                                           | 56: padding to page size  |
+                                           +---------------------------+
+                                           END OF PAGE
+
+
+Device Usage:
+-------------
+
+The device has one property, which may be only be set using the command line:
+
+  guid - sets the value of the GUID.  A special value "auto" instructs
+         QEMU to generate a new random GUID.
+
+For example:
+
+  QEMU  -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
+  QEMU  -device vmgenid,guid=auto
+
+The property may be queried via QMP/HMP:
+
+  (QEMU) query-vm-generation-id
+  {"return": {"guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}}
+
+Setting of this parameter is intentionally left out from the QMP/HMP
+interfaces.  There are no known use cases for changing the GUID once QEMU is
+running, and adding this capability would greatly increase the complexity.
Signature · 1 line
MST
#3 lore raw

Re: [Qemu-devel] [PULL 02/15] docs: VM Generation ID device description

Hi

Quoted 271 lines · Michael S. Tsirkin

From: Ben Warren <[email protected]>

This patch is based off an earlier version by
Gal Hammer ([email protected])

Requirements section, ASCII diagrams and overall help provided by Laszlo Ersek ([email protected])

---
 docs/specs/vmgenid.txt | 245
+++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 245 insertions(+)
 create mode 100644 docs/specs/vmgenid.txt
docs/specs/vmgenid.txt new file +27 -0
new file mode 100644
index 0000000..aa9f518
@@ -0,0 +1,245 @@
+VIRTUAL MACHINE GENERATION ID
+=============================
+
+Copyright (C) 2016 Red Hat, Inc.
+Copyright (C) 2017 Skyport Systems, Inc.
+
+This work is licensed under the terms of the GNU GPL, version 2 or later.
+See the COPYING file in the top-level directory.
+
+===
+
+The VM generation ID (vmgenid) device is an emulated device which
+exposes a 128-bit, cryptographically random, integer value identifier,
+referred to as a Globally Unique Identifier, or GUID.
+
+This allows management applications (e.g. libvirt) to notify the guest
+operating system when the virtual machine is executed with a different
+configuration (e.g. snapshot execution or creation from a template).  The
+guest operating system notices the change, and is then able to react as
+appropriate by marking its copies of distributed databases as dirty,
+re-initializing its random number generator etc.
+
+
+Requirements
+------------
+
+These requirements are extracted from the "How to implement virtual

machine

docs/specs/vmgenid.txt new file +10 -0
+generation ID support in a virtualization platform" section of the
+specification, dated August 1, 2012.
+
+
+The document may be found on the web at:
+  http://go.microsoft.com/fwlink/?LinkId=260709
+
+R1a. The generation ID shall live in an 8-byte aligned buffer.
+
+R1b. The buffer holding the generation ID shall be in guest RAM, ROM, or

device

docs/specs/vmgenid.txt new file +3 -0
+     MMIO range.
+
+R1c. The buffer holding the generation ID shall be kept separate from

areas

docs/specs/vmgenid.txt new file +6 -0
+     used by the operating system.
+
+R1d. The buffer shall not be covered by an AddressRangeMemory or
+     AddressRangeACPI entry in the E820 or UEFI memory map.
+
+R1e. The generation ID shall not live in a page frame that could be

mapped with
+ caching disabled. (In other words, regardless of whether the
generation ID

docs/specs/vmgenid.txt new file +3 -0
+     lives in RAM, ROM or MMIO, it shall only be mapped as cacheable.)
+
+R2 to R5. [These AML requirements are isolated well enough in the

Microsoft

docs/specs/vmgenid.txt new file +10 -0
+          specification for us to simply refer to them here.]
+
+R6. The hypervisor shall expose a _HID (hardware identifier) object in the
+    VMGenId device's scope that is unique to the hypervisor vendor.
+
+
+QEMU Implementation
+-------------------
+
+The above-mentioned specification does not dictate which ACPI descriptor

table
+will contain the VM Generation ID device. Other implementations (Hyper-V and
+Xen) put it in the main descriptor table (Differentiated System Description
+Table or DSDT). For ease of debugging and implementation, we have decided to

docs/specs/vmgenid.txt new file +44 -0
+put it in its own Secondary System Description Table, or SSDT.
+
+The following is a dump of the contents from a running system:
+
+# iasl -p ./SSDT -d /sys/firmware/acpi/tables/SSDT
+
+Intel ACPI Component Architecture
+ASL+ Optimizing Compiler version 20150717-64
+Copyright (c) 2000 - 2015 Intel Corporation
+
+Reading ACPI table from file /sys/firmware/acpi/tables/SSDT - Length
+00000198 (0x0000C6)
+ACPI: SSDT 0x0000000000000000 0000C6 (v01 BOCHS  VMGENID  00000001 BXPC
+00000001)
+Acpi table [SSDT] successfully installed and loaded
+Pass 1 parse of [SSDT]
+Pass 2 parse of [SSDT]
+Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)
+
+Parsing completed
+Disassembly completed
+ASL Output:    ./SSDT.dsl - 1631 bytes
+# cat SSDT.dsl
+/*
+ * Intel ACPI Component Architecture
+ * AML/ASL+ Disassembler version 20150717-64
+ * Copyright (c) 2000 - 2015 Intel Corporation
+ *
+ * Disassembling to symbolic ASL+ operators
+ *
+ * Disassembly of /sys/firmware/acpi/tables/SSDT, Sun Feb  5 00:19:37 2017
+ *
+ * Original Table Header:
+ *     Signature        "SSDT"
+ *     Length           0x000000CA (202)
+ *     Revision         0x01
+ *     Checksum         0x4B
+ *     OEM ID           "BOCHS "
+ *     OEM Table ID     "VMGENID"
+ *     OEM Revision     0x00000001 (1)
+ *     Compiler ID      "BXPC"
+ *     Compiler Version 0x00000001 (1)
+ */
+DefinitionBlock ("/sys/firmware/acpi/tables/SSDT.aml", "SSDT", 1, "BOCHS

",
+"VMGENID", 0x00000001)

docs/specs/vmgenid.txt new file +73 -0
+{
+    Name (VGIA, 0x07FFF000)
+    Scope (\_SB)
+    {
+        Device (VGEN)
+        {
+            Name (_HID, "QEMUVGID")  // _HID: Hardware ID
+            Name (_CID, "VM_Gen_Counter")  // _CID: Compatible ID
+            Name (_DDN, "VM_Gen_Counter")  // _DDN: DOS Device Name
+            Method (_STA, 0, NotSerialized)  // _STA: Status
+            {
+                Local0 = 0x0F
+                If ((VGIA == Zero))
+                {
+                    Local0 = Zero
+                }
+
+                Return (Local0)
+            }
+
+            Method (ADDR, 0, NotSerialized)
+            {
+                Local0 = Package (0x02) {}
+                Index (Local0, Zero) = (VGIA + 0x28)
+                Index (Local0, One) = Zero
+                Return (Local0)
+            }
+        }
+    }
+
+    Method (\_GPE._E05, 0, NotSerialized)  // _Exx: Edge-Triggered GPE
+    {
+        Notify (\_SB.VGEN, 0x80) // Status Change
+    }
+}
+
+
+Design Details:
+---------------
+
+Requirements R1a through R1e dictate that the memory holding the
+VM Generation ID must be allocated and owned by the guest firmware,
+in this case BIOS or UEFI.  However, to be useful, QEMU must be able to
+change the contents of the memory at runtime, specifically when starting a
+backed-up or snapshotted image.  In order to do this, QEMU must know the
+address that has been allocated.
+
+The mechanism chosen for this memory sharing is writeable fw_cfg blobs.
+These are data object that are visible to both QEMU and guests, and are
+addressable as sequential files.
+
+More information about fw_cfg can be found in "docs/specs/fw_cfg.txt"
+
+Two fw_cfg blobs are used in this case:
+
+/etc/vmgenid_guid - contains the actual VM Generation ID GUID
+                  - read-only to the guest
+/etc/vmgenid_addr - contains the address of the downloaded vmgenid blob
+                  - writeable by the guest
+
+
+QEMU sends the following commands to the guest at startup:
+
+1. Allocate memory for vmgenid_guid fw_cfg blob.
+2. Write the address of vmgenid_guid into the SSDT (VGIA ACPI variable as
+   shown above in the iasl dump).  Note that this change is not propagated
+   back to QEMU.
+3. Write the address of vmgenid_guid back to QEMU's copy of vmgenid_addr
+   via the fw_cfg DMA interface.
+
+After step 3, QEMU is able to update the contents of vmgenid_guid at will.
+
+Since BIOS or UEFI does not necessarily run when we wish to change the

GUID,

docs/specs/vmgenid.txt new file +4 -0
+the value of VGIA is persisted via the VMState mechanism.
+
+As spelled out in the specification, any change to the GUID executes an
+ACPI notification.  The exact handler to use is not specified, so the

vmgenid

docs/specs/vmgenid.txt new file +17 -0
+device uses the first unused one:  \_GPE._E05.
+
+
+Endian-ness Considerations:
+---------------------------
+
+Although not specified in Microsoft's document, it is assumed that the
+device is expected to use little-endian format.
+
+All GUID passed in via command line or monitor are treated as big-endian.
+GUID values displayed via monitor are shown in big-endian format.
+
+
+GUID Storage Format:
+--------------------
+
+In order to implement an OVMF "SDT Header Probe Suppressor", the contents

of

docs/specs/vmgenid.txt new file +2 -0
+the vmgenid_guid fw_cfg blob are not simply a 128-bit GUID.  There is also
+significant padding in order to align and fill a memory page, as shown in

the

docs/specs/vmgenid.txt new file +24 -0
+following diagram:
+
++----------------------------------+
+| SSDT with OEM Table ID = VMGENID |
++----------------------------------+
+| ...                              |       TOP OF PAGE
+| VGIA dword object ---------------|-----> +---------------------------+
+| ...                              |       | fw-allocated array for    |
+| _STA method referring to VGIA    |       | "etc/vmgenid_guid"        |
+| ...                              |       +---------------------------+
+| ADDR method referring to VGIA    |       |  0: OVMF SDT Header probe |
+| ...                              |       |     suppressor            |
++----------------------------------+       | 36: padding for 8-byte    |
+                                           |     alignment             |
+                                           | 40: GUID                  |
+                                           | 56: padding to page size  |
+                                           +---------------------------+
+                                           END OF PAGE
+
+
+Device Usage:
+-------------
+
+The device has one property, which may be only be set using the command

line:

docs/specs/vmgenid.txt line 236

Quoted 8 lines
docs/specs/vmgenid.txt new file +8 -0
+
+  guid - sets the value of the GUID.  A special value "auto" instructs
+         QEMU to generate a new random GUID.
+
+For example:
+
+  QEMU  -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
+  QEMU  -device vmgenid,guid=auto

The default will keep uuid to null, should it be documented? Wouldn't it make sense to default to auto?

Quoted 10 lines
docs/specs/vmgenid.txt new file +7 -0
+The property may be queried via QMP/HMP:
+
+  (QEMU) query-vm-generation-id
+  {"return": {"guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}}
+
+Setting of this parameter is intentionally left out from the QMP/HMP
+interfaces.  There are no known use cases for changing the GUID once QEMU

is
+running, and adding this capability would greatly increase the complexity.

Is this supposed to be not permitted?

{ "execute": "qom-set", "arguments": { "path":
"/machine/peripheral-anon/device[1]", "property": "guid", "value": "auto" } }

Is there any linux kernel support being worked on?

thanks

Signature · 1 line
Marc-André Lureau
#4 lore raw

Re: [Qemu-devel] [PULL 02/15] docs: VM Generation ID device description

Quoted 11 lines · Marc-André Lureau
Quoted 9 lines · Michael S. Tsirkin
docs/specs/vmgenid.txt new file +4 -0
+Device Usage:
+-------------
+
+The device has one property, which may be only be set using the command

line:

docs/specs/vmgenid.txt new file +4 -0
+
+  guid - sets the value of the GUID.  A special value "auto" instructs
+         QEMU to generate a new random GUID.
+
Quoted 8 lines

docs/specs/vmgenid.txt line 236

Quoted 5 lines
docs/specs/vmgenid.txt new file +4 -0
+For example:
+
+  QEMU  -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
+  QEMU  -device vmgenid,guid=auto

The default will keep uuid to null, should it be documented? Wouldn't it make sense to default to auto?

I guess it might.

Quoted 15 lines
Quoted 9 lines
docs/specs/vmgenid.txt new file +7 -0
+The property may be queried via QMP/HMP:
+
+  (QEMU) query-vm-generation-id
+  {"return": {"guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}}
+
+Setting of this parameter is intentionally left out from the QMP/HMP
+interfaces.  There are no known use cases for changing the GUID once QEMU
Quoted 3 lines

is
+running, and adding this capability would greatly increase the complexity.

Is this supposed to be not permitted?

Quoted 3 lines

{ "execute": "qom-set", "arguments": { "path":
"/machine/peripheral-anon/device[1]", "property": "guid", "value": "auto" } }

I don't know if qom-set can be disabled for individual devices / device properties. Either way, setting a new GUID for VMGENID will definitely take custom code.

Quoted 1 line

Is there any linux kernel support being worked on?

There's an RHBZ for it (alias "vmgenid-kernel"):

https://bugzilla.redhat.com/show_bug.cgi?id=1159983

(It is private because RHBZs for the kernel component are private by default.)

Thanks
Laszlo

#5 lore raw

Re: [Qemu-devel] [PULL 02/15] docs: VM Generation ID device description

In reply to Marc-André Lureau
Quoted 268 lines · Marc-André Lureau

Hi

On Thu, Mar 2, 2017 at 10:22 AM Michael S. Tsirkin <[email protected] <mailto:[email protected]>> wrote:
From: Ben Warren <[email protected] <mailto:[email protected]>>

This patch is based off an earlier version by
Gal Hammer ([email protected] <mailto:[email protected]>)

Requirements section, ASCII diagrams and overall help provided by Laszlo Ersek ([email protected] <mailto:[email protected]>)

Signed-off-by Gal Hammer <[email protected] <mailto:[email protected]>>
Signed-off-by Ben Warren <[email protected] <mailto:[email protected]>>
Reviewed-by Laszlo Ersek <[email protected] <mailto:[email protected]>>
Reviewed-by Igor Mammedov <[email protected] <mailto:[email protected]>>
Reviewed-by Michael S. Tsirkin <[email protected] <mailto:[email protected]>>
Signed-off-by Michael S. Tsirkin <[email protected] <mailto:[email protected]>>
---
 docs/specs/vmgenid.txt | 245 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 245 insertions(+)
 create mode 100644 docs/specs/vmgenid.txt
docs/specs/vmgenid.txt new file +236 -0
new file mode 100644
index 0000000..aa9f518
@@ -0,0 +1,245 @@
+VIRTUAL MACHINE GENERATION ID
+=============================
+
+Copyright (C) 2016 Red Hat, Inc.
+Copyright (C) 2017 Skyport Systems, Inc.
+
+This work is licensed under the terms of the GNU GPL, version 2 or later.
+See the COPYING file in the top-level directory.
+
+===
+
+The VM generation ID (vmgenid) device is an emulated device which
+exposes a 128-bit, cryptographically random, integer value identifier,
+referred to as a Globally Unique Identifier, or GUID.
+
+This allows management applications (e.g. libvirt) to notify the guest
+operating system when the virtual machine is executed with a different
+configuration (e.g. snapshot execution or creation from a template).  The
+guest operating system notices the change, and is then able to react as
+appropriate by marking its copies of distributed databases as dirty,
+re-initializing its random number generator etc.
+
+
+Requirements
+------------
+
+These requirements are extracted from the "How to implement virtual machine
+generation ID support in a virtualization platform" section of the
+specification, dated August 1, 2012.
+
+
+The document may be found on the web at:
+  http://go.microsoft.com/fwlink/?LinkId=260709 <http://go.microsoft.com/fwlink/?LinkId=260709>
+
+R1a. The generation ID shall live in an 8-byte aligned buffer.
+
+R1b. The buffer holding the generation ID shall be in guest RAM, ROM, or device
+     MMIO range.
+
+R1c. The buffer holding the generation ID shall be kept separate from areas
+     used by the operating system.
+
+R1d. The buffer shall not be covered by an AddressRangeMemory or
+     AddressRangeACPI entry in the E820 or UEFI memory map.
+
+R1e. The generation ID shall not live in a page frame that could be mapped with
+     caching disabled. (In other words, regardless of whether the generation ID
+     lives in RAM, ROM or MMIO, it shall only be mapped as cacheable.)
+
+R2 to R5. [These AML requirements are isolated well enough in the Microsoft
+          specification for us to simply refer to them here.]
+
+R6. The hypervisor shall expose a _HID (hardware identifier) object in the
+    VMGenId device's scope that is unique to the hypervisor vendor.
+
+
+QEMU Implementation
+-------------------
+
+The above-mentioned specification does not dictate which ACPI descriptor table
+will contain the VM Generation ID device.  Other implementations (Hyper-V and
+Xen) put it in the main descriptor table (Differentiated System Description
+Table or DSDT).  For ease of debugging and implementation, we have decided to
+put it in its own Secondary System Description Table, or SSDT.
+
+The following is a dump of the contents from a running system:
+
+# iasl -p ./SSDT -d /sys/firmware/acpi/tables/SSDT
+
+Intel ACPI Component Architecture
+ASL+ Optimizing Compiler version 20150717-64
+Copyright (c) 2000 - 2015 Intel Corporation
+
+Reading ACPI table from file /sys/firmware/acpi/tables/SSDT - Length
+00000198 (0x0000C6)
+ACPI: SSDT 0x0000000000000000 0000C6 (v01 BOCHS  VMGENID  00000001 BXPC
+00000001)
+Acpi table [SSDT] successfully installed and loaded
+Pass 1 parse of [SSDT]
+Pass 2 parse of [SSDT]
+Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)
+
+Parsing completed
+Disassembly completed
+ASL Output:    ./SSDT.dsl - 1631 bytes
+# cat SSDT.dsl
+/*
+ * Intel ACPI Component Architecture
+ * AML/ASL+ Disassembler version 20150717-64
+ * Copyright (c) 2000 - 2015 Intel Corporation
+ *
+ * Disassembling to symbolic ASL+ operators
+ *
+ * Disassembly of /sys/firmware/acpi/tables/SSDT, Sun Feb  5 00:19:37 2017
+ *
+ * Original Table Header:
+ *     Signature        "SSDT"
+ *     Length           0x000000CA (202)
+ *     Revision         0x01
+ *     Checksum         0x4B
+ *     OEM ID           "BOCHS "
+ *     OEM Table ID     "VMGENID"
+ *     OEM Revision     0x00000001 (1)
+ *     Compiler ID      "BXPC"
+ *     Compiler Version 0x00000001 (1)
+ */
+DefinitionBlock ("/sys/firmware/acpi/tables/SSDT.aml", "SSDT", 1, "BOCHS ",
+"VMGENID", 0x00000001)
+{
+    Name (VGIA, 0x07FFF000)
+    Scope (\_SB)
+    {
+        Device (VGEN)
+        {
+            Name (_HID, "QEMUVGID")  // _HID: Hardware ID
+            Name (_CID, "VM_Gen_Counter")  // _CID: Compatible ID
+            Name (_DDN, "VM_Gen_Counter")  // _DDN: DOS Device Name
+            Method (_STA, 0, NotSerialized)  // _STA: Status
+            {
+                Local0 = 0x0F
+                If ((VGIA == Zero))
+                {
+                    Local0 = Zero
+                }
+
+                Return (Local0)
+            }
+
+            Method (ADDR, 0, NotSerialized)
+            {
+                Local0 = Package (0x02) {}
+                Index (Local0, Zero) = (VGIA + 0x28)
+                Index (Local0, One) = Zero
+                Return (Local0)
+            }
+        }
+    }
+
+    Method (\_GPE._E05, 0, NotSerialized)  // _Exx: Edge-Triggered GPE
+    {
+        Notify (\_SB.VGEN, 0x80) // Status Change
+    }
+}
+
+
+Design Details:
+---------------
+
+Requirements R1a through R1e dictate that the memory holding the
+VM Generation ID must be allocated and owned by the guest firmware,
+in this case BIOS or UEFI.  However, to be useful, QEMU must be able to
+change the contents of the memory at runtime, specifically when starting a
+backed-up or snapshotted image.  In order to do this, QEMU must know the
+address that has been allocated.
+
+The mechanism chosen for this memory sharing is writeable fw_cfg blobs.
+These are data object that are visible to both QEMU and guests, and are
+addressable as sequential files.
+
+More information about fw_cfg can be found in "docs/specs/fw_cfg.txt"
+
+Two fw_cfg blobs are used in this case:
+
+/etc/vmgenid_guid - contains the actual VM Generation ID GUID
+                  - read-only to the guest
+/etc/vmgenid_addr - contains the address of the downloaded vmgenid blob
+                  - writeable by the guest
+
+
+QEMU sends the following commands to the guest at startup:
+
+1. Allocate memory for vmgenid_guid fw_cfg blob.
+2. Write the address of vmgenid_guid into the SSDT (VGIA ACPI variable as
+   shown above in the iasl dump).  Note that this change is not propagated
+   back to QEMU.
+3. Write the address of vmgenid_guid back to QEMU's copy of vmgenid_addr
+   via the fw_cfg DMA interface.
+
+After step 3, QEMU is able to update the contents of vmgenid_guid at will.
+
+Since BIOS or UEFI does not necessarily run when we wish to change the GUID,
+the value of VGIA is persisted via the VMState mechanism.
+
+As spelled out in the specification, any change to the GUID executes an
+ACPI notification.  The exact handler to use is not specified, so the vmgenid
+device uses the first unused one:  \_GPE._E05.
+
+
+Endian-ness Considerations:
+---------------------------
+
+Although not specified in Microsoft's document, it is assumed that the
+device is expected to use little-endian format.
+
+All GUID passed in via command line or monitor are treated as big-endian.
+GUID values displayed via monitor are shown in big-endian format.
+
+
+GUID Storage Format:
+--------------------
+
+In order to implement an OVMF "SDT Header Probe Suppressor", the contents of
+the vmgenid_guid fw_cfg blob are not simply a 128-bit GUID.  There is also
+significant padding in order to align and fill a memory page, as shown in the
+following diagram:
+
++----------------------------------+
+| SSDT with OEM Table ID = VMGENID |
++----------------------------------+
+| ...                              |       TOP OF PAGE
+| VGIA dword object ---------------|-----> +---------------------------+
+| ...                              |       | fw-allocated array for    |
+| _STA method referring to VGIA    |       | "etc/vmgenid_guid"        |
+| ...                              |       +---------------------------+
+| ADDR method referring to VGIA    |       |  0: OVMF SDT Header probe |
+| ...                              |       |     suppressor            |
++----------------------------------+       | 36: padding for 8-byte    |
+                                           |     alignment             |
+                                           | 40: GUID                  |
+                                           | 56: padding to page size  |
+                                           +---------------------------+
+                                           END OF PAGE
+
+
+Device Usage:
+-------------
+
+The device has one property, which may be only be set using the command line:
+
+  guid - sets the value of the GUID.  A special value "auto" instructs
+         QEMU to generate a new random GUID.
+
+For example:
+
+  QEMU  -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
+  QEMU  -device vmgenid,guid=auto
Quoted 1 line

The default will keep uuid to null, should it be documented? Wouldn't it make sense to default to auto?

There is no default - you have to supply a value. It’s up to whatever software is managing VM lifecycle to decide what value to pass in. Always setting to ‘auto’ will cause a lot of churn within Windows that may or may not be acceptable to your use case.

Quoted 10 lines
docs/specs/vmgenid.txt new file +8 -0
+The property may be queried via QMP/HMP:
+
+  (QEMU) query-vm-generation-id
+  {"return": {"guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}}
+
+Setting of this parameter is intentionally left out from the QMP/HMP
+interfaces.  There are no known use cases for changing the GUID once QEMU is
+running, and adding this capability would greatly increase the complexity.
Quoted 5 lines

Is this supposed to be not permitted?

{ "execute": "qom-set", "arguments": { "path": "/machine/peripheral-anon/device[1]", "property": "guid", "value": "auto" } }

Is there any linux kernel support being worked on?

This isn’t really relevant to the Linux kernel, at least in any way I can think of. What did you have in mind?

Quoted 4 lines

thanks

Signature · 1 line
Marc-André Lureau

—Ben

#6 lore raw

Re: [Qemu-devel] [PULL 02/15] docs: VM Generation ID device description

Hi

Quoted 18 lines · Ben Warren

On Apr 12, 2017, at 1:06 PM, Marc-André Lureau <[email protected]> wrote:

docs/specs/vmgenid.txt new file +4 -0
+Device Usage:
+-------------
+
+The device has one property, which may be only be set using the command

line:

docs/specs/vmgenid.txt new file +8 -0
+
+  guid - sets the value of the GUID.  A special value "auto" instructs
+         QEMU to generate a new random GUID.
+
+For example:
+
+  QEMU  -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
+  QEMU  -device vmgenid,guid=auto
Quoted 9 lines

The default will keep uuid to null, should it be documented? Wouldn't it make sense to default to auto?

There is no default - you have to supply a value. It’s up to whatever software is managing VM lifecycle to decide what value to pass in. Always setting to ‘auto’ will cause a lot of churn within Windows that may or may not be acceptable to your use case.

Why would you have a vmgenid device if it's always null? Does that please some windows use-cases as well?

Quoted 15 lines
docs/specs/vmgenid.txt new file +7 -0
+The property may be queried via QMP/HMP:
+
+  (QEMU) query-vm-generation-id
+  {"return": {"guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}}
+
+Setting of this parameter is intentionally left out from the QMP/HMP
+interfaces.  There are no known use cases for changing the GUID once QEMU

is
+running, and adding this capability would greatly increase the complexity.

Is this supposed to be not permitted?

Quoted 9 lines

{ "execute": "qom-set", "arguments": { "path":
"/machine/peripheral-anon/device[1]", "property": "guid", "value": "auto" } }

Is there any linux kernel support being worked on?

This isn’t really relevant to the Linux kernel, at least in any way I can think of. What did you have in mind?

Testing, but apparently we do have RFE for RHEL as Laszlo pointed out.

Thanks

Signature · 1 line
Marc-André Lureau
#7 lore raw

Re: [Qemu-devel] [PULL 02/15] docs: VM Generation ID device description

Quoted 21 lines · Marc-André Lureau

Hi

Quoted 15 lines · On Thu, Apr 13, 2017 at 12:17 AM Ben Warren <[email protected]…

On Apr 12, 2017, at 1:06 PM, Marc-André Lureau <[email protected] <mailto:[email protected]>> wrote:

docs/specs/vmgenid.txt new file +12 -0
+Device Usage:
+-------------
+
+The device has one property, which may be only be set using the command line:
+
+  guid - sets the value of the GUID.  A special value "auto" instructs
+         QEMU to generate a new random GUID.
+
+For example:
+
+  QEMU  -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
+  QEMU  -device vmgenid,guid=auto
Quoted 7 lines
Quoted 1 line

The default will keep uuid to null, should it be documented? Wouldn't it make sense to default to auto?

There is no default - you have to supply a value. It’s up to whatever software is managing VM lifecycle to decide what value to pass in. Always setting to ‘auto’ will cause a lot of churn within Windows that may or may not be acceptable to your use case.

Why would you have a vmgenid device if it's always null? Does that please some windows use-cases as well?

I don’t get what you mean by this. What device is always null? Either the device is instantiated or it isn’t. If not there, Windows will not find a device and I don’t know how derived objects (Invocation ID, etc.) are handled.

Quoted 12 lines
Quoted 12 lines
docs/specs/vmgenid.txt new file +8 -0
+The property may be queried via QMP/HMP:
+
+  (QEMU) query-vm-generation-id
+  {"return": {"guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}}
+
+Setting of this parameter is intentionally left out from the QMP/HMP
+interfaces.  There are no known use cases for changing the GUID once QEMU is
+running, and adding this capability would greatly increase the complexity.

Is this supposed to be not permitted?

Quoted 7 lines
Quoted 3 lines

{ "execute": "qom-set", "arguments": { "path": "/machine/peripheral-anon/device[1]", "property": "guid", "value": "auto" } }

Is there any linux kernel support being worked on?

This isn’t really relevant to the Linux kernel, at least in any way I can think of. What did you have in mind?

Testing, but apparently we do have RFE for RHEL as Laszlo pointed out.

OK, so you mean a guest driver. I do have one that needs work to go upstream, but has been helpful to me in testing.
https://github.com/ben-skyportsystems/vmgenid-test <https://github.com/ben-skyportsystems/vmgenid-test>

Quoted 4 lines

Thanks

Signature · 1 line
Marc-André Lureau
#8 lore raw

Re: [Qemu-devel] [PULL 02/15] docs: VM Generation ID device description

Hi

Quoted 35 lines · Ben Warren

On Apr 12, 2017, at 1:22 PM, Marc-André Lureau <[email protected]> wrote:

Hi

On Thu, Apr 13, 2017 at 12:17 AM Ben Warren <[email protected]> wrote:

On Apr 12, 2017, at 1:06 PM, Marc-André Lureau <[email protected]> wrote:

docs/specs/vmgenid.txt new file +4 -0
+Device Usage:
+-------------
+
+The device has one property, which may be only be set using the command

line:

docs/specs/vmgenid.txt new file +8 -0
+
+  guid - sets the value of the GUID.  A special value "auto" instructs
+         QEMU to generate a new random GUID.
+
+For example:
+
+  QEMU  -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
+  QEMU  -device vmgenid,guid=auto

The default will keep uuid to null, should it be documented? Wouldn't it make sense to default to auto?

There is no default - you have to supply a value. It’s up to whatever software is managing VM lifecycle to decide what value to pass in. Always setting to ‘auto’ will cause a lot of churn within Windows that may or may not be acceptable to your use case.

Quoted 9 lines

Why would you have a vmgenid device if it's always null? Does that please some windows use-cases as well?

I don’t get what you mean by this. What device is always null? Either the device is instantiated or it isn’t. If not there, Windows will not find a device and I don’t know how derived objects (Invocation ID, etc.) are handled.

If you start a VM without specifying guid argument, you'll always have a genid null uuid, event after a migration (this could have been handled by qemu without requiring management layer, no?). I don't understand why auto would create more churn than what the management layer would do by setting new uuid for each VM started. Could you explain?

Quoted 25 lines
docs/specs/vmgenid.txt new file +7 -0
+The property may be queried via QMP/HMP:
+
+  (QEMU) query-vm-generation-id
+  {"return": {"guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}}
+
+Setting of this parameter is intentionally left out from the QMP/HMP
+interfaces.  There are no known use cases for changing the GUID once QEMU

is
+running, and adding this capability would greatly increase the complexity.

Is this supposed to be not permitted?

{ "execute": "qom-set", "arguments": { "path":
"/machine/peripheral-anon/device[1]", "property": "guid", "value": "auto" } }

Is there any linux kernel support being worked on?

This isn’t really relevant to the Linux kernel, at least in any way I can think of. What did you have in mind?

Quoted 6 lines

Testing, but apparently we do have RFE for RHEL as Laszlo pointed out.

OK, so you mean a guest driver. I do have one that needs work to go upstream, but has been helpful to me in testing.
https://github.com/ben-skyportsystems/vmgenid-test

Thanks, that's exactly what I was looking for :)

Signature · 1 line
Marc-André Lureau
#9 lore raw

Re: [Qemu-devel] [PULL 02/15] docs: VM Generation ID device description

Quoted 31 lines · Marc-André Lureau

Hi

Quoted 25 lines · On Thu, Apr 13, 2017 at 12:25 AM Ben Warren <[email protected]…

On Apr 12, 2017, at 1:22 PM, Marc-André Lureau <[email protected] <mailto:[email protected]>> wrote:

Hi

Quoted 15 lines · On Thu, Apr 13, 2017 at 12:17 AM Ben Warren <[email protected]…

On Apr 12, 2017, at 1:06 PM, Marc-André Lureau <[email protected] <mailto:[email protected]>> wrote:

docs/specs/vmgenid.txt new file +12 -0
+Device Usage:
+-------------
+
+The device has one property, which may be only be set using the command line:
+
+  guid - sets the value of the GUID.  A special value "auto" instructs
+         QEMU to generate a new random GUID.
+
+For example:
+
+  QEMU  -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
+  QEMU  -device vmgenid,guid=auto
Quoted 1 line

The default will keep uuid to null, should it be documented? Wouldn't it make sense to default to auto?

There is no default - you have to supply a value. It’s up to whatever software is managing VM lifecycle to decide what value to pass in. Always setting to ‘auto’ will cause a lot of churn within Windows that may or may not be acceptable to your use case.

Quoted 7 lines
Quoted 2 lines

Why would you have a vmgenid device if it's always null? Does that please some windows use-cases as well?

I don’t get what you mean by this. What device is always null? Either the device is instantiated or it isn’t. If not there, Windows will not find a device and I don’t know how derived objects (Invocation ID, etc.) are handled.

If you start a VM without specifying guid argument, you'll always have a genid null uuid, event after a migration (this could have been handled by qemu without requiring management layer, no?). I don't understand why auto would create more churn than what the management layer would do by setting new uuid for each VM started. Could you explain?

Looks like there’s a bug. GUID should be a mandatory parameter. As for the churn, I’ll give you one example. If an Active Directory Domain Controller (ADDC) detects a change in VM Generation ID, it takes this to mean that the VM has been rolled back in time, and so its replication sequence numbers are “dirty”. This has the effect of causing the Domain controller to perform a full “pull replication” with other ADDCs. In large deployments this can be costly. VM Generation ID is used by other applications besides AD.

Quoted 19 lines
Quoted 19 lines
Quoted 11 lines
docs/specs/vmgenid.txt new file +8 -0
+The property may be queried via QMP/HMP:
+
+  (QEMU) query-vm-generation-id
+  {"return": {"guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}}
+
+Setting of this parameter is intentionally left out from the QMP/HMP
+interfaces.  There are no known use cases for changing the GUID once QEMU is
+running, and adding this capability would greatly increase the complexity.
Quoted 5 lines

Is this supposed to be not permitted?

{ "execute": "qom-set", "arguments": { "path": "/machine/peripheral-anon/device[1]", "property": "guid", "value": "auto" } }

Is there any linux kernel support being worked on?

This isn’t really relevant to the Linux kernel, at least in any way I can think of. What did you have in mind?

Quoted 6 lines
Quoted 1 line

Testing, but apparently we do have RFE for RHEL as Laszlo pointed out.

OK, so you mean a guest driver. I do have one that needs work to go upstream, but has been helpful to me in testing.
https://github.com/ben-skyportsystems/vmgenid-test <https://github.com/ben-skyportsystems/vmgenid-test>

Thanks, that's exactly what I was looking for :)

Good. I wish I had the time to integrate this upstream, but it’s one of those things that is good enough, and so will have to wait for another time.

Quoted 2 lines
Signature · 1 line
Marc-André Lureau
#10 lore raw

Re: [Qemu-devel] [PULL 02/15] docs: VM Generation ID device description

Hi

Quoted 53 lines · Ben Warren

On Apr 12, 2017, at 1:47 PM, Marc-André Lureau <[email protected]> wrote:

Hi

On Thu, Apr 13, 2017 at 12:25 AM Ben Warren <[email protected]> wrote:

On Apr 12, 2017, at 1:22 PM, Marc-André Lureau <[email protected]> wrote:

Hi

On Thu, Apr 13, 2017 at 12:17 AM Ben Warren <[email protected]> wrote:

On Apr 12, 2017, at 1:06 PM, Marc-André Lureau <[email protected]> wrote:

(quoted diff) +4 -0
+Device Usage:
+-------------
+
+The device has one property, which may be only be set using the command

line:

(quoted diff) +8 -0
+
+  guid - sets the value of the GUID.  A special value "auto" instructs
+         QEMU to generate a new random GUID.
+
+For example:
+
+  QEMU  -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
+  QEMU  -device vmgenid,guid=auto

The default will keep uuid to null, should it be documented? Wouldn't it make sense to default to auto?

There is no default - you have to supply a value. It’s up to whatever software is managing VM lifecycle to decide what value to pass in. Always setting to ‘auto’ will cause a lot of churn within Windows that may or may not be acceptable to your use case.

Why would you have a vmgenid device if it's always null? Does that please some windows use-cases as well?

I don’t get what you mean by this. What device is always null? Either the device is instantiated or it isn’t. If not there, Windows will not find a device and I don’t know how derived objects (Invocation ID, etc.) are handled.

Quoted 8 lines

If you start a VM without specifying guid argument, you'll always have a genid null uuid, event after a migration (this could have been handled by qemu without requiring management layer, no?). I don't understand why auto would create more churn than what the management layer would do by setting new uuid for each VM started. Could you explain?

Looks like there’s a bug. GUID should be a mandatory parameter.

Not necessarily a bug, if the guid can be changed when starting a "new" VM, which I think should work.

However, I didn't manage to get your driver noticing the acpi event. I tried to migrate/save & restore, and no vmgenid_notify kernel messages came out, nor notices got incremented. How did you test it?

Quoted 9 lines

As for the churn, I’ll give you one example. If an Active Directory Domain Controller (ADDC) detects a change in VM Generation ID, it takes this to mean that the VM has been rolled back in time, and so its replication sequence numbers are “dirty”. This has the effect of causing the Domain controller to perform a full “pull replication” with other ADDCs. In large deployments this can be costly. VM Generation ID is used by other applications besides AD.

I start to understand better the use case and how the device should be used.

thanks again

Quoted 36 lines
(quoted diff) +7 -0
+The property may be queried via QMP/HMP:
+
+  (QEMU) query-vm-generation-id
+  {"return": {"guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}}
+
+Setting of this parameter is intentionally left out from the QMP/HMP
+interfaces.  There are no known use cases for changing the GUID once QEMU

is
+running, and adding this capability would greatly increase the complexity.

Is this supposed to be not permitted?

{ "execute": "qom-set", "arguments": { "path":
"/machine/peripheral-anon/device[1]", "property": "guid", "value": "auto" } }

Is there any linux kernel support being worked on?

This isn’t really relevant to the Linux kernel, at least in any way I can think of. What did you have in mind?

Testing, but apparently we do have RFE for RHEL as Laszlo pointed out.

OK, so you mean a guest driver. I do have one that needs work to go upstream, but has been helpful to me in testing.
https://github.com/ben-skyportsystems/vmgenid-test

Thanks, that's exactly what I was looking for :)

Quoted 7 lines

Good. I wish I had the time to integrate this upstream, but it’s one of those things that is good enough, and so will have to wait for another time.

--
Marc-André Lureau

--

Marc-André Lureau

#11 lore raw

Re: [Qemu-devel] [PULL 02/15] docs: VM Generation ID device description

Quoted 70 lines · Marc-André Lureau

Hi

On Thu, Apr 13, 2017 at 1:03 AM Ben Warren <[email protected]> wrote:

On Apr 12, 2017, at 1:47 PM, Marc-André Lureau < [email protected]> wrote:

Hi

On Thu, Apr 13, 2017 at 12:25 AM Ben Warren <[email protected]> wrote:

On Apr 12, 2017, at 1:22 PM, Marc-André Lureau < [email protected]> wrote:

Hi

On Thu, Apr 13, 2017 at 12:17 AM Ben Warren < [email protected]> wrote:

On Apr 12, 2017, at 1:06 PM, Marc-André Lureau < [email protected]> wrote:

+Device Usage:
+-------------
+
+The device has one property, which may be only be set using the command line:
+
+  guid - sets the value of the GUID.  A special value "auto" instructs
+         QEMU to generate a new random GUID. +
+For example:
+
+  QEMU  -device vmgenid,guid= "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87" +  QEMU  -device vmgenid,guid=auto

The default will keep uuid to null, should it be documented? Wouldn't it make sense to default to auto?

There is no default - you have to supply a value. It’s up to whatever software is managing VM lifecycle to decide what value to pass in.  Always setting to ‘auto’ will cause a lot of churn within Windows that may or may not be acceptable to your use case.

Why would you have a vmgenid device if it's always null? Does that please some windows use-cases as well?

I don’t get what you mean by this.  What device is always null? Either the device is instantiated or it isn’t.  If not there, Windows will not find a device and I don’t know how derived objects (Invocation ID, etc.) are handled.

If you start a VM without specifying guid argument, you'll always have a genid null uuid, event after a migration (this could have been handled by qemu without requiring management layer, no?). I don't understand why auto would create more churn than what the management layer would do by setting new uuid for each VM started. Could you explain?

Quoted 5 lines

Looks like there’s a bug.  GUID should be a mandatory parameter.

Not necessarily a bug, if the guid can be changed when starting a "new" VM, which I think should work.

I think spec does not allow for a special "invalid" guid value ATM.

Quoted 71 lines

However, I didn't manage to get your driver noticing the acpi event. I tried to migrate/save & restore, and no vmgenid_notify kernel messages came out, nor notices got incremented. How did you test it?

As for the churn, I’ll give you one example.  If an Active Directory Domain Controller (ADDC) detects a change in VM Generation ID, it takes this to mean that the VM has been rolled back in time, and so its replication sequence numbers are “dirty”.  This has the effect of causing the Domain controller to perform a full “pull replication” with other ADDCs.  In large deployments this can be costly.  VM Generation ID is used by other applications besides AD.

I start to understand better the use case and how the device should be used.
thanks again

+The property may be queried via QMP/HMP:
+
+  (QEMU) query-vm-generation-id
+  {"return": {"guid":
"324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}} +
+Setting of this parameter is intentionally left out from the QMP/HMP
+interfaces.  There are no known use cases for changing the GUID once QEMU is +running, and adding this capability would greatly increase the complexity.


Is this supposed to be not permitted?

{ "execute": "qom-set", "arguments": { "path": "/ machine/peripheral-anon/device[1]", "property": "guid", "value": "auto" } }

Is there any linux kernel support being worked on?

This isn’t really relevant to the Linux kernel, at least in any way I can think of.  What did you have in mind?

Testing, but apparently we do have RFE for RHEL as Laszlo pointed out.

OK, so you mean a guest driver.  I do have one that needs work to go upstream, but has been helpful to me in testing.
https://github.com/ben-skyportsystems/vmgenid-test

Thanks, that's exactly what I was looking for :)

Good.  I wish I had the time to integrate this upstream, but it’s one of those things that is good enough, and so will have to wait for another time.

--
Marc-André Lureau

--
Marc-André Lureau

#12 lore raw

Re: [Qemu-devel] [PULL 02/15] docs: VM Generation ID device description

In reply to Marc-André Lureau

Hi

Quoted 66 lines · Marc-André Lureau

Hi

On Thu, Apr 13, 2017 at 1:03 AM Ben Warren <[email protected]> wrote:

On Apr 12, 2017, at 1:47 PM, Marc-André Lureau <[email protected]> wrote:

Hi

On Thu, Apr 13, 2017 at 12:25 AM Ben Warren <[email protected]> wrote:

On Apr 12, 2017, at 1:22 PM, Marc-André Lureau <[email protected]> wrote:

Hi

On Thu, Apr 13, 2017 at 12:17 AM Ben Warren <[email protected]> wrote:

On Apr 12, 2017, at 1:06 PM, Marc-André Lureau <[email protected]> wrote:

(quoted diff) +4 -0
+Device Usage:
+-------------
+
+The device has one property, which may be only be set using the command

line:

(quoted diff) +8 -0
+
+  guid - sets the value of the GUID.  A special value "auto" instructs
+         QEMU to generate a new random GUID.
+
+For example:
+
+  QEMU  -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
+  QEMU  -device vmgenid,guid=auto

The default will keep uuid to null, should it be documented? Wouldn't it make sense to default to auto?

There is no default - you have to supply a value. It’s up to whatever software is managing VM lifecycle to decide what value to pass in. Always setting to ‘auto’ will cause a lot of churn within Windows that may or may not be acceptable to your use case.

Why would you have a vmgenid device if it's always null? Does that please some windows use-cases as well?

I don’t get what you mean by this. What device is always null? Either the device is instantiated or it isn’t. If not there, Windows will not find a device and I don’t know how derived objects (Invocation ID, etc.) are handled.

If you start a VM without specifying guid argument, you'll always have a genid null uuid, event after a migration (this could have been handled by qemu without requiring management layer, no?). I don't understand why auto would create more churn than what the management layer would do by setting new uuid for each VM started. Could you explain?

Looks like there’s a bug. GUID should be a mandatory parameter.

Quoted 8 lines

Not necessarily a bug, if the guid can be changed when starting a "new" VM, which I think should work.

However, I didn't manage to get your driver noticing the acpi event. I tried to migrate/save & restore, and no vmgenid_notify kernel messages came out, nor notices got incremented. How did you test it?

Actually I was using an old bios, now I can change the guid and the guest notices the change.

{ "execute": "qom-set", "arguments": { "path":
"/machine/peripheral-anon/device[1]", "property": "guid", "value": "..." } }

works, the guest noticed the change and the new value can be read. I don't know what else would be required (except a better API) to allow QMP to modify it.

thanks

Signature · 1 line
Marc-André Lureau
#13 lore raw

Re: [Qemu-devel] [PULL 02/15] docs: VM Generation ID device description

In reply to Marc-André Lureau
Quoted 284 lines · Marc-André Lureau

Hi

On Thu, Mar 2, 2017 at 10:22 AM Michael S. Tsirkin <[email protected]> wrote:

From: Ben Warren <[email protected]>

This patch is based off an earlier version by
Gal Hammer ([email protected])

Requirements section, ASCII diagrams and overall help provided by Laszlo Ersek ([email protected])

---
 docs/specs/vmgenid.txt | 245
+++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 245 insertions(+)
 create mode 100644 docs/specs/vmgenid.txt

diff --git a/docs/specs/vmgenid.txt b/docs/specs/vmgenid.txt new file mode 100644
index 0000000..aa9f518
--- /dev/null
+++ b/docs/specs/vmgenid.txt
@@ -0,0 +1,245 @@
+VIRTUAL MACHINE GENERATION ID
+=============================
+
+Copyright (C) 2016 Red Hat, Inc.
+Copyright (C) 2017 Skyport Systems, Inc.
+
+This work is licensed under the terms of the GNU GPL, version 2 or later. +See the COPYING file in the top-level directory.
+
+===
+
+The VM generation ID (vmgenid) device is an emulated device which +exposes a 128-bit, cryptographically random, integer value identifier, +referred to as a Globally Unique Identifier, or GUID.
+
+This allows management applications (e.g. libvirt) to notify the guest +operating system when the virtual machine is executed with a different +configuration (e.g. snapshot execution or creation from a template).  The +guest operating system notices the change, and is then able to react as +appropriate by marking its copies of distributed databases as dirty, +re-initializing its random number generator etc.
+
+
+Requirements
+------------
+
+These requirements are extracted from the "How to implement virtual machine
+generation ID support in a virtualization platform" section of the +specification, dated August 1, 2012.
+
+
+The document may be found on the web at:
+  http://go.microsoft.com/fwlink/?LinkId=260709
+
+R1a. The generation ID shall live in an 8-byte aligned buffer. +
+R1b. The buffer holding the generation ID shall be in guest RAM, ROM, or device
+     MMIO range.
+
+R1c. The buffer holding the generation ID shall be kept separate from areas
+     used by the operating system.
+
+R1d. The buffer shall not be covered by an AddressRangeMemory or +     AddressRangeACPI entry in the E820 or UEFI memory map.
+
+R1e. The generation ID shall not live in a page frame that could be mapped with
+     caching disabled. (In other words, regardless of whether the generation ID
+     lives in RAM, ROM or MMIO, it shall only be mapped as cacheable.) +
+R2 to R5. [These AML requirements are isolated well enough in the Microsoft
+          specification for us to simply refer to them here.] +
+R6. The hypervisor shall expose a _HID (hardware identifier) object in the +    VMGenId device's scope that is unique to the hypervisor vendor. +
+
+QEMU Implementation
+-------------------
+
+The above-mentioned specification does not dictate which ACPI descriptor table
+will contain the VM Generation ID device.  Other implementations (Hyper-V and
+Xen) put it in the main descriptor table (Differentiated System Description
+Table or DSDT).  For ease of debugging and implementation, we have decided to
+put it in its own Secondary System Description Table, or SSDT. +
+The following is a dump of the contents from a running system:
+
+# iasl -p ./SSDT -d /sys/firmware/acpi/tables/SSDT
+
+Intel ACPI Component Architecture
+ASL+ Optimizing Compiler version 20150717-64
+Copyright (c) 2000 - 2015 Intel Corporation
+
+Reading ACPI table from file /sys/firmware/acpi/tables/SSDT - Length +00000198 (0x0000C6)
+ACPI: SSDT 0x0000000000000000 0000C6 (v01 BOCHS  VMGENID  00000001 BXPC +00000001)
+Acpi table [SSDT] successfully installed and loaded
+Pass 1 parse of [SSDT]
+Pass 2 parse of [SSDT]
+Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)
+
+Parsing completed
+Disassembly completed
+ASL Output:    ./SSDT.dsl - 1631 bytes
+# cat SSDT.dsl
+/*
+ * Intel ACPI Component Architecture
+ * AML/ASL+ Disassembler version 20150717-64
+ * Copyright (c) 2000 - 2015 Intel Corporation
+ *
+ * Disassembling to symbolic ASL+ operators
+ *
+ * Disassembly of /sys/firmware/acpi/tables/SSDT, Sun Feb  5 00:19:37 2017
+ *
+ * Original Table Header:
+ *     Signature        "SSDT"
+ *     Length           0x000000CA (202)
+ *     Revision         0x01
+ *     Checksum         0x4B
+ *     OEM ID           "BOCHS "
+ *     OEM Table ID     "VMGENID"
+ *     OEM Revision     0x00000001 (1)
+ *     Compiler ID      "BXPC"
+ *     Compiler Version 0x00000001 (1)
+ */
+DefinitionBlock ("/sys/firmware/acpi/tables/SSDT.aml", "SSDT", 1, "BOCHS ",
+"VMGENID", 0x00000001)
+{
+    Name (VGIA, 0x07FFF000)
+    Scope (\_SB)
+    {
+        Device (VGEN)
+        {
+            Name (_HID, "QEMUVGID")  // _HID: Hardware ID
+            Name (_CID, "VM_Gen_Counter")  // _CID: Compatible ID +            Name (_DDN, "VM_Gen_Counter")  // _DDN: DOS Device Name +            Method (_STA, 0, NotSerialized)  // _STA: Status +            {
+                Local0 = 0x0F
+                If ((VGIA == Zero))
+                {
+                    Local0 = Zero
+                }
+
+                Return (Local0)
+            }
+
+            Method (ADDR, 0, NotSerialized)
+            {
+                Local0 = Package (0x02) {}
+                Index (Local0, Zero) = (VGIA + 0x28)
+                Index (Local0, One) = Zero
+                Return (Local0)
+            }
+        }
+    }
+
+    Method (\_GPE._E05, 0, NotSerialized)  // _Exx: Edge-Triggered GPE +    {
+        Notify (\_SB.VGEN, 0x80) // Status Change
+    }
+}
+
+
+Design Details:
+---------------
+
+Requirements R1a through R1e dictate that the memory holding the +VM Generation ID must be allocated and owned by the guest firmware, +in this case BIOS or UEFI.  However, to be useful, QEMU must be able to +change the contents of the memory at runtime, specifically when starting a +backed-up or snapshotted image.  In order to do this, QEMU must know the +address that has been allocated.
+
+The mechanism chosen for this memory sharing is writeable fw_cfg blobs. +These are data object that are visible to both QEMU and guests, and are +addressable as sequential files.
+
+More information about fw_cfg can be found in "docs/specs/fw_cfg.txt" +
+Two fw_cfg blobs are used in this case:
+
+/etc/vmgenid_guid - contains the actual VM Generation ID GUID +                  - read-only to the guest
+/etc/vmgenid_addr - contains the address of the downloaded vmgenid blob +                  - writeable by the guest
+
+
+QEMU sends the following commands to the guest at startup:
+
+1. Allocate memory for vmgenid_guid fw_cfg blob.
+2. Write the address of vmgenid_guid into the SSDT (VGIA ACPI variable as +   shown above in the iasl dump).  Note that this change is not propagated +   back to QEMU.
+3. Write the address of vmgenid_guid back to QEMU's copy of vmgenid_addr +   via the fw_cfg DMA interface.
+
+After step 3, QEMU is able to update the contents of vmgenid_guid at will. +
+Since BIOS or UEFI does not necessarily run when we wish to change the GUID,
+the value of VGIA is persisted via the VMState mechanism.
+
+As spelled out in the specification, any change to the GUID executes an +ACPI notification.  The exact handler to use is not specified, so the vmgenid
+device uses the first unused one:  \_GPE._E05.
+
+
+Endian-ness Considerations:
+---------------------------
+
+Although not specified in Microsoft's document, it is assumed that the +device is expected to use little-endian format.
+
+All GUID passed in via command line or monitor are treated as big-endian. +GUID values displayed via monitor are shown in big-endian format. +
+
+GUID Storage Format:
+--------------------
+
+In order to implement an OVMF "SDT Header Probe Suppressor", the contents of
+the vmgenid_guid fw_cfg blob are not simply a 128-bit GUID.  There is also +significant padding in order to align and fill a memory page, as shown in the
+following diagram:
+
++----------------------------------+
+| SSDT with OEM Table ID = VMGENID |
++----------------------------------+
+| ...                              |       TOP OF PAGE
+| VGIA dword object ---------------|-----> +---------------------------+ +| ...                              |       | fw-allocated array for    | +| _STA method referring to VGIA    |       | "etc/vmgenid_guid"        | +| ...                              |       +---------------------------+ +| ADDR method referring to VGIA    |       |  0: OVMF SDT Header probe | +| ...                              |       |     suppressor            | ++----------------------------------+       | 36: padding for 8-byte    | +                                           |     alignment             | +                                           | 40: GUID                  | +                                           | 56: padding to page size  | +                                           +---------------------------+ +                                           END OF PAGE
+
+
+Device Usage:
+-------------
+
+The device has one property, which may be only be set using the command line:
+
+  guid - sets the value of the GUID.  A special value "auto" instructs +         QEMU to generate a new random GUID.
+
+For example:
+
+  QEMU  -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87" +  QEMU  -device vmgenid,guid=auto

Quoted 2 lines

The default will keep uuid to null, should it be documented? Wouldn't it make sense to default to auto?

Interesting. I'd say default should fail init.

Quoted 11 lines

+The property may be queried via QMP/HMP:
+
+  (QEMU) query-vm-generation-id
+  {"return": {"guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}} +
+Setting of this parameter is intentionally left out from the QMP/HMP +interfaces.  There are no known use cases for changing the GUID once QEMU is
+running, and adding this capability would greatly increase the complexity.

Quoted 5 lines


Is this supposed to be not permitted?

{ "execute": "qom-set", "arguments": { "path": "/machine/peripheral-anon/device [1]", "property": "guid", "value": "auto" } }

anon means in particular no stability.

Also we are yet to tie this to generate
an interrupt and update guest memory properly.
Patches welcome.

Quoted 1 line

Is there any linux kernel support being worked on?

I vaguely rememeber some patches but couldn't find them. An ACPI driver would be easy to implement, one thing to be careful about is to make sure all memory maps are cached as spec requires this.

Quoted 3 lines

thanks
--
Marc-André Lureau

#14 lore raw

[Qemu-devel] [PULL 03/15] ACPI: Add vmgenid blob storage to the build tables

In reply to Michael S. Tsirkin

From: Ben Warren <[email protected]>

This allows them to be centrally initialized and destroyed

The "AcpiBuildTables.vmgenid" array will be used to construct the "etc/vmgenid_guid" fw_cfg blob.

Its contents will be linked into fw_cfg after being built on the pc_machine_done() -> acpi_setup() -> acpi_build() call path, and dropped without use on the subsequent, guest triggered, acpi_build_update() -> acpi_build() call path.

---
 include/hw/acpi/aml-build.h | 1 +
 hw/acpi/aml-build.c         | 2 ++
 2 files changed, 3 insertions(+)
include/hw/acpi/aml-build.h +1 -0
index 559326c..00c21f1 100644
@@ -210,6 +210,7 @@ struct AcpiBuildTables {
     GArray *table_data;
     GArray *rsdp;
     GArray *tcpalog;
+    GArray *vmgenid;
     BIOSLinker *linker;
 } AcpiBuildTables;
 
hw/acpi/aml-build.c +2 -0
index b2a1e40..c6f2032 100644
@@ -1559,6 +1559,7 @@ void acpi_build_tables_init(AcpiBuildTables *tables)
     tables->rsdp = g_array_new(false, true /* clear */, 1);
     tables->table_data = g_array_new(false, true /* clear */, 1);
     tables->tcpalog = g_array_new(false, true /* clear */, 1);
+    tables->vmgenid = g_array_new(false, true /* clear */, 1);
     tables->linker = bios_linker_loader_init();
 }
 
@@ -1568,6 +1569,7 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)
     g_array_free(tables->rsdp, true);
     g_array_free(tables->table_data, true);
     g_array_free(tables->tcpalog, mfre);
+    g_array_free(tables->vmgenid, mfre);
 }
 
 /* Build rsdt table */
Signature · 1 line
MST
#15 lore raw

[Qemu-devel] [PULL 05/15] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands

In reply to Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

Add commands to query Virtual Machine Generation ID counter.

QMP command example:

    { "execute": "query-vm-generation-id" }

HMP command example:
info vm-generation-id

---
 qapi-schema.json     | 20 ++++++++++++++++++++
 hmp.h                |  1 +
 hmp.c                |  9 +++++++++
 hw/acpi/vmgenid.c    | 16 ++++++++++++++++
 stubs/vmgenid.c      |  9 +++++++++
 hmp-commands-info.hx | 14 ++++++++++++++
 stubs/Makefile.objs  |  1 +
 7 files changed, 70 insertions(+)
 create mode 100644 stubs/vmgenid.c
qapi-schema.json +20 -0
index d6186d4..84692da 100644
@@ -6188,3 +6188,23 @@
 #
 ##
 { 'command': 'query-hotpluggable-cpus', 'returns': ['HotpluggableCPU'] }
+
+##
+# @GuidInfo:
+#
+# GUID information.
+#
+# @guid: the globally unique identifier
+#
+# Since: 2.9
+##
+{ 'struct': 'GuidInfo', 'data': {'guid': 'str'} }
+
+##
+# @query-vm-generation-id:
+#
+# Show Virtual Machine Generation ID
+#
+# Since 2.9
+##
+{ 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }
hmp.h +1 -0
index 05daf7c..799fd37 100644
@@ -137,5 +137,6 @@ void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict);
 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict);
 void hmp_info_dump(Monitor *mon, const QDict *qdict);
 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict);
+void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict);
 
 #endif
hmp.c +9 -0
index 83e287e..aadbcf5 100644
@@ -2576,3 +2576,12 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
 
     qapi_free_HotpluggableCPUList(saved);
 }
+
+void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
+{
+    GuidInfo *info = qmp_query_vm_generation_id(NULL);
+    if (info) {
+        monitor_printf(mon, "%s\n", info->guid);
+    }
+    qapi_free_GuidInfo(info);
+}
hw/acpi/vmgenid.c +16 -0
index c8465df..744f284 100644
@@ -240,3 +240,19 @@ static void vmgenid_register_types(void)
 }
 
 type_init(vmgenid_register_types)
+
+GuidInfo *qmp_query_vm_generation_id(Error **errp)
+{
+    GuidInfo *info;
+    VmGenIdState *vms;
+    Object *obj = find_vmgenid_dev();
+
+    if (!obj) {
+        return NULL;
+    }
+    vms = VMGENID(obj);
+
+    info = g_malloc0(sizeof(*info));
+    info->guid = qemu_uuid_unparse_strdup(&vms->guid);
+    return info;
+}
stubs/vmgenid.c new file +9 -0
new file mode 100644
index 0000000..c64eb7a
@@ -0,0 +1,9 @@
+#include "qemu/osdep.h"
+#include "qmp-commands.h"
+#include "qapi/qmp/qerror.h"
+
+GuidInfo *qmp_query_vm_generation_id(Error **errp)
+{
+    error_setg(errp, QERR_UNSUPPORTED);
+    return NULL;
+}
hmp-commands-info.hx +14 -0
index b0f35e6..a53f105 100644
@@ -802,6 +802,20 @@ Show information about hotpluggable CPUs
 ETEXI
 
 STEXI
+@item info vm-generation-id
+@findex vm-generation-id
+Show Virtual Machine Generation ID
+ETEXI
+
+    {
+        .name       = "vm-generation-id",
+        .args_type  = "",
+        .params     = "",
+        .help       = "Show Virtual Machine Generation ID",
+        .cmd = hmp_info_vm_generation_id,
+    },
+
+STEXI
 @end table
 ETEXI
 
stubs/Makefile.objs +1 -0
index aa6050f..224f04b 100644
@@ -36,3 +36,4 @@ stub-obj-y += qmp_pc_dimm_device_list.o
 stub-obj-y += target-monitor-defs.o
 stub-obj-y += target-get-monitor-def.o
 stub-obj-y += pc_madt_cpu_entry.o
+stub-obj-y += vmgenid.o
Signature · 1 line
MST
#16 lore raw

Re: [Qemu-devel] [PULL 05/15] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands

Crash bug, I'm afraid...

Quoted 56 lines · Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

Add commands to query Virtual Machine Generation ID counter.

QMP command example:

    { "execute": "query-vm-generation-id" }

HMP command example:
info vm-generation-id

---
 qapi-schema.json     | 20 ++++++++++++++++++++
 hmp.h                |  1 +
 hmp.c                |  9 +++++++++
 hw/acpi/vmgenid.c    | 16 ++++++++++++++++
 stubs/vmgenid.c      |  9 +++++++++
 hmp-commands-info.hx | 14 ++++++++++++++
 stubs/Makefile.objs  |  1 +
 7 files changed, 70 insertions(+)
 create mode 100644 stubs/vmgenid.c
qapi-schema.json +20 -0
index d6186d4..84692da 100644
@@ -6188,3 +6188,23 @@
 #
 ##
 { 'command': 'query-hotpluggable-cpus', 'returns': ['HotpluggableCPU'] }
+
+##
+# @GuidInfo:
+#
+# GUID information.
+#
+# @guid: the globally unique identifier
+#
+# Since: 2.9
+##
+{ 'struct': 'GuidInfo', 'data': {'guid': 'str'} }
+
+##
+# @query-vm-generation-id:
+#
+# Show Virtual Machine Generation ID
+#
+# Since 2.9
+##
+{ 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }

[...]

Quoted 14 lines
hw/acpi/vmgenid.c +6 -0
index c8465df..744f284 100644
@@ -240,3 +240,19 @@ static void vmgenid_register_types(void)
 }
 
 type_init(vmgenid_register_types)
+
+GuidInfo *qmp_query_vm_generation_id(Error **errp)
+{
+    GuidInfo *info;
+    VmGenIdState *vms;
+    Object *obj = find_vmgenid_dev();

hw/acpi/vmgenid.c static void vmgenid_register_types(void) · line 258

Quoted 10 lines
hw/acpi/vmgenid.c +10 -0
+
+    if (!obj) {
+        return NULL;
+    }
+    vms = VMGENID(obj);
+
+    info = g_malloc0(sizeof(*info));
+    info->guid = qemu_uuid_unparse_strdup(&vms->guid);
+    return info;
+}

This either returns a GuidInfo or NULL.

If it returns NULL, the generated qmp_marshal_output_GuidInfo() will crash like this:

#0  0x00007fffdb4c7765 in raise () at /lib64/libc.so.6
#1  0x00007fffdb4c936a in abort () at /lib64/libc.so.6
#2  0x00007fffdb4bff97 in __assert_fail_base () at /lib64/libc.so.6
#3  0x00007fffdb4c0042 in  () at /lib64/libc.so.6
#4  0x0000555555c800a0 in visit_start_struct (v=
    0x555557727000, name=0x555555cf29e8 "unused", obj=0x7fffffffc7c8, size=8, errp=0x7fffffffc790) at /work/armbru/qemu/qapi/qapi-visit-core.c:49
#5  0x0000555555c5d398 in visit_type_GuidInfo (v=
    0x555557727000, name=0x555555cf29e8 "unused", obj=0x7fffffffc7c8, errp=0x7fffffffc7d8) at qapi-visit.c:6038
#6  0x0000555555922fc0 in qmp_marshal_output_GuidInfo (ret_in=0x0, ret_out=0x7fffffffc870, errp=0x7fffffffc820) at qmp-marshal.c:5148
#7  0x0000555555923123 in qmp_marshal_query_vm_generation_id (args=0x555557a67500, ret=0x7fffffffc870, errp=0x7fffffffc868) at qmp-marshal.c:5186
#8  0x0000555555c83a73 in do_qmp_dispatch (request=0x555556ab3200, errp=0x7fffffffc8c0) at /work/armbru/qemu/qapi/qmp-dispatch.c:97
#9  0x0000555555c83ba3 in qmp_dispatch (request=0x555556ab3200)
    at /work/armbru/qemu/qapi/qmp-dispatch.c:124
#10 0x00005555557bb671 in handle_qmp_command (parser=
    0x5555568776b0, tokens=0x555556858520) at /work/armbru/qemu/monitor.c:3789

#11 0x0000555555c8af2f in json_message_process_token (lexer=0x5555568776b8, input=0x5555568582e0, type=JSON_RCURLY, x=48, y=1)
at /work/armbru/qemu/qobject/json-streamer.c:105

Sorry for not having reviewed this earlier. On the other hand, how come this survived testing?

[...]

#17 lore raw

Re: [Qemu-devel] [PULL 05/15] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands

Quoted 106 lines · Markus Armbruster

Crash bug, I'm afraid...

Quoted 56 lines · Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

Add commands to query Virtual Machine Generation ID counter.

QMP command example:

    { "execute": "query-vm-generation-id" }

HMP command example:
info vm-generation-id

---
 qapi-schema.json     | 20 ++++++++++++++++++++
 hmp.h                |  1 +
 hmp.c                |  9 +++++++++
 hw/acpi/vmgenid.c    | 16 ++++++++++++++++
 stubs/vmgenid.c      |  9 +++++++++
 hmp-commands-info.hx | 14 ++++++++++++++
 stubs/Makefile.objs  |  1 +
 7 files changed, 70 insertions(+)
 create mode 100644 stubs/vmgenid.c
qapi-schema.json +20 -0
index d6186d4..84692da 100644
@@ -6188,3 +6188,23 @@
 #
 ##
 { 'command': 'query-hotpluggable-cpus', 'returns': ['HotpluggableCPU'] }
+
+##
+# @GuidInfo:
+#
+# GUID information.
+#
+# @guid: the globally unique identifier
+#
+# Since: 2.9
+##
+{ 'struct': 'GuidInfo', 'data': {'guid': 'str'} }
+
+##
+# @query-vm-generation-id:
+#
+# Show Virtual Machine Generation ID
+#
+# Since 2.9
+##
+{ 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }

[...]

Quoted 14 lines
hw/acpi/vmgenid.c +6 -0
index c8465df..744f284 100644
@@ -240,3 +240,19 @@ static void vmgenid_register_types(void)
 }
 
 type_init(vmgenid_register_types)
+
+GuidInfo *qmp_query_vm_generation_id(Error **errp)
+{
+    GuidInfo *info;
+    VmGenIdState *vms;
+    Object *obj = find_vmgenid_dev();

hw/acpi/vmgenid.c static void vmgenid_register_types(void) · line 258

Quoted 10 lines
hw/acpi/vmgenid.c +10 -0
+
+    if (!obj) {
+        return NULL;
+    }
+    vms = VMGENID(obj);
+
+    info = g_malloc0(sizeof(*info));
+    info->guid = qemu_uuid_unparse_strdup(&vms->guid);
+    return info;
+}

This either returns a GuidInfo or NULL.

If it returns NULL, the generated qmp_marshal_output_GuidInfo() will crash like this:

#0  0x00007fffdb4c7765 in raise () at /lib64/libc.so.6
#1  0x00007fffdb4c936a in abort () at /lib64/libc.so.6
#2  0x00007fffdb4bff97 in __assert_fail_base () at /lib64/libc.so.6
#3  0x00007fffdb4c0042 in  () at /lib64/libc.so.6
#4  0x0000555555c800a0 in visit_start_struct (v=
    0x555557727000, name=0x555555cf29e8 "unused", obj=0x7fffffffc7c8, size=8, errp=0x7fffffffc790) at /work/armbru/qemu/qapi/qapi-visit-core.c:49
#5  0x0000555555c5d398 in visit_type_GuidInfo (v=
    0x555557727000, name=0x555555cf29e8 "unused", obj=0x7fffffffc7c8, errp=0x7fffffffc7d8) at qapi-visit.c:6038
#6  0x0000555555922fc0 in qmp_marshal_output_GuidInfo (ret_in=0x0, ret_out=0x7fffffffc870, errp=0x7fffffffc820) at qmp-marshal.c:5148
#7  0x0000555555923123 in qmp_marshal_query_vm_generation_id (args=0x555557a67500, ret=0x7fffffffc870, errp=0x7fffffffc868) at qmp-marshal.c:5186
#8  0x0000555555c83a73 in do_qmp_dispatch (request=0x555556ab3200, errp=0x7fffffffc8c0) at /work/armbru/qemu/qapi/qmp-dispatch.c:97
#9  0x0000555555c83ba3 in qmp_dispatch (request=0x555556ab3200)
    at /work/armbru/qemu/qapi/qmp-dispatch.c:124
#10 0x00005555557bb671 in handle_qmp_command (parser=
    0x5555568776b0, tokens=0x555556858520) at /work/armbru/qemu/monitor.c:3789
Quoted 5 lines

#11 0x0000555555c8af2f in json_message_process_token (lexer=0x5555568776b8, input=0x5555568582e0, type=JSON_RCURLY, x=48, y=1)
at /work/armbru/qemu/qobject/json-streamer.c:105

Sorry for not having reviewed this earlier. On the other hand, how come this survived testing?

We primarily focused on testing the functionality, not the failure / corner cases, I think. (There are at least two other known startup scenarios that are not handled correctly just yet, although they don't crash -- multiple vmgenid devices, and vmgenid on machtypes without writeable fw_cfg.)

Also, in my testing I only called the monitor command via HMP (from virsh), and AFAICS that one doesn't crash even if the device is missing. Nonetheless, qmp_query_vm_generation_id() should set an error when it returns NULL, yes.

I think Ben wants to post a followup series with those fixes mentioned above, in time for 2.9, perhaps this crash can be addressed in there too. Ben?

Thanks
Laszlo

#18 lore raw

Re: [Qemu-devel] [PULL 05/15] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands

Quoted 119 lines · Laszlo Ersek
Quoted 106 lines · Markus Armbruster

Crash bug, I'm afraid...

Quoted 56 lines · Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

Add commands to query Virtual Machine Generation ID counter.

QMP command example:

    { "execute": "query-vm-generation-id" }

HMP command example:
info vm-generation-id

---
 qapi-schema.json     | 20 ++++++++++++++++++++
 hmp.h                |  1 +
 hmp.c                |  9 +++++++++
 hw/acpi/vmgenid.c    | 16 ++++++++++++++++
 stubs/vmgenid.c      |  9 +++++++++
 hmp-commands-info.hx | 14 ++++++++++++++
 stubs/Makefile.objs  |  1 +
 7 files changed, 70 insertions(+)
 create mode 100644 stubs/vmgenid.c
qapi-schema.json +20 -0
index d6186d4..84692da 100644
@@ -6188,3 +6188,23 @@
 #
 ##
 { 'command': 'query-hotpluggable-cpus', 'returns': ['HotpluggableCPU'] }
+
+##
+# @GuidInfo:
+#
+# GUID information.
+#
+# @guid: the globally unique identifier
+#
+# Since: 2.9
+##
+{ 'struct': 'GuidInfo', 'data': {'guid': 'str'} }
+
+##
+# @query-vm-generation-id:
+#
+# Show Virtual Machine Generation ID
+#
+# Since 2.9
+##
+{ 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }

[...]

Quoted 14 lines
hw/acpi/vmgenid.c +6 -0
index c8465df..744f284 100644
@@ -240,3 +240,19 @@ static void vmgenid_register_types(void)
 }
 
 type_init(vmgenid_register_types)
+
+GuidInfo *qmp_query_vm_generation_id(Error **errp)
+{
+    GuidInfo *info;
+    VmGenIdState *vms;
+    Object *obj = find_vmgenid_dev();

hw/acpi/vmgenid.c static void vmgenid_register_types(void) · line 258

Quoted 10 lines
hw/acpi/vmgenid.c +10 -0
+
+    if (!obj) {
+        return NULL;
+    }
+    vms = VMGENID(obj);
+
+    info = g_malloc0(sizeof(*info));
+    info->guid = qemu_uuid_unparse_strdup(&vms->guid);
+    return info;
+}

This either returns a GuidInfo or NULL.

If it returns NULL, the generated qmp_marshal_output_GuidInfo() will crash like this:

#0  0x00007fffdb4c7765 in raise () at /lib64/libc.so.6
#1  0x00007fffdb4c936a in abort () at /lib64/libc.so.6
#2  0x00007fffdb4bff97 in __assert_fail_base () at /lib64/libc.so.6
#3  0x00007fffdb4c0042 in  () at /lib64/libc.so.6
#4  0x0000555555c800a0 in visit_start_struct (v=
    0x555557727000, name=0x555555cf29e8 "unused", obj=0x7fffffffc7c8, size=8, errp=0x7fffffffc790) at /work/armbru/qemu/qapi/qapi-visit-core.c:49
#5  0x0000555555c5d398 in visit_type_GuidInfo (v=
    0x555557727000, name=0x555555cf29e8 "unused", obj=0x7fffffffc7c8, errp=0x7fffffffc7d8) at qapi-visit.c:6038
#6  0x0000555555922fc0 in qmp_marshal_output_GuidInfo (ret_in=0x0, ret_out=0x7fffffffc870, errp=0x7fffffffc820) at qmp-marshal.c:5148
#7  0x0000555555923123 in qmp_marshal_query_vm_generation_id (args=0x555557a67500, ret=0x7fffffffc870, errp=0x7fffffffc868) at qmp-marshal.c:5186
#8  0x0000555555c83a73 in do_qmp_dispatch (request=0x555556ab3200, errp=0x7fffffffc8c0) at /work/armbru/qemu/qapi/qmp-dispatch.c:97
#9  0x0000555555c83ba3 in qmp_dispatch (request=0x555556ab3200)
    at /work/armbru/qemu/qapi/qmp-dispatch.c:124
#10 0x00005555557bb671 in handle_qmp_command (parser=
    0x5555568776b0, tokens=0x555556858520) at /work/armbru/qemu/monitor.c:3789
Quoted 5 lines

#11 0x0000555555c8af2f in json_message_process_token (lexer=0x5555568776b8, input=0x5555568582e0, type=JSON_RCURLY, x=48, y=1)
at /work/armbru/qemu/qobject/json-streamer.c:105

Sorry for not having reviewed this earlier. On the other hand, how come this survived testing?

We primarily focused on testing the functionality, not the failure / corner cases, I think. (There are at least two other known startup scenarios that are not handled correctly just yet, although they don't crash -- multiple vmgenid devices, and vmgenid on machtypes without writeable fw_cfg.)

Quoted 8 lines

Also, in my testing I only called the monitor command via HMP (from virsh), and AFAICS that one doesn't crash even if the device is missing. Nonetheless, qmp_query_vm_generation_id() should set an error when it returns NULL, yes.

I think Ben wants to post a followup series with those fixes mentioned above, in time for 2.9, perhaps this crash can be addressed in there too. Ben?

Regarding your other email ("New QMP command without a test -> automatic NAK"), Ben did write a small test suite for this feature:

[Qemu-devel] [PATCH v8 7/8] tests: Add unit tests for the VM Generation
ID feature

and it contains a test called "/vmgenid/vmgenid/query-monitor".

That patch is not part of the pull request because the functional tests in the same suite only pass if you have an updated SeaBIOS blob in the tree as well. While the SeaBIOS patches have been committed, the update for the blob bundled with QEMU is still in progress. Thus the patch with the tests is being delayed.

So, it wasn't negligence, we simply missed this failure case because we were so focused on the long-awaited functionality. We didn't miss other failure cases that were a bit closer to the functionality.

BTW, now that I look at said "/vmgenid/vmgenid/query-monitor" test case, it also doesn't seem to catch this error -- the monitor command is apparently not called without the device present. So yeah, review focused specifically on QMP / QAPI bits is always welcome.

Thanks
Laszlo

#19 lore raw

Re: [Qemu-devel] [PULL 05/15] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands

Quoted 8 lines · Laszlo Ersek

On 03/02/17 09:25, Laszlo Ersek wrote:

Regarding your other email ("New QMP command without a test -> automatic NAK"), Ben did write a small test suite for this feature:

[Qemu-devel] [PATCH v8 7/8] tests: Add unit tests for the VM Generation
ID feature

Quoted 7 lines

and it contains a test called "/vmgenid/vmgenid/query-monitor".

That patch is not part of the pull request because the functional tests in the same suite only pass if you have an updated SeaBIOS blob in the tree as well. While the SeaBIOS patches have been committed, the update for the blob bundled with QEMU is still in progress. Thus the patch with the tests is being delayed.

Posting the testing part that depends on in-progress work only as RFC sounds like a perfectly acceptable case of the "not practical" exception mentioned "New QMP command without a test -> automatic NAK".

Quoted 7 lines

So, it wasn't negligence, we simply missed this failure case because we were so focused on the long-awaited functionality. We didn't miss other failure cases that were a bit closer to the functionality.

BTW, now that I look at said "/vmgenid/vmgenid/query-monitor" test case, it also doesn't seem to catch this error -- the monitor command is apparently not called without the device present.

I expect you to try to cover all QMP command error cases with automated tests. I don't expect you to always succeed. We're all human :)

Quoted 2 lines

So yeah, review
focused specifically on QMP / QAPI bits is always welcome.

It's a struggle, to be honest. Bits of QMP and QAPI are often buried deep in patches dealing with other stuff. QMP can usually be separated into its own patch, but QAPI is just infrastructure, it *wants* to be used.

#20 lore raw

Re: [Qemu-devel] [PULL 05/15] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands

In reply to Laszlo Ersek
Quoted 110 lines · Laszlo Ersek
Quoted 109 lines · Markus Armbruster

Crash bug, I'm afraid...

Quoted 56 lines · Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

Add commands to query Virtual Machine Generation ID counter.

QMP command example:

    { "execute": "query-vm-generation-id" }

HMP command example:
info vm-generation-id

---
 qapi-schema.json     | 20 ++++++++++++++++++++
 hmp.h                |  1 +
 hmp.c                |  9 +++++++++
 hw/acpi/vmgenid.c    | 16 ++++++++++++++++
 stubs/vmgenid.c      |  9 +++++++++
 hmp-commands-info.hx | 14 ++++++++++++++
 stubs/Makefile.objs  |  1 +
 7 files changed, 70 insertions(+)
 create mode 100644 stubs/vmgenid.c
qapi-schema.json +20 -0
index d6186d4..84692da 100644
@@ -6188,3 +6188,23 @@
 #
 ##
 { 'command': 'query-hotpluggable-cpus', 'returns': ['HotpluggableCPU'] }
+
+##
+# @GuidInfo:
+#
+# GUID information.
+#
+# @guid: the globally unique identifier
+#
+# Since: 2.9
+##
+{ 'struct': 'GuidInfo', 'data': {'guid': 'str'} }
+
+##
+# @query-vm-generation-id:
+#
+# Show Virtual Machine Generation ID
+#
+# Since 2.9
+##
+{ 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }

[...]

Quoted 14 lines
hw/acpi/vmgenid.c +6 -0
index c8465df..744f284 100644
@@ -240,3 +240,19 @@ static void vmgenid_register_types(void)
 }
 
 type_init(vmgenid_register_types)
+
+GuidInfo *qmp_query_vm_generation_id(Error **errp)
+{
+    GuidInfo *info;
+    VmGenIdState *vms;
+    Object *obj = find_vmgenid_dev();

hw/acpi/vmgenid.c static void vmgenid_register_types(void) · line 258

Quoted 10 lines
hw/acpi/vmgenid.c +10 -0
+
+    if (!obj) {
+        return NULL;
+    }
+    vms = VMGENID(obj);
+
+    info = g_malloc0(sizeof(*info));
+    info->guid = qemu_uuid_unparse_strdup(&vms->guid);
+    return info;
+}

This either returns a GuidInfo or NULL.

If it returns NULL, the generated qmp_marshal_output_GuidInfo() will crash like this:

#0  0x00007fffdb4c7765 in raise () at /lib64/libc.so.6
#1  0x00007fffdb4c936a in abort () at /lib64/libc.so.6
#2  0x00007fffdb4bff97 in __assert_fail_base () at /lib64/libc.so.6
#3  0x00007fffdb4c0042 in  () at /lib64/libc.so.6
#4  0x0000555555c800a0 in visit_start_struct (v=
    0x555557727000, name=0x555555cf29e8 "unused", obj=0x7fffffffc7c8, size=8, errp=0x7fffffffc790) at /work/armbru/qemu/qapi/qapi-visit-core.c:49
#5  0x0000555555c5d398 in visit_type_GuidInfo (v=
    0x555557727000, name=0x555555cf29e8 "unused", obj=0x7fffffffc7c8, errp=0x7fffffffc7d8) at qapi-visit.c:6038
#6  0x0000555555922fc0 in qmp_marshal_output_GuidInfo (ret_in=0x0, ret_out=0x7fffffffc870, errp=0x7fffffffc820) at qmp-marshal.c:5148
#7  0x0000555555923123 in qmp_marshal_query_vm_generation_id (args=0x555557a67500, ret=0x7fffffffc870, errp=0x7fffffffc868) at qmp-marshal.c:5186
#8  0x0000555555c83a73 in do_qmp_dispatch (request=0x555556ab3200, errp=0x7fffffffc8c0) at /work/armbru/qemu/qapi/qmp-dispatch.c:97
#9  0x0000555555c83ba3 in qmp_dispatch (request=0x555556ab3200)
    at /work/armbru/qemu/qapi/qmp-dispatch.c:124
#10 0x00005555557bb671 in handle_qmp_command (parser=
    0x5555568776b0, tokens=0x555556858520) at /work/armbru/qemu/monitor.c:3789

#11 0x0000555555c8af2f in json_message_process_token (lexer=0x5555568776b8, input=0x5555568582e0, type=JSON_RCURLY, x=48, y=1)
at /work/armbru/qemu/qobject/json-streamer.c:105

Quoted 5 lines
Quoted 2 lines

Sorry for not having reviewed this earlier. On the other hand, how come this survived testing?

We primarily focused on testing the functionality, not the failure / corner cases, I think.

That's as natural as it is wrong :)

I'm a lackluster tester myself. The only way I can bring myself to test systematically is write automated tests. Fortunately, our infrastructure for that is much better than it used to be. Our habits still seem to be trailing the infrastructure, though.

See also "New QMP command without a test -> automatic NAK", Message-ID:
<[email protected]>.

Quoted 7 lines

(There are at least two other known startup
scenarios that are not handled correctly just yet, although they don't crash -- multiple vmgenid devices, and vmgenid on machtypes without writeable fw_cfg.)

Also, in my testing I only called the monitor command via HMP (from virsh), and AFAICS that one doesn't crash even if the device is missing.

Correct.

Quoted 2 lines

Nonetheless, qmp_query_vm_generation_id() should set an error when it returns NULL, yes.

That's the obvious fix. It's a one-liner.

Quoted 3 lines

I think Ben wants to post a followup series with those fixes mentioned above, in time for 2.9, perhaps this crash can be addressed in there too. Ben?

Since the fix is a one-liner, I'd like you guys to consider respinning this pull request with the fix.

#21 lore raw

Re: [Qemu-devel] [PULL 05/15] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands

Quoted 141 lines · Markus Armbruster
Quoted 110 lines · Laszlo Ersek
Quoted 109 lines · Markus Armbruster

Crash bug, I'm afraid...

Quoted 56 lines · Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

Add commands to query Virtual Machine Generation ID counter.

QMP command example:

    { "execute": "query-vm-generation-id" }

HMP command example:
info vm-generation-id

---
 qapi-schema.json     | 20 ++++++++++++++++++++
 hmp.h                |  1 +
 hmp.c                |  9 +++++++++
 hw/acpi/vmgenid.c    | 16 ++++++++++++++++
 stubs/vmgenid.c      |  9 +++++++++
 hmp-commands-info.hx | 14 ++++++++++++++
 stubs/Makefile.objs  |  1 +
 7 files changed, 70 insertions(+)
 create mode 100644 stubs/vmgenid.c
qapi-schema.json +20 -0
index d6186d4..84692da 100644
@@ -6188,3 +6188,23 @@
 #
 ##
 { 'command': 'query-hotpluggable-cpus', 'returns': ['HotpluggableCPU'] }
+
+##
+# @GuidInfo:
+#
+# GUID information.
+#
+# @guid: the globally unique identifier
+#
+# Since: 2.9
+##
+{ 'struct': 'GuidInfo', 'data': {'guid': 'str'} }
+
+##
+# @query-vm-generation-id:
+#
+# Show Virtual Machine Generation ID
+#
+# Since 2.9
+##
+{ 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }

[...]

Quoted 14 lines
hw/acpi/vmgenid.c +6 -0
index c8465df..744f284 100644
@@ -240,3 +240,19 @@ static void vmgenid_register_types(void)
 }
 
 type_init(vmgenid_register_types)
+
+GuidInfo *qmp_query_vm_generation_id(Error **errp)
+{
+    GuidInfo *info;
+    VmGenIdState *vms;
+    Object *obj = find_vmgenid_dev();

hw/acpi/vmgenid.c static void vmgenid_register_types(void) · line 258

Quoted 10 lines
hw/acpi/vmgenid.c +10 -0
+
+    if (!obj) {
+        return NULL;
+    }
+    vms = VMGENID(obj);
+
+    info = g_malloc0(sizeof(*info));
+    info->guid = qemu_uuid_unparse_strdup(&vms->guid);
+    return info;
+}

This either returns a GuidInfo or NULL.

If it returns NULL, the generated qmp_marshal_output_GuidInfo() will crash like this:

#0  0x00007fffdb4c7765 in raise () at /lib64/libc.so.6
#1  0x00007fffdb4c936a in abort () at /lib64/libc.so.6
#2  0x00007fffdb4bff97 in __assert_fail_base () at /lib64/libc.so.6
#3  0x00007fffdb4c0042 in  () at /lib64/libc.so.6
#4  0x0000555555c800a0 in visit_start_struct (v=
    0x555557727000, name=0x555555cf29e8 "unused", obj=0x7fffffffc7c8, size=8, errp=0x7fffffffc790) at /work/armbru/qemu/qapi/qapi-visit-core.c:49
#5  0x0000555555c5d398 in visit_type_GuidInfo (v=
    0x555557727000, name=0x555555cf29e8 "unused", obj=0x7fffffffc7c8, errp=0x7fffffffc7d8) at qapi-visit.c:6038
#6  0x0000555555922fc0 in qmp_marshal_output_GuidInfo (ret_in=0x0, ret_out=0x7fffffffc870, errp=0x7fffffffc820) at qmp-marshal.c:5148
#7  0x0000555555923123 in qmp_marshal_query_vm_generation_id (args=0x555557a67500, ret=0x7fffffffc870, errp=0x7fffffffc868) at qmp-marshal.c:5186
#8  0x0000555555c83a73 in do_qmp_dispatch (request=0x555556ab3200, errp=0x7fffffffc8c0) at /work/armbru/qemu/qapi/qmp-dispatch.c:97
#9  0x0000555555c83ba3 in qmp_dispatch (request=0x555556ab3200)
    at /work/armbru/qemu/qapi/qmp-dispatch.c:124
#10 0x00005555557bb671 in handle_qmp_command (parser=
    0x5555568776b0, tokens=0x555556858520) at /work/armbru/qemu/monitor.c:3789

#11 0x0000555555c8af2f in json_message_process_token (lexer=0x5555568776b8, input=0x5555568582e0, type=JSON_RCURLY, x=48, y=1)
at /work/armbru/qemu/qobject/json-streamer.c:105

Quoted 5 lines
Quoted 2 lines

Sorry for not having reviewed this earlier. On the other hand, how come this survived testing?

We primarily focused on testing the functionality, not the failure / corner cases, I think.

That's as natural as it is wrong :)

I'm a lackluster tester myself. The only way I can bring myself to test systematically is write automated tests. Fortunately, our infrastructure for that is much better than it used to be. Our habits still seem to be trailing the infrastructure, though.

See also "New QMP command without a test -> automatic NAK", Message-ID:
<[email protected]>.

Quoted 7 lines

(There are at least two other known startup
scenarios that are not handled correctly just yet, although they don't crash -- multiple vmgenid devices, and vmgenid on machtypes without writeable fw_cfg.)

Also, in my testing I only called the monitor command via HMP (from virsh), and AFAICS that one doesn't crash even if the device is missing.

Correct.

Quoted 2 lines

Nonetheless, qmp_query_vm_generation_id() should set an error when it returns NULL, yes.

Quoted 8 lines

That's the obvious fix. It's a one-liner.

Quoted 3 lines

I think Ben wants to post a followup series with those fixes mentioned above, in time for 2.9, perhaps this crash can be addressed in there too. Ben?

Since the fix is a one-liner, I'd like you guys to consider respinning this pull request with the fix.

If Ben & Michael send out a new pull with the above fixed, I'd like to point out that the updated SeaBIOS blob is now in the tree (see commit 8779fccbef0c, "seabios: update to 1.10.2 release", 2017-02-28), so the unit test patch can be included as well.

Thanks
Laszlo

#22 lore raw

Re: [Qemu-devel] [PULL 05/15] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands

I

Quoted 150 lines · Laszlo Ersek
Quoted 147 lines · Markus Armbruster
Quoted 110 lines · Laszlo Ersek
Quoted 109 lines · Markus Armbruster

Crash bug, I'm afraid...

Quoted 56 lines · Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

Add commands to query Virtual Machine Generation ID counter.

QMP command example:

   { "execute": "query-vm-generation-id" }

HMP command example:
info vm-generation-id

---

qapi-schema.json     | 20 ++++++++++++++++++++
hmp.h                |  1 +
hmp.c                |  9 +++++++++
hw/acpi/vmgenid.c    | 16 ++++++++++++++++
stubs/vmgenid.c      |  9 +++++++++
hmp-commands-info.hx | 14 ++++++++++++++
stubs/Makefile.objs  |  1 +
7 files changed, 70 insertions(+)

create mode 100644 stubs/vmgenid.c

qapi-schema.json +20 -0
index d6186d4..84692da 100644
@@ -6188,3 +6188,23 @@
 #
 ##
 { 'command': 'query-hotpluggable-cpus', 'returns': ['HotpluggableCPU'] }
+
+##
+# @GuidInfo:
+#
+# GUID information.
+#
+# @guid: the globally unique identifier
+#
+# Since: 2.9
+##
+{ 'struct': 'GuidInfo', 'data': {'guid': 'str'} }
+
+##
+# @query-vm-generation-id:
+#
+# Show Virtual Machine Generation ID
+#
+# Since 2.9
+##
+{ 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }

[...]

Quoted 14 lines
hw/acpi/vmgenid.c +6 -0
index c8465df..744f284 100644
@@ -240,3 +240,19 @@ static void vmgenid_register_types(void)
 }
 
 type_init(vmgenid_register_types)
+
+GuidInfo *qmp_query_vm_generation_id(Error **errp)
+{
+    GuidInfo *info;
+    VmGenIdState *vms;
+    Object *obj = find_vmgenid_dev();

hw/acpi/vmgenid.c static void vmgenid_register_types(void) · line 258

Quoted 10 lines
hw/acpi/vmgenid.c +10 -0
+
+    if (!obj) {
+        return NULL;
+    }
+    vms = VMGENID(obj);
+
+    info = g_malloc0(sizeof(*info));
+    info->guid = qemu_uuid_unparse_strdup(&vms->guid);
+    return info;
+}

This either returns a GuidInfo or NULL.

If it returns NULL, the generated qmp_marshal_output_GuidInfo() will crash like this:

#0  0x00007fffdb4c7765 in raise () at /lib64/libc.so.6
#1  0x00007fffdb4c936a in abort () at /lib64/libc.so.6
#2  0x00007fffdb4bff97 in __assert_fail_base () at /lib64/libc.so.6
#3  0x00007fffdb4c0042 in  () at /lib64/libc.so.6
#4  0x0000555555c800a0 in visit_start_struct (v=
   0x555557727000, name=0x555555cf29e8 "unused", obj=0x7fffffffc7c8, size=8, errp=0x7fffffffc790) at /work/armbru/qemu/qapi/qapi-visit-core.c:49
#5  0x0000555555c5d398 in visit_type_GuidInfo (v=
   0x555557727000, name=0x555555cf29e8 "unused", obj=0x7fffffffc7c8, errp=0x7fffffffc7d8) at qapi-visit.c:6038
#6  0x0000555555922fc0 in qmp_marshal_output_GuidInfo (ret_in=0x0, ret_out=0x7fffffffc870, errp=0x7fffffffc820) at qmp-marshal.c:5148
#7  0x0000555555923123 in qmp_marshal_query_vm_generation_id (args=0x555557a67500, ret=0x7fffffffc870, errp=0x7fffffffc868) at qmp-marshal.c:5186
#8  0x0000555555c83a73 in do_qmp_dispatch (request=0x555556ab3200, errp=0x7fffffffc8c0) at /work/armbru/qemu/qapi/qmp-dispatch.c:97
#9  0x0000555555c83ba3 in qmp_dispatch (request=0x555556ab3200)

at /work/armbru/qemu/qapi/qmp-dispatch.c:124
#10 0x00005555557bb671 in handle_qmp_command (parser=
0x5555568776b0, tokens=0x555556858520) at /work/armbru/qemu/monitor.c:3789
#11 0x0000555555c8af2f in json_message_process_token (lexer=0x5555568776b8, input=0x5555568582e0, type=JSON_RCURLY, x=48, y=1)
at /work/armbru/qemu/qobject/json-streamer.c:105

Quoted 5 lines
Quoted 2 lines

Sorry for not having reviewed this earlier. On the other hand, how come this survived testing?

We primarily focused on testing the functionality, not the failure / corner cases, I think.

That's as natural as it is wrong :)

I'm a lackluster tester myself. The only way I can bring myself to test systematically is write automated tests. Fortunately, our infrastructure for that is much better than it used to be. Our habits still seem to be trailing the infrastructure, though.

See also "New QMP command without a test -> automatic NAK", Message-ID:
<[email protected]>.

Quoted 7 lines

(There are at least two other known startup
scenarios that are not handled correctly just yet, although they don't crash -- multiple vmgenid devices, and vmgenid on machtypes without writeable fw_cfg.)

Also, in my testing I only called the monitor command via HMP (from virsh), and AFAICS that one doesn't crash even if the device is missing.

Correct.

Quoted 2 lines

Nonetheless, qmp_query_vm_generation_id() should set an error when it returns NULL, yes.

That's the obvious fix. It's a one-liner.

Quoted 3 lines

I think Ben wants to post a followup series with those fixes mentioned above, in time for 2.9, perhaps this crash can be addressed in there too. Ben?

Quoted 8 lines
Quoted 2 lines

Since the fix is a one-liner, I'd like you guys to consider respinning this pull request with the fix.

If Ben & Michael send out a new pull with the above fixed, I'd like to point out that the updated SeaBIOS blob is now in the tree (see commit 8779fccbef0c, "seabios: update to 1.10.2 release", 2017-02-28), so the unit test patch can be included as well.

Yes, the SeaBIOS image is now pulled in, so it’d be great to pull in the unit tests too. What do I do here - send a patch with the fix, or a re-spin of the single original patch without the bug, or a re-spin of the patch series?

Quoted 4 lines

Thanks
Laszlo

—Ben

#23 lore raw

Re: [Qemu-devel] [PULL 05/15] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands

Quoted 159 lines · Ben Warren

I

Quoted 150 lines · Laszlo Ersek
Quoted 147 lines · Markus Armbruster
Quoted 110 lines · Laszlo Ersek
Quoted 109 lines · Markus Armbruster

Crash bug, I'm afraid...

Quoted 56 lines · Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

Add commands to query Virtual Machine Generation ID counter.

QMP command example:

   { "execute": "query-vm-generation-id" }

HMP command example:
info vm-generation-id

---

qapi-schema.json     | 20 ++++++++++++++++++++
hmp.h                |  1 +
hmp.c                |  9 +++++++++
hw/acpi/vmgenid.c    | 16 ++++++++++++++++
stubs/vmgenid.c      |  9 +++++++++
hmp-commands-info.hx | 14 ++++++++++++++
stubs/Makefile.objs  |  1 +
7 files changed, 70 insertions(+)

create mode 100644 stubs/vmgenid.c

qapi-schema.json +20 -0
index d6186d4..84692da 100644
@@ -6188,3 +6188,23 @@
 #
 ##
 { 'command': 'query-hotpluggable-cpus', 'returns': ['HotpluggableCPU'] }
+
+##
+# @GuidInfo:
+#
+# GUID information.
+#
+# @guid: the globally unique identifier
+#
+# Since: 2.9
+##
+{ 'struct': 'GuidInfo', 'data': {'guid': 'str'} }
+
+##
+# @query-vm-generation-id:
+#
+# Show Virtual Machine Generation ID
+#
+# Since 2.9
+##
+{ 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }

[...]

Quoted 14 lines
hw/acpi/vmgenid.c +6 -0
index c8465df..744f284 100644
@@ -240,3 +240,19 @@ static void vmgenid_register_types(void)
 }
 
 type_init(vmgenid_register_types)
+
+GuidInfo *qmp_query_vm_generation_id(Error **errp)
+{
+    GuidInfo *info;
+    VmGenIdState *vms;
+    Object *obj = find_vmgenid_dev();

hw/acpi/vmgenid.c static void vmgenid_register_types(void) · line 258

Quoted 10 lines
hw/acpi/vmgenid.c +10 -0
+
+    if (!obj) {
+        return NULL;
+    }
+    vms = VMGENID(obj);
+
+    info = g_malloc0(sizeof(*info));
+    info->guid = qemu_uuid_unparse_strdup(&vms->guid);
+    return info;
+}

This either returns a GuidInfo or NULL.

If it returns NULL, the generated qmp_marshal_output_GuidInfo() will crash like this:

#0  0x00007fffdb4c7765 in raise () at /lib64/libc.so.6
#1  0x00007fffdb4c936a in abort () at /lib64/libc.so.6
#2  0x00007fffdb4bff97 in __assert_fail_base () at /lib64/libc.so.6
#3  0x00007fffdb4c0042 in  () at /lib64/libc.so.6
#4  0x0000555555c800a0 in visit_start_struct (v=
   0x555557727000, name=0x555555cf29e8 "unused", obj=0x7fffffffc7c8, size=8, errp=0x7fffffffc790) at /work/armbru/qemu/qapi/qapi-visit-core.c:49
#5  0x0000555555c5d398 in visit_type_GuidInfo (v=
   0x555557727000, name=0x555555cf29e8 "unused", obj=0x7fffffffc7c8, errp=0x7fffffffc7d8) at qapi-visit.c:6038
#6  0x0000555555922fc0 in qmp_marshal_output_GuidInfo (ret_in=0x0, ret_out=0x7fffffffc870, errp=0x7fffffffc820) at qmp-marshal.c:5148
#7  0x0000555555923123 in qmp_marshal_query_vm_generation_id (args=0x555557a67500, ret=0x7fffffffc870, errp=0x7fffffffc868) at qmp-marshal.c:5186
#8  0x0000555555c83a73 in do_qmp_dispatch (request=0x555556ab3200, errp=0x7fffffffc8c0) at /work/armbru/qemu/qapi/qmp-dispatch.c:97
#9  0x0000555555c83ba3 in qmp_dispatch (request=0x555556ab3200)

at /work/armbru/qemu/qapi/qmp-dispatch.c:124
#10 0x00005555557bb671 in handle_qmp_command (parser=
0x5555568776b0, tokens=0x555556858520) at /work/armbru/qemu/monitor.c:3789
#11 0x0000555555c8af2f in json_message_process_token (lexer=0x5555568776b8, input=0x5555568582e0, type=JSON_RCURLY, x=48, y=1)
at /work/armbru/qemu/qobject/json-streamer.c:105

Quoted 5 lines
Quoted 2 lines

Sorry for not having reviewed this earlier. On the other hand, how come this survived testing?

We primarily focused on testing the functionality, not the failure / corner cases, I think.

That's as natural as it is wrong :)

I'm a lackluster tester myself. The only way I can bring myself to test systematically is write automated tests. Fortunately, our infrastructure for that is much better than it used to be. Our habits still seem to be trailing the infrastructure, though.

See also "New QMP command without a test -> automatic NAK", Message-ID:
<[email protected]>.

Quoted 7 lines

(There are at least two other known startup
scenarios that are not handled correctly just yet, although they don't crash -- multiple vmgenid devices, and vmgenid on machtypes without writeable fw_cfg.)

Also, in my testing I only called the monitor command via HMP (from virsh), and AFAICS that one doesn't crash even if the device is missing.

Correct.

Quoted 2 lines

Nonetheless, qmp_query_vm_generation_id() should set an error when it returns NULL, yes.

That's the obvious fix. It's a one-liner.

Quoted 3 lines

I think Ben wants to post a followup series with those fixes mentioned above, in time for 2.9, perhaps this crash can be addressed in there too. Ben?

Quoted 8 lines
Quoted 2 lines

Since the fix is a one-liner, I'd like you guys to consider respinning this pull request with the fix.

If Ben & Michael send out a new pull with the above fixed, I'd like to point out that the updated SeaBIOS blob is now in the tree (see commit 8779fccbef0c, "seabios: update to 1.10.2 release", 2017-02-28), so the unit test patch can be included as well.

Quoted 7 lines

Yes, the SeaBIOS image is now pulled in, so it’d be great to pull in the unit tests too. What do I do here - send a patch with the fix, or a re-spin of the single original patch without the bug, or a re-spin of the patch series?

Quoted 4 lines

Thanks
Laszlo

—Ben

Send the fix first of all pls.

Can you send pointer to the test patches pls? I have some version on a branch but I'd rather not guess.

Signature · 1 line
MST
#24 lore raw

Re: [Qemu-devel] [PULL 05/15] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands

Quoted 161 lines · Michael S. Tsirkin
Quoted 160 lines · Ben Warren

I

Quoted 150 lines · Laszlo Ersek
Quoted 147 lines · Markus Armbruster
Quoted 110 lines · Laszlo Ersek
Quoted 109 lines · Markus Armbruster

Crash bug, I'm afraid...

Quoted 56 lines · Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

Add commands to query Virtual Machine Generation ID counter.

QMP command example:

   { "execute": "query-vm-generation-id" }

HMP command example:
info vm-generation-id

---

qapi-schema.json     | 20 ++++++++++++++++++++
hmp.h                |  1 +
hmp.c                |  9 +++++++++
hw/acpi/vmgenid.c    | 16 ++++++++++++++++
stubs/vmgenid.c      |  9 +++++++++
hmp-commands-info.hx | 14 ++++++++++++++
stubs/Makefile.objs  |  1 +
7 files changed, 70 insertions(+)

create mode 100644 stubs/vmgenid.c

qapi-schema.json +20 -0
index d6186d4..84692da 100644
@@ -6188,3 +6188,23 @@
 #
 ##
 { 'command': 'query-hotpluggable-cpus', 'returns': ['HotpluggableCPU'] }
+
+##
+# @GuidInfo:
+#
+# GUID information.
+#
+# @guid: the globally unique identifier
+#
+# Since: 2.9
+##
+{ 'struct': 'GuidInfo', 'data': {'guid': 'str'} }
+
+##
+# @query-vm-generation-id:
+#
+# Show Virtual Machine Generation ID
+#
+# Since 2.9
+##
+{ 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }

[...]

Quoted 14 lines
hw/acpi/vmgenid.c +6 -0
index c8465df..744f284 100644
@@ -240,3 +240,19 @@ static void vmgenid_register_types(void)
 }
 
 type_init(vmgenid_register_types)
+
+GuidInfo *qmp_query_vm_generation_id(Error **errp)
+{
+    GuidInfo *info;
+    VmGenIdState *vms;
+    Object *obj = find_vmgenid_dev();

hw/acpi/vmgenid.c static void vmgenid_register_types(void) · line 258

Quoted 10 lines
hw/acpi/vmgenid.c +10 -0
+
+    if (!obj) {
+        return NULL;
+    }
+    vms = VMGENID(obj);
+
+    info = g_malloc0(sizeof(*info));
+    info->guid = qemu_uuid_unparse_strdup(&vms->guid);
+    return info;
+}

This either returns a GuidInfo or NULL.

If it returns NULL, the generated qmp_marshal_output_GuidInfo() will crash like this:

#0  0x00007fffdb4c7765 in raise () at /lib64/libc.so.6
#1  0x00007fffdb4c936a in abort () at /lib64/libc.so.6
#2  0x00007fffdb4bff97 in __assert_fail_base () at /lib64/libc.so.6
#3  0x00007fffdb4c0042 in  () at /lib64/libc.so.6
#4  0x0000555555c800a0 in visit_start_struct (v=
   0x555557727000, name=0x555555cf29e8 "unused", obj=0x7fffffffc7c8, size=8, errp=0x7fffffffc790) at /work/armbru/qemu/qapi/qapi-visit-core.c:49
#5  0x0000555555c5d398 in visit_type_GuidInfo (v=
   0x555557727000, name=0x555555cf29e8 "unused", obj=0x7fffffffc7c8, errp=0x7fffffffc7d8) at qapi-visit.c:6038
#6  0x0000555555922fc0 in qmp_marshal_output_GuidInfo (ret_in=0x0, ret_out=0x7fffffffc870, errp=0x7fffffffc820) at qmp-marshal.c:5148
#7  0x0000555555923123 in qmp_marshal_query_vm_generation_id (args=0x555557a67500, ret=0x7fffffffc870, errp=0x7fffffffc868) at qmp-marshal.c:5186
#8  0x0000555555c83a73 in do_qmp_dispatch (request=0x555556ab3200, errp=0x7fffffffc8c0) at /work/armbru/qemu/qapi/qmp-dispatch.c:97
#9  0x0000555555c83ba3 in qmp_dispatch (request=0x555556ab3200)

at /work/armbru/qemu/qapi/qmp-dispatch.c:124
#10 0x00005555557bb671 in handle_qmp_command (parser=
0x5555568776b0, tokens=0x555556858520) at /work/armbru/qemu/monitor.c:3789
#11 0x0000555555c8af2f in json_message_process_token (lexer=0x5555568776b8, input=0x5555568582e0, type=JSON_RCURLY, x=48, y=1)
at /work/armbru/qemu/qobject/json-streamer.c:105

Quoted 5 lines
Quoted 2 lines

Sorry for not having reviewed this earlier. On the other hand, how come this survived testing?

We primarily focused on testing the functionality, not the failure / corner cases, I think.

That's as natural as it is wrong :)

I'm a lackluster tester myself. The only way I can bring myself to test systematically is write automated tests. Fortunately, our infrastructure for that is much better than it used to be. Our habits still seem to be trailing the infrastructure, though.

See also "New QMP command without a test -> automatic NAK", Message-ID:
<[email protected]>.

Quoted 7 lines

(There are at least two other known startup
scenarios that are not handled correctly just yet, although they don't crash -- multiple vmgenid devices, and vmgenid on machtypes without writeable fw_cfg.)

Also, in my testing I only called the monitor command via HMP (from virsh), and AFAICS that one doesn't crash even if the device is missing.

Correct.

Quoted 2 lines

Nonetheless, qmp_query_vm_generation_id() should set an error when it returns NULL, yes.

That's the obvious fix. It's a one-liner.

Quoted 3 lines

I think Ben wants to post a followup series with those fixes mentioned above, in time for 2.9, perhaps this crash can be addressed in there too. Ben?

Quoted 8 lines
Quoted 2 lines

Since the fix is a one-liner, I'd like you guys to consider respinning this pull request with the fix.

If Ben & Michael send out a new pull with the above fixed, I'd like to point out that the updated SeaBIOS blob is now in the tree (see commit 8779fccbef0c, "seabios: update to 1.10.2 release", 2017-02-28), so the unit test patch can be included as well.

Yes, the SeaBIOS image is now pulled in, so it’d be great to pull in the unit tests too. What do I do here - send a patch with the fix, or a re-spin of the single original patch without the bug, or a re-spin of the patch series?

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Thanks
Laszlo

—Ben

Send the fix first of all pls.

Ben, once you add error_setg() to the "return NULL" branch in qmp_query_vm_generation_id(), please remember to print and also release that error object in hmp_info_vm_generation_id() as well. Sth like (not even build tested):

hmp.c +0 -0
index 0ed1157c2c3a..c057be49a5ce 100644
@@ -2580,9 +2580,11 @@ void hmp_hotpluggable_cpus(Monitor *mon, const

QDict *qdict)

void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict) {

-    GuidInfo *info = qmp_query_vm_generation_id(NULL);
+    Error *err = NULL;
+    GuidInfo *info = qmp_query_vm_generation_id(&err);
     if (info) {
         monitor_printf(mon, "%s\n", info->guid);
     }
+    hmp_handle_error(mon, &err);
     qapi_free_GuidInfo(info);

}

Quoted 4 lines

Can you send pointer to the test patches pls? I have some version on a branch but I'd rather not guess.

subject: [Qemu-devel] [PATCH v8 7/8] tests: Add unit tests for the VM Generation ID feature

message-id:
<5353279f68be14c63f049bc34902675290e45b1d.1487286467.git.ben@skyportsystems.com>

URLs:
https://www.mail-archive.com/[email protected]/msg430491.html
http://lists.nongnu.org/archive/html/qemu-devel/2017-02/msg03781.html

#25 lore raw

[Qemu-devel] [PULL 04/15] ACPI: Add Virtual Machine Generation ID support

In reply to Michael S. Tsirkin

From: Ben Warren <[email protected]>

This implements the VM Generation ID feature by passing a 128-bit GUID to the guest via a fw_cfg blob.
Any time the GUID changes, an ACPI notify event is sent to the guest

The user interface is a simple device with one parameter:
- guid (string, must be "auto" or in UUID format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)

---
 default-configs/i386-softmmu.mak     |   1 +
 default-configs/x86_64-softmmu.mak   |   1 +
 include/hw/acpi/acpi_dev_interface.h |   1 +
 include/hw/acpi/vmgenid.h            |  35 +++++
 hw/acpi/vmgenid.c                    | 242 +++++++++++++++++++++++++++++++++++
 hw/i386/acpi-build.c                 |  16 +++
 hw/acpi/Makefile.objs                |   1 +
 7 files changed, 297 insertions(+)
 create mode 100644 include/hw/acpi/vmgenid.h
 create mode 100644 hw/acpi/vmgenid.c
default-configs/i386-softmmu.mak +1 -0
index 48b07a4..029e952 100644
@@ -59,3 +59,4 @@ CONFIG_I82801B11=y
 CONFIG_SMBIOS=y
 CONFIG_HYPERV_TESTDEV=$(CONFIG_KVM)
 CONFIG_PXB=y
+CONFIG_ACPI_VMGENID=y
default-configs/x86_64-softmmu.mak +1 -0
index fd96345..d1d7432 100644
@@ -59,3 +59,4 @@ CONFIG_I82801B11=y
 CONFIG_SMBIOS=y
 CONFIG_HYPERV_TESTDEV=$(CONFIG_KVM)
 CONFIG_PXB=y
+CONFIG_ACPI_VMGENID=y
include/hw/acpi/acpi_dev_interface.h +1 -0
index 71d3c48..3c2e4e9 100644
@@ -11,6 +11,7 @@ typedef enum {
     ACPI_CPU_HOTPLUG_STATUS = 4,
     ACPI_MEMORY_HOTPLUG_STATUS = 8,
     ACPI_NVDIMM_HOTPLUG_STATUS = 16,
+    ACPI_VMGENID_CHANGE_STATUS = 32,
 } AcpiEventStatusBits;
 
 #define TYPE_ACPI_DEVICE_IF "acpi-device-interface"
include/hw/acpi/vmgenid.h new file +35 -0
new file mode 100644
index 0000000..db7fa0e
@@ -0,0 +1,35 @@
+#ifndef ACPI_VMGENID_H
+#define ACPI_VMGENID_H
+
+#include "hw/acpi/bios-linker-loader.h"
+#include "hw/qdev.h"
+#include "qemu/uuid.h"
+
+#define VMGENID_DEVICE           "vmgenid"
+#define VMGENID_GUID             "guid"
+#define VMGENID_GUID_FW_CFG_FILE      "etc/vmgenid_guid"
+#define VMGENID_ADDR_FW_CFG_FILE      "etc/vmgenid_addr"
+
+#define VMGENID_FW_CFG_SIZE      4096 /* Occupy a page of memory */
+#define VMGENID_GUID_OFFSET      40   /* allow space for
+                                       * OVMF SDT Header Probe Supressor
+                                       */
+
+#define VMGENID(obj) OBJECT_CHECK(VmGenIdState, (obj), VMGENID_DEVICE)
+
+typedef struct VmGenIdState {
+    DeviceClass parent_obj;
+    QemuUUID guid;                /* The 128-bit GUID seen by the guest */
+    uint8_t vmgenid_addr_le[8];   /* Address of the GUID (little-endian) */
+} VmGenIdState;
+
+static inline Object *find_vmgenid_dev(void)
+{
+    return object_resolve_path_type("", VMGENID_DEVICE, NULL);
+}
+
+void vmgenid_build_acpi(VmGenIdState *vms, GArray *table_data, GArray *guid,
+                        BIOSLinker *linker);
+void vmgenid_add_fw_cfg(VmGenIdState *vms, FWCfgState *s, GArray *guid);
+
+#endif
hw/acpi/vmgenid.c new file +242 -0

242 lines not on this page · raw message

hw/i386/acpi-build.c +16 -0
index 1c928ab..db04cf5 100644
@@ -42,6 +42,7 @@
 #include "hw/acpi/memory_hotplug.h"
 #include "sysemu/tpm.h"
 #include "hw/acpi/tpm.h"
+#include "hw/acpi/vmgenid.h"
 #include "sysemu/tpm_backend.h"
 #include "hw/timer/mc146818rtc_regs.h"
 #include "sysemu/numa.h"
@@ -2610,6 +2611,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
     size_t aml_len = 0;
     GArray *tables_blob = tables->table_data;
     AcpiSlicOem slic_oem = { .id = NULL, .table_id = NULL };
+    Object *vmgenid_dev;
 
     acpi_get_pm_info(&pm);
     acpi_get_misc_info(&misc);
@@ -2653,6 +2655,13 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
     acpi_add_table(table_offsets, tables_blob);
     build_madt(tables_blob, tables->linker, pcms);
 
+    vmgenid_dev = find_vmgenid_dev();
+    if (vmgenid_dev) {
+        acpi_add_table(table_offsets, tables_blob);
+        vmgenid_build_acpi(VMGENID(vmgenid_dev), tables_blob,
+                           tables->vmgenid, tables->linker);
+    }
+
     if (misc.has_hpet) {
         acpi_add_table(table_offsets, tables_blob);
         build_hpet(tables_blob, tables->linker);
@@ -2823,6 +2832,7 @@ void acpi_setup(void)
     PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
     AcpiBuildTables tables;
     AcpiBuildState *build_state;
+    Object *vmgenid_dev;
 
     if (!pcms->fw_cfg) {
         ACPI_BUILD_DPRINTF("No fw cfg. Bailing out.\n");
@@ -2859,6 +2869,12 @@ void acpi_setup(void)
     fw_cfg_add_file(pcms->fw_cfg, ACPI_BUILD_TPMLOG_FILE,
                     tables.tcpalog->data, acpi_data_len(tables.tcpalog));
 
+    vmgenid_dev = find_vmgenid_dev();
+    if (vmgenid_dev) {
+        vmgenid_add_fw_cfg(VMGENID(vmgenid_dev), pcms->fw_cfg,
+                           tables.vmgenid);
+    }
+
     if (!pcmc->rsdp_in_ram) {
         /*
          * Keep for compatibility with old machine types.
hw/acpi/Makefile.objs +1 -0
index 6acf798..11c35bc 100644
@@ -5,6 +5,7 @@ common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o
 common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o
 common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o
 common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o
+common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o
 common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o
 
 common-obj-y += acpi_interface.o
Signature · 1 line
MST
#26 lore raw

[Qemu-devel] [PULL 07/15] MAINTAINERS: Add VM Generation ID entries

In reply to Michael S. Tsirkin

From: Ben Warren <[email protected]>

---
 MAINTAINERS | 9 +++++++++
 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
index 8b54935..b9a2171 100644
@@ -1124,6 +1124,15 @@ F: hw/nvram/chrp_nvram.c
 F: include/hw/nvram/chrp_nvram.h
 F: tests/prom-env-test.c
 
+VM Generation ID
+M: Ben Warren <[email protected]>
+S: Maintained
+F: hw/acpi/vmgenid.c
+F: include/hw/acpi/vmgenid.h
+F: docs/specs/vmgenid.txt
+F: tests/vmgenid-test.c
+F: stubs/vmgenid.c
+
 Subsystems
 ----------
 Audio
Signature · 1 line
MST
#27 lore raw

[Qemu-devel] [PULL 06/15] tests: Move reusable ACPI code into a utility file

In reply to Michael S. Tsirkin

From: Ben Warren <[email protected]>

Also usable by upcoming VM Generation ID tests

---
 tests/acpi-utils.h       |  94 +++++++++++++++++++++++++++++++++
 tests/acpi-utils.c       |  65 +++++++++++++++++++++++
 tests/bios-tables-test.c | 132 ++++++-----------------------------------------
 MAINTAINERS              |   2 +
 tests/Makefile.include   |   2 +-
 5 files changed, 177 insertions(+), 118 deletions(-)
 create mode 100644 tests/acpi-utils.h
 create mode 100644 tests/acpi-utils.c
tests/acpi-utils.h new file +94 -0
new file mode 100644
index 0000000..9f9a2d5
@@ -0,0 +1,94 @@
+/*
+ * Utilities for working with ACPI tables
+ *
+ * Copyright (c) 2013 Red Hat Inc.
+ *
+ * Authors:
+ *  Michael S. Tsirkin <[email protected]>,
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef TEST_ACPI_UTILS_H
+#define TEST_ACPI_UTILS_H
+
+#include "hw/acpi/acpi-defs.h"
+#include "libqtest.h"
+
+/* DSDT and SSDTs format */
+typedef struct {
+    AcpiTableHeader header;
+    gchar *aml;            /* aml bytecode from guest */
+    gsize aml_len;
+    gchar *aml_file;
+    gchar *asl;            /* asl code generated from aml */
+    gsize asl_len;
+    gchar *asl_file;
+    bool tmp_files_retain;   /* do not delete the temp asl/aml */
+} QEMU_PACKED AcpiSdtTable;
+
+#define ACPI_READ_FIELD(field, addr)           \
+    do {                                       \
+        switch (sizeof(field)) {               \
+        case 1:                                \
+            field = readb(addr);               \
+            break;                             \
+        case 2:                                \
+            field = readw(addr);               \
+            break;                             \
+        case 4:                                \
+            field = readl(addr);               \
+            break;                             \
+        case 8:                                \
+            field = readq(addr);               \
+            break;                             \
+        default:                               \
+            g_assert(false);                   \
+        }                                      \
+        addr += sizeof(field);                  \
+    } while (0);
+
+#define ACPI_READ_ARRAY_PTR(arr, length, addr)  \
+    do {                                        \
+        int idx;                                \
+        for (idx = 0; idx < length; ++idx) {    \
+            ACPI_READ_FIELD(arr[idx], addr);    \
+        }                                       \
+    } while (0);
+
+#define ACPI_READ_ARRAY(arr, addr)                               \
+    ACPI_READ_ARRAY_PTR(arr, sizeof(arr) / sizeof(arr[0]), addr)
+
+#define ACPI_READ_TABLE_HEADER(table, addr)                      \
+    do {                                                         \
+        ACPI_READ_FIELD((table)->signature, addr);               \
+        ACPI_READ_FIELD((table)->length, addr);                  \
+        ACPI_READ_FIELD((table)->revision, addr);                \
+        ACPI_READ_FIELD((table)->checksum, addr);                \
+        ACPI_READ_ARRAY((table)->oem_id, addr);                  \
+        ACPI_READ_ARRAY((table)->oem_table_id, addr);            \
+        ACPI_READ_FIELD((table)->oem_revision, addr);            \
+        ACPI_READ_ARRAY((table)->asl_compiler_id, addr);         \
+        ACPI_READ_FIELD((table)->asl_compiler_revision, addr);   \
+    } while (0);
+
+#define ACPI_ASSERT_CMP(actual, expected) do { \
+    uint32_t ACPI_ASSERT_CMP_le = cpu_to_le32(actual); \
+    char ACPI_ASSERT_CMP_str[5] = {}; \
+    memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 4); \
+    g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
+} while (0)
+
+#define ACPI_ASSERT_CMP64(actual, expected) do { \
+    uint64_t ACPI_ASSERT_CMP_le = cpu_to_le64(actual); \
+    char ACPI_ASSERT_CMP_str[9] = {}; \
+    memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 8); \
+    g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
+} while (0)
+
+uint8_t acpi_calc_checksum(const uint8_t *data, int len);
+uint32_t acpi_find_rsdp_address(void);
+void acpi_parse_rsdp_table(uint32_t addr, AcpiRsdpDescriptor *rsdp_table);
+
+#endif  /* TEST_ACPI_UTILS_H */
tests/acpi-utils.c new file +65 -0

65 lines not on this page · raw message

tests/bios-tables-test.c +15 -117

192 lines not on this page · raw message

MAINTAINERS +2 -0
index be79f68..8b54935 100644
@@ -908,6 +908,8 @@ F: hw/acpi/*
 F: hw/smbios/*
 F: hw/i386/acpi-build.[hc]
 F: hw/arm/virt-acpi-build.c
+F: tests/bios-tables-test.c
+F: tests/acpi-utils.[hc]
 
 ppc4xx
 M: Alexander Graf <[email protected]>
tests/Makefile.include +1 -1
index 3310c17..364ef1b 100644
@@ -669,7 +669,7 @@ tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o
 tests/boot-order-test$(EXESUF): tests/boot-order-test.o $(libqos-obj-y)
 tests/boot-serial-test$(EXESUF): tests/boot-serial-test.o $(libqos-obj-y)
 tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o \
-	tests/boot-sector.o $(libqos-obj-y)
+	tests/boot-sector.o tests/acpi-utils.o $(libqos-obj-y)
 tests/pxe-test$(EXESUF): tests/pxe-test.o tests/boot-sector.o $(libqos-obj-y)
 tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y)
 tests/ds1338-test$(EXESUF): tests/ds1338-test.o $(libqos-imx-obj-y)
Signature · 1 line
MST
#28 lore raw

[Qemu-devel] [PULL 08/15] virtio: check for vring setup in virtio_queue_empty

In reply to Michael S. Tsirkin

From: Paolo Bonzini <[email protected]>

If the vring has not been set up, there is nothing in the virtqueue. virtio_queue_host_notifier_aio_poll calls virtio_queue_empty even in this case; we have to filter it out just like virtio_queue_notify_aio_vq.

---
 hw/virtio/virtio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio.c +1 -1
index 23483c7..e487e36 100644
@@ -2291,7 +2291,7 @@ static bool virtio_queue_host_notifier_aio_poll(void *opaque)
     VirtQueue *vq = container_of(n, VirtQueue, host_notifier);
     bool progress;
 
-    if (virtio_queue_empty(vq)) {
+    if (!vq->vring.desc || virtio_queue_empty(vq)) {
         return false;
     }
 
Signature · 1 line
MST
#29 lore raw

[Qemu-devel] [PULL 09/15] virtio: guard vring access when setting notification

In reply to Michael S. Tsirkin

From: Cornelia Huck <[email protected]>

Switching to vring caches exposed an existing bug in virtio_queue_set_notification(): We can't access vring structures if they have not been set up yet. This may happen, for example, for virtio-blk devices with multiple queues: The code will try to switch notifiers for every queue, but the guest may have only set up a subset of them.

Fix this by guarding access to the vring memory by checking for vring.desc. The first aio poll will iron out any remaining inconsistencies for later-configured queues (buggy legacy drivers).

---
 hw/virtio/virtio.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/virtio/virtio.c +4 -0
index e487e36..bf8a644 100644
@@ -288,6 +288,10 @@ void virtio_queue_set_notification(VirtQueue *vq, int enable)
 {
     vq->notification = enable;
 
+    if (!vq->vring.desc) {
+        return;
+    }
+
     rcu_read_lock();
     if (virtio_vdev_has_feature(vq->vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_set_avail_event(vq, vring_avail_idx(vq));
Signature · 1 line
MST
#30 lore raw

[Qemu-devel] [PULL 10/15] virtio: invalidate memory in vring_set_avail_event()

In reply to Michael S. Tsirkin

From: Stefan Hajnoczi <[email protected]>

Remember to invalidate the avail event field so the memory pages are marked dirty.

---
 hw/virtio/virtio.c | 1 +
 1 file changed, 1 insertion(+)
hw/virtio/virtio.c +1 -0
index bf8a644..294c909 100644
@@ -282,6 +282,7 @@ static inline void vring_set_avail_event(VirtQueue *vq, uint16_t val)
     caches = atomic_rcu_read(&vq->vring.caches);
     pa = offsetof(VRingUsed, ring[vq->vring.num]);
     virtio_stw_phys_cached(vq->vdev, &caches->used, pa, val);
+    address_space_cache_invalidate(&caches->used, pa, sizeof(val));
 }
 
 void virtio_queue_set_notification(VirtQueue *vq, int enable)
Signature · 1 line
MST
#31 lore raw

[Qemu-devel] [PULL 11/15] virtio: add missing region cache init in virtio_load()

In reply to Michael S. Tsirkin

From: Stefan Hajnoczi <[email protected]>

Commit 97cd965c070152bc626c7507df9fb356bbe1cd81 ("virtio: use VRingMemoryRegionCaches for avail and used rings") switched to a memory region cache to avoid repeated map/unmap operations.

The virtio_load() process is a little tricky because vring addresses are serialized in two separate places. VIRTIO 1.0 devices serialize desc and then a subsection with used and avail. Legacy devices only serialize desc.

Live migration of VIRTIO 1.0 devices fails on the destination host with:

VQ 0 size 0x80 < last_avail_idx 0x12f8 - used_idx 0x0
Failed to load virtio-blk:virtio
error while loading state for instance 0x0 of device '0000:00:04.0/virtio-blk'

This happens because the memory region cache is only initialized after desc is loaded and not after the used and avail subsection is loaded. If the guest chose memory addresses that don't match the legacy ring layout then the wrong guest memory location is accessed.

Wait until all ring addresses are known before trying to initialize the region cache. Also clarify the incomplete comment about VIRTIO-1 ring address subsection.

---
 hw/virtio/virtio.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
hw/virtio/virtio.c +19 -6
index 294c909..efce4b3 100644
@@ -1857,7 +1857,10 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
         if (k->has_variable_vring_alignment) {
             qemu_put_be32(f, vdev->vq[i].vring.align);
         }
-        /* XXX virtio-1 devices */
+        /*
+         * Save desc now, the rest of the ring addresses are saved in
+         * subsections for VIRTIO-1 devices.
+         */
         qemu_put_be64(f, vdev->vq[i].vring.desc);
         qemu_put_be16s(f, &vdev->vq[i].last_avail_idx);
         if (k->save_queue) {
@@ -1998,14 +2001,11 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
         vdev->vq[i].signalled_used_valid = false;
         vdev->vq[i].notification = true;
 
-        if (vdev->vq[i].vring.desc) {
-            /* XXX virtio-1 devices */
-            virtio_queue_update_rings(vdev, i);
-        } else if (vdev->vq[i].last_avail_idx) {
+        if (!vdev->vq[i].vring.desc && vdev->vq[i].last_avail_idx) {
             error_report("VQ %d address 0x0 "
                          "inconsistent with Host index 0x%x",
                          i, vdev->vq[i].last_avail_idx);
-                return -1;
+            return -1;
         }
         if (k->load_queue) {
             ret = k->load_queue(qbus->parent, i, f);
@@ -2066,6 +2066,19 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
     for (i = 0; i < num; i++) {
         if (vdev->vq[i].vring.desc) {
             uint16_t nheads;
+
+            /*
+             * VIRTIO-1 devices migrate desc, used, and avail ring addresses so
+             * only the region cache needs to be set up.  Legacy devices need
+             * to calculate used and avail ring addresses based on the desc
+             * address.
+             */
+            if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) {
+                virtio_init_region_cache(vdev, i);
+            } else {
+                virtio_queue_update_rings(vdev, i);
+            }
+
             nheads = vring_avail_idx(&vdev->vq[i]) - vdev->vq[i].last_avail_idx;
             /* Check it isn't doing strange things with descriptor numbers. */
             if (nheads > vdev->vq[i].vring.num) {
Signature · 1 line
MST
#32 lore raw

[Qemu-devel] [PULL 12/15] virtio: unbreak virtio-pci with IOMMU after caching ring translations

In reply to Michael S. Tsirkin

From: Jason Wang <[email protected]>

Commit c611c76417f5 ("virtio: add MemoryListener to cache ring translations") registers a memory listener to dma_as. This may not work when IOMMU is enabled: dma_as(bus_master_as) were initialized in pcibus_machine_done() after virtio_realize(). This will cause a segfault. Fixing this by using pci_device_iommu_address_space() instead to make sure address space were initialized at this time.

With this fix, IOMMU device were required to be initialized before any virtio-pci devices.

Fixes c611c76417f5 ("virtio: add MemoryListener to cache ring translations")
Cc Paolo Bonzini <[email protected]>
---
 hw/virtio/virtio-pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-pci.c +1 -1
index 5ce42af..b76f3f6 100644
@@ -1153,7 +1153,7 @@ static AddressSpace *virtio_pci_get_dma_as(DeviceState *d)
     VirtIOPCIProxy *proxy = VIRTIO_PCI(d);
     PCIDevice *dev = &proxy->pci_dev;
 
-    return pci_get_address_space(dev);
+    return pci_device_iommu_address_space(dev);
 }
 
 static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy,
Signature · 1 line
MST
#33 lore raw

[Qemu-devel] [PULL 13/15] acpi: simplify _OSC

In reply to Michael S. Tsirkin

Our _OSC method has a bunch of unused code loading data into external CTRL and SUPP fields which are then never used. Drop this in favor of a single local variable.

---
 hw/i386/acpi-build.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
hw/i386/acpi-build.c +1 -4
index db04cf5..efbbfcb 100644
@@ -1804,7 +1804,7 @@ static Aml *build_q35_osc_method(void)
     Aml *else_ctx;
     Aml *method;
     Aml *a_cwd1 = aml_name("CDW1");
-    Aml *a_ctrl = aml_name("CTRL");
+    Aml *a_ctrl = aml_local(0);
 
     method = aml_method("_OSC", 4, AML_NOTSERIALIZED);
     aml_append(method, aml_create_dword_field(aml_arg(3), aml_int(0), "CDW1"));
@@ -1814,7 +1814,6 @@ static Aml *build_q35_osc_method(void)
     aml_append(if_ctx, aml_create_dword_field(aml_arg(3), aml_int(4), "CDW2"));
     aml_append(if_ctx, aml_create_dword_field(aml_arg(3), aml_int(8), "CDW3"));
 
-    aml_append(if_ctx, aml_store(aml_name("CDW2"), aml_name("SUPP")));
     aml_append(if_ctx, aml_store(aml_name("CDW3"), a_ctrl));
 
     /*
@@ -1899,8 +1898,6 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
         aml_append(dev, aml_name_decl("_CID", aml_eisaid("PNP0A03")));
         aml_append(dev, aml_name_decl("_ADR", aml_int(0)));
         aml_append(dev, aml_name_decl("_UID", aml_int(1)));
-        aml_append(dev, aml_name_decl("SUPP", aml_int(0)));
-        aml_append(dev, aml_name_decl("CTRL", aml_int(0)));
         aml_append(dev, build_q35_osc_method());
         aml_append(sb_scope, dev);
         aml_append(dsdt, sb_scope);
Signature · 1 line
MST
#34 lore raw

[Qemu-devel] [PULL 14/15] tests/acpi: update DSDT after last patch

In reply to Michael S. Tsirkin
---
 tests/acpi-test-data/q35/DSDT        | Bin 7860 -> 7824 bytes
 tests/acpi-test-data/q35/DSDT.bridge | Bin 7877 -> 7841 bytes
 tests/acpi-test-data/q35/DSDT.cphp   | Bin 8323 -> 8287 bytes
 tests/acpi-test-data/q35/DSDT.ipmibt | Bin 7935 -> 7899 bytes
 tests/acpi-test-data/q35/DSDT.memhp  | Bin 9225 -> 9189 bytes
 5 files changed, 0 insertions(+), 0 deletions(-)
tests/acpi-test-data/q35/DSDT binary +0 -0
index d11567c3dc220894911166681ee7303fadfe04e8..0dccad439b8e8e00b403c8d290a89630c4329d45 100644
GIT binary patch
tests/acpi-test-data/q35/DSDT.bridge binary +0 -0
index 412a6e910404dca9b5d6e6c2d027b9e10ccc2a84..8cd66c3b3143297a5262480e46be9ee811a6291f 100644
GIT binary patch
tests/acpi-test-data/q35/DSDT.cphp binary +0 -0
index 79902d0d30f02d74594cb87b14460ea02764d460..3c28a17a69db15dc92c825c1502a7f86ab975c0d 100644
GIT binary patch
tests/acpi-test-data/q35/DSDT.ipmibt binary +0 -0
index b658329c5b8e7eba009ad96f7cd26674b5a2c861..3ceb876127725f199e3df903bc71e4023e2fa225 100644
GIT binary patch
tests/acpi-test-data/q35/DSDT.memhp binary +0 -0
index e46c1fb5a21b8b45a4db5955989941875169a46d..bdbefd47a5398ed96498b77bfb6a74f7ea638db1 100644
GIT binary patch
Signature · 1 line
MST
#35 lore raw

[Qemu-devel] [PULL 15/15] hw/pxb-pcie: fix PCI Express hotplug support

In reply to Michael S. Tsirkin

From: Marcel Apfelbaum <[email protected]>

Add the missing osc method for pxb-pcie devices as APCI spec recommends, see 6.2.9.1 OSC Implementation Example for PCI Host Bridge Devices, ACPI 3.0a:

It is recommended that a machine with multiple host bridge devices should report the same capabilities for all host bridges, and also negotiate control of the features described in the Control Field in the same way for all host bridges.

---
 hw/i386/acpi-build.c | 3 +++
 dtc                  | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
hw/i386/acpi-build.c +3 -0
index efbbfcb..8018f05 100644
@@ -1962,6 +1962,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
             aml_append(dev, aml_name_decl("_UID", aml_int(bus_num)));
             aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0A03")));
             aml_append(dev, aml_name_decl("_BBN", aml_int(bus_num)));
+            if (pci_bus_is_express(bus)) {
+                aml_append(dev, build_q35_osc_method());
+            }
 
             if (numa_node != NUMA_NODE_UNASSIGNED) {
                 aml_append(dev, aml_name_decl("_PXM", aml_int(numa_node)));
dtc +1 -1
index ec02b34..65cc4d2 160000
@@ -1 +1 @@
-Subproject commit ec02b34c05be04f249ffaaca4b666f5246877dea
+Subproject commit 65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf
Signature · 1 line
MST
#36 lore raw
In reply to Michael S. Tsirkin
Quoted 12 lines · Michael S. Tsirkin

The following changes since commit 1e0addb682c3c552fd97480037d4f8ff18e2b87e:

Merge remote-tracking branch 'remotes/sstabellini/tags/xen-20170228-tag' into staging (2017-03-01 20:33:47 +0000)

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 077dd74239a99f6c1e77c5c1aa24cfc7f58cd20c:

hw/pxb-pcie: fix PCI Express hotplug support (2017-03-02 07:31:26 +0200)

Quoted 8 lines

----------------------------------------------------------------
virtio, pc: fixes, features

virtio support for region caches broke a bunch of stuff - fixing most of it though it's not ideal. Still pondering the right way to fix it.
New: VM gen ID and hotplug for PXB.

This is now well past the softfreeze deadline; do you have a justification for putting new features in during freeze?

thanks
-- PMM

#37 lore raw
Quoted 20 lines · Peter Maydell
Quoted 19 lines · Michael S. Tsirkin

The following changes since commit 1e0addb682c3c552fd97480037d4f8ff18e2b87e:

Merge remote-tracking branch 'remotes/sstabellini/tags/xen-20170228-tag' into staging (2017-03-01 20:33:47 +0000)

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 077dd74239a99f6c1e77c5c1aa24cfc7f58cd20c:

hw/pxb-pcie: fix PCI Express hotplug support (2017-03-02 07:31:26 +0200)

----------------------------------------------------------------
virtio, pc: fixes, features

virtio support for region caches broke a bunch of stuff - fixing most of it though it's not ideal. Still pondering the right way to fix it.
New: VM gen ID and hotplug for PXB.

Quoted 7 lines
Quoted 1 line

This is now well past the softfreeze deadline; do you have a justification for putting new features in during freeze?

thanks
-- PMM

pxb hotplug support is more a bugfix than a feature - we just forgot to include the acpi bits, and the patches are very small. vm gen id has been in my tree for a long time and bios bits have been merged. If we keep it out of this release there's more of a chance they will bitrot which would be a mess.

Signature · 1 line
MST
#38 lore raw
In reply to Michael S. Tsirkin
Quoted 12 lines · Michael S. Tsirkin

The following changes since commit 1e0addb682c3c552fd97480037d4f8ff18e2b87e:

Merge remote-tracking branch 'remotes/sstabellini/tags/xen-20170228-tag' into staging (2017-03-01 20:33:47 +0000)

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 077dd74239a99f6c1e77c5c1aa24cfc7f58cd20c:

hw/pxb-pcie: fix PCI Express hotplug support (2017-03-02 07:31:26 +0200)

Quoted 9 lines

----------------------------------------------------------------
virtio, pc: fixes, features

virtio support for region caches broke a bunch of stuff - fixing most of it though it's not ideal. Still pondering the right way to fix it.
New: VM gen ID and hotplug for PXB.

Applied, thanks.

-- PMM

#40 lore raw
Quoted 10 lines · Peter Maydell
Quoted 1 line · Michael S. Tsirkin
 dtc                                  |   2 +-

I just noticed this erroneous submodule update in here, unfortunately after I pushed it to master :-(

I'll fix up the tree...

thanks
-- PMM

Ouch. submodules are a pain :(
Let me know if you need me to rebase. Sorry.

Signature · 1 line
MST