Skip to contentSkip to conversation

Virtual Machine Generation ID

PATCH RESEND Superseded Gal Hammer 2 participants 7 messages Sep 14, 2014

v2 of 16 Superseded Latest is v16 →

lore
Share & tools
lore

Gal Hammer

author
#0 lore raw

v2 cover Virtual Machine Generation ID

Hi,

A two parts patch to add a QEmu support for Microsoft's Virtual Machine Generation ID device.

The first one add a new ACPI directive which allow to use a 16-bytes buffer in an ACPI table. This buffer is for storing the VM's UUID.

The second is the ACPI tables changes and the actual device.

Your comment are welcomed.

Thanks,

Gal.

V2: - Remove "-uuid" command line parameter.
- Move device's description from SSDT to DDST table.
- Add new "vmgenid" sysbus device.

Gal Hammer (2):
i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive.
i386: Add a Virtual Machine Generation ID device.

 default-configs/i386-softmmu.mak   |  1 +
 default-configs/x86_64-softmmu.mak |  1 +
 hw/i386/acpi-build.c               | 23 ++++++++++-
 hw/i386/acpi-dsdt.dsl              | 37 +++++++++++++++++
 hw/misc/Makefile.objs              |  1 +
 hw/misc/vmgenid.c                  | 85 ++++++++++++++++++++++++++++++++++++++
 include/hw/i386/pc.h               |  3 ++
 scripts/acpi_extract.py            | 23 +++++++----
 8 files changed, 163 insertions(+), 11 deletions(-)
 create mode 100644 hw/misc/vmgenid.c
Signature · 1 line
1.9.3
author
#1 lore raw

PATCH v2 1/2 i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive.

Add a 16-bytes buffer to allow storing a 128-bit UUID value in an ACPI table.

---
 scripts/acpi_extract.py | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
scripts/acpi_extract.py +14 -9
index 22ea468..88314fc 100755
@@ -139,13 +139,16 @@ def aml_name_string(offset):
         offset += 1
     return offset;
 
-# Given data offset, find 8 byte buffer offset
-def aml_data_buffer8(offset):
-    #0x08 NameOp NameString DataRef
-    expect = [0x11, 0x0B, 0x0A, 0x08]
+# Given data offset, find variable length byte buffer offset
+def aml_data_buffer(offset, length):
+    #0x11 PkgLength BufferSize ByteList
+    if (length > 63):
+        die( "Name offset 0x%x: expected an one byte PkgLength (length<=63)" %
+             (offset));
+    expect = [0x11, length+3, 0x0A, length]
     if (aml[offset:offset+4] != expect):
         die( "Name offset 0x%x: expected %s actual %s" %
-             (offset, aml[offset:offset+4], expect))
+             (offset, expect, aml[offset:offset+4]))
     return offset + len(expect)
 
 # Given data offset, find dword const offset
@@ -172,9 +175,9 @@ def aml_data_byte_const(offset):
              (offset, aml[offset]));
     return offset + 1;
 
-# Find name'd buffer8
-def aml_name_buffer8(offset):
-    return aml_data_buffer8(aml_name_string(offset) + 4)
+# Find name'd buffer
+def aml_name_buffer(offset, length):
+    return aml_data_buffer(aml_name_string(offset) + 4, length)
 
 # Given name offset, find dword const offset
 def aml_name_dword_const(offset):
@@ -308,7 +311,9 @@ for i in range(len(asl)):
         output[array] = aml
         continue
     if (directive == "ACPI_EXTRACT_NAME_BUFFER8"):
-        offset = aml_name_buffer8(offset)
+        offset = aml_name_buffer(offset, 8)
+    elif (directive == "ACPI_EXTRACT_NAME_BUFFER16"):
+        offset = aml_name_buffer(offset, 16)
     elif (directive == "ACPI_EXTRACT_NAME_DWORD_CONST"):
         offset = aml_name_dword_const(offset)
     elif (directive == "ACPI_EXTRACT_NAME_WORD_CONST"):
Signature · 1 line
1.9.3
Reviewed-by on v2 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive.

Il 14/09/2014 08:25, Gal Hammer ha scritto:

Quoted 15 lines

Add a 16-bytes buffer to allow storing a 128-bit UUID value in an ACPI table.

---
 scripts/acpi_extract.py | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
