From: Takuya Yoshikawa <takuya.yoshikawa@gmail.com>
To: Gleb Natapov <gleb@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH] kvm: reset arch memslot info on memslot creation
Date: Fri, 12 Jul 2013 11:09:51 +0900 [thread overview]
Message-ID: <20130712110951.2b9ffb0e0e3fdeb537db132a@gmail.com> (raw)
In-Reply-To: <20130711074153.GB5895@redhat.com>
On Thu, 11 Jul 2013 10:41:53 +0300
Gleb Natapov <gleb@redhat.com> wrote:
> On Wed, Jul 10, 2013 at 10:49:56PM +0900, Takuya Yoshikawa wrote:
> > On Wed, 10 Jul 2013 11:24:39 +0300
> > "Michael S. Tsirkin" <mst@redhat.com> wrote:
> >
> > > On x86, kvm_arch_create_memslot assumes that rmap/lpage_info for the
> > > slot are zeroed out: if they weren't, error handling code after out_free
> > > label will free memory which wasn't allocated here.
> > > This always happens to be the case because on KVM_MR_DELETE we clear the
> > > whole arch structure. So there's no bug, but it's cleaner not to rely
> > > on this here.
> >
> > Yes, the assumption is that the function is called only with zero-sized slots.
> > Since changing the size is not allowed, DELETE-CREATE is the only case we
> > care about.
> >
> > But isn't it possible to make it explicit that zero-sized slots have always
> > zero-cleared contents instead? Otherwise, there would be many troubles.
> >
> Do you have something in mind?
>
I remember that I once wrote code that assumed flags field was cleared before
creating a new slot and was pointed out that such assumptions might be dangerous:
actually, it's cleared separately but not so easy to notice.
So, I want to make it clear what differentiate DELETE'ed slots from others.
If we only assume (npages == 0), CREATE should properly set everything,
having out_free troubles in mind like this patch. If we also assume the other
fields are zero, then DELETE is responsible for that assumption, some comment
in code may be helpful.
Actually, (rmap==NULL) was once used to check if we needed to allocate memory
for a new slot, meaning that we assumed the latter. I felt uneasy and changed
that to (npages == 0).
Let's make it clear the underlying assumptions now.
Takuya
prev parent reply other threads:[~2013-07-12 2:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-10 8:24 Michael S. Tsirkin
2013-07-10 13:49 ` Takuya Yoshikawa
2013-07-11 7:41 ` Gleb Natapov
2013-07-12 2:09 ` Takuya Yoshikawa [this message]
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=20130712110951.2b9ffb0e0e3fdeb537db132a@gmail.com \
--to=takuya.yoshikawa@gmail.com \
--cc=gleb@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=pbonzini@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
Powered by JetHome