Virtual Machine Generation ID
v9 cover Virtual Machine Generation ID
Hi,
Resending patches after the release of version 2.2.
Please note that this patch set doesn't include the *.hex.generated files and the binary ACPI tables (make check will fail).
Thanks,
Gal.
V9 - Add a unit test.
- Rebased to version 2.2.
- Removed hex.generated the binary files from patch.
V8 - Add a device's description file.
- GUID is stored in fw cfg file and the guest writes the physical address to the device (reduces vmexits).
V7 - Move the device's description back to the static SSDT table.
- The GUID is store in a "hard coded" physical address and not in the ACPI table itself.
- ACPI notification is triggered when the GUID is changed.
V6 - include the pre-compiled ASL file
- remove an empty line at end of files.
V5 - Move device's description to SSDT table (dynamic).
V4 - Fix a typo in error message string.
- Move device's description from DSDT back to SSDT table.
V3 - Remove "-uuid" command line parameter.
- Move device's description from SSDT to DSDT table.
- Add new "vmgenid" sysbus device.
Gal Hammer (3):
docs: vm generation id device's description
i386: Add a Virtual Machine Generation ID device
tests: add a unit test for the vmgenid device.
default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + docs/specs/vmgenid.txt | 27 ++++++++++++++++++++ hw/acpi/core.c | 8 ++++++ hw/acpi/ich9.c | 8 ++++++ hw/acpi/piix4.c | 8 ++++++ hw/i386/acpi-build.c | 26 +++++++++++++++++++ hw/i386/acpi-dsdt.dsl | 4 ++- hw/i386/pc.c | 8 ++++++ hw/i386/q35-acpi-dsdt.dsl | 5 +++- hw/i386/ssdt-misc.dsl | 43 ++++++++++++++++++++++++++++++++ hw/isa/lpc_ich9.c | 1 + hw/misc/Makefile.objs | 1 + include/hw/acpi/acpi.h | 2 ++ include/hw/acpi/acpi_dev_interface.h | 4 +++ include/hw/acpi/ich9.h | 2 ++ include/hw/i386/pc.h | 3 +++ tests/Makefile | 2 ++ tests/vmgenid-test.c | 48 ++++++++++++++++++++++++++++++++++++ 19 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 docs/specs/vmgenid.txt create mode 100644 tests/vmgenid-test.c
Signature · 1 line
1.9.3
PATCH v9 1/3 docs: vm generation id device's description
--- docs/specs/vmgenid.txt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 docs/specs/vmgenid.txt
docs/specs/vmgenid.txt new file +27 -0
@@ -0,0 +1,27 @@ +VIRTUAL MACHINE GENERATION ID +============================= + +The VM generation ID (vmgenid) device is an emulated device which +expose a 128-bit, cryptographically random, integer value identifier. +This allows management applications (e.g. libvirt) to notify the guest +operating system when the virtual machine is executed with a different +configuration (e.g. snapshot execution or creation from a template). + +Specs is on the web at: http://go.microsoft.com/fwlink/?LinkId=260709 + +--- + +The vmgenid device is a sysbus device with the following ACPI ID: +"QEMU0002". + +The device adds a "vmgenid.uuid" property, which can be modifed using +the -global command line argument or the QMP interface. + +The device uses a fixed memory resource: 0xfedf0000-0xfedf0003. The +guest is expected to write the physical address of the GUID's buffer +to that memory resource. This allows the device to modify the GUID if +requested by the management application. + +According to the specification, any change to the GUID executes an +ACPI notification. The vmgenid device triggers the GPE._E00 which +executes the ACPI Notify operation.
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH V9 1/3] docs: vm generation id device's description
Quoted 13 lines · Gal Hammer
Signed-off-by Gal Hammer <[email protected]>--- docs/specs/vmgenid.txt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 docs/specs/vmgenid.txtdocs/specs/vmgenid.txt new file +0
-0
docs/specs/vmgenid.txt line 1
Quoted 1 line
docs/specs/vmgenid.txt new file +1
-0@@ -0,0 +1,27 @@ +VIRTUAL MACHINE GENERATION ID
Just because we aren't consistent doesn't mean that new files can get away with not listing a license/copyright notice. Check some of the other recent doc additions for ideas on how to do it concisely.
docs/specs/vmgenid.txt line 5
Quoted 4 lines
docs/specs/vmgenid.txt new file +4
-0+============================= + +The VM generation ID (vmgenid) device is an emulated device which +expose a 128-bit, cryptographically random, integer value identifier.
s/expose/exposes/
docs/specs/vmgenid.txt line 10
Quoted 5 lines
docs/specs/vmgenid.txt new file +5
-0+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). + +Specs is on the web at: http://go.microsoft.com/fwlink/?LinkId=260709
s/Specs is/This is specified/
docs/specs/vmgenid.txt line 17
Quoted 7 lines
docs/specs/vmgenid.txt new file +7
-0+ +--- + +The vmgenid device is a sysbus device with the following ACPI ID: +"QEMU0002". + +The device adds a "vmgenid.uuid" property, which can be modifed using
s/modifed/modified/
docs/specs/vmgenid.txt line 20
Quoted 3 lines
docs/specs/vmgenid.txt new file +3
-0+the -global command line argument or the QMP interface. + +The device uses a fixed memory resource: 0xfedf0000-0xfedf0003. The
What endianness is the memory resource? Is 4 bytes sufficient, or should it be 8 bytes because it holds a pointer? Or is the size dependent on the guest hardware?
docs/specs/vmgenid.txt line 23
Quoted 3 lines
docs/specs/vmgenid.txt new file +3
-0+guest is expected to write the physical address of the GUID's buffer +to that memory resource. This allows the device to modify the GUID if +requested by the management application.
What endianness is the GUID buffer?
Quoted 5 lines
docs/specs/vmgenid.txt new file +4
-0+ +According to the specification, any change to the GUID executes an +ACPI notification. The vmgenid device triggers the GPE._E00 which +executes the ACPI Notify operation.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH V9 1/3] docs: vm generation id device's description
----- Original Message -----
Quoted 13 lines
From: "Eric Blake" <[email protected]>
To: "Gal Hammer" <[email protected]>, [email protected]
Sent: Tuesday, December 9, 2014 7:50:07 PM
Subject: Re: [Qemu-devel] [PATCH V9 1/3] docs: vm generation id device's descriptionQuoted 7 lines · Gal Hammer
Signed-off-by Gal Hammer <[email protected]>--- docs/specs/vmgenid.txt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 docs/specs/vmgenid.txt
Quoted 11 lines
docs/specs/vmgenid.txt line 1
Quoted 7 lines
docs/specs/vmgenid.txt new file +1
-0@@ -0,0 +1,27 @@ +VIRTUAL MACHINE GENERATION IDJust because we aren't consistent doesn't mean that new files can get away with not listing a license/copyright notice. Check some of the other recent doc additions for ideas on how to do it concisely.
Most of the files in the docs/specs doesn't have a legal notice so I missed it. Fixed.
Quoted 16 lines
docs/specs/vmgenid.txt line 5
Quoted 5 lines
docs/specs/vmgenid.txt new file +4
-0+============================= + +The VM generation ID (vmgenid) device is an emulated device which +expose a 128-bit, cryptographically random, integer value identifier.s/expose/exposes/
docs/specs/vmgenid.txt line 10
Quoted 5 lines
docs/specs/vmgenid.txt new file +5
-0+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). + +Specs is on the web at: http://go.microsoft.com/fwlink/?LinkId=260709s/Specs is/This is specified/
Quoted 9 lines
docs/specs/vmgenid.txt line 17
Quoted 7 lines
docs/specs/vmgenid.txt new file +7
-0+ +--- + +The vmgenid device is a sysbus device with the following ACPI ID: +"QEMU0002". + +The device adds a "vmgenid.uuid" property, which can be modifed usings/modifed/modified/
Fixed the typos. Thanks.
Quoted 7 lines
docs/specs/vmgenid.txt line 20
Quoted 3 lines
docs/specs/vmgenid.txt new file +3
-0+the -global command line argument or the QMP interface. + +The device uses a fixed memory resource: 0xfedf0000-0xfedf0003. TheWhat endianness is the memory resource? Is 4 bytes sufficient, or should it be 8 bytes because it holds a pointer? Or is the size dependent on the guest hardware?
Current implementation allocates the GUID's buffer in a 32-bit address range so the device uses 4 LE bytes.
Quoted 5 lines
docs/specs/vmgenid.txt line 23
Quoted 3 lines
docs/specs/vmgenid.txt new file +3
-0+guest is expected to write the physical address of the GUID's buffer +to that memory resource. This allows the device to modify the GUID if +requested by the management application.What endianness is the GUID buffer?
The spec say nothing about it. I assumed it is LE.
Quoted 11 lines
docs/specs/vmgenid.txt line 27
Quoted 5 lines
docs/specs/vmgenid.txt new file +4
-0+ +According to the specification, any change to the GUID executes an +ACPI notification. The vmgenid device triggers the GPE._E00 which +executes the ACPI Notify operation.--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Thanks,
Gal.
PATCH v9 2/3 i386: Add a Virtual Machine Generation ID device
In reply to Gal HammerBased on Microsoft's sepecifications (paper can be dowloaded from
http://go.microsoft.com/fwlink/?LinkId=260709), add a device description to the SSDT ACPI table and its implementation.
The GUID is set using a global "vmgenid.uuid" parameter.
--- default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/acpi/core.c | 8 +++++++ hw/acpi/ich9.c | 8 +++++++ hw/acpi/piix4.c | 8 +++++++ hw/i386/acpi-build.c | 26 ++++++++++++++++++++++ hw/i386/acpi-dsdt.dsl | 4 +++- hw/i386/pc.c | 8 +++++++ hw/i386/q35-acpi-dsdt.dsl | 5 ++++- hw/i386/ssdt-misc.dsl | 43 ++++++++++++++++++++++++++++++++++++ hw/isa/lpc_ich9.c | 1 + hw/misc/Makefile.objs | 1 + include/hw/acpi/acpi.h | 2 ++ include/hw/acpi/acpi_dev_interface.h | 4 ++++ include/hw/acpi/ich9.h | 2 ++ include/hw/i386/pc.h | 3 +++ 16 files changed, 123 insertions(+), 2 deletions(-)
default-configs/i386-softmmu.mak +1 -0
@@ -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
@@ -45,3 +45,4 @@ CONFIG_IOAPIC=y CONFIG_ICC_BUS=y CONFIG_PVPANIC=y CONFIG_MEM_HOTPLUG=y +CONFIG_VMGENID=y
hw/acpi/core.c +8 -0
@@ -28,6 +28,8 @@#include "qapi-visit.h" #include "qapi-event.h" +#define ACPI_VM_GENERATION_ID_CHANGED_STATUS 1 +struct acpi_table_header {uint16_t _length;/* our length, not actual part of the hdr */ /* allows easier parsing for fw_cfg clients */
@@ -683,3 +685,9 @@ void acpi_update_sci(ACPIREGS *regs, qemu_irq irq) (regs->pm1.evt.en &ACPI_BITMASK_TIMER_ENABLE ) && !(pm1a_sts & ACPI_BITMASK_TIMER_STATUS)); } + +void acpi_vm_generation_id_changed (ACPIREGS *acpi_regs,qemu_irq irq) +{ + acpi_regs->gpe.sts[0 ] |=ACPI_VM_GENERATION_ID_CHANGED_STATUS ; +acpi_update_sci (acpi_regs, irq); +}
hw/acpi/ich9.c +8 -0
@@ -307,3 +307,11 @@ void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)acpi_memory_ospm_status (&s->pm.acpi_memory_hotplug, list); } + +void ich9_vm_generation_id_changed (AcpiDeviceIf *adev) +{ +ICH9LPCState *s =ICH9_LPC_DEVICE (adev); +ICH9LPCPMRegs *pm = &s->pm; + +acpi_vm_generation_id_changed (&pm->acpi_regs, pm->irq); +}
hw/acpi/piix4.c +8 -0
@@ -574,6 +574,13 @@ static void piix4_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)acpi_memory_ospm_status (&s->acpi_memory_hotplug, list); } +static void piix4_vm_generation_id_changed (AcpiDeviceIf *adev) +{ +PIIX4PMState *s =PIIX4_PM (adev); + +acpi_vm_generation_id_changed (&s->ar, s->irq); +} +static Property piix4_pm_properties[] = {DEFINE_PROP_UINT32 ("smb_io_base" , PIIX4PMState, smb_io_base,0 ),DEFINE_PROP_UINT8 (ACPI_PM_PROP_S3_DISABLED , PIIX4PMState, disable_s3,0 ),
@@ -611,6 +618,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data) hc->plug = piix4_device_plug_cb; hc->unplug_request = piix4_device_unplug_request_cb; adevc->ospm_status = piix4_ospm_status; + adevc->vm_generation_id_changed = piix4_vm_generation_id_changed; }static const TypeInfo piix4_pm_info = {
hw/i386/acpi-build.c +26 -0
@@ -251,6 +251,7 @@ static void acpi_get_pci_info(PcPciInfo *info)#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log" +#define ACPI_BUILD_VMGENID_FILE "etc/vm-generation-id" static void build_header(GArray *linker, GArray *table_data,
@@ -1062,6 +1063,8 @@ build_ssdt(GArray *table_data, GArray *linker, {MachineState *machine =MACHINE (qdev_get_machine ());uint32_t nr_mem = machine->ram_slots; +uint32_t vm_gid_physical_address; +uint32_t vm_gid_offset =0 ;unsigned acpi_cpus = guest_info->apic_id_limit;int ssdt_start = table_data->len;uint8_t *ssdt_ptr;
@@ -1090,6 +1093,21 @@ build_ssdt(GArray *table_data, GArray *linker,ACPI_BUILD_SET_LE (ssdt_ptr,sizeof (ssdp_misc_aml), ssdt_isa_pest[0 ],16 , misc->pvpanic_port); +if (vm_generation_id_set ()) { + vm_gid_physical_address = ssdt_start + ssdt_acpi_vm_gid_addr[0 ]; +bios_linker_loader_alloc (linker,ACPI_BUILD_VMGENID_FILE ,8 , true); +bios_linker_loader_add_pointer (linker,ACPI_BUILD_VMGENID_FILE , +ACPI_BUILD_TABLE_FILE , + table_data, + &vm_gid_offset, +sizeof (vm_gid_offset)); + }else { + vm_gid_physical_address =0 ; + } + +ACPI_BUILD_SET_LE (ssdt_ptr,sizeof (ssdp_misc_aml), + ssdt_acpi_vm_gid_addr[0 ],32 , vm_gid_physical_address); +ACPI_BUILD_SET_LE (ssdt_ptr,sizeof (ssdp_misc_aml), ssdt_mctrl_nr_slots[0 ],32 , nr_mem);
@@ -1484,6 +1502,7 @@ struct AcpiBuildTables {GArray *table_data;GArray *rsdp;GArray *tcpalog; +GArray *vmgenid;GArray *linker; } AcpiBuildTables;
@@ -1492,6 +1511,7 @@ static inline 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 (); }
@@ -1502,6 +1522,7 @@ static inline void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)g_array_free (tables->rsdp, mfre);g_array_free (tables->table_data, true);g_array_free (tables->tcpalog, mfre); +g_array_free (tables->vmgenid, mfre); } typedef
@@ -1784,6 +1805,11 @@ void acpi_setup(PcGuestInfo *guest_info)fw_cfg_add_file (guest_info->fw_cfg,ACPI_BUILD_TPMLOG_FILE , tables.tcpalog->data,acpi_data_len (tables.tcpalog)); +/* Add a 128-bit fw cfg file which stores the VM generation id. */ +g_array_set_size (tables.vmgenid,16 ); +fw_cfg_add_file (guest_info->fw_cfg,ACPI_BUILD_VMGENID_FILE , + tables.vmgenid->data, tables.vmgenid->len); +/* * RSDP is small so it's easy to keep it immutable, no need to * bother with ROM blobs.
hw/i386/acpi-dsdt.dsl +3 -1
@@ -306,7 +306,9 @@ DefinitionBlock ( Scope(\_GPE) { Name(_HID, "ACPI0006") - Method(_L00) { + External(\_SB.VMGI, DeviceObj) + Method(_E00) { + Notify(\_SB.VMGI, 0x80) } Method(_E01) { // PCI hotplug event
hw/i386/pc.c +8 -0
@@ -59,6 +59,7 @@#include "hw/pci/pci_host.h" #include "acpi-build.h" #include "hw/mem/pc-dimm.h" +#include "hw/misc/vmgenid.h" #include "trace.h" #include "qapi/visitor.h" #include "qapi-visit.h"
@@ -1356,6 +1357,7 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,int i;DriveInfo *fd[MAX_FD ];DeviceState *hpet =NULL ; +DeviceState *vmgenid;int pit_isa_irq =0 ;qemu_irq pit_alt_irq =NULL ;qemu_irq rtc_irq =NULL ;
@@ -1454,6 +1456,12 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi, fd[i] =drive_get (IF_FLOPPY ,0 , i); } *floppy =fdctrl_init_isa (isa_bus, fd); + + vmgenid =qdev_try_create (NULL ,VMGENID_DEVICE ); +if (vmgenid) { +qdev_init_nofail (vmgenid); +sysbus_mmio_map (SYS_BUS_DEVICE (vmgenid),0 ,VMGENID_BASE_ADDRESS ); + } }void pc_nic_init (ISABus *isa_bus,PCIBus *pci_bus)
hw/i386/q35-acpi-dsdt.dsl +4 -1
@@ -414,7 +414,10 @@ DefinitionBlock ( Scope(\_GPE) { Name(_HID, "ACPI0006") - Method(_L00) { + External(\_SB.VMGI, DeviceObj) + Method(_E00) + { + Notify(\_SB.VMGI, 0x80) } Method(_L01) { }
hw/i386/ssdt-misc.dsl +43 -0
53 lines not on this page · raw message
hw/isa/lpc_ich9.c +1 -0
@@ -678,6 +678,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) hc->plug = ich9_device_plug_cb; hc->unplug_request = ich9_device_unplug_request_cb; adevc->ospm_status = ich9_pm_ospm_status; + adevc->vm_generation_id_changed = ich9_vm_generation_id_changed; }static const TypeInfo ich9_lpc_info = {
hw/misc/Makefile.objs +1 -0
@@ -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
include/hw/acpi/acpi.h +2 -0
@@ -185,4 +185,6 @@ unsigned acpi_table_len(void *current);void acpi_table_add (const QemuOpts *opts,Error **errp);void acpi_table_add_builtin (const QemuOpts *opts,Error **errp); +void acpi_vm_generation_id_changed (ACPIREGS *acpi_regs,qemu_irq irq); +#endif /* !QEMU_HW_ACPI_H */
include/hw/acpi/acpi_dev_interface.h +4 -0
@@ -28,6 +28,9 @@ typedef struct AcpiDeviceIf {* ospm_status: returns status of ACPI device objects, reported * via _OST method if device supports it. * +* vm_generation_id_changed: notify the guest that it generation +* id was changed. +* * Interface is designed for providing unified interface * to generic ACPI functionality that could be used without * knowledge about internals of actual device that implements
@@ -39,5 +42,6 @@ typedef struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev,ACPIOSTInfoList ***list); + void (*vm_generation_id_changed)(AcpiDeviceIf *adev); } AcpiDeviceIfClass;#endif
include/hw/acpi/ich9.h +2 -0
@@ -61,4 +61,6 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp);void ich9_pm_device_plug_cb (ICH9LPCPMRegs *pm,DeviceState *dev,Error **errp);void ich9_pm_ospm_status (AcpiDeviceIf *adev,ACPIOSTInfoList ***list); + +void ich9_vm_generation_id_changed (AcpiDeviceIf *adev);#endif /* HW_ACPI_ICH9_H */
include/hw/i386/pc.h +3 -0
@@ -298,6 +298,9 @@ void pc_system_firmware_init(MemoryRegion *rom_memory,/* pvpanic.c */ uint16_t pvpanic_port (void ); +/* vmgenid.c */ +bool vm_generation_id_set (void ); +/* e820 types */ #define E820_RAM 1#define E820_RESERVED 2
Signature · 1 line
1.9.3
PATCH v9 3/3 tests: add a unit test for the vmgenid device.
In reply to Gal Hammer--- tests/Makefile | 2 ++ tests/vmgenid-test.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 tests/vmgenid-test.c
tests/Makefile +2 -0
@@ -64,6 +64,7 @@ gcov-files-check-qom-interface-y = qom/object.c check-unit-$(CONFIG_POSIX) += tests/test-vmstate$(EXESUF) check-unit-y += tests/test-qemu-opts$(EXESUF) gcov-files-test-qemu-opts-y = qom/test-qemu-opts.c +check-qtest-i386-y += tests/vmgenid-test$(EXESUF) check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
@@ -351,6 +352,7 @@ tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y) tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o $(qtest-obj-y) tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a libqemustub.a +tests/vmgenid-test$(EXESUF): tests/vmgenid-test.o ifeq ($(CONFIG_POSIX),y) LIBS += -lutil
tests/vmgenid-test.c new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
1.9.3