Skip to contentSkip to conversation

Virtual Machine Generation ID

PATCH Superseded Igor Mammedov 4 participants 23 messages Jan 19, 2016 – Jan 26, 2016

v17 of 19 Superseded Latest is v19 →

lore
Share & tools
lore
#0 lore raw

v17 cover Virtual Machine Generation ID

It's respin of v14* series which uses a PCI BAR to map VGID page in guest AS.

Changes since v14:
- statically reserve used BAR resources in SSDT, so that Windows won't claim them during PCI rebalancing
- support VGID page in high mem in addition to low mem
- add QMP/HMP interfaces to get/set VM Generation ID
- do not consume a PCI slot by default and attach vmgenid device as a function of multifuction ISA bridge.
- allow only one vmgenid device instance

Tested with WS2012R2x64.
Git tree for testing:
https://github.com/imammedo/qemu.git vmgenid_v17

* v14, https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg00530.html

Gal Hammer (1):
docs: vm generation id device's description

Igor Mammedov (8):
acpi: extend ACPI interface to provide access to ACPI registers and
SCI irq
pc: add a Virtual Machine Generation ID device
tests: add a unit test for the vmgenid device.
qmp/hmp: add query-vm-generation-id and 'info vm-generation-id'
commands
qmp/hmp: add set-vm-generation-id commands
add MachineClass->default_props for setting default device properties
pc: put PIIX3 in slot 1 explicitly and cleanup functions assignment pc/q53: by default put vmgenid device as an function of ISA bridge

 default-configs/i386-softmmu.mak     |   1 +
 default-configs/x86_64-softmmu.mak   |   1 +
 docs/specs/pci-ids.txt               |   1 +
 docs/specs/vmgenid.txt               |  36 +++++++
 hmp-commands-info.hx                 |  13 +++
 hmp-commands.hx                      |  13 +++
 hmp.c                                |  21 ++++
 hmp.h                                |   2 +
 hw/acpi/piix4.c                      |  17 ++++
 hw/i386/acpi-build.c                 |  56 ++++++++++-
 hw/i386/pc_piix.c                    |  29 ++++--
 hw/i386/pc_q35.c                     |  12 +++
 hw/isa/lpc_ich9.c                    |  16 +++
 hw/isa/vt82c686.c                    |  19 ++++
 hw/misc/Makefile.objs                |   1 +
 hw/misc/vmgenid.c                    | 183 +++++++++++++++++++++++++++++++++++
 hw/pci-host/piix.c                   |   9 +-
 include/hw/acpi/acpi.h               |   1 +
 include/hw/acpi/acpi_dev_interface.h |   9 ++
 include/hw/boards.h                  |   1 +
 include/hw/i386/ich9.h               |   3 +-
 include/hw/i386/pc.h                 |   9 +-
 include/hw/misc/vmgenid.h            |  27 ++++++
 include/hw/pci/pci.h                 |   1 +
 qapi-schema.json                     |  18 ++++
 qmp-commands.hx                      |  41 ++++++++
 stubs/Makefile.objs                  |   1 +
 stubs/vmgenid.c                      |  13 +++
 tests/Makefile                       |   2 +
 tests/vmgenid-test.c                 |  92 ++++++++++++++++++
 vl.c                                 |   4 +
 31 files changed, 636 insertions(+), 16 deletions(-)
 create mode 100644 docs/specs/vmgenid.txt
 create mode 100644 hw/misc/vmgenid.c
 create mode 100644 include/hw/misc/vmgenid.h
 create mode 100644 stubs/vmgenid.c
 create mode 100644 tests/vmgenid-test.c
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v17 1/9 acpi: extend ACPI interface to provide access to ACPI registers and SCI irq

so that we don't have to always add proxy wrappers in piix4pm/ich9 to access ACPI regs and SCI kept in piix4pm/lcp_ich9 devices and call acpi_foo() API directly.

---
 hw/acpi/piix4.c                      | 17 +++++++++++++++++
 hw/isa/lpc_ich9.c                    | 16 ++++++++++++++++
 hw/isa/vt82c686.c                    | 19 +++++++++++++++++++
 include/hw/acpi/acpi_dev_interface.h |  9 +++++++++
 4 files changed, 61 insertions(+)
hw/acpi/piix4.c +17 -0
index 2cd2fee..5e29be4 100644
@@ -583,6 +583,21 @@ static void piix4_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
     acpi_memory_ospm_status(&s->acpi_memory_hotplug, list);
 }
 
+static ACPIREGS *piix4_acpi_regs(AcpiDeviceIf *adev)
+{
+    PIIX4PMState *s = PIIX4_PM(adev);
+
+    return &s->ar;
+}
+
+static qemu_irq piix4_acpi_irq(AcpiDeviceIf *adev)
+{
+    PIIX4PMState *s = PIIX4_PM(adev);
+
+    return s->irq;
+}
+
+
 static Property piix4_pm_properties[] = {
     DEFINE_PROP_UINT32("smb_io_base", PIIX4PMState, smb_io_base, 0),
     DEFINE_PROP_UINT8(ACPI_PM_PROP_S3_DISABLED, PIIX4PMState, disable_s3, 0),
@@ -621,6 +636,8 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data)
     hc->unplug_request = piix4_device_unplug_request_cb;
     hc->unplug = piix4_device_unplug_cb;
     adevc->ospm_status = piix4_ospm_status;
+    adevc->regs = piix4_acpi_regs;
+    adevc->sci = piix4_acpi_irq;
 }
 
 static const TypeInfo piix4_pm_info = {
hw/isa/lpc_ich9.c +16 -0
index ed9907d..9d60caa 100644
@@ -700,6 +700,20 @@ static Property ich9_lpc_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
+static ACPIREGS *ich9_acpi_regs(AcpiDeviceIf *adev)
+{
+    ICH9LPCState *s = ICH9_LPC_DEVICE(adev);
+
+    return &s->pm.acpi_regs;
+}
+
+static qemu_irq ich9_acpi_irq(AcpiDeviceIf *adev)
+{
+    ICH9LPCState *s = ICH9_LPC_DEVICE(adev);
+
+    return s->pm.irq;
+}
+
 static void ich9_lpc_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -727,6 +741,8 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data)
     hc->unplug_request = ich9_device_unplug_request_cb;
     hc->unplug = ich9_device_unplug_cb;
     adevc->ospm_status = ich9_pm_ospm_status;
+    adevc->regs = ich9_acpi_regs;
+    adevc->sci = ich9_acpi_irq;
 }
 
 static const TypeInfo ich9_lpc_info = {
hw/isa/vt82c686.c +19 -0
index 6c2190b..58707d4 100644
@@ -391,6 +391,18 @@ I2CBus *vt82c686b_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
     return s->smb.smbus;
 }
 
+static ACPIREGS *via_pm_acpi_regs(AcpiDeviceIf *adev)
+{
+    VT686PMState *s = VT82C686B_PM_DEVICE(adev);
+
+    return &s->ar;
+}
+
+static qemu_irq via_pm_acpi_irq(AcpiDeviceIf *adev)
+{
+    return NULL;
+}
+
 static Property via_pm_properties[] = {
     DEFINE_PROP_UINT32("smb_io_base", VT686PMState, smb_io_base, 0),
     DEFINE_PROP_END_OF_LIST(),
@@ -400,6 +412,7 @@ static void via_pm_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+    AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_CLASS(klass);
 
     k->realize = vt82c686b_pm_realize;
     k->config_write = pm_write_config;
@@ -411,6 +424,8 @@ static void via_pm_class_init(ObjectClass *klass, void *data)
     dc->vmsd = &vmstate_acpi;
     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
     dc->props = via_pm_properties;
+    adevc->regs = via_pm_acpi_regs;
+    adevc->sci = via_pm_acpi_irq;
 }
 
 static const TypeInfo via_pm_info = {
@@ -418,6 +433,10 @@ static const TypeInfo via_pm_info = {
     .parent        = TYPE_PCI_DEVICE,
     .instance_size = sizeof(VT686PMState),
     .class_init    = via_pm_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_ACPI_DEVICE_IF },
+        { }
+    },
 };
 
 static const VMStateDescription vmstate_via = {
include/hw/acpi/acpi_dev_interface.h +9 -0
index f245f8d..e3f1bad 100644
@@ -3,6 +3,9 @@
 
 #include "qom/object.h"
 #include "qapi-types.h"
+#include "hw/irq.h"
+
+typedef struct ACPIREGS ACPIREGS;
 
 #define TYPE_ACPI_DEVICE_IF "acpi-device-interface"
 
@@ -28,6 +31,10 @@ typedef struct AcpiDeviceIf {
  * ospm_status: returns status of ACPI device objects, reported
  *              via _OST method if device supports it.
  *
+ * regs: returns pointer to ACPI registers block
+ *
+ * sci: return pointer to IRQ object associated with SCI
+ *
  * Interface is designed for providing unified interface
  * to generic ACPI functionality that could be used without
  * knowledge about internals of actual device that implements
@@ -39,5 +46,7 @@ typedef struct AcpiDeviceIfClass {
 
     /* <public> */
     void (*ospm_status)(AcpiDeviceIf *adev, ACPIOSTInfoList ***list);
+    ACPIREGS *(*regs)(AcpiDeviceIf *adev);
+    qemu_irq (*sci)(AcpiDeviceIf *adev);
 } AcpiDeviceIfClass;
 #endif
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v17 2/9 docs: vm generation id device's description

In reply to Igor Mammedov

From: Gal Hammer <[email protected]>

---
 docs/specs/vmgenid.txt | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 docs/specs/vmgenid.txt
docs/specs/vmgenid.txt new file +36 -0
new file mode 100644
index 0000000..718850a
@@ -0,0 +1,36 @@
+VIRTUAL MACHINE GENERATION ID
+=============================
+
+Copyright (C) 2014 Red Hat, 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.
+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).
+
+This is specified on the web at: http://go.microsoft.com/fwlink/?LinkId=260709
+
+---
+
+The vmgenid device is a PCI device with the following ACPI ID: "QEMU0003".
+
+The device has a "vmgenid.uuid" property, which can be set using
+the command line argument or the QMP interface.
+For example:
+QEMU  -device vmgenid,id=FOO,uuid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
+
+Or to change uuid in runtime use:
+ qom-set "/machine/peripheral/FOO.uuid" "124e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
+
+According to the specification, any change to the GUID executes an
+ACPI notification. The vmgenid device triggers the \_GPE._E00 handler
+which executes the ACPI Notify operation.
+
+Although not specified in Microsoft's document, it is assumed that the
+device is expected to use the little-endian system.
Signature · 1 line
1.8.3.1
Reviewed-by on v17 2/9
#3 lore raw

Re: [Qemu-devel] [PATCH v17 2/9] docs: vm generation id device's description

Quoted 15 lines · Igor Mammedov

From: Gal Hammer <[email protected]>

---
 docs/specs/vmgenid.txt | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 docs/specs/vmgenid.txt
docs/specs/vmgenid.txt new file +0 -0
new file mode 100644
index 0000000..718850a

docs/specs/vmgenid.txt line 4

Quoted 4 lines
docs/specs/vmgenid.txt new file +4 -0
@@ -0,0 +1,36 @@
+VIRTUAL MACHINE GENERATION ID
+=============================
+
+Copyright (C) 2014 Red Hat, Inc.

Do you want to add 2016?

Otherwise,

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#4 lore raw

Re: [Qemu-devel] [PATCH v17 2/9] docs: vm generation id device's description

Quoted 10 lines · On Wed, 20 Jan 2016 09:40:04 -0700 Eric Blake <[email protected]> wrote:
Quoted 9 lines · Igor Mammedov

From: Gal Hammer <[email protected]>

---
 docs/specs/vmgenid.txt | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 docs/specs/vmgenid.txt
Quoted 12 lines

docs/specs/vmgenid.txt line 4

Quoted 10 lines
docs/specs/vmgenid.txt new file +4 -0
new file mode 100644
index 0000000..718850a
@@ -0,0 +1,36 @@
+VIRTUAL MACHINE GENERATION ID
+=============================
+
+Copyright (C) 2014 Red Hat, Inc.

Do you want to add 2016?

Sure, I'll fix it up.

Quoted 4 lines

Otherwise,

#5 lore raw

PATCH v17 3/9 pc: add a Virtual Machine Generation ID device

In reply to Igor Mammedov

Based on Microsoft's specifications (paper can be downloaded from http://go.microsoft.com/fwlink/?LinkId=260709,
easily found by "Virtual Machine Generation ID" keywords), add a PCI device with corresponding description in SSDT ACPI table.

