RFC: Add support for VM Generation ID
cover RFC: Add support for VM Generation ID
From: Ben Warren <[email protected]>
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
Signature · 1 line
2.7.4
PATCH 1/5 docs: vm generation id device's description
From: Ben Warren <[email protected]>
--- docs/specs/vmgenid.txt | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 docs/specs/vmgenid.txt
docs/specs/vmgenid.txt new file +39 -0
@@ -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.
Signature · 1 line
2.7.4
PATCH 2/5 ACPI: Add a function for building named qword entries
In reply to [email protected]From: Ben Warren <[email protected]>
--- hw/acpi/aml-build.c | 28 ++++++++++++++++++++++++++++ include/hw/acpi/aml-build.h | 4 ++++ 2 files changed, 32 insertions(+)
hw/acpi/aml-build.c +28 -0
@@ -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 )
include/hw/acpi/aml-build.h +4 -0
@@ -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);
Signature · 1 line
2.7.4
PATCH 3/5 ACPI: Add Virtual Machine Generation ID support
In reply to [email protected]From: Ben Warren <[email protected]>
This implements the VM Generation ID feature by passing a 128-bit GUID to the guest via a fw_cfg blob.
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
--- 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
default-configs/i386-softmmu.mak +1 -0
@@ -56,3 +56,4 @@ CONFIG_IOH3420=y CONFIG_I82801B11=y CONFIG_SMBIOS=y CONFIG_HYPERV_TESTDEV=$(CONFIG_KVM) +CONFIG_ACPI_VMGENID=y
default-configs/x86_64-softmmu.mak +1 -0
@@ -56,3 +56,4 @@ CONFIG_IOH3420=y CONFIG_I82801B11=y CONFIG_SMBIOS=y CONFIG_HYPERV_TESTDEV=$(CONFIG_KVM) +CONFIG_ACPI_VMGENID=y
hw/acpi/Makefile.objs +1 -0
@@ -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
hw/acpi/vmgenid.c new file +198 -0
198 lines not on this page · raw message
hw/i386/acpi-build.c +5 -0
@@ -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.
hw/misc/Makefile.objs +1 -0
@@ -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
include/hw/acpi/vmgenid.h new file +26 -0
@@ -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
Signature · 1 line
2.7.4
PATCH 4/5 qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands
In reply to [email protected]From: Igor Mammedov <[email protected]>
Add commands to query Virtual Machine Generation ID counter.
QMP command example:
{ "execute": "query-vm-generation-id" }HMP command example:
info vm-generation-id
--- 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
hmp-commands-info.hx +13 -0
@@ -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
hmp.c +9 -0
@@ -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); +}
hmp.h +1 -0
@@ -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
qapi-schema.json +20 -0
@@ -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' }
stubs/Makefile.objs +1 -0
@@ -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
stubs/vmgenid.c new file +8 -0
@@ -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 ; +}
Signature · 1 line
2.7.4
PATCH 5/5 qmp/hmp: add set-vm-generation-id commands
In reply to [email protected]From: Igor Mammedov <[email protected]>
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
--- hmp-commands.hx | 13 +++++++++++++ hmp.c | 13 +++++++++++++ hmp.h | 1 + qapi-schema.json | 12 ++++++++++++ stubs/vmgenid.c | 6 ++++++ 5 files changed, 45 insertions(+)
hmp-commands.hx +13 -0
@@ -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
hmp.c +13 -0
@@ -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 ; + } +}
hmp.h +1 -0
@@ -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
qapi-schema.json +12 -0
@@ -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' } }
stubs/vmgenid.c +6 -0
@@ -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 ; +}
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 5/5] qmp/hmp: add set-vm-generation-id commands
Quoted 28 lines · On 12/19/2016 04:46 PM, [email protected] wrote:
From: Igor Mammedov <[email protected]>
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-b9bb6c91fb87Signed-off-by Ben Warren <[email protected]>Cc Igor Mammedov <[email protected]>Cc Eric Blake <[email protected]>---
+++
b/qapi-schema.jsonqapi-schema.json +2
-0@@ -4796,3 +4796,15 @@ # Since 2.9 ## { 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' } + +##
qapi-schema.json line 4810
Quoted 10 lines
qapi-schema.json +10
-0+# @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?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 5/5] qmp/hmp: add set-vm-generation-id commands
Hi Eric,
Quoted 36 lines · Eric Blake
Quoted 33 lines · On 12/19/2016 04:46 PM, [email protected] <mailto:[email protected]>…
From: Igor Mammedov <[email protected]>
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-b9bb6c91fb87Signed-off-by Ben Warren <[email protected]>Cc Igor Mammedov <[email protected]>Cc Eric Blake <[email protected]>---
+++
b/qapi-schema.jsonqapi-schema.json +7
-0@@ -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?
Quoted 9 lines
qapi-schema.json line 4810
Quoted 5 lines
qapi-schema.json +5
-0+# @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.
Quoted 3 lines
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org <http://libvirt.org/>
—Ben
Your series seems to have some coding style problems. See output below for more information:
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: [email protected]
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 [email protected]