kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: Jan Kiszka <jan.kiszka@web.de>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"ddutile@redhat.com" <ddutile@redhat.com>,
	"mst@redhat.com" <mst@redhat.com>,
	"chrisw@redhat.com" <chrisw@redhat.com>
Subject: Re: [RFC PATCH 0/2] Expose available KVM free memory slot count to help avoid aborts
Date: Tue, 25 Jan 2011 16:53:44 +0200	[thread overview]
Message-ID: <4D3EE3F8.3020603@redhat.com> (raw)
In-Reply-To: <1295966492.3230.55.camel@x201>

On 01/25/2011 04:41 PM, Alex Williamson wrote:
> >  >
> >  >
> >  >  kvm: Allow memory slot array to grow on demand
> >  >
> >  >  Remove fixed KVM_MEMORY_SLOTS limit, allowing the slot array
> >  >  to grow on demand.  Private slots are now allocated at the
> >  >  front instead of the end.  Only x86 seems to use private slots,
> >
> >  Hmm, doesn't current user space expect slots 8..11 to be the private
> >  ones and wouldn't it cause troubles if slots 0..3 are suddenly reserved?
>
> The private slots aren't currently visible to userspace, they're
> actually slots 32..35.  The patch automatically increments user passed
> slot ids so userspace has it's own zero-based view of the array.
> Frankly, I don't understand why userspace reserves slots 8..11, is this
> compatibility with older kernel implementations?

I think so.  I believe these kernel versions are too old now to matter, 
but of course I can't be sure.

> >  >  so this is now zero for all other archs.  The memslots pointer
> >  >  is already updated using rcu, so changing the size off the
> >  >  array when it's replaces is straight forward.  x86 also keeps
> >  >  a bitmap of slots used by a kvm_mmu_page, which requires a
> >  >  shadow tlb flush whenever we increase the number of slots.
> >  >  This forces the pages to be rebuilt with the new bitmap size.
> >
> >  Is it possible for user space to increase the slot number to ridiculous
> >  amounts (at least as far as kmalloc allows) and then trigger a kernel
> >  walk through them in non-preemptible contexts? Just wondering, I haven't
> >  checked all contexts of functions like kvm_is_visible_gfn yet.
> >
> >  If yes, we should already switch to rbtree or something like that.
> >  Otherwise that may wait a bit, but probably not too long.
>
> Yeah, Avi has brought up the hole that userspace can exploit this
> interface with these changes.  However, for 99+% of users, this change
> leaves the slot array at about the same size, or makes it smaller.  Only
> huge, scale-out guests would probably even see a doubling of slots (my
> guest with 14 82576 VFs uses 48 slots).  On the kernel side, I think we
> can safely save a tree implementation as a later optimization should we
> determine it's necessary.  We'll have to see how the userspace side
> matches to figure out what's best there.  Thanks,
>

A tree would probably be a pessimization until we are able to cache the 
result of lookups.  That's because the linear scan generates a very 
simple pattern of branch predictions and memory accesses, while a tree 
uses a whole bunch of cachelines and generates unpredictable branches 
(if the inputs are unpredictable).

Note that with TDP most lookups result in failure, so all we need is a 
fast way to determine whether to perform the lookup at all or not.  That 
can be done by caching the last lookup for this address in the spte by 
setting a reserved bits.  For the other lookups, which we believe will 
succeed, we can assume the probablity of a match is related to the slot 
size, and sort the slots by page count.

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


  parent reply	other threads:[~2011-01-25 14:53 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-21 23:48 [RFC PATCH 0/2] Expose available KVM free memory slot count to help avoid aborts Alex Williamson
2011-01-21 23:48 ` [RFC PATCH 1/2] kvm: Allow querying free slots Alex Williamson
2011-01-21 23:48 ` [RFC PATCH 2/2] device-assignment: Count required kvm memory slots Alex Williamson
2011-01-22 22:11 ` [RFC PATCH 0/2] Expose available KVM free memory slot count to help avoid aborts Michael S. Tsirkin
2011-01-24  9:32 ` Marcelo Tosatti
2011-01-24 14:16   ` Jan Kiszka
2011-01-24 15:44     ` Alex Williamson
2011-01-25  5:37       ` Alex Williamson
2011-01-25  7:36         ` Jan Kiszka
2011-01-25 14:41           ` Alex Williamson
2011-01-25 14:45             ` Michael S. Tsirkin
2011-01-25 14:54               ` Avi Kivity
2011-01-25 14:53             ` Avi Kivity [this message]
2011-01-25 14:59               ` Michael S. Tsirkin
2011-01-25 17:33                 ` Avi Kivity
2011-01-25 17:58                   ` Michael S. Tsirkin
2011-01-26  9:17                     ` Avi Kivity
2011-01-26  9:20                       ` Michael S. Tsirkin
2011-01-26  9:23                         ` Avi Kivity
2011-01-26  9:39                           ` Michael S. Tsirkin
2011-01-26  9:54                             ` Avi Kivity
2011-01-26 12:08                               ` Michael S. Tsirkin
2011-01-27  9:21                                 ` Avi Kivity
2011-01-27  9:26                                   ` Michael S. Tsirkin
2011-01-27  9:28                                     ` Avi Kivity
2011-01-27  9:29                                       ` Michael S. Tsirkin
2011-01-27  9:51                                         ` Avi Kivity
2011-01-27  9:28                                     ` Michael S. Tsirkin
2011-01-25 16:35               ` Jan Kiszka
2011-01-25 19:13                 ` Alex Williamson
2011-01-26  8:14                   ` Jan Kiszka
2011-01-25 10:23         ` Avi Kivity
2011-01-25 14:57           ` Alex Williamson
2011-01-25 17:11             ` Avi Kivity
2011-01-25 17:43               ` Alex Williamson
2011-01-26  9:22                 ` Avi Kivity
2011-01-31 19:18         ` Marcelo Tosatti
2011-02-23 21:46           ` Alex Williamson
2011-02-24 12:34             ` Avi Kivity
2011-02-24 12:37               ` Avi Kivity
2011-02-24 18:10               ` Alex Williamson
2011-01-25 10:20   ` Avi Kivity
2011-01-25 14:46     ` Alex Williamson
2011-01-25 14:56       ` Avi Kivity
2011-01-25 14:55     ` Michael S. Tsirkin
2011-01-25 14:58       ` Avi Kivity
2011-01-25 15:23         ` Michael S. Tsirkin
2011-01-25 17:34           ` Avi Kivity
2011-01-25 18:00             ` Michael S. Tsirkin
2011-01-26  9:25               ` Avi Kivity

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=4D3EE3F8.3020603@redhat.com \
    --to=avi@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=chrisw@redhat.com \
    --cc=ddutile@redhat.com \
    --cc=jan.kiszka@web.de \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.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).