The GUID is set using "vmgenid.uuid" property.

Example of using vmgenid device:
-device vmgenid,id=FOO,uuid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"

'vmgenid' device initialization flow is as following:
1. vmgenid has RAM BAR registered with size of UUID buffer
2. BIOS initializes PCI devices and it maps BAR in PCI hole
3. BIOS reads ACPI tables from QEMU, at that moment tables are generated with \_SB.VMGI.ADDR constant pointing to GPA where BIOS's mapped vmgenid's BAR earlier

Note:
This implementation uses PCI class 0x0500 code for vmgenid device, that is marked as NO_DRV in Windows's machine.inf. Testing various Windows versions showed that, OS doesn't touch nor checks for resource conflicts
for such PCI devices.
There was concern that during PCI rebalancing, OS
could reprogram the BAR at other place, which would leave VGEN.ADDR pointing to the old (no more valid) address.
However testing showed that Windows does rebalancing only for PCI device that have a driver attached
and completely ignores NO_DRV class of devices.
Which in turn creates a problem where OS could remap one of PCI devices(with driver) over BAR used by
a driver-less PCI device.
Statically declaring used memory range as VGEN._CRS makes OS to honor resource reservation and an ignored BAR range is not longer touched during PCI rebalancing.

---
changes since 14:
- reserve BAR resources so that Windows won't touch it during PCI rebalancing - "Michael S. Tsirkin" <[email protected]>
- ACPI: split VGEN device of PCI device descriptor
and place it at PCI0 scope, so that won't be need trace its location on PCI buses. - "Michael S. Tsirkin" <[email protected]>
- permit only one vmgenid to be created
- enable BAR be mapped above 4Gb if it can't be mapped at low mem

---
 default-configs/i386-softmmu.mak   |   1 +
 default-configs/x86_64-softmmu.mak |   1 +
 docs/specs/pci-ids.txt             |   1 +
 hw/i386/acpi-build.c               |  56 +++++++++++++-
 hw/misc/Makefile.objs              |   1 +
 hw/misc/vmgenid.c                  | 152 +++++++++++++++++++++++++++++++++++++
 include/hw/acpi/acpi.h             |   1 +
 include/hw/misc/vmgenid.h          |  27 +++++++
 include/hw/pci/pci.h               |   1 +
 9 files changed, 239 insertions(+), 2 deletions(-)
 create mode 100644 hw/misc/vmgenid.c
 create mode 100644 include/hw/misc/vmgenid.h
default-configs/i386-softmmu.mak +1 -0
index b177e52..6402439 100644
@@ -51,6 +51,7 @@ CONFIG_APIC=y
 CONFIG_IOAPIC=y
 CONFIG_PVPANIC=y
 CONFIG_MEM_HOTPLUG=y
+CONFIG_VMGENID=y
 CONFIG_NVDIMM=y
 CONFIG_ACPI_NVDIMM=y
 CONFIG_XIO3130=y
default-configs/x86_64-softmmu.mak +1 -0
index 6e3b312..fdac18f 100644
@@ -51,6 +51,7 @@ CONFIG_APIC=y
 CONFIG_IOAPIC=y
 CONFIG_PVPANIC=y
 CONFIG_MEM_HOTPLUG=y
+CONFIG_VMGENID=y
 CONFIG_NVDIMM=y
 CONFIG_ACPI_NVDIMM=y
 CONFIG_XIO3130=y
docs/specs/pci-ids.txt +1 -0
index 0adcb89..e65ecf9 100644
@@ -47,6 +47,7 @@ PCI devices (other than virtio):
 1b36:0005  PCI test device (docs/specs/pci-testdev.txt)
 1b36:0006  PCI Rocker Ethernet switch device
 1b36:0007  PCI SD Card Host Controller Interface (SDHCI)
+1b36:0009  PCI VM-Generation device
 1b36:000a  PCI-PCI bridge (multiseat)
 
 All these devices are documented in docs/specs.
hw/i386/acpi-build.c +54 -2

86 lines not on this page · raw message

hw/misc/Makefile.objs +1 -0
index d4765c2..1f05edd 100644
@@ -43,4 +43,5 @@ obj-$(CONFIG_STM32F2XX_SYSCFG) += stm32f2xx_syscfg.o
 
 obj-$(CONFIG_PVPANIC) += pvpanic.o
 obj-$(CONFIG_EDU) += edu.o
+obj-$(CONFIG_VMGENID) += vmgenid.o
 obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o
hw/misc/vmgenid.c new file +152 -0

152 lines not on this page · raw message

include/hw/acpi/acpi.h +1 -0
index b20bd55..3fb6399 100644
@@ -25,6 +25,7 @@
 #include "qemu/option.h"
 #include "exec/memory.h"
 #include "hw/irq.h"
