From nobody Thu May 2 09:21:58 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544466330313633.1328297663883; Mon, 10 Dec 2018 10:25:30 -0800 (PST) Received: from localhost ([::1]:34195 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQFF-0005DQ-5J for importer@patchew.org; Mon, 10 Dec 2018 13:25:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQAl-0001Wl-PP for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWQAj-0006NT-Ld for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53970) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWQAj-0006KR-BU for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:49 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1B7A430DDBCA; Mon, 10 Dec 2018 18:20:44 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id D75EB5C1B5; Mon, 10 Dec 2018 18:20:42 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 19:10:07 +0100 Message-Id: <1544465415-207855-2-git-send-email-imammedo@redhat.com> In-Reply-To: <1544465415-207855-1-git-send-email-imammedo@redhat.com> References: <1544465415-207855-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 10 Dec 2018 18:20:44 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/9] tests: acpi: remove not used ACPI_READ_GENERIC_ADDRESS macro 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: Laurent Vivier , Thomas Huth , Samuel Ortiz , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Igor Mammedov Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/acpi-utils.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/acpi-utils.h b/tests/acpi-utils.h index 4f4899d..c8844a2 100644 --- a/tests/acpi-utils.h +++ b/tests/acpi-utils.h @@ -70,14 +70,6 @@ typedef struct { g_assert_cmpstr(ACPI_ASSERT_CMP_str, =3D=3D, expected); \ } while (0) =20 -#define ACPI_READ_GENERIC_ADDRESS(field, addr) \ - do { \ - ACPI_READ_FIELD((field).space_id, addr); \ - ACPI_READ_FIELD((field).bit_width, addr); \ - ACPI_READ_FIELD((field).bit_offset, addr); \ - ACPI_READ_FIELD((field).access_width, addr); \ - ACPI_READ_FIELD((field).address, addr); \ - } while (0) =20 =20 uint8_t acpi_calc_checksum(const uint8_t *data, int len); --=20 2.7.4 From nobody Thu May 2 09:21:58 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15444661909541001.0123809289372; Mon, 10 Dec 2018 10:23:10 -0800 (PST) Received: from localhost ([::1]:34184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQCv-0002hM-LF for importer@patchew.org; Mon, 10 Dec 2018 13:23:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59233) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQAm-0001Wr-Kt for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWQAj-0006Ni-QP for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42484) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWQAj-0006L8-B3 for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:49 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 90F9F234; Mon, 10 Dec 2018 18:20:45 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E4815C1B4; Mon, 10 Dec 2018 18:20:44 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 19:10:08 +0100 Message-Id: <1544465415-207855-3-git-send-email-imammedo@redhat.com> In-Reply-To: <1544465415-207855-1-git-send-email-imammedo@redhat.com> References: <1544465415-207855-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 10 Dec 2018 18:20:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/9] tests: acpi: use AcpiSdtTable::aml in consistent way 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: Laurent Vivier , Thomas Huth , Samuel Ortiz , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently in the 1st case we store table body fetched from QEMU in AcpiSdtTable::aml minus it's header but in the 2nd case when we load reference aml from disk, it holds whole blob including header. More over in the 1st case, we read header in separate AcpiSdtTable::header structure and then jump over hoops to fixup tables and combine both. Treat AcpiSdtTable::aml as whole table blob approach in both cases and when fetching tables from QEMU, first get table length and then fetch whole table into AcpiSdtTable::aml instead if doing it field by field. As result * AcpiSdtTable::aml is used in consistent manner * FADT fixups use offsets from spec instead of being shifted by header length * calculating checksums and dumping blobs becomes simpler Signed-off-by: Igor Mammedov --- tests/acpi-utils.h | 6 +++-- tests/bios-tables-test.c | 59 +++++++++++++++++---------------------------= ---- 2 files changed, 25 insertions(+), 40 deletions(-) diff --git a/tests/acpi-utils.h b/tests/acpi-utils.h index c8844a2..2244e8e 100644 --- a/tests/acpi-utils.h +++ b/tests/acpi-utils.h @@ -18,8 +18,10 @@ =20 /* DSDT and SSDTs format */ typedef struct { - AcpiTableHeader header; - gchar *aml; /* aml bytecode from guest */ + union { + AcpiTableHeader *header; + uint8_t *aml; /* aml bytecode from guest */ + }; gsize aml_len; gchar *aml_file; gchar *asl; /* asl code generated from aml */ diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index 8749b77..1666cf7 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -161,29 +161,24 @@ static void sanitize_fadt_ptrs(test_data *data) for (i =3D 0; i < data->tables->len; i++) { AcpiSdtTable *sdt =3D &g_array_index(data->tables, AcpiSdtTable, i= ); =20 - if (memcmp(&sdt->header.signature, "FACP", 4)) { + if (memcmp(&sdt->header->signature, "FACP", 4)) { continue; } =20 /* check original FADT checksum before sanitizing table */ - g_assert(!(uint8_t)( - acpi_calc_checksum((uint8_t *)sdt, sizeof(AcpiTableHeader)) + - acpi_calc_checksum((uint8_t *)sdt->aml, sdt->aml_len) - )); + g_assert(!acpi_calc_checksum((uint8_t *)sdt->aml, sdt->aml_len)); =20 /* sdt->aml field offset :=3D spec offset - header size */ - memset(sdt->aml + 0, 0, 4); /* sanitize FIRMWARE_CTRL(36) ptr */ - memset(sdt->aml + 4, 0, 4); /* sanitize DSDT(40) ptr */ - if (sdt->header.revision >=3D 3) { - memset(sdt->aml + 96, 0, 8); /* sanitize X_FIRMWARE_CTRL(132) = ptr */ - memset(sdt->aml + 104, 0, 8); /* sanitize X_DSDT(140) ptr */ + memset(sdt->aml + 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */ + memset(sdt->aml + 40, 0, 4); /* sanitize DSDT ptr */ + if (sdt->header->revision >=3D 3) { + memset(sdt->aml + 132, 0, 8); /* sanitize X_FIRMWARE_CTRL ptr = */ + memset(sdt->aml + 140, 0, 8); /* sanitize X_DSDT ptr */ } =20 /* update checksum */ - sdt->header.checksum =3D 0; - sdt->header.checksum -=3D - acpi_calc_checksum((uint8_t *)sdt, sizeof(AcpiTableHeader)) + - acpi_calc_checksum((uint8_t *)sdt->aml, sdt->aml_len); + sdt->header->checksum =3D 0; + sdt->header->checksum -=3D acpi_calc_checksum(sdt->aml, sdt->aml_l= en); break; } } @@ -210,30 +205,21 @@ static void test_acpi_facs_table(test_data *data) */ static void fetch_table(AcpiSdtTable *sdt_table, uint32_t addr) { - uint8_t checksum; - - memset(sdt_table, 0, sizeof(*sdt_table)); - ACPI_READ_TABLE_HEADER(&sdt_table->header, addr); - - sdt_table->aml_len =3D le32_to_cpu(sdt_table->header.length) - - sizeof(AcpiTableHeader); + memread(addr + 4, &sdt_table->aml_len, 4); /* Length of ACPI table */ + sdt_table->aml_len =3D le32_to_cpu(sdt_table->aml_len); sdt_table->aml =3D g_malloc0(sdt_table->aml_len); - ACPI_READ_ARRAY_PTR(sdt_table->aml, sdt_table->aml_len, addr); + memread(addr, sdt_table->aml, sdt_table->aml_len); /* get whole table = */ =20 - checksum =3D acpi_calc_checksum((uint8_t *)sdt_table, - sizeof(AcpiTableHeader)) + - acpi_calc_checksum((uint8_t *)sdt_table->aml, - sdt_table->aml_len); - g_assert(!checksum); + g_assert(!acpi_calc_checksum(sdt_table->aml, sdt_table->aml_len)); } =20 static void test_acpi_dsdt_table(test_data *data) { - AcpiSdtTable dsdt_table; + AcpiSdtTable dsdt_table =3D {}; uint32_t addr =3D le32_to_cpu(data->dsdt_addr); =20 fetch_table(&dsdt_table, addr); - ACPI_ASSERT_CMP(dsdt_table.header.signature, "DSDT"); + ACPI_ASSERT_CMP(dsdt_table.header->signature, "DSDT"); =20 /* Since DSDT isn't in RSDT, add DSDT to ASL test tables list manually= */ g_array_append_val(data->tables, dsdt_table); @@ -246,7 +232,7 @@ static void fetch_rsdt_referenced_tables(test_data *dat= a) int i; =20 for (i =3D 0; i < tables_nr; i++) { - AcpiSdtTable ssdt_table; + AcpiSdtTable ssdt_table =3D {}; uint32_t addr; =20 addr =3D le32_to_cpu(data->rsdt_tables_addr[i]); @@ -273,7 +259,7 @@ static void dump_aml_files(test_data *data, bool rebuil= d) =20 if (rebuild) { aml_file =3D g_strdup_printf("%s/%s/%.4s%s", data_dir, data->m= achine, - (gchar *)&sdt->header.signature, ex= t); + (gchar *)&sdt->header->signature, e= xt); fd =3D g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); } else { @@ -282,8 +268,6 @@ static void dump_aml_files(test_data *data, bool rebuil= d) } g_assert(fd >=3D 0); =20 - ret =3D qemu_write_full(fd, sdt, sizeof(AcpiTableHeader)); - g_assert(ret =3D=3D sizeof(AcpiTableHeader)); ret =3D qemu_write_full(fd, sdt->aml, sdt->aml_len); g_assert(ret =3D=3D sdt->aml_len); =20 @@ -295,7 +279,7 @@ static void dump_aml_files(test_data *data, bool rebuil= d) =20 static bool compare_signature(AcpiSdtTable *sdt, const char *signature) { - return !memcmp(&sdt->header.signature, signature, 4); + return !memcmp(&sdt->header->signature, signature, 4); } =20 static bool load_asl(GArray *sdts, AcpiSdtTable *sdt) @@ -390,11 +374,10 @@ static GArray *load_expected_aml(test_data *data) sdt =3D &g_array_index(data->tables, AcpiSdtTable, i); =20 memset(&exp_sdt, 0, sizeof(exp_sdt)); - exp_sdt.header.signature =3D sdt->header.signature; =20 try_again: aml_file =3D g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machi= ne, - (gchar *)&sdt->header.signature, ext); + (gchar *)&sdt->header->signature, ext); if (getenv("V")) { fprintf(stderr, "\nLooking for expected file '%s'\n", aml_file= ); } @@ -410,7 +393,7 @@ try_again: if (getenv("V")) { fprintf(stderr, "\nUsing expected file '%s'\n", aml_file); } - ret =3D g_file_get_contents(aml_file, &exp_sdt.aml, + ret =3D g_file_get_contents(aml_file, (gchar **)&exp_sdt.aml, &exp_sdt.aml_len, &error); g_assert(ret); g_assert_no_error(error); @@ -454,7 +437,7 @@ static void test_acpi_asl(test_data *data) fprintf(stderr, "Warning! iasl couldn't parse the expected aml\n"); } else { - uint32_t signature =3D cpu_to_le32(exp_sdt->header.signatu= re); + uint32_t signature =3D cpu_to_le32(exp_sdt->header->signat= ure); sdt->tmp_files_retain =3D true; exp_sdt->tmp_files_retain =3D true; fprintf(stderr, --=20 2.7.4 From nobody Thu May 2 09:21:58 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544466610512781.9857877771735; Mon, 10 Dec 2018 10:30:10 -0800 (PST) Received: from localhost ([::1]:34227 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQJk-0001B8-VB for importer@patchew.org; Mon, 10 Dec 2018 13:30:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59236) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQAm-0001Wt-NW for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWQAj-0006NJ-HZ for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45384) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWQAj-0006Lw-8R for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:49 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 11E9C3001FE7; Mon, 10 Dec 2018 18:20:47 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id D83D95C1B4; Mon, 10 Dec 2018 18:20:45 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 19:10:09 +0100 Message-Id: <1544465415-207855-4-git-send-email-imammedo@redhat.com> In-Reply-To: <1544465415-207855-1-git-send-email-imammedo@redhat.com> References: <1544465415-207855-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 10 Dec 2018 18:20:47 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/9] tests: acpi: make sure FADT is fetched only once 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: Laurent Vivier , Thomas Huth , Samuel Ortiz , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Whole FADT is fetched as part of RSDT referenced tables in fetch_rsdt_referenced_tables() albeit a bit later than when FADT is partially parsed in fadt_fetch_facs_and_dsdt_ptrs(). However there is no reason for calling fetch_rsdt_referenced_tables() so late, just move it right after we fetched RSDT and before fadt_fetch_facs_and_dsdt_ptrs(). That way we can reuse whole FADT fetched by fetch_rsdt_referenced_tables() and avoid duplicate custom fields fetching in fadt_fetch_facs_and_dsdt_ptrs(). While at it rename fadt_fetch_facs_and_dsdt_ptrs() to test_acpi_fadt_table(). The follow up patch will merge fadt_fetch_facs_and_dsdt_ptrs() into test_acpi_rsdt_table(), so that we would end up calling only test_acpi_FOO_table() for consistency for tables that require special processing. Signed-off-by: Igor Mammedov --- tests/bios-tables-test.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index 1666cf7..5faf75f 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -139,18 +139,15 @@ static void test_acpi_rsdt_table(test_data *data) data->rsdt_tables_nr =3D tables_nr; } =20 -static void fadt_fetch_facs_and_dsdt_ptrs(test_data *data) +static void test_acpi_fadt_table(test_data *data) { - uint32_t addr; - AcpiTableHeader hdr; + /* FADT table is 1st */ + AcpiSdtTable *fadt =3D &g_array_index(data->tables, typeof(*fadt), 0); =20 - /* FADT table comes first */ - addr =3D le32_to_cpu(data->rsdt_tables_addr[0]); - ACPI_READ_TABLE_HEADER(&hdr, addr); - ACPI_ASSERT_CMP(hdr.signature, "FACP"); + ACPI_ASSERT_CMP(fadt->header->signature, "FACP"); =20 - ACPI_READ_FIELD(data->facs_addr, addr); - ACPI_READ_FIELD(data->dsdt_addr, addr); + memcpy(&data->facs_addr, fadt->aml + 36 /* FIRMWARE_CTRL */, 4); + memcpy(&data->dsdt_addr, fadt->aml + 40 /* DSDT */, 4); } =20 static void sanitize_fadt_ptrs(test_data *data) @@ -622,10 +619,10 @@ static void test_acpi_one(const char *params, test_da= ta *data) test_acpi_rsdp_address(data); test_acpi_rsdp_table(data); test_acpi_rsdt_table(data); - fadt_fetch_facs_and_dsdt_ptrs(data); + fetch_rsdt_referenced_tables(data); + test_acpi_fadt_table(data); test_acpi_facs_table(data); test_acpi_dsdt_table(data); - fetch_rsdt_referenced_tables(data); =20 sanitize_fadt_ptrs(data); =20 --=20 2.7.4 From nobody Thu May 2 09:21:58 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544466464480347.09667766356074; Mon, 10 Dec 2018 10:27:44 -0800 (PST) Received: from localhost ([::1]:34213 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQHP-00071O-8I for importer@patchew.org; Mon, 10 Dec 2018 13:27:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59258) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQAn-0001XQ-PM for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWQAl-0006Oj-A4 for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43074) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWQAk-0006Ne-Rb for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:51 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 85E96307D85B; Mon, 10 Dec 2018 18:20:48 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 581645C1B4; Mon, 10 Dec 2018 18:20:47 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 19:10:10 +0100 Message-Id: <1544465415-207855-5-git-send-email-imammedo@redhat.com> In-Reply-To: <1544465415-207855-1-git-send-email-imammedo@redhat.com> References: <1544465415-207855-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 10 Dec 2018 18:20:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/9] tests: acpi: simplify rsdt handling 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: Laurent Vivier , Thomas Huth , Samuel Ortiz , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" RSDT referenced tables always have length at offset 4 and checksum at offset 9, that's enough for reusing fetch_table() and replacing custom RSDT fetching code with it. While at it * merge fetch_rsdt_referenced_tables() into test_acpi_rsdt_table() * drop test_data::rsdt_table/rsdt_tables_addr/rsdt_tables_nr since we need this data only for duration of test_acpi_rsdt_table() to fetch other tables and use locals instead. Signed-off-by: Igor Mammedov --- tests/bios-tables-test.c | 128 +++++++++++++++++++------------------------= ---- 1 file changed, 51 insertions(+), 77 deletions(-) diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index 5faf75f..bea33a6 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -28,12 +28,9 @@ typedef struct { const char *variant; uint32_t rsdp_addr; uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */]; - AcpiRsdtDescriptorRev1 rsdt_table; uint32_t dsdt_addr; uint32_t facs_addr; AcpiFacsDescriptorRev1 facs_table; - uint32_t *rsdt_tables_addr; - int rsdt_tables_nr; GArray *tables; uint32_t smbios_ep_addr; struct smbios_21_entry_point smbios_ep_table; @@ -49,33 +46,48 @@ static const char *iasl =3D stringify(CONFIG_IASL); static const char *iasl; #endif =20 +static void cleanup_table_descriptor(AcpiSdtTable *table) +{ + g_free(table->aml); + if (table->aml_file && + !table->tmp_files_retain && + g_strstr_len(table->aml_file, -1, "aml-")) { + unlink(table->aml_file); + } + g_free(table->aml_file); + g_free(table->asl); + if (table->asl_file && + !table->tmp_files_retain) { + unlink(table->asl_file); + } + g_free(table->asl_file); +} + static void free_test_data(test_data *data) { - AcpiSdtTable *temp; int i; =20 - g_free(data->rsdt_tables_addr); - for (i =3D 0; i < data->tables->len; ++i) { - temp =3D &g_array_index(data->tables, AcpiSdtTable, i); - g_free(temp->aml); - if (temp->aml_file && - !temp->tmp_files_retain && - g_strstr_len(temp->aml_file, -1, "aml-")) { - unlink(temp->aml_file); - } - g_free(temp->aml_file); - g_free(temp->asl); - if (temp->asl_file && - !temp->tmp_files_retain) { - unlink(temp->asl_file); - } - g_free(temp->asl_file); + cleanup_table_descriptor(&g_array_index(data->tables, AcpiSdtTable= , i)); } =20 g_array_free(data->tables, true); } =20 +/** fetch_table + * load ACPI table at @addr into table descriptor @sdt_table + * and check that header checksum matches actual one. + */ +static void fetch_table(AcpiSdtTable *sdt_table, uint32_t addr) +{ + memread(addr + 4, &sdt_table->aml_len, 4); /* Length of ACPI table */ + sdt_table->aml_len =3D le32_to_cpu(sdt_table->aml_len); + sdt_table->aml =3D g_malloc0(sdt_table->aml_len); + memread(addr, sdt_table->aml, sdt_table->aml_len); /* get whole table = */ + + g_assert(!acpi_calc_checksum(sdt_table->aml, sdt_table->aml_len)); +} + static void test_acpi_rsdp_address(test_data *data) { uint32_t off =3D acpi_find_rsdp_address(); @@ -107,36 +119,31 @@ static void test_acpi_rsdp_table(test_data *data) =20 static void test_acpi_rsdt_table(test_data *data) { - AcpiRsdtDescriptorRev1 *rsdt_table =3D &data->rsdt_table; uint32_t addr =3D acpi_get_rsdt_address(data->rsdp_table); - uint32_t *tables; - int tables_nr; - uint8_t checksum; - uint32_t rsdt_table_length; + const int entry_size =3D 4 /* 32-bit Entry size */; + const int tables_off =3D 36 /* 1st Entry */; + AcpiSdtTable rsdt =3D {}; + int i, table_len, table_nr; + uint32_t *entry; =20 /* read the header */ - ACPI_READ_TABLE_HEADER(rsdt_table, addr); - ACPI_ASSERT_CMP(rsdt_table->signature, "RSDT"); - - rsdt_table_length =3D le32_to_cpu(rsdt_table->length); - - /* compute the table entries in rsdt */ - tables_nr =3D (rsdt_table_length - sizeof(AcpiRsdtDescriptorRev1)) / - sizeof(uint32_t); - g_assert(tables_nr > 0); + fetch_table(&rsdt, addr); + ACPI_ASSERT_CMP(rsdt.header->signature, "RSDT"); =20 - /* get the addresses of the tables pointed by rsdt */ - tables =3D g_new0(uint32_t, tables_nr); - ACPI_READ_ARRAY_PTR(tables, tables_nr, addr); + /* Load all tables and add to test list directly RSDT referenced table= s */ + table_len =3D le32_to_cpu(rsdt.header->length); + table_nr =3D (table_len - tables_off) / entry_size; + for (i =3D 0; i < table_nr; i++) { + AcpiSdtTable ssdt_table =3D {}; =20 - checksum =3D acpi_calc_checksum((uint8_t *)rsdt_table, rsdt_table_leng= th) + - acpi_calc_checksum((uint8_t *)tables, - tables_nr * sizeof(uint32_t)); - g_assert(!checksum); + entry =3D (uint32_t *)(rsdt.aml + tables_off + i * entry_size); + addr =3D le32_to_cpu(*entry); + fetch_table(&ssdt_table, addr); =20 - /* SSDT tables after FADT */ - data->rsdt_tables_addr =3D tables; - data->rsdt_tables_nr =3D tables_nr; + /* Add table to ASL test tables list */ + g_array_append_val(data->tables, ssdt_table); + } + cleanup_table_descriptor(&rsdt); } =20 static void test_acpi_fadt_table(test_data *data) @@ -196,20 +203,6 @@ static void test_acpi_facs_table(test_data *data) ACPI_ASSERT_CMP(facs_table->signature, "FACS"); } =20 -/** fetch_table - * load ACPI table at @addr into table descriptor @sdt_table - * and check that header checksum matches actual one. - */ -static void fetch_table(AcpiSdtTable *sdt_table, uint32_t addr) -{ - memread(addr + 4, &sdt_table->aml_len, 4); /* Length of ACPI table */ - sdt_table->aml_len =3D le32_to_cpu(sdt_table->aml_len); - sdt_table->aml =3D g_malloc0(sdt_table->aml_len); - memread(addr, sdt_table->aml, sdt_table->aml_len); /* get whole table = */ - - g_assert(!acpi_calc_checksum(sdt_table->aml, sdt_table->aml_len)); -} - static void test_acpi_dsdt_table(test_data *data) { AcpiSdtTable dsdt_table =3D {}; @@ -222,24 +215,6 @@ static void test_acpi_dsdt_table(test_data *data) g_array_append_val(data->tables, dsdt_table); } =20 -/* Load all tables and add to test list directly RSDT referenced tables */ -static void fetch_rsdt_referenced_tables(test_data *data) -{ - int tables_nr =3D data->rsdt_tables_nr; - int i; - - for (i =3D 0; i < tables_nr; i++) { - AcpiSdtTable ssdt_table =3D {}; - uint32_t addr; - - addr =3D le32_to_cpu(data->rsdt_tables_addr[i]); - fetch_table(&ssdt_table, addr); - - /* Add table to ASL test tables list */ - g_array_append_val(data->tables, ssdt_table); - } -} - static void dump_aml_files(test_data *data, bool rebuild) { AcpiSdtTable *sdt; @@ -619,7 +594,6 @@ static void test_acpi_one(const char *params, test_data= *data) test_acpi_rsdp_address(data); test_acpi_rsdp_table(data); test_acpi_rsdt_table(data); - fetch_rsdt_referenced_tables(data); test_acpi_fadt_table(data); test_acpi_facs_table(data); test_acpi_dsdt_table(data); --=20 2.7.4 From nobody Thu May 2 09:21:58 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544466190955360.6323593448262; Mon, 10 Dec 2018 10:23:10 -0800 (PST) Received: from localhost ([::1]:34185 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQCy-0002iA-9u for importer@patchew.org; Mon, 10 Dec 2018 13:23:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQAo-0001XX-CY for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWQAl-0006PA-MR for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56620) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWQAl-0006Nx-93 for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:51 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 02D4930A5A63; Mon, 10 Dec 2018 18:20:50 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA9C75C1B5; Mon, 10 Dec 2018 18:20:48 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 19:10:11 +0100 Message-Id: <1544465415-207855-6-git-send-email-imammedo@redhat.com> In-Reply-To: <1544465415-207855-1-git-send-email-imammedo@redhat.com> References: <1544465415-207855-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 10 Dec 2018 18:20:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 5/9] tests: acpi: reuse fetch_table() for fetching FACS and DSDT 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: Laurent Vivier , Thomas Huth , Samuel Ortiz , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It allows to remove a bit more of code duplication and reuse common utility to get ACPI tables from guest (modulo RSDP). While at it, consolidate signature checking into fetch_table() instead of open-codding it. Considering FACS is special and doesn't have checksum, make checksum validation optin, the same goes for signature verification. PS: By pure accident, patch also fixes FACS not being tested against reference table since it wasn't added to data::tables list. But we managed not to regress it since reference file was added by commit (d25979380 acpi unit-test: add test files) back in 2013 Signed-off-by: Igor Mammedov --- tests/bios-tables-test.c | 74 +++++++++++++++++---------------------------= ---- 1 file changed, 26 insertions(+), 48 deletions(-) diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index bea33a6..df61fc2 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -28,9 +28,6 @@ typedef struct { const char *variant; uint32_t rsdp_addr; uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */]; - uint32_t dsdt_addr; - uint32_t facs_addr; - AcpiFacsDescriptorRev1 facs_table; GArray *tables; uint32_t smbios_ep_addr; struct smbios_21_entry_point smbios_ep_table; @@ -75,17 +72,27 @@ static void free_test_data(test_data *data) } =20 /** fetch_table - * load ACPI table at @addr into table descriptor @sdt_table - * and check that header checksum matches actual one. + * load ACPI table at @addr_ptr offset pointer into table descriptor + * @sdt_table and check that signature/checksum matches actual one. */ -static void fetch_table(AcpiSdtTable *sdt_table, uint32_t addr) +static void fetch_table(AcpiSdtTable *sdt_table, uint8_t *addr_ptr, + const char *sig, bool verify_checksum) { + uint32_t addr; + + memcpy(&addr, addr_ptr , sizeof(addr)); + addr =3D le32_to_cpu(addr); memread(addr + 4, &sdt_table->aml_len, 4); /* Length of ACPI table */ sdt_table->aml_len =3D le32_to_cpu(sdt_table->aml_len); sdt_table->aml =3D g_malloc0(sdt_table->aml_len); memread(addr, sdt_table->aml, sdt_table->aml_len); /* get whole table = */ =20 - g_assert(!acpi_calc_checksum(sdt_table->aml, sdt_table->aml_len)); + if (sig) { + ACPI_ASSERT_CMP(sdt_table->header->signature, sig); + } + if (verify_checksum) { + g_assert(!acpi_calc_checksum(sdt_table->aml, sdt_table->aml_len)); + } } =20 static void test_acpi_rsdp_address(test_data *data) @@ -119,16 +126,13 @@ static void test_acpi_rsdp_table(test_data *data) =20 static void test_acpi_rsdt_table(test_data *data) { - uint32_t addr =3D acpi_get_rsdt_address(data->rsdp_table); const int entry_size =3D 4 /* 32-bit Entry size */; const int tables_off =3D 36 /* 1st Entry */; AcpiSdtTable rsdt =3D {}; int i, table_len, table_nr; - uint32_t *entry; =20 /* read the header */ - fetch_table(&rsdt, addr); - ACPI_ASSERT_CMP(rsdt.header->signature, "RSDT"); + fetch_table(&rsdt, &data->rsdp_table[16 /* RsdtAddress */], "RSDT", tr= ue); =20 /* Load all tables and add to test list directly RSDT referenced table= s */ table_len =3D le32_to_cpu(rsdt.header->length); @@ -136,9 +140,8 @@ static void test_acpi_rsdt_table(test_data *data) for (i =3D 0; i < table_nr; i++) { AcpiSdtTable ssdt_table =3D {}; =20 - entry =3D (uint32_t *)(rsdt.aml + tables_off + i * entry_size); - addr =3D le32_to_cpu(*entry); - fetch_table(&ssdt_table, addr); + fetch_table(&ssdt_table, rsdt.aml + tables_off + i * entry_size, + NULL, true); =20 /* Add table to ASL test tables list */ g_array_append_val(data->tables, ssdt_table); @@ -149,12 +152,17 @@ static void test_acpi_rsdt_table(test_data *data) static void test_acpi_fadt_table(test_data *data) { /* FADT table is 1st */ - AcpiSdtTable *fadt =3D &g_array_index(data->tables, typeof(*fadt), 0); + AcpiSdtTable table =3D g_array_index(data->tables, typeof(table), 0); + uint8_t *fadt_aml =3D table.aml; + + ACPI_ASSERT_CMP(table.header->signature, "FACP"); =20 - ACPI_ASSERT_CMP(fadt->header->signature, "FACP"); + /* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */ + fetch_table(&table, fadt_aml + 36 /* FIRMWARE_CTRL */, "FACS", false); + g_array_append_val(data->tables, table); =20 - memcpy(&data->facs_addr, fadt->aml + 36 /* FIRMWARE_CTRL */, 4); - memcpy(&data->dsdt_addr, fadt->aml + 40 /* DSDT */, 4); + fetch_table(&table, fadt_aml + 40 /* DSDT */, "DSDT", true); + g_array_append_val(data->tables, table); } =20 static void sanitize_fadt_ptrs(test_data *data) @@ -187,34 +195,6 @@ static void sanitize_fadt_ptrs(test_data *data) } } =20 -static void test_acpi_facs_table(test_data *data) -{ - AcpiFacsDescriptorRev1 *facs_table =3D &data->facs_table; - uint32_t addr =3D le32_to_cpu(data->facs_addr); - - ACPI_READ_FIELD(facs_table->signature, addr); - ACPI_READ_FIELD(facs_table->length, addr); - ACPI_READ_FIELD(facs_table->hardware_signature, addr); - ACPI_READ_FIELD(facs_table->firmware_waking_vector, addr); - ACPI_READ_FIELD(facs_table->global_lock, addr); - ACPI_READ_FIELD(facs_table->flags, addr); - ACPI_READ_ARRAY(facs_table->resverved3, addr); - - ACPI_ASSERT_CMP(facs_table->signature, "FACS"); -} - -static void test_acpi_dsdt_table(test_data *data) -{ - AcpiSdtTable dsdt_table =3D {}; - uint32_t addr =3D le32_to_cpu(data->dsdt_addr); - - fetch_table(&dsdt_table, addr); - ACPI_ASSERT_CMP(dsdt_table.header->signature, "DSDT"); - - /* Since DSDT isn't in RSDT, add DSDT to ASL test tables list manually= */ - g_array_append_val(data->tables, dsdt_table); -} - static void dump_aml_files(test_data *data, bool rebuild) { AcpiSdtTable *sdt; @@ -595,8 +575,6 @@ static void test_acpi_one(const char *params, test_data= *data) test_acpi_rsdp_table(data); test_acpi_rsdt_table(data); test_acpi_fadt_table(data); - test_acpi_facs_table(data); - test_acpi_dsdt_table(data); =20 sanitize_fadt_ptrs(data); =20 --=20 2.7.4 From nobody Thu May 2 09:21:58 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15444661910571014.162471106821; Mon, 10 Dec 2018 10:23:11 -0800 (PST) Received: from localhost ([::1]:34186 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQCy-0002jb-EO for importer@patchew.org; Mon, 10 Dec 2018 13:23:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59305) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQAp-0001Xa-Lr for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWQAn-0006QS-4x for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59046) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWQAm-0006PE-M7 for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:53 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7604130842CF; Mon, 10 Dec 2018 18:20:51 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 486545C1B4; Mon, 10 Dec 2018 18:20:50 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 19:10:12 +0100 Message-Id: <1544465415-207855-7-git-send-email-imammedo@redhat.com> In-Reply-To: <1544465415-207855-1-git-send-email-imammedo@redhat.com> References: <1544465415-207855-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 10 Dec 2018 18:20:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 6/9] tests: acpi: reuse fetch_table() in vmgenid-test 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: Laurent Vivier , Thomas Huth , Samuel Ortiz , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Move fetch_table() into acpi-utils.c renaming it to acpi_fetch_table() and reuse it in vmgenid-test that reads RSDT and then tables it references, to find and parse VMGNEID SSDT. While at it wrap RSDT referenced tables enumeration into FOREACH macro (similar to what we do with QLIST_FOREACH & co) to reuse it with bios and vmgenid tests. Signed-off-by: Igor Mammedov --- tests/acpi-utils.h | 22 ++++++----------- tests/acpi-utils.c | 33 +++++++++++++++++++------ tests/bios-tables-test.c | 48 +++++++++--------------------------- tests/vmgenid-test.c | 63 +++++++++++++++-----------------------------= ---- 4 files changed, 62 insertions(+), 104 deletions(-) diff --git a/tests/acpi-utils.h b/tests/acpi-utils.h index 2244e8e..1b584d3 100644 --- a/tests/acpi-utils.h +++ b/tests/acpi-utils.h @@ -22,7 +22,7 @@ typedef struct { AcpiTableHeader *header; uint8_t *aml; /* aml bytecode from guest */ }; - gsize aml_len; + uint32_t aml_len; gchar *aml_file; gchar *asl; /* asl code generated from aml */ gsize asl_len; @@ -47,19 +47,6 @@ typedef struct { #define ACPI_READ_ARRAY(arr, addr) \ ACPI_READ_ARRAY_PTR(arr, sizeof(arr) / sizeof(arr[0]), addr) =20 -#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 { \ char ACPI_ASSERT_CMP_str[5] =3D {}; \ memcpy(ACPI_ASSERT_CMP_str, &actual, 4); \ @@ -73,11 +60,16 @@ typedef struct { } while (0) =20 =20 +#define ACPI_FOREACH_RSDT_ENTRY(table, table_len, entry_ptr, entry_size) \ + for (entry_ptr =3D table + 36 /* 1st Entry */; = \ + entry_ptr < table + table_len; \ + entry_ptr +=3D entry_size) =20 uint8_t acpi_calc_checksum(const uint8_t *data, int len); uint32_t acpi_find_rsdp_address(void); -uint32_t acpi_get_rsdt_address(uint8_t *rsdp_table); uint64_t acpi_get_xsdt_address(uint8_t *rsdp_table); void acpi_parse_rsdp_table(uint32_t addr, uint8_t *rsdp_table); +void acpi_fetch_table(uint8_t **aml, uint32_t *aml_len, const uint8_t *add= r_ptr, + const char *sig, bool verify_checksum); =20 #endif /* TEST_ACPI_UTILS_H */ diff --git a/tests/acpi-utils.c b/tests/acpi-utils.c index d07f748..de1492c 100644 --- a/tests/acpi-utils.c +++ b/tests/acpi-utils.c @@ -52,14 +52,6 @@ uint32_t acpi_find_rsdp_address(void) return off; } =20 -uint32_t acpi_get_rsdt_address(uint8_t *rsdp_table) -{ - uint32_t rsdt_physical_address; - - memcpy(&rsdt_physical_address, &rsdp_table[16 /* RsdtAddress offset */= ], 4); - return le32_to_cpu(rsdt_physical_address); -} - uint64_t acpi_get_xsdt_address(uint8_t *rsdp_table) { uint64_t xsdt_physical_address; @@ -93,3 +85,28 @@ void acpi_parse_rsdp_table(uint32_t addr, uint8_t *rsdp_= table) =20 ACPI_ASSERT_CMP64(*((uint64_t *)(rsdp_table)), "RSD PTR "); } + +/** acpi_fetch_table + * load ACPI table at @addr_ptr offset pointer into buffer and return it = in + * @aml, its length in @aml_len and check that signature/checksum matches + * actual one. + */ +void acpi_fetch_table(uint8_t **aml, uint32_t *aml_len, const uint8_t *add= r_ptr, + const char *sig, bool verify_checksum) +{ + uint32_t addr, len; + + memcpy(&addr, addr_ptr , sizeof(addr)); + addr =3D le32_to_cpu(addr); + memread(addr + 4, &len, 4); /* Length of ACPI table */ + *aml_len =3D le32_to_cpu(len); + *aml =3D g_malloc0(*aml_len); + memread(addr, *aml, *aml_len); /* get whole table */ + + if (sig) { + ACPI_ASSERT_CMP(**aml, sig); + } + if (verify_checksum) { + g_assert(!acpi_calc_checksum(*aml, *aml_len)); + } +} diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index df61fc2..8160fc0 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -71,30 +71,6 @@ static void free_test_data(test_data *data) g_array_free(data->tables, true); } =20 -/** fetch_table - * load ACPI table at @addr_ptr offset pointer into table descriptor - * @sdt_table and check that signature/checksum matches actual one. - */ -static void fetch_table(AcpiSdtTable *sdt_table, uint8_t *addr_ptr, - const char *sig, bool verify_checksum) -{ - uint32_t addr; - - memcpy(&addr, addr_ptr , sizeof(addr)); - addr =3D le32_to_cpu(addr); - memread(addr + 4, &sdt_table->aml_len, 4); /* Length of ACPI table */ - sdt_table->aml_len =3D le32_to_cpu(sdt_table->aml_len); - sdt_table->aml =3D g_malloc0(sdt_table->aml_len); - memread(addr, sdt_table->aml, sdt_table->aml_len); /* get whole table = */ - - if (sig) { - ACPI_ASSERT_CMP(sdt_table->header->signature, sig); - } - if (verify_checksum) { - g_assert(!acpi_calc_checksum(sdt_table->aml, sdt_table->aml_len)); - } -} - static void test_acpi_rsdp_address(test_data *data) { uint32_t off =3D acpi_find_rsdp_address(); @@ -126,22 +102,18 @@ static void test_acpi_rsdp_table(test_data *data) =20 static void test_acpi_rsdt_table(test_data *data) { - const int entry_size =3D 4 /* 32-bit Entry size */; - const int tables_off =3D 36 /* 1st Entry */; AcpiSdtTable rsdt =3D {}; - int i, table_len, table_nr; + uint8_t *ent; =20 - /* read the header */ - fetch_table(&rsdt, &data->rsdp_table[16 /* RsdtAddress */], "RSDT", tr= ue); + /* read RSDT table */ + acpi_fetch_table(&rsdt.aml, &rsdt.aml_len, + &data->rsdp_table[16 /* RsdtAddress */], "RSDT", true= ); =20 /* Load all tables and add to test list directly RSDT referenced table= s */ - table_len =3D le32_to_cpu(rsdt.header->length); - table_nr =3D (table_len - tables_off) / entry_size; - for (i =3D 0; i < table_nr; i++) { + ACPI_FOREACH_RSDT_ENTRY(rsdt.aml, rsdt.aml_len, ent, 4 /* Entry size *= /) { AcpiSdtTable ssdt_table =3D {}; =20 - fetch_table(&ssdt_table, rsdt.aml + tables_off + i * entry_size, - NULL, true); + acpi_fetch_table(&ssdt_table.aml, &ssdt_table.aml_len, ent, NULL, = true); =20 /* Add table to ASL test tables list */ g_array_append_val(data->tables, ssdt_table); @@ -158,10 +130,12 @@ static void test_acpi_fadt_table(test_data *data) ACPI_ASSERT_CMP(table.header->signature, "FACP"); =20 /* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */ - fetch_table(&table, fadt_aml + 36 /* FIRMWARE_CTRL */, "FACS", false); + acpi_fetch_table(&table.aml, &table.aml_len, + fadt_aml + 36 /* FIRMWARE_CTRL */, "FACS", false); g_array_append_val(data->tables, table); =20 - fetch_table(&table, fadt_aml + 40 /* DSDT */, "DSDT", true); + acpi_fetch_table(&table.aml, &table.aml_len, + fadt_aml + 40 /* DSDT */, "DSDT", true); g_array_append_val(data->tables, table); } =20 @@ -346,7 +320,7 @@ try_again: fprintf(stderr, "\nUsing expected file '%s'\n", aml_file); } ret =3D g_file_get_contents(aml_file, (gchar **)&exp_sdt.aml, - &exp_sdt.aml_len, &error); + (gsize *)&exp_sdt.aml_len, &error); g_assert(ret); g_assert_no_error(error); g_assert(exp_sdt.aml); diff --git a/tests/vmgenid-test.c b/tests/vmgenid-test.c index 97219ae..316dcf5 100644 --- a/tests/vmgenid-test.c +++ b/tests/vmgenid-test.c @@ -23,26 +23,13 @@ */ #define RSDP_ADDR_INVALID 0x100000 /* RSDP must be below this address */ =20 -typedef struct { - AcpiTableHeader header; - gchar name_op; - gchar vgia[4]; - gchar val_op; - uint32_t vgia_val; -} QEMU_PACKED VgidTable; - static uint32_t acpi_find_vgia(void) { uint32_t rsdp_offset; uint32_t guid_offset =3D 0; uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */]; - uint32_t rsdt, rsdt_table_length; - AcpiRsdtDescriptorRev1 rsdt_table; - size_t tables_nr; - uint32_t *tables; - AcpiTableHeader ssdt_table; - VgidTable vgid_table; - int i; + uint32_t rsdt_len, table_length; + uint8_t *rsdt, *ent; =20 /* Wait for guest firmware to finish and start the payload. */ boot_sector_test(global_qtest); @@ -53,47 +40,35 @@ static uint32_t acpi_find_vgia(void) g_assert_cmphex(rsdp_offset, <, RSDP_ADDR_INVALID); =20 acpi_parse_rsdp_table(rsdp_offset, rsdp_table); + acpi_fetch_table(&rsdt, &rsdt_len, &rsdp_table[16 /* RsdtAddress */], + "RSDT", true); =20 - rsdt =3D acpi_get_rsdt_address(rsdp_table); - g_assert(rsdt); - - /* read the header */ - ACPI_READ_TABLE_HEADER(&rsdt_table, rsdt); - ACPI_ASSERT_CMP(rsdt_table.signature, "RSDT"); - rsdt_table_length =3D le32_to_cpu(rsdt_table.length); + ACPI_FOREACH_RSDT_ENTRY(rsdt, rsdt_len, ent, 4 /* Entry size */) { + uint8_t *table_aml; =20 - /* compute the table entries in rsdt */ - g_assert_cmpint(rsdt_table_length, >, sizeof(AcpiRsdtDescriptorRev1)); - tables_nr =3D (rsdt_table_length - sizeof(AcpiRsdtDescriptorRev1)) / - sizeof(uint32_t); - - /* 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++) { - uint32_t addr =3D le32_to_cpu(tables[i]); - ACPI_READ_TABLE_HEADER(&ssdt_table, addr); - if (!strncmp((char *)ssdt_table.oem_table_id, "VMGENID", 7)) { + acpi_fetch_table(&table_aml, &table_length, ent, NULL, true); + if (!memcmp(table_aml + 16 /* OEM Table ID */, "VMGENID", 7)) { + uint32_t vgia_val; + uint8_t *aml =3D &table_aml[36 /* AML byte-code start */]; /* the first entry in the table should be VGIA * That's all we need */ - ACPI_READ_FIELD(vgid_table.name_op, addr); - g_assert(vgid_table.name_op =3D=3D 0x08); /* name */ - ACPI_READ_ARRAY(vgid_table.vgia, addr); - g_assert(memcmp(vgid_table.vgia, "VGIA", 4) =3D=3D 0); - ACPI_READ_FIELD(vgid_table.val_op, addr); - g_assert(vgid_table.val_op =3D=3D 0x0C); /* dword */ - ACPI_READ_FIELD(vgid_table.vgia_val, addr); + g_assert(aml[0 /* name_op*/] =3D=3D 0x08); + g_assert(memcmp(&aml[1 /* name */], "VGIA", 4) =3D=3D 0); + g_assert(aml[5 /* value op */] =3D=3D 0x0C /* dword */); + memcpy(&vgia_val, &aml[6 /* value */], 4); + /* The GUID is written at a fixed offset into the fw_cfg file * in order to implement the "OVMF SDT Header probe suppressor" * see docs/specs/vmgenid.txt for more details */ - guid_offset =3D le32_to_cpu(vgid_table.vgia_val) + VMGENID_GUI= D_OFFSET; + guid_offset =3D le32_to_cpu(vgia_val) + VMGENID_GUID_OFFSET; + g_free(table_aml); break; } + g_free(table_aml); } - g_free(tables); + g_free(rsdt); return guid_offset; } =20 --=20 2.7.4 From nobody Thu May 2 09:21:58 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544466338896588.4517291441746; Mon, 10 Dec 2018 10:25:38 -0800 (PST) Received: from localhost ([::1]:34201 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQFN-0005Ls-Pa for importer@patchew.org; Mon, 10 Dec 2018 13:25:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59321) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQAq-0001Xb-Jd for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWQAo-0006SI-P6 for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59484) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWQAo-0006QZ-9y for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:54 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EAC1F308212F; Mon, 10 Dec 2018 18:20:52 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDDBA5C1B4; Mon, 10 Dec 2018 18:20:51 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 19:10:13 +0100 Message-Id: <1544465415-207855-8-git-send-email-imammedo@redhat.com> In-Reply-To: <1544465415-207855-1-git-send-email-imammedo@redhat.com> References: <1544465415-207855-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Mon, 10 Dec 2018 18:20:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 7/9] tests: smbios: fetch whole table in one step instead of reading it step by step 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: Laurent Vivier , Thomas Huth , Samuel Ortiz , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" replace a bunch of ACPI_READ_ARRAY/ACPI_READ_FIELD macro, that read SMBIOS table field by field with one memread() to fetch whole table at once and drop no longer used ACPI_READ_ARRAY/ACPI_READ_FIELD macro. Signed-off-by: Igor Mammedov --- tests/acpi-utils.h | 17 ----------------- tests/bios-tables-test.c | 15 +-------------- 2 files changed, 1 insertion(+), 31 deletions(-) diff --git a/tests/acpi-utils.h b/tests/acpi-utils.h index 1b584d3..bc0cd19 100644 --- a/tests/acpi-utils.h +++ b/tests/acpi-utils.h @@ -30,23 +30,6 @@ typedef struct { bool tmp_files_retain; /* do not delete the temp asl/aml */ } AcpiSdtTable; =20 -#define ACPI_READ_FIELD(field, addr) \ - do { \ - memread(addr, &field, sizeof(field)); \ - 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_ASSERT_CMP(actual, expected) do { \ char ACPI_ASSERT_CMP_str[5] =3D {}; \ memcpy(ACPI_ASSERT_CMP_str, &actual, 4); \ diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index 8160fc0..9aa7c86 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -402,32 +402,19 @@ static bool smbios_ep_table_ok(test_data *data) struct smbios_21_entry_point *ep_table =3D &data->smbios_ep_table; uint32_t addr =3D data->smbios_ep_addr; =20 - ACPI_READ_ARRAY(ep_table->anchor_string, addr); + memread(addr, ep_table, sizeof(*ep_table)); if (memcmp(ep_table->anchor_string, "_SM_", 4)) { return false; } - ACPI_READ_FIELD(ep_table->checksum, addr); - ACPI_READ_FIELD(ep_table->length, addr); - ACPI_READ_FIELD(ep_table->smbios_major_version, addr); - ACPI_READ_FIELD(ep_table->smbios_minor_version, addr); - ACPI_READ_FIELD(ep_table->max_structure_size, addr); - ACPI_READ_FIELD(ep_table->entry_point_revision, addr); - ACPI_READ_ARRAY(ep_table->formatted_area, addr); - ACPI_READ_ARRAY(ep_table->intermediate_anchor_string, addr); if (memcmp(ep_table->intermediate_anchor_string, "_DMI_", 5)) { return false; } - ACPI_READ_FIELD(ep_table->intermediate_checksum, addr); - ACPI_READ_FIELD(ep_table->structure_table_length, addr); if (ep_table->structure_table_length =3D=3D 0) { return false; } - ACPI_READ_FIELD(ep_table->structure_table_address, addr); - ACPI_READ_FIELD(ep_table->number_of_structures, addr); if (ep_table->number_of_structures =3D=3D 0) { return false; } - ACPI_READ_FIELD(ep_table->smbios_bcd_revision, addr); if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table) || acpi_calc_checksum((uint8_t *)ep_table + 0x10, sizeof *ep_table - 0x10)) { --=20 2.7.4 From nobody Thu May 2 09:21:58 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 154446647379988.68084941910718; Mon, 10 Dec 2018 10:27:53 -0800 (PST) Received: from localhost ([::1]:34214 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQHY-00079d-8X for importer@patchew.org; Mon, 10 Dec 2018 13:27:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQAt-0001ZY-6M for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:21:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWQAp-0006TG-W0 for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56172) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWQAp-0006SA-IV for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:55 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 69B2258E5A; Mon, 10 Dec 2018 18:20:54 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C1395C1B4; Mon, 10 Dec 2018 18:20:53 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 19:10:14 +0100 Message-Id: <1544465415-207855-9-git-send-email-imammedo@redhat.com> In-Reply-To: <1544465415-207855-1-git-send-email-imammedo@redhat.com> References: <1544465415-207855-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 10 Dec 2018 18:20:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 8/9] tests: acpi: squash sanitize_fadt_ptrs() into test_acpi_fadt_table() 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: Laurent Vivier , Thomas Huth , Samuel Ortiz , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" some parts of sanitize_fadt_ptrs() do redundant job - locating FADT - checking original checksum There is no need to do it as test_acpi_fadt_table() already does that, so drop duplicate code and move remaining fixup code into test_acpi_fadt_table(). Signed-off-by: Igor Mammedov --- tests/bios-tables-test.c | 40 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index 9aa7c86..40b224f 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -126,6 +126,7 @@ static void test_acpi_fadt_table(test_data *data) /* FADT table is 1st */ AcpiSdtTable table =3D g_array_index(data->tables, typeof(table), 0); uint8_t *fadt_aml =3D table.aml; + uint32_t fadt_len =3D table.aml_len; =20 ACPI_ASSERT_CMP(table.header->signature, "FACP"); =20 @@ -137,36 +138,17 @@ static void test_acpi_fadt_table(test_data *data) acpi_fetch_table(&table.aml, &table.aml_len, fadt_aml + 40 /* DSDT */, "DSDT", true); g_array_append_val(data->tables, table); -} - -static void sanitize_fadt_ptrs(test_data *data) -{ - /* fixup pointers in FADT */ - int i; - - for (i =3D 0; i < data->tables->len; i++) { - AcpiSdtTable *sdt =3D &g_array_index(data->tables, AcpiSdtTable, i= ); - - if (memcmp(&sdt->header->signature, "FACP", 4)) { - continue; - } =20 - /* check original FADT checksum before sanitizing table */ - g_assert(!acpi_calc_checksum((uint8_t *)sdt->aml, sdt->aml_len)); - - /* sdt->aml field offset :=3D spec offset - header size */ - memset(sdt->aml + 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */ - memset(sdt->aml + 40, 0, 4); /* sanitize DSDT ptr */ - if (sdt->header->revision >=3D 3) { - memset(sdt->aml + 132, 0, 8); /* sanitize X_FIRMWARE_CTRL ptr = */ - memset(sdt->aml + 140, 0, 8); /* sanitize X_DSDT ptr */ - } - - /* update checksum */ - sdt->header->checksum =3D 0; - sdt->header->checksum -=3D acpi_calc_checksum(sdt->aml, sdt->aml_l= en); - break; + memset(fadt_aml + 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */ + memset(fadt_aml + 40, 0, 4); /* sanitize DSDT ptr */ + if (fadt_aml[8 /* FADT Major Version */] >=3D 3) { + memset(fadt_aml + 132, 0, 8); /* sanitize X_FIRMWARE_CTRL ptr */ + memset(fadt_aml + 140, 0, 8); /* sanitize X_DSDT ptr */ } + + /* update checksum */ + fadt_aml[9 /* Checksum */] =3D 0; + fadt_aml[9 /* Checksum */] -=3D acpi_calc_checksum(fadt_aml, fadt_len); } =20 static void dump_aml_files(test_data *data, bool rebuild) @@ -537,8 +519,6 @@ static void test_acpi_one(const char *params, test_data= *data) test_acpi_rsdt_table(data); test_acpi_fadt_table(data); =20 - sanitize_fadt_ptrs(data); - if (iasl) { if (getenv(ACPI_REBUILD_EXPECTED_AML)) { dump_aml_files(data, true); --=20 2.7.4 From nobody Thu May 2 09:21:58 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544466336737726.2050954667488; Mon, 10 Dec 2018 10:25:36 -0800 (PST) Received: from localhost ([::1]:34198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQFL-0005IJ-Kf for importer@patchew.org; Mon, 10 Dec 2018 13:25:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQAt-0001Zw-KH for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:21:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWQAr-0006U9-Kr for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35250) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWQAr-0006TK-38 for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:57 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D790281DEC; Mon, 10 Dec 2018 18:20:55 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD1A75C1B4; Mon, 10 Dec 2018 18:20:54 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 19:10:15 +0100 Message-Id: <1544465415-207855-10-git-send-email-imammedo@redhat.com> In-Reply-To: <1544465415-207855-1-git-send-email-imammedo@redhat.com> References: <1544465415-207855-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 10 Dec 2018 18:20:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 9/9] tests: acpi: use AcpiSdtTable::aml instead of AcpiSdtTable::header::signature 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: Laurent Vivier , Thomas Huth , Samuel Ortiz , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" AcpiSdtTable::header::signature is the only remained field from AcpiTableHeader structure used by tests. Instead of using packed structure to access signature, just read it directly from table blob and remove no longer used AcpiSdtTable::header / union and keep only AcpiSdtTable::aml byte array. Signed-off-by: Igor Mammedov --- tests/acpi-utils.h | 6 +----- tests/bios-tables-test.c | 20 +++++++++----------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/tests/acpi-utils.h b/tests/acpi-utils.h index bc0cd19..8d04f76 100644 --- a/tests/acpi-utils.h +++ b/tests/acpi-utils.h @@ -13,15 +13,11 @@ #ifndef TEST_ACPI_UTILS_H #define TEST_ACPI_UTILS_H =20 -#include "hw/acpi/acpi-defs.h" #include "libqtest.h" =20 /* DSDT and SSDTs format */ typedef struct { - union { - AcpiTableHeader *header; - uint8_t *aml; /* aml bytecode from guest */ - }; + uint8_t *aml; /* aml bytecode from guest */ uint32_t aml_len; gchar *aml_file; gchar *asl; /* asl code generated from aml */ diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index 40b224f..1a4e3b3 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -43,6 +43,11 @@ static const char *iasl =3D stringify(CONFIG_IASL); static const char *iasl; #endif =20 +static bool compare_signature(const AcpiSdtTable *sdt, const char *signatu= re) +{ + return !memcmp(sdt->aml, signature, 4); +} + static void cleanup_table_descriptor(AcpiSdtTable *table) { g_free(table->aml); @@ -128,7 +133,7 @@ static void test_acpi_fadt_table(test_data *data) uint8_t *fadt_aml =3D table.aml; uint32_t fadt_len =3D table.aml_len; =20 - ACPI_ASSERT_CMP(table.header->signature, "FACP"); + g_assert(compare_signature(&table, "FACP")); =20 /* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */ acpi_fetch_table(&table.aml, &table.aml_len, @@ -167,7 +172,7 @@ static void dump_aml_files(test_data *data, bool rebuil= d) =20 if (rebuild) { aml_file =3D g_strdup_printf("%s/%s/%.4s%s", data_dir, data->m= achine, - (gchar *)&sdt->header->signature, e= xt); + sdt->aml, ext); fd =3D g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); } else { @@ -185,11 +190,6 @@ static void dump_aml_files(test_data *data, bool rebui= ld) } } =20 -static bool compare_signature(AcpiSdtTable *sdt, const char *signature) -{ - return !memcmp(&sdt->header->signature, signature, 4); -} - static bool load_asl(GArray *sdts, AcpiSdtTable *sdt) { AcpiSdtTable *temp; @@ -285,7 +285,7 @@ static GArray *load_expected_aml(test_data *data) =20 try_again: aml_file =3D g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machi= ne, - (gchar *)&sdt->header->signature, ext); + sdt->aml, ext); if (getenv("V")) { fprintf(stderr, "\nLooking for expected file '%s'\n", aml_file= ); } @@ -345,14 +345,12 @@ static void test_acpi_asl(test_data *data) fprintf(stderr, "Warning! iasl couldn't parse the expected aml\n"); } else { - uint32_t signature =3D cpu_to_le32(exp_sdt->header->signat= ure); sdt->tmp_files_retain =3D true; exp_sdt->tmp_files_retain =3D true; fprintf(stderr, "acpi-test: Warning! %.4s mismatch. " "Actual [asl:%s, aml:%s], Expected [asl:%s, aml:%s= ].\n", - (gchar *)&signature, - sdt->asl_file, sdt->aml_file, + exp_sdt->aml, sdt->asl_file, sdt->aml_file, exp_sdt->asl_file, exp_sdt->aml_file); if (getenv("V")) { const char *diff_cmd =3D getenv("DIFF"); --=20 2.7.4