Skip to contentSkip to conversation

tools/libacpi: fix boot flags passed to PVHv2 guests

PATCH In review Roger Pau Monne 3 participants 7 messages Dec 12, 2016 – Dec 13, 2016

lore
Share & tools
lore
#0 lore raw

v4 cover tools/libacpi: fix boot flags passed to PVHv2 guests

Hello,

Those are the remaining two patches in the series, the first one adds supports for FADT v5 to libacpi, and the second one introduces the usage of the FADT no RTC boot flag for PVHv2 guests. Note that ACPI tables for HVM guests should remain unmodified.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#1 lore raw

PATCH v4 1/2 tools/libacpi: update FADT layout to support version 5

Update the structure of the FADT table to version 5, and use that version for PVHv2 guests. Note that HVM guests will continue to use FADT 4. In order to do this, add a new field to acpi_config that contains the ACPI revision to use by libacpi. Note that currently this only applies to the FADT.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
Changes since v3:
- Add a new field to acpi_config that contains the ACPI revision to use.
- Rename acpi_50_fadt acpi_fadt.
- Make fadt_size unsigned int.
- Don't pre-initialize the length and revision fields of the Fadt static table.
- Rebase on top of staging.

---
 tools/firmware/hvmloader/util.c |  1 +
 tools/libacpi/acpi2_0.h         |  8 +++++---
 tools/libacpi/build.c           | 35 ++++++++++++++++++++++++++++-------
 tools/libacpi/libacpi.h         |  1 +
 tools/libacpi/static_tables.c   |  6 ++----
 tools/libxl/libxl_x86_acpi.c    |  1 +
 6 files changed, 38 insertions(+), 14 deletions(-)
tools/firmware/hvmloader/util.c +1 -0
index c05de53..f2bec51 100644
@@ -952,6 +952,7 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
                             ACPI_HAS_WAET | ACPI_HAS_PMTIMER |
                             ACPI_HAS_BUTTONS | ACPI_HAS_VGA |
                             ACPI_HAS_8042);
+    config->acpi_revision = 4;
 
     config->tis_hdr = (uint16_t *)ACPI_TIS_HDR_ADDRESS;
 