+#include "hw/acpi/acpi_dev_interface.h"
 
 /*
  * current device naming scheme supports up to 256 memory devices
include/hw/misc/vmgenid.h new file +27 -0
new file mode 100644
index 0000000..e103f23
@@ -0,0 +1,27 @@
+/*
+ *  Virtual Machine Generation ID Device
+ *
+ *  Copyright (C) 2016 Red Hat Inc.
+ *
+ *  Authors: Gal Hammer <[email protected]>
+ *           Igor Mammedov <[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 HW_MISC_VMGENID_H
+#define HW_MISC_VMGENID_H
+
+#include "qom/object.h"
+
+#define VMGENID_DEVICE           "vmgenid"
+#define VMGENID_UUID             "uuid"
+#define VMGENID_VMGID_BUF_ADDR   "vmgid-addr"
+#define VMGENID_VMGID_BUF_SIZE   0x1000
+#define VMGENID_VMGID_BUF_BAR    0
+
+Object *find_vmgneid_dev(Error **errp);
+
+#endif
include/hw/pci/pci.h +1 -0
index dedf277..f4c9d48 100644
@@ -94,6 +94,7 @@
 #define PCI_DEVICE_ID_REDHAT_PXB         0x0009
 #define PCI_DEVICE_ID_REDHAT_BRIDGE_SEAT 0x000a
 #define PCI_DEVICE_ID_REDHAT_PXB_PCIE    0x000b
+#define PCI_DEVICE_ID_REDHAT_VMGENID     0x000c
 #define PCI_DEVICE_ID_REDHAT_QXL         0x0100
 
 #define FMT_PCIBUS                      PRIx64
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH v17 4/9 tests: add a unit test for the vmgenid device.

In reply to Igor Mammedov

* test that guest can read UUID provided on CLI from buffer accessing it at HPA which is available via 'vmgid-addr' property when device is inintialized.
* test setting UUID at runtime and check that it's updated at expected HPA.

---
 tests/Makefile       |  2 ++
 tests/vmgenid-test.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+)
 create mode 100644 tests/vmgenid-test.c
tests/Makefile +2 -0
index b7352f1..8cccf6e 100644
@@ -206,6 +206,7 @@ check-qtest-i386-y += tests/usb-hcd-xhci-test$(EXESUF)
 gcov-files-i386-y += hw/usb/hcd-xhci.c
 check-qtest-i386-y += tests/pc-cpu-test$(EXESUF)
 check-qtest-i386-y += tests/q35-test$(EXESUF)
+check-qtest-i386-y += tests/vmgenid-test$(EXESUF)
 gcov-files-i386-y += hw/pci-host/q35.c
 check-qtest-i386-$(CONFIG_VHOST_NET_TEST_i386) += tests/vhost-user-test$(EXESUF)
 ifeq ($(CONFIG_VHOST_NET_TEST_i386),)
@@ -565,6 +566,7 @@ tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(test-block-o
 tests/test-netfilter$(EXESUF): tests/test-netfilter.o $(qtest-obj-y)
 tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o contrib/ivshmem-server/ivshmem-server.o $(libqos-pc-obj-y)
 tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o
+tests/vmgenid-test$(EXESUF): tests/vmgenid-test.o
 
 ifeq ($(CONFIG_POSIX),y)
 LIBS += -lutil
tests/vmgenid-test.c new file +92 -0

92 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#7 lore raw

PATCH v17 5/9 qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands

In reply to Igor Mammedov

Add commands to query Virtual Machine Generation ID counter.

QMP command example:

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

HMP command example:
info vm-generation-id

---
 hmp-commands-info.hx | 13 +++++++++++++
 hmp.c                |  9 +++++++++
 hmp.h                |  1 +
 hw/misc/vmgenid.c    | 20 ++++++++++++++++++++
 qapi-schema.json     |  9 +++++++++
 qmp-commands.hx      | 19 +++++++++++++++++++
 stubs/Makefile.objs  |  1 +
 stubs/vmgenid.c      |  7 +++++++
 8 files changed, 79 insertions(+)
 create mode 100644 stubs/vmgenid.c
hmp-commands-info.hx +13 -0
index 9b71351..b649a5d 100644
@@ -787,6 +787,19 @@ Display the value of a storage key (s390 only)
 ETEXI
 
 STEXI
+@item info vm-generation-id
+Show Virtual Machine Generation ID
+ETEXI
+
+    {
+        .name       = "vm-generation-id",
+        .args_type  = "",
+        .params     = "",
+        .help       = "Show Virtual Machine Generation ID",
+        .mhandler.cmd = hmp_info_vm_generation_id,
+    },
+
+STEXI
 @end table
 ETEXI
 
hmp.c +9 -0
index 54f2620..63a4457 100644
@@ -2375,3 +2375,12 @@ void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
 
     qapi_free_RockerOfDpaGroupList(list);
 }
+
+void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
+{
+    UuidInfo *info = qmp_query_vm_generation_id(NULL);
+    if (info) {
+        monitor_printf(mon, "%s\n", info->UUID);
+    }
+    qapi_free_UuidInfo(info);
+}
hmp.h +1 -0
index a8c5b5a..21c5132 100644
@@ -131,5 +131,6 @@ void hmp_rocker(Monitor *mon, const QDict *qdict);
 void hmp_rocker_ports(Monitor *mon, const QDict *qdict);
 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_vm_generation_id(Monitor *mon, const QDict *qdict);
 
 #endif
hw/misc/vmgenid.c +20 -0
index 68b4245..9323b23 100644
@@ -16,6 +16,7 @@
 #include "hw/misc/vmgenid.h"
 #include "hw/acpi/acpi.h"
 #include "qapi/visitor.h"
+#include "qmp-commands.h"
 
 #define VMGENID(obj) OBJECT_CHECK(VmGenIdState, (obj), VMGENID_DEVICE)
 
@@ -38,6 +39,25 @@ Object *find_vmgneid_dev(Error **errp)
     return obj;
 }
 
+UuidInfo *qmp_query_vm_generation_id(Error **errp)
+{
+    UuidInfo *info;
+    VmGenIdState *vdev;
+    Object *obj = find_vmgneid_dev(errp);
+
+    if (!obj) {
+        return NULL;
+    }
+    vdev = VMGENID(obj);
+    info = g_malloc0(sizeof(*info));
+    info->UUID = g_strdup_printf(UUID_FMT, vdev->guid[0], vdev->guid[1],
+        vdev->guid[2], vdev->guid[3], vdev->guid[4], vdev->guid[5],
+        vdev->guid[6], vdev->guid[7], vdev->guid[8], vdev->guid[9],
+        vdev->guid[10], vdev->guid[11], vdev->guid[12], vdev->guid[13],
+        vdev->guid[14], vdev->guid[15]);
+    return info;
+}
+
 static void vmgenid_update_guest(VmGenIdState *s)
 {
     Object *acpi_obj;
qapi-schema.json +9 -0
index b3038b2..a4ff6c1 100644
@@ -4081,3 +4081,12 @@
 ##
 { 'enum': 'ReplayMode',
   'data': [ 'none', 'record', 'play' ] }
+
+##
+# @query-vm-generation-id
+#
+# Show Virtual Machine Generation ID
+#
+# Since 2.6
+##
+{ 'command': 'query-vm-generation-id', 'returns': 'UuidInfo' }
qmp-commands.hx +19 -0
index db072a6..9408a3d 100644
@@ -4795,3 +4795,22 @@ Example:
                  {"type": 0, "out-pport": 0, "pport": 0, "vlan-id": 3840,
                   "pop-vlan": 1, "id": 251658240}
    ]}
+
+EQMP
+
+    {
+        .name       = "query-vm-generation-id",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_query_vm_generation_id,
+    },
+
+SQMP
+Show Virtual Machine Generation ID counter
+-----
+
+Arguments: none
+
+Example:
+
+-> { "execute": "query-vm-generation-id" }
+<- {"return": {"UUID": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}}
stubs/Makefile.objs +1 -0
index d7898a0..c1ebfcc 100644
@@ -38,3 +38,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 += vhost.o
+stub-obj-y += vmgenid.o
stubs/vmgenid.c new file +7 -0
new file mode 100644
index 0000000..3cf1013
@@ -0,0 +1,7 @@
+#include "qmp-commands.h"
+
+UuidInfo *qmp_query_vm_generation_id(Error **errp)
+{
+    error_setg(errp, "this command is not currently supported");
+    return NULL;
+}
Signature · 1 line
1.8.3.1
Reviewed-by on v17 5/9
#8 lore raw

Re: [Qemu-devel] [PATCH v17 5/9] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands

Quoted 10 lines · Igor Mammedov

Add commands to query Virtual Machine Generation ID counter.

QMP command example:

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

HMP command example:
info vm-generation-id

---

Quoted 4 lines

+++ b/qapi-schema.json

qapi-schema.json +0 -0
@@ -4081,3 +4081,12 @@
 ##
 { 'enum': 'ReplayMode',

qapi-schema.json line 4092

Quoted 10 lines
qapi-schema.json +9 -0
   'data': [ 'none', 'record', 'play' ] }
+
+##
+# @query-vm-generation-id
+#
+# Show Virtual Machine Generation ID
+#
+# Since 2.6
+##
+{ 'command': 'query-vm-generation-id', 'returns': 'UuidInfo' }

Nice reuse of an existing type, but maybe you want a followup patch to make that type more generically worded (as it is no longer used _just_ for a UUID of the guest):

# @UuidInfo:
#
# Guest UUID information.
#
# @UUID: the UUID of the guest

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#9 lore raw

PATCH v17 6/9 qmp/hmp: add set-vm-generation-id commands

In reply to Igor Mammedov

Add set-vm-generation-id command to set Virtual Machine Generation ID counter.

QMP command example:

    { "execute": "set-vm-generation-id",
          "arguments": {
              "uuid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
          }
    }

HMP command example:

    set-vm-generation-id 324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87
---
 hmp-commands.hx   | 13 +++++++++++++
 hmp.c             | 12 ++++++++++++
 hmp.h             |  1 +
 hw/misc/vmgenid.c | 11 +++++++++++
 qapi-schema.json  |  9 +++++++++
 qmp-commands.hx   | 22 ++++++++++++++++++++++
 stubs/vmgenid.c   |  6 ++++++
 7 files changed, 74 insertions(+)
hmp-commands.hx +13 -0
index bb52e4d..06800b0 100644
@@ -1756,5 +1756,18 @@ ETEXI
     },
 
 STEXI
+@item set-vm-generation-id @var{uuid}
+Set Virtual Machine Generation ID counter to @var{uuid}
+ETEXI
+
+    {
+        .name       = "set-vm-generation-id",
+        .args_type  = "uuid:s",
+        .params     = "uuid",
+        .help       = "Set Virtual Machine Generation ID counter",
+        .mhandler.cmd = hmp_set_vm_generation_id,
+    },
+
+STEXI
 @end table
 ETEXI
hmp.c +12 -0
index 63a4457..fad94f1 100644
@@ -2384,3 +2384,15 @@ void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
     }
     qapi_free_UuidInfo(info);
 }
+
+void hmp_set_vm_generation_id(Monitor *mon, const QDict *qdict)
+{
+    Error *errp = NULL;
+    const char *uuid = qdict_get_str(qdict, "uuid");
+
+    qmp_set_vm_generation_id(uuid, &errp);
+    if (errp != NULL) {
+        hmp_handle_error(mon, &errp);
+        return;
+    }
+}
hmp.h +1 -0
index 21c5132..cbf2045 100644
@@ -132,5 +132,6 @@ void hmp_rocker_ports(Monitor *mon, const QDict *qdict);
 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_vm_generation_id(Monitor *mon, const QDict *qdict);
+void hmp_set_vm_generation_id(Monitor *mon, const QDict *qdict);
 
 #endif
hw/misc/vmgenid.c +11 -0
index 9323b23..bec832f 100644
@@ -58,6 +58,17 @@ UuidInfo *qmp_query_vm_generation_id(Error **errp)
     return info;
 }
 
+void qmp_set_vm_generation_id(const char *uuid, Error **errp)
+{
+    Object *obj = find_vmgneid_dev(errp);
+
+    if (!obj) {
+        return;
+    }
+
+    object_property_set_str(obj, uuid, VMGENID_UUID, errp);
+}
+
 static void vmgenid_update_guest(VmGenIdState *s)
 {
     Object *acpi_obj;
qapi-schema.json +9 -0
index a4ff6c1..789b7d7 100644
@@ -4090,3 +4090,12 @@
 # Since 2.6
 ##
 { 'command': 'query-vm-generation-id', 'returns': 'UuidInfo' }
+
+##
+# @set-vm-generation-id
+#
+# Set Virtual Machine Generation ID
+#
+# Since 2.6
+##
+{ 'command': 'set-vm-generation-id', 'data': { 'uuid': 'str' } }
qmp-commands.hx +22 -0
index 9408a3d..306082f 100644
@@ -4814,3 +4814,25 @@ Example:
 
 -> { "execute": "query-vm-generation-id" }
 <- {"return": {"UUID": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}}
+
+EQMP
+
+    {
+        .name       = "set-vm-generation-id",
+        .args_type  = "uuid:s",
+        .mhandler.cmd_new = qmp_marshal_set_vm_generation_id,
+    },
+
+SQMP
+Set Virtual Machine Generation ID counter
+-----
+
+Arguments:
+
+- "UUID": counter ID in UUID string representation (json-string)"
+
+Example:
+
+-> { "execute": "set-vm-generation-id" ,
+     "arguments": { "uuid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87" } }
+<- {"return": {}}
stubs/vmgenid.c +6 -0
index 3cf1013..0fffb87 100644
@@ -5,3 +5,9 @@ UuidInfo *qmp_query_vm_generation_id(Error **errp)
     error_setg(errp, "this command is not currently supported");
     return NULL;
 }
+
+void qmp_set_vm_generation_id(const char *uuid, Error **errp)
+{
+    error_setg(errp, "this command is not currently supported");
+    return;
+}
Signature · 1 line
1.8.3.1
#10 lore raw

Re: [Qemu-devel] [PATCH v17 6/9] qmp/hmp: add set-vm-generation-id commands

Quoted 19 lines · Igor Mammedov

Add set-vm-generation-id command to set Virtual Machine Generation ID counter.

QMP command example:

    { "execute": "set-vm-generation-id",
          "arguments": {
              "uuid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
          }
    }

HMP command example:

    set-vm-generation-id 324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87

---

+++ b/hmp.c

hmp.c +0 -0
@@ -2384,3 +2384,15 @@ void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
     }

hmp.c void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict) · line 2394

Quoted 10 lines
hmp.c +8 -0
     qapi_free_UuidInfo(info);
 }
+
+void hmp_set_vm_generation_id(Monitor *mon, const QDict *qdict)
+{
+    Error *errp = NULL;
+    const char *uuid = qdict_get_str(qdict, "uuid");
+
+    qmp_set_vm_generation_id(uuid, &errp);
+    if (errp != NULL) {

I might have written 'if (errp)', but that's cosmetic style.

qapi-schema.json line 4098

Quoted 11 lines
qapi-schema.json +7 -0
+++ b/qapi-schema.json
@@ -4090,3 +4090,12 @@
 # Since 2.6
 ##
 { 'command': 'query-vm-generation-id', 'returns': 'UuidInfo' }
+
+##
+# @set-vm-generation-id
+#
+# Set Virtual Machine Generation ID
+#

Missing documentation of the @uuid argument.

qmp-commands.hx Example: · line 4816

Quoted 11 lines
qapi-schema.json +3 -0
+# Since 2.6
+##
+{ 'command': 'set-vm-generation-id', 'data': { 'uuid': 'str' } }
qmp-commands.hx +0 -0
index 9408a3d..306082f 100644
@@ -4814,3 +4814,25 @@ Example:
 
 -> { "execute": "query-vm-generation-id" }
 <- {"return": {"UUID": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}}

Annoying that the set uses 'uuid' and the query responds with 'UUID'; I prefer the lowercase version in new API, so maybe patch 5/9 should create a new return type with desirable spelling rather than reusing the older type.

qmp-commands.hx Example: · line 4832

Quoted 7 lines
qmp-commands.hx +7 -0
+SQMP
+Set Virtual Machine Generation ID counter
+-----
+
+Arguments:
+
+- "UUID": counter ID in UUID string representation (json-string)"

wrong case, per the example.

Quoted 6 lines
qmp-commands.hx +6 -0
+
+Example:
+
+-> { "execute": "set-vm-generation-id" ,
+     "arguments": { "uuid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87" } }
+<- {"return": {}}
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#11 lore raw

Re: [Qemu-devel] [PATCH v17 6/9] qmp/hmp: add set-vm-generation-id commands

Quoted 56 lines · On Wed, 20 Jan 2016 09:48:41 -0700 Eric Blake <[email protected]> wrote:
Quoted 19 lines · Igor Mammedov

Add set-vm-generation-id command to set Virtual Machine Generation ID counter.

QMP command example:

    { "execute": "set-vm-generation-id",
          "arguments": {
              "uuid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
          }
    }

HMP command example:

    set-vm-generation-id 324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87

---

+++ b/hmp.c

hmp.c +0 -0
@@ -2384,3 +2384,15 @@ void hmp_info_vm_generation_id(Monitor *mon,
 const QDict *qdict) }

hmp.c void hmp_info_vm_generation_id(Monitor *mon, · line 2394

Quoted 10 lines
hmp.c +8 -0
     qapi_free_UuidInfo(info);
 }
+
+void hmp_set_vm_generation_id(Monitor *mon, const QDict *qdict)
+{
+    Error *errp = NULL;
+    const char *uuid = qdict_get_str(qdict, "uuid");
+
+    qmp_set_vm_generation_id(uuid, &errp);
+    if (errp != NULL) {

I might have written 'if (errp)', but that's cosmetic style.

qapi-schema.json line 4098

Quoted 11 lines
qapi-schema.json +7 -0
+++ b/qapi-schema.json
@@ -4090,3 +4090,12 @@
 # Since 2.6
 ##
 { 'command': 'query-vm-generation-id', 'returns': 'UuidInfo' }
+
+##
+# @set-vm-generation-id
+#
+# Set Virtual Machine Generation ID
+#

Missing documentation of the @uuid argument.

Quoted 9 lines
qapi-schema.json +3 -0
+# Since 2.6
+##
+{ 'command': 'set-vm-generation-id', 'data': { 'uuid': 'str' } }
qmp-commands.hx +0 -0
index 9408a3d..306082f 100644
@@ -4814,3 +4814,25 @@ Example:
 
Quoted 7 lines

qmp-commands.hx Example: · line 4816

Quoted 2 lines
qmp-commands.hx +0 -0
 -> { "execute": "query-vm-generation-id" }
 <- {"return": {"UUID": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}}

Annoying that the set uses 'uuid' and the query responds with 'UUID'; I prefer the lowercase version in new API, so maybe patch 5/9 should create a new return type with desirable spelling rather than reusing the older type.

ok, I'll add a new type.

Quoted 19 lines

qmp-commands.hx Example: · line 4832

Quoted 9 lines
qmp-commands.hx +7 -0
+SQMP
+Set Virtual Machine Generation ID counter
+-----
+
+Arguments:
+
+- "UUID": counter ID in UUID string representation (json-string)"

wrong case, per the example.

Quoted 6 lines
qmp-commands.hx +5 -0
+
+Example:
+
+-> { "execute": "set-vm-generation-id" ,
+     "arguments": { "uuid":

"324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87" } } +<- {"return": {}}

#12 lore raw

PATCH v17 7/9 add MachineClass->default_props for setting default device properties

In reply to Igor Mammedov
---
 include/hw/boards.h | 1 +
 vl.c                | 4 ++++
 2 files changed, 5 insertions(+)
include/hw/boards.h +1 -0
index 0f30959..d495611 100644
@@ -90,6 +90,7 @@ struct MachineClass {
     const char *default_machine_opts;
     const char *default_boot_order;
     const char *default_display;
+    GlobalProperty *default_props;
     GlobalProperty *compat_props;
     const char *hw_version;
     ram_addr_t default_ram_size;
vl.c +4 -0
index b7a083e..0db74b1 100644
@@ -4492,6 +4492,10 @@ int main(int argc, char **argv, char **envp)
             exit (i == 1 ? 1 : 0);
     }
 
+    if (machine_class->default_props) {
+        qdev_prop_register_global_list(machine_class->default_props);
+    }
+
     if (machine_class->compat_props) {
         qdev_prop_register_global_list(machine_class->compat_props);
     }
Signature · 1 line
1.8.3.1
#13 lore raw

Re: [Qemu-devel] [PATCH v17 7/9] add MachineClass->default_props for setting default device properties

Quoted 11 lines · Igor Mammedov
---
 include/hw/boards.h | 1 +
 vl.c                | 4 ++++
 2 files changed, 5 insertions(+)
include/hw/boards.h +0 -0
index 0f30959..d495611 100644

include/hw/boards.h struct MachineClass { · line 94

Quoted 5 lines
include/hw/boards.h +1 -0
@@ -90,6 +90,7 @@ struct MachineClass {
     const char *default_machine_opts;
     const char *default_boot_order;
     const char *default_display;
+    GlobalProperty *default_props;
     GlobalProperty *compat_props;

Could you explain (in a comment?) the purpose of each field? They seem to do exactly the same thing, so why couldn't they become a single linked list, where the compat classes just append new items to the existing default_props list?

(If we build default_props by appending instead of overwriting the parent class list, we will be able to finally eliminate PC_COMPAT_* macro nesting)

Signature · 1 line
Eduardo
#14 lore raw

Re: [Qemu-devel] [PATCH v17 7/9] add MachineClass->default_props for setting default device properties

Quoted 23 lines · On Sat, 23 Jan 2016 12:59:56 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 11 lines · Igor Mammedov
---
 include/hw/boards.h | 1 +
 vl.c                | 4 ++++
 2 files changed, 5 insertions(+)
include/hw/boards.h +0 -0
index 0f30959..d495611 100644

include/hw/boards.h struct MachineClass { · line 94

Quoted 5 lines
include/hw/boards.h +1 -0
@@ -90,6 +90,7 @@ struct MachineClass {
     const char *default_machine_opts;
     const char *default_boot_order;
     const char *default_display;
+    GlobalProperty *default_props;
     GlobalProperty *compat_props;  

Could you explain (in a comment?) the purpose of each field? They seem to do exactly the same thing, so why couldn't they become a single linked list, where the compat classes just append new items to the existing default_props list?

Quoted 3 lines

(If we build default_props by appending instead of overwriting the parent class list, we will be able to finally eliminate PC_COMPAT_* macro nesting)

The only reason I've added it as separate field is to keep the current way compat_props are working instead of rewriting not related to this series part.

Alternatively we could add qdev_prop_prepend_global_list() API and add static defaults calling it from board's machine-init.

#15 lore raw

Re: [Qemu-devel] [PATCH v17 7/9] add MachineClass->default_props for setting default device properties

Quoted 26 lines · Igor Mammedov
Quoted 23 lines · On Sat, 23 Jan 2016 12:59:56 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 11 lines · Igor Mammedov
---
 include/hw/boards.h | 1 +
 vl.c                | 4 ++++
 2 files changed, 5 insertions(+)
include/hw/boards.h +0 -0
index 0f30959..d495611 100644

include/hw/boards.h struct MachineClass { · line 94

Quoted 5 lines
include/hw/boards.h +1 -0
@@ -90,6 +90,7 @@ struct MachineClass {
     const char *default_machine_opts;
     const char *default_boot_order;
     const char *default_display;
+    GlobalProperty *default_props;
     GlobalProperty *compat_props;  

Could you explain (in a comment?) the purpose of each field? They seem to do exactly the same thing, so why couldn't they become a single linked list, where the compat classes just append new items to the existing default_props list?

Quoted 7 lines
Quoted 3 lines

(If we build default_props by appending instead of overwriting the parent class list, we will be able to finally eliminate PC_COMPAT_* macro nesting)

The only reason I've added it as separate field is to keep the current way compat_props are working instead of rewriting not related to this series part.

OK to me, but I would like to have the reason for having two very similar fields documented in struct MachineClass.

Quoted 2 lines

Alternatively we could add qdev_prop_prepend_global_list() API and add static defaults calling it from board's machine-init.

If we can choose between having stuff in MachineClass and adding extra machine-init code, I prefer to have it in MachineClass.

Signature · 1 line
Eduardo
#16 lore raw

PATCH v17 8/9 pc: put PIIX3 in slot 1 explicitly and cleanup functions assignment

In reply to Igor Mammedov

currently slot for PIIX3 bridge is selected dynamically but it's always in slot 1 for existing machine types.
However it's easy to regress if another PCI device were added before PIIX3 is created and also requires passing around devfn of the created bridge.
Replace dynamic slot assignment with a static one like it's done for ICH9_LPC, explicitly setting slot # for the bridge.
While at it cleanup IDE/USB/PIIX4_PM functions assignment, replacing magic offsets with defines.

---
Static assignment will help with adding other functions to multifunction bridge in following patch.

---
 hw/i386/pc_piix.c    | 17 ++++++++++-------
 hw/pci-host/piix.c   |  9 ++++-----
 include/hw/i386/pc.h |  8 +++++++-
 3 files changed, 21 insertions(+), 13 deletions(-)
hw/i386/pc_piix.c +10 -7
index df2b824..ae96272 100644
@@ -73,7 +73,6 @@ static void pc_init1(MachineState *machine,
     PCIBus *pci_bus;
     ISABus *isa_bus;
     PCII440FXState *i440fx_state;
-    int piix3_devfn = -1;
     qemu_irq *gsi;
     qemu_irq *i8259;
     qemu_irq smi_irq;
@@ -180,7 +179,7 @@ static void pc_init1(MachineState *machine,
     if (pcmc->pci_enabled) {
         pci_bus = i440fx_init(host_type,
                               pci_type,
-                              &i440fx_state, &piix3_devfn, &isa_bus, gsi,
+                              &i440fx_state, &isa_bus, gsi,
                               system_memory, system_io, machine->ram_size,
                               pcms->below_4g_mem_size,
                               pcms->above_4g_mem_size,
@@ -230,9 +229,11 @@ static void pc_init1(MachineState *machine,
     if (pcmc->pci_enabled) {
         PCIDevice *dev;
         if (xen_enabled()) {
-            dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1);
+            dev = pci_piix3_xen_ide_init(pci_bus, hd,
+                PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_IDE_FUNC));
         } else {
-            dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
+            dev = pci_piix3_ide_init(pci_bus, hd,
+                PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_IDE_FUNC));
         }
         idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
         idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
@@ -255,7 +256,8 @@ static void pc_init1(MachineState *machine,
     pc_cmos_init(pcms, idebus[0], idebus[1], rtc_state);
 
     if (pcmc->pci_enabled && usb_enabled()) {
-        pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci");
+        pci_create_simple(pci_bus, PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_USB_FUNC),
+                          "piix3-usb-uhci");
     }
 
     if (pcmc->pci_enabled && acpi_enabled) {
@@ -264,8 +266,9 @@ static void pc_init1(MachineState *machine,
 
         smi_irq = qemu_allocate_irq(pc_acpi_smi_interrupt, first_cpu, 0);
         /* TODO: Populate SPD eeprom data.  */
