acpi-build: fix ACPI RAM management
This fixes multiple issues around ACPI RAM management: RSDP and linker RAM aren't currently marked dirty on update, so they won't be migrated correctly. Let's handle all tables in the same way: set correct size (assert if too big), update, mark RAM dirty. This also drops assert checking that table size didn't change: table size is fundamentally dynamic and depends on hw configuration, just set the correct size and use that (memory core asserts if size is too large). This also means we can drop tracking table size, memory core does this for us now. Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
129ddaf31b
commit
42d859001d
|
@ -1363,13 +1363,12 @@ typedef
|
||||||
struct AcpiBuildState {
|
struct AcpiBuildState {
|
||||||
/* Copy of table in RAM (for patching). */
|
/* Copy of table in RAM (for patching). */
|
||||||
ram_addr_t table_ram;
|
ram_addr_t table_ram;
|
||||||
uint32_t table_size;
|
|
||||||
/* Is table patched? */
|
/* Is table patched? */
|
||||||
uint8_t patched;
|
uint8_t patched;
|
||||||
PcGuestInfo *guest_info;
|
PcGuestInfo *guest_info;
|
||||||
void *rsdp;
|
void *rsdp;
|
||||||
|
ram_addr_t rsdp_ram;
|
||||||
ram_addr_t linker_ram;
|
ram_addr_t linker_ram;
|
||||||
uint32_t linker_size;
|
|
||||||
} AcpiBuildState;
|
} AcpiBuildState;
|
||||||
|
|
||||||
static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
|
static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
|
||||||
|
@ -1552,6 +1551,17 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
|
||||||
g_array_free(table_offsets, true);
|
g_array_free(table_offsets, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void acpi_ram_update(ram_addr_t ram, GArray *data)
|
||||||
|
{
|
||||||
|
uint32_t size = acpi_data_len(data);
|
||||||
|
|
||||||
|
/* Make sure RAM size is correct - in case it got changed e.g. by migration */
|
||||||
|
qemu_ram_resize(ram, size, &error_abort);
|
||||||
|
|
||||||
|
memcpy(qemu_get_ram_ptr(ram), data->data, size);
|
||||||
|
cpu_physical_memory_set_dirty_range_nocode(ram, size);
|
||||||
|
}
|
||||||
|
|
||||||
static void acpi_build_update(void *build_opaque, uint32_t offset)
|
static void acpi_build_update(void *build_opaque, uint32_t offset)
|
||||||
{
|
{
|
||||||
AcpiBuildState *build_state = build_opaque;
|
AcpiBuildState *build_state = build_opaque;
|
||||||
|
@ -1567,21 +1577,15 @@ static void acpi_build_update(void *build_opaque, uint32_t offset)
|
||||||
|
|
||||||
acpi_build(build_state->guest_info, &tables);
|
acpi_build(build_state->guest_info, &tables);
|
||||||
|
|
||||||
assert(acpi_data_len(tables.table_data) == build_state->table_size);
|
acpi_ram_update(build_state->table_ram, tables.table_data);
|
||||||
|
|
||||||
/* Make sure RAM size is correct - in case it got changed by migration */
|
if (build_state->rsdp) {
|
||||||
qemu_ram_resize(build_state->table_ram, build_state->table_size,
|
memcpy(build_state->rsdp, tables.rsdp->data, acpi_data_len(tables.rsdp));
|
||||||
&error_abort);
|
} else {
|
||||||
|
acpi_ram_update(build_state->rsdp_ram, tables.rsdp);
|
||||||
memcpy(qemu_get_ram_ptr(build_state->table_ram), tables.table_data->data,
|
}
|
||||||
build_state->table_size);
|
|
||||||
memcpy(build_state->rsdp, tables.rsdp->data, acpi_data_len(tables.rsdp));
|
|
||||||
memcpy(qemu_get_ram_ptr(build_state->linker_ram), tables.linker->data,
|
|
||||||
build_state->linker_size);
|
|
||||||
|
|
||||||
cpu_physical_memory_set_dirty_range_nocode(build_state->table_ram,
|
|
||||||
build_state->table_size);
|
|
||||||
|
|
||||||
|
acpi_ram_update(build_state->linker_ram, tables.linker);
|
||||||
acpi_build_tables_cleanup(&tables, true);
|
acpi_build_tables_cleanup(&tables, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1642,11 +1646,9 @@ void acpi_setup(PcGuestInfo *guest_info)
|
||||||
ACPI_BUILD_TABLE_FILE,
|
ACPI_BUILD_TABLE_FILE,
|
||||||
ACPI_BUILD_TABLE_MAX_SIZE);
|
ACPI_BUILD_TABLE_MAX_SIZE);
|
||||||
assert(build_state->table_ram != RAM_ADDR_MAX);
|
assert(build_state->table_ram != RAM_ADDR_MAX);
|
||||||
build_state->table_size = acpi_data_len(tables.table_data);
|
|
||||||
|
|
||||||
build_state->linker_ram =
|
build_state->linker_ram =
|
||||||
acpi_add_rom_blob(build_state, tables.linker, "etc/table-loader", 0);
|
acpi_add_rom_blob(build_state, tables.linker, "etc/table-loader", 0);
|
||||||
build_state->linker_size = acpi_data_len(tables.linker);
|
|
||||||
|
|
||||||
fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_TPMLOG_FILE,
|
fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_TPMLOG_FILE,
|
||||||
tables.tcpalog->data, acpi_data_len(tables.tcpalog));
|
tables.tcpalog->data, acpi_data_len(tables.tcpalog));
|
||||||
|
@ -1661,10 +1663,11 @@ void acpi_setup(PcGuestInfo *guest_info)
|
||||||
acpi_build_update, build_state,
|
acpi_build_update, build_state,
|
||||||
tables.rsdp->data, acpi_data_len(tables.rsdp));
|
tables.rsdp->data, acpi_data_len(tables.rsdp));
|
||||||
build_state->rsdp = tables.rsdp->data;
|
build_state->rsdp = tables.rsdp->data;
|
||||||
|
build_state->rsdp_ram = (ram_addr_t)-1;
|
||||||
} else {
|
} else {
|
||||||
build_state->rsdp = qemu_get_ram_ptr(
|
build_state->rsdp = NULL;
|
||||||
acpi_add_rom_blob(build_state, tables.rsdp, ACPI_BUILD_RSDP_FILE, 0)
|
build_state->rsdp_ram = acpi_add_rom_blob(build_state, tables.rsdp,
|
||||||
);
|
ACPI_BUILD_RSDP_FILE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
qemu_register_reset(acpi_build_reset, build_state);
|
qemu_register_reset(acpi_build_reset, build_state);
|
||||||
|
|
Loading…
Reference in a new issue