scripts/acpi_extract.py +0 -0
index 22ea468..88314fc 100755
@@ -139,13 +139,16 @@ def aml_name_string(offset):
         offset += 1
     return offset;

scripts/acpi_extract.py def aml_name_string(offset): · line 146

Quoted 10 lines
scripts/acpi_extract.py +5 -4
 
-# Given data offset, find 8 byte buffer offset
-def aml_data_buffer8(offset):
-    #0x08 NameOp NameString DataRef
-    expect = [0x11, 0x0B, 0x0A, 0x08]
+# Given data offset, find variable length byte buffer offset
+def aml_data_buffer(offset, length):
+    #0x11 PkgLength BufferSize ByteList
+    if (length > 63):
+        die( "Name offset 0x%x: expected an one byte PkgLength (length<=63)" %

s/an/a/

Quoted 24 lines
scripts/acpi_extract.py +6 -4
+             (offset));
+    expect = [0x11, length+3, 0x0A, length]
     if (aml[offset:offset+4] != expect):
         die( "Name offset 0x%x: expected %s actual %s" %
-             (offset, aml[offset:offset+4], expect))
+             (offset, expect, aml[offset:offset+4]))
     return offset + len(expect)
 
 # Given data offset, find dword const offset
@@ -172,9 +175,9 @@ def aml_data_byte_const(offset):
              (offset, aml[offset]));
     return offset + 1;
 
-# Find name'd buffer8
-def aml_name_buffer8(offset):
-    return aml_data_buffer8(aml_name_string(offset) + 4)
+# Find name'd buffer
+def aml_name_buffer(offset, length):
+    return aml_data_buffer(aml_name_string(offset) + 4, length)
 
 # Given name offset, find dword const offset
 def aml_name_dword_const(offset):

scripts/acpi_extract.py for i in range(len(asl)): · line 319

Quoted 10 lines
scripts/acpi_extract.py +3 -1
@@ -308,7 +311,9 @@ for i in range(len(asl)):
         output[array] = aml
         continue
     if (directive == "ACPI_EXTRACT_NAME_BUFFER8"):
-        offset = aml_name_buffer8(offset)
+        offset = aml_name_buffer(offset, 8)
+    elif (directive == "ACPI_EXTRACT_NAME_BUFFER16"):
+        offset = aml_name_buffer(offset, 16)
     elif (directive == "ACPI_EXTRACT_NAME_DWORD_CONST"):
         offset = aml_name_dword_const(offset)
     elif (directive == "ACPI_EXTRACT_NAME_WORD_CONST"):

Apart from the above grammatical nit,

Paolo

author
#3 lore raw

PATCH v2 2/2 i386: Add a Virtual Machine Generation ID device.

In reply to Gal Hammer

Based on Microsoft's sepecifications (paper can be dowloaded from
http://go.microsoft.com/fwlink/?LinkId=260709), add a device description to the DSDT ACPI table.

The GUID is set using a new "vmgenid" device.

---
 default-configs/i386-softmmu.mak   |  1 +
 default-configs/x86_64-softmmu.mak |  1 +
 hw/i386/acpi-build.c               | 23 ++++++++++-
 hw/i386/acpi-dsdt.dsl              | 37 +++++++++++++++++
 hw/misc/Makefile.objs              |  1 +
 hw/misc/vmgenid.c                  | 85 ++++++++++++++++++++++++++++++++++++++
 include/hw/i386/pc.h               |  3 ++
 7 files changed, 149 insertions(+), 2 deletions(-)
 create mode 100644 hw/misc/vmgenid.c
default-configs/i386-softmmu.mak +1 -0
index 8e08841..bd33c75 100644
@@ -45,3 +45,4 @@ CONFIG_IOAPIC=y
 CONFIG_ICC_BUS=y
 CONFIG_PVPANIC=y
 CONFIG_MEM_HOTPLUG=y
+CONFIG_VMGENID=y
default-configs/x86_64-softmmu.mak +1 -0
index 66557ac..006fc7c 100644
@@ -45,3 +45,4 @@ CONFIG_IOAPIC=y
 CONFIG_ICC_BUS=y
 CONFIG_PVPANIC=y
 CONFIG_MEM_HOTPLUG=y