tools/libacpi/acpi2_0.h +5 -3
index 500f95e..5715197 100644
@@ -169,7 +169,7 @@ struct acpi_10_fadt {
 /*
  * Fixed ACPI Description Table Structure (FADT).
  */
-struct acpi_20_fadt {
+struct acpi_fadt {
     struct acpi_header header;
     uint32_t firmware_ctrl;
     uint32_t dsdt;
@@ -222,6 +222,9 @@ struct acpi_20_fadt {
     struct acpi_20_generic_address x_pm_tmr_blk;
     struct acpi_20_generic_address x_gpe0_blk;
     struct acpi_20_generic_address x_gpe1_blk;
+    /* Only available starting from FADT revision 5. */
+    struct acpi_20_generic_address sleep_control;
+    struct acpi_20_generic_address sleep_status;
 };
 
 /*
@@ -422,7 +425,7 @@ struct acpi_20_slit {
  */
 #define ACPI_2_0_RSDP_SIGNATURE ASCII64('R','S','D',' ','P','T','R',' ')
 #define ACPI_2_0_FACS_SIGNATURE ASCII32('F','A','C','S')
-#define ACPI_2_0_FADT_SIGNATURE ASCII32('F','A','C','P')
+#define ACPI_FADT_SIGNATURE     ASCII32('F','A','C','P')
 #define ACPI_2_0_MADT_SIGNATURE ASCII32('A','P','I','C')
 #define ACPI_2_0_RSDT_SIGNATURE ASCII32('R','S','D','T')
 #define ACPI_2_0_XSDT_SIGNATURE ASCII32('X','S','D','T')
@@ -436,7 +439,6 @@ struct acpi_20_slit {
  * Table revision numbers.
  */
 #define ACPI_2_0_RSDP_REVISION 0x02
-#define ACPI_2_0_FADT_REVISION 0x04
 #define ACPI_2_0_MADT_REVISION 0x02
 #define ACPI_2_0_RSDT_REVISION 0x01
 #define ACPI_2_0_XSDT_REVISION 0x01
tools/libacpi/build.c +28 -7
index 2bdfaab..6bd50b3 100644
@@ -33,7 +33,7 @@
 extern struct acpi_20_rsdp Rsdp;
 extern struct acpi_20_rsdt Rsdt;
 extern struct acpi_20_xsdt Xsdt;
-extern struct acpi_20_fadt Fadt;
+extern struct acpi_fadt Fadt;
 extern struct acpi_20_facs Facs;
 extern struct acpi_20_waet Waet;
 
@@ -503,12 +503,13 @@ int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config)
     struct acpi_20_rsdp *rsdp;
     struct acpi_20_rsdt *rsdt;
     struct acpi_20_xsdt *xsdt;
-    struct acpi_20_fadt *fadt;
+    struct acpi_fadt    *fadt;
     struct acpi_10_fadt *fadt_10;
     struct acpi_20_facs *facs;
     unsigned char       *dsdt;
     unsigned long        secondary_tables[ACPI_MAX_SECONDARY_TABLES];
     int                  nr_secondaries, i;
+    unsigned int         fadt_size;
 
     acpi_info = (struct acpi_info *)config->infop;
     memset(acpi_info, 0, sizeof(*acpi_info));
@@ -572,7 +573,23 @@ int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config)
                  offsetof(struct acpi_header, checksum),
                  sizeof(struct acpi_10_fadt));
 
-    fadt = ctxt->mem_ops.alloc(ctxt, sizeof(struct acpi_20_fadt), 16);
+    switch ( config->acpi_revision )
+    {
+    case 4:
+        /*
+         * NB: we can use offsetof because there's no padding between
+         * x_gpe1_blk and sleep_control.
+         */
+        fadt_size = offsetof(struct acpi_fadt, sleep_control);
+        break;
+    case 5:
+        fadt_size = sizeof(*fadt);
+        break;
+    default:
+        printf("ACPI revision %u not supported\n", config->acpi_revision);
+        return -1;
+    }
+    fadt = ctxt->mem_ops.alloc(ctxt, fadt_size, 16);
     if (!fadt) goto oom;
     if ( !(config->table_flags & ACPI_HAS_PMTIMER) )
     {
@@ -581,7 +598,13 @@ int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config)
     }
     if ( !(config->table_flags & ACPI_HAS_BUTTONS) )
         Fadt.flags |= (ACPI_PWR_BUTTON | ACPI_SLP_BUTTON);
-    memcpy(fadt, &Fadt, sizeof(struct acpi_20_fadt));
+    memcpy(fadt, &Fadt, fadt_size);
+    /*
+     * For both ACPI 4 and 5 the revision of the FADT matches the ACPI
+     * revision.
+     */
+    fadt->header.revision = config->acpi_revision;
+    fadt->header.length = fadt_size;
     fadt->dsdt   = ctxt->mem_ops.v2p(ctxt, dsdt);
     fadt->x_dsdt = ctxt->mem_ops.v2p(ctxt, dsdt);
     fadt->firmware_ctrl   = ctxt->mem_ops.v2p(ctxt, facs);
@@ -590,9 +613,7 @@ int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config)
         fadt->iapc_boot_arch |= ACPI_FADT_NO_VGA;
     if ( config->table_flags & ACPI_HAS_8042 )
         fadt->iapc_boot_arch |= ACPI_FADT_8042;
-    set_checksum(fadt,
-                 offsetof(struct acpi_header, checksum),
-                 sizeof(struct acpi_20_fadt));
+    set_checksum(fadt, offsetof(struct acpi_header, checksum), fadt_size);
 
     nr_secondaries = construct_secondary_tables(ctxt, secondary_tables,
                  config, acpi_info);
