Skip to contentSkip to conversation

pc: acpi-build: make linker & RSDP tables dynamic

PATCH Superseded Igor Mammedov 3 participants 5 messages Jun 17, 2014 – Jun 18, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pc: acpi-build: make linker & RSDP tables dynamic

linker and RSDP tables are build only once, so if later during rebuild sizes of ACPI tables change pointers will be patched incorrectly due to wrong offsets.

To fix it rebuild linker and RSDP tables along with the rest of ACPI tables so that they would have correct offsets.

---
 hw/i386/acpi-build.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
hw/i386/acpi-build.c +14 -7
index fab25ad..8301bb4 100644
@@ -1862,6 +1862,10 @@ struct AcpiBuildState {
     /* Copy of table in RAM (for patching). */
     uint8_t *table_ram;
     uint32_t table_size;
+    uint8_t *linker_ram;
+    uint32_t linker_size;
+    uint8_t *rsdp_ram;
+    uint32_t rsdp_size;
     /* Is table patched? */
     uint8_t patched;
     PcGuestInfo *guest_info;
@@ -1998,6 +2002,10 @@ static void acpi_build_update(void *build_opaque, uint32_t offset)
     assert(acpi_data_len(tables.table_data) == build_state->table_size);
     memcpy(build_state->table_ram, tables.table_data->data,
            build_state->table_size);
+    memcpy(build_state->linker_ram, tables.linker->data,
+           build_state->linker_size);
+    memcpy(build_state->rsdp_ram, tables.rsdp->data,
+           build_state->rsdp_size);
 
     acpi_build_tables_cleanup(&tables, true);
 }
@@ -2060,14 +2068,13 @@ void acpi_setup(PcGuestInfo *guest_info)
                                                ACPI_BUILD_TABLE_FILE);
     build_state->table_size = acpi_data_len(tables.table_data);
 
-    acpi_add_rom_blob(NULL, tables.linker, "etc/table-loader");
+    build_state->linker_ram = acpi_add_rom_blob(build_state, tables.linker,
+                                                "etc/table-loader");
+    build_state->linker_size = acpi_data_len(tables.linker);
 
-    /*
-     * RSDP is small so it's easy to keep it immutable, no need to
-     * bother with ROM blobs.
-     */
-    fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_RSDP_FILE,
-                    tables.rsdp->data, acpi_data_len(tables.rsdp));
+    build_state->rsdp_ram = acpi_add_rom_blob(build_state, tables.rsdp,
+                                              ACPI_BUILD_RSDP_FILE);
+    build_state->rsdp_size = acpi_data_len(tables.rsdp);
 
     qemu_register_reset(acpi_build_reset, build_state);
     acpi_build_reset(build_state);
Signature · 1 line
1.9.3
#1 lore raw
Quoted 9 lines · Igor Mammedov

linker and RSDP tables are build only once, so if later during rebuild sizes of ACPI tables change pointers will be patched incorrectly due to wrong offsets.

To fix it rebuild linker and RSDP tables along with the rest of ACPI tables so that they would have correct offsets.

If you are adding a new blob you are breaking cross-version migration. Need to handle that depending on pc version as appropriate.

Quoted 53 lines
---
 hw/i386/acpi-build.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
hw/i386/acpi-build.c +14 -7
index fab25ad..8301bb4 100644
@@ -1862,6 +1862,10 @@ struct AcpiBuildState {
     /* Copy of table in RAM (for patching). */
     uint8_t *table_ram;
     uint32_t table_size;
+    uint8_t *linker_ram;
+    uint32_t linker_size;
+    uint8_t *rsdp_ram;
+    uint32_t rsdp_size;
     /* Is table patched? */
     uint8_t patched;
     PcGuestInfo *guest_info;
@@ -1998,6 +2002,10 @@ static void acpi_build_update(void *build_opaque, uint32_t offset)
     assert(acpi_data_len(tables.table_data) == build_state->table_size);
     memcpy(build_state->table_ram, tables.table_data->data,
            build_state->table_size);
+    memcpy(build_state->linker_ram, tables.linker->data,
+           build_state->linker_size);
+    memcpy(build_state->rsdp_ram, tables.rsdp->data,
+           build_state->rsdp_size);
 
     acpi_build_tables_cleanup(&tables, true);
 }
@@ -2060,14 +2068,13 @@ void acpi_setup(PcGuestInfo *guest_info)
                                                ACPI_BUILD_TABLE_FILE);
     build_state->table_size = acpi_data_len(tables.table_data);
 
-    acpi_add_rom_blob(NULL, tables.linker, "etc/table-loader");
+    build_state->linker_ram = acpi_add_rom_blob(build_state, tables.linker,
+                                                "etc/table-loader");
+    build_state->linker_size = acpi_data_len(tables.linker);
 
