Skip to contentSkip to conversation

acpi: Use apic_id_limit when calculating legacy ACPI table size

PATCH In review Eduardo Habkost 2 participants 3 messages Nov 11, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 acpi: Use apic_id_limit when calculating legacy ACPI table size

The code that calculates the legacy ACPI table size for migration compatibility uses max_cpus when calculating legacy_aml_len (the size of the DSDT and SSDT tables). However, the SSDT grows according to APIC ID limit, not max_cpus.

The bug is not triggered very often because of the 4k alignment on the table size. But it can be triggered if you are unlucky enough to cross a 4k boundary.

Change the legacy_aml_len calculation to use apic_id_limit, to calculate the right size.

---
This patch was submitted in 2014 and reviewed by Paolo. Only today I noticed that it was never merged.

Changes v1 -> v2:
* Use pcms->apic_id_limit, as guest_info doesn't exist anymore

---
 hw/i386/acpi-build.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/acpi-build.c +1 -1
index c02f408..bb66446 100644
@@ -2859,7 +2859,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
          */
         int legacy_aml_len =
             pcmc->legacy_acpi_table_size +
-            ACPI_BUILD_LEGACY_CPU_AML_SIZE * max_cpus;
+            ACPI_BUILD_LEGACY_CPU_AML_SIZE * pcms->apic_id_limit;
         int legacy_table_size =
             ROUND_UP(tables_blob->len - aml_len + legacy_aml_len,
                      ACPI_BUILD_ALIGN_SIZE);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 5 lines · Eduardo Habkost

The code that calculates the legacy ACPI table size for migration compatibility uses max_cpus when calculating legacy_aml_len (the size of the DSDT and SSDT tables). However, the SSDT grows according to APIC ID limit, not max_cpus.

Quoted 8 lines

The bug is not triggered very often because of the 4k alignment on the table size. But it can be triggered if you are unlucky enough to cross a 4k boundary.

Change the legacy_aml_len calculation to use apic_id_limit, to calculate the right size.

Does this affect migration in some way?

Quoted 25 lines

---
This patch was submitted in 2014 and reviewed by Paolo. Only today I noticed that it was never merged.

Changes v1 -> v2:
* Use pcms->apic_id_limit, as guest_info doesn't exist anymore

---
 hw/i386/acpi-build.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/acpi-build.c +1 -1
index c02f408..bb66446 100644
@@ -2859,7 +2859,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
          */
         int legacy_aml_len =
             pcmc->legacy_acpi_table_size +
-            ACPI_BUILD_LEGACY_CPU_AML_SIZE * max_cpus;
+            ACPI_BUILD_LEGACY_CPU_AML_SIZE * pcms->apic_id_limit;
         int legacy_table_size =
             ROUND_UP(tables_blob->len - aml_len + legacy_aml_len,
                      ACPI_BUILD_ALIGN_SIZE);
Signature · 1 line
2.7.4
#2 lore raw
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Eduardo Habkost

The code that calculates the legacy ACPI table size for migration compatibility uses max_cpus when calculating legacy_aml_len (the size of the DSDT and SSDT tables). However, the SSDT grows according to APIC ID limit, not max_cpus.

The bug is not triggered very often because of the 4k alignment on the table size. But it can be triggered if you are unlucky enough to cross a 4k boundary.

Quoted 6 lines
Quoted 4 lines

Change the legacy_aml_len calculation to use apic_id_limit, to calculate the right size.

Does this affect migration in some way?

It affects migration in the same way that a wrong PCMachineClass::legacy_acpi_table_size value would. (I don't know what are the exact symptoms when the sizes are wrong)

In 2014 I could even trigger the "Warning: migration may not work." message before applying this fix, I think it was because the difference between aml_len and legacy_aml_len was smaller. But something changed in between and the effects of the wrong size calculation are harder to see.

Quoted 26 lines
Quoted 26 lines

---
This patch was submitted in 2014 and reviewed by Paolo. Only today I noticed that it was never merged.

Changes v1 -> v2:
* Use pcms->apic_id_limit, as guest_info doesn't exist anymore

---
 hw/i386/acpi-build.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/acpi-build.c +1 -1
index c02f408..bb66446 100644
@@ -2859,7 +2859,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
          */
         int legacy_aml_len =
             pcmc->legacy_acpi_table_size +
-            ACPI_BUILD_LEGACY_CPU_AML_SIZE * max_cpus;
+            ACPI_BUILD_LEGACY_CPU_AML_SIZE * pcms->apic_id_limit;
         int legacy_table_size =
             ROUND_UP(tables_blob->len - aml_len + legacy_aml_len,
                      ACPI_BUILD_ALIGN_SIZE);
Signature · 1 line
2.7.4
Signature · 1 line
Eduardo