tools/libacpi/libacpi.h +1 -0
index db2d7b2..dbc6c8b 100644
@@ -63,6 +63,7 @@ struct acpi_config {
     uint64_t pci_hi_start, pci_hi_len;
 
     uint32_t table_flags;
+    uint8_t acpi_revision;
 
     uint64_t vm_gid[2];
     unsigned long vm_gid_addr; /* OUT parameter */
tools/libacpi/static_tables.c +2 -4
index 1f6247d..13946aa 100644
@@ -38,11 +38,9 @@ struct acpi_20_facs Facs = {
 #define ACPI_PM_TMR_BLK_BIT_WIDTH           0x20
 #define ACPI_PM_TMR_BLK_BIT_OFFSET          0x00
 
-struct acpi_20_fadt Fadt = {
+struct acpi_fadt Fadt = {
     .header = {
-        .signature    = ACPI_2_0_FADT_SIGNATURE,
-        .length       = sizeof(struct acpi_20_fadt),
-        .revision     = ACPI_2_0_FADT_REVISION,
+        .signature    = ACPI_FADT_SIGNATURE,
         .oem_id       = ACPI_OEM_ID, 
         .oem_table_id = ACPI_OEM_TABLE_ID,
         .oem_revision = ACPI_OEM_REVISION,
tools/libxl/libxl_x86_acpi.c +1 -0
index ff0e2df..686ac8e 100644
@@ -151,6 +151,7 @@ static int init_acpi_config(libxl__gc *gc,
 
     config->lapic_base_address = LAPIC_BASE_ADDRESS;
     config->lapic_id = acpi_lapic_id;
+    config->acpi_revision = 5;
 
 out:
     return 0;
Signature · 7 lines
2.9.3 (Apple Git-75)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v4 1/2
#2 lore raw

Re: [PATCH v4 1/2] tools/libacpi: update FADT layout to support version 5

Quoted 20 lines · Roger Pau Monne

Update the structure of the FADT table to version 5, and use that version for PVHv2 guests. Note that HVM guests will continue to use FADT 4. In order to do this, add a new field to acpi_config that contains the ACPI revision to use by libacpi. Note that currently this only applies to the FADT.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
Changes since v3:
- Add a new field to acpi_config that contains the ACPI revision to use.
- Rename acpi_50_fadt acpi_fadt.
- Make fadt_size unsigned int.
- Don't pre-initialize the length and revision fields of the Fadt static table.
- Rebase on top of staging.

Quoted 7 lines
---
 tools/firmware/hvmloader/util.c |  1 +
 tools/libacpi/acpi2_0.h         |  8 +++++---
 tools/libacpi/build.c           | 35 ++++++++++++++++++++++++++++-------
 tools/libacpi/libacpi.h         |  1 +
 tools/libacpi/static_tables.c   |  6 ++----
 tools/libxl/libxl_x86_acpi.c    |  1 +

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH v4 1/2] tools/libacpi: update FADT layout to support version 5

In reply to Roger Pau Monne
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 12.12.16 at 17:04, <[email protected]> wrote:

Update the structure of the FADT table to version 5, and use that version for PVHv2 guests. Note that HVM guests will continue to use FADT 4. In order to do this, add a new field to acpi_config that contains the ACPI revision to use by libacpi. Note that currently this only applies to the FADT.

To be honest I'm of two minds here. On one hand the patch is fine as is for the immediate purpose. On the other hand I would have hoped for a little more complete handling of this:
- The spec is at version 6.1 - I don't see why we should give anything less to PVHv2 guests, causing possible compatibility issues going forward.
- The version consists of both a major and a minor part, yet no provisions are being made to allow for this.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw

Re: [PATCH v4 1/2] tools/libacpi: update FADT layout to support version 5

Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 12.12.16 at 17:04, <[email protected]> wrote:

Update the structure of the FADT table to version 5, and use that version for PVHv2 guests. Note that HVM guests will continue to use FADT 4. In order to do this, add a new field to acpi_config that contains the ACPI revision to use by libacpi. Note that currently this only applies to the FADT.

Quoted 8 lines
Quoted 1 line

To be honest I'm of two minds here. On one hand the patch is fine as is for the immediate purpose. On the other hand I would have hoped for a little more complete handling of this:
- The spec is at version 6.1 - I don't see why we should give anything less to PVHv2 guests, causing possible compatibility issues going forward.

I'm not opposed to bumping the ACPI version to 6.1, it's just that this needs to be properly done IMHO, and I would like to see all tables bumped to the revision specified in 6.1. This is the minor bump needed in order to use the no RTC flag, so I feel it's safer, and other tables should not get that much off-sync compared to FADT.

Quoted 2 lines

- The version consists of both a major and a minor part, yet no provisions are being made to allow for this.

Given the nature of this "fix" (which initially only focused on being able to use the no RTC flag) I didn't see the need to introduce the minor version. TBH, the FADT field used for the minor version is still marked as "reserved" in our current layout. I would prefer that to be done in a proper patch series that fixes all this minor issues and properly bumps the version to 6.1.

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw

PATCH v4 2/2 tools/libacpi: announce that PVHv2 has no CMOS RTC in FADT

In reply to Roger Pau Monne

At the moment this flag is unconditionally set for PVHv2 domains. Note that using this boot flag requires that the FADT table revision is at least 5 (or any later version), so bump the current FADT version from 4 to 5 and add two new fields that will be unused.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
Changes since v3:
- Rebase on top of previous patch.
---
Ideally this should be somehow fetched from the emulation_flags set of flags, but sadly there's no way for hvmloader (which runs in guest context) to fetch this information. If at some point a rtc option is added to libxl, we should see about passing it through to init_acpi_config in libxl_x86_acpi.c so that we can then appropriately set this flag for PVHv2 guests.

---
 tools/firmware/hvmloader/util.c | 2 +-
 tools/libacpi/acpi2_0.h         | 1 +
 tools/libacpi/build.c           | 9 +++++++++
 tools/libacpi/libacpi.h         | 1 +
 4 files changed, 12 insertions(+), 1 deletion(-)
tools/firmware/hvmloader/util.c +1 -1
index f2bec51..03cfb79 100644
@@ -951,7 +951,7 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
     config->table_flags |= (ACPI_HAS_TCPA | ACPI_HAS_IOAPIC |
                             ACPI_HAS_WAET | ACPI_HAS_PMTIMER |
                             ACPI_HAS_BUTTONS | ACPI_HAS_VGA |
-                            ACPI_HAS_8042);
+                            ACPI_HAS_8042 | ACPI_HAS_CMOS_RTC);
     config->acpi_revision = 4;
 
     config->tis_hdr = (uint16_t *)ACPI_TIS_HDR_ADDRESS;
tools/libacpi/acpi2_0.h +1 -0
index 5715197..2619ba3 100644
@@ -233,6 +233,7 @@ struct acpi_fadt {
 #define ACPI_FADT_LEGACY_DEVICES    (1 << 0)
 #define ACPI_FADT_8042              (1 << 1)
 #define ACPI_FADT_NO_VGA            (1 << 2)
+#define ACPI_FADT_NO_CMOS_RTC       (1 << 5)
 
 /*
  * FADT Fixed Feature Flags.
tools/libacpi/build.c +9 -0
index 6bd50b3..a02ffbf 100644
@@ -613,6 +613,15 @@ int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config)
         fadt->iapc_boot_arch |= ACPI_FADT_NO_VGA;
     if ( config->table_flags & ACPI_HAS_8042 )
         fadt->iapc_boot_arch |= ACPI_FADT_8042;
+    if ( !(config->table_flags & ACPI_HAS_CMOS_RTC) )
+    {
+        if ( fadt->header.revision < 5 )
+        {
+            printf("ACPI_FADT_NO_CMOS_RTC requires FADT revision 5\n");
+            return -1;
+        }
+        fadt->iapc_boot_arch |= ACPI_FADT_NO_CMOS_RTC;
+    }
     set_checksum(fadt, offsetof(struct acpi_header, checksum), fadt_size);
 
     nr_secondaries = construct_secondary_tables(ctxt, secondary_tables,
tools/libacpi/libacpi.h +1 -0
index dbc6c8b..67bd67f 100644
@@ -34,6 +34,7 @@
 #define ACPI_HAS_BUTTONS     (1<<11)
 #define ACPI_HAS_VGA         (1<<12)
 #define ACPI_HAS_8042        (1<<13)
+#define ACPI_HAS_CMOS_RTC    (1<<14)
 
 struct xen_vmemrange;
 struct acpi_numa {
Signature · 7 lines
2.9.3 (Apple Git-75)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v4 2/2
#6 lore raw

Re: [PATCH v4 2/2] tools/libacpi: announce that PVHv2 has no CMOS RTC in FADT

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 12.12.16 at 17:04, <[email protected]> wrote:

At the moment this flag is unconditionally set for PVHv2 domains. Note that using this boot flag requires that the FADT table revision is at least 5 (or any later version), so bump the current FADT version from 4 to 5 and add two new fields that will be unused.

That last part is now stale, but could easily be dropped while committing (pending resolution of my uncertainty on patch 1).

Quoted 2 lines

With that adjustment

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel