From: Peter Maydell <peter.maydell@linaro.org>
To: Alexander Graf <agraf@suse.de>
Cc: "Bogdan.Vlad@freescale.com" <Bogdan.Vlad@freescale.com>,
QEMU Developers <qemu-devel@nongnu.org>,
Marc Zyngier <marc.zyngier@arm.com>,
"qemu-ppc@nongnu.org" <qemu-ppc@nongnu.org>,
"Varun.Sethi@freescale.com" <Varun.Sethi@freescale.com>,
Scott Wood <scottwood@freescale.com>,
"mihai.caraman@freescale.com" <mihai.caraman@freescale.com>
Subject: Re: [Qemu-devel] [PATCH] roms: Flush icache when writing roms to guest memory
Date: Wed, 11 Dec 2013 13:56:57 +0000 [thread overview]
Message-ID: <CAFEAcA8yuTA4q-Cu-tODU3Z2GRJh+LQAMqKHo0OQKfJp2abT1g@mail.gmail.com> (raw)
In-Reply-To: <1386768216-33686-1-git-send-email-agraf@suse.de>
On 11 December 2013 13:23, Alexander Graf <agraf@suse.de> wrote:
> 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.
> @@ -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);
> + }
I bet these aren't the only places where code gets written
to guest memory. Also are you sure flush_icache_range()
works correctly when multiple threads (multiple vCPUs,
potentially executing on different host CPUs) are involved? The
TCG case only needs to care about "this thread writes code
to memory that it will itself later execute", not any kind of
cross-host-CPU flushing.
There was a huge thread on kvmarm earlier this year
https://lists.cs.columbia.edu/pipermail/kvmarm/2013-August/006716.html
about a similar sort of issue, and I think the conclusion was that
the kernel basically had to deal with the problem itself [though
the thread is rather confusing...]. I've cc'd Marc Z in the hope
he remembers the ARM specific detail...
thanks
-- PMM
next prev parent reply other threads:[~2013-12-11 13:57 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-11 13:23 [Qemu-devel] [PATCH] roms: Flush icache when writing roms to guest memory Alexander Graf
2013-12-11 13:27 ` 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 [this message]
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=CAFEAcA8yuTA4q-Cu-tODU3Z2GRJh+LQAMqKHo0OQKfJp2abT1g@mail.gmail.com \
--to=peter.maydell@linaro.org \
--cc=Bogdan.Vlad@freescale.com \
--cc=Varun.Sethi@freescale.com \
--cc=agraf@suse.de \
--cc=marc.zyngier@arm.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).