-    /*
-     * RSDP is small so it's easy to keep it immutable, no need to
-     * bother with ROM blobs.
-     */
-    fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_RSDP_FILE,
-                    tables.rsdp->data, acpi_data_len(tables.rsdp));
+    build_state->rsdp_ram = acpi_add_rom_blob(build_state, tables.rsdp,
+                                              ACPI_BUILD_RSDP_FILE);
+    build_state->rsdp_size = acpi_data_len(tables.rsdp);
 
     qemu_register_reset(acpi_build_reset, build_state);
     acpi_build_reset(build_state);
Signature · 1 line
1.9.3
Tested-by Reviewed-by
#2 lore raw
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Igor Mammedov

linker and RSDP tables are build only once, so if later during rebuild sizes of ACPI tables change pointers will be patched incorrectly due to wrong offsets.

Quoted 8 lines
Quoted 5 lines

To fix it rebuild linker and RSDP tables along with the rest of ACPI tables so that they would have correct offsets.

If you are adding a new blob you are breaking cross-version migration. Need to handle that depending on pc version as appropriate.

Besides the above comment,

Thanks,
Marcel

Quoted 54 lines
Quoted 54 lines
---
 hw/i386/acpi-build.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
hw/i386/acpi-build.c +14 -7
index fab25ad..8301bb4 100644
@@ -1862,6 +1862,10 @@ struct AcpiBuildState {
     /* Copy of table in RAM (for patching). */
     uint8_t *table_ram;
     uint32_t table_size;
+    uint8_t *linker_ram;
+    uint32_t linker_size;
+    uint8_t *rsdp_ram;
+    uint32_t rsdp_size;
     /* Is table patched? */
     uint8_t patched;
     PcGuestInfo *guest_info;
@@ -1998,6 +2002,10 @@ static void acpi_build_update(void *build_opaque, uint32_t offset)
     assert(acpi_data_len(tables.table_data) == build_state->table_size);
     memcpy(build_state->table_ram, tables.table_data->data,
            build_state->table_size);
+    memcpy(build_state->linker_ram, tables.linker->data,
+           build_state->linker_size);
+    memcpy(build_state->rsdp_ram, tables.rsdp->data,
+           build_state->rsdp_size);
 
     acpi_build_tables_cleanup(&tables, true);
 }
@@ -2060,14 +2068,13 @@ void acpi_setup(PcGuestInfo *guest_info)
                                                ACPI_BUILD_TABLE_FILE);
     build_state->table_size = acpi_data_len(tables.table_data);
 
-    acpi_add_rom_blob(NULL, tables.linker, "etc/table-loader");
+    build_state->linker_ram = acpi_add_rom_blob(build_state, tables.linker,
+                                                "etc/table-loader");
+    build_state->linker_size = acpi_data_len(tables.linker);
 
-    /*
-     * RSDP is small so it's easy to keep it immutable, no need to
-     * bother with ROM blobs.
-     */
-    fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_RSDP_FILE,
-                    tables.rsdp->data, acpi_data_len(tables.rsdp));
+    build_state->rsdp_ram = acpi_add_rom_blob(build_state, tables.rsdp,
+                                              ACPI_BUILD_RSDP_FILE);
+    build_state->rsdp_size = acpi_data_len(tables.rsdp);
 
     qemu_register_reset(acpi_build_reset, build_state);
     acpi_build_reset(build_state);
Signature · 1 line
1.9.3
#3 lore raw
Quoted 12 lines · Marcel Apfelbaum
Quoted 11 lines · Michael S. Tsirkin
Quoted 9 lines · Igor Mammedov

linker and RSDP tables are build only once, so if later during rebuild sizes of ACPI tables change pointers will be patched incorrectly due to wrong offsets.

To fix it rebuild linker and RSDP tables along with the rest of ACPI tables so that they would have correct offsets.

Quoted 8 lines
Quoted 2 lines

If you are adding a new blob you are breaking cross-version migration. Need to handle that depending on pc version as appropriate.

Besides the above comment,

Thanks,
Marcel

This will need a bit more motivation to go in than is provided here.

Quoted 56 lines
Quoted 54 lines
Quoted 54 lines
---
 hw/i386/acpi-build.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
hw/i386/acpi-build.c +14 -7
index fab25ad..8301bb4 100644
@@ -1862,6 +1862,10 @@ struct AcpiBuildState {
     /* Copy of table in RAM (for patching). */
     uint8_t *table_ram;
     uint32_t table_size;
+    uint8_t *linker_ram;
+    uint32_t linker_size;
+    uint8_t *rsdp_ram;
+    uint32_t rsdp_size;
     /* Is table patched? */
     uint8_t patched;
     PcGuestInfo *guest_info;
@@ -1998,6 +2002,10 @@ static void acpi_build_update(void *build_opaque, uint32_t offset)
     assert(acpi_data_len(tables.table_data) == build_state->table_size);
     memcpy(build_state->table_ram, tables.table_data->data,
            build_state->table_size);
+    memcpy(build_state->linker_ram, tables.linker->data,
+           build_state->linker_size);
+    memcpy(build_state->rsdp_ram, tables.rsdp->data,
+           build_state->rsdp_size);
 
     acpi_build_tables_cleanup(&tables, true);
 }
