All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: Samuel Ortiz <sameo@linux.intel.com>
Cc: qemu-devel@nongnu.org, Laurent Vivier <lvivier@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	Thomas Huth <thuth@redhat.com>,
	Eduardo Habkost <ehabkost@redhat.com>,
	Ben Warren <ben@skyportsystems.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Shannon Zhao <shannon.zhaosl@gmail.com>,
	qemu-arm@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH 8/8] hw: acpi: Remove AcpiRsdpDescriptor and fix tests
Date: Wed, 28 Nov 2018 10:50:38 +0100	[thread overview]
Message-ID: <20181128105038.592f50a0@redhat.com> (raw)
In-Reply-To: <20181126162942.21258-9-sameo@linux.intel.com>

On Mon, 26 Nov 2018 17:29:41 +0100
Samuel Ortiz <sameo@linux.intel.com> wrote:

> We switched to the build_append_*() API for all RSDP callers, and this
> patch converts all existing tests depending on this structure.
> It is no longer needed and we can thus remove it.
I'd rephrase it as following:

The sole user of AcpiRsdpDescriptor structure is test,
drop test dependency on it and remove no longer used structure.


> 
> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
> ---
>  include/hw/acpi/acpi-defs.h | 13 ----------
>  tests/acpi-utils.h          |  5 +++-
>  tests/acpi-utils.c          | 48 ++++++++++++++++++++++++++++++-------
>  tests/bios-tables-test.c    | 27 ++++++++++++++-------
>  tests/vmgenid-test.c        |  8 ++++---
>  5 files changed, 67 insertions(+), 34 deletions(-)
> 
> diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
> index 9b2f6b8043..abef1d57ae 100644
> --- a/include/hw/acpi/acpi-defs.h
> +++ b/include/hw/acpi/acpi-defs.h
> @@ -40,19 +40,6 @@ enum {
>      ACPI_FADT_F_LOW_POWER_S0_IDLE_CAPABLE,
>  };
>  
> -struct AcpiRsdpDescriptor {        /* Root System Descriptor Pointer */
> -    uint64_t signature;              /* ACPI signature, contains "RSD PTR " */
> -    uint8_t  checksum;               /* To make sum of struct == 0 */
> -    uint8_t  oem_id [6];             /* OEM identification */
> -    uint8_t  revision;               /* Must be 0 for 1.0, 2 for 2.0 */
> -    uint32_t rsdt_physical_address;  /* 32-bit physical address of RSDT */
> -    uint32_t length;                 /* XSDT Length in bytes including hdr */
> -    uint64_t xsdt_physical_address;  /* 64-bit physical address of XSDT */
> -    uint8_t  extended_checksum;      /* Checksum of entire table */
> -    uint8_t  reserved [3];           /* Reserved field must be 0 */
> -} QEMU_PACKED;
> -typedef struct AcpiRsdpDescriptor AcpiRsdpDescriptor;
> -
>  typedef struct AcpiRsdpData {
>      uint8_t oem_id[6]; /* OEM identification */
>      uint8_t revision;  /* Must be 0 for 1.0, 2 for 2.0 */
> diff --git a/tests/acpi-utils.h b/tests/acpi-utils.h
> index ac52abd0dd..fb1a67a21f 100644
> --- a/tests/acpi-utils.h
> +++ b/tests/acpi-utils.h
> @@ -82,6 +82,9 @@ typedef struct {
>  
>  uint8_t acpi_calc_checksum(const uint8_t *data, int len);
>  uint32_t acpi_find_rsdp_address(void);
> -void acpi_parse_rsdp_table(uint32_t addr, AcpiRsdpDescriptor *rsdp_table);
> +uint32_t acpi_find_rsdt_address(uint8_t *rsdp_table);
> +uint64_t acpi_find_xsdt_address(uint8_t *rsdp_table);
> +void acpi_parse_rsdp_table(uint32_t addr, uint8_t *rsdp_table,
> +                           uint8_t revision);
>  
>  #endif  /* TEST_ACPI_UTILS_H */
> diff --git a/tests/acpi-utils.c b/tests/acpi-utils.c
> index 41dc1ea9b4..c8fe2d1342 100644
> --- a/tests/acpi-utils.c
> +++ b/tests/acpi-utils.c
> @@ -52,14 +52,44 @@ uint32_t acpi_find_rsdp_address(void)
>      return off;
>  }
>  
> -void acpi_parse_rsdp_table(uint32_t addr, AcpiRsdpDescriptor *rsdp_table)
> +uint32_t acpi_find_rsdt_address(uint8_t *rsdp_table)
s/acpi_find_rsdt_address/acpi_get_rsdt_address/
likewise for xsdt

>  {
> -    ACPI_READ_FIELD(rsdp_table->signature, addr);
> -    ACPI_ASSERT_CMP64(rsdp_table->signature, "RSD PTR ");
> -
> -    ACPI_READ_FIELD(rsdp_table->checksum, addr);
> -    ACPI_READ_ARRAY(rsdp_table->oem_id, addr);
> -    ACPI_READ_FIELD(rsdp_table->revision, addr);
> -    ACPI_READ_FIELD(rsdp_table->rsdt_physical_address, addr);
> -    ACPI_READ_FIELD(rsdp_table->length, addr);
> +    uint32_t rsdt_physical_address = *((uint32_t *)(rsdp_table +
> +                                                    ACPI_RSDP_RSDT_OFFSET));
above cast looks pretty ugly and on some hw it might trigger SIGBUS
maybe:

       memcpy(addr, &rsdp_table[16 /* RsdtAddress offset */], 4);

> +    uint8_t revision = rsdp_table[ACPI_RSDP_REVISION_OFFSET];
> +
> +    if (revision != ACPI_RSDP_REV_1) {
theoretically not rev1 might have rsdt pointer as well for legacy OS
but we don't do this in QEMU, so it doesn't really matter

> +        return 0;
> +    }
> +
> +    return le32_to_cpu(rsdt_physical_address);
> +}
> +
> +uint64_t acpi_find_xsdt_address(uint8_t *rsdp_table)
> +{
> +    uint64_t xsdt_physical_address = *((uint64_t *)(rsdp_table +
> +                                                    ACPI_RSDP_XSDT_OFFSET));
access to uninitialized data if not rev2,
here it's not harmful but it's better not to confuse tools and fetch value after revision check

> +    uint8_t revision = rsdp_table[ACPI_RSDP_REVISION_OFFSET];
> +
> +    if (revision != ACPI_RSDP_REV_2) {
> +        return 0;
> +    }
> +
> +    return le64_to_cpu(xsdt_physical_address);
> +}
> +
> +void acpi_parse_rsdp_table(uint32_t addr, uint8_t *rsdp_table, uint8_t revision)
> +{
> +    switch (revision) {
> +    case ACPI_RSDP_REV_1:
> +        memread(addr, rsdp_table, ACPI_RSDP_REV_1_LEN);
> +        break;
> +    case ACPI_RSDP_REV_2:
> +        memread(addr, rsdp_table, ACPI_RSDP_REV_2_LEN);
> +        break;
> +    default:
> +        g_assert_not_reached();
> +    }
> +
> +    ACPI_ASSERT_CMP64(*((uint64_t *)(rsdp_table)), ACPI_RSDP_SIGNATURE);
>  }
> diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c
> index d661d9be62..8cde404bda 100644
> --- a/tests/bios-tables-test.c
> +++ b/tests/bios-tables-test.c
> @@ -27,7 +27,8 @@ typedef struct {
>      const char *machine;
>      const char *variant;
>      uint32_t rsdp_addr;
> -    AcpiRsdpDescriptor rsdp_table;
> +    uint8_t rsdp_table[ACPI_RSDP_REV_2_LEN];
> +    uint32_t rsdt_physical_address;
>      AcpiRsdtDescriptorRev1 rsdt_table;
>      uint32_t dsdt_addr;
>      uint32_t facs_addr;
> @@ -83,21 +84,31 @@ static void test_acpi_rsdp_address(test_data *data)
>      data->rsdp_addr = off;
>  }
>  
> -static void test_acpi_rsdp_table(test_data *data)
> +static void test_acpi_rsdp_table(test_data *data, uint8_t revision)
>  {
> -    AcpiRsdpDescriptor *rsdp_table = &data->rsdp_table;
> +    uint8_t *rsdp_table = data->rsdp_table;
>      uint32_t addr = data->rsdp_addr;
>  
> -    acpi_parse_rsdp_table(addr, rsdp_table);
> +    acpi_parse_rsdp_table(addr, rsdp_table, revision);
>  
> -    /* rsdp checksum is not for the whole table, but for the first 20 bytes */
> -    g_assert(!acpi_calc_checksum((uint8_t *)rsdp_table, 20));
> +    switch (revision) {
> +    case ACPI_RSDP_REV_1:
> +        /* With rev 1, checksum is only for the first 20 bytes */
> +        g_assert(!acpi_calc_checksum(rsdp_table,  ACPI_RSDP_REV_1_LEN));
> +        break;
> +    case ACPI_RSDP_REV_2:
> +        /* With revision 2, we have 2 checksums */
> +        g_assert(!acpi_calc_checksum(rsdp_table, ACPI_RSDP_REV_1_LEN));
> +        g_assert(!acpi_calc_checksum(rsdp_table, ACPI_RSDP_REV_2_LEN));
> +    default:
> +        g_assert_not_reached();
> +    }
>  }
>  
>  static void test_acpi_rsdt_table(test_data *data)
>  {
>      AcpiRsdtDescriptorRev1 *rsdt_table = &data->rsdt_table;
> -    uint32_t addr = le32_to_cpu(data->rsdp_table.rsdt_physical_address);
> +    uint32_t addr = acpi_find_rsdt_address(data->rsdp_table);
>      uint32_t *tables;
>      int tables_nr;
>      uint8_t checksum;
> @@ -626,7 +637,7 @@ static void test_acpi_one(const char *params, test_data *data)
>  
>      data->tables = g_array_new(false, true, sizeof(AcpiSdtTable));
>      test_acpi_rsdp_address(data);
> -    test_acpi_rsdp_table(data);
> +    test_acpi_rsdp_table(data, ACPI_RSDP_REV_1);
>      test_acpi_rsdt_table(data);
>      fadt_fetch_facs_and_dsdt_ptrs(data);
>      test_acpi_facs_table(data);
> diff --git a/tests/vmgenid-test.c b/tests/vmgenid-test.c
> index 0a6fb55f2e..db5b084c18 100644
> --- a/tests/vmgenid-test.c
> +++ b/tests/vmgenid-test.c
> @@ -35,7 +35,7 @@ static uint32_t acpi_find_vgia(void)
>  {
>      uint32_t rsdp_offset;
>      uint32_t guid_offset = 0;
> -    AcpiRsdpDescriptor rsdp_table;
> +    uint8_t rsdp_table[ACPI_RSDP_REV_2_LEN];
>      uint32_t rsdt, rsdt_table_length;
>      AcpiRsdtDescriptorRev1 rsdt_table;
>      size_t tables_nr;
> @@ -52,9 +52,11 @@ static uint32_t acpi_find_vgia(void)
>  
>      g_assert_cmphex(rsdp_offset, <, RSDP_ADDR_INVALID);
>  
> -    acpi_parse_rsdp_table(rsdp_offset, &rsdp_table);
> +    acpi_parse_rsdp_table(rsdp_offset, rsdp_table, ACPI_RSDP_REV_1);
> +
> +    rsdt = acpi_find_rsdt_address(rsdp_table);
> +    g_assert(rsdt);
>  
> -    rsdt = le32_to_cpu(rsdp_table.rsdt_physical_address);
>      /* read the header */
>      ACPI_READ_TABLE_HEADER(&rsdt_table, rsdt);
>      ACPI_ASSERT_CMP(rsdt_table.signature, "RSDT");

      reply	other threads:[~2018-11-28  9:50 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-26 16:29 [Qemu-devel] [PATCH 0/8] hw: acpi: RSDP fixes and refactoring Samuel Ortiz
2018-11-26 16:29 ` [Qemu-devel] [PATCH 1/8] hw: acpi: The RSDP build API can return void Samuel Ortiz
2018-11-26 17:07   ` Philippe Mathieu-Daudé
2018-11-27 14:15   ` Thomas Huth
2018-11-26 16:29 ` [Qemu-devel] [PATCH 2/8] hw: arm: acpi: Fix incorrect checksums in RSDP Samuel Ortiz
2018-11-27 14:50   ` Igor Mammedov
2018-11-26 16:29 ` [Qemu-devel] [PATCH 3/8] hw: i386: Use correct RSDT length for checksum Samuel Ortiz
2018-11-26 16:29 ` [Qemu-devel] [PATCH 4/8] hw: arm: Carry RSDP specific data through AcpiRsdpData Samuel Ortiz
2018-11-26 17:42   ` Philippe Mathieu-Daudé
2018-11-27 15:25   ` Igor Mammedov
2018-11-27 15:42     ` Samuel Ortiz
2018-11-27 16:27       ` Igor Mammedov
2018-11-28  3:26         ` Michael S. Tsirkin
2018-11-28 10:05           ` Samuel Ortiz
2018-11-28  9:46         ` Samuel Ortiz
2018-11-28 10:16           ` Samuel Ortiz
2018-11-28 12:12           ` Igor Mammedov
2018-11-26 16:29 ` [Qemu-devel] [PATCH 5/8] hw: arm: Convert the RSDP build to the buid_append_foo() API Samuel Ortiz
2018-11-27 15:51   ` Igor Mammedov
2018-11-26 16:29 ` [Qemu-devel] [PATCH 6/8] hw: arm: Support both legacy and current RSDP build Samuel Ortiz
2018-11-27 16:38   ` Igor Mammedov
2018-11-26 16:29 ` [Qemu-devel] [PATCH 7/8] hw: acpi: Export and share the ARM " Samuel Ortiz
2018-11-26 17:19   ` Philippe Mathieu-Daudé
2018-11-26 16:29 ` [Qemu-devel] [PATCH 8/8] hw: acpi: Remove AcpiRsdpDescriptor and fix tests Samuel Ortiz
2018-11-28  9:50   ` Igor Mammedov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181128105038.592f50a0@redhat.com \
    --to=imammedo@redhat.com \
    --cc=ben@skyportsystems.com \
    --cc=ehabkost@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=sameo@linux.intel.com \
    --cc=shannon.zhaosl@gmail.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.