Add support for VM Generation ID
v3 cover 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 patch set has dependencies on new guest functionality, in particular the support for a new linker-loader command and the ability to write back data to QEMU over a DMA link. Work is in flight in both SeaBIOS and OVMF to support this.
v2->v3:
- Added second writeable fw_cfg for storing the VM Generaiton ID address. This uses a new linker-loader command for instructing the guest to write back the allocated address. A patch for SeaBIOS has been submitted (https://www.seabios.org/pipermail/seabios/2017-January/011079.html)
and the resulting binary will need to be pulled into QEMU once accepted.
- Setting VM Generation ID by command line or qmp/hmp now accepts an "auto" value, whereby QEMU generates a random GUID.
- Incorporated review comments from v2 mainly around code styling and AML syntax
- Changed to use the E05 ACPI event instead of E00v1->v2:
- Removed "changed" boolean parameter as it is unneeded
- Added ACPI Notify logic
- Style changes to pass checkpatch.pl
- Added support for dynamic sysbus to pc_piix boards
Ben Warren (4):
ACPI: Add a function for building named qword entries
linker-loader: add new 'allocate and return address' cmd
ACPI: Add Virtual Machine Generation ID support
PC: Support dynamic sysbus on pc_i440fx
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 + hmp-commands-info.hx | 13 +++ hmp-commands.hx | 13 +++ hmp.c | 21 ++++ hmp.h | 2 + hw/acpi/Makefile.objs | 1 + hw/acpi/aml-build.c | 28 +++++ hw/acpi/bios-linker-loader.c | 71 +++++++++++- hw/acpi/vmgenid.c | 214 +++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 9 ++ hw/i386/pc_piix.c | 1 + include/hw/acpi/acpi_dev_interface.h | 1 + include/hw/acpi/aml-build.h | 4 + include/hw/acpi/bios-linker-loader.h | 7 ++ include/hw/acpi/vmgenid.h | 32 ++++++ qapi-schema.json | 31 +++++ stubs/Makefile.objs | 1 + stubs/vmgenid.c | 14 +++ 19 files changed, 462 insertions(+), 3 deletions(-) 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.10.1 (Apple Git-78)
PATCH v3 1/6 ACPI: Add a function for building named qword entries
From: Ben Warren <[email protected]>
This is initially used to patch a 64-bit address into the VM Generation ID SSDT
--- 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.10.1 (Apple Git-78)
PATCH v3 2/6 linker-loader: add new 'allocate and return address' cmd
In reply to [email protected]From: Ben Warren <[email protected]>
This adds a new linker-loader command to instruct the guest to allocate memory for a fw_cfg file and write the address back into another writeable fw_cfg file. Knowing this address, QEMU can then write into guest memory at runtime.
--- hw/acpi/bios-linker-loader.c | 71 ++++++++++++++++++++++++++++++++++-- include/hw/acpi/bios-linker-loader.h | 7 ++++ 2 files changed, 75 insertions(+), 3 deletions(-)
hw/acpi/bios-linker-loader.c +68 -3
@@ -78,6 +78,22 @@ struct BiosLinkerLoaderEntry {uint32_t length; } cksum; +/* +* COMMAND_ALLOCATE_RETURN_ADDR - allocate a table from @alloc_ret_file +* subject to @alloc_ret_align alignment (must be power of 2) +* and @alloc_ret_zone (can be HIGH or FSEG) requirements. +* Additionally, return the address of the allocation in +* @addr_file. +* +* This may be used instead of COMMAND_ALLOCATE +*/ +struct { +char alloc_ret_file[BIOS_LINKER_LOADER_FILESZ ]; +uint32_t alloc_ret_align; +uint8_t alloc_ret_zone; +char alloc_ret_addr_file[BIOS_LINKER_LOADER_FILESZ ]; + }; +/* padding */ char pad[124 ]; };
@@ -85,9 +101,10 @@ struct BiosLinkerLoaderEntry {typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry ;enum { -BIOS_LINKER_LOADER_COMMAND_ALLOCATE =0x1 , -BIOS_LINKER_LOADER_COMMAND_ADD_POINTER =0x2 , -BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM =0x3 , +BIOS_LINKER_LOADER_COMMAND_ALLOCATE =0x1 , +BIOS_LINKER_LOADER_COMMAND_ADD_POINTER =0x2 , +BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM =0x3 , +BIOS_LINKER_LOADER_COMMAND_ALLOCATE_RET_ADDR =0x4 , };enum {
@@ -278,3 +295,51 @@ void bios_linker_loader_add_pointer(BIOSLinker *linker,g_array_append_vals (linker->cmd_blob, &entry,sizeof entry); } + +/* +* bios_linker_loader_alloc_ret_addr: ask guest to load file into guest memory +* and patch the address in another file +* +* @linker: linker object instance +* @data_file: name of the file blob to be loaded +* @file_blob: pointer to blob corresponding to @file_name +* @alloc_align: required minimal alignment in bytes. Must be a power of 2. +* @alloc_fseg: request allocation in FSEG zone (useful for the RSDP ACPI table) +* @addr_file: destination file that will contain the address. +* This must already exist +* +* Note: this command must precede any other linker command that uses +* the data file. +*/ +void bios_linker_loader_alloc_ret_addr (BIOSLinker *linker, +const char *data_file, +GArray *file_blob, +uint32_t alloc_align, +bool alloc_fseg, +const char *addr_file) +{ +BiosLinkerLoaderEntry entry; +BiosLinkerFileEntry d_file = {g_strdup (data_file), file_blob}; + +/* Address file is expected to already be loaded */ +const BiosLinkerFileEntry *a_file = +bios_linker_find_file (linker, addr_file); + +assert (!(alloc_align & (alloc_align -1 ))); +assert (a_file); + +g_array_append_val (linker->file_list, d_file); + +memset (&entry,0 ,sizeof entry); +strncpy (entry.alloc_ret_file, data_file, +sizeof entry.alloc_ret_file -1 ); +strncpy (entry.alloc_ret_addr_file, addr_file, +sizeof entry.alloc_ret_addr_file -1 ); + entry.command =cpu_to_le32 (BIOS_LINKER_LOADER_COMMAND_ALLOCATE_RET_ADDR ); + entry.alloc.align =cpu_to_le32 (alloc_align); + entry.alloc.zone = alloc_fseg ?BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG : +BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH ; + +/* Alloc entries must come first, so prepend them */ +g_array_append_vals (linker->cmd_blob, &entry,sizeof entry); +}
include/hw/acpi/bios-linker-loader.h +7 -0
@@ -26,5 +26,12 @@ void bios_linker_loader_add_pointer(BIOSLinker *linker,const char *src_file, uint32_t src_offset); +void bios_linker_loader_alloc_ret_addr (BIOSLinker *linker, +const char *data_file, +GArray *file_blob, +uint32_t alloc_align, +bool alloc_fseg, +const char *addr_file); +void bios_linker_loader_cleanup (BIOSLinker *linker);#endif
Signature · 1 line
2.10.1 (Apple Git-78)
PATCH v3 3/6 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.
Any time the GUID changes, and ACPI notify event is sent to the guest
The user interface is a simple device with one parameter:
- guid (string, must be "auto" or in UUID format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
--- default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/acpi/Makefile.objs | 1 + hw/acpi/vmgenid.c | 214 +++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 9 ++ include/hw/acpi/acpi_dev_interface.h | 1 + include/hw/acpi/vmgenid.h | 32 ++++++ 7 files changed, 259 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 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 +214 -0
214 lines not on this page · raw message
hw/i386/acpi-build.c +9 -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"
@@ -2655,6 +2656,10 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)acpi_add_table (table_offsets, tables_blob);build_madt (tables_blob, tables->linker, pcms); +if (has_vmgenid ()) { +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);
@@ -2861,6 +2866,10 @@ void acpi_setup(void)fw_cfg_add_file (pcms->fw_cfg,ACPI_BUILD_TPMLOG_FILE , tables.tcpalog->data,acpi_data_len (tables.tcpalog)); +if (has_vmgenid ()) { +vmgenid_add_fw_cfg (pcms->fw_cfg); + } +if (!pcmc->rsdp_in_ram) {/* * Keep for compatibility with old machine types.
include/hw/acpi/acpi_dev_interface.h +1 -0
@@ -11,6 +11,7 @@ typedef enum {ACPI_CPU_HOTPLUG_STATUS =4 ,ACPI_MEMORY_HOTPLUG_STATUS =8 ,ACPI_NVDIMM_HOTPLUG_STATUS =16 , +ACPI_VMGENID_CHANGE_STATUS =32 , } AcpiEventStatusBits;#define TYPE_ACPI_DEVICE_IF "acpi-device-interface"
include/hw/acpi/vmgenid.h new file +32 -0
@@ -0,0 +1,32 @@ +#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_GUID_FW_CFG_FILE "etc/vmgenid" +#define VMGENID_ADDR_FW_CFG_FILE "etc/vmgenid_addr" + +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; +GArray *vgia; + +}VmGenIdState ; + +static inline bool has_vmgenid (void ) +{ +return object_resolve_path_type ("" ,VMGENID_DEVICE ,NULL ) !=NULL ; +} + +#endif
Signature · 1 line
2.10.1 (Apple Git-78)
PATCH v3 4/6 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
@@ -2564,3 +2564,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
@@ -6021,3 +6021,23 @@ # ## { 'command': 'query-hotpluggable-cpus', 'returns': ['HotpluggableCPU'] } + +## +# @GuidInfo: +# +# GUID information. +# +# @guid: the globally unique identifier +# +# Since: 2.9 +## +{ 'struct': 'GuidInfo', 'data': {'guid': 'str'} } + +## +# @query-vm-generation-id: +# +# Show Virtual Machine Generation ID +# +# Since 2.9 +## +{ 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }
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.10.1 (Apple Git-78)
PATCH v3 5/6 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": {
"guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
}
}HMP command example:
set-vm-generation-id guid=324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87
--- hmp-commands.hx | 13 +++++++++++++ hmp.c | 12 ++++++++++++ hmp.h | 1 + qapi-schema.json | 11 +++++++++++ stubs/vmgenid.c | 6 ++++++ 5 files changed, 43 insertions(+)
hmp-commands.hx +13 -0
@@ -1775,5 +1775,18 @@ ETEXI }, STEXI +@item set-vm-generation-id @var{uuid} +Set Virtual Machine Generation ID counter to @var{guid} +ETEXI + + { + .name = "set-vm-generation-id", + .args_type = "guid:s", + .params = "guid", + .help = "Set Virtual Machine Generation ID counter", + .cmd = hmp_set_vm_generation_id, + }, + +STEXI @end table ETEXI
hmp.c +12 -0
@@ -2573,3 +2573,15 @@ 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" ); + +qmp_set_vm_generation_id (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 +11 -0
@@ -6041,3 +6041,14 @@ # Since 2.9 ## { 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' } + +## +# @set-vm-generation-id: +# +# Set Virtual Machine Generation ID +# +# @guid: new GUID to set as Virtual Machine Generation ID +# +# Since 2.9 +## +{ 'command': 'set-vm-generation-id', 'data': {'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 (const char *guid,Error **errp) +{ +error_setg (errp,"this command is not currently supported" ); +return ; +}
Signature · 1 line
2.10.1 (Apple Git-78)
PATCH v3 6/6 PC: Support dynamic sysbus on pc_i440fx
In reply to [email protected]From: Ben Warren <[email protected]>
This allows pc_i440fx-based machines to add new devices such as VM Generation ID directly to the sysbus.
--- hw/i386/pc_piix.c | 1 + 1 file changed, 1 insertion(+)
hw/i386/pc_piix.c +1 -0
@@ -435,6 +435,7 @@ static void pc_i440fx_machine_options(MachineClass *m) m->hot_add_cpu = pc_hot_add_cpu; m->default_machine_opts ="firmware=bios-256k.bin" ; m->default_display ="std" ; + m->has_dynamic_sysbus = true; }static void pc_i440fx_2_9_machine_options (MachineClass *m)
Signature · 1 line
2.10.1 (Apple Git-78)