All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/5] RFC: Add support for VM Generation ID
@ 2016-12-19 22:46 ben
  2016-12-19 22:46 ` [Qemu-devel] [PATCH 1/5] docs: vm generation id device's description ben
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: ben @ 2016-12-19 22:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ben Warren

From: Ben Warren <ben@skyportsystems.com>

This patch set adds support for passing a GUID to Windows guests.  It is a
re-implementation of previous patch sets written by Igor Mammedov et al, but
this time passing the GUID data as a fw_cfg blob.

This has been tested to work with Windows 2012 R2.  I consider it RFC quality
since there are probably problems with the HMP implementation and no unit tests
are included.

Ben Warren (3):
  docs: vm generation id device's description
  ACPI: Add a function for building named qword entries
  ACPI: Add Virtual Machine Generation ID support

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

 default-configs/i386-softmmu.mak   |   1 +
 default-configs/x86_64-softmmu.mak |   1 +
 docs/specs/vmgenid.txt             |  39 ++++++++
 hmp-commands-info.hx               |  13 +++
 hmp-commands.hx                    |  13 +++
 hmp.c                              |  22 +++++
 hmp.h                              |   2 +
 hw/acpi/Makefile.objs              |   1 +
 hw/acpi/aml-build.c                |  28 ++++++
 hw/acpi/vmgenid.c                  | 198 +++++++++++++++++++++++++++++++++++++
 hw/i386/acpi-build.c               |   5 +
 hw/misc/Makefile.objs              |   1 +
 include/hw/acpi/aml-build.h        |   4 +
 include/hw/acpi/vmgenid.h          |  26 +++++
 qapi-schema.json                   |  32 ++++++
 stubs/Makefile.objs                |   1 +
 stubs/vmgenid.c                    |  14 +++
 17 files changed, 401 insertions(+)
 create mode 100644 docs/specs/vmgenid.txt
 create mode 100644 hw/acpi/vmgenid.c
 create mode 100644 include/hw/acpi/vmgenid.h
 create mode 100644 stubs/vmgenid.c

-- 
2.7.4

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 1/5] docs: vm generation id device's description
  2016-12-19 22:46 [Qemu-devel] [PATCH 0/5] RFC: Add support for VM Generation ID ben
@ 2016-12-19 22:46 ` ben
  2016-12-19 22:46 ` [Qemu-devel] [PATCH 2/5] ACPI: Add a function for building named qword entries ben
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: ben @ 2016-12-19 22:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ben Warren, Gal Hammer

From: Ben Warren <ben@skyportsystems.com>

Signed-off-by: Ben Warren <ben@skyportsystems.com>
Cc: Gal Hammer <ghammer@redhat.com>
---
 docs/specs/vmgenid.txt | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 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..94277a9
--- /dev/null
+++ b/docs/specs/vmgenid.txt
@@ -0,0 +1,39 @@
+VIRTUAL MACHINE GENERATION ID
+=============================
+
+Copyright (C) 2016 Red Hat, Inc.
+Copyright (C) 2016 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.
+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 sysbus device with the ACPI ID "QEMU_Gen_Counter_V1".
+
+The device has two properties, which can be set using the command line
+argument or the QMP interface:
+ guid - sets the value of the GUID
+ changed - signals that the value has changed since the last invocation
+For example:
+QEMU  -device vmgenid,changed=true,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
+
+Or to change guid in runtime use:
+ set-vm-generation-id changed=true guid="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.
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 2/5] ACPI: Add a function for building named qword entries
  2016-12-19 22:46 [Qemu-devel] [PATCH 0/5] RFC: Add support for VM Generation ID ben
  2016-12-19 22:46 ` [Qemu-devel] [PATCH 1/5] docs: vm generation id device's description ben
@ 2016-12-19 22:46 ` ben
  2016-12-19 22:46 ` [Qemu-devel] [PATCH 3/5] ACPI: Add Virtual Machine Generation ID support ben
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: ben @ 2016-12-19 22:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ben Warren

From: Ben Warren <ben@skyportsystems.com>

Signed-off-by: Ben Warren <ben@skyportsystems.com>
---
 hw/acpi/aml-build.c         | 28 ++++++++++++++++++++++++++++
 include/hw/acpi/aml-build.h |  4 ++++
 2 files changed, 32 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index b2a1e40..dc4edc2 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -285,6 +285,34 @@ build_append_named_dword(GArray *array, const char *name_format, ...)
     return offset;
 }
 
