From: Scott Wood <scottwood@freescale.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "Bogdan.Vlad@freescale.com" <Bogdan.Vlad@freescale.com>,
Alexander Graf <agraf@suse.de>,
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>,
"mihai.caraman@freescale.com" <mihai.caraman@freescale.com>
Subject: Re: [Qemu-devel] [PATCH] roms: Flush icache when writing roms to guest memory
Date: Fri, 13 Dec 2013 13:18:50 -0600 [thread overview]
Message-ID: <1386962330.10013.302.camel@snotra.buserror.net> (raw)
In-Reply-To: <CAFEAcA8yuTA4q-Cu-tODU3Z2GRJh+LQAMqKHo0OQKfJp2abT1g@mail.gmail.com>
On Wed, 2013-12-11 at 13:56 +0000, Peter Maydell wrote:
> 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?
On PPC these cache operations broadcast, and are the architecturally
defined way of doing self-modifying code.
> 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.
Can't the TCG thread get migrated between CPUs?
> 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...
Hmm, a good point is raised in that thread regarding what happens if a
page is swapped out and then back in:
https://lists.cs.columbia.edu/pipermail/kvmarm/2013-August/006738.html
I think the usual mechanism PPC booke uses to handle this is currently
not effective with KVM because we get the pages via __get_user_pages
fast() rather than by enabling execute permission in an ISI (see the
second instance of set_pte_filter() in arch/powerpc/mm/pgtable.c). Even
if we fix that to invoke the cache cleaning code when KVM acquires a
page, though, QEMU would still need to flush if it modifies/loads code
on a page that may already be marked in the kernel as having been
cleaned.
-Scott
next prev parent reply other threads:[~2013-12-13 19:52 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
2013-12-13 19:18 ` Scott Wood [this message]
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=1386962330.10013.302.camel@snotra.buserror.net \
--to=scottwood@freescale.com \
--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=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/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).