From: Alexander Graf <agraf@suse.de>
To: QEMU Developers <qemu-devel@nongnu.org>
Cc: "Bogdan.Vlad@freescale.com" <Bogdan.Vlad@freescale.com>,
"mihai.caraman@freescale.com" <mihai.caraman@freescale.com>,
"qemu-ppc@nongnu.org" <qemu-ppc@nongnu.org>,
Scott Wood <scottwood@freescale.com>,
"Varun.Sethi@freescale.com" <Varun.Sethi@freescale.com>
Subject: [Qemu-devel] [PATCH] roms: Flush icache when writing roms to guest memory
Date: Wed, 11 Dec 2013 14:23:36 +0100 [thread overview]
Message-ID: <1386768216-33686-1-git-send-email-agraf@suse.de> (raw)
We use the rom infrastructure to write firmware and/or initial kernel
blobs into guest address space. So we're essentially the layer before
the first code that gets executed inside the guest.
The guest expects that its data and instruction cache view of the world
is 100% consistent when it initially boots. This works just fine on
initial rom population for the first boot.
However, when we reboot and then repopulate the rom region there could
be old code still stuck in the instruction cache, giving the guest an
inconsistent view of the world when we're using kvm.
So we need to invalidate the icache every time we write a rom into guest
address space. We do not need to do this for every DMA since the guest
expects it has to flush the icache manually in that case.
This fixes random reboot issues on e5500 (booke ppc) for me.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
exec.c | 8 ++++++++
hw/core/loader.c | 10 ++++++++++
2 files changed, 18 insertions(+)
diff --git a/exec.c b/exec.c
index f4b9ef2..cc63eb6 100644
--- a/exec.c
+++ b/exec.c
@@ -50,6 +50,7 @@
#include "translate-all.h"
#include "exec/memory-internal.h"
+#include "qemu/cache-utils.h"
//#define DEBUG_SUBPAGE
@@ -2033,6 +2034,13 @@ void cpu_physical_memory_write_rom(hwaddr addr,
ptr = qemu_get_ram_ptr(addr1);
memcpy(ptr, buf, l);
invalidate_and_set_dirty(addr1, l);
+ if (kvm_enabled()) {
+ /*
+ * The guest may want to directly execute from the rom region,
+ * so we better invalidate its icache
+ */
+ flush_icache_range((uintptr_t)ptr, (uintptr_t)ptr + l);
+ }
}
len -= l;
buf += l;
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 60d2ebd..4f809f3 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -51,6 +51,7 @@
#include "hw/nvram/fw_cfg.h"
#include "exec/memory.h"
#include "exec/address-spaces.h"
+#include "qemu/cache-utils.h"
#include <zlib.h>
@@ -619,6 +620,7 @@ static void *rom_set_mr(Rom *rom, Object *owner, const char *name)
data = memory_region_get_ram_ptr(rom->mr);
memcpy(data, rom->data, rom->datasize);
+ flush_icache_range((uintptr_t)data, (uintptr_t)data + rom->datasize);
return data;
}
@@ -777,6 +779,14 @@ static void rom_reset(void *unused)
if (rom->mr) {
void *host = memory_region_get_ram_ptr(rom->mr);
memcpy(host, rom->data, rom->datasize);
+ if (kvm_enabled()) {
+ /*
+ * The guest may want to directly execute from the rom region,
+ * so we better invalidate its icache
+ */
+ flush_icache_range((uintptr_t)host,
+ (uintptr_t)host + rom->datasize);
+ }
} else {
cpu_physical_memory_write_rom(rom->addr, rom->data, rom->datasize);
}
--
1.8.1.4
next reply other threads:[~2013-12-11 13:23 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-11 13:23 Alexander Graf [this message]
2013-12-11 13:27 ` [Qemu-devel] [PATCH] roms: Flush icache when writing roms to guest memory Paolo Bonzini
2013-12-11 13:35 ` Alexander Graf
2013-12-11 14:03 ` Paolo Bonzini
2013-12-11 14:20 ` Alexander Graf
2013-12-11 14:07 ` Peter Maydell
2013-12-11 14:17 ` Alexander Graf
2013-12-11 14:27 ` mihai.caraman
2013-12-11 14:18 ` mihai.caraman
2013-12-11 14:25 ` Peter Maydell
2013-12-11 14:31 ` Alexander Graf
2013-12-11 14:58 ` mihai.caraman
2013-12-11 13:56 ` Peter Maydell
2013-12-13 19:18 ` Scott Wood
2013-12-14 10:58 ` Paolo Bonzini
2013-12-14 11:08 ` Peter Maydell
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=1386768216-33686-1-git-send-email-agraf@suse.de \
--to=agraf@suse.de \
--cc=Bogdan.Vlad@freescale.com \
--cc=Varun.Sethi@freescale.com \
--cc=mihai.caraman@freescale.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=scottwood@freescale.com \
/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).