+/*
+ * Build NAME(XXXX, 0x00000000) where 0x00000000 is encoded as a qword,
+ * and return the offset to 0x00000000 for runtime patching.
+ *
+ * Warning: runtime patching is best avoided. Only use this as
+ * a replacement for DataTableRegion (for guests that don't
+ * support it).
+ */
+int
+build_append_named_qword(GArray *array, const char *name_format, ...)
+{
+    int offset;
+    va_list ap;
+
+    build_append_byte(array, 0x08); /* NameOp */
+    va_start(ap, name_format);
+    build_append_namestringv(array, name_format, ap);
+    va_end(ap);
+
+    build_append_byte(array, 0x0E); /* QWordPrefix */
+
+    offset = array->len;
+    build_append_int_noprefix(array, 0x00000000, 8);
+    assert(array->len == offset + 8);
+
+    return offset;
+}
+
 static GPtrArray *alloc_list;
 
 static Aml *aml_alloc(void)
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 559326c..dbf63cf 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -385,6 +385,10 @@ int
 build_append_named_dword(GArray *array, const char *name_format, ...)
 GCC_FMT_ATTR(2, 3);
 
+int
+build_append_named_qword(GArray *array, const char *name_format, ...)
+GCC_FMT_ATTR(2, 3);
+
 void build_srat_memory(AcpiSratMemoryAffinity *numamem, uint64_t base,
                        uint64_t len, int node, MemoryAffinityFlags flags);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 3/5] ACPI: Add Virtual Machine Generation ID support
  2016-12-19 22:46 [Qemu-devel] [PATCH 0/5] RFC: Add support for VM Generation ID ben
  2016-12-19 22:46 ` [Qemu-devel] [PATCH 1/5] docs: vm generation id device's description ben
  2016-12-19 22:46 ` [Qemu-devel] [PATCH 2/5] ACPI: Add a function for building named qword entries ben
@ 2016-12-19 22:46 ` ben
  2016-12-19 22:46 ` [Qemu-devel] [PATCH 4/5] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands ben
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: ben @ 2016-12-19 22:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ben Warren

From: Ben Warren <ben@skyportsystems.com>

This implements the VM Generation ID feature by passing a 128-bit
GUID to the guest via a fw_cfg blob.

