All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: kvm@vger.kernel.org, Alexander Graf <agraf@suse.de>,
	kvm-ppc@vger.kernel.org, Scott Wood <scottwood@freescale.com>,
	Alex Williamson <Alex.Williamson@redhat.com>
Subject: Re: Question about removing memslots
Date: Wed, 28 Mar 2012 09:37:38 +0000	[thread overview]
Message-ID: <4F72DBE2.6060909@redhat.com> (raw)
In-Reply-To: <1332919486.2882.88.camel@pasglop>

On 03/28/2012 09:24 AM, Benjamin Herrenschmidt wrote:
> So I was chasing a bug today when I realized that some "drivers" in qemu
> do interesting things with memory regions.

They're usually called devices, drivers live in the guest.

> More specifically, cirrus emulation constantly flips the linear
> framebuffer between being mapped into the guest and being emulated MMIO
> (the latter for the purpose of image blits).
>
> This made me ponder ... whenever a memslot is "removed" like that (in
> the case for example where cirrus turns the fb into emulation), we need
> to ensure that any cached translation that involve those GPAs are
> flushed out of whatever caching (HW or SW) is done by the KVM arch
> code...
>
> So I started looking and the only thing I can find (let me know if I
> missed something) is kvm_arch_flush_shadow(). Is that it ? Because it
> doesn't take the memslot going away as an argument, so it doesn't know
> -what- to flush...
>
> Now I see that x86 just seems to flush everything, which is quite heavy
> handed considering how often cirrus does it, but maybe it doesn't have a
> choice (lack of reverse mapping from GPA ?).

We do have a reverse mapping, so we could easily flush just a single
slot.  The reason it hasn't been done is that slot changes are very are
on x86.  They're usually only done by 16-bit software; 32-bit software
just maps the entire framebuffer BAR and accesses it directly.  It's
also usually done in a tight loop, so flushing everything doesn't have a
large impact (and with a 20-bit address space, you couldn't cause a
large impact if you wanted to - memory is all of 256 pages).

> I also noticed that powerpc ... doesn't do anything :-) Ooops....
>
> So all translations still present in the TLB will remain there, all
> translations present in the MMU hash table as well, etc...
>
> Now, in order to implement that properly and efficiently, we would need
> to at least get the GPA (if not the whole memslot).
>
> Do you have any objection (provided I didn't completely misunderstand
> something which is quite possible) to us adding that argument to
> kvm_arch_flush_shadow() ? We can easily put in a small patch adding that
> as an unused argument, and later get the proper implementation for
> powerpc.

Sure, it makes sense.

> Another thing I noticed while at it is that my version of
> __kvm_set_memory_region() appears to call kvm_iommu_map_pages() whenever
> adding a memslot ... but never does the opposite unmapping when that
> memory slot is removed.... isn't that potentially an issue ?

It is.  Alex?

-- 
error compiling committee.c: too many arguments to function


WARNING: multiple messages have this Message-ID (diff)
From: Avi Kivity <avi@redhat.com>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: kvm@vger.kernel.org, Alexander Graf <agraf@suse.de>,
	kvm-ppc@vger.kernel.org, Scott Wood <scottwood@freescale.com>,
	Alex Williamson <Alex.Williamson@redhat.com>
Subject: Re: Question about removing memslots
Date: Wed, 28 Mar 2012 11:37:38 +0200	[thread overview]
Message-ID: <4F72DBE2.6060909@redhat.com> (raw)
In-Reply-To: <1332919486.2882.88.camel@pasglop>

On 03/28/2012 09:24 AM, Benjamin Herrenschmidt wrote:
> So I was chasing a bug today when I realized that some "drivers" in qemu
> do interesting things with memory regions.

They're usually called devices, drivers live in the guest.