@@ -2060,14 +2068,13 @@ void acpi_setup(PcGuestInfo *guest_info)
                                                ACPI_BUILD_TABLE_FILE);
     build_state->table_size = acpi_data_len(tables.table_data);
 
-    acpi_add_rom_blob(NULL, tables.linker, "etc/table-loader");
+    build_state->linker_ram = acpi_add_rom_blob(build_state, tables.linker,
+                                                "etc/table-loader");
+    build_state->linker_size = acpi_data_len(tables.linker);
 
-    /*
-     * RSDP is small so it's easy to keep it immutable, no need to
-     * bother with ROM blobs.
-     */
-    fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_RSDP_FILE,
-                    tables.rsdp->data, acpi_data_len(tables.rsdp));
+    build_state->rsdp_ram = acpi_add_rom_blob(build_state, tables.rsdp,
+                                              ACPI_BUILD_RSDP_FILE);
+    build_state->rsdp_size = acpi_data_len(tables.rsdp);
 
     qemu_register_reset(acpi_build_reset, build_state);
     acpi_build_reset(build_state);
Signature · 1 line
1.9.3
#4 lore raw
Quoted 19 lines · On Wed, 18 Jun 2014 12:19:10 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 18 lines · Marcel Apfelbaum
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Igor Mammedov

linker and RSDP tables are build only once, so if later during rebuild sizes of ACPI tables change pointers will be patched incorrectly due to wrong offsets.

Quoted 8 lines
Quoted 5 lines

To fix it rebuild linker and RSDP tables along with the rest of ACPI tables so that they would have correct offsets.

If you are adding a new blob you are breaking cross-version migration. Need to handle that depending on pc version as appropriate.

Besides the above comment,

Quoted 5 lines
Quoted 2 lines

Thanks,
Marcel

This will need a bit more motivation to go in than is provided here.

I'll address comment above and also will dig up example why it was needed in a month old dynamic ACPI tables series.

Quoted 58 lines
Quoted 57 lines
Quoted 55 lines
Quoted 55 lines

---
 hw/i386/acpi-build.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
hw/i386/acpi-build.c +14 -7
index fab25ad..8301bb4 100644
@@ -1862,6 +1862,10 @@ struct AcpiBuildState {
     /* Copy of table in RAM (for patching). */
     uint8_t *table_ram;
     uint32_t table_size;
+    uint8_t *linker_ram;
+    uint32_t linker_size;
+    uint8_t *rsdp_ram;
+    uint32_t rsdp_size;
     /* Is table patched? */
     uint8_t patched;
     PcGuestInfo *guest_info;
@@ -1998,6 +2002,10 @@ static void acpi_build_update(void *build_opaque, uint32_t offset)
     assert(acpi_data_len(tables.table_data) == build_state->table_size);
     memcpy(build_state->table_ram, tables.table_data->data,
            build_state->table_size);
+    memcpy(build_state->linker_ram, tables.linker->data,
+           build_state->linker_size);
+    memcpy(build_state->rsdp_ram, tables.rsdp->data,
+           build_state->rsdp_size);
 
     acpi_build_tables_cleanup(&tables, true);
 }
@@ -2060,14 +2068,13 @@ void acpi_setup(PcGuestInfo *guest_info)
                                                ACPI_BUILD_TABLE_FILE);
     build_state->table_size = acpi_data_len(tables.table_data);
 
-    acpi_add_rom_blob(NULL, tables.linker, "etc/table-loader");
+    build_state->linker_ram = acpi_add_rom_blob(build_state, tables.linker,
+                                                "etc/table-loader");
+    build_state->linker_size = acpi_data_len(tables.linker);
 
-    /*
-     * RSDP is small so it's easy to keep it immutable, no need to
-     * bother with ROM blobs.
-     */
-    fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_RSDP_FILE,
-                    tables.rsdp->data, acpi_data_len(tables.rsdp));
+    build_state->rsdp_ram = acpi_add_rom_blob(build_state, tables.rsdp,
+                                              ACPI_BUILD_RSDP_FILE);
+    build_state->rsdp_size = acpi_data_len(tables.rsdp);
 
     qemu_register_reset(acpi_build_reset, build_state);
     acpi_build_reset(build_state);
Signature · 1 line
1.9.3