acpi-build: mark RAM dirty on table update

acpi build modifies internal FW CFG RAM on first access
but we forgot to mark it dirty.
If this RAM has been migrated already, it won't be
migrated again, returning corrupted tables to guest.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Michael S. Tsirkin 2014-11-17 07:49:21 +02:00
parent 109e90e470
commit ad5b88b1f1
3 changed files with 14 additions and 7 deletions

View File

@ -811,12 +811,12 @@ err:
return -1; return -1;
} }
void *rom_add_blob(const char *name, const void *blob, size_t len, ram_addr_t rom_add_blob(const char *name, const void *blob, size_t len,
hwaddr addr, const char *fw_file_name, hwaddr addr, const char *fw_file_name,
FWCfgReadCallback fw_callback, void *callback_opaque) FWCfgReadCallback fw_callback, void *callback_opaque)
{ {
Rom *rom; Rom *rom;
void *data = NULL; ram_addr_t ret = RAM_ADDR_MAX;
rom = g_malloc0(sizeof(*rom)); rom = g_malloc0(sizeof(*rom));
rom->name = g_strdup(name); rom->name = g_strdup(name);
@ -828,11 +828,13 @@ void *rom_add_blob(const char *name, const void *blob, size_t len,
rom_insert(rom); rom_insert(rom);
if (fw_file_name && fw_cfg) { if (fw_file_name && fw_cfg) {
char devpath[100]; char devpath[100];
void *data;
snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name); snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name);
if (rom_file_has_mr) { if (rom_file_has_mr) {
data = rom_set_mr(rom, OBJECT(fw_cfg), devpath); data = rom_set_mr(rom, OBJECT(fw_cfg), devpath);
ret = memory_region_get_ram_addr(rom->mr);
} else { } else {
data = rom->data; data = rom->data;
} }
@ -841,7 +843,7 @@ void *rom_add_blob(const char *name, const void *blob, size_t len,
fw_callback, callback_opaque, fw_callback, callback_opaque,
data, rom->romsize); data, rom->romsize);
} }
return data; return ret;
} }
/* This function is specific for elf program because we don't need to allocate /* This function is specific for elf program because we don't need to allocate

View File

@ -56,6 +56,7 @@
#include "qapi/qmp/qint.h" #include "qapi/qmp/qint.h"
#include "qom/qom-qobject.h" #include "qom/qom-qobject.h"
#include "exec/ram_addr.h"
/* These are used to size the ACPI tables for -M pc-i440fx-1.7 and /* These are used to size the ACPI tables for -M pc-i440fx-1.7 and
* -M pc-i440fx-2.0. Even if the actual amount of AML generated grows * -M pc-i440fx-2.0. Even if the actual amount of AML generated grows
@ -1511,7 +1512,7 @@ static inline void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)
typedef typedef
struct AcpiBuildState { struct AcpiBuildState {
/* Copy of table in RAM (for patching). */ /* Copy of table in RAM (for patching). */
uint8_t *table_ram; ram_addr_t table_ram;
uint32_t table_size; uint32_t table_size;
/* Is table patched? */ /* Is table patched? */
uint8_t patched; uint8_t patched;
@ -1716,7 +1717,10 @@ 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); assert(acpi_data_len(tables.table_data) == build_state->table_size);
memcpy(build_state->table_ram, tables.table_data->data, memcpy(qemu_get_ram_ptr(build_state->table_ram), tables.table_data->data,
build_state->table_size);
cpu_physical_memory_set_dirty_range_nocode(build_state->table_ram,
build_state->table_size); build_state->table_size);
acpi_build_tables_cleanup(&tables, true); acpi_build_tables_cleanup(&tables, true);
@ -1728,7 +1732,7 @@ static void acpi_build_reset(void *build_opaque)
build_state->patched = 0; build_state->patched = 0;
} }
static void *acpi_add_rom_blob(AcpiBuildState *build_state, GArray *blob, static ram_addr_t acpi_add_rom_blob(AcpiBuildState *build_state, GArray *blob,
const char *name) const char *name)
{ {
return rom_add_blob(name, blob->data, acpi_data_len(blob), -1, name, return rom_add_blob(name, blob->data, acpi_data_len(blob), -1, name,
@ -1777,6 +1781,7 @@ void acpi_setup(PcGuestInfo *guest_info)
/* Now expose it all to Guest */ /* Now expose it all to Guest */
build_state->table_ram = acpi_add_rom_blob(build_state, tables.table_data, build_state->table_ram = acpi_add_rom_blob(build_state, tables.table_data,
ACPI_BUILD_TABLE_FILE); ACPI_BUILD_TABLE_FILE);
assert(build_state->table_ram != RAM_ADDR_MAX);
build_state->table_size = acpi_data_len(tables.table_data); build_state->table_size = acpi_data_len(tables.table_data);
acpi_add_rom_blob(NULL, tables.linker, "etc/table-loader"); acpi_add_rom_blob(NULL, tables.linker, "etc/table-loader");

View File

@ -59,7 +59,7 @@ extern bool rom_file_has_mr;
int rom_add_file(const char *file, const char *fw_dir, int rom_add_file(const char *file, const char *fw_dir,
hwaddr addr, int32_t bootindex, hwaddr addr, int32_t bootindex,
bool option_rom); bool option_rom);
void *rom_add_blob(const char *name, const void *blob, size_t len, ram_addr_t rom_add_blob(const char *name, const void *blob, size_t len,
hwaddr addr, const char *fw_file_name, hwaddr addr, const char *fw_file_name,
FWCfgReadCallback fw_callback, void *callback_opaque); FWCfgReadCallback fw_callback, void *callback_opaque);
int rom_add_elf_program(const char *name, void *data, size_t datasize, int rom_add_elf_program(const char *name, void *data, size_t datasize,