qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Richard Henderson <rth@twiddle.net>,
	Anthony Liguori <aliguori@amazon.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PULL 11/15] acpi-build: mark RAM dirty on table update
Date: Sun, 23 Nov 2014 13:18:30 +0200	[thread overview]
Message-ID: <1416741307-32307-12-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1416741307-32307-1-git-send-email-mst@redhat.com>

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>
---
 include/hw/loader.h  |  2 +-
 hw/core/loader.c     |  8 +++++---
 hw/i386/acpi-build.c | 11 ++++++++---
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/include/hw/loader.h b/include/hw/loader.h
index 054c6a2..6481639 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -59,7 +59,7 @@ extern bool rom_file_has_mr;
 int rom_add_file(const char *file, const char *fw_dir,
                  hwaddr addr, int32_t bootindex,
                  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,
                    FWCfgReadCallback fw_callback, void *callback_opaque);
 int rom_add_elf_program(const char *name, void *data, size_t datasize,
diff --git a/hw/core/loader.c b/hw/core/loader.c
index fc15535..7527fd3 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -811,12 +811,12 @@ err:
     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,
                    FWCfgReadCallback fw_callback, void *callback_opaque)
 {
     Rom *rom;
-    void *data = NULL;
+    ram_addr_t ret = RAM_ADDR_MAX;
 
     rom           = g_malloc0(sizeof(*rom));
     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);
     if (fw_file_name && fw_cfg) {
         char devpath[100];
+        void *data;
 
         snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name);
 
         if (rom_file_has_mr) {
             data = rom_set_mr(rom, OBJECT(fw_cfg), devpath);
+            ret = memory_region_get_ram_addr(rom->mr);
         } else {
             data = rom->data;
         }
@@ -841,7 +843,7 @@ void *rom_add_blob(const char *name, const void *blob, size_t len,
                                  fw_callback, callback_opaque,
                                  data, rom->romsize);
     }
-    return data;
+    return ret;
 }
 
 /* This function is specific for elf program because we don't need to allocate
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 4003b6b..92a36e3 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -56,6 +56,7 @@
 
 #include "qapi/qmp/qint.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
  * -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
 struct AcpiBuildState {
     /* Copy of table in RAM (for patching). */
-    uint8_t *table_ram;
+    ram_addr_t table_ram;
     uint32_t table_size;
     /* Is table patched? */
     uint8_t patched;
@@ -1716,9 +1717,12 @@ static void acpi_build_update(void *build_opaque, uint32_t offset)
     acpi_build(build_state->guest_info, &tables);
 
     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);
+
     acpi_build_tables_cleanup(&tables, true);
 }
 
@@ -1728,7 +1732,7 @@ static void acpi_build_reset(void *build_opaque)
     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)
 {
     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 */
     build_state->table_ram = acpi_add_rom_blob(build_state, tables.table_data,
                                                ACPI_BUILD_TABLE_FILE);
+    assert(build_state->table_ram != RAM_ADDR_MAX);
     build_state->table_size = acpi_data_len(tables.table_data);
 
     acpi_add_rom_blob(NULL, tables.linker, "etc/table-loader");
-- 
MST

  parent reply	other threads:[~2014-11-23 11:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-23 11:17 [Qemu-devel] [PULL 00/15] pc, pci, misc bugfixes Michael S. Tsirkin
2014-11-23 11:17 ` [Qemu-devel] [PULL 01/15] qemu-char: fix tcp_get_fds Michael S. Tsirkin
2014-11-23 11:17 ` [Qemu-devel] [PULL 02/15] pc: kvm: check if KVM has free memory slots to avoid abort() Michael S. Tsirkin
2014-11-23 11:17 ` [Qemu-devel] [PULL 03/15] pc: make pc_dimm_plug() more readble Michael S. Tsirkin
2014-11-23 11:17 ` [Qemu-devel] [PULL 04/15] pc: limit DIMM address and size to page aligned values Michael S. Tsirkin
2014-11-23 11:17 ` [Qemu-devel] [PULL 05/15] memory: expose alignment used for allocating RAM as MemoryRegion API Michael S. Tsirkin
2014-11-23 11:17 ` [Qemu-devel] [PULL 06/15] pc: align DIMM's address/size by backend's alignment value Michael S. Tsirkin
2014-11-23 11:18 ` [Qemu-devel] [PULL 07/15] pc: pc-dimm: use backend alignment during address auto allocation Michael S. Tsirkin
2014-11-23 11:18 ` [Qemu-devel] [PULL 08/15] pc: explicitly check maxmem limit when adding DIMM Michael S. Tsirkin
2014-11-23 11:18 ` [Qemu-devel] [PULL 09/15] pc: count in 1Gb hugepage alignment when sizing hotplug-memory container Michael S. Tsirkin
2014-11-23 11:18 ` [Qemu-devel] [PULL 10/15] hw/pci: fix crash on shpc error flow Michael S. Tsirkin
2014-11-23 11:18 ` Michael S. Tsirkin [this message]
2014-11-23 11:18 ` [Qemu-devel] [PULL 12/15] target-i386: move generic memory hotplug methods to DSDTs Michael S. Tsirkin
2014-11-23 11:18 ` [Qemu-devel] [PULL 13/15] pcie: fix typo in pcie_cap_deverr_init() Michael S. Tsirkin
2014-11-23 11:18 ` [Qemu-devel] [PULL 14/15] pcie: fix improper use of negative value Michael S. Tsirkin
2014-11-23 11:18 ` [Qemu-devel] [PULL 15/15] pc: acpi: mark all possible CPUs as enabled in SRAT Michael S. Tsirkin
2014-11-24 13:07 ` [Qemu-devel] [PULL 00/15] pc, pci, misc bugfixes Peter Maydell
2014-11-24 14:16   ` [Qemu-devel] [PATCH 08/15] fixup! pc: explicitly check maxmem limit when adding DIMM Igor Mammedov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1416741307-32307-12-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=aliguori@amazon.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).