-        smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
-                              gsi[9], smi_irq,
+        smbus = piix4_pm_init(pci_bus,
+                              PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_PIIX4_PM_FUNC),
+                              0xb100, gsi[9], smi_irq,
                               pc_machine_is_smm_enabled(pcms),
                               &piix4_pm);
         smbus_eeprom_init(smbus, 8, NULL, 0);
hw/pci-host/piix.c +4 -5
index b0d7e31..b8bf1fc 100644
@@ -310,7 +310,6 @@ static void i440fx_realize(PCIDevice *dev, Error **errp)
 
 PCIBus *i440fx_init(const char *host_type, const char *pci_type,
                     PCII440FXState **pi440fx_state,
-                    int *piix3_devfn,
                     ISABus **isa_bus, qemu_irq *pic,
                     MemoryRegion *address_space_mem,
                     MemoryRegion *address_space_io,
@@ -382,13 +381,15 @@ PCIBus *i440fx_init(const char *host_type, const char *pci_type,
      * These additional routes can be discovered through ACPI. */
     if (xen_enabled()) {
         PCIDevice *pci_dev = pci_create_simple_multifunction(b,
-                             -1, true, "PIIX3-xen");
+                             PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_PCI_FUNC),
+                             true, "PIIX3-xen");
         piix3 = PIIX3_PCI_DEVICE(pci_dev);
         pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq,
                 piix3, XEN_PIIX_NUM_PIRQS);
     } else {
         PCIDevice *pci_dev = pci_create_simple_multifunction(b,
-                             -1, true, "PIIX3");
+                             PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_PCI_FUNC),
+                             true, "PIIX3");
         piix3 = PIIX3_PCI_DEVICE(pci_dev);
         pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3,
                 PIIX_NUM_PIRQS);