+CONFIG_VMGENID=y
hw/i386/acpi-build.c +21 -2
index 85e5834..153dadc 100644
@@ -1390,15 +1390,34 @@ build_mcfg_q35(GArray *table_data, GArray *linker, AcpiMcfgInfo *info)
 static void
 build_dsdt(GArray *table_data, GArray *linker, AcpiMiscInfo *misc)
 {
-    AcpiTableHeader *dsdt;
+    int dsdt_start = table_data->len;
+    uint8_t *dsdt;
+    uint8_t *vm_gid_ptr;
+    uint32_t vm_gid_physical_address;
 
     assert(misc->dsdt_code && misc->dsdt_size);
 
     dsdt = acpi_data_push(table_data, misc->dsdt_size);
     memcpy(dsdt, misc->dsdt_code, misc->dsdt_size);
 
+    vm_gid_ptr = acpi_data_get_ptr(dsdt, misc->dsdt_size,
+                                   *dsdt_acpi_vm_gid, 16);
+    if (vm_generation_id(vm_gid_ptr)) {
+        vm_gid_physical_address = dsdt_start + *dsdt_acpi_vm_gid;
+        bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
+                                       ACPI_BUILD_TABLE_FILE,
+                                       table_data,
+                                       dsdt + *dsdt_acpi_vm_gid_addr,
+                                       sizeof(uint32_t));
+    } else {
+        vm_gid_physical_address = 0;
+    }
+
+    ACPI_BUILD_SET_LE(dsdt, misc->dsdt_size,
+                      *dsdt_acpi_vm_gid_addr, 32, vm_gid_physical_address);
+
     memset(dsdt, 0, sizeof *dsdt);
-    build_header(linker, table_data, dsdt, "DSDT",
+    build_header(linker, table_data, (AcpiTableHeader *)dsdt, "DSDT",
                  misc->dsdt_size, 1);
 }
 
hw/i386/acpi-dsdt.dsl +37 -0
index 559f4b6..9015881 100644
@@ -294,6 +294,43 @@ DefinitionBlock (
         }
     }
 
+/****************************************************************
+ * Virtual Machine Generation ID Device
+ ****************************************************************/
+    Scope(\_SB) {
+
+        Device(VMGI) {
+            Name(_HID, "QEMU0002")
+            Name(_CID, "VM_Gen_Counter")
+            Name(_DDN, "VM_Gen_Counter")
+
+            ACPI_EXTRACT_NAME_DWORD_CONST dsdt_acpi_vm_gid_addr
+            Name(VGIA, 0x12345678)
+
+            ACPI_EXTRACT_NAME_BUFFER16 dsdt_acpi_vm_gid
+            Name(VGID, Buffer(16) {
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })
+
+            Method(_STA, 0, NotSerialized) {
+                Store(VGIA, Local0)
+                If (LEqual(Local0, Zero)) {
+                    Return (0x00)
+                } Else {
+                    Return (0x0F)
+                }
+            }
+
+            Method(ADDR, 0, Serialized) {
+                Store(Package(2) { }, Local0)
+                Store(VGIA, Index(Local0, 0))
+                Store(0x0000, Index(Local0, 1))
+                return (Local0)
+            }
+        }
+    }
+
+
 #include "hw/acpi/pc-hotplug.h"
 #define CPU_STATUS_BASE PIIX4_CPU_HOTPLUG_IO_BASE
 #include "acpi-dsdt-cpu-hotplug.dsl"
hw/misc/Makefile.objs +1 -0
index 979e532..c18b800 100644
@@ -41,3 +41,4 @@ obj-$(CONFIG_SLAVIO) += slavio_misc.o
 obj-$(CONFIG_ZYNQ) += zynq_slcr.o
 
 obj-$(CONFIG_PVPANIC) += pvpanic.o
+obj-$(CONFIG_VMGENID) += vmgenid.o
hw/misc/vmgenid.c new file +85 -0

85 lines not on this page · raw message

