From nobody Tue Apr 30 01:51:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486286080614598.7415298415301; Sun, 5 Feb 2017 01:14:40 -0800 (PST) Received: from localhost ([::1]:42338 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIu6-0003g0-Ml for importer@patchew.org; Sun, 05 Feb 2017 04:14:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59505) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIsB-0002XD-Fx for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1caIs9-0001r1-2W for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:39 -0500 Received: from mail-pg0-x230.google.com ([2607:f8b0:400e:c05::230]:35453) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1caIs8-0001qt-RT for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:36 -0500 Received: by mail-pg0-x230.google.com with SMTP id 194so19475546pgd.2 for ; Sun, 05 Feb 2017 01:12:36 -0800 (PST) Received: from Arrow.corp.skyportsystems.com (76-236-31-201.lightspeed.sntcca.sbcglobal.net. [76.236.31.201]) by smtp.gmail.com with ESMTPSA id s24sm2347127pgo.25.2017.02.05.01.12.35 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 05 Feb 2017 01:12:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=joPDF3ldFJxA+MN8QNB75ZwyZ92cdD5gqXD+eA1qXnk=; b=K+9GXY4eohz67IxxEaoIa2Tcvcf9NxWUOwGZiZCGIQCm6sNAHOkWraBKB8Kn6pxSXm dLAQoRuKdptGu1WGCjQ1gtk1ch5a9gP9uCoMPU7q9Vbv0wYXwkVc+6784BrrcHIfiVGV PCBWNvUb6TkQ69092XqmQFpr+qR0YpSMiGj6A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=joPDF3ldFJxA+MN8QNB75ZwyZ92cdD5gqXD+eA1qXnk=; b=XnQWd5JUpRuhtaz5Rv9Okt64KWLq7JJx0iUdafnOHOYicH0PzURS68aOCuASrlI2Vs GwG4e7F/OOthoyXGxMwCYe5omeSk5zfziJ+BVJO8sSviB6DBuEyfiNbPjqDMXH4JenA9 4Szpy1wAQFiZdiC2I2iajyEP92V0Sgagqq4inQMuk97CF+F9MM0IW1RpbYfSFvomeDv0 II7CV5fA35hyRxZApZHXol7jz/KrB57ehYcQY5hSlJzquK+tm7vBGi6uS6oiNjYtxoI+ 6SbTj4AQQVsw1lfSzMx9k3m1LXnR72q6yIybKdhTopsiIy81d8uZM6n+4kT1aOn8dVoz FvDA== X-Gm-Message-State: AIkVDXL/mSjN+WkeYPOhiLU9FMXGLIkYfckb/l8kQ2H0exPCSHEVFRXV/+3PeBnWfozi2tf+ X-Received: by 10.99.101.131 with SMTP id z125mr6806049pgb.218.1486285956035; Sun, 05 Feb 2017 01:12:36 -0800 (PST) From: ben@skyportsystems.com To: qemu-devel@nongnu.org Date: Sun, 5 Feb 2017 01:11:56 -0800 Message-Id: X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::230 Subject: [Qemu-devel] [PATCH v5 01/10] ACPI: Add a function for building named qword entries X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: imammedo@redhat.com, lersek@redhat.com, Ben Warren , mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ben Warren This is initially used to patch a 64-bit address into the VM Generation ID SSDT Signed-off-by: Ben Warren --- hw/acpi/aml-build.c | 35 +++++++++++++++++++++++++++++++++++ include/hw/acpi/aml-build.h | 4 ++++ 2 files changed, 39 insertions(+) diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index b2a1e40..9fc54c9 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -264,6 +264,9 @@ static void build_append_int(GArray *table, uint64_t va= lue) * Warning: runtime patching is best avoided. Only use this as * a replacement for DataTableRegion (for guests that don't * support it). + * + * ACPI 5.0: 19.2.5 + * 32-bit integers are supported beginning with ACPI 1.0 */ int build_append_named_dword(GArray *array, const char *name_format, ...) @@ -285,6 +288,38 @@ build_append_named_dword(GArray *array, const char *na= me_format, ...) return offset; } =20 +/* + * Build NAME(XXXX, 0x0000000000000000) where 0x0000000000000000 + * is encoded as a qword, and return the offset to 0x0000000000000000 + * for runtime patching. + * + * Warning: runtime patching is best avoided. Only use this as + * a replacement for DataTableRegion (for guests that don't + * support it). + * + * ACPI 5.0: 19.2.5 + * 64-bit integers are supported beginning with ACPI 2.0 + */ +int +build_append_named_qword(GArray *array, const char *name_format, ...) +{ + int offset; + va_list ap; + + build_append_byte(array, 0x08); /* NameOp */ + va_start(ap, name_format); + build_append_namestringv(array, name_format, ap); + va_end(ap); + + build_append_byte(array, 0x0E); /* QWordPrefix */ + + offset =3D array->len; + build_append_int_noprefix(array, 0x0000000000000000, 8); + assert(array->len =3D=3D offset + 8); + + return offset; +} + static GPtrArray *alloc_list; =20 static Aml *aml_alloc(void) diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index 559326c..dbf63cf 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -385,6 +385,10 @@ int build_append_named_dword(GArray *array, const char *name_format, ...) GCC_FMT_ATTR(2, 3); =20 +int +build_append_named_qword(GArray *array, const char *name_format, ...) +GCC_FMT_ATTR(2, 3); + void build_srat_memory(AcpiSratMemoryAffinity *numamem, uint64_t base, uint64_t len, int node, MemoryAffinityFlags flags); =20 --=20 2.7.4 From nobody Tue Apr 30 01:51:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486286081655439.96433208468363; Sun, 5 Feb 2017 01:14:41 -0800 (PST) Received: from localhost ([::1]:42339 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIu8-0003gX-49 for importer@patchew.org; Sun, 05 Feb 2017 04:14:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIsB-0002XH-IP for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1caIsA-0001rE-0G for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:39 -0500 Received: from mail-pg0-x230.google.com ([2607:f8b0:400e:c05::230]:36566) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1caIs9-0001r7-Nw for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:37 -0500 Received: by mail-pg0-x230.google.com with SMTP id v184so19465480pgv.3 for ; Sun, 05 Feb 2017 01:12:37 -0800 (PST) Received: from Arrow.corp.skyportsystems.com (76-236-31-201.lightspeed.sntcca.sbcglobal.net. [76.236.31.201]) by smtp.gmail.com with ESMTPSA id s24sm2347127pgo.25.2017.02.05.01.12.36 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 05 Feb 2017 01:12:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=nsYOgJEk5Q7DoHHoAkRm82k051xS4ae1NPDI/QL70m4=; b=jejbGUOx63xpGFbneUyRsMq37JMAa11xn+zeFNKmfnWqO5To8wltbWqih2FAxbsoZk /QteIMHE6AHPbUxN3SzrAclhidAryCU+L5+Bd4OEb3+/d4x7G+a/bPhfBR7dgXazqxD9 pnCwOuqAEunMM/0x/9/xKlmVGCDxvcdBvZ7TY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=nsYOgJEk5Q7DoHHoAkRm82k051xS4ae1NPDI/QL70m4=; b=BamhVtYERL03zSBKMLeKLRE7tDDxHA8w/ZWp0X6Mx6lMR2OsLXIu/Jnwg22wf7A10X dDzgiLZzQYZKgIdoNdCmIPZWkyz/Cfvz4dfkIpUgGWij1s+mXllDzi1nMGP5RCGIyO50 AO4q3yP5yI2J1A+uGRe0zdRw52yNR/Tomf6a+Mqd5m24CheCa8KIwTONiN0nWdXpKVZL VKi/dUgPb5XhcdVFYmmrfoq69rIYt6smvGJFVQOqdqFJZDdyjJmCBrT1jWpdc6bD2npx XSl/Fvekirbf/egqESH/tgatO4WGMkP4h3sMdQfAKnB1j38Y51UoE8kC7Cr9yC/yB1Zj WQyg== X-Gm-Message-State: AIkVDXI5IuG/AHQWLoseVolq+cJwm/Q89ehKf1EiUPOEg72WMd96yaJ3MSMgHBHMS/IgEp/g X-Received: by 10.98.75.16 with SMTP id y16mr6839350pfa.23.1486285956944; Sun, 05 Feb 2017 01:12:36 -0800 (PST) From: ben@skyportsystems.com To: qemu-devel@nongnu.org Date: Sun, 5 Feb 2017 01:11:57 -0800 Message-Id: <2bb2dd455ea355b279867a312924add82ae685e4.1486285434.git.ben@skyportsystems.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::230 Subject: [Qemu-devel] [PATCH v5 02/10] linker-loader: Add new 'write pointer' command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: imammedo@redhat.com, lersek@redhat.com, Ben Warren , mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ben Warren This adds to the existing 'add pointer' functionality in that it instructs the guest (BIOS or UEFI) to not patch memory but to instead write the changes back to QEMU via a writeable fw_cfg file. Signed-off-by: Ben Warren --- hw/acpi/aml-build.c | 2 +- hw/acpi/bios-linker-loader.c | 35 ++++++++++++++++++++++++--------= --- hw/acpi/nvdimm.c | 2 +- hw/arm/virt-acpi-build.c | 4 ++-- hw/i386/acpi-build.c | 8 ++++---- include/hw/acpi/bios-linker-loader.h | 3 ++- 6 files changed, 34 insertions(+), 20 deletions(-) diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index 9fc54c9..03b6c6c 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -1626,7 +1626,7 @@ build_rsdt(GArray *table_data, BIOSLinker *linker, GA= rray *table_offsets, /* rsdt->table_offset_entry to be filled by Guest linker */ bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, rsdt_entry_offset, rsdt_entry_size, - ACPI_BUILD_TABLE_FILE, ref_tbl_offset); + ACPI_BUILD_TABLE_FILE, ref_tbl_offset, false); } build_header(linker, table_data, (void *)rsdt, "RSDT", rsdt_len, 1, oem_id, oem_table_id); diff --git a/hw/acpi/bios-linker-loader.c b/hw/acpi/bios-linker-loader.c index d963ebe..e46bc29 100644 --- a/hw/acpi/bios-linker-loader.c +++ b/hw/acpi/bios-linker-loader.c @@ -52,10 +52,13 @@ struct BiosLinkerLoaderEntry { } alloc; =20 /* - * COMMAND_ADD_POINTER - patch the table (originating from - * @dest_file) at @pointer.offset, by adding a pointer to the table + * COMMAND_ADD_POINTER & + * COMMAND_WRITE_POINTER - patch guest memory (originating from + * @dest_file) at @pointer.offset, by adding a pointer to the memo= ry * originating from @src_file. 1,2,4 or 8 byte unsigned * addition is used depending on @pointer.size. + * Instead of patching memory, COMMAND_WRITE_POINTER writes the ch= anges + * to @dest_file in QEMU via fw_cfg DMA. */ struct { char dest_file[BIOS_LINKER_LOADER_FILESZ]; @@ -85,9 +88,10 @@ struct BiosLinkerLoaderEntry { typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry; =20 enum { - BIOS_LINKER_LOADER_COMMAND_ALLOCATE =3D 0x1, - BIOS_LINKER_LOADER_COMMAND_ADD_POINTER =3D 0x2, - BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM =3D 0x3, + BIOS_LINKER_LOADER_COMMAND_ALLOCATE =3D 0x1, + BIOS_LINKER_LOADER_COMMAND_ADD_POINTER =3D 0x2, + BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM =3D 0x3, + BIOS_LINKER_LOADER_COMMAND_WRITE_POINTER =3D 0x4, }; =20 enum { @@ -242,13 +246,15 @@ void bios_linker_loader_add_checksum(BIOSLinker *link= er, const char *file_name, * @src_offset: location within source file blob to which * @dest_file+@dst_patched_offset will point to after * firmware's executed ADD_POINTER command + * @write_back: guest should write change contents back to QEMU after patc= hing */ void bios_linker_loader_add_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) + uint32_t src_offset, + bool write_back) { uint64_t le_src_offset; BiosLinkerLoaderEntry entry; @@ -257,8 +263,11 @@ void bios_linker_loader_add_pointer(BIOSLinker *linker, const BiosLinkerFileEntry *source_file =3D bios_linker_find_file(linker, src_file); =20 - assert(dst_patched_offset < dst_file->blob->len); - assert(dst_patched_offset + dst_patched_size <=3D dst_file->blob->len); + /* dst_file need not exist if writing back */ + if (!write_back) { + assert(dst_patched_offset < dst_file->blob->len); + assert(dst_patched_offset + dst_patched_size <=3D dst_file->blob->= len); + } assert(src_offset < source_file->blob->len); =20 memset(&entry, 0, sizeof entry); @@ -266,15 +275,19 @@ void bios_linker_loader_add_pointer(BIOSLinker *linke= r, sizeof entry.pointer.dest_file - 1); strncpy(entry.pointer.src_file, src_file, sizeof entry.pointer.src_file - 1); - entry.command =3D cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_POINTER); + entry.command =3D cpu_to_le32(write_back ? + BIOS_LINKER_LOADER_COMMAND_WRITE_POINTER : + BIOS_LINKER_LOADER_COMMAND_ADD_POINTER); entry.pointer.offset =3D cpu_to_le32(dst_patched_offset); entry.pointer.size =3D dst_patched_size; assert(dst_patched_size =3D=3D 1 || dst_patched_size =3D=3D 2 || dst_patched_size =3D=3D 4 || dst_patched_size =3D=3D 8); =20 le_src_offset =3D cpu_to_le64(src_offset); - memcpy(dst_file->blob->data + dst_patched_offset, - &le_src_offset, dst_patched_size); + if (!write_back) { + memcpy(dst_file->blob->data + dst_patched_offset, + &le_src_offset, dst_patched_size); + } =20 g_array_append_vals(linker->cmd_blob, &entry, sizeof entry); } diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c index 8e7d6ec..175996e 100644 --- a/hw/acpi/nvdimm.c +++ b/hw/acpi/nvdimm.c @@ -1266,7 +1266,7 @@ static void nvdimm_build_ssdt(GArray *table_offsets, = GArray *table_data, sizeof(NvdimmDsmIn), false /* high memory */); bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, mem_addr_offset, sizeof(uint32_t), - NVDIMM_DSM_MEM_FILE, 0); + NVDIMM_DSM_MEM_FILE, 0, false); build_header(linker, table_data, (void *)(table_data->data + nvdimm_ssdt), "SSDT", table_data->len - nvdimm_ssdt, 1, NULL, "NVDIMM"); diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 07a10ac..a13f40d 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -380,7 +380,7 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsi= gned rsdt_tbl_offset) /* Address to be filled by Guest linker */ bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE, rsdt_pa_offset, rsdt_pa_size, - ACPI_BUILD_TABLE_FILE, rsdt_tbl_offset); + ACPI_BUILD_TABLE_FILE, rsdt_tbl_offset, false); =20 /* Checksum to be filled by Guest linker */ bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, @@ -684,7 +684,7 @@ static void build_fadt(GArray *table_data, BIOSLinker *= linker, /* DSDT address to be filled by Guest linker */ bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, dsdt_entry_offset, sizeof(fadt->dsdt), - ACPI_BUILD_TABLE_FILE, dsdt_tbl_offset); + ACPI_BUILD_TABLE_FILE, dsdt_tbl_offset, false); =20 build_header(linker, table_data, (void *)fadt, "FACP", sizeof(*fadt), 5, NULL, NULL); diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 1c928ab..78a1d84 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -319,13 +319,13 @@ build_fadt(GArray *table_data, BIOSLinker *linker, Ac= piPmInfo *pm, /* FACS address to be filled by Guest linker */ bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, fw_ctrl_offset, sizeof(fadt->firmware_ctrl), - ACPI_BUILD_TABLE_FILE, facs_tbl_offset); + ACPI_BUILD_TABLE_FILE, facs_tbl_offset, false); =20 /* DSDT address to be filled by Guest linker */ fadt_setup(fadt, pm); bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, dsdt_entry_offset, sizeof(fadt->dsdt), - ACPI_BUILD_TABLE_FILE, dsdt_tbl_offset); + ACPI_BUILD_TABLE_FILE, dsdt_tbl_offset, false); =20 build_header(linker, table_data, (void *)fadt, "FACP", sizeof(*fadt), 1, oem_id, oem_table= _id); @@ -2262,7 +2262,7 @@ build_tpm_tcpa(GArray *table_data, BIOSLinker *linker= , GArray *tcpalog) /* log area start address to be filled by Guest linker */ bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, log_addr_offset, log_addr_size, - ACPI_BUILD_TPMLOG_FILE, 0); + ACPI_BUILD_TPMLOG_FILE, 0, false); =20 build_header(linker, table_data, (void *)tcpa, "TCPA", sizeof(*tcpa), 2, NULL, NULL); @@ -2552,7 +2552,7 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, un= signed rsdt_tbl_offset) /* Address to be filled by Guest linker */ bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE, rsdt_pa_offset, rsdt_pa_size, - ACPI_BUILD_TABLE_FILE, rsdt_tbl_offset); + ACPI_BUILD_TABLE_FILE, rsdt_tbl_offset, false); =20 /* Checksum to be filled by Guest linker */ bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, diff --git a/include/hw/acpi/bios-linker-loader.h b/include/hw/acpi/bios-li= nker-loader.h index fa1e5d1..d97e39d 100644 --- a/include/hw/acpi/bios-linker-loader.h +++ b/include/hw/acpi/bios-linker-loader.h @@ -24,7 +24,8 @@ void bios_linker_loader_add_pointer(BIOSLinker *linker, uint32_t dst_patched_offset, uint8_t dst_patched_size, const char *src_file, - uint32_t src_offset); + uint32_t src_offset, + bool write_back); =20 void bios_linker_loader_cleanup(BIOSLinker *linker); #endif --=20 2.7.4 From nobody Tue Apr 30 01:51:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486286083636530.899346591479; Sun, 5 Feb 2017 01:14:43 -0800 (PST) Received: from localhost ([::1]:42340 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIuA-0003iX-Ay for importer@patchew.org; Sun, 05 Feb 2017 04:14:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59531) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIsC-0002Xt-N0 for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1caIsB-0001rT-7c for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:40 -0500 Received: from mail-pf0-x231.google.com ([2607:f8b0:400e:c00::231]:36734) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1caIsA-0001rK-Us for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:39 -0500 Received: by mail-pf0-x231.google.com with SMTP id 189so16301300pfu.3 for ; Sun, 05 Feb 2017 01:12:38 -0800 (PST) Received: from Arrow.corp.skyportsystems.com (76-236-31-201.lightspeed.sntcca.sbcglobal.net. [76.236.31.201]) by smtp.gmail.com with ESMTPSA id s24sm2347127pgo.25.2017.02.05.01.12.37 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 05 Feb 2017 01:12:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=b0E0bi8kJG8G5JOD4X2S7+gE4xj8RUCNVJVz3lMgcuo=; b=LKFtaROoc6kGLN2A5qYbbSbDoeRbSQP0kFanCrwn9NWxZmoDHQeWxV4vWqZmmlLLOJ bwvrsOBgGpNvv+sYNGl79YLEFXuV+zek76Zs9kMZb8zV6vo9YPQ/Q/7BN99I0cr0Y+Xs 7YGxhT7d2y87tO1SzxJqIocV7GPxWCy7eeLb4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=b0E0bi8kJG8G5JOD4X2S7+gE4xj8RUCNVJVz3lMgcuo=; b=sjve7rO51vn3WhZbPphpTnjh4uncWfbRlScBVkKZoMvZO5C/+5H+56gv/dtVdI/tcc d8y4zzVxxGyZi7bIVDIW1M2e0jux0yPdxqednrj3jKhoMnKW0btYclFvk/jmxDliHUrw QJFxlNVqC8odrIsEYlpGfWwdBjuLAiuW0ytcRKzh3B16F66ZC4D3t5suSzdlMMDOk1Qh Szv9D4qLkolaLRZQsViG1b+CXabNbfRZe3Cjl/cALLnmRXAK8P7IwyfOL1aJd+2FY08T aAm6XDc6eCMhPVGfvzTsD27AiHd+HZRu2WylHffTLalPn3Hz6ASxgX8L7bpVsLowme+P GxWA== X-Gm-Message-State: AIkVDXLcJeELnL+5uvTPc/NxDZYJ8bHqk06Gy+i8Y5yk1Gchc7nsScLgxzsNcTQMtmjWvscE X-Received: by 10.98.90.196 with SMTP id o187mr6780846pfb.30.1486285958018; Sun, 05 Feb 2017 01:12:38 -0800 (PST) From: ben@skyportsystems.com To: qemu-devel@nongnu.org Date: Sun, 5 Feb 2017 01:11:58 -0800 Message-Id: <9a2d2cb01e42d6e61c6198356781dbb2919aca05.1486285434.git.ben@skyportsystems.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::231 Subject: [Qemu-devel] [PATCH v5 03/10] docs: VM Generation ID device description X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gal Hammer , imammedo@redhat.com, lersek@redhat.com, Ben Warren , mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ben Warren This patch is based off an earlier version by Gal Hammer (ghammer@redhat.com) Requirements section, ASCII diagrams and overall help provided by Laszlo Ersek (lersek@redhat.com) Signed-off-by: Gal Hammer Signed-off-by: Ben Warren Reviewed-by: Laszlo Ersek --- docs/specs/vmgenid.txt | 239 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 239 insertions(+) create mode 100644 docs/specs/vmgenid.txt diff --git a/docs/specs/vmgenid.txt b/docs/specs/vmgenid.txt new file mode 100644 index 0000000..d36f8bd --- /dev/null +++ b/docs/specs/vmgenid.txt @@ -0,0 +1,239 @@ +VIRTUAL MACHINE GENERATION ID +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D + +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. + +=3D=3D=3D + +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=3D260709 + +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 d= evice + 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 generati= on 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 t= able +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 =3D 0x0F + If ((VGIA =3D=3D Zero)) + { + Local0 =3D Zero + } + + Return (Local0) + } + + Method (ADDR, 0, NotSerialized) + { + Local0 =3D Package (0x02) {} + Index (Local0, Zero) =3D (VGIA + 0x28) + Index (Local0, One) =3D Zero + Return (Local0) + } + } + } + + Method (\_GPE._E05, 0, NotSerialized) // _Exx: Edge-Triggered GPE + { + Notify (\_SB.VGEN, 0x80) // Status Change + } +} + + +Design Details: +--------------- + +Requirements R1a through R1e dicate that the memory holding the +VM Generation ID must be allocated and owned by the guest operating system, +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 in-memory data structures that are visible to both QEMU and gues= ts, +and are addressable as files. + +Two fw_cfg blobs are used in this case: + +/etc/vmgenid - contains the actual VM Generation ID GUID + - read-only to the guest +/etc/vmgenid_addr - contains the address of the GUID + - writeable by the guest + + +QEMU sends the following commands to the guest at startup: + +1. Allocate memory for vmgenid fw_cfg blob. +2. Write the address of vmgenid 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 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 at will. + +Since BIOS or UEFI does not necessarily run when we wish to change the GUI= D, +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 vmge= nid +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 work with OVMF "SDT Header Probe Supressor", the contents of +the vmgenid 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 =3D VMGENID | ++----------------------------------+ +| ... | TOP OF PAGE +| VGIA dword object ---------------|-----> +---------------------------+ +| ... | | fw-allocated array for | +| _STA method referring to VGIA | | "etc/vmgenid" | +| ... | +---------------------------+ +| 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 can be set using the command line +argument or the QMP interface: + + 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=3D"324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87" + +Or to change guid in runtime use: + + set-vm-generation-id guid=3D124e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87 + set-vm-generation-id guid=3Dauto --=20 2.7.4 From nobody Tue Apr 30 01:51:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486286353954766.783740300581; Sun, 5 Feb 2017 01:19:13 -0800 (PST) Received: from localhost ([::1]:42361 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIyW-0007MI-IA for importer@patchew.org; Sun, 05 Feb 2017 04:19:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59525) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIsC-0002Xl-GS for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1caIsB-0001ro-M8 for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:40 -0500 Received: from mail-pf0-x235.google.com ([2607:f8b0:400e:c00::235]:34228) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1caIsB-0001rN-Gf for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:39 -0500 Received: by mail-pf0-x235.google.com with SMTP id e4so16279791pfg.1 for ; Sun, 05 Feb 2017 01:12:39 -0800 (PST) Received: from Arrow.corp.skyportsystems.com (76-236-31-201.lightspeed.sntcca.sbcglobal.net. [76.236.31.201]) by smtp.gmail.com with ESMTPSA id s24sm2347127pgo.25.2017.02.05.01.12.38 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 05 Feb 2017 01:12:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=ab1Aa6q2F9IHHoYFtt22CK8eMd0tVJuwdIj8VDtWW+Q=; b=SeGEcRVbsQe+y4SWqlkMSlhDIfnzao1bbVtWO7LNEyX8SDfbrIohoAVYifE/HLmOFU VfvhXfEFXb4lMheBBrEG3HfCW1tkcVOv69MMLqJTZlk07OIepG+9DOsyv9693F9NoUxl o7e8d7QDnlqPn2Rx0ryH1V01X3SxCjbw9foIg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=ab1Aa6q2F9IHHoYFtt22CK8eMd0tVJuwdIj8VDtWW+Q=; b=FsBtLoH4V2SSsYCFDtpWZTsWxzIwowwmlRpnu5W3RPe/MWqoZ4QO2VRooW6GOT6zaw vdfsO73V3pIZbZxy/0AXL2tOL6IyxKO4wJJfsgzvhQ3uTHbvWVjZb+mmxiwcCMlwcfX6 K7I3aI78rc6srJHhBlsSO/ZX3hmErZM7gYSB5A6EAkIjwQhW7b7ytR+GTf9eTPdeHWJ5 EaDyFGr9/zyhgEDJLSzcvZHptV3YAl1HBhMa0d/2PiM9e00+X8WheQna3Go4Ms5QBQ/s 8Juagn9fJWbgwo0O4kkeRxhl6jKsQ0p3l79qeM6un8ykJH9u7oeN1WmTIj+GWz7FCE95 4XRg== X-Gm-Message-State: AIkVDXLkN7ycB10XGo5xk8Y1oiGEfp7MaxSMK2Z0ezCTWgPUj3COlrnkSMg81Qrjb9RZfduk X-Received: by 10.99.7.151 with SMTP id 145mr6798737pgh.121.1486285958735; Sun, 05 Feb 2017 01:12:38 -0800 (PST) From: ben@skyportsystems.com To: qemu-devel@nongnu.org Date: Sun, 5 Feb 2017 01:11:59 -0800 Message-Id: <91b9bb30a86d2b303bab813f7f5ad361810c3149.1486285434.git.ben@skyportsystems.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::235 Subject: [Qemu-devel] [PATCH v5 04/10] ACPI: Add vmgenid storage entries to the build tables X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: imammedo@redhat.com, lersek@redhat.com, Ben Warren , mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ben Warren This allows them to be centrally initialized and destroyed Signed-off-by: Ben Warren Reviewed-by: Laszlo Ersek --- hw/acpi/aml-build.c | 2 ++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 3 insertions(+) diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index 03b6c6c..0f39eaf 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -1594,6 +1594,7 @@ void acpi_build_tables_init(AcpiBuildTables *tables) tables->rsdp =3D g_array_new(false, true /* clear */, 1); tables->table_data =3D g_array_new(false, true /* clear */, 1); tables->tcpalog =3D g_array_new(false, true /* clear */, 1); + tables->vmgenid =3D g_array_new(false, true /* clear */, 1); tables->linker =3D bios_linker_loader_init(); } =20 @@ -1603,6 +1604,7 @@ void acpi_build_tables_cleanup(AcpiBuildTables *table= s, 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); } =20 /* Build rsdt table */ diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index dbf63cf..6f4e239 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -210,6 +210,7 @@ struct AcpiBuildTables { GArray *table_data; GArray *rsdp; GArray *tcpalog; + GArray *vmgenid; BIOSLinker *linker; } AcpiBuildTables; =20 --=20 2.7.4 From nobody Tue Apr 30 01:51:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486286139930916.9722568156102; Sun, 5 Feb 2017 01:15:39 -0800 (PST) Received: from localhost ([::1]:42343 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIv4-0004UQ-Gn for importer@patchew.org; Sun, 05 Feb 2017 04:15:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIsE-0002Z4-GA for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1caIsC-0001s9-Nc for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:42 -0500 Received: from mail-pg0-x230.google.com ([2607:f8b0:400e:c05::230]:36567) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1caIsC-0001rs-Fb for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:40 -0500 Received: by mail-pg0-x230.google.com with SMTP id v184so19465631pgv.3 for ; Sun, 05 Feb 2017 01:12:40 -0800 (PST) Received: from Arrow.corp.skyportsystems.com (76-236-31-201.lightspeed.sntcca.sbcglobal.net. [76.236.31.201]) by smtp.gmail.com with ESMTPSA id s24sm2347127pgo.25.2017.02.05.01.12.38 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 05 Feb 2017 01:12:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=k510d86ygum2Y+PLTMGCjKa2+6iD1ZQWbJghGI9B8hY=; b=rZjuI9zhcxSZ0tgEbxxWEW2kfN7IrExfYmEd6qL1Nej/7tupAcmJsDOw4YR325eB5R nsEAO7tnqYOKQwldKW8pHGlfmSywD7VF7fFHp1VuNY23kUA4Ifi3WQNDoStakRntt4Bi NZQiT/YWPyPuExnAip+ESqkcjPy+5VsxERas4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=k510d86ygum2Y+PLTMGCjKa2+6iD1ZQWbJghGI9B8hY=; b=OYADGpjqp37AQelKeb5Znja1alpsViH9sLIfBK91wXrTu9aoKmBRd1wUjsiCdesy4l E7Gaz1aBuHOPvYASQTh7Q+DoC/fkVMoFfutYXkckk4GDCxM/PFcoqFVYoJ6VIsNA5u0t F6oaa9k6+/EUWmr58Xa7gXdfHFwJ2Go0A+B1n8tItMFQ8KCF2qv3iITN3gw6s+CY+MvE OPnpmfnSni8xT3xr0qk9XBtlMVtuMFT3gpsf/salMytCUb1mwNNIb8aRRDXkx71RRlPp LQl9opj4uc5UUNpQcVwzNbFkjQYfh5epuA/AE+1yop0990i9EJKdfYGJHQKJleQ/dDnU oD/w== X-Gm-Message-State: AIkVDXIH99lmeN0bnn7ggJk6UbJKeKCxY3rCuw8bwtLiiRh4YkDcw0IKjPRY1Qtvkurzc9ea X-Received: by 10.99.100.70 with SMTP id y67mr6823314pgb.74.1486285959653; Sun, 05 Feb 2017 01:12:39 -0800 (PST) From: ben@skyportsystems.com To: qemu-devel@nongnu.org Date: Sun, 5 Feb 2017 01:12:00 -0800 Message-Id: <28ff6ff023dd041fc7557955dea916adce72efea.1486285434.git.ben@skyportsystems.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::230 Subject: [Qemu-devel] [PATCH v5 05/10] ACPI: Add Virtual Machine Generation ID support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: imammedo@redhat.com, lersek@redhat.com, Ben Warren , mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ben Warren 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) Signed-off-by: Ben Warren --- default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/acpi/Makefile.objs | 1 + hw/acpi/vmgenid.c | 206 +++++++++++++++++++++++++++++++= ++++ hw/i386/acpi-build.c | 10 ++ include/hw/acpi/acpi_dev_interface.h | 1 + include/hw/acpi/vmgenid.h | 37 +++++++ 7 files changed, 257 insertions(+) create mode 100644 hw/acpi/vmgenid.c create mode 100644 include/hw/acpi/vmgenid.h diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmm= u.mak index 384cefb..1a43542 100644 --- a/default-configs/i386-softmmu.mak +++ b/default-configs/i386-softmmu.mak @@ -58,3 +58,4 @@ CONFIG_I82801B11=3Dy CONFIG_SMBIOS=3Dy CONFIG_HYPERV_TESTDEV=3D$(CONFIG_KVM) CONFIG_PXB=3Dy +CONFIG_ACPI_VMGENID=3Dy diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-so= ftmmu.mak index 491a191..aee8b08 100644 --- a/default-configs/x86_64-softmmu.mak +++ b/default-configs/x86_64-softmmu.mak @@ -58,3 +58,4 @@ CONFIG_I82801B11=3Dy CONFIG_SMBIOS=3Dy CONFIG_HYPERV_TESTDEV=3D$(CONFIG_KVM) CONFIG_PXB=3Dy +CONFIG_ACPI_VMGENID=3Dy diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs index 6acf798..11c35bc 100644 --- a/hw/acpi/Makefile.objs +++ b/hw/acpi/Makefile.objs @@ -5,6 +5,7 @@ common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) +=3D cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) +=3D memory_hotplug.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) +=3D cpu.o common-obj-$(CONFIG_ACPI_NVDIMM) +=3D nvdimm.o +common-obj-$(CONFIG_ACPI_VMGENID) +=3D vmgenid.o common-obj-$(call lnot,$(CONFIG_ACPI_X86)) +=3D acpi-stub.o =20 common-obj-y +=3D acpi_interface.o diff --git a/hw/acpi/vmgenid.c b/hw/acpi/vmgenid.c new file mode 100644 index 0000000..6c9ecfd --- /dev/null +++ b/hw/acpi/vmgenid.c @@ -0,0 +1,206 @@ +/* + * Virtual Machine Generation ID Device + * + * Copyright (C) 2017 Skyport Systems. + * + * Author: Ben Warren + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * 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(GArray *table_data, GArray *guid, BIOSLinker *link= er) +{ + Object *obj; + VmGenIdState *s; + Aml *ssdt, *dev, *scope, *method, *addr, *if_ctx; + uint32_t vgia_offset; + + obj =3D find_vmgenid_dev(NULL); + assert(obj); + s =3D VMGENID(obj); + + /* Fill in the GUID values */ + if (guid->len !=3D VMGENID_FW_CFG_SIZE) { + g_array_set_size(guid, VMGENID_FW_CFG_SIZE); + } + g_array_insert_vals(guid, VMGENID_GUID_OFFSET, s->guid.data, 16); + + /* Put this in a separate SSDT table */ + ssdt =3D init_aml_allocator(); + + /* Reserve space for header */ + acpi_data_push(ssdt->buf, sizeof(AcpiTableHeader)); + + /* Storage for the GUID address */ + vgia_offset =3D table_data->len + + build_append_named_dword(ssdt->buf, "VGIA"); + scope =3D aml_scope("\\_SB"); + dev =3D 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 =3D aml_method("_STA", 0, AML_NOTSERIALIZED); + addr =3D aml_local(0); + aml_append(method, aml_store(aml_int(0xf), addr)); + if_ctx =3D 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 =3D aml_method("ADDR", 0, AML_NOTSERIALIZED); + + addr =3D 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), NUL= L), + 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 =3D 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 */ + bios_linker_loader_add_pointer(linker, + VMGENID_ADDR_FW_CFG_FILE, 0, sizeof(uint32_t), + VMGENID_GUID_FW_CFG_FILE, 0, true); + + /* Patch address of GUID fw_cfg blob into the AML */ + bios_linker_loader_add_pointer(linker, + ACPI_BUILD_TABLE_FILE, vgia_offset, sizeof(uint32_t), + VMGENID_GUID_FW_CFG_FILE, 0, false); + + 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(FWCfgState *s, GArray *guid) +{ + Object *obj =3D find_vmgenid_dev(NULL); + assert(obj); + VmGenIdState *vms =3D VMGENID(obj); + + /* 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->vgia_le, sizeof(uint32_t), false); +} + +static void vmgenid_update_guest(VmGenIdState *s) +{ + Object *obj =3D object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, NULL= ); + uint32_t vgia; + + if (obj) { + /* Write the GUID to guest memory */ + memcpy(&vgia, s->vgia_le, sizeof(vgia)); + vgia =3D le32_to_cpu(vgia); + if (vgia) { + cpu_physical_memory_write(vgia + VMGENID_GUID_OFFSET, + s->guid.data, sizeof(s->guid.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 *s =3D VMGENID(obj); + + if (!strncmp(value, "auto", 4)) { + qemu_uuid_generate(&s->guid); + } else if (qemu_uuid_parse(value, &s->guid) < 0) { + error_setg(errp, "'%s. %s': Failed to parse GUID string: %s", + object_get_typename(OBJECT(s)), VMGENID_GUID, value); + return; + } + /* QemuUUID has the first three words as big-endian, and expect that a= ny + * GUIDs passed in will always be BE. The guest, however will expect + * the fields to be little-endian, so store that way internally. Make + * sure to swap back whenever reporting via monitor */ + qemu_uuid_bswap(&s->guid); + + /* Send the ACPI notify */ + vmgenid_update_guest(s); +} + +/* 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 *s =3D opaque; + vmgenid_update_guest(s); + return 0; +} + +static const VMStateDescription vmstate_vmgenid =3D { + .name =3D "vmgenid", + .version_id =3D 1, + .minimum_version_id =3D 1, + .post_load =3D vmgenid_post_load, + .fields =3D (VMStateField[]) { + VMSTATE_UINT8_ARRAY(vgia_le, VmGenIdState, sizeof(uint32_t)), + VMSTATE_END_OF_LIST() + }, +}; + +static void vmgenid_initfn(Object *obj) +{ + object_property_add_str(obj, VMGENID_GUID, NULL, vmgenid_set_guid, NUL= L); +} + +static void vmgenid_device_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->vmsd =3D &vmstate_vmgenid; +} + +static const TypeInfo vmgenid_device_info =3D { + .name =3D VMGENID_DEVICE, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(VmGenIdState), + .instance_init =3D vmgenid_initfn, + .class_init =3D vmgenid_device_class_init, +}; + +static void vmgenid_register_types(void) +{ + type_register_static(&vmgenid_device_info); +} + +type_init(vmgenid_register_types) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 78a1d84..4c40f76 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -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" @@ -2653,6 +2654,11 @@ void acpi_build(AcpiBuildTables *tables, MachineStat= e *machine) acpi_add_table(table_offsets, tables_blob); build_madt(tables_blob, tables->linker, pcms); =20 + if (find_vmgenid_dev(NULL)) { + acpi_add_table(table_offsets, tables_blob); + vmgenid_build_acpi(tables_blob, tables->vmgenid, tables->linker); + } + if (misc.has_hpet) { acpi_add_table(table_offsets, tables_blob); build_hpet(tables_blob, tables->linker); @@ -2859,6 +2865,10 @@ void acpi_setup(void) fw_cfg_add_file(pcms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data, acpi_data_len(tables.tcpalog)); =20 + if (find_vmgenid_dev(NULL)) { + vmgenid_add_fw_cfg(pcms->fw_cfg, tables.vmgenid); + } + if (!pcmc->rsdp_in_ram) { /* * Keep for compatibility with old machine types. diff --git a/include/hw/acpi/acpi_dev_interface.h b/include/hw/acpi/acpi_de= v_interface.h index 71d3c48..3c2e4e9 100644 --- a/include/hw/acpi/acpi_dev_interface.h +++ b/include/hw/acpi/acpi_dev_interface.h @@ -11,6 +11,7 @@ typedef enum { ACPI_CPU_HOTPLUG_STATUS =3D 4, ACPI_MEMORY_HOTPLUG_STATUS =3D 8, ACPI_NVDIMM_HOTPLUG_STATUS =3D 16, + ACPI_VMGENID_CHANGE_STATUS =3D 32, } AcpiEventStatusBits; =20 #define TYPE_ACPI_DEVICE_IF "acpi-device-interface" diff --git a/include/hw/acpi/vmgenid.h b/include/hw/acpi/vmgenid.h new file mode 100644 index 0000000..b60437a --- /dev/null +++ b/include/hw/acpi/vmgenid.h @@ -0,0 +1,37 @@ +#ifndef ACPI_VMGENID_H +#define ACPI_VMGENID_H + +#include "hw/acpi/bios-linker-loader.h" +#include "hw/sysbus.h" +#include "qemu/uuid.h" + +#define VMGENID_DEVICE "vmgenid" +#define VMGENID_GUID "guid" +#define VMGENID_GUID_FW_CFG_FILE "etc/vmgenid" +#define VMGENID_ADDR_FW_CFG_FILE "etc/vmgenid_addr" + +#define VMGENID_FW_CFG_SIZE 4096 /* Occupy a page of memory */ +#define VMGENID_GUID_OFFSET 40 /* allow space for + * OVMF SDT Header Probe Supressor */ + +void vmgenid_add_fw_cfg(FWCfgState *s, GArray *guid); +void vmgenid_build_acpi(GArray *table_data, GArray *guid, BIOSLinker *link= er); + +#define VMGENID(obj) OBJECT_CHECK(VmGenIdState, (obj), VMGENID_DEVICE) + +typedef struct VmGenIdState { + SysBusDevice parent_obj; + QemuUUID guid; + uint8_t vgia_le[4]; +} VmGenIdState; + +static Object *find_vmgenid_dev(Error **errp) +{ + Object *obj =3D object_resolve_path_type("", VMGENID_DEVICE, NULL); + if (!obj && errp) { + error_setg(errp, "%s is not found", VMGENID_DEVICE); + } + return obj; +} + +#endif --=20 2.7.4 From nobody Tue Apr 30 01:51:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486286364277475.38034750977374; Sun, 5 Feb 2017 01:19:24 -0800 (PST) Received: from localhost ([::1]:42363 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIyg-0007TE-VA for importer@patchew.org; Sun, 05 Feb 2017 04:19:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59563) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIsF-0002Zw-MH for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1caIsE-0001se-I7 for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:43 -0500 Received: from mail-pg0-x22d.google.com ([2607:f8b0:400e:c05::22d]:34236) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1caIsE-0001sP-Cw for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:42 -0500 Received: by mail-pg0-x22d.google.com with SMTP id 14so19485478pgg.1 for ; Sun, 05 Feb 2017 01:12:42 -0800 (PST) Received: from Arrow.corp.skyportsystems.com (76-236-31-201.lightspeed.sntcca.sbcglobal.net. [76.236.31.201]) by smtp.gmail.com with ESMTPSA id s24sm2347127pgo.25.2017.02.05.01.12.40 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 05 Feb 2017 01:12:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=b/c7wUZpsLnkvOcBw9QfhW77h0NASTp1YghA5tC3PUo=; b=z9KsokfLc7R549xt8nSUjEiRHC9+EoOH4DwZ60B1OYPdWKSTWFujt8uxVvvjG0/oaz ZSbzZaqkrcpE3UkGO+3i3XHSzHPCviwSolnLzqoDPw3ddCHe2jzJyJQx+2BlMfe3XrAp jFNoXBOfxxReL8svP7O1XucfWRIL1snc+sSl4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=b/c7wUZpsLnkvOcBw9QfhW77h0NASTp1YghA5tC3PUo=; b=HW9bqkUOcbuwBpsTDiLk7cM8/S9jcDIDgjCd7p8tGkQJxG3AnDpNjHMfyE8yXht9uc NPk9AoZkUNQf91isZHn60FTSZg1g11st+sjCPVKrOgWk2hG0VV5l/5pE0oHgqlHFSa6u /JB6tVagTRvV61cOs+3214fnUN3VeF7VRyVSeTJ8Qyrxb2eIp26O3skx8aEwP39WHR+P SH+YQkQ2S1ee2VxWHZ1BVMffmbMkU7JgYlaBm+ZEXh1gjepqpWx2QrptKS0ZseDZcAXc lPG8y22d+JSMRi5Yf5KKo66nfMZvdZhgKUH4j27tgawCSKhjiCIHPEmojaoWmBN6x5Mn C2nA== X-Gm-Message-State: AIkVDXIfJoD+GGQw18r9jqpqxq6UolVOdHQBzi3AR/g6U6346L6takN6lzQOiWTUVDPk7PJy X-Received: by 10.99.147.81 with SMTP id w17mr6952513pgm.111.1486285961543; Sun, 05 Feb 2017 01:12:41 -0800 (PST) From: ben@skyportsystems.com To: qemu-devel@nongnu.org Date: Sun, 5 Feb 2017 01:12:01 -0800 Message-Id: <867d090f5fb596a4e7068bc3283b3db195061df1.1486285434.git.ben@skyportsystems.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::22d Subject: [Qemu-devel] [PATCH v5 06/10] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: imammedo@redhat.com, lersek@redhat.com, Ben Warren , mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Igor Mammedov Add commands to query Virtual Machine Generation ID counter. QMP command example: { "execute": "query-vm-generation-id" } HMP command example: info vm-generation-id Signed-off-by: Igor Mammedov Reviewed-by: Eric Blake Signed-off-by: Ben Warren --- hmp-commands-info.hx | 13 +++++++++++++ hmp.c | 9 +++++++++ hmp.h | 1 + hw/acpi/vmgenid.c | 20 ++++++++++++++++++++ qapi-schema.json | 20 ++++++++++++++++++++ stubs/Makefile.objs | 1 + stubs/vmgenid.c | 8 ++++++++ 7 files changed, 72 insertions(+) create mode 100644 stubs/vmgenid.c diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index b0f35e6..f3df793 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -802,6 +802,19 @@ Show information about hotpluggable CPUs ETEXI =20 STEXI +@item info vm-generation-id +Show Virtual Machine Generation ID +ETEXI + + { + .name =3D "vm-generation-id", + .args_type =3D "", + .params =3D "", + .help =3D "Show Virtual Machine Generation ID", + .cmd =3D hmp_info_vm_generation_id, + }, + +STEXI @end table ETEXI =20 diff --git a/hmp.c b/hmp.c index 2bc4f06..535613d 100644 --- a/hmp.c +++ b/hmp.c @@ -2565,3 +2565,12 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict= *qdict) =20 qapi_free_HotpluggableCPUList(saved); } + +void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict) +{ + GuidInfo *info =3D qmp_query_vm_generation_id(NULL); + if (info) { + monitor_printf(mon, "%s\n", info->guid); + } + qapi_free_GuidInfo(info); +} diff --git a/hmp.h b/hmp.h index 05daf7c..799fd37 100644 --- a/hmp.h +++ b/hmp.h @@ -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); =20 #endif diff --git a/hw/acpi/vmgenid.c b/hw/acpi/vmgenid.c index 6c9ecfd..e148051 100644 --- a/hw/acpi/vmgenid.c +++ b/hw/acpi/vmgenid.c @@ -204,3 +204,23 @@ static void vmgenid_register_types(void) } =20 type_init(vmgenid_register_types) + +GuidInfo *qmp_query_vm_generation_id(Error **errp) +{ + GuidInfo *info; + VmGenIdState *vdev; + QemuUUID guid; + Object *obj =3D find_vmgenid_dev(errp); + + if (!obj) { + return NULL; + } + vdev =3D VMGENID(obj); + /* Convert GUID back to big-endian before displaying */ + memcpy(&guid, &vdev->guid, sizeof(guid)); + qemu_uuid_bswap(&guid); + + info =3D g_malloc0(sizeof(*info)); + info->guid =3D qemu_uuid_unparse_strdup(&guid); + return info; +} diff --git a/qapi-schema.json b/qapi-schema.json index cbdffdd..384a7f3 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -6031,3 +6031,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' } diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index a187295..0bffca6 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -35,3 +35,4 @@ stub-obj-y +=3D qmp_pc_dimm_device_list.o stub-obj-y +=3D target-monitor-defs.o stub-obj-y +=3D target-get-monitor-def.o stub-obj-y +=3D pc_madt_cpu_entry.o +stub-obj-y +=3D vmgenid.o diff --git a/stubs/vmgenid.c b/stubs/vmgenid.c new file mode 100644 index 0000000..8c448ac --- /dev/null +++ b/stubs/vmgenid.c @@ -0,0 +1,8 @@ +#include "qemu/osdep.h" +#include "qmp-commands.h" + +GuidInfo *qmp_query_vm_generation_id(Error **errp) +{ + error_setg(errp, "this command is not currently supported"); + return NULL; +} --=20 2.7.4 From nobody Tue Apr 30 01:51:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486286425807140.86905151824897; Sun, 5 Feb 2017 01:20:25 -0800 (PST) Received: from localhost ([::1]:42364 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIzf-0008Ll-6U for importer@patchew.org; Sun, 05 Feb 2017 04:20:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIsG-0002b4-EH for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1caIsF-0001sp-BR for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:44 -0500 Received: from mail-pf0-x22c.google.com ([2607:f8b0:400e:c00::22c]:36736) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1caIsF-0001sk-5S for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:43 -0500 Received: by mail-pf0-x22c.google.com with SMTP id 189so16301528pfu.3 for ; Sun, 05 Feb 2017 01:12:43 -0800 (PST) Received: from Arrow.corp.skyportsystems.com (76-236-31-201.lightspeed.sntcca.sbcglobal.net. [76.236.31.201]) by smtp.gmail.com with ESMTPSA id s24sm2347127pgo.25.2017.02.05.01.12.41 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 05 Feb 2017 01:12:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=S1KOfFAWgPsLKUyJxXG0gJM8Qtvh8g7j7lyJlMs7QOg=; b=LGhIjbi+gZURLTm6wyCEEAKk5YNCtazRLoGm9usfInFFziPOFy+xmIqnjBsLrf6b/Q 1y2ybGuBd9a3kjx0taeEJkaFd+PbGRn/okeJffItMdTIUh5EXZ1bMij97VHeNAd5eGw2 Y5g01QW9Tz2g12yfKXuLcm1QLr/nub30oHCfA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=S1KOfFAWgPsLKUyJxXG0gJM8Qtvh8g7j7lyJlMs7QOg=; b=FfRq/LgHBVuL6tGQYiMck4muzpwMxvNtnw3lZ1+X03QVt2JtObRfcF2A468yMuFAlO x/5KNndi7FycpXoqwVs2zqluLIg6cRnrHv88hSNbnLPof9bRwtlVEn3pzaVTI6LsBnKa 98sF+sv80vXkuLCgrIFoUtZD3jo2lbXY/EODm+EWRzrwosrLqzpDeA+BbLpukAxhaBVp BL5fZOvjvwAY/0W21UXsLv76ebJfAojmiLby/KfA8O9T2X+i7kUXtIW1YpgeoL3c7ssJ yeduB5iLUQmJFxMMYAzDgKOprPFV0e0ddWjiKmOXq+3nmPFOmHZW4n70TrABnvJc4/2/ piNw== X-Gm-Message-State: AIkVDXKXxyPZZmLe9p64riFbq6fiqFTQCxmGgcq3RzhOPWsuuNcv8OaNn81BtlsjzDtmBaCx X-Received: by 10.99.232.5 with SMTP id s5mr6952223pgh.66.1486285962223; Sun, 05 Feb 2017 01:12:42 -0800 (PST) From: ben@skyportsystems.com To: qemu-devel@nongnu.org Date: Sun, 5 Feb 2017 01:12:02 -0800 Message-Id: <755a17f2d8daf7d2a62b23bb8957c114a93ccf12.1486285434.git.ben@skyportsystems.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::22c Subject: [Qemu-devel] [PATCH v5 07/10] qmp/hmp: add set-vm-generation-id commands X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: imammedo@redhat.com, lersek@redhat.com, Ben Warren , mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Igor Mammedov Add set-vm-generation-id command to set Virtual Machine Generation ID counter. QMP command example: { "execute": "set-vm-generation-id", "arguments": { "guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87" } } HMP command example: set-vm-generation-id guid=3D324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87 Signed-off-by: Igor Mammedov Reviewed-by: Eric Blake Signed-off-by: Ben Warren --- hmp-commands.hx | 13 +++++++++++++ hmp.c | 12 ++++++++++++ hmp.h | 1 + hw/acpi/vmgenid.c | 12 ++++++++++++ qapi-schema.json | 11 +++++++++++ stubs/vmgenid.c | 6 ++++++ 6 files changed, 55 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 8819281..56744aa 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1775,5 +1775,18 @@ ETEXI }, =20 STEXI +@item set-vm-generation-id @var{uuid} +Set Virtual Machine Generation ID counter to @var{guid} +ETEXI + + { + .name =3D "set-vm-generation-id", + .args_type =3D "guid:s", + .params =3D "guid", + .help =3D "Set Virtual Machine Generation ID counter", + .cmd =3D hmp_set_vm_generation_id, + }, + +STEXI @end table ETEXI diff --git a/hmp.c b/hmp.c index 535613d..39c8965 100644 --- a/hmp.c +++ b/hmp.c @@ -2574,3 +2574,15 @@ void hmp_info_vm_generation_id(Monitor *mon, const Q= Dict *qdict) } qapi_free_GuidInfo(info); } + +void hmp_set_vm_generation_id(Monitor *mon, const QDict *qdict) +{ + Error *errp =3D NULL; + const char *guid =3D qdict_get_str(qdict, "guid"); + + qmp_set_vm_generation_id(guid, &errp); + if (errp) { + hmp_handle_error(mon, &errp); + return; + } +} diff --git a/hmp.h b/hmp.h index 799fd37..e0ac1e8 100644 --- a/hmp.h +++ b/hmp.h @@ -138,5 +138,6 @@ void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict= *qdict); void hmp_info_dump(Monitor *mon, const QDict *qdict); void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict); void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict); +void hmp_set_vm_generation_id(Monitor *mon, const QDict *qdict); =20 #endif diff --git a/hw/acpi/vmgenid.c b/hw/acpi/vmgenid.c index e148051..af8b35c 100644 --- a/hw/acpi/vmgenid.c +++ b/hw/acpi/vmgenid.c @@ -224,3 +224,15 @@ GuidInfo *qmp_query_vm_generation_id(Error **errp) info->guid =3D qemu_uuid_unparse_strdup(&guid); return info; } + +void qmp_set_vm_generation_id(const char *guid, Error **errp) +{ + Object *obj =3D find_vmgenid_dev(errp); + + if (!obj) { + return; + } + + object_property_set_str(obj, guid, VMGENID_GUID, errp); + return; +} diff --git a/qapi-schema.json b/qapi-schema.json index 384a7f3..ed2657d 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -6051,3 +6051,14 @@ # Since 2.9 ## { 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' } + +## +# @set-vm-generation-id: +# +# Set Virtual Machine Generation ID +# +# @guid: new GUID to set as Virtual Machine Generation ID +# +# Since 2.9 +## +{ 'command': 'set-vm-generation-id', 'data': {'guid': 'str'} } diff --git a/stubs/vmgenid.c b/stubs/vmgenid.c index 8c448ac..d25d41b 100644 --- a/stubs/vmgenid.c +++ b/stubs/vmgenid.c @@ -6,3 +6,9 @@ GuidInfo *qmp_query_vm_generation_id(Error **errp) error_setg(errp, "this command is not currently supported"); return NULL; } + +void qmp_set_vm_generation_id(const char *guid, Error **errp) +{ + error_setg(errp, "this command is not currently supported"); + return; +} --=20 2.7.4 From nobody Tue Apr 30 01:51:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486286684932922.3461895975666; Sun, 5 Feb 2017 01:24:44 -0800 (PST) Received: from localhost ([::1]:42388 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caJ3r-0003ZU-Dw for importer@patchew.org; Sun, 05 Feb 2017 04:24:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIsG-0002bT-Rm for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1caIsG-0001t3-1P for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:44 -0500 Received: from mail-pg0-x235.google.com ([2607:f8b0:400e:c05::235]:36568) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1caIsF-0001st-SU for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:43 -0500 Received: by mail-pg0-x235.google.com with SMTP id v184so19465821pgv.3 for ; Sun, 05 Feb 2017 01:12:43 -0800 (PST) Received: from Arrow.corp.skyportsystems.com (76-236-31-201.lightspeed.sntcca.sbcglobal.net. [76.236.31.201]) by smtp.gmail.com with ESMTPSA id s24sm2347127pgo.25.2017.02.05.01.12.42 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 05 Feb 2017 01:12:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=LuI1jdhyVDovgJQ5e64VH4gAFTekhQEjSty4u8ZBh9g=; b=GoPUDq8xWf9ebBPfBiU0MlUM2GT5W/cK8RiKg/R9ij5uIkz9ov1GayagVZs5e65ReK VJFUJ3AdC1KhEyNPp/387+By9FiUvHt+Ren5L5fKwV9qG9YUFCRYfEmtrp0fLTnjQViM goJBwo//kvTaWzCNTux3sjKXkvuLU4ufbR+7Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=LuI1jdhyVDovgJQ5e64VH4gAFTekhQEjSty4u8ZBh9g=; b=bzs/FFem8Z4Vaj6aE4AFweMyHPYm+7vMDW7ktYlki8Xc0az3oRlpAer6w2abKmuzKV Jwe5RHqiIsPGpoFhpT/bfCUhbEDJqZFuY9R5+vxttwW0nmAHtcrD1QeaZzuzyp6GPur0 7Z4vgRoBbnB8M+bFuw5dLQynJqM1lUyd1xNpAYAQHSlKRp08OCM6KzAb63eE9XVVU6eg NvQOPUcrol1SG8nqeb3+usoGwJhcC4MD5d40KVPsoLYfbYdKetf6r84YqWJ8YEzoNsp3 UWTjXr0sje33UfmmIyD1BeofyDkQELiuu2Es1F71nFWRowOQhOoetAWAtS3EBdgBGL/3 xhIA== X-Gm-Message-State: AIkVDXL+i+STRV6kd++lsKJKQwARvT3LuXlZ5sOU54uUc+q12VS+WlJXWKRVGZAxeP38cooh X-Received: by 10.84.224.199 with SMTP id k7mr9111446pln.25.1486285963132; Sun, 05 Feb 2017 01:12:43 -0800 (PST) From: ben@skyportsystems.com To: qemu-devel@nongnu.org Date: Sun, 5 Feb 2017 01:12:03 -0800 Message-Id: X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::235 Subject: [Qemu-devel] [PATCH v5 08/10] PC: Support dynamic sysbus on pc_i440fx X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: imammedo@redhat.com, lersek@redhat.com, Ben Warren , mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ben Warren This allows pc_i440fx-based machines to add new devices such as VM Generation ID directly to the sysbus. Signed-off-by: Ben Warren --- hw/i386/pc_piix.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 9f102aa..c8ad99c 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -435,6 +435,7 @@ static void pc_i440fx_machine_options(MachineClass *m) m->hot_add_cpu =3D pc_hot_add_cpu; m->default_machine_opts =3D "firmware=3Dbios-256k.bin"; m->default_display =3D "std"; + m->has_dynamic_sysbus =3D true; } =20 static void pc_i440fx_2_9_machine_options(MachineClass *m) --=20 2.7.4 From nobody Tue Apr 30 01:51:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486286636152829.9687708602869; Sun, 5 Feb 2017 01:23:56 -0800 (PST) Received: from localhost ([::1]:42387 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caJ34-0002ni-MF for importer@patchew.org; Sun, 05 Feb 2017 04:23:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIsK-0002f9-8C for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1caIsH-0001tP-3n for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:48 -0500 Received: from mail-pg0-x232.google.com ([2607:f8b0:400e:c05::232]:33307) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1caIsG-0001t9-Ry for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:45 -0500 Received: by mail-pg0-x232.google.com with SMTP id 204so19502002pge.0 for ; Sun, 05 Feb 2017 01:12:44 -0800 (PST) Received: from Arrow.corp.skyportsystems.com (76-236-31-201.lightspeed.sntcca.sbcglobal.net. [76.236.31.201]) by smtp.gmail.com with ESMTPSA id s24sm2347127pgo.25.2017.02.05.01.12.43 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 05 Feb 2017 01:12:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=ugP5NXfnQv77+SNcFjKodK/DY4T2KPyCbclNk+ptxlo=; b=y4U5OurZp1jM9aqbRNrJfzdY69NTuu8OxlAtjl/wMFgt1zqp/YGLAzi+CPmQ8Vk1Gd yvSxmESkk/ovXcKdunQGuuHp1x+sbd/d5TR2hG1gMir4N4v8LUnkgZA4WF6Abe5xLIwM fIah1W90BcKL9GO+onObnJoJE2+HGfxJ6L9dg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=ugP5NXfnQv77+SNcFjKodK/DY4T2KPyCbclNk+ptxlo=; b=GBjyWCKSqCzbWqDfrM6rEJcIRJfT1gi0UTYZcZM5W5jwneLe655068VMcYfsb524sJ 6qP7sgmaoGYN+8SlWbDQTzLVhzZy8S8fSOw9JMOHWSbrUPFkbHSW7cHRFQi6sGWJx8Ia QG0ahrSrG5pLKoEJY6FjSPhHCkVDfginxCpt5lRba6Tqb+H+egPi0lmwPtU1vgzXDZ20 tntlhgptTTYVu9nIMaNmxJotsJy+dB3Hpr3PLxtr7X78MA0CgBLfzKrndCqBv66ndf29 dulnXK4J8ojp2m8Xjq18F+E8QQw7GZbVdXTOr0vYT199fdrodsxZOXAc0cA2roHfJZds a4HA== X-Gm-Message-State: AIkVDXKDagezeYgDS48D/3MUbFvhFbpa8DYtnk4JwZQ4lYQFaRfm16rfJG5OwRI4QLHr3McA X-Received: by 10.84.232.133 with SMTP id i5mr8858279plk.79.1486285964054; Sun, 05 Feb 2017 01:12:44 -0800 (PST) From: ben@skyportsystems.com To: qemu-devel@nongnu.org Date: Sun, 5 Feb 2017 01:12:04 -0800 Message-Id: X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::232 Subject: [Qemu-devel] [PATCH v5 09/10] tests: Move reusable ACPI macros into a new header file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: imammedo@redhat.com, lersek@redhat.com, Ben Warren , mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ben Warren Also usable by upcoming VM Generation ID tests Signed-off-by: Ben Warren --- tests/acpi-utils.h | 75 ++++++++++++++++++++++++++++++++++++++++++++= ++++ tests/bios-tables-test.c | 72 +-------------------------------------------= -- 2 files changed, 76 insertions(+), 71 deletions(-) create mode 100644 tests/acpi-utils.h diff --git a/tests/acpi-utils.h b/tests/acpi-utils.h new file mode 100644 index 0000000..d5e5eff --- /dev/null +++ b/tests/acpi-utils.h @@ -0,0 +1,75 @@ +#ifndef TEST_ACPI_UTILS_H +#define TEST_ACPI_UTILS_H + +/* DSDT and SSDTs format */ +typedef struct { + AcpiTableHeader header; + gchar *aml; /* aml bytecode from guest */ + gsize aml_len; + gchar *aml_file; + gchar *asl; /* asl code generated from aml */ + gsize asl_len; + gchar *asl_file; + bool tmp_files_retain; /* do not delete the temp asl/aml */ +} QEMU_PACKED AcpiSdtTable; + +#define ACPI_READ_FIELD(field, addr) \ + do { \ + switch (sizeof(field)) { \ + case 1: \ + field =3D readb(addr); \ + break; \ + case 2: \ + field =3D readw(addr); \ + break; \ + case 4: \ + field =3D readl(addr); \ + break; \ + case 8: \ + field =3D readq(addr); \ + break; \ + default: \ + g_assert(false); \ + } \ + addr +=3D sizeof(field); \ + } while (0); + +#define ACPI_READ_ARRAY_PTR(arr, length, addr) \ + do { \ + int idx; \ + for (idx =3D 0; idx < length; ++idx) { \ + ACPI_READ_FIELD(arr[idx], addr); \ + } \ + } while (0); + +#define ACPI_READ_ARRAY(arr, addr) \ + ACPI_READ_ARRAY_PTR(arr, sizeof(arr) / sizeof(arr[0]), addr) + +#define ACPI_READ_TABLE_HEADER(table, addr) \ + do { \ + ACPI_READ_FIELD((table)->signature, addr); \ + ACPI_READ_FIELD((table)->length, addr); \ + ACPI_READ_FIELD((table)->revision, addr); \ + ACPI_READ_FIELD((table)->checksum, addr); \ + ACPI_READ_ARRAY((table)->oem_id, addr); \ + ACPI_READ_ARRAY((table)->oem_table_id, addr); \ + ACPI_READ_FIELD((table)->oem_revision, addr); \ + ACPI_READ_ARRAY((table)->asl_compiler_id, addr); \ + ACPI_READ_FIELD((table)->asl_compiler_revision, addr); \ + } while (0); + +#define ACPI_ASSERT_CMP(actual, expected) do { \ + uint32_t ACPI_ASSERT_CMP_le =3D cpu_to_le32(actual); \ + char ACPI_ASSERT_CMP_str[5] =3D {}; \ + memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 4); \ + g_assert_cmpstr(ACPI_ASSERT_CMP_str, =3D=3D, expected); \ +} while (0) + +#define ACPI_ASSERT_CMP64(actual, expected) do { \ + uint64_t ACPI_ASSERT_CMP_le =3D cpu_to_le64(actual); \ + char ACPI_ASSERT_CMP_str[9] =3D {}; \ + memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 8); \ + g_assert_cmpstr(ACPI_ASSERT_CMP_str, =3D=3D, expected); \ +} while (0) + +#endif /* TEST_ACPI_UTILS_H */ diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index 5404805..c642f7f 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -17,6 +17,7 @@ #include "hw/acpi/acpi-defs.h" #include "hw/smbios/smbios.h" #include "qemu/bitmap.h" +#include "acpi-utils.h" #include "boot-sector.h" =20 #define MACHINE_PC "pc" @@ -24,18 +25,6 @@ =20 #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML" =20 -/* DSDT and SSDTs format */ -typedef struct { - AcpiTableHeader header; - gchar *aml; /* aml bytecode from guest */ - gsize aml_len; - gchar *aml_file; - gchar *asl; /* asl code generated from aml */ - gsize asl_len; - gchar *asl_file; - bool tmp_files_retain; /* do not delete the temp asl/aml */ -} QEMU_PACKED AcpiSdtTable; - typedef struct { const char *machine; const char *variant; @@ -53,65 +42,6 @@ typedef struct { int required_struct_types_len; } test_data; =20 -#define ACPI_READ_FIELD(field, addr) \ - do { \ - switch (sizeof(field)) { \ - case 1: \ - field =3D readb(addr); \ - break; \ - case 2: \ - field =3D readw(addr); \ - break; \ - case 4: \ - field =3D readl(addr); \ - break; \ - case 8: \ - field =3D readq(addr); \ - break; \ - default: \ - g_assert(false); \ - } \ - addr +=3D sizeof(field); \ - } while (0); - -#define ACPI_READ_ARRAY_PTR(arr, length, addr) \ - do { \ - int idx; \ - for (idx =3D 0; idx < length; ++idx) { \ - ACPI_READ_FIELD(arr[idx], addr); \ - } \ - } while (0); - -#define ACPI_READ_ARRAY(arr, addr) \ - ACPI_READ_ARRAY_PTR(arr, sizeof(arr)/sizeof(arr[0]), addr) - -#define ACPI_READ_TABLE_HEADER(table, addr) \ - do { \ - ACPI_READ_FIELD((table)->signature, addr); \ - ACPI_READ_FIELD((table)->length, addr); \ - ACPI_READ_FIELD((table)->revision, addr); \ - ACPI_READ_FIELD((table)->checksum, addr); \ - ACPI_READ_ARRAY((table)->oem_id, addr); \ - ACPI_READ_ARRAY((table)->oem_table_id, addr); \ - ACPI_READ_FIELD((table)->oem_revision, addr); \ - ACPI_READ_ARRAY((table)->asl_compiler_id, addr); \ - ACPI_READ_FIELD((table)->asl_compiler_revision, addr); \ - } while (0); - -#define ACPI_ASSERT_CMP(actual, expected) do { \ - uint32_t ACPI_ASSERT_CMP_le =3D cpu_to_le32(actual); \ - char ACPI_ASSERT_CMP_str[5] =3D {}; \ - memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 4); \ - g_assert_cmpstr(ACPI_ASSERT_CMP_str, =3D=3D, expected); \ -} while (0) - -#define ACPI_ASSERT_CMP64(actual, expected) do { \ - uint64_t ACPI_ASSERT_CMP_le =3D cpu_to_le64(actual); \ - char ACPI_ASSERT_CMP_str[9] =3D {}; \ - memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 8); \ - g_assert_cmpstr(ACPI_ASSERT_CMP_str, =3D=3D, expected); \ -} while (0) - static char disk[] =3D "tests/acpi-test-disk-XXXXXX"; static const char *data_dir =3D "tests/acpi-test-data"; #ifdef CONFIG_IASL --=20 2.7.4 From nobody Tue Apr 30 01:51:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486286360824717.1324096448299; Sun, 5 Feb 2017 01:19:20 -0800 (PST) Received: from localhost ([::1]:42362 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIyc-0007Ql-WB for importer@patchew.org; Sun, 05 Feb 2017 04:19:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59610) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caIsK-0002f8-7u for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1caIsH-0001td-W0 for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:48 -0500 Received: from mail-pg0-x235.google.com ([2607:f8b0:400e:c05::235]:34237) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1caIsH-0001tY-O2 for qemu-devel@nongnu.org; Sun, 05 Feb 2017 04:12:45 -0500 Received: by mail-pg0-x235.google.com with SMTP id 14so19485676pgg.1 for ; Sun, 05 Feb 2017 01:12:45 -0800 (PST) Received: from Arrow.corp.skyportsystems.com (76-236-31-201.lightspeed.sntcca.sbcglobal.net. [76.236.31.201]) by smtp.gmail.com with ESMTPSA id s24sm2347127pgo.25.2017.02.05.01.12.44 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 05 Feb 2017 01:12:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=c3Ju2lJCh9KizfXpD0SF8Mkq9dleGWgTaGgjuQ5pQ0A=; b=Ef7sS+119f4wQrj2rewxLbiRmR6qT6t3moQwYnyMtrFqsABoCd66AZ04HIcMeziZXF 1FFxHw+FYlWl0N54c2CkLcqiDBYcJJGmNf+DJ/ynwKxlRdO0X2nDIakzlg4asyYomusl /V2UTD5o6lAA3GNIB67JWhtixpNKbBWL+7gLg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=c3Ju2lJCh9KizfXpD0SF8Mkq9dleGWgTaGgjuQ5pQ0A=; b=KgqMJ3a62x9u2gIRJi+GsvIBxgrZx4ZOcqme2DVIzEDyTuM8QTzZ5s/Fu8r+oONlFZ KtWp/9HfTHfCClp2gGobFr6hG0B8NopG1fKVjQ/JcluUz5JCeY0L4rltQR0JGHX+lw0P U5nr8/Zu/WLsjY1T3l+ebwCd4aKRSwZW8v24iNYRQpL977krc+6t5ediX5upZMXMKmnC GqeO5odwqmYgsTuO0bXyFj4qDO1fbJufSl/+qY5q21BO7Ecxa9pII5v9i5BRWCBiG6mC h0qJ0qBqHPNPP/i3+TASsWZoZfuaJjADHsTaflVMhlsb4lm65za2B+irMNGwaOPNF8kE 2Xdw== X-Gm-Message-State: AIkVDXLCtl3VmxBNiy4jKPtDBLVAJD6vb8YD8fNFH2cNSvTyBIqHISHA8Sq61mVUJSheh4QV X-Received: by 10.99.98.132 with SMTP id w126mr6831242pgb.59.1486285964850; Sun, 05 Feb 2017 01:12:44 -0800 (PST) From: ben@skyportsystems.com To: qemu-devel@nongnu.org Date: Sun, 5 Feb 2017 01:12:05 -0800 Message-Id: X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::235 Subject: [Qemu-devel] [PATCH v5 10/10] tests: Add unit tests for the VM Generation ID feature X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: imammedo@redhat.com, lersek@redhat.com, Ben Warren , mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ben Warren The following tests are implemented: * test that a GUID passed in by command line is propagated to the guest. * test that changing the GUID at runtime via the monitor is reflected in the guest. * test that the "auto" argument to the GUID generates a different, and correct GUID as seen by the guest. This patch is loosely based on a previous patch from: Gal Hammer and Igor Mammedov Signed-off-by: Ben Warren --- tests/Makefile.include | 2 + tests/vmgenid-test.c | 184 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 186 insertions(+) create mode 100644 tests/vmgenid-test.c diff --git a/tests/Makefile.include b/tests/Makefile.include index 634394a..ca4b3f7 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -241,6 +241,7 @@ check-qtest-i386-y +=3D tests/usb-hcd-xhci-test$(EXESUF) gcov-files-i386-y +=3D hw/usb/hcd-xhci.c check-qtest-i386-y +=3D tests/pc-cpu-test$(EXESUF) check-qtest-i386-y +=3D tests/q35-test$(EXESUF) +check-qtest-i386-y +=3D tests/vmgenid-test$(EXESUF) gcov-files-i386-y +=3D hw/pci-host/q35.c check-qtest-i386-$(CONFIG_VHOST_NET_TEST_i386) +=3D tests/vhost-user-test$= (EXESUF) ifeq ($(CONFIG_VHOST_NET_TEST_i386),) @@ -726,6 +727,7 @@ tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o contr= ib/ivshmem-server/ivshmem tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o contrib/libvho= st-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 =20 tests/migration/stress$(EXESUF): tests/migration/stress.o $(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ,"L= INK","$(TARGET_DIR)$@") diff --git a/tests/vmgenid-test.c b/tests/vmgenid-test.c new file mode 100644 index 0000000..0f5ba07 --- /dev/null +++ b/tests/vmgenid-test.c @@ -0,0 +1,184 @@ +/* + * 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 late= r. + * See the COPYING file in the top-level directory. + */ + +#include +#include +#include +#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" + +static uint64_t vgia; + +typedef struct { + AcpiTableHeader header; + gchar name_op; + gchar vgia[4]; + gchar val_op; + uint64_t vgia_val; +} QEMU_PACKED VgidTable; + +static uint64_t find_vgia(void) +{ + uint32_t off; + AcpiRsdpDescriptor rsdp_table; + uint32_t rsdt; + AcpiRsdtDescriptorRev1 rsdt_table; + int tables_nr; + uint32_t *tables; + AcpiTableHeader ssdt_table; + VgidTable vgid_table; + int i; + + /* First, find the RSDP */ + for (off =3D 0xf0000; off < 0x100000; off +=3D 0x10) { + uint8_t sig[] =3D "RSD PTR "; + + for (i =3D 0; i < sizeof sig - 1; ++i) { + sig[i] =3D readb(off + i); + } + + if (!memcmp(sig, "RSD PTR ", sizeof sig)) { + break; + } + } + g_assert_cmphex(off, <, 0x100000); + + /* Parse the RSDP header so we can find the RSDT */ + ACPI_READ_FIELD(rsdp_table.signature, off); + ACPI_ASSERT_CMP64(rsdp_table.signature, "RSD PTR "); + + ACPI_READ_FIELD(rsdp_table.checksum, off); + ACPI_READ_ARRAY(rsdp_table.oem_id, off); + ACPI_READ_FIELD(rsdp_table.revision, off); + ACPI_READ_FIELD(rsdp_table.rsdt_physical_address, off); + + rsdt =3D 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 =3D (rsdt_table.length - sizeof(AcpiRsdtDescriptorRev1)) / + sizeof(uint32_t); + g_assert_cmpint(tables_nr, >, 0); + + /* get the addresses of the tables pointed by rsdt */ + tables =3D g_new0(uint32_t, tables_nr); + ACPI_READ_ARRAY_PTR(tables, tables_nr, rsdt); + + for (i =3D 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 =3D=3D 0x08); /* name */ + ACPI_READ_ARRAY(vgid_table.vgia, tables[i]); + g_assert(memcmp(vgid_table.vgia, "VGIA", 4) =3D=3D 0); + ACPI_READ_FIELD(vgid_table.val_op, tables[i]); + g_assert(vgid_table.val_op =3D=3D 0x0E); /* qword */ + ACPI_READ_FIELD(vgid_table.vgia_val, tables[i]); + return vgid_table.vgia_val; + } + } + return 0; +} + +static void vmgenid_read_guid(uint8_t *guid) +{ + int i; + + if (vgia =3D=3D 0) { + vgia =3D find_vgia(); + } + g_assert(vgia); + + /* Read the GUID directly from guest memory */ + for (i =3D 0; i < 16; i++) { + guid[i] =3D readb(vgia + i); + } +} + +static void vmgenid_test(void) +{ + uint8_t measured[16]; + QemuUUID expected; + g_assert(qemu_uuid_parse(VGID_GUID, &expected) =3D=3D 0); + vmgenid_read_guid(measured); + g_assert(memcmp(measured, expected.data, sizeof(measured)) =3D=3D 0); +} + +static void vmgenid_set_guid_test(void) +{ + QDict *response; + gchar *cmd; + uint8_t measured[16]; + QemuUUID expected; + g_assert(qemu_uuid_parse(VGID_GUID, &expected) =3D=3D 0); + /* Change the GUID slightly */ + expected.data[0] +=3D 1; + + cmd =3D g_strdup_printf("{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/testvgid', " + "'property': 'guid', 'value': '%s' } }", + qemu_uuid_unparse_strdup(&expected)); + response =3D qmp(cmd); + g_assert(qdict_haskey(response, "return")); + QDECREF(response); + + vmgenid_read_guid(measured); + g_assert(memcmp(measured, expected.data, sizeof(measured)) =3D=3D 0); +} + +static void vmgenid_set_guid_auto_test(void) +{ + QDict *response; + QemuUUID measured; + QemuUUID expected; + + /* Read the initial value */ + vmgenid_read_guid(expected.data); + + /* Setting to 'auto' generates a random GUID */ + response =3D qmp("{ 'execute': 'qom-set', 'arguments': { " + "'path': '/machine/peripheral/testvgid', " + "'property': 'guid', 'value': 'auto' } }"); + + g_assert(qdict_haskey(response, "return")); + QDECREF(response); + + vmgenid_read_guid(measured.data); + g_assert(memcmp(measured.data, expected.data, sizeof(measured.data)) != =3D 0); +} + +int main(int argc, char **argv) +{ + int ret; + + g_test_init(&argc, &argv, NULL); + + qtest_start("-machine accel=3Dtcg -device vmgenid,id=3Dtestvgid," + "guid=3D" VGID_GUID); + qtest_add_func("/vmgenid/vmgenid", vmgenid_test); + qtest_add_func("/vmgenid/vmgenid/set-guid", vmgenid_set_guid_test); + qtest_add_func("/vmgenid/vmgenid/set-guid-auto", + vmgenid_set_guid_auto_test); + ret =3D g_test_run(); + + qtest_end(); + + return ret; +} --=20 2.7.4