@@ -397,8 +398,6 @@ PCIBus *i440fx_init(const char *host_type, const char *pci_type,
     piix3->pic = pic;
     *isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(piix3), "isa.0"));
 
-    *piix3_devfn = piix3->dev.devfn;
-
     ram_size = ram_size / 8 / 1024 / 1024;
     if (ram_size > 255) {
         ram_size = 255;
include/hw/i386/pc.h +7 -1
index 588a33c..ea0c1d7 100644
@@ -288,8 +288,14 @@ typedef struct PCII440FXState PCII440FXState;
 
 #define TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE "igd-passthrough-i440FX"
 
+#define PIIX3_PCI_SLOT                       1
+#define PIIX3_PCI_FUNC                       0
+#define PIIX3_IDE_FUNC                       1
+#define PIIX3_USB_FUNC                       2
+#define PIIX3_PIIX4_PM_FUNC                  3
+
 PCIBus *i440fx_init(const char *host_type, const char *pci_type,
-                    PCII440FXState **pi440fx_state, int *piix_devfn,
+                    PCII440FXState **pi440fx_state,
                     ISABus **isa_bus, qemu_irq *pic,
                     MemoryRegion *address_space_mem,
                     MemoryRegion *address_space_io,
Signature · 1 line
1.8.3.1
#17 lore raw

PATCH v17 9/9 pc/q53: by default put vmgenid device as an function of ISA bridge

In reply to Igor Mammedov

it will save a PCI slot that would be used otherwise.

---
 hw/i386/pc_piix.c      | 12 ++++++++++++
 hw/i386/pc_q35.c       | 12 ++++++++++++
 include/hw/i386/ich9.h |  3 ++-
 include/hw/i386/pc.h   |  1 +
 4 files changed, 27 insertions(+), 1 deletion(-)
hw/i386/pc_piix.c +12 -0
index ae96272..65b8982 100644
@@ -54,6 +54,7 @@
 #endif
 #include "migration/migration.h"
 #include "kvm_i386.h"
+#include "hw/misc/vmgenid.h"
 
 #define MAX_IDE_BUS 2
 
@@ -415,6 +416,17 @@ static void pc_xen_hvm_init(MachineState *machine)
 
 static void pc_i440fx_machine_options(MachineClass *m)
 {
+    static GlobalProperty dev_defaults[] = {
+        {
+            .driver   = VMGENID_DEVICE,
+            .property = "addr",
+            .value    = stringify(PIIX3_PCI_SLOT) "."
+                        stringify(PIIX3_VMGENID_FUNC),
+        },
+        {}
+    };
+
+    m->default_props = dev_defaults;
     m->family = "pc_piix";
     m->desc = "Standard PC (i440FX + PIIX, 1996)";
     m->hot_add_cpu = pc_hot_add_cpu;
hw/i386/pc_q35.c +12 -0
index 412b3cd..e147b95 100644
@@ -45,6 +45,7 @@
 #include "hw/usb.h"
 #include "qemu/error-report.h"
 #include "migration/migration.h"
+#include "hw/misc/vmgenid.h"
 
 /* ICH9 AHCI has 6 ports */
 #define MAX_SATA_PORTS     6
@@ -339,6 +340,17 @@ static void pc_compat_1_4(MachineState *machine)
 
 static void pc_q35_machine_options(MachineClass *m)
 {
+    static GlobalProperty dev_defaults[] = {
+        {
+            .driver   = VMGENID_DEVICE,
+            .property = "addr",
+            .value    = stringify(ICH9_LPC_DEV) "."
+                        stringify(ICH9_LPC_VMGENID_FUNC),
+        },
+        {}
+    };
+
+    m->default_props = dev_defaults;
     m->family = "pc_q35";
     m->desc = "Standard PC (Q35 + ICH9, 2009)";
     m->hot_add_cpu = pc_hot_add_cpu;
include/hw/i386/ich9.h +2 -1
index b9d2b04..271b0c7 100644
@@ -129,8 +129,9 @@ Object *ich9_lpc_find(void);
 #define ICH9_A2_LPC                             "ICH9 A2 LPC"
 #define ICH9_A2_LPC_SAVEVM_VERSION              0
 
-#define ICH9_LPC_DEV                            31
+#define ICH9_LPC_DEV                            0x1f
 #define ICH9_LPC_FUNC                           0
+#define ICH9_LPC_VMGENID_FUNC                   6
 
 #define ICH9_A2_LPC_REVISION                    0x2
 #define ICH9_LPC_NB_PIRQS                       8       /* PCI A-H */
include/hw/i386/pc.h +1 -0
index ea0c1d7..9f54211 100644
@@ -293,6 +293,7 @@ typedef struct PCII440FXState PCII440FXState;
 #define PIIX3_IDE_FUNC                       1
 #define PIIX3_USB_FUNC                       2
 #define PIIX3_PIIX4_PM_FUNC                  3
+#define PIIX3_VMGENID_FUNC                   7
 
 PCIBus *i440fx_init(const char *host_type, const char *pci_type,
                     PCII440FXState **pi440fx_state,
Signature · 1 line
1.8.3.1
#18 lore raw
In reply to Igor Mammedov

Here is SSDT ASL diff with vmgenid device present that Laszlo's asked for:

@@ -135,6 +135,11 @@ DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS

         })
     }

+ Method (\_GPE._E00, 0, NotSerialized) // _Exx: Edge-Triggered GPE
+ {
+ Notify (\_SB.PCI0.VGEN, 0x80) // Status Change
+ }
+

     Scope (\_SB)
     {
         Device (PCI0.PRES)
@@ -703,6 +708,28 @@ DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS
                 DVNT (PCIU, One)
                 DVNT (PCID, 0x03)
             }
+
+            Device (VGEN)
+            {
+                Name (_HID, "QEMU0003")  // _HID: Hardware ID
+                Name (_CID, "VM_Gen_Counter")  // _CID: Compatible ID
+                Name (_DDN, "VM_Gen_Counter")  // _DDN: DOS Device Name
+                Name (ADDR, Package (0x02)
+                {
+                    0xFEBF0000, 
+                    Zero
+                })
+                Name (_CRS, ResourceTemplate ()  // _CRS: Current Resource Settings
+                {
+                    QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
+                        0x0000000000000000, // Granularity
+                        0x00000000FEBF0000, // Range Minimum
+                        0x00000000FEBF0FFF, // Range Maximum
+                        0x0000000000000000, // Translation Offset
+                        0x0000000000001000, // Length
+                        ,, , AddressRangeMemory, TypeStatic)
+                })
+            }
         }
     }

}