include/hw/i386/pc.h +3 -0
index a39cb42..b21c22e 100644
@@ -290,6 +290,9 @@ void pc_system_firmware_init(MemoryRegion *rom_memory,
 /* pvpanic.c */
 uint16_t pvpanic_port(void);
 
+/* vmgenid.c */
+bool vm_generation_id(uint8_t id[16]);
+
 /* e820 types */
 #define E820_RAM        1
 #define E820_RESERVED   2
Signature · 1 line
1.9.3
#4 lore raw
In reply to Gal Hammer

Il 14/09/2014 08:25, Gal Hammer ha scritto:

Quoted 24 lines

Hi,

A two parts patch to add a QEmu support for Microsoft's Virtual Machine Generation ID device.

The first one add a new ACPI directive which allow to use a 16-bytes buffer in an ACPI table. This buffer is for storing the VM's UUID.

The second is the ACPI tables changes and the actual device.

Your comment are welcomed.

Thanks,

Gal.

V2: - Remove "-uuid" command line parameter.
- Move device's description from SSDT to DDST table.
- Add new "vmgenid" sysbus device.

Gal Hammer (2):
i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive.
i386: Add a Virtual Machine Generation ID device.

Quoted 11 lines
 default-configs/i386-softmmu.mak   |  1 +
 default-configs/x86_64-softmmu.mak |  1 +
 hw/i386/acpi-build.c               | 23 ++++++++++-
 hw/i386/acpi-dsdt.dsl              | 37 +++++++++++++++++
 hw/misc/Makefile.objs              |  1 +
 hw/misc/vmgenid.c                  | 85 ++++++++++++++++++++++++++++++++++++++
 include/hw/i386/pc.h               |  3 ++
 scripts/acpi_extract.py            | 23 +++++++----
 8 files changed, 163 insertions(+), 11 deletions(-)
 create mode 100644 hw/misc/vmgenid.c

The idea is okay, but the device has to be added to the Q35 DSDT as well. If you just #included a file in the same style as acpi-dsdt-hpet.dsl, you would have a namespace clash between the PIIX and Q35 DSDTs. acpi-dsdt-hpet.dsl can do it because it has no ACPI_EXTRACT directives.

I think because of this, it is a bit simpler to add the device optionally to the SSDT, similar to how the TPM is handled.

Paolo

author
#5 lore raw
Quoted 37 lines · Paolo Bonzini

Il 14/09/2014 08:25, Gal Hammer ha scritto:

Quoted 33 lines

Hi,

A two parts patch to add a QEmu support for Microsoft's Virtual Machine Generation ID device.

The first one add a new ACPI directive which allow to use a 16-bytes buffer in an ACPI table. This buffer is for storing the VM's UUID.

The second is the ACPI tables changes and the actual device.

Your comment are welcomed.

Thanks,

Gal.

V2: - Remove "-uuid" command line parameter.
- Move device's description from SSDT to DDST table.
- Add new "vmgenid" sysbus device.

Gal Hammer (2):
i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive.
i386: Add a Virtual Machine Generation ID device.

  default-configs/i386-softmmu.mak   |  1 +
  default-configs/x86_64-softmmu.mak |  1 +
  hw/i386/acpi-build.c               | 23 ++++++++++-
  hw/i386/acpi-dsdt.dsl              | 37 +++++++++++++++++
  hw/misc/Makefile.objs              |  1 +
  hw/misc/vmgenid.c                  | 85 ++++++++++++++++++++++++++++++++++++++
  include/hw/i386/pc.h               |  3 ++
  scripts/acpi_extract.py            | 23 +++++++----
  8 files changed, 163 insertions(+), 11 deletions(-)
Quoted 2 lines

create mode 100644 hw/misc/vmgenid.c

Quoted 8 lines

The idea is okay, but the device has to be added to the Q35 DSDT as well. If you just #included a file in the same style as acpi-dsdt-hpet.dsl, you would have a namespace clash between the PIIX and Q35 DSDTs. acpi-dsdt-hpet.dsl can do it because it has no ACPI_EXTRACT directives.

I think because of this, it is a bit simpler to add the device optionally to the SSDT, similar to how the TPM is handled.

Back to SSDT? Didn't you say something about migration issues that prevent me from using SSDT because the table's data is modified?

Quoted 3 lines

Paolo

Gal.

#6 lore raw

Il 14/09/2014 12:51, Gal Hammer ha scritto:

Quoted 6 lines
Quoted 3 lines

I think because of this, it is a bit simpler to add the device optionally to the SSDT, similar to how the TPM is handled.

Back to SSDT? Didn't you say something about migration issues that prevent me from using SSDT because the table's data is modified?

I said you have to either:

1) Use the DSDT, with a dynamic _STA method.

2) Use the SSDT, and only add the device if the device is specified on the command line. This avoids the avoid migration issues. At this point the _STA method can be static.

Using the DSDT is possible, it's just that you have to do it as well for Q35, and I think it is harder than moving it back to the SSDT. Sorry for not thinking earlier about the different chipsets.

Paolo