All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: gleb@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH v2 01/10] kvm: Restrict non-existing slot state transitions
Date: Tue, 11 Dec 2012 23:39:27 -0200	[thread overview]
Message-ID: <20121212013926.GA7281@amt.cnet> (raw)
In-Reply-To: <20121212012909.GC2898@amt.cnet>

On Tue, Dec 11, 2012 at 11:29:09PM -0200, Marcelo Tosatti wrote:
> On Mon, Dec 10, 2012 at 10:32:45AM -0700, Alex Williamson wrote:
> > The API documentation states:
> > 
> > 	When changing an existing slot, it may be moved in the guest
> > 	physical memory space, or its flags may be modified.
> > 
> > An "existing slot" requires a non-zero npages (memory_size).  The only
> > transition we should therefore allow for a non-existing slot should be
> > to create the slot, which includes setting a non-zero memory_size.  We
> > currently allow calls to modify non-existing slots, which is pointless,
> > confusing, and possibly wrong.
> > 
> > With this we know that the invalidation path of __kvm_set_memory_region
> > is always for a delete or move and never for adding a zero size slot.
> > 
> > Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> > ---
> >  virt/kvm/kvm_main.c |    9 +++++++--
> >  1 file changed, 7 insertions(+), 2 deletions(-)
> > 
> > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> > index 6e8fa7e..e426704 100644
> > --- a/virt/kvm/kvm_main.c
> > +++ b/virt/kvm/kvm_main.c
> > @@ -753,10 +753,15 @@ int __kvm_set_memory_region(struct kvm *kvm,
> >  	new.npages = npages;
> >  	new.flags = mem->flags;
> >  
> > -	/* Disallow changing a memory slot's size. */
> > +	/*
> > +	 * Disallow changing a memory slot's size or changing anything about
> > +	 * zero sized slots that doesn't involve making them non-zero.
> > +	 */
> >  	r = -EINVAL;
> >  	if (npages && old.npages && npages != old.npages)
> >  		goto out_free;
> > +	if (!npages && !old.npages)
> > +		goto out_free;
> 
>         /* General sanity checks */
>         if (mem->memory_size & (PAGE_SIZE - 1))
>                 goto out;
>         if (mem->guest_phys_addr & (PAGE_SIZE - 1))
>                 goto out;
> 
>         if (mem->guest_phys_addr + mem->memory_size < mem->guest_phys_addr)
>                 goto out;
> 
> If mem->memory_size is zero, then check above fails. 

Err, no read a "<=" while writing that.

> If mem->memory_size > 0, it must be at least PAGE_SIZE, in which case 
> npages == 1.
> 
> Which means the code does not allow changes to non-existing slots.
> Yes?
> 

  reply	other threads:[~2012-12-12  1:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-10 17:32 [PATCH v2 00/10] kvm: memory slot cleanups, fix, and increase Alex Williamson
2012-12-10 17:32 ` [PATCH v2 01/10] kvm: Restrict non-existing slot state transitions Alex Williamson
2012-12-12  1:29   ` Marcelo Tosatti
2012-12-12  1:39     ` Marcelo Tosatti [this message]
2012-12-12  4:30       ` Alex Williamson
2012-12-10 17:32 ` [PATCH v2 02/10] kvm: Check userspace_addr when modifying a memory slot Alex Williamson
2012-12-10 17:32 ` [PATCH v2 03/10] kvm: Fix iommu map/unmap to handle memory slot moves Alex Williamson
2012-12-10 17:33 ` [PATCH v2 04/10] kvm: Minor memory slot optimization Alex Williamson
2012-12-10 17:33 ` [PATCH v2 05/10] kvm: Rename KVM_MEMORY_SLOTS -> KVM_USER_MEM_SLOTS Alex Williamson
2012-12-10 17:33 ` [PATCH v2 06/10] kvm: Make KVM_PRIVATE_MEM_SLOTS optional Alex Williamson
2012-12-10 17:33 ` [PATCH v2 07/10] kvm: struct kvm_memory_slot.user_alloc -> bool Alex Williamson
2012-12-10 17:33 ` [PATCH v2 08/10] kvm: struct kvm_memory_slot.flags -> u32 Alex Williamson
2012-12-10 17:33 ` [PATCH v2 09/10] kvm: struct kvm_memory_slot.id -> short Alex Williamson
2012-12-10 17:33 ` [PATCH v2 10/10] kvm: Increase user memory slots on x86 to 125 Alex Williamson
2012-12-12  2:11 ` [PATCH v2 00/10] kvm: memory slot cleanups, fix, and increase Marcelo Tosatti
2012-12-12 14:13 ` Gleb Natapov
2012-12-15  1:03 ` Marcelo Tosatti

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=20121212013926.GA7281@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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 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.