The user interface is a simple device with two parameters:
 - guid (string, must be in UUID format
   xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
 - changed (boolean, signal to the guest that the guid value is new

Signed-off-by: Ben Warren <ben@skyportsystems.com>
---
 default-configs/i386-softmmu.mak   |   1 +
 default-configs/x86_64-softmmu.mak |   1 +
 hw/acpi/Makefile.objs              |   1 +
 hw/acpi/vmgenid.c                  | 198 +++++++++++++++++++++++++++++++++++++
 hw/i386/acpi-build.c               |   5 +
 hw/misc/Makefile.objs              |   1 +
 include/hw/acpi/vmgenid.h          |  26 +++++
 7 files changed, 233 insertions(+)
 create mode 100644 hw/acpi/vmgenid.c
 create mode 100644 include/hw/acpi/vmgenid.h

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 0b51360..b2bccf6 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -56,3 +56,4 @@ CONFIG_IOH3420=y
 CONFIG_I82801B11=y
 CONFIG_SMBIOS=y
 CONFIG_HYPERV_TESTDEV=$(CONFIG_KVM)
+CONFIG_ACPI_VMGENID=y
diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-softmmu.mak
index 7f89503..c6bd310 100644
--- a/default-configs/x86_64-softmmu.mak
+++ b/default-configs/x86_64-softmmu.mak
@@ -56,3 +56,4 @@ CONFIG_IOH3420=y
 CONFIG_I82801B11=y
 CONFIG_SMBIOS=y
 CONFIG_HYPERV_TESTDEV=$(CONFIG_KVM)
+CONFIG_ACPI_VMGENID=y
diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
index 489e63b..7dc95cd 100644
--- a/hw/acpi/Makefile.objs
+++ b/hw/acpi/Makefile.objs
@@ -4,6 +4,7 @@ common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o
 common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o memory_hotplug_acpi_table.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-$(CONFIG_ACPI) += acpi_interface.o
 common-obj-$(CONFIG_ACPI) += bios-linker-loader.o
 common-obj-$(CONFIG_ACPI) += aml-build.o
diff --git a/hw/acpi/vmgenid.c b/hw/acpi/vmgenid.c
new file mode 100644
index 0000000..0f094a7
--- /dev/null
+++ b/hw/acpi/vmgenid.c
@@ -0,0 +1,198 @@
+/*
+ *  Virtual Machine Generation ID Device
+ *
+ *  Copyright (C) 2016 Skyport Systems.
+ *
+ *  Authors: Ben Warren <ben@skyportsystems.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qmp-commands.h"
+#include "hw/acpi/aml-build.h"
+#include "hw/acpi/vmgenid.h"
+#include "hw/nvram/fw_cfg.h"
+
+Object *find_vmgenid_dev(Error **errp)
+{
+    Object *obj = object_resolve_path_type("", VMGENID_DEVICE, NULL);
+    if (!obj) {
+        error_setg(errp, VMGENID_DEVICE " is not found");
+    }
+    return obj;
+}
+
+void vmgenid_build_acpi(GArray *table_offsets, GArray *table_data,
+        BIOSLinker *linker)
+{
+    Object *obj = find_vmgenid_dev(NULL);
+    if (!obj) {
+        return;
+    }
+    VmGenIdState *s = VMGENID(obj);
+
+    acpi_add_table(table_offsets, table_data);
+
+    GArray *guid = g_array_new(false, true, sizeof(s->guid.data));
+    g_array_append_val(guid, s->guid.data);
+
+    Aml *ssdt, *dev, *scope, *pkg, *method;
+
+    /* Put this in a separate SSDT table */
+    ssdt = init_aml_allocator();
+
+    /* Reserve space for header */
+    acpi_data_push(ssdt->buf, sizeof(AcpiTableHeader));
+
+    /* Storage for the GUID address */
+    uint32_t vgia_offset = table_data->len +
+        build_append_named_qword(ssdt->buf, "VGIA");
+    dev = aml_device("VGEN");
+    scope = aml_scope("_SB");
+    aml_append(dev, aml_name_decl("_HID", aml_string("QEMU_Gen_Counter_V1")));
+    aml_append(dev, aml_name_decl("_CID", aml_string("VM_Gen_Counter")));
+    aml_append(dev, aml_name_decl("_DDN", aml_string("VM_Gen_Counter")));
+
+    /* Simple status method to check that address is linked and non-zero */
+    method = aml_method("_STA", 0, AML_NOTSERIALIZED);
+    Aml *if_ctx = aml_if(aml_equal(aml_name("VGIA"), aml_int(0)));
+    aml_append(if_ctx, aml_return(aml_int(0)));
+    aml_append(method, if_ctx);
+    Aml *else_ctx = aml_else();
+    aml_append(else_ctx, aml_return(aml_int(0xf)));
+    aml_append(method, else_ctx);
+    aml_append(dev, method);
+
+    /* the ADDR method returns two 32-bit words representing the lower and
+     * upper halves * of the physical address of the fw_cfg blob
+     * (holding the GUID) */
+    method = aml_method("ADDR", 0, AML_NOTSERIALIZED);
+
+    pkg = aml_package(2);
+    aml_append(pkg, aml_int(0));
+    aml_append(pkg, aml_int(0));
+
+    aml_append(method, aml_name_decl("LPKG", pkg));
+    aml_append(method,aml_store(aml_and(aml_name("VGIA"),
+        aml_int(0xffffffff), NULL), aml_index(aml_name("LPKG"), aml_int(0))));
+    aml_append(method, aml_store(aml_shiftright(aml_name("VGIA"),
+        aml_int(32), NULL), aml_index(aml_name("LPKG"), aml_int(1))));
+    aml_append(method, aml_return(aml_name("LPKG")));
+
+    aml_append(dev, method);
+    aml_append(scope, dev);
+    aml_append(ssdt, scope);
+
+    /* If the VM Generation ID has changed, attach a notify */
+    if (s->is_changed) {
+        scope = aml_scope("_GPE");
+        method = aml_method("_E00", 0, AML_NOTSERIALIZED);
+        aml_append(method, aml_notify(aml_name("_SB.VGEN"), aml_int(0x80)));
+        aml_append(scope, method);
+        aml_append(ssdt, scope);
+    }
+
+    /* copy AML table into ACPI tables blob and patch in fw_cfg blob */
+    g_array_append_vals(table_data, ssdt->buf->data, ssdt->buf->len);
+    bios_linker_loader_alloc(linker, VMGENID_FW_CFG_FILE, guid, 0,
+                             false /* high memory */);
+    bios_linker_loader_add_pointer(linker,
+        ACPI_BUILD_TABLE_FILE, vgia_offset, sizeof(uint64_t),
+        VMGENID_FW_CFG_FILE, 0);
+
+    build_header(linker, table_data,
+        (void *)(table_data->data + table_data->len - ssdt->buf->len),
+        "SSDT", ssdt->buf->len, 1, NULL, "VMGENID");
+    free_aml_allocator();
+}
+
+void vmgenid_add_fw_cfg(FWCfgState *s)
+{
+    Object *obj = find_vmgenid_dev(NULL);
+    if (!obj) {
+        return;
+    }
+    VmGenIdState *vms = VMGENID(obj);
+    fw_cfg_add_file(s, VMGENID_FW_CFG_FILE, vms->guid.data,
+        sizeof(vms->guid.data));
+}
+
+static void vmgenid_set_guid(Object *obj, const char *value, Error **errp)
+{
+    VmGenIdState *s = VMGENID(obj);
+
+    if (qemu_uuid_parse(value, &s->guid) < 0) {
+        error_setg(errp, "'%s." VMGENID_GUID
+                   "': Failed to parse GUID string: %s",
+                   object_get_typename(OBJECT(s)),
+                   value);
+        return;
+    }
+}
+
+static void vmgenid_set_changed(Object *obj, bool changed, Error **errp)
+{
+    VmGenIdState *s = VMGENID(obj);
+
+    if (changed == s->is_changed) {
+        return;
+    }
+    s->is_changed = changed;
+}
+
+static void vmgenid_initfn(Object *obj)
+{
+    object_property_add_str(obj, VMGENID_GUID, NULL, vmgenid_set_guid, NULL);
+    object_property_add_bool(obj, VMGENID_CHANGED, NULL,
+                            vmgenid_set_changed, NULL);
+}
+
+static const TypeInfo vmgenid_device_info = {
+    .name          = VMGENID_DEVICE,
+    .parent	       = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(VmGenIdState),
+    .instance_init = vmgenid_initfn,
+};
+
+static void vmgenid_register_types(void)
+{
+    type_register_static(&vmgenid_device_info);
+}
+
+type_init(vmgenid_register_types)
+
+GuidInfo *qmp_query_vm_generation_id(Error **errp)
+{
+    GuidInfo *info;
+    VmGenIdState *vdev;
+    Object *obj = find_vmgenid_dev(errp);
+
+    if (!obj) {
+        return NULL;
+    }
+    vdev = VMGENID(obj);
+    info = g_malloc0(sizeof(*info));
+    info->guid = g_strdup_printf(UUID_FMT, vdev->guid.data[0],
+            vdev->guid.data[1], vdev->guid.data[2], vdev->guid.data[3],
+            vdev->guid.data[4], vdev->guid.data[5], vdev->guid.data[6],
+            vdev->guid.data[7], vdev->guid.data[8], vdev->guid.data[9],
+            vdev->guid.data[10], vdev->guid.data[11], vdev->guid.data[12],
+            vdev->guid.data[13], vdev->guid.data[14], vdev->guid.data[15]);
+    return info;
+}
+
+void qmp_set_vm_generation_id(bool changed, const char *guid, Error **errp)
+{
+    Object *obj = find_vmgenid_dev(errp);
+
+    if (!obj) {
+        return;
+    }
+
+    object_property_set_str(obj, guid, VMGENID_GUID, errp);
+    object_property_set_bool(obj, changed, VMGENID_CHANGED, errp);
+    return;
+}
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 9708cdc..cde81b7 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -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"
@@ -2785,6 +2786,8 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
     acpi_add_table(table_offsets, tables_blob);
     build_madt(tables_blob, tables->linker, pcms);
 
+    vmgenid_build_acpi(table_offsets, tables_blob, tables->linker);
+
     if (misc.has_hpet) {
         acpi_add_table(table_offsets, tables_blob);
         build_hpet(tables_blob, tables->linker);
@@ -2991,6 +2994,8 @@ void acpi_setup(void)
     fw_cfg_add_file(pcms->fw_cfg, ACPI_BUILD_TPMLOG_FILE,
                     tables.tcpalog->data, acpi_data_len(tables.tcpalog));
 
+    vmgenid_add_fw_cfg(pcms->fw_cfg);
+
     if (!pcmc->rsdp_in_ram) {
         /*
          * Keep for compatibility with old machine types.
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
index 1a89615..ca0f1bb 100644
--- a/hw/misc/Makefile.objs
+++ b/hw/misc/Makefile.objs
@@ -53,3 +53,4 @@ obj-$(CONFIG_EDU) += edu.o
 obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o
 obj-$(CONFIG_AUX) += auxbus.o
 obj-$(CONFIG_ASPEED_SOC) += aspeed_scu.o aspeed_sdmc.o
+obj-$(CONFIG_VMGENID) += vmgenid.o
diff --git a/include/hw/acpi/vmgenid.h b/include/hw/acpi/vmgenid.h
new file mode 100644
index 0000000..990ccf1
--- /dev/null
+++ b/include/hw/acpi/vmgenid.h
@@ -0,0 +1,26 @@
+#ifndef ACPI_VMGENID_H
+#define ACPI_VMGENID_H
+
+#include "hw/acpi/bios-linker-loader.h"
+#include "hw/sysbus.h"
+#include "qemu/uuid.h"
+
+#define VMGENID_DEVICE           "vmgenid"
+#define VMGENID_GUID             "guid"
+#define VMGENID_CHANGED          "changed"
+#define VMGENID_FW_CFG_FILE      "etc/vmgenid"
+
+Object *find_vmgenid_dev(Error **errp);
+void vmgenid_add_fw_cfg(FWCfgState *s);
+void vmgenid_build_acpi(GArray *table_offsets, GArray *table_data,
+                       BIOSLinker *linker);
+
+#define VMGENID(obj) OBJECT_CHECK(VmGenIdState, (obj), VMGENID_DEVICE)
+
+typedef struct VmGenIdState {
+    SysBusDevice parent_obj;
+    QemuUUID guid;
+    bool is_changed;
+} VmGenIdState;
+
+#endif
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 4/5] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands
  2016-12-19 22:46 [Qemu-devel] [PATCH 0/5] RFC: Add support for VM Generation ID ben
                   ` (2 preceding siblings ...)
  2016-12-19 22:46 ` [Qemu-devel] [PATCH 3/5] ACPI: Add Virtual Machine Generation ID support ben
@ 2016-12-19 22:46 ` ben
  2016-12-19 22:46 ` [Qemu-devel] [PATCH 5/5] qmp/hmp: add set-vm-generation-id commands ben
  2016-12-20 23:04 ` [Qemu-devel] [PATCH 0/5] RFC: Add support for VM Generation ID no-reply
  5 siblings, 0 replies; 9+ messages in thread
From: ben @ 2016-12-19 22:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Ben Warren

From: Igor Mammedov <imammedo@redhat.com>

Add commands to query Virtual Machine Generation ID counter.

QMP command example:
    { "execute": "query-vm-generation-id" }

HMP command example:
    info vm-generation-id

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Ben Warren <ben@skyportsystems.com>
---
 hmp-commands-info.hx | 13 +++++++++++++
 hmp.c                |  9 +++++++++
 hmp.h                |  1 +
 qapi-schema.json     | 20 ++++++++++++++++++++
 stubs/Makefile.objs  |  1 +
 stubs/vmgenid.c      |  8 ++++++++
 6 files changed, 52 insertions(+)
 create mode 100644 stubs/vmgenid.c

diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index 55d50c4..b0bb052 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -802,6 +802,19 @@ Show information about hotpluggable CPUs
 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",
+        .cmd = hmp_info_vm_generation_id,
+    },
+
+STEXI
 @end table
 ETEXI
 
diff --git a/hmp.c b/hmp.c
index b869617..9ec27ae 100644
--- a/hmp.c
+++ b/hmp.c
@@ -2570,3 +2570,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);
+}
diff --git a/hmp.h b/hmp.h
index 05daf7c..799fd37 100644
--- a/hmp.h
+++ b/hmp.h
@@ -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
diff --git a/qapi-schema.json b/qapi-schema.json
index a0d3b5d..2348391 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4776,3 +4776,23 @@
 # Since: 2.7
 ##
 { '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' }
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 2b5bb74..988d5d7 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -50,3 +50,4 @@ stub-obj-y += smbios_type_38.o
 stub-obj-y += ipmi.o
 stub-obj-y += pc_madt_cpu_entry.o
 stub-obj-y += migration-colo.o
+stub-obj-y += vmgenid.o
diff --git a/stubs/vmgenid.c b/stubs/vmgenid.c
new file mode 100644
index 0000000..8c448ac
--- /dev/null
+++ b/stubs/vmgenid.c
@@ -0,0 +1,8 @@
+#include "qemu/osdep.h"
+#include "qmp-commands.h"
+
+GuidInfo *qmp_query_vm_generation_id(Error **errp)
+{
+    error_setg(errp, "this command is not currently supported");
+    return NULL;
+}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 5/5] qmp/hmp: add set-vm-generation-id commands
  2016-12-19 22:46 [Qemu-devel] [PATCH 0/5] RFC: Add support for VM Generation ID ben
                   ` (3 preceding siblings ...)
  2016-12-19 22:46 ` [Qemu-devel] [PATCH 4/5] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands ben
@ 2016-12-19 22:46 ` ben
  2016-12-20 14:36   ` Eric Blake
  2016-12-20 23:04 ` [Qemu-devel] [PATCH 0/5] RFC: Add support for VM Generation ID no-reply
  5 siblings, 1 reply; 9+ messages in thread
From: ben @ 2016-12-19 22:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Ben Warren, Eric Blake

From: Igor Mammedov <imammedo@redhat.com>

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

QMP command example:
    { "execute": "set-vm-generation-id",
          "arguments": {
              "changed": true,
              "guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
          }
    }

HMP command example:
    set-vm-generation-id changed=true guid=324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87

Signed-off-by: Ben Warren <ben@skyportsystems.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Eric Blake <eblake@redhat.com>
---
 hmp-commands.hx  | 13 +++++++++++++
 hmp.c            | 13 +++++++++++++
 hmp.h            |  1 +
 qapi-schema.json | 12 ++++++++++++
 stubs/vmgenid.c  |  6 ++++++
 5 files changed, 45 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 8819281..495fc95 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1775,5 +1775,18 @@ ETEXI
     },
 
 STEXI
+@item set-vm-generation-id @var{changed} @var{uuid}
+Set Virtual Machine Generation ID counter to @var{guid}
+ETEXI
+
+    {
+        .name       = "set-vm-generation-id",
+        .args_type  = "changed:b,guid:s",
+        .params     = "changed guid",
+        .help       = "Set Virtual Machine Generation ID counter",
+        .cmd = hmp_set_vm_generation_id,
+    },
+
+STEXI
 @end table
 ETEXI
diff --git a/hmp.c b/hmp.c
index 9ec27ae..d73af31 100644
--- a/hmp.c
+++ b/hmp.c
@@ -2579,3 +2579,16 @@ void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
     }
     qapi_free_GuidInfo(info);
 }
+
+void hmp_set_vm_generation_id(Monitor *mon, const QDict *qdict)
+{
+    Error *errp = NULL;
+    const char *guid = qdict_get_str(qdict, "guid");
+    bool changed = qdict_get_bool(qdict, "changed");
+
+    qmp_set_vm_generation_id(changed, guid, &errp);
+    if (errp) {
+        hmp_handle_error(mon, &errp);
+        return;
+    }
+}
diff --git a/hmp.h b/hmp.h
index 799fd37..e0ac1e8 100644
--- a/hmp.h
+++ b/hmp.h
@@ -138,5 +138,6 @@ 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);
+void hmp_set_vm_generation_id(Monitor *mon, const QDict *qdict);
 
 #endif
diff --git a/qapi-schema.json b/qapi-schema.json
index 2348391..72f3515 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4796,3 +4796,15 @@
 # Since 2.9
 ##
 { 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }
+
+##
+# @set-vm-generation-id
+#
+# Set Virtual Machine Generation ID
+#
+# @changed: Is the Virtual Machine Generation ID a new value?
+# @guid: new GUID to set as Virtual Machine Generation ID
+#
+# Since 2.9
+##
+{ 'command': 'set-vm-generation-id', 'data': { 'changed': 'bool', 'guid': 'str' } }
diff --git a/stubs/vmgenid.c b/stubs/vmgenid.c
index 8c448ac..588aeb4 100644
--- a/stubs/vmgenid.c
+++ b/stubs/vmgenid.c
@@ -6,3 +6,9 @@ GuidInfo *qmp_query_vm_generation_id(Error **errp)
     error_setg(errp, "this command is not currently supported");
     return NULL;
 }
+
+void qmp_set_vm_generation_id(bool changed, const char *guid, Error **errp)
+{
+    error_setg(errp, "this command is not currently supported");
+    return;
+}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH 5/5] qmp/hmp: add set-vm-generation-id commands
  2016-12-19 22:46 ` [Qemu-devel] [PATCH 5/5] qmp/hmp: add set-vm-generation-id commands ben
@ 2016-12-20 14:36   ` Eric Blake
  2016-12-20 17:23     ` Ben Warren
  0 siblings, 1 reply; 9+ messages in thread
From: Eric Blake @ 2016-12-20 14:36 UTC (permalink / raw)
  To: ben, qemu-devel; +Cc: Igor Mammedov

[-- Attachment #1: Type: text/plain, Size: 1387 bytes --]

On 12/19/2016 04:46 PM, ben@skyportsystems.com wrote:
> From: Igor Mammedov <imammedo@redhat.com>
> 
> Add set-vm-generation-id command to set Virtual Machine
> Generation ID counter.
> 
> QMP command example:
>     { "execute": "set-vm-generation-id",
>           "arguments": {
>               "changed": true,
>               "guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
>           }
>     }
> 
> HMP command example:
>     set-vm-generation-id changed=true guid=324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87
> 
> Signed-off-by: Ben Warren <ben@skyportsystems.com>
> Cc: Igor Mammedov <imammedo@redhat.com>
> Cc: Eric Blake <eblake@redhat.com>
> ---

> +++ b/qapi-schema.json
> @@ -4796,3 +4796,15 @@
>  # Since 2.9
>  ##
>  { 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }
> +
> +##
> +# @set-vm-generation-id
> +#
> +# Set Virtual Machine Generation ID
> +#
> +# @changed: Is the Virtual Machine Generation ID a new value?
> +# @guid: new GUID to set as Virtual Machine Generation ID
> +#
> +# Since 2.9
> +##
> +{ 'command': 'set-vm-generation-id', 'data': { 'changed': 'bool', 'guid': 'str' } }

When should 'changed' ever be set to false?  Should it be an optional
parameter, defaulting to true, if it is even needed?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH 5/5] qmp/hmp: add set-vm-generation-id commands
  2016-12-20 14:36   ` Eric Blake
@ 2016-12-20 17:23     ` Ben Warren
  0 siblings, 0 replies; 9+ messages in thread
From: Ben Warren @ 2016-12-20 17:23 UTC (permalink / raw)
  To: Eric Blake; +Cc: qemu-devel, Igor Mammedov

[-- Attachment #1: Type: text/plain, Size: 3180 bytes --]

Hi Eric,
> On Dec 20, 2016, at 6:36 AM, Eric Blake <eblake@redhat.com> wrote:
> 
> On 12/19/2016 04:46 PM, ben@skyportsystems.com <mailto:ben@skyportsystems.com> wrote:
>> From: Igor Mammedov <imammedo@redhat.com>
>> 
>> Add set-vm-generation-id command to set Virtual Machine
>> Generation ID counter.
>> 
>> QMP command example:
>>    { "execute": "set-vm-generation-id",
>>          "arguments": {
>>              "changed": true,
>>              "guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
>>          }
>>    }
>> 
>> HMP command example:
>>    set-vm-generation-id changed=true guid=324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87
>> 
>> Signed-off-by: Ben Warren <ben@skyportsystems.com>
>> Cc: Igor Mammedov <imammedo@redhat.com>
>> Cc: Eric Blake <eblake@redhat.com>
>> ---
> 
>> +++ b/qapi-schema.json
>> @@ -4796,3 +4796,15 @@
>> # Since 2.9
>> ##
>> { 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }
>> +
>> +##
>> +# @set-vm-generation-id
>> +#
>> +# Set Virtual Machine Generation ID
>> +#
>> +# @changed: Is the Virtual Machine Generation ID a new value?
>> +# @guid: new GUID to set as Virtual Machine Generation ID
>> +#
>> +# Since 2.9
>> +##
>> +{ 'command': 'set-vm-generation-id', 'data': { 'changed': 'bool', 'guid': 'str' } }
> 
> When should 'changed' ever be set to false?  Should it be an optional
> parameter, defaulting to true, if it is even needed?
> 
Let me explain the intent, then we can talk about implementation.  I apologize if this is stuff you already know.  The purpose of VM Generation ID in Windows is to detect time rollbacks.  Active Directory in particular can get out of sync in hard-to-debug ways.  VM Generation ID is supposed to help with this, in that it tells Windows that a time rollback has occurred and therefore its AD data is “dirty” and must be “pull-synced” from its replication partners.  The problem is that this replication can be quite costly in large installations, so I want to only do it if necessary.  So the answer to your question is that “changed” will be false most of the time, and will be set to true only in a couple of situations: new VM instantiation and snapshot rollback.  It’s up to the managing service (libvirt or custom SW, I guess) to manage the lifecycle of a VM and set this flag accordingly.

Now, the VM Generation ID spec identifies an ACPI Notify operation that is bound to the VM Generation ID ACPI object.  I have this GPE only being set if the ‘changed’ variable is true.  I don’t know enough about ACPI to know if this is the right approach, and will be doing as much testing within Windows to see if this does what I want, but as I’m sure you know Windows is pretty opaque and it’s not always obvious how to get the relevant information.

I have both Hyper-V and Xen setups available and am trying to emulate the Hyper-V one since we should probably consider it to be a reference design.  I know Xen just sets this thing blindly and we can do better than that.

> -- 
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org <http://libvirt.org/>
—Ben


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 3583 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH 0/5] RFC: Add support for VM Generation ID
  2016-12-19 22:46 [Qemu-devel] [PATCH 0/5] RFC: Add support for VM Generation ID ben
                   ` (4 preceding siblings ...)
  2016-12-19 22:46 ` [Qemu-devel] [PATCH 5/5] qmp/hmp: add set-vm-generation-id commands ben
@ 2016-12-20 23:04 ` no-reply
  5 siblings, 0 replies; 9+ messages in thread
From: no-reply @ 2016-12-20 23:04 UTC (permalink / raw)
  To: ben; +Cc: famz, qemu-devel

Hi,

Your series seems to have some coding style problems. See output below for
more information:

Subject: [Qemu-devel] [PATCH 0/5] RFC: Add support for VM Generation ID
Message-id: cover.1482187052.git.ben@skyportsystems.com
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
611c93d qmp/hmp: add set-vm-generation-id commands
4715fed qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands
9fbce29 ACPI: Add Virtual Machine Generation ID support
dbe5029 ACPI: Add a function for building named qword entries
4875862 docs: vm generation id device's description

=== OUTPUT BEGIN ===
Checking PATCH 1/5: docs: vm generation id device's description...
Checking PATCH 2/5: ACPI: Add a function for building named qword entries...
Checking PATCH 3/5: ACPI: Add Virtual Machine Generation ID support...
ERROR: space required after that ',' (ctx:VxV)
#131: FILE: hw/acpi/vmgenid.c:79:
+    aml_append(method,aml_store(aml_and(aml_name("VGIA"),
                      ^

ERROR: code indent should never use tabs
#207: FILE: hw/acpi/vmgenid.c:155:
+    .parent^I       = TYPE_SYS_BUS_DEVICE,$

total: 2 errors, 0 warnings, 266 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 4/5: qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands...
Checking PATCH 5/5: qmp/hmp: add set-vm-generation-id commands...
=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-12-20 23:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-19 22:46 [Qemu-devel] [PATCH 0/5] RFC: Add support for VM Generation ID ben
2016-12-19 22:46 ` [Qemu-devel] [PATCH 1/5] docs: vm generation id device's description ben
2016-12-19 22:46 ` [Qemu-devel] [PATCH 2/5] ACPI: Add a function for building named qword entries ben
2016-12-19 22:46 ` [Qemu-devel] [PATCH 3/5] ACPI: Add Virtual Machine Generation ID support ben
2016-12-19 22:46 ` [Qemu-devel] [PATCH 4/5] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands ben
2016-12-19 22:46 ` [Qemu-devel] [PATCH 5/5] qmp/hmp: add set-vm-generation-id commands ben
2016-12-20 14:36   ` Eric Blake
2016-12-20 17:23     ` Ben Warren
2016-12-20 23:04 ` [Qemu-devel] [PATCH 0/5] RFC: Add support for VM Generation ID no-reply

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.