'make V=1 check' doesn't show it since I've forgot to extend bios-tables-test with vmgenid variant, but it should be a separate patch anyway and I'd prefer to do it after I merge DSDT with SSDT, which will reduce number of test blobs we keep in tree along with other benefits.

Quoted 73 lines · On Tue, 19 Jan 2016 14:06:20 +0100 Igor Mammedov <[email protected]> wrote:

It's respin of v14* series which uses a PCI BAR to map VGID page in guest AS.

Changes since v14:
- statically reserve used BAR resources in SSDT, so that Windows won't claim them during PCI rebalancing
- support VGID page in high mem in addition to low mem
- add QMP/HMP interfaces to get/set VM Generation ID
- do not consume a PCI slot by default and attach vmgenid device as a function of multifuction ISA bridge.
- allow only one vmgenid device instance

Tested with WS2012R2x64.
Git tree for testing:
https://github.com/imammedo/qemu.git vmgenid_v17

* v14, https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg00530.html

Gal Hammer (1):
docs: vm generation id device's description

Igor Mammedov (8):
acpi: extend ACPI interface to provide access to ACPI registers and
SCI irq
pc: add a Virtual Machine Generation ID device
tests: add a unit test for the vmgenid device.
qmp/hmp: add query-vm-generation-id and 'info vm-generation-id'
commands
qmp/hmp: add set-vm-generation-id commands
add MachineClass->default_props for setting default device properties
pc: put PIIX3 in slot 1 explicitly and cleanup functions assignment pc/q53: by default put vmgenid device as an function of ISA bridge

 default-configs/i386-softmmu.mak     |   1 +
 default-configs/x86_64-softmmu.mak   |   1 +
 docs/specs/pci-ids.txt               |   1 +
 docs/specs/vmgenid.txt               |  36 +++++++
 hmp-commands-info.hx                 |  13 +++
 hmp-commands.hx                      |  13 +++
 hmp.c                                |  21 ++++
 hmp.h                                |   2 +
 hw/acpi/piix4.c                      |  17 ++++
 hw/i386/acpi-build.c                 |  56 ++++++++++-
 hw/i386/pc_piix.c                    |  29 ++++--
 hw/i386/pc_q35.c                     |  12 +++
 hw/isa/lpc_ich9.c                    |  16 +++
 hw/isa/vt82c686.c                    |  19 ++++
 hw/misc/Makefile.objs                |   1 +
 hw/misc/vmgenid.c                    | 183 +++++++++++++++++++++++++++++++++++
 hw/pci-host/piix.c                   |   9 +-
 include/hw/acpi/acpi.h               |   1 +
 include/hw/acpi/acpi_dev_interface.h |   9 ++
 include/hw/boards.h                  |   1 +
 include/hw/i386/ich9.h               |   3 +-
 include/hw/i386/pc.h                 |   9 +-
 include/hw/misc/vmgenid.h            |  27 ++++++
 include/hw/pci/pci.h                 |   1 +
 qapi-schema.json                     |  18 ++++
 qmp-commands.hx                      |  41 ++++++++
 stubs/Makefile.objs                  |   1 +
 stubs/vmgenid.c                      |  13 +++
 tests/Makefile                       |   2 +
 tests/vmgenid-test.c                 |  92 ++++++++++++++++++
 vl.c                                 |   4 +
 31 files changed, 636 insertions(+), 16 deletions(-)
 create mode 100644 docs/specs/vmgenid.txt
 create mode 100644 hw/misc/vmgenid.c
 create mode 100644 include/hw/misc/vmgenid.h
 create mode 100644 stubs/vmgenid.c
 create mode 100644 tests/vmgenid-test.c
#19 lore raw

Review DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS · line 142

Quoted 12 lines · Igor Mammedov

Here is SSDT ASL diff with vmgenid device present that Laszlo's asked for:

(quoted diff) +5 -0
@@ -135,6 +135,11 @@ DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS
         })
     }
 
+    Method (\_GPE._E00, 0, NotSerialized)  // _Exx: Edge-Triggered GPE
+    {
+        Notify (\_SB.PCI0.VGEN, 0x80) // Status Change
+    }
+

Thanks a lot! I have one comment for this: I think _E00 cannot be used. Please see the argument in my earlier (now obsolete) patch:

[PATCH FYI 02/13] hw/acpi: add i386 callbacks for injecting GPE 04
when the VMGENID changes

http://thread.gmane.org/gmane.comp.emulators.qemu/357940/focus=361705

Thanks!
Laszlo

Quoted 117 lines
(quoted diff) +22 -0
     Scope (\_SB)
     {
         Device (PCI0.PRES)
@@ -703,6 +708,28 @@ DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS
                 DVNT (PCIU, One)
                 DVNT (PCID, 0x03)
             }
+
+            Device (VGEN)
+            {
+                Name (_HID, "QEMU0003")  // _HID: Hardware ID
+                Name (_CID, "VM_Gen_Counter")  // _CID: Compatible ID
+                Name (_DDN, "VM_Gen_Counter")  // _DDN: DOS Device Name
+                Name (ADDR, Package (0x02)
+                {
+                    0xFEBF0000, 
+                    Zero
+                })
+                Name (_CRS, ResourceTemplate ()  // _CRS: Current Resource Settings
+                {
+                    QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
+                        0x0000000000000000, // Granularity
+                        0x00000000FEBF0000, // Range Minimum
+                        0x00000000FEBF0FFF, // Range Maximum
+                        0x0000000000000000, // Translation Offset
+                        0x0000000000001000, // Length
+                        ,, , AddressRangeMemory, TypeStatic)
+                })
+            }
         }
     }
 }

'make V=1 check' doesn't show it since I've forgot to extend bios-tables-test with vmgenid variant, but it should be a separate patch anyway and I'd prefer to do it after I merge DSDT with SSDT, which will reduce number of test blobs we keep in tree along with other benefits.

Quoted 73 lines · On Tue, 19 Jan 2016 14:06:20 +0100 Igor Mammedov <[email protected]> wrote:

It's respin of v14* series which uses a PCI BAR to map VGID page in guest AS.

Changes since v14:
- statically reserve used BAR resources in SSDT, so that Windows won't claim them during PCI rebalancing
- support VGID page in high mem in addition to low mem
- add QMP/HMP interfaces to get/set VM Generation ID
- do not consume a PCI slot by default and attach vmgenid device as a function of multifuction ISA bridge.
- allow only one vmgenid device instance

Tested with WS2012R2x64.
Git tree for testing:
https://github.com/imammedo/qemu.git vmgenid_v17

* v14, https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg00530.html

Gal Hammer (1):
docs: vm generation id device's description

Igor Mammedov (8):
acpi: extend ACPI interface to provide access to ACPI registers and
SCI irq
pc: add a Virtual Machine Generation ID device
tests: add a unit test for the vmgenid device.
qmp/hmp: add query-vm-generation-id and 'info vm-generation-id'
commands
qmp/hmp: add set-vm-generation-id commands
add MachineClass->default_props for setting default device properties
pc: put PIIX3 in slot 1 explicitly and cleanup functions assignment pc/q53: by default put vmgenid device as an function of ISA bridge

 default-configs/i386-softmmu.mak     |   1 +
 default-configs/x86_64-softmmu.mak   |   1 +
 docs/specs/pci-ids.txt               |   1 +
 docs/specs/vmgenid.txt               |  36 +++++++
 hmp-commands-info.hx                 |  13 +++
 hmp-commands.hx                      |  13 +++
 hmp.c                                |  21 ++++
 hmp.h                                |   2 +
 hw/acpi/piix4.c                      |  17 ++++
 hw/i386/acpi-build.c                 |  56 ++++++++++-
 hw/i386/pc_piix.c                    |  29 ++++--
 hw/i386/pc_q35.c                     |  12 +++
 hw/isa/lpc_ich9.c                    |  16 +++
 hw/isa/vt82c686.c                    |  19 ++++
 hw/misc/Makefile.objs                |   1 +
 hw/misc/vmgenid.c                    | 183 +++++++++++++++++++++++++++++++++++
 hw/pci-host/piix.c                   |   9 +-
 include/hw/acpi/acpi.h               |   1 +
 include/hw/acpi/acpi_dev_interface.h |   9 ++
 include/hw/boards.h                  |   1 +
 include/hw/i386/ich9.h               |   3 +-
 include/hw/i386/pc.h                 |   9 +-
 include/hw/misc/vmgenid.h            |  27 ++++++
 include/hw/pci/pci.h                 |   1 +
 qapi-schema.json                     |  18 ++++
 qmp-commands.hx                      |  41 ++++++++
 stubs/Makefile.objs                  |   1 +
 stubs/vmgenid.c                      |  13 +++
 tests/Makefile                       |   2 +
 tests/vmgenid-test.c                 |  92 ++++++++++++++++++
 vl.c                                 |   4 +
 31 files changed, 636 insertions(+), 16 deletions(-)
 create mode 100644 docs/specs/vmgenid.txt
 create mode 100644 hw/misc/vmgenid.c
 create mode 100644 include/hw/misc/vmgenid.h
 create mode 100644 stubs/vmgenid.c
 create mode 100644 tests/vmgenid-test.c
