Add support for VM Generation ID
v7 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.
v6->v7:
- Rebased to top of tree.
- Added 'src_offset' field to "write pointer" command
- Reworked unit tests based on feedback
- various minor changes based on feedback
- Added entries to MAINTAINERS file
v5->v6:
- Rebased to top of tree.
- Changed device from sysbus to a simple device. This removed the need for adding dynamic sysbus support to pc_piix boards.
- Removed patch that introduced QWORD patching of AML.
- Removed ability to set GUID via QMP/HMP.
- Improved comments/documentation in code.
v4->v5:
- Added significantly more detail to the documentation.
- Replaced the previously-implemented linker-loader command with a new one:
"write pointer". This allows writing the guest address of a fw_cfg blob back to an arbitrary offset in a writeable fw_cfg file visible to QEMU. This will require support in SeaBIOS and OVMF (ongoing).
- Fixed endianness issues throughout.
- Several styling cleanups.
v3->v4:
- Rebased to top of tree.
- Re-added document patch that was accidentally dropped from the last revision.
- Added VMState functionality so that VGIA is restored properly.
- Added Unit testsv2->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 (7):
linker-loader: Add new 'write pointer' command
docs: VM Generation ID device description
ACPI: Add vmgenid blob storage to the build tables
ACPI: Add Virtual Machine Generation ID support
tests: Move reusable ACPI code into a utility file
tests: Add unit tests for the VM Generation ID feature
MAINTAINERS: Add VM Generation ID entry
Igor Mammedov (1):
qmp/hmp: add query-vm-generation-id and 'info vm-generation-id'
commands
MAINTAINERS | 8 ++ default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + docs/specs/vmgenid.txt | 245 +++++++++++++++++++++++++++++++++ hmp-commands-info.hx | 14 ++ hmp.c | 9 ++ hmp.h | 1 + hw/acpi/Makefile.objs | 1 + hw/acpi/aml-build.c | 2 + hw/acpi/bios-linker-loader.c | 66 ++++++++- hw/acpi/vmgenid.c | 255 +++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 16 +++ include/hw/acpi/acpi_dev_interface.h | 1 + include/hw/acpi/aml-build.h | 1 + include/hw/acpi/bios-linker-loader.h | 7 + include/hw/acpi/vmgenid.h | 35 +++++ qapi-schema.json | 20 +++ stubs/Makefile.objs | 1 + stubs/vmgenid.c | 9 ++ tests/Makefile.include | 4 +- tests/acpi-utils.c | 65 +++++++++ tests/acpi-utils.h | 94 +++++++++++++ tests/bios-tables-test.c | 132 +++--------------- tests/vmgenid-test.c | 174 ++++++++++++++++++++++++ 24 files changed, 1041 insertions(+), 121 deletions(-) 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 create mode 100644 tests/acpi-utils.c create mode 100644 tests/acpi-utils.h create mode 100644 tests/vmgenid-test.c
Signature · 1 line
2.7.4
PATCH v7 1/8 linker-loader: Add new 'write pointer' command
From: Ben Warren <[email protected]>
This is similar to the existing 'add pointer' functionality, but instead of instructing the guest (BIOS or UEFI) to patch memory, it instructs the guest to write the pointer back to QEMU via a writeable fw_cfg file.
--- hw/acpi/bios-linker-loader.c | 66 ++++++++++++++++++++++++++++++++++-- include/hw/acpi/bios-linker-loader.h | 7 ++++ 2 files changed, 70 insertions(+), 3 deletions(-)
hw/acpi/bios-linker-loader.c +63 -3
@@ -78,6 +78,21 @@ struct BiosLinkerLoaderEntry {uint32_t length; } cksum; +/* +* COMMAND_WRITE_POINTER - write the fw_cfg file (originating from +* @dest_file) at @wr_pointer.offset, by adding a pointer to +* @src_offset within the table originating from @src_file. +* 1,2,4 or 8 byte unsigned addition is used depending on +* @wr_pointer.size. +*/ +struct { +char dest_file[BIOS_LINKER_LOADER_FILESZ ]; +char src_file[BIOS_LINKER_LOADER_FILESZ ]; +uint32_t dst_offset; +uint32_t src_offset; +uint8_t size; + } wr_pointer; +/* padding */ char pad[124 ]; };
@@ -85,9 +100,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_WRITE_POINTER =0x4 , };enum {
@@ -278,3 +294,47 @@ void bios_linker_loader_add_pointer(BIOSLinker *linker,g_array_append_vals (linker->cmd_blob, &entry,sizeof entry); } + +/* +* bios_linker_loader_write_pointer: ask guest to write a pointer to the +* source file into the destination file, and write it back to QEMU via +* fw_cfg DMA. +* +* @linker: linker object instance +* @dest_file: destination file that must be written +* @dst_patched_offset: location within destination file blob to be patched +* with the pointer to @src_file, in bytes +* @dst_patched_offset_size: size of the pointer to be patched +* at @dst_patched_offset in @dest_file blob, in bytes +* @src_file: source file who's address must be taken +* @src_offset: location within source file blob to which +* @dest_file+@dst_patched_offset will point to after +* firmware's executed WRITE_POINTER command +*/ +void bios_linker_loader_write_pointer (BIOSLinker *linker, +const char *dest_file, +uint32_t dst_patched_offset, +uint8_t dst_patched_size, +const char *src_file, +uint32_t src_offset) +{ +BiosLinkerLoaderEntry entry; +const BiosLinkerFileEntry *source_file = +bios_linker_find_file (linker, src_file); + +assert (source_file); +assert (src_offset <= source_file->blob->len); +memset (&entry,0 ,sizeof entry); +strncpy (entry.wr_pointer.dest_file, dest_file, +sizeof entry.wr_pointer.dest_file -1 ); +strncpy (entry.wr_pointer.src_file, src_file, +sizeof entry.wr_pointer.src_file -1 ); + entry.command =cpu_to_le32 (BIOS_LINKER_LOADER_COMMAND_WRITE_POINTER ); + entry.wr_pointer.dst_offset =cpu_to_le32 (dst_patched_offset); + entry.wr_pointer.src_offset =cpu_to_le32 (dst_patched_offset); + entry.wr_pointer.size = dst_patched_size; +assert (dst_patched_size ==1 || dst_patched_size ==2 || + dst_patched_size ==4 || dst_patched_size ==8 ); + +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_write_pointer (BIOSLinker *linker, +const char *dest_file, +uint32_t dst_patched_offset, +uint8_t dst_patched_size, +const char *src_file, +uint32_t src_offset); +void bios_linker_loader_cleanup (BIOSLinker *linker);#endif
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v7 1/8] linker-loader: Add new 'write pointer' command
Quoted 27 lines · On Wed, 15 Feb 2017 22:18:11 -0800 [email protected] wrote:
From: Ben Warren <[email protected]>
This is similar to the existing 'add pointer' functionality, but instead of instructing the guest (BIOS or UEFI) to patch memory, it instructs the guest to write the pointer back to QEMU via a writeable
fw_cfgfile.Signed-off-by Ben Warren <[email protected]>--- hw/acpi/bios-linker-loader.c | 66 ++++++++++++++++++++++++++++++++++-- include/hw/acpi/bios-linker-loader.h | 7 ++++ 2 files changed, 70 insertions(+), 3 deletions(-)hw/acpi/bios-linker-loader.c +7
-0@@ -78,6 +78,21 @@ struct BiosLinkerLoaderEntry {uint32_t length; } cksum; +/* +* COMMAND_WRITE_POINTER - write the fw_cfg file (originating from +* @dest_file) at @wr_pointer.offset, by adding a pointer to +* @src_offset within the table originating from @src_file. +* 1,2,4 or 8 byte unsigned addition is used depending on +* @wr_pointer.size. +*/
hw/acpi/bios-linker-loader.c struct BiosLinkerLoaderEntry { · line 97
Quoted 10 lines
hw/acpi/bios-linker-loader.c +8
-0+struct { +char dest_file[BIOS_LINKER_LOADER_FILESZ ]; +char src_file[BIOS_LINKER_LOADER_FILESZ ]; +uint32_t dst_offset; +uint32_t src_offset; +uint8_t size; + } wr_pointer; +/* padding */ char pad[124 ];
Shouldn't padding be reduced by 4 bytes to keep sizeof(BiosLinkerLoaderEntry) the same as before patch, so that old bios would be able to skip this unknown command and read the next at the right offset?
Quoted 39 lines
hw/acpi/bios-linker-loader.c +24
-3};@@ -85,9 +100,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_WRITE_POINTER =0x4 , };enum {@@ -278,3 +294,47 @@ void bios_linker_loader_add_pointer(BIOSLinker *linker,g_array_append_vals (linker->cmd_blob, &entry,sizeof entry); } + +/* +* bios_linker_loader_write_pointer: ask guest to write a pointer to the +* source file into the destination file, and write it back to QEMU via +* fw_cfg DMA. +* +* @linker: linker object instance +* @dest_file: destination file that must be written +* @dst_patched_offset: location within destination file blob to be patched +* with the pointer to @src_file, in bytes +* @dst_patched_offset_size: size of the pointer to be patched +* at @dst_patched_offset in @dest_file blob, in bytes +* @src_file: source file who's address must be taken +* @src_offset: location within source file blob to which +* @dest_file+@dst_patched_offset will point to after +* firmware's executed WRITE_POINTER command +*/ +void bios_linker_loader_write_pointer(BIOSLinker *linker, + const char *dest_file, + uint32_t dst_patched_offset,
hw/acpi/bios-linker-loader.c void bios_linker_loader_add_pointer(BIOSLinker *linker, · line 326
Quoted 10 lines
hw/acpi/bios-linker-loader.c +10
-0+uint8_t dst_patched_size, + const char *src_file, + uint32_t src_offset) +{ + BiosLinkerLoaderEntry entry; +const BiosLinkerFileEntry *source_file = +bios_linker_find_file (linker, src_file); + +assert (source_file); +assert (src_offset <= source_file->blob->len);
off by one, should be '<'
Quoted 21 lines
hw/acpi/bios-linker-loader.c +14
-0+memset (&entry,0 ,sizeof entry); +strncpy (entry.wr_pointer.dest_file, dest_file, +sizeof entry.wr_pointer.dest_file -1 ); +strncpy (entry.wr_pointer.src_file, src_file, +sizeof entry.wr_pointer.src_file -1 ); + entry.command =cpu_to_le32 (BIOS_LINKER_LOADER_COMMAND_WRITE_POINTER ); + entry.wr_pointer.dst_offset =cpu_to_le32 (dst_patched_offset); + entry.wr_pointer.src_offset =cpu_to_le32 (dst_patched_offset); + entry.wr_pointer.size = dst_patched_size; +assert (dst_patched_size ==1 || dst_patched_size ==2 || + dst_patched_size ==4 || dst_patched_size ==8 ); + +g_array_append_vals (linker->cmd_blob, &entry,sizeof entry); +}include/hw/acpi/bios-linker-loader.h +0
-0@@ -26,5 +26,12 @@ void bios_linker_loader_add_pointer(BIOSLinker *linker,const char *src_file, uint32_t src_offset);
include/hw/acpi/bios-linker-loader.h void bios_linker_loader_add_pointer(BIOSLinker *linker, · line 37
Quoted 10 lines
include/hw/acpi/bios-linker-loader.h +7
-0+void bios_linker_loader_write_pointer (BIOSLinker *linker, +const char *dest_file, +uint32_t dst_patched_offset, +uint8_t dst_patched_size, +const char *src_file, +uint32_t src_offset); +void bios_linker_loader_cleanup (BIOSLinker *linker);#endif
Taking in account comments above are corner cases.
1: old bios running on new QEMU with vmgenid device and OLD/not supported bios 2: assert check
It's ok fixes for above issues being fixed in follow up patch or as fixup while patch is staged in pci tree
Re: [Qemu-devel] [PATCH v7 1/8] linker-loader: Add new 'write pointer' command
Quoted 36 lines · Igor Mammedov
Quoted 33 lines · On Wed, 15 Feb 2017 22:18:11 -0800 [email protected] wrote:
From: Ben Warren <[email protected]>
This is similar to the existing 'add pointer' functionality, but instead of instructing the guest (BIOS or UEFI) to patch memory, it instructs the guest to write the pointer back to QEMU via a writeable
fw_cfgfile.Signed-off-by Ben Warren <[email protected]>--- hw/acpi/bios-linker-loader.c | 66 ++++++++++++++++++++++++++++++++++-- include/hw/acpi/bios-linker-loader.h | 7 ++++ 2 files changed, 70 insertions(+), 3 deletions(-)hw/acpi/bios-linker-loader.c +13
-0@@ -78,6 +78,21 @@ struct BiosLinkerLoaderEntry {uint32_t length; } cksum; +/* +* COMMAND_WRITE_POINTER - write the fw_cfg file (originating from +* @dest_file) at @wr_pointer.offset, by adding a pointer to +* @src_offset within the table originating from @src_file. +* 1,2,4 or 8 byte unsigned addition is used depending on +* @wr_pointer.size. +*/ +struct { +char dest_file[BIOS_LINKER_LOADER_FILESZ ]; +char src_file[BIOS_LINKER_LOADER_FILESZ ]; +uint32_t dst_offset; +uint32_t src_offset; +uint8_t size;
Quoted 8 lines
hw/acpi/bios-linker-loader.c struct BiosLinkerLoaderEntry { · line 97
Quoted 4 lines
hw/acpi/bios-linker-loader.c +2
-0+ } wr_pointer; +/* padding */ char pad[124 ];Shouldn't padding be reduced by 4 bytes to keep sizeof(BiosLinkerLoaderEntry) the same as before patch, so that old bios would be able to skip this unknown command and read the next at the right offset?
IMHO no - because it's a union.
Quoted 91 lines
Quoted 39 lines
hw/acpi/bios-linker-loader.c +24
-3};@@ -85,9 +100,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_WRITE_POINTER =0x4 , };enum {@@ -278,3 +294,47 @@ void bios_linker_loader_add_pointer(BIOSLinker *linker,g_array_append_vals (linker->cmd_blob, &entry,sizeof entry); } + +/* +* bios_linker_loader_write_pointer: ask guest to write a pointer to the +* source file into the destination file, and write it back to QEMU via +* fw_cfg DMA. +* +* @linker: linker object instance +* @dest_file: destination file that must be written +* @dst_patched_offset: location within destination file blob to be patched +* with the pointer to @src_file, in bytes +* @dst_patched_offset_size: size of the pointer to be patched +* at @dst_patched_offset in @dest_file blob, in bytes +* @src_file: source file who's address must be taken +* @src_offset: location within source file blob to which +* @dest_file+@dst_patched_offset will point to after +* firmware's executed WRITE_POINTER command +*/ +void bios_linker_loader_write_pointer(BIOSLinker *linker, + const char *dest_file, + uint32_t dst_patched_offset,hw/acpi/bios-linker-loader.c void bios_linker_loader_add_pointer(BIOSLinker *linker, · line 326
Quoted 10 lines
hw/acpi/bios-linker-loader.c +10
-0+uint8_t dst_patched_size, + const char *src_file, + uint32_t src_offset) +{ + BiosLinkerLoaderEntry entry; +const BiosLinkerFileEntry *source_file = +bios_linker_find_file (linker, src_file); + +assert (source_file); +assert (src_offset <= source_file->blob->len);off by one, should be '<'
Quoted 21 lines
hw/acpi/bios-linker-loader.c +14
-0+memset (&entry,0 ,sizeof entry); +strncpy (entry.wr_pointer.dest_file, dest_file, +sizeof entry.wr_pointer.dest_file -1 ); +strncpy (entry.wr_pointer.src_file, src_file, +sizeof entry.wr_pointer.src_file -1 ); + entry.command =cpu_to_le32 (BIOS_LINKER_LOADER_COMMAND_WRITE_POINTER ); + entry.wr_pointer.dst_offset =cpu_to_le32 (dst_patched_offset); + entry.wr_pointer.src_offset =cpu_to_le32 (dst_patched_offset); + entry.wr_pointer.size = dst_patched_size; +assert (dst_patched_size ==1 || dst_patched_size ==2 || + dst_patched_size ==4 || dst_patched_size ==8 ); + +g_array_append_vals (linker->cmd_blob, &entry,sizeof entry); +}include/hw/acpi/bios-linker-loader.h +0
-0@@ -26,5 +26,12 @@ void bios_linker_loader_add_pointer(BIOSLinker *linker,const char *src_file, uint32_t src_offset);include/hw/acpi/bios-linker-loader.h void bios_linker_loader_add_pointer(BIOSLinker *linker, · line 37
Quoted 10 lines
include/hw/acpi/bios-linker-loader.h +7
-0+void bios_linker_loader_write_pointer (BIOSLinker *linker, +const char *dest_file, +uint32_t dst_patched_offset, +uint8_t dst_patched_size, +const char *src_file, +uint32_t src_offset); +void bios_linker_loader_cleanup (BIOSLinker *linker);#endif Taking in account comments above are corner cases.
1: old bios running on new QEMU with vmgenid device and OLD/not supported bios 2: assert checkIt's ok fixes for above issues being fixed in follow up patch or as fixup while patch is staged in pci tree
Reviewed-by Igor Mammedov <[email protected]>
Re: [Qemu-devel] [PATCH v7 1/8] linker-loader: Add new 'write pointer' command
In reply to Igor MammedovQuoted 18 lines · Igor Mammedov
Quoted 18 lines
+++
b/hw/acpi/bios-linker-loader.chw/acpi/bios-linker-loader.c +13
-0@@ -78,6 +78,21 @@ struct BiosLinkerLoaderEntry {uint32_t length; } cksum; +/* +* COMMAND_WRITE_POINTER - write the fw_cfg file (originating from +* @dest_file) at @wr_pointer.offset, by adding a pointer to +* @src_offset within the table originating from @src_file. +* 1,2,4 or 8 byte unsigned addition is used depending on +* @wr_pointer.size. +*/ +struct { +char dest_file[BIOS_LINKER_LOADER_FILESZ ]; +char src_file[BIOS_LINKER_LOADER_FILESZ ]; +uint32_t dst_offset; +uint32_t src_offset; +uint8_t size;
Quoted 8 lines
hw/acpi/bios-linker-loader.c struct BiosLinkerLoaderEntry { · line 97
Quoted 4 lines
hw/acpi/bios-linker-loader.c +2
-0+ } wr_pointer; +/* padding */ char pad[124 ];Shouldn't padding be reduced by 4 bytes to keep sizeof(BiosLinkerLoaderEntry) the same as before patch, so that old bios would be able to skip this unknown command and read the next at the right offset?
No, because you are in the middle of a union rather than a struct (the outer BiosLinkerLoaderEntry struct size is determined by the largest member of the union, which is 'char pad[124]'; the new wr_pointer addition to the union does not change the size of the union).
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v7 1/8] linker-loader: Add new 'write pointer' command
In reply to [email protected]Quoted 76 lines · On 02/16/17 07:18, [email protected] wrote:
From: Ben Warren <[email protected]>
This is similar to the existing 'add pointer' functionality, but instead of instructing the guest (BIOS or UEFI) to patch memory, it instructs the guest to write the pointer back to QEMU via a writeable
fw_cfgfile.Signed-off-by Ben Warren <[email protected]>--- hw/acpi/bios-linker-loader.c | 66 ++++++++++++++++++++++++++++++++++-- include/hw/acpi/bios-linker-loader.h | 7 ++++ 2 files changed, 70 insertions(+), 3 deletions(-)hw/acpi/bios-linker-loader.c +39
-3@@ -78,6 +78,21 @@ struct BiosLinkerLoaderEntry {uint32_t length; } cksum; +/* +* COMMAND_WRITE_POINTER - write the fw_cfg file (originating from +* @dest_file) at @wr_pointer.offset, by adding a pointer to +* @src_offset within the table originating from @src_file. +* 1,2,4 or 8 byte unsigned addition is used depending on +* @wr_pointer.size. +*/ +struct { +char dest_file[BIOS_LINKER_LOADER_FILESZ ]; +char src_file[BIOS_LINKER_LOADER_FILESZ ]; +uint32_t dst_offset; +uint32_t src_offset; +uint8_t size; + } wr_pointer; +/* padding */ char pad[124 ]; };@@ -85,9 +100,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_WRITE_POINTER =0x4 , };enum {@@ -278,3 +294,47 @@ void bios_linker_loader_add_pointer(BIOSLinker *linker,g_array_append_vals (linker->cmd_blob, &entry,sizeof entry); } + +/* +* bios_linker_loader_write_pointer: ask guest to write a pointer to the +* source file into the destination file, and write it back to QEMU via +* fw_cfg DMA. +* +* @linker: linker object instance +* @dest_file: destination file that must be written +* @dst_patched_offset: location within destination file blob to be patched +* with the pointer to @src_file, in bytes +* @dst_patched_offset_size: size of the pointer to be patched +* at @dst_patched_offset in @dest_file blob, in bytes +* @src_file: source file who's address must be taken +* @src_offset: location within source file blob to which +* @dest_file+@dst_patched_offset will point to after +* firmware's executed WRITE_POINTER command +*/ +void bios_linker_loader_write_pointer(BIOSLinker *linker, + const char *dest_file, + uint32_t dst_patched_offset,
hw/acpi/bios-linker-loader.c void bios_linker_loader_add_pointer(BIOSLinker *linker, · line 326
Quoted 10 lines
hw/acpi/bios-linker-loader.c +10
-0+uint8_t dst_patched_size, + const char *src_file, + uint32_t src_offset) +{ + BiosLinkerLoaderEntry entry; +const BiosLinkerFileEntry *source_file = +bios_linker_find_file (linker, src_file); + +assert (source_file); +assert (src_offset <= source_file->blob->len);
(1) Off by one, as pointed out by Igor.
hw/acpi/bios-linker-loader.c void bios_linker_loader_add_pointer(BIOSLinker *linker, · line 334
Quoted 8 lines
hw/acpi/bios-linker-loader.c +8
-0+memset (&entry,0 ,sizeof entry); +strncpy (entry.wr_pointer.dest_file, dest_file, +sizeof entry.wr_pointer.dest_file -1 ); +strncpy (entry.wr_pointer.src_file, src_file, +sizeof entry.wr_pointer.src_file -1 ); + entry.command =cpu_to_le32 (BIOS_LINKER_LOADER_COMMAND_WRITE_POINTER ); + entry.wr_pointer.dst_offset =cpu_to_le32 (dst_patched_offset); + entry.wr_pointer.src_offset =cpu_to_le32 (dst_patched_offset);
(2) copy/paste error, you should be assigning "src_offset", as in:
hw/acpi/bios-linker-loader.c void bios_linker_loader_write_pointer(BIOSLinker *linker, · line 337
Quoted 13 lines
hw/acpi/bios-linker-loader.c +1
-1@@ -331,7 +331,7 @@ void bios_linker_loader_write_pointer(BIOSLinker *linker, sizeof entry.wr_pointer.src_file - 1); entry.command =cpu_to_le32 (BIOS_LINKER_LOADER_COMMAND_WRITE_POINTER ); entry.wr_pointer.dst_offset =cpu_to_le32 (dst_patched_offset); - entry.wr_pointer.src_offset =cpu_to_le32 (dst_patched_offset); + entry.wr_pointer.src_offset =cpu_to_le32 (src_offset); entry.wr_pointer.size = dst_patched_size;assert (dst_patched_size ==1 || dst_patched_size ==2 || dst_patched_size ==4 || dst_patched_size ==8 );
With these errors fixed:
I also tested this series (with the assignment under (2) fixed up, of course), as documented earlier in <https://www.mail-archive.com/[email protected]/msg430075.html> (msgid <[email protected]>).
Hence, with (1) and (2) fixed, you can also add
Thanks
Laszlo
Quoted 24 lines
hw/acpi/bios-linker-loader.c +6
-0+ entry.wr_pointer.size = dst_patched_size; +assert (dst_patched_size ==1 || dst_patched_size ==2 || + dst_patched_size ==4 || dst_patched_size ==8 ); + +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_write_pointer (BIOSLinker *linker, +const char *dest_file, +uint32_t dst_patched_offset, +uint8_t dst_patched_size, +const char *src_file, +uint32_t src_offset); +void bios_linker_loader_cleanup (BIOSLinker *linker);#endif
Re: [Qemu-devel] [PATCH v7 1/8] linker-loader: Add new 'write pointer' command
Quoted 84 lines · Laszlo Ersek
Quoted 80 lines · On 02/16/17 07:18, [email protected] <mailto:[email protected]> wrote:
From: Ben Warren <[email protected]>
This is similar to the existing 'add pointer' functionality, but instead of instructing the guest (BIOS or UEFI) to patch memory, it instructs the guest to write the pointer back to QEMU via a writeable
fw_cfgfile.Signed-off-by Ben Warren <[email protected]>---
hw/acpi/bios-linker-loader.c| 66 ++++++++++++++++++++++++++++++++++--include/hw/acpi/bios-linker-loader.h| 7 ++++2 files changed, 70 insertions(+), 3 deletions(-)hw/acpi/bios-linker-loader.c +43
-3@@ -78,6 +78,21 @@ struct BiosLinkerLoaderEntry {uint32_t length; } cksum; +/* +* COMMAND_WRITE_POINTER - write the fw_cfg file (originating from +* @dest_file) at @wr_pointer.offset, by adding a pointer to +* @src_offset within the table originating from @src_file. +* 1,2,4 or 8 byte unsigned addition is used depending on +* @wr_pointer.size. +*/ +struct { +char dest_file[BIOS_LINKER_LOADER_FILESZ ]; +char src_file[BIOS_LINKER_LOADER_FILESZ ]; +uint32_t dst_offset; +uint32_t src_offset; +uint8_t size; + } wr_pointer; +/* padding */ char pad[124 ]; };@@ -85,9 +100,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_WRITE_POINTER =0x4 , };enum {@@ -278,3 +294,47 @@ void bios_linker_loader_add_pointer(BIOSLinker *linker,g_array_append_vals (linker->cmd_blob, &entry,sizeof entry); } + +/* +* bios_linker_loader_write_pointer: ask guest to write a pointer to the +* source file into the destination file, and write it back to QEMU via +* fw_cfg DMA. +* +* @linker: linker object instance +* @dest_file: destination file that must be written +* @dst_patched_offset: location within destination file blob to be patched +* with the pointer to @src_file, in bytes +* @dst_patched_offset_size: size of the pointer to be patched +* at @dst_patched_offset in @dest_file blob, in bytes +* @src_file: source file who's address must be taken +* @src_offset: location within source file blob to which +* @dest_file+@dst_patched_offset will point to after +* firmware's executed WRITE_POINTER command +*/ +void bios_linker_loader_write_pointer (BIOSLinker *linker, +const char *dest_file, +uint32_t dst_patched_offset, +uint8_t dst_patched_size, +const char *src_file, +uint32_t src_offset) +{
Quoted 8 lines
hw/acpi/bios-linker-loader.c void bios_linker_loader_add_pointer(BIOSLinker *linker, · line 326
Quoted 6 lines
hw/acpi/bios-linker-loader.c +6
-0+BiosLinkerLoaderEntry entry; +const BiosLinkerFileEntry *source_file = +bios_linker_find_file (linker, src_file); + +assert (source_file); +assert (src_offset <= source_file->blob->len);(1) Off by one, as pointed out by Igor.
Oh, “off-by-one” errors. One of the three biggest sources of bugs in programming. The other being recursion. Sorry, couldn’t resist :)
Quoted 10 lines
hw/acpi/bios-linker-loader.c void bios_linker_loader_add_pointer(BIOSLinker *linker, · line 334
Quoted 9 lines
hw/acpi/bios-linker-loader.c +8
-0+memset (&entry,0 ,sizeof entry); +strncpy (entry.wr_pointer.dest_file, dest_file, +sizeof entry.wr_pointer.dest_file -1 ); +strncpy (entry.wr_pointer.src_file, src_file, +sizeof entry.wr_pointer.src_file -1 ); + entry.command =cpu_to_le32 (BIOS_LINKER_LOADER_COMMAND_WRITE_POINTER ); + entry.wr_pointer.dst_offset =cpu_to_le32 (dst_patched_offset); + entry.wr_pointer.src_offset =cpu_to_le32 (dst_patched_offset);
Quoted 2 lines
(2) copy/paste error, you should be assigning "
src_offset", as in:
Oops.
Quoted 18 lines
hw/acpi/bios-linker-loader.c void bios_linker_loader_write_pointer(BIOSLinker *linker, · line 337
Quoted 13 lines
hw/acpi/bios-linker-loader.c +1
-1@@ -331,7 +331,7 @@ void bios_linker_loader_write_pointer(BIOSLinker *linker, sizeof entry.wr_pointer.src_file - 1); entry.command =cpu_to_le32 (BIOS_LINKER_LOADER_COMMAND_WRITE_POINTER ); entry.wr_pointer.dst_offset =cpu_to_le32 (dst_patched_offset); - entry.wr_pointer.src_offset =cpu_to_le32 (dst_patched_offset); + entry.wr_pointer.src_offset =cpu_to_le32 (src_offset); entry.wr_pointer.size = dst_patched_size;assert (dst_patched_size ==1 || dst_patched_size ==2 || dst_patched_size ==4 || dst_patched_size ==8 );With these errors fixed:
Reviewed-by Laszlo Ersek <[email protected] <mailto:[email protected]>>
Quoted 9 lines
I also tested this series (with the assignment under (2) fixed up, of course), as documented earlier in <https://www.mail-archive.com/[email protected]/msg430075.html <https://www.mail-archive.com/[email protected]/msg430075.html>> (msgid <[email protected] <mailto:[email protected]>>).
Hence, with (1) and (2) fixed, you can also add
Tested-by Laszlo Ersek <[email protected] <mailto:[email protected]>>Thanks
Laszlo
Thanks a lot!
—Ben
Quoted 23 lines
Quoted 23 lines
hw/acpi/bios-linker-loader.c +6
-0+ entry.wr_pointer.size = dst_patched_size; +assert (dst_patched_size ==1 || dst_patched_size ==2 || + dst_patched_size ==4 || dst_patched_size ==8 ); + +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_write_pointer (BIOSLinker *linker, +const char *dest_file, +uint32_t dst_patched_offset, +uint8_t dst_patched_size, +const char *src_file, +uint32_t src_offset); +void bios_linker_loader_cleanup (BIOSLinker *linker);#endif
PATCH v7 2/8 docs: VM Generation ID device description
In reply to [email protected]From: Ben Warren <[email protected]>
This patch is based off an earlier version by
Gal Hammer ([email protected])
Requirements section, ASCII diagrams and overall help provided by Laszlo Ersek ([email protected])
--- docs/specs/vmgenid.txt | 245 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 docs/specs/vmgenid.txt
docs/specs/vmgenid.txt new file +245 -0
@@ -0,0 +1,245 @@ +VIRTUAL MACHINE GENERATION ID +============================= + +Copyright (C) 2016 Red Hat, Inc. +Copyright (C) 2017 Skyport Systems, Inc. + +This work is licensed under the terms of the GNU GPL, version 2 or later. +See the COPYING file in the top-level directory. + +=== + +The VM generation ID (vmgenid) device is an emulated device which +exposes a 128-bit, cryptographically random, integer value identifier, +referred to as a Globally Unique Identifier, or GUID. + +This allows management applications (e.g. libvirt) to notify the guest +operating system when the virtual machine is executed with a different +configuration (e.g. snapshot execution or creation from a template). The +guest operating system notices the change, and is then able to react as +appropriate by marking its copies of distributed databases as dirty, +re-initializing its random number generator etc. + + +Requirements +------------ + +These requirements are extracted from the "How to implement virtual machine +generation ID support in a virtualization platform" section of the +specification, dated August 1, 2012. + + +The document may be found on the web at: + http://go.microsoft.com/fwlink/?LinkId=260709 + +R1a. The generation ID shall live in an 8-byte aligned buffer. + +R1b. The buffer holding the generation ID shall be in guest RAM, ROM, or device + MMIO range. + +R1c. The buffer holding the generation ID shall be kept separate from areas + used by the operating system. + +R1d. The buffer shall not be covered by an AddressRangeMemory or + AddressRangeACPI entry in the E820 or UEFI memory map. + +R1e. The generation ID shall not live in a page frame that could be mapped with + caching disabled. (In other words, regardless of whether the generation ID + lives in RAM, ROM or MMIO, it shall only be mapped as cacheable.) + +R2 to R5. [These AML requirements are isolated well enough in the Microsoft + specification for us to simply refer to them here.] + +R6. The hypervisor shall expose a _HID (hardware identifier) object in the + VMGenId device's scope that is unique to the hypervisor vendor. + + +QEMU Implementation +------------------- + +The above-mentioned specification does not dictate which ACPI descriptor table +will contain the VM Generation ID device. Other implementations (Hyper-V and +Xen) put it in the main descriptor table (Differentiated System Description +Table or DSDT). For ease of debugging and implementation, we have decided to +put it in its own Secondary System Description Table, or SSDT. + +The following is a dump of the contents from a running system: + +# iasl -p ./SSDT -d /sys/firmware/acpi/tables/SSDT + +Intel ACPI Component Architecture +ASL+ Optimizing Compiler version 20150717-64 +Copyright (c) 2000 - 2015 Intel Corporation + +Reading ACPI table from file /sys/firmware/acpi/tables/SSDT - Length +00000198 (0x0000C6) +ACPI: SSDT 0x0000000000000000 0000C6 (v01 BOCHS VMGENID 00000001 BXPC +00000001) +Acpi table [SSDT] successfully installed and loaded +Pass 1 parse of [SSDT] +Pass 2 parse of [SSDT] +Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions) + +Parsing completed +Disassembly completed +ASL Output: ./SSDT.dsl - 1631 bytes +# cat SSDT.dsl +/* + * Intel ACPI Component Architecture + * AML/ASL+ Disassembler version 20150717-64 + * Copyright (c) 2000 - 2015 Intel Corporation + * + * Disassembling to symbolic ASL+ operators + * + * Disassembly of /sys/firmware/acpi/tables/SSDT, Sun Feb 5 00:19:37 2017 + * + * Original Table Header: + * Signature "SSDT" + * Length 0x000000CA (202) + * Revision 0x01 + * Checksum 0x4B + * OEM ID "BOCHS " + * OEM Table ID "VMGENID" + * OEM Revision 0x00000001 (1) + * Compiler ID "BXPC" + * Compiler Version 0x00000001 (1) + */ +DefinitionBlock ("/sys/firmware/acpi/tables/SSDT.aml", "SSDT", 1, "BOCHS ", +"VMGENID", 0x00000001) +{ + Name (VGIA, 0x07FFF000) + Scope (\_SB) + { + Device (VGEN) + { + Name (_HID, "QEMUVGID") // _HID: Hardware ID + Name (_CID, "VM_Gen_Counter") // _CID: Compatible ID + Name (_DDN, "VM_Gen_Counter") // _DDN: DOS Device Name + Method (_STA, 0, NotSerialized) // _STA: Status + { + Local0 = 0x0F + If ((VGIA == Zero)) + { + Local0 = Zero + } + + Return (Local0) + } + + Method (ADDR, 0, NotSerialized) + { + Local0 = Package (0x02) {} + Index (Local0, Zero) = (VGIA + 0x28) + Index (Local0, One) = Zero + Return (Local0) + } + } + } + + Method (\_GPE._E05, 0, NotSerialized) // _Exx: Edge-Triggered GPE + { + Notify (\_SB.VGEN, 0x80) // Status Change + } +} + + +Design Details: +--------------- + +Requirements R1a through R1e dictate that the memory holding the +VM Generation ID must be allocated and owned by the guest firmware, +in this case BIOS or UEFI. However, to be useful, QEMU must be able to +change the contents of the memory at runtime, specifically when starting a +backed-up or snapshotted image. In order to do this, QEMU must know the +address that has been allocated. + +The mechanism chosen for this memory sharing is writeable fw_cfg blobs. +These are data object that are visible to both QEMU and guests, and are +addressable as sequential files. + +More information about fw_cfg can be found in "docs/specs/fw_cfg.txt" + +Two fw_cfg blobs are used in this case: + +/etc/vmgenid_guid - contains the actual VM Generation ID GUID + - read-only to the guest +/etc/vmgenid_addr - contains the address of the downloaded vmgenid blob + - writeable by the guest + + +QEMU sends the following commands to the guest at startup: + +1. Allocate memory for vmgenid_guid fw_cfg blob. +2. Write the address of vmgenid_guid into the SSDT (VGIA ACPI variable as + shown above in the iasl dump). Note that this change is not propagated + back to QEMU. +3. Write the address of vmgenid_guid back to QEMU's copy of vmgenid_addr + via the fw_cfg DMA interface. + +After step 3, QEMU is able to update the contents of vmgenid_guid at will. + +Since BIOS or UEFI does not necessarily run when we wish to change the GUID, +the value of VGIA is persisted via the VMState mechanism. + +As spelled out in the specification, any change to the GUID executes an +ACPI notification. The exact handler to use is not specified, so the vmgenid +device uses the first unused one: \_GPE._E05. + + +Endian-ness Considerations: +--------------------------- + +Although not specified in Microsoft's document, it is assumed that the +device is expected to use little-endian format. + +All GUID passed in via command line or monitor are treated as big-endian. +GUID values displayed via monitor are shown in big-endian format. + + +GUID Storage Format: +-------------------- + +In order to implement an OVMF "SDT Header Probe Suppressor", the contents of +the vmgenid_guid fw_cfg blob are not simply a 128-bit GUID. There is also +significant padding in order to align and fill a memory page, as shown in the +following diagram: + ++----------------------------------+ +| SSDT with OEM Table ID = VMGENID | ++----------------------------------+ +| ... | TOP OF PAGE +| VGIA dword object ---------------|-----> +---------------------------+ +| ... | | fw-allocated array for | +| _STA method referring to VGIA | | "etc/vmgenid_guid" | +| ... | +---------------------------+ +| ADDR method referring to VGIA | | 0: OVMF SDT Header probe | +| ... | | suppressor | ++----------------------------------+ | 36: padding for 8-byte | + | alignment | + | 40: GUID | + | 56: padding to page size | + +---------------------------+ + END OF PAGE + + +Device Usage: +------------- + +The device has one property, which may be only be set using the command line: + + guid - sets the value of the GUID. A special value "auto" instructs + QEMU to generate a new random GUID. + +For example: + + QEMU -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87" + QEMU -device vmgenid,guid=auto + +The property may be queried via QMP/HMP: + + (QEMU) query-vm-generation-id + {"return": {"guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"}} + +Setting of this parameter is intentionally left out from the QMP/HMP +interfaces. There are no known use cases for changing the GUID once QEMU is +running, and adding this capability would greatly increase the complexity.
Signature · 1 line
2.7.4
PATCH v7 3/8 ACPI: Add vmgenid blob storage to the build tables
In reply to [email protected]From: Ben Warren <[email protected]>
This allows them to be centrally initialized and destroyed
The "AcpiBuildTables.vmgenid" array will be used to construct the "etc/vmgenid_guid" fw_cfg blob.
Its contents will be linked into fw_cfg after being built on the pc_machine_done() -> acpi_setup() -> acpi_build() call path, and dropped without use on the subsequent, guest triggered, acpi_build_update() -> acpi_build() call path.
--- hw/acpi/aml-build.c | 2 ++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 3 insertions(+)
hw/acpi/aml-build.c +2 -0
@@ -1559,6 +1559,7 @@ void acpi_build_tables_init(AcpiBuildTables *tables) tables->rsdp =g_array_new (false, true/* clear */ ,1 ); tables->table_data =g_array_new (false, true/* clear */ ,1 ); tables->tcpalog =g_array_new (false, true/* clear */ ,1 ); + tables->vmgenid =g_array_new (false, true/* clear */ ,1 ); tables->linker =bios_linker_loader_init (); }
@@ -1568,6 +1569,7 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)g_array_free (tables->rsdp, true);g_array_free (tables->table_data, true);g_array_free (tables->tcpalog, mfre); +g_array_free (tables->vmgenid, mfre); }/* Build rsdt table */
include/hw/acpi/aml-build.h +1 -0
@@ -210,6 +210,7 @@ struct AcpiBuildTables {GArray *table_data;GArray *rsdp;GArray *tcpalog; +GArray *vmgenid;BIOSLinker *linker; } AcpiBuildTables;
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v7 3/8] ACPI: Add vmgenid blob storage to the build tables
Quoted 12 lines · On 02/16/17 07:18, [email protected] wrote:
From: Ben Warren <[email protected]>
This allows them to be centrally initialized and destroyed
The "AcpiBuildTables.vmgenid" array will be used to construct the "etc/vmgenid_guid"
fw_cfgblob.Its contents will be linked into
fw_cfgafter being built on thepc_machine_done()->acpi_setup()->acpi_build()call path, and dropped without use on the subsequent, guest triggered,acpi_build_update()->acpi_build()call path.
Quoted 7 lines
Signed-off-by Ben Warren <[email protected]>Reviewed-by Laszlo Ersek <[email protected]>Reviewed-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 2 ++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 3 insertions(+)
PATCH v7 4/8 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, an ACPI notify event is sent to the guest
The user interface is a simple device with one parameter:
- guid (string, must be "auto" or in UUID format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
--- default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/acpi/Makefile.objs | 1 + hw/acpi/vmgenid.c | 239 +++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 16 +++ include/hw/acpi/acpi_dev_interface.h | 1 + include/hw/acpi/vmgenid.h | 35 +++++ 7 files changed, 294 insertions(+) create mode 100644 hw/acpi/vmgenid.c create mode 100644 include/hw/acpi/vmgenid.h
default-configs/i386-softmmu.mak +1 -0
@@ -59,3 +59,4 @@ CONFIG_I82801B11=y CONFIG_SMBIOS=y CONFIG_HYPERV_TESTDEV=$(CONFIG_KVM) CONFIG_PXB=y +CONFIG_ACPI_VMGENID=y
default-configs/x86_64-softmmu.mak +1 -0
@@ -59,3 +59,4 @@ CONFIG_I82801B11=y CONFIG_SMBIOS=y CONFIG_HYPERV_TESTDEV=$(CONFIG_KVM) CONFIG_PXB=y +CONFIG_ACPI_VMGENID=y
hw/acpi/Makefile.objs +1 -0
@@ -5,6 +5,7 @@ common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o +common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o common-obj-y += acpi_interface.o
hw/acpi/vmgenid.c new file +239 -0
239 lines not on this page · raw message
hw/i386/acpi-build.c +16 -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"
@@ -2610,6 +2611,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)size_t aml_len =0 ;GArray *tables_blob = tables->table_data;AcpiSlicOem slic_oem = { .id =NULL , .table_id =NULL }; +Object *vmgenid_dev;acpi_get_pm_info (&pm);acpi_get_misc_info (&misc);
@@ -2653,6 +2655,13 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)acpi_add_table (table_offsets, tables_blob);build_madt (tables_blob, tables->linker, pcms); + vmgenid_dev =find_vmgenid_dev (); +if (vmgenid_dev) { +acpi_add_table (table_offsets, tables_blob); +vmgenid_build_acpi (VMGENID (vmgenid_dev), tables_blob, + tables->vmgenid, tables->linker); + } +if (misc.has_hpet) {acpi_add_table (table_offsets, tables_blob);build_hpet (tables_blob, tables->linker);
@@ -2823,6 +2832,7 @@ void acpi_setup(void)PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);AcpiBuildTables tables;AcpiBuildState *build_state; +Object *vmgenid_dev;if (!pcms->fw_cfg) {ACPI_BUILD_DPRINTF ("No fw cfg. Bailing out.\n" );
@@ -2859,6 +2869,12 @@ void acpi_setup(void)fw_cfg_add_file (pcms->fw_cfg,ACPI_BUILD_TPMLOG_FILE , tables.tcpalog->data,acpi_data_len (tables.tcpalog)); + vmgenid_dev =find_vmgenid_dev (); +if (vmgenid_dev) { +vmgenid_add_fw_cfg (VMGENID (vmgenid_dev), pcms->fw_cfg, + tables.vmgenid); + } +if (!pcmc->rsdp_in_ram) {/* * Keep for compatibility with old machine types.
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 +35 -0
@@ -0,0 +1,35 @@ +#ifndef ACPI_VMGENID_H +#define ACPI_VMGENID_H + +#include "hw/acpi/bios-linker-loader.h" +#include "hw/qdev.h" +#include "qemu/uuid.h" + +#define VMGENID_DEVICE "vmgenid" +#define VMGENID_GUID "guid" +#define VMGENID_GUID_FW_CFG_FILE "etc/vmgenid_guid" +#define VMGENID_ADDR_FW_CFG_FILE "etc/vmgenid_addr" + +#define VMGENID_FW_CFG_SIZE 4096/* Occupy a page of memory */ +#define VMGENID_GUID_OFFSET 40/* allow space for +* OVMF SDT Header Probe Supressor +*/ + +#define VMGENID (obj) OBJECT_CHECK(VmGenIdState, (obj), VMGENID_DEVICE) + +typedef struct VmGenIdState { +DeviceClass parent_obj; +QemuUUID guid;/* The 128-bit GUID seen by the guest */ +uint8_t vmgenid_addr_le[8 ];/* Address of the GUID (little-endian) */ +}VmGenIdState ; + +static inline Object *find_vmgenid_dev (void ) +{ +return object_resolve_path_type ("" ,VMGENID_DEVICE ,NULL ); +} + +void vmgenid_build_acpi (VmGenIdState *vms,GArray *table_data,GArray *guid, +BIOSLinker *linker); +void vmgenid_add_fw_cfg (VmGenIdState *vms,FWCfgState *s,GArray *guid); + +#endif
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v7 4/8] ACPI: Add Virtual Machine Generation ID support
Quoted 11 lines · On Wed, 15 Feb 2017 22:18:14 -0800 [email protected] wrote:
From: Ben Warren <[email protected]>
This implements the VM Generation ID feature by passing a 128-bit GUID to the guest via a
fw_cfgblob.
Any time the GUID changes, an ACPI notify event is sent to the guestThe user interface is a simple device with one parameter:
- guid (string, must be "auto" or in UUID format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)Signed-off-by Ben Warren <[email protected]>
Thing to get fixed on top is to check
that there isn't vmgenid device present already
into realizefn() and fail gracefully is there is.
Quoted 395 lines
--- default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/acpi/Makefile.objs | 1 + hw/acpi/vmgenid.c | 239 +++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 16 +++ include/hw/acpi/acpi_dev_interface.h | 1 + include/hw/acpi/vmgenid.h | 35 +++++ 7 files changed, 294 insertions(+) create mode 100644 hw/acpi/vmgenid.c create mode 100644 include/hw/acpi/vmgenid.hdefault-configs/i386-softmmu.mak +1
-0@@ -59,3 +59,4 @@ CONFIG_I82801B11=y CONFIG_SMBIOS=y CONFIG_HYPERV_TESTDEV=$(CONFIG_KVM) CONFIG_PXB=y +CONFIG_ACPI_VMGENID=ydefault-configs/x86_64-softmmu.mak +1
-0@@ -59,3 +59,4 @@ CONFIG_I82801B11=y CONFIG_SMBIOS=y CONFIG_HYPERV_TESTDEV=$(CONFIG_KVM) CONFIG_PXB=y +CONFIG_ACPI_VMGENID=yhw/acpi/Makefile.objs +1
-0@@ -5,6 +5,7 @@ common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o +common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o common-obj-y += acpi_interface.ohw/acpi/vmgenid.c new file +239
-0@@ -0,0 +1,239 @@ +/* +* Virtual Machine Generation ID Device +* +* Copyright (C) 2017 Skyport Systems. +* +* Author: Ben Warren <[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. +* +*/ + +#include "qemu/osdep.h" +#include "qmp-commands.h" +#include "hw/acpi/acpi.h" +#include "hw/acpi/aml-build.h" +#include "hw/acpi/vmgenid.h" +#include "hw/nvram/fw_cfg.h" +#include "sysemu/sysemu.h" + +void vmgenid_build_acpi (VmGenIdState *vms,GArray *table_data,GArray *guid, +BIOSLinker *linker) +{ +Aml *ssdt, *dev, *scope, *method, *addr, *if_ctx; +uint32_t vgia_offset; +QemuUUID guid_le; + +/* Fill in the GUID values. These need to be converted to little-endian +* first, since that's what the guest expects +*/ +g_array_set_size (guid,VMGENID_FW_CFG_SIZE -ARRAY_SIZE (guid_le.data)); + guid_le = vms->guid; +qemu_uuid_bswap (&guid_le); +/* The GUID is written at a fixed offset into the fw_cfg file +* in order to implement the "OVMF SDT Header probe suppressor" +* see docs/specs/vmgenid.txt for more details +*/ +g_array_insert_vals (guid,VMGENID_GUID_OFFSET , guid_le.data, +ARRAY_SIZE (guid_le.data)); + +/* 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 */ + vgia_offset = table_data->len + +build_append_named_dword (ssdt->buf,"VGIA" ); + scope =aml_scope ("\\_SB" ); + dev =aml_device ("VGEN" ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("QEMUVGID" ))); +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 ); + addr =aml_local (0 ); +aml_append (method,aml_store (aml_int (0xf ), addr)); + if_ctx =aml_if (aml_equal (aml_name ("VGIA" ),aml_int (0 ))); +aml_append (if_ctx,aml_store (aml_int (0 ), addr)); +aml_append (method, if_ctx); +aml_append (method,aml_return (addr)); +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 ); + + addr =aml_local (0 ); +aml_append (method,aml_store (aml_package (2 ), addr)); + +aml_append (method,aml_store (aml_add (aml_name ("VGIA" ), +aml_int (VMGENID_GUID_OFFSET ),NULL ), +aml_index (addr,aml_int (0 )))); +aml_append (method,aml_store (aml_int (0 ),aml_index (addr,aml_int (1 )))); +aml_append (method,aml_return (addr)); + +aml_append (dev, method); +aml_append (scope, dev); +aml_append (ssdt, scope); + +/* attach an ACPI notify */ + method =aml_method ("\\_GPE._E05" ,0 ,AML_NOTSERIALIZED ); +aml_append (method,aml_notify (aml_name ("\\_SB.VGEN" ),aml_int (0x80 ))); +aml_append (ssdt, method); + +g_array_append_vals (table_data, ssdt->buf->data, ssdt->buf->len); + +/* Allocate guest memory for the Data fw_cfg blob */ +bios_linker_loader_alloc (linker,VMGENID_GUID_FW_CFG_FILE , guid,4096 , + false/* page boundary, high memory */ ); + +/* Patch address of GUID fw_cfg blob into the ADDR fw_cfg blob +* so QEMU can write the GUID there. The address is expected to be +* < 4GB, but write 64 bits anyway. +*/ +bios_linker_loader_write_pointer (linker, +VMGENID_ADDR_FW_CFG_FILE ,0 ,sizeof (uint64_t ), +VMGENID_GUID_FW_CFG_FILE ,VMGENID_GUID_OFFSET ); + +/* Patch address of GUID fw_cfg blob into the AML so OSPM can retrieve +* and read it. Note that while we provide storage for 64 bits, only +* the least-signficant 32 get patched into AML. +*/ +bios_linker_loader_add_pointer (linker, +ACPI_BUILD_TABLE_FILE , vgia_offset,sizeof (uint32_t ), +VMGENID_GUID_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 (VmGenIdState *vms,FWCfgState *s,GArray *guid) +{ +/* Create a read-only fw_cfg file for GUID */ +fw_cfg_add_file (s,VMGENID_GUID_FW_CFG_FILE , guid->data, +VMGENID_FW_CFG_SIZE ); +/* Create a read-write fw_cfg file for Address */ +fw_cfg_add_file_callback (s,VMGENID_ADDR_FW_CFG_FILE ,NULL ,NULL , + vms->vmgenid_addr_le, +ARRAY_SIZE (vms->vmgenid_addr_le), false); +} + +static void vmgenid_update_guest (VmGenIdState *vms) +{ +Object *obj =object_resolve_path_type ("" ,TYPE_ACPI_DEVICE_IF ,NULL ); +uint32_t vmgenid_addr; +QemuUUID guid_le; + +if (obj) { +/* Write the GUID to guest memory */ +memcpy (&vmgenid_addr, vms->vmgenid_addr_le,sizeof (vmgenid_addr)); + vmgenid_addr =le32_to_cpu (vmgenid_addr); +/* A zero value in vmgenid_addr means that BIOS has not yet written +* the address +*/ +if (vmgenid_addr) { +/* QemuUUID has the first three words as big-endian, and expect +* that any GUIDs passed in will always be BE. The guest, +* however, will expect the fields to be little-endian. +* Perform a byte swap immediately before writing. +*/ + guid_le = vms->guid; +qemu_uuid_bswap (&guid_le); +/* The GUID is written at a fixed offset into the fw_cfg file +* in order to implement the "OVMF SDT Header probe suppressor" +* see docs/specs/vmgenid.txt for more details +*/ +cpu_physical_memory_write (vmgenid_addr, guid_le.data, +sizeof (guid_le.data)); +/* Send _GPE.E05 event */ +acpi_send_event (DEVICE (obj),ACPI_VMGENID_CHANGE_STATUS ); + } + } +} + +static void vmgenid_set_guid (Object *obj,const char *value,Error **errp) +{ +VmGenIdState *vms =VMGENID (obj); + +if (!strcmp (value,"auto" )) { +qemu_uuid_generate (&vms->guid); + }else if (qemu_uuid_parse (value, &vms->guid) <0 ) { +error_setg (errp,"'%s. %s': Failed to parse GUID string: %s" , +object_get_typename (OBJECT (vms)),VMGENID_GUID , value); +return ; + } + +vmgenid_update_guest (vms); +} + +/* After restoring an image, we need to update the guest memory and notify +* it of a potential change to VM Generation ID +*/ +static int vmgenid_post_load (void *opaque,int version_id) +{ +VmGenIdState *vms = opaque; +vmgenid_update_guest (vms); +return 0 ; +} + +static const VMStateDescription vmstate_vmgenid = { + .name ="vmgenid" , + .version_id =1 , + .minimum_version_id =1 , + .post_load = vmgenid_post_load, + .fields = (VMStateField []) { +VMSTATE_UINT8_ARRAY (vmgenid_addr_le, VmGenIdState,sizeof (uint64_t )), +VMSTATE_END_OF_LIST () + }, +}; + +static void vmgenid_handle_reset (void *opaque) +{ +VmGenIdState *vms =VMGENID (opaque); +/* Clear the guest-allocated GUID address when the VM resets */ +memset (vms->vmgenid_addr_le,0 ,ARRAY_SIZE (vms->vmgenid_addr_le)); +} + +static void vmgenid_realize (DeviceState *dev,Error **errp) +{ +VmGenIdState *vms =VMGENID (dev); +qemu_register_reset (vmgenid_handle_reset, vms); +} + +static void vmgenid_device_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->vmsd = &vmstate_vmgenid; + dc->realize = vmgenid_realize; + dc->hotpluggable = false; + +object_class_property_add_str (klass,VMGENID_GUID ,NULL , + vmgenid_set_guid,NULL ); +object_class_property_set_description (klass,VMGENID_GUID , +"Set Global Unique Identifier " +"(big-endian) or auto for random value" , +NULL ); +} + +static const TypeInfo vmgenid_device_info = { + .name =VMGENID_DEVICE , + .parent =TYPE_DEVICE , + .instance_size =sizeof (VmGenIdState), + .class_init = vmgenid_device_class_init, +}; + +static void vmgenid_register_types (void ) +{ +type_register_static (&vmgenid_device_info); +} + +type_init (vmgenid_register_types)hw/i386/acpi-build.c +16
-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" @@ -2610,6 +2611,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)size_t aml_len =0 ;GArray *tables_blob = tables->table_data;AcpiSlicOem slic_oem = { .id =NULL , .table_id =NULL }; +Object *vmgenid_dev;acpi_get_pm_info (&pm);acpi_get_misc_info (&misc);@@ -2653,6 +2655,13 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)acpi_add_table (table_offsets, tables_blob);build_madt (tables_blob, tables->linker, pcms); + vmgenid_dev =find_vmgenid_dev (); +if (vmgenid_dev) { +acpi_add_table (table_offsets, tables_blob); +vmgenid_build_acpi (VMGENID (vmgenid_dev), tables_blob, + tables->vmgenid, tables->linker); + } +if (misc.has_hpet) {acpi_add_table (table_offsets, tables_blob);build_hpet (tables_blob, tables->linker);@@ -2823,6 +2832,7 @@ void acpi_setup(void)PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);AcpiBuildTables tables;AcpiBuildState *build_state; +Object *vmgenid_dev;if (!pcms->fw_cfg) {ACPI_BUILD_DPRINTF ("No fw cfg. Bailing out.\n" );@@ -2859,6 +2869,12 @@ void acpi_setup(void)fw_cfg_add_file (pcms->fw_cfg,ACPI_BUILD_TPMLOG_FILE , tables.tcpalog->data,acpi_data_len (tables.tcpalog)); + vmgenid_dev =find_vmgenid_dev (); +if (vmgenid_dev) { +vmgenid_add_fw_cfg (VMGENID (vmgenid_dev), pcms->fw_cfg, + tables.vmgenid); + } +if (!pcmc->rsdp_in_ram) {/* * Keep for compatibility with old machine types. 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 +35
-0@@ -0,0 +1,35 @@ +#ifndef ACPI_VMGENID_H +#define ACPI_VMGENID_H + +#include "hw/acpi/bios-linker-loader.h" +#include "hw/qdev.h" +#include "qemu/uuid.h" + +#define VMGENID_DEVICE "vmgenid" +#define VMGENID_GUID "guid" +#define VMGENID_GUID_FW_CFG_FILE "etc/vmgenid_guid" +#define VMGENID_ADDR_FW_CFG_FILE "etc/vmgenid_addr" + +#define VMGENID_FW_CFG_SIZE 4096/* Occupy a page of memory */ +#define VMGENID_GUID_OFFSET 40/* allow space for +* OVMF SDT Header Probe Supressor +*/ + +#define VMGENID (obj) OBJECT_CHECK(VmGenIdState, (obj), VMGENID_DEVICE) + +typedef struct VmGenIdState { +DeviceClass parent_obj; +QemuUUID guid;/* The 128-bit GUID seen by the guest */ +uint8_t vmgenid_addr_le[8 ];/* Address of the GUID (little-endian) */ +}VmGenIdState ; + +static inline Object *find_vmgenid_dev (void ) +{ +return object_resolve_path_type ("" ,VMGENID_DEVICE ,NULL ); +} + +void vmgenid_build_acpi (VmGenIdState *vms,GArray *table_data,GArray *guid, +BIOSLinker *linker); +void vmgenid_add_fw_cfg (VmGenIdState *vms,FWCfgState *s,GArray *guid); + +#endif
Re: [Qemu-devel] [PATCH v7 4/8] ACPI: Add Virtual Machine Generation ID support
Quoted 16 lines · Igor Mammedov
Quoted 10 lines · On Wed, 15 Feb 2017 22:18:14 -0800 [email protected] wrote:
From: Ben Warren <[email protected]>
This implements the VM Generation ID feature by passing a 128-bit GUID to the guest via a
fw_cfgblob.
Any time the GUID changes, an ACPI notify event is sent to the guestThe user interface is a simple device with one parameter:
- guid (string, must be "auto" or in UUID format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
Quoted 7 lines
Quoted 1 line
Signed-off-by Ben Warren <[email protected]>Reviewed-by Igor Mammedov <[email protected]>Thing to get fixed on top is to check
that there isn't vmgenid device present already
intorealizefn()and fail gracefully is there is.
I made the change as follows:
===
hw/acpi/vmgenid.c +7 -0
@@ -207,8 +207,15 @@ static void vmgenid_handle_reset(void *opaque)static void vmgenid_realize (DeviceState *dev,Error **errp) { +static bool is_realized = false;VmGenIdState *vms =VMGENID (dev); + +if (is_realized) { +error_setg (errp,"Device %s may only be specified once" , +VMGENID_DEVICE ); + }qemu_register_reset (vmgenid_handle_reset, vms); + is_realized = true; }
===
Sample output:
$ ../workspace/qemu/x86_64-softmmu/qemu-system-x86_64 -nographic -bios ../workspace/seabios/out/bios.bin -machine type=q35 -hda beiwe-with-vmgenid-driver.qcow2 -qmp unix:./qmp-sock,server,nowait -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb66" -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb67" qemu-system-x86_64: -device vmgenid,guid=324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb67: Device vmgenid may only be specified once
Good enough? If so, I’ll roll it in. Otherwise, it’ll be a supplemental patch.
—Ben
<snip>
Re: [Qemu-devel] [PATCH v7 4/8] ACPI: Add Virtual Machine Generation ID support
Quoted 47 lines · Ben Warren
Quoted 16 lines · Igor Mammedov
Quoted 10 lines · On Wed, 15 Feb 2017 22:18:14 -0800 [email protected] wrote:
From: Ben Warren <[email protected]>
This implements the VM Generation ID feature by passing a 128-bit GUID to the guest via a
fw_cfgblob.
Any time the GUID changes, an ACPI notify event is sent to the guestThe user interface is a simple device with one parameter:
- guid (string, must be "auto" or in UUID format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)Quoted 7 lines
Quoted 1 line
Signed-off-by Ben Warren <[email protected]>Reviewed-by Igor Mammedov <[email protected]>Thing to get fixed on top is to check
that there isn't vmgenid device present already
intorealizefn()and fail gracefully is there is.I made the change as follows:
===hw/acpi/vmgenid.c +7
-0@@ -207,8 +207,15 @@ static void vmgenid_handle_reset(void *opaque)static void vmgenid_realize (DeviceState *dev,Error **errp) { +static bool is_realized = false;VmGenIdState *vms =VMGENID (dev); + +if (is_realized) { +error_setg (errp,"Device %s may only be specified once" , +VMGENID_DEVICE ); + }qemu_register_reset (vmgenid_handle_reset, vms); + is_realized = true; }===
Sample output:
Quoted 5 lines
$ ../workspace/qemu/x86_64-softmmu/qemu-system-x86_64 -nographic -bios ../workspace/seabios/out/bios.bin -machine type=q35 -hda beiwe-with-vmgenid-driver.qcow2 -qmp unix:./qmp-sock,server,nowait -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb66" -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb67" qemu-system-x86_64: -device vmgenid,guid=324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb67: Device vmgenid may only be specified onceGood enough? If so, I’ll roll it in. Otherwise, it’ll be a supplemental patch.
Ehm, I'd say let's postpone that patch. Function (or even file) scope static variables that plaster over QOM shortcomings (or, well, "non-trivial QOM patterns") are strongly frowned upon. I've done it myself before (totally as a last resort, really -- not kidding!), and it was real hard to get into the tree.
This deserves more discussion, so please delay it.
(While at it, please remember my other recommendation for realize():
enforcing that the running machine type / version provides the guest with the DMA interface for fw_cfg. For that, based on prior consensus, you'll need another device property, to be set in parallel to fw_cfg_mem's and fw_cfg_io's "dma-enabled" property. So I think it makes sense to address all of these things in a separate, followup series.)
Thanks!
Laszlo
Re: [Qemu-devel] [PATCH v7 4/8] ACPI: Add Virtual Machine Generation ID support
Quoted 63 lines · Laszlo Ersek
Quoted 47 lines · Ben Warren
Quoted 16 lines · Igor Mammedov
Quoted 10 lines · On Wed, 15 Feb 2017 22:18:14 -0800 [email protected] wrote:
From: Ben Warren <[email protected]>
This implements the VM Generation ID feature by passing a 128-bit GUID to the guest via a
fw_cfgblob.
Any time the GUID changes, an ACPI notify event is sent to the guestThe user interface is a simple device with one parameter:
- guid (string, must be "auto" or in UUID format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)Quoted 7 lines
Quoted 1 line
Signed-off-by Ben Warren <[email protected]>Reviewed-by Igor Mammedov <[email protected]>Thing to get fixed on top is to check
that there isn't vmgenid device present already
intorealizefn()and fail gracefully is there is.I made the change as follows:
===hw/acpi/vmgenid.c +7
-0@@ -207,8 +207,15 @@ static void vmgenid_handle_reset(void *opaque)static void vmgenid_realize (DeviceState *dev,Error **errp) { +static bool is_realized = false;VmGenIdState *vms =VMGENID (dev); + +if (is_realized) { +error_setg (errp,"Device %s may only be specified once" , +VMGENID_DEVICE ); + }qemu_register_reset (vmgenid_handle_reset, vms); + is_realized = true; }===
Sample output:Quoted 5 lines
$ ../workspace/qemu/x86_64-softmmu/qemu-system-x86_64 -nographic -bios ../workspace/seabios/out/bios.bin -machine type=q35 -hda beiwe-with-vmgenid-driver.qcow2 -qmp unix:./qmp-sock,server,nowait -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb66" -device vmgenid,guid="324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb67" qemu-system-x86_64: -device vmgenid,guid=324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb67: Device vmgenid may only be specified onceGood enough? If so, I’ll roll it in. Otherwise, it’ll be a supplemental patch.
Ehm, I'd say let's postpone that patch. Function (or even file) scope static variables that plaster over QOM shortcomings (or, well, "non-trivial QOM patterns") are strongly frowned upon. I've done it myself before (totally as a last resort, really -- not kidding!), and it was real hard to get into the tree.
Quoted 9 lines
This deserves more discussion, so please delay it.
(While at it, please remember my other recommendation for
realize():
enforcing that the running machine type / version provides the guest with the DMA interface forfw_cfg. For that, based on prior consensus, you'll need another device property, to be set in parallel to fw_cfg_mem's and fw_cfg_io's "dma-enabled" property. So I think it makes sense to address all of these things in a separate, followup series.)
OK, makes sense.
Quoted 2 lines
Thanks!
Laszlo
—Ben
Re: [Qemu-devel] [PATCH v7 4/8] ACPI: Add Virtual Machine Generation ID support
In reply to [email protected]Quoted 11 lines · On 02/16/17 07:18, [email protected] wrote:
From: Ben Warren <[email protected]>
This implements the VM Generation ID feature by passing a 128-bit GUID to the guest via a
fw_cfgblob.
Any time the GUID changes, an ACPI notify event is sent to the guestThe user interface is a simple device with one parameter:
- guid (string, must be "auto" or in UUID format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)Signed-off-by Ben Warren <[email protected]>
Quoted 11 lines
--- default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/acpi/Makefile.objs | 1 + hw/acpi/vmgenid.c | 239 +++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 16 +++ include/hw/acpi/acpi_dev_interface.h | 1 + include/hw/acpi/vmgenid.h | 35 +++++ 7 files changed, 294 insertions(+) create mode 100644 hw/acpi/vmgenid.c create mode 100644 include/hw/acpi/vmgenid.h
I compared this version against v6. It looks good. I also tested it (with the fixup I mentioned under v7 1/8, and without live migration).
Thanks
Laszlo
PATCH v7 5/8 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 | 14 ++++++++++++++ hmp.c | 9 +++++++++ hmp.h | 1 + hw/acpi/vmgenid.c | 16 ++++++++++++++++ qapi-schema.json | 20 ++++++++++++++++++++ stubs/Makefile.objs | 1 + stubs/vmgenid.c | 9 +++++++++ 7 files changed, 70 insertions(+) create mode 100644 stubs/vmgenid.c
hmp-commands-info.hx +14 -0
@@ -802,6 +802,20 @@ Show information about hotpluggable CPUs ETEXI STEXI +@item info vm-generation-id +@findex vm-generation-id +Show Virtual Machine Generation ID +ETEXI + + { + .name = "vm-generation-id", + .args_type = "", + .params = "", + .help = "Show Virtual Machine Generation ID", + .cmd = hmp_info_vm_generation_id, + }, + +STEXI @end table ETEXI
hmp.c +9 -0
@@ -2565,3 +2565,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
hw/acpi/vmgenid.c +16 -0
@@ -237,3 +237,19 @@ static void vmgenid_register_types(void) }type_init (vmgenid_register_types) + +GuidInfo *qmp_query_vm_generation_id(Error **errp) +{ +GuidInfo *info; +VmGenIdState *vms; +Object *obj =find_vmgenid_dev (); + +if (!obj) { +return NULL ; + } + vms =VMGENID (obj); + + info =g_malloc0 (sizeof (*info)); + info->guid =qemu_uuid_unparse_strdup (&vms->guid); +return info; +}
qapi-schema.json +20 -0
@@ -6056,3 +6056,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
@@ -35,3 +35,4 @@ stub-obj-y += qmp_pc_dimm_device_list.o stub-obj-y += target-monitor-defs.o stub-obj-y += target-get-monitor-def.o stub-obj-y += pc_madt_cpu_entry.o +stub-obj-y += vmgenid.o
stubs/vmgenid.c new file +9 -0
@@ -0,0 +1,9 @@ +#include "qemu/osdep.h" +#include "qmp-commands.h" +#include "qapi/qmp/qerror.h" + +GuidInfo *qmp_query_vm_generation_id (Error **errp) +{ +error_setg (errp,QERR_UNSUPPORTED ); +return NULL ; +}
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v7 5/8] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands
Quoted 14 lines · On 02/16/17 07:18, [email protected] wrote:
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-idSigned-off-by Igor Mammedov <[email protected]>Reviewed-by Eric Blake <[email protected]>Signed-off-by Ben Warren <[email protected]>Reviewed-by Laszlo Ersek <[email protected]>
Quoted 10 lines
--- hmp-commands-info.hx | 14 ++++++++++++++ hmp.c | 9 +++++++++ hmp.h | 1 + hw/acpi/vmgenid.c | 16 ++++++++++++++++ qapi-schema.json | 20 ++++++++++++++++++++ stubs/Makefile.objs | 1 + stubs/vmgenid.c | 9 +++++++++ 7 files changed, 70 insertions(+) create mode 100644 stubs/vmgenid.c
I tested the "info vm-generation-id" command via HMP.
Thanks,
Laszlo
PATCH v7 6/8 tests: Move reusable ACPI code into a utility file
In reply to [email protected]From: Ben Warren <[email protected]>
Also usable by upcoming VM Generation ID tests
--- tests/Makefile.include | 2 +- tests/acpi-utils.c | 65 +++++++++++++++++++++++ tests/acpi-utils.h | 94 +++++++++++++++++++++++++++++++++ tests/bios-tables-test.c | 132 ++++++----------------------------------------- 4 files changed, 175 insertions(+), 118 deletions(-) create mode 100644 tests/acpi-utils.c create mode 100644 tests/acpi-utils.h
tests/Makefile.include +1 -1
@@ -667,7 +667,7 @@ tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o tests/boot-order-test$(EXESUF): tests/boot-order-test.o $(libqos-obj-y) tests/boot-serial-test$(EXESUF): tests/boot-serial-test.o $(libqos-obj-y) tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o \ - tests/boot-sector.o $(libqos-obj-y) + tests/boot-sector.o tests/acpi-utils.o $(libqos-obj-y) tests/pxe-test$(EXESUF): tests/pxe-test.o tests/boot-sector.o $(libqos-obj-y) tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y) tests/ds1338-test$(EXESUF): tests/ds1338-test.o $(libqos-imx-obj-y)
tests/acpi-utils.c new file +65 -0
65 lines not on this page · raw message
tests/acpi-utils.h new file +94 -0
94 lines not on this page · raw message
tests/bios-tables-test.c +15 -117
192 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v7 7/8 tests: Add unit tests for the VM Generation ID feature
In reply to [email protected]From: Ben Warren <[email protected]>
The following tests are implemented:
* test that a GUID passed in by command line is propagated to the guest. Read the GUID both from guest memory and from the monitor
* test that the "auto" argument to the GUID generates a valid GUID, as seen by the guest.
This patch is loosely based on a previous patch from:
Gal Hammer <[email protected]> and Igor Mammedov <[email protected]>
--- tests/Makefile.include | 2 + tests/vmgenid-test.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 tests/vmgenid-test.c
tests/Makefile.include +2 -0
@@ -241,6 +241,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),)
@@ -726,6 +727,7 @@ tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o contrib/ivshmem-server/ivshmem tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o contrib/libvhost-user/libvhost-user.o $(test-util-obj-y) tests/test-uuid$(EXESUF): tests/test-uuid.o $(test-util-obj-y) tests/test-arm-mptimer$(EXESUF): tests/test-arm-mptimer.o +tests/vmgenid-test$(EXESUF): tests/vmgenid-test.o tests/acpi-utils.o tests/migration/stress$(EXESUF): tests/migration/stress.o $(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ,"LINK","$(TARGET_DIR)$@")
tests/vmgenid-test.c new file +174 -0
174 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v7 7/8] tests: Add unit tests for the VM Generation ID feature
Quoted 81 lines · On Wed, 15 Feb 2017 22:18:17 -0800 [email protected] wrote:
From: Ben Warren <[email protected]>
The following tests are implemented:
* test that a GUID passed in by command line is propagated to the guest. Read the GUID both from guest memory and from the monitor
* test that the "auto" argument to the GUID generates a valid GUID, as seen by the guest.This patch is loosely based on a previous patch from:
Gal Hammer <[email protected]> and Igor Mammedov <[email protected]>Signed-off-by Ben Warren <[email protected]>--- tests/Makefile.include | 2 + tests/vmgenid-test.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 tests/vmgenid-test.ctests/Makefile.include +2
-0@@ -241,6 +241,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),)@@ -726,6 +727,7 @@ tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o contrib/ivshmem-server/ivshmem tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o contrib/libvhost-user/libvhost-user.o $(test-util-obj-y) tests/test-uuid$(EXESUF): tests/test-uuid.o $(test-util-obj-y) tests/test-arm-mptimer$(EXESUF): tests/test-arm-mptimer.o +tests/vmgenid-test$(EXESUF): tests/vmgenid-test.o tests/acpi-utils.o tests/migration/stress$(EXESUF): tests/migration/stress.o $(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ,"LINK","$(TARGET_DIR)$@")tests/vmgenid-test.c new file +37
-0@@ -0,0 +1,174 @@ +/* +* QTest testcase for VM Generation ID +* +* Copyright (c) 2016 Red Hat, Inc. +* Copyright (c) 2017 Skyport Systems +* +* 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 <glib.h> +#include <string.h> +#include <unistd.h> +#include "qemu/osdep.h" +#include "qemu/bitmap.h" +#include "qemu/uuid.h" +#include "hw/acpi/acpi-defs.h" +#include "acpi-utils.h" +#include "libqtest.h" + +#define VGID_GUID "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87" +#define VMGENID_GUID_OFFSET 40/* allow space for +* OVMF SDT Header Probe Supressor +*/ + +typedef struct { +AcpiTableHeader header; +gchar name_op; +gchar vgia[4 ]; +gchar val_op; +uint32_t vgia_val; +} QEMU_PACKED VgidTable; + +static uint32_t acpi_find_vgia (void ) +{ +uint32_t off; +AcpiRsdpDescriptor rsdp_table;
tests/vmgenid-test.c line 47
Quoted 10 lines
tests/vmgenid-test.c new file +10
-0+uint32_t rsdt; +AcpiRsdtDescriptorRev1 rsdt_table; +int tables_nr; +uint32_t *tables; +AcpiTableHeader ssdt_table; +VgidTable vgid_table; +int i; + + off =acpi_find_rsdp_address (); + g_assert_cmphex(off, <, 0x100000);
something's off here,
it fails for me for me with:
QTEST_QEMU_BINARY=x86_64-softmmu/qemu-system-x86_64 tests/vmgenid-test
/x86_64/vmgenid/vmgenid: **
ERROR:/home/imammedo/builds/qemu/tests/vmgenid-test.c:47:acpi_find_vgia: assertion failed (off < 0x100000): (0x00100000 < 0x00100000)
Quoted 127 lines
tests/vmgenid-test.c new file +127
-0+ +acpi_parse_rsdp_table (off, &rsdp_table); + + rsdt = rsdp_table.rsdt_physical_address; +/* read the header */ +ACPI_READ_TABLE_HEADER (&rsdt_table, rsdt); +ACPI_ASSERT_CMP (rsdt_table.signature,"RSDT" ); + +/* compute the table entries in rsdt */ + tables_nr = (rsdt_table.length -sizeof (AcpiRsdtDescriptorRev1)) / +sizeof (uint32_t ); + g_assert_cmpint(tables_nr, >, 0); + +/* get the addresses of the tables pointed by rsdt */ + tables =g_new0 (uint32_t, tables_nr); +ACPI_READ_ARRAY_PTR (tables, tables_nr, rsdt); + +for (i =0 ; i < tables_nr; i++) { +ACPI_READ_TABLE_HEADER (&ssdt_table, tables[i]); +if (!strncmp ((char *)ssdt_table.oem_table_id,"VMGENID" ,7 )) { +/* the first entry in the table should be VGIA +* That's all we need +*/ +ACPI_READ_FIELD (vgid_table.name_op, tables[i]); +g_assert (vgid_table.name_op ==0x08 );/* name */ +ACPI_READ_ARRAY (vgid_table.vgia, tables[i]); +g_assert (memcmp (vgid_table.vgia,"VGIA" ,4 ) ==0 ); +ACPI_READ_FIELD (vgid_table.val_op, tables[i]); +g_assert (vgid_table.val_op ==0x0C );/* dword */ +ACPI_READ_FIELD (vgid_table.vgia_val, tables[i]); +/* The GUID is written at a fixed offset into the fw_cfg file +* in order to implement the "OVMF SDT Header probe suppressor" +* see docs/specs/vmgenid.txt for more details +*/ +return vgid_table.vgia_val +VMGENID_GUID_OFFSET ; + } + } +return 0 ; +} + +static void read_guid_from_memory (QemuUUID *guid) +{ +uint32_t vmgenid_addr; +int i; + + vmgenid_addr =acpi_find_vgia (); +g_assert (vmgenid_addr); + +/* Read the GUID directly from guest memory */ +for (i =0 ; i <16 ; i++) { + guid->data[i] =readb (vmgenid_addr + i); + } +/* The GUID is in little-endian format in the guest, while QEMU +* uses big-endian. Swap after reading. +*/ +qemu_uuid_bswap (guid); +} + +static void read_guid_from_monitor (QemuUUID *guid) +{ +QDict *rsp, *rsp_ret; +const char *guid_str; + + rsp =qmp ("{ 'execute': 'query-vm-generation-id' }" ); +if (qdict_haskey (rsp,"return" )) { + rsp_ret =qdict_get_qdict (rsp,"return" ); +g_assert (qdict_haskey (rsp_ret,"guid" )); + guid_str =qdict_get_str (rsp_ret,"guid" ); +g_assert (qemu_uuid_parse (guid_str, guid) ==0 ); + } +QDECREF (rsp); +} + +static void vmgenid_test (void ) +{ +QemuUUID expected, measured; +gchar *cmd; + +g_assert (qemu_uuid_parse (VGID_GUID , &expected) ==0 ); + + cmd =g_strdup_printf ("-machine accel=tcg -device vmgenid,id=testvgid," +"guid=%s" ,VGID_GUID ); +qtest_start (cmd); + +/* Read the GUID from accessing guest memory */ +read_guid_from_memory (&measured); +g_assert (memcmp (measured.data, expected.data,sizeof (measured.data)) ==0 ); + +/* Read the GUID via the monitor */ +read_guid_from_monitor (&measured); +g_assert (memcmp (measured.data, expected.data,sizeof (measured.data)) ==0 ); + +qtest_quit (global_qtest); +g_free (cmd); +} + +static void vmgenid_set_guid_auto_test (void ) +{ +const char *cmd; +QemuUUID measured; + + cmd ="-machine accel=tcg -device vmgenid,id=testvgid," "guid=auto" ; +qtest_start (cmd); + +read_guid_from_memory (&measured); + +/* Just check that the GUID is non-null */ +g_assert (!qemu_uuid_is_null (&measured)); + +qtest_quit (global_qtest); +} + +int main (int argc,char **argv) +{ +int ret; + +g_test_init (&argc, &argv,NULL ); + +qtest_add_func ("/vmgenid/vmgenid" , vmgenid_test); +qtest_add_func ("/vmgenid/vmgenid/set-guid-auto" , + vmgenid_set_guid_auto_test); + ret =g_test_run (); + +qtest_end (); + +return ret; +}
Re: [Qemu-devel] [PATCH v7 7/8] tests: Add unit tests for the VM Generation ID feature
Quoted 100 lines · Igor Mammedov
Quoted 81 lines · On Wed, 15 Feb 2017 22:18:17 -0800 [email protected]…
From: Ben Warren <[email protected]>
The following tests are implemented:
* test that a GUID passed in by command line is propagated to the guest. Read the GUID both from guest memory and from the monitor
* test that the "auto" argument to the GUID generates a valid GUID, as seen by the guest.This patch is loosely based on a previous patch from:
Gal Hammer <[email protected]> and Igor Mammedov <[email protected]>Signed-off-by Ben Warren <[email protected]>---
tests/Makefile.include | 2 +tests/vmgenid-test.c| 174 +++++++++++++++++++++++++++++++++++++++++++++++++2 files changed, 176 insertions(+)create mode 100644
tests/vmgenid-test.ctests/Makefile.include +0
-0@@ -241,6 +241,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.ccheck-qtest-i386-$(CONFIG_VHOST_NET_TEST_i386) += tests/vhost-user-test$(EXESUF) ifeq ($(CONFIG_VHOST_NET_TEST_i386),)tests/Makefile.include +0
-0@@ -726,6 +727,7 @@ tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o contrib/ivshmem-server/ivshmem tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o contrib/libvhost-user/libvhost-user.o $(test-util-obj-y) tests/test-uuid$(EXESUF): tests/test-uuid.o $(test-util-obj-y)tests/test-arm-mptimer$(EXESUF):
tests/test-arm-mptimer.o+tests/vmgenid-test$(EXESUF):tests/vmgenid-test.otests/acpi-utils.otests/migration/stress$(EXESUF):
tests/migration/stress.o$(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ,"LINK","$(TARGET_DIR)$@")tests/vmgenid-test.c new file +37
-0@@ -0,0 +1,174 @@ +/* +* QTest testcase for VM Generation ID +* +* Copyright (c) 2016 Red Hat, Inc. +* Copyright (c) 2017 Skyport Systems +* +* 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 <glib.h> +#include <string.h> +#include <unistd.h> +#include "qemu/osdep.h" +#include "qemu/bitmap.h" +#include "qemu/uuid.h" +#include "hw/acpi/acpi-defs.h" +#include "acpi-utils.h" +#include "libqtest.h" + +#define VGID_GUID "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87" +#define VMGENID_GUID_OFFSET 40/* allow space for +* OVMF SDT Header Probe Supressor +*/ + +typedef struct { +AcpiTableHeader header; +gchar name_op; +gchar vgia[4 ]; +gchar val_op; +uint32_t vgia_val; +} QEMU_PACKED VgidTable; + +static uint32_t acpi_find_vgia (void ) +{ +uint32_t off; +AcpiRsdpDescriptor rsdp_table;tests/vmgenid-test.c line 47
Quoted 10 lines
tests/vmgenid-test.c new file +10
-0+uint32_t rsdt; +AcpiRsdtDescriptorRev1 rsdt_table; +int tables_nr; +uint32_t *tables; +AcpiTableHeader ssdt_table; +VgidTable vgid_table; +int i; + + off =acpi_find_rsdp_address (); + g_assert_cmphex(off, <, 0x100000);something's off here,
it fails for me for me with:
Quoted 4 lines
QTEST_QEMU_BINARY=x86_64-softmmu/qemu-system-x86_64 tests/vmgenid-test
/x86_64/vmgenid/vmgenid: **
ERROR:/home/imammedo/builds/qemu/tests/vmgenid-test.c:47:acpi_find_vgia: assertion failed (off <0x100000): (0x00100000<0x00100000)
Probably a timing issue. I’ll get to the bottom of it ASAP
Quoted 127 lines
Quoted 127 lines
tests/vmgenid-test.c new file +127
-0+ +acpi_parse_rsdp_table (off, &rsdp_table); + + rsdt = rsdp_table.rsdt_physical_address; +/* read the header */ +ACPI_READ_TABLE_HEADER (&rsdt_table, rsdt); +ACPI_ASSERT_CMP (rsdt_table.signature,"RSDT" ); + +/* compute the table entries in rsdt */ + tables_nr = (rsdt_table.length -sizeof (AcpiRsdtDescriptorRev1)) / +sizeof (uint32_t ); + g_assert_cmpint(tables_nr, >, 0); + +/* get the addresses of the tables pointed by rsdt */ + tables =g_new0 (uint32_t, tables_nr); +ACPI_READ_ARRAY_PTR (tables, tables_nr, rsdt); + +for (i =0 ; i < tables_nr; i++) { +ACPI_READ_TABLE_HEADER (&ssdt_table, tables[i]); +if (!strncmp ((char *)ssdt_table.oem_table_id,"VMGENID" ,7 )) { +/* the first entry in the table should be VGIA +* That's all we need +*/ +ACPI_READ_FIELD (vgid_table.name_op, tables[i]); +g_assert (vgid_table.name_op ==0x08 );/* name */ +ACPI_READ_ARRAY (vgid_table.vgia, tables[i]); +g_assert (memcmp (vgid_table.vgia,"VGIA" ,4 ) ==0 ); +ACPI_READ_FIELD (vgid_table.val_op, tables[i]); +g_assert (vgid_table.val_op ==0x0C );/* dword */ +ACPI_READ_FIELD (vgid_table.vgia_val, tables[i]); +/* The GUID is written at a fixed offset into the fw_cfg file +* in order to implement the "OVMF SDT Header probe suppressor" +* see docs/specs/vmgenid.txt for more details +*/ +return vgid_table.vgia_val +VMGENID_GUID_OFFSET ; + } + } +return 0 ; +} + +static void read_guid_from_memory (QemuUUID *guid) +{ +uint32_t vmgenid_addr; +int i; + + vmgenid_addr =acpi_find_vgia (); +g_assert (vmgenid_addr); + +/* Read the GUID directly from guest memory */ +for (i =0 ; i <16 ; i++) { + guid->data[i] =readb (vmgenid_addr + i); + } +/* The GUID is in little-endian format in the guest, while QEMU +* uses big-endian. Swap after reading. +*/ +qemu_uuid_bswap (guid); +} + +static void read_guid_from_monitor (QemuUUID *guid) +{ +QDict *rsp, *rsp_ret; +const char *guid_str; + + rsp =qmp ("{ 'execute': 'query-vm-generation-id' }" ); +if (qdict_haskey (rsp,"return" )) { + rsp_ret =qdict_get_qdict (rsp,"return" ); +g_assert (qdict_haskey (rsp_ret,"guid" )); + guid_str =qdict_get_str (rsp_ret,"guid" ); +g_assert (qemu_uuid_parse (guid_str, guid) ==0 ); + } +QDECREF (rsp); +} + +static void vmgenid_test (void ) +{ +QemuUUID expected, measured; +gchar *cmd; + +g_assert (qemu_uuid_parse (VGID_GUID , &expected) ==0 ); + + cmd =g_strdup_printf ("-machine accel=tcg -device vmgenid,id=testvgid," +"guid=%s" ,VGID_GUID ); +qtest_start (cmd); + +/* Read the GUID from accessing guest memory */ +read_guid_from_memory (&measured); +g_assert (memcmp (measured.data, expected.data,sizeof (measured.data)) ==0 ); + +/* Read the GUID via the monitor */ +read_guid_from_monitor (&measured); +g_assert (memcmp (measured.data, expected.data,sizeof (measured.data)) ==0 ); + +qtest_quit (global_qtest); +g_free (cmd); +} + +static void vmgenid_set_guid_auto_test (void ) +{ +const char *cmd; +QemuUUID measured; + + cmd ="-machine accel=tcg -device vmgenid,id=testvgid," "guid=auto" ; +qtest_start (cmd); + +read_guid_from_memory (&measured); + +/* Just check that the GUID is non-null */ +g_assert (!qemu_uuid_is_null (&measured)); + +qtest_quit (global_qtest); +} + +int main (int argc,char **argv) +{ +int ret; + +g_test_init (&argc, &argv,NULL ); + +qtest_add_func ("/vmgenid/vmgenid" , vmgenid_test); +qtest_add_func ("/vmgenid/vmgenid/set-guid-auto" , + vmgenid_set_guid_auto_test); + ret =g_test_run (); + +qtest_end (); + +return ret; +}
PATCH v7 8/8 MAINTAINERS: Add VM Generation ID entry
In reply to [email protected]From: Ben Warren <[email protected]>
Also add BIOS tables entry
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -909,6 +909,7 @@ F: hw/acpi/* F: hw/smbios/* F: hw/i386/acpi-build.[hc] F: hw/arm/virt-acpi-build.c +F: tests/bios-tables-test.c ppc4xx M: Alexander Graf <[email protected]>
@@ -1123,6 +1124,13 @@ F: hw/nvram/chrp_nvram.c F: include/hw/nvram/chrp_nvram.h F: tests/prom-env-test.c +VM Generation ID +M: Ben Warren <[email protected]> +S: Maintained +F: hw/acpi/vmgenid.c +F: include/hw/acpi/vmgenid.h +F: tests/vmgenid-test.c + Subsystems ---------- Audio
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v7 8/8] MAINTAINERS: Add VM Generation ID entry
Quoted 14 lines · On 02/16/17 07:18, [email protected] wrote:
From: Ben Warren <[email protected]>
Also add BIOS tables entry
Signed-off-by Ben Warren <[email protected]>--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)MAINTAINERS +0
-0
MAINTAINERS F: hw/acpi/* · line 912
Quoted 4 lines
MAINTAINERS +1
-0@@ -909,6 +909,7 @@ F: hw/acpi/* F: hw/smbios/* F: hw/i386/acpi-build.[hc] F: hw/arm/virt-acpi-build.c +F: tests/bios-tables-test.c
(1) Please add:
tests/acpi-utils.ctests/acpi-utils.h
(2) I think this hunk belongs to
[PATCH v7 6/8] tests: Move reusable ACPI code into a utility file
or else an entirely separate patch.
Quoted 4 lines
MAINTAINERS +0
-0ppc4xx M: Alexander Graf <[email protected]>
MAINTAINERS F: hw/nvram/chrp_nvram.c · line 1133
Quoted 10 lines
MAINTAINERS +7
-0@@ -1123,6 +1124,13 @@ F: hw/nvram/chrp_nvram.c F: include/hw/nvram/chrp_nvram.h F: tests/prom-env-test.c +VM Generation ID +M: Ben Warren <[email protected]> +S: Maintained +F: hw/acpi/vmgenid.c +F: include/hw/acpi/vmgenid.h +F: tests/vmgenid-test.c +
(3) Please add:
docs/specs/vmgenid.txtstubs/vmgenid.c
With those changes, for this patch:
Thanks
Laszlo
Quoted 4 lines
MAINTAINERS +0
-0Subsystems ---------- Audio
Quoted 6 lines · On Wed, 15 Feb 2017 22:18:10 -0800 [email protected] wrote:
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_cfgblob.
Quoted 7 lines
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.
v6->v7:
- Rebased to top of tree.
- Added 'src_offset' field to "write pointer" command
Ben,
Do you plan to post updated write pointer seabios impl.?
Quoted 16 lines · Igor Mammedov
Quoted 10 lines · On Wed, 15 Feb 2017 22:18:10 -0800 [email protected] wrote:
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_cfgblob.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.
Quoted 6 lines
Quoted 3 lines
v6->v7:
- Rebased to top of tree.
- Added 'src_offset' field to "write pointer" commandBen,
Do you plan to post updated write pointer seabios impl.?
Yes, I will do so this morning (I expect within the next 4 hours). I thought I’d let you guys hash out the ‘src_offset’ issue first.
—Ben
Quoted 10 lines · On 02/16/17 07:18, [email protected] wrote:
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_cfgblob.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.
Quoted 6 lines
v6->v7:
- Rebased to top of tree.
- Added 'src_offset' field to "write pointer" command
- Reworked unit tests based on feedback
- various minor changes based on feedback
- Added entries toMAINTAINERSfile
I posted the OVMF series:
[edk2] [PATCH 0/5] OvmfPkg: support QEMU_LOADER_WRITE_POINTER
Message-Id: <[email protected]>
https://lists.01.org/pipermail/edk2-devel/2017-February/007454.html
Thanks,
Laszlo