> More specifically, cirrus emulation constantly flips the linear
> framebuffer between being mapped into the guest and being emulated MMIO
> (the latter for the purpose of image blits).
>
> This made me ponder ... whenever a memslot is "removed" like that (in
> the case for example where cirrus turns the fb into emulation), we need
> to ensure that any cached translation that involve those GPAs are
> flushed out of whatever caching (HW or SW) is done by the KVM arch
> code...
>
> So I started looking and the only thing I can find (let me know if I
> missed something) is kvm_arch_flush_shadow(). Is that it ? Because it
> doesn't take the memslot going away as an argument, so it doesn't know
> -what- to flush...
>
> Now I see that x86 just seems to flush everything, which is quite heavy
> handed considering how often cirrus does it, but maybe it doesn't have a
> choice (lack of reverse mapping from GPA ?).

We do have a reverse mapping, so we could easily flush just a single
slot.  The reason it hasn't been done is that slot changes are very are
on x86.  They're usually only done by 16-bit software; 32-bit software
just maps the entire framebuffer BAR and accesses it directly.  It's
also usually done in a tight loop, so flushing everything doesn't have a
large impact (and with a 20-bit address space, you couldn't cause a
large impact if you wanted to - memory is all of 256 pages).

> I also noticed that powerpc ... doesn't do anything :-) Ooops....
>
> So all translations still present in the TLB will remain there, all
> translations present in the MMU hash table as well, etc...
>
> Now, in order to implement that properly and efficiently, we would need
> to at least get the GPA (if not the whole memslot).
>
> Do you have any objection (provided I didn't completely misunderstand
> something which is quite possible) to us adding that argument to
> kvm_arch_flush_shadow() ? We can easily put in a small patch adding that
> as an unused argument, and later get the proper implementation for
> powerpc.

Sure, it makes sense.

> Another thing I noticed while at it is that my version of
> __kvm_set_memory_region() appears to call kvm_iommu_map_pages() whenever
> adding a memslot ... but never does the opposite unmapping when that
> memory slot is removed.... isn't that potentially an issue ?

It is.  Alex?

-- 
error compiling committee.c: too many arguments to function

  reply	other threads:[~2012-03-28  9:37 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-28  7:24 Question about removing memslots Benjamin Herrenschmidt
2012-03-28  7:24 ` Benjamin Herrenschmidt
2012-03-28  9:37 ` Avi Kivity [this message]
2012-03-28  9:37   ` Avi Kivity
2012-03-28  9:59   ` Benjamin Herrenschmidt
2012-03-28  9:59     ` Benjamin Herrenschmidt
2012-03-28 10:05     ` Avi Kivity
2012-03-28 10:05       ` Avi Kivity
2012-03-28 10:17       ` Benjamin Herrenschmidt
2012-03-28 10:17         ` Benjamin Herrenschmidt
2012-03-28 10:51         ` Avi Kivity
2012-03-28 10:51           ` Avi Kivity
2012-03-28 21:04           ` Benjamin Herrenschmidt
2012-03-28 21:04             ` Benjamin Herrenschmidt
2012-03-29  9:36             ` Avi Kivity
2012-03-29  9:36               ` Avi Kivity
2012-03-29 11:46               ` Benjamin Herrenschmidt
2012-03-29 11:46                 ` Benjamin Herrenschmidt
2012-03-29 13:49               ` Gerd Hoffmann
2012-03-29 13:49                 ` Gerd Hoffmann
2012-03-29  5:15   ` Takuya Yoshikawa
2012-03-29  5:15     ` Takuya Yoshikawa
2012-03-29  9:44     ` Avi Kivity
2012-03-29  9:44       ` Avi Kivity
2012-03-29 15:21       ` Takuya Yoshikawa
2012-03-29 15:21         ` Takuya Yoshikawa
2012-03-29 15:26         ` Avi Kivity
2012-03-29 15:26           ` Avi Kivity
2012-03-29 15:35           ` Takuya Yoshikawa
2012-03-29 15:35             ` Takuya Yoshikawa

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=4F72DBE2.6060909@redhat.com \
    --to=avi@redhat.com \
    --cc=Alex.Williamson@redhat.com \
    --cc=agraf@suse.de \
    --cc=benh@kernel.crashing.org \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.