#20 lore raw
Quoted 17 lines · On Tue, 19 Jan 2016 17:49:30 +0100 Laszlo Ersek <[email protected]> wrote:

Review DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS · line 142

Quoted 12 lines · Igor Mammedov

Here is SSDT ASL diff with vmgenid device present that Laszlo's asked for:

(quoted diff) +5 -0
@@ -135,6 +135,11 @@ DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS
         })
     }
 
+    Method (\_GPE._E00, 0, NotSerialized)  // _Exx: Edge-Triggered GPE
+    {
+        Notify (\_SB.PCI0.VGEN, 0x80) // Status Change
+    }
+  

Thanks a lot! I have one comment for this: I think _E00 cannot be used. Please see the argument in my earlier (now obsolete) patch:

Quoted 7 lines

[PATCH FYI 02/13] hw/acpi: add i386 callbacks for injecting GPE 04
when the VMGENID changes

http://thread.gmane.org/gmane.comp.emulators.qemu/357940/focus=361705

Thanks!
Laszlo

It should be ok to use _E00 per spec since it's GPE event.

Here is quote from spec to what you were referring in your patch:

'(A query response of 0 from the embedded controller is reserved for “no outstanding events.”)'

That limits 0 bit handler limitation only to 'embedded controller' which is handled by _QXX methods.

Quoted 120 lines
Quoted 119 lines
(quoted diff) +22 -0
     Scope (\_SB)
     {
         Device (PCI0.PRES)
@@ -703,6 +708,28 @@ DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS
                 DVNT (PCIU, One)
                 DVNT (PCID, 0x03)
             }
+
+            Device (VGEN)
+            {
+                Name (_HID, "QEMU0003")  // _HID: Hardware ID
+                Name (_CID, "VM_Gen_Counter")  // _CID: Compatible ID
+                Name (_DDN, "VM_Gen_Counter")  // _DDN: DOS Device Name
+                Name (ADDR, Package (0x02)
+                {
+                    0xFEBF0000, 
+                    Zero
+                })
+                Name (_CRS, ResourceTemplate ()  // _CRS: Current Resource Settings
+                {
+                    QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
+                        0x0000000000000000, // Granularity
+                        0x00000000FEBF0000, // Range Minimum
+                        0x00000000FEBF0FFF, // Range Maximum
+                        0x0000000000000000, // Translation Offset
+                        0x0000000000001000, // Length
+                        ,, , AddressRangeMemory, TypeStatic)
+                })
+            }
         }
     }
 }

'make V=1 check' doesn't show it since I've forgot to extend bios-tables-test with vmgenid variant, but it should be a separate patch anyway and I'd prefer to do it after I merge DSDT with SSDT, which will reduce number of test blobs we keep in tree along with other benefits.

Quoted 73 lines · On Tue, 19 Jan 2016 14:06:20 +0100 Igor Mammedov <[email protected]> wrote:

It's respin of v14* series which uses a PCI BAR to map VGID page in guest AS.

Changes since v14:
- statically reserve used BAR resources in SSDT, so that Windows won't claim them during PCI rebalancing
- support VGID page in high mem in addition to low mem
- add QMP/HMP interfaces to get/set VM Generation ID
- do not consume a PCI slot by default and attach vmgenid device as a function of multifuction ISA bridge.
- allow only one vmgenid device instance

Tested with WS2012R2x64.
Git tree for testing:
https://github.com/imammedo/qemu.git vmgenid_v17

* v14, https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg00530.html

Gal Hammer (1):
docs: vm generation id device's description

Igor Mammedov (8):
acpi: extend ACPI interface to provide access to ACPI registers and
SCI irq
pc: add a Virtual Machine Generation ID device
tests: add a unit test for the vmgenid device.
qmp/hmp: add query-vm-generation-id and 'info vm-generation-id'
commands
qmp/hmp: add set-vm-generation-id commands
add MachineClass->default_props for setting default device properties
pc: put PIIX3 in slot 1 explicitly and cleanup functions assignment pc/q53: by default put vmgenid device as an function of ISA bridge

 default-configs/i386-softmmu.mak     |   1 +
 default-configs/x86_64-softmmu.mak   |   1 +
 docs/specs/pci-ids.txt               |   1 +
 docs/specs/vmgenid.txt               |  36 +++++++
 hmp-commands-info.hx                 |  13 +++
 hmp-commands.hx                      |  13 +++
 hmp.c                                |  21 ++++
 hmp.h                                |   2 +
 hw/acpi/piix4.c                      |  17 ++++
 hw/i386/acpi-build.c                 |  56 ++++++++++-
 hw/i386/pc_piix.c                    |  29 ++++--
 hw/i386/pc_q35.c                     |  12 +++
 hw/isa/lpc_ich9.c                    |  16 +++
 hw/isa/vt82c686.c                    |  19 ++++
 hw/misc/Makefile.objs                |   1 +
 hw/misc/vmgenid.c                    | 183 +++++++++++++++++++++++++++++++++++
 hw/pci-host/piix.c                   |   9 +-
 include/hw/acpi/acpi.h               |   1 +
 include/hw/acpi/acpi_dev_interface.h |   9 ++
 include/hw/boards.h                  |   1 +
 include/hw/i386/ich9.h               |   3 +-
 include/hw/i386/pc.h                 |   9 +-
 include/hw/misc/vmgenid.h            |  27 ++++++
 include/hw/pci/pci.h                 |   1 +
 qapi-schema.json                     |  18 ++++
 qmp-commands.hx                      |  41 ++++++++
 stubs/Makefile.objs                  |   1 +
 stubs/vmgenid.c                      |  13 +++
 tests/Makefile                       |   2 +
 tests/vmgenid-test.c                 |  92 ++++++++++++++++++
 vl.c                                 |   4 +
 31 files changed, 636 insertions(+), 16 deletions(-)
 create mode 100644 docs/specs/vmgenid.txt
 create mode 100644 hw/misc/vmgenid.c
 create mode 100644 include/hw/misc/vmgenid.h
 create mode 100644 stubs/vmgenid.c
 create mode 100644 tests/vmgenid-test.c
#21 lore raw
Quoted 29 lines · Igor Mammedov
Quoted 17 lines · On Tue, 19 Jan 2016 17:49:30 +0100 Laszlo Ersek <[email protected]> wrote:

Review DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS · line 142

Quoted 12 lines · Igor Mammedov

Here is SSDT ASL diff with vmgenid device present that Laszlo's asked for:

(quoted diff) +5 -0
@@ -135,6 +135,11 @@ DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS
         })
     }
 
+    Method (\_GPE._E00, 0, NotSerialized)  // _Exx: Edge-Triggered GPE
+    {
+        Notify (\_SB.PCI0.VGEN, 0x80) // Status Change
+    }
+  

Thanks a lot! I have one comment for this: I think _E00 cannot be used. Please see the argument in my earlier (now obsolete) patch:

Quoted 7 lines

[PATCH FYI 02/13] hw/acpi: add i386 callbacks for injecting GPE 04
when the VMGENID changes

http://thread.gmane.org/gmane.comp.emulators.qemu/357940/focus=361705

Thanks!
Laszlo

It should be ok to use _E00 per spec since it's GPE event.

Quoted 7 lines

Here is quote from spec to what you were referring in your patch:

'(A query response of 0 from the embedded controller is reserved for “no outstanding events.”)'

That limits 0 bit handler limitation only to 'embedded controller' which is handled by _QXX methods.

Okay.

My other remark / question is then, do you think that having *both* _L00 and _E00 is valid?

The section under

5.6.4.1.1 Queuing the Matching Control Method for Execution

seems to suggest that it's either-or; you can have at most one kind of handler (either _Exx for edge triggered, or _Lxx for level triggered).

_L00 is already present in the DSDT; see build_dsdt():

        aml_append(scope, aml_method("_L00", 0, AML_NOTSERIALIZED));

and this series adds _E00.

... Hm, wait, it's okay -- your "[PATCH v17 3/9] pc: add a Virtual Machine Generation ID device" removes the _L00 method. Cool.

(I just wonder why the ASL diff you posted didn't show this... I guess because that diff was for the SSDT only, and the _L00 method was removed from the DSDT.)

Thanks!
Laszlo

Quoted 122 lines
Quoted 121 lines
Quoted 120 lines
(quoted diff) +22 -0
     Scope (\_SB)
     {
         Device (PCI0.PRES)
@@ -703,6 +708,28 @@ DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS
                 DVNT (PCIU, One)
                 DVNT (PCID, 0x03)
             }
+
+            Device (VGEN)
+            {
+                Name (_HID, "QEMU0003")  // _HID: Hardware ID
+                Name (_CID, "VM_Gen_Counter")  // _CID: Compatible ID
+                Name (_DDN, "VM_Gen_Counter")  // _DDN: DOS Device Name
+                Name (ADDR, Package (0x02)
+                {
+                    0xFEBF0000, 
+                    Zero
+                })
+                Name (_CRS, ResourceTemplate ()  // _CRS: Current Resource Settings
+                {
+                    QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
+                        0x0000000000000000, // Granularity
+                        0x00000000FEBF0000, // Range Minimum
+                        0x00000000FEBF0FFF, // Range Maximum
+                        0x0000000000000000, // Translation Offset
+                        0x0000000000001000, // Length
+                        ,, , AddressRangeMemory, TypeStatic)
+                })
+            }
         }
     }
 }

'make V=1 check' doesn't show it since I've forgot to extend bios-tables-test with vmgenid variant, but it should be a separate patch anyway and I'd prefer to do it after I merge DSDT with SSDT, which will reduce number of test blobs we keep in tree along with other benefits.

Quoted 73 lines · On Tue, 19 Jan 2016 14:06:20 +0100 Igor Mammedov <[email protected]> wrote:

It's respin of v14* series which uses a PCI BAR to map VGID page in guest AS.

Changes since v14:
- statically reserve used BAR resources in SSDT, so that Windows won't claim them during PCI rebalancing
- support VGID page in high mem in addition to low mem
- add QMP/HMP interfaces to get/set VM Generation ID
- do not consume a PCI slot by default and attach vmgenid device as a function of multifuction ISA bridge.
- allow only one vmgenid device instance

Tested with WS2012R2x64.
Git tree for testing:
https://github.com/imammedo/qemu.git vmgenid_v17

* v14, https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg00530.html

Gal Hammer (1):
docs: vm generation id device's description

Igor Mammedov (8):
acpi: extend ACPI interface to provide access to ACPI registers and
SCI irq
pc: add a Virtual Machine Generation ID device
tests: add a unit test for the vmgenid device.
qmp/hmp: add query-vm-generation-id and 'info vm-generation-id'
commands
qmp/hmp: add set-vm-generation-id commands
add MachineClass->default_props for setting default device properties
pc: put PIIX3 in slot 1 explicitly and cleanup functions assignment pc/q53: by default put vmgenid device as an function of ISA bridge

 default-configs/i386-softmmu.mak     |   1 +
 default-configs/x86_64-softmmu.mak   |   1 +
 docs/specs/pci-ids.txt               |   1 +
 docs/specs/vmgenid.txt               |  36 +++++++
 hmp-commands-info.hx                 |  13 +++
 hmp-commands.hx                      |  13 +++
 hmp.c                                |  21 ++++
 hmp.h                                |   2 +
 hw/acpi/piix4.c                      |  17 ++++
 hw/i386/acpi-build.c                 |  56 ++++++++++-
 hw/i386/pc_piix.c                    |  29 ++++--
 hw/i386/pc_q35.c                     |  12 +++
 hw/isa/lpc_ich9.c                    |  16 +++
 hw/isa/vt82c686.c                    |  19 ++++
 hw/misc/Makefile.objs                |   1 +
 hw/misc/vmgenid.c                    | 183 +++++++++++++++++++++++++++++++++++
 hw/pci-host/piix.c                   |   9 +-
 include/hw/acpi/acpi.h               |   1 +
 include/hw/acpi/acpi_dev_interface.h |   9 ++
 include/hw/boards.h                  |   1 +
 include/hw/i386/ich9.h               |   3 +-
 include/hw/i386/pc.h                 |   9 +-
 include/hw/misc/vmgenid.h            |  27 ++++++
 include/hw/pci/pci.h                 |   1 +
 qapi-schema.json                     |  18 ++++
 qmp-commands.hx                      |  41 ++++++++
 stubs/Makefile.objs                  |   1 +
 stubs/vmgenid.c                      |  13 +++
 tests/Makefile                       |   2 +
 tests/vmgenid-test.c                 |  92 ++++++++++++++++++
 vl.c                                 |   4 +
 31 files changed, 636 insertions(+), 16 deletions(-)
 create mode 100644 docs/specs/vmgenid.txt
 create mode 100644 hw/misc/vmgenid.c
 create mode 100644 include/hw/misc/vmgenid.h
 create mode 100644 stubs/vmgenid.c
 create mode 100644 tests/vmgenid-test.c
#22 lore raw
Quoted 55 lines · On Wed, 20 Jan 2016 15:20:12 +0100 Laszlo Ersek <[email protected]> wrote:
Quoted 30 lines · Igor Mammedov
Quoted 18 lines · On Tue, 19 Jan 2016 17:49:30 +0100 Laszlo Ersek <[email protected]> wrote:

Review

Quoted 13 lines · Igor Mammedov

Here is SSDT ASL diff with vmgenid device present that Laszlo's asked for:

(quoted diff) +1 -0
@@ -135,6 +135,11 @@ DefinitionBlock
 ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ",
 "BXPCS }) }
 
+    Method (\_GPE._E00, 0, NotSerialized)  // _Exx:

Edge-Triggered GPE

(quoted diff) +4 -0
+    {
+        Notify (\_SB.PCI0.VGEN, 0x80) // Status Change
+    }
+  

Thanks a lot! I have one comment for this: I think _E00 cannot be used. Please see the argument in my earlier (now obsolete) patch:

Quoted 7 lines

[PATCH FYI 02/13] hw/acpi: add i386 callbacks for injecting GPE
04 when the VMGENID changes

http://thread.gmane.org/gmane.comp.emulators.qemu/357940/focus=361705

Thanks!
Laszlo

It should be ok to use _E00 per spec since it's GPE event.

Quoted 7 lines

Here is quote from spec to what you were referring in your patch:

'(A query response of 0 from the embedded controller is reserved for “no outstanding events.”)'

That limits 0 bit handler limitation only to 'embedded controller' which is handled by _QXX methods.

Okay.

My other remark / question is then, do you think that having *both* _L00 and _E00 is valid?

The section under

5.6.4.1.1 Queuing the Matching Control Method for Execution

seems to suggest that it's either-or; you can have at most one kind of handler (either _Exx for edge triggered, or _Lxx for level triggered).

_L00 is already present in the DSDT; see build_dsdt():

        aml_append(scope, aml_method("_L00", 0, AML_NOTSERIALIZED));
Quoted 8 lines

and this series adds _E00.

... Hm, wait, it's okay -- your "[PATCH v17 3/9] pc: add a Virtual Machine Generation ID device" removes the _L00 method. Cool.

(I just wonder why the ASL diff you posted didn't show this... I guess because that diff was for the SSDT only, and the _L00 method was removed from the DSDT.)

yep, and I'm working on merging both tables which should allow to simplify/reduce generated ASL code and it's maintenance in future.

Quoted 134 lines

Thanks!
Laszlo

Quoted 128 lines
Quoted 127 lines
Quoted 126 lines


     Scope (\_SB)
     {
         Device (PCI0.PRES)
(quoted diff) +0 -0
@@ -703,6 +708,28 @@ DefinitionBlock

("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS DVNT (PCIU, One) DVNT (PCID, 0x03)

             }
(quoted diff) +5 -0
+
+            Device (VGEN)
+            {
+                Name (_HID, "QEMU0003")  // _HID: Hardware ID
+                Name (_CID, "VM_Gen_Counter")  // _CID:

Compatible ID
+ Name (_DDN, "VM_Gen_Counter") // _DDN: DOS
Device Name

(quoted diff) +6 -0
+                Name (ADDR, Package (0x02)
+                {
+                    0xFEBF0000, 
+                    Zero
+                })
+                Name (_CRS, ResourceTemplate ()  // _CRS:

Current Resource Settings

(quoted diff) +2 -0
+                {
+                    QWordMemory (ResourceProducer, PosDecode,

MinFixed, MaxFixed, Cacheable, ReadWrite,

(quoted diff) +8 -0
+                        0x0000000000000000, // Granularity
+                        0x00000000FEBF0000, // Range Minimum
+                        0x00000000FEBF0FFF, // Range Maximum
+                        0x0000000000000000, // Translation Offset
+                        0x0000000000001000, // Length
+                        ,, , AddressRangeMemory, TypeStatic)
+                })
+            }
         }
     }
 }

'make V=1 check' doesn't show it since I've forgot to extend bios-tables-test with vmgenid variant, but it should be a separate patch anyway and I'd prefer to do it after I merge DSDT with SSDT, which will reduce number of test blobs we keep in tree along with other benefits.

Quoted 75 lines · On Tue, 19 Jan 2016 14:06:20 +0100 Igor Mammedov <[email protected]> wrote:

It's respin of v14* series which uses a PCI BAR to map VGID page in guest AS.

Changes since v14:
- statically reserve used BAR resources in SSDT, so that Windows won't claim them during PCI rebalancing
- support VGID page in high mem in addition to low mem
- add QMP/HMP interfaces to get/set VM Generation ID
- do not consume a PCI slot by default and attach vmgenid device as a function of multifuction ISA bridge.
- allow only one vmgenid device instance

Tested with WS2012R2x64.
Git tree for testing:
https://github.com/imammedo/qemu.git vmgenid_v17

* v14,
https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg00530.html

Gal Hammer (1):
docs: vm generation id device's description

Igor Mammedov (8):
acpi: extend ACPI interface to provide access to ACPI
registers and SCI irq
pc: add a Virtual Machine Generation ID device
tests: add a unit test for the vmgenid device. qmp/hmp: add query-vm-generation-id and 'info vm-generation-id'
commands
qmp/hmp: add set-vm-generation-id commands
add MachineClass->default_props for setting default device
properties pc: put PIIX3 in slot 1 explicitly and cleanup functions assignment pc/q53: by default put vmgenid device as an function of ISA bridge

 default-configs/i386-softmmu.mak     |   1 +
 default-configs/x86_64-softmmu.mak   |   1 +
 docs/specs/pci-ids.txt               |   1 +
 docs/specs/vmgenid.txt               |  36 +++++++
 hmp-commands-info.hx                 |  13 +++
 hmp-commands.hx                      |  13 +++
 hmp.c                                |  21 ++++
 hmp.h                                |   2 +
 hw/acpi/piix4.c                      |  17 ++++
 hw/i386/acpi-build.c                 |  56 ++++++++++-
 hw/i386/pc_piix.c                    |  29 ++++--
 hw/i386/pc_q35.c                     |  12 +++
 hw/isa/lpc_ich9.c                    |  16 +++
 hw/isa/vt82c686.c                    |  19 ++++
 hw/misc/Makefile.objs                |   1 +
 hw/misc/vmgenid.c                    | 183
+++++++++++++++++++++++++++++++++++
hw/pci-host/piix.c                   |   9 +-
include/hw/acpi/acpi.h               |   1 +
include/hw/acpi/acpi_dev_interface.h |   9 ++
include/hw/boards.h                  |   1 +
include/hw/i386/ich9.h               |   3 +-
include/hw/i386/pc.h                 |   9 +-
include/hw/misc/vmgenid.h            |  27 ++++++
include/hw/pci/pci.h                 |   1 +
qapi-schema.json                     |  18 ++++
qmp-commands.hx                      |  41 ++++++++
stubs/Makefile.objs                  |   1 +
stubs/vmgenid.c                      |  13 +++
tests/Makefile                       |   2 +
tests/vmgenid-test.c                 |  92 ++++++++++++++++++
vl.c                                 |   4 + 31 files changed,
636 insertions(+), 16 deletions(-) create mode 100644
docs/specs/vmgenid.txt create mode 100644 hw/misc/vmgenid.c
 create mode 100644 include/hw/misc/vmgenid.h
 create mode 100644 stubs/vmgenid.c
 create mode 100644 tests/vmgenid-test.c