From: Gleb Natapov <gleb@redhat.com>
To: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
kvm@vger.kernel.org, Avi Kivity <avi@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Nick Piggin <npiggin@suse.de>
Subject: Re: [PATCH 5/6] kvm, x86: use ro page and don't copy shared page
Date: Thu, 29 Jul 2010 08:56:41 +0300 [thread overview]
Message-ID: <20100729055641.GK31711@redhat.com> (raw)
In-Reply-To: <4C50E43A.4020106@cn.fujitsu.com>
On Thu, Jul 29, 2010 at 10:15:22AM +0800, Lai Jiangshan wrote:
> On 07/16/2010 03:19 PM, Gleb Natapov wrote:
>
> >> +/* get a current mapped page fast, and test whether the page is writable. */
> >> +static struct page *get_user_page_and_protection(unsigned long addr,
> >> + int *writable)
> >> +{
> >> + struct page *page[1];
> >> +
> >> + if (__get_user_pages_fast(addr, 1, 1, page) == 1) {
> >> + *writable = 1;
> >> + return page[0];
> >> + }
> >> + if (__get_user_pages_fast(addr, 1, 0, page) == 1) {
> >> + *writable = 0;
> >> + return page[0];
> >> + }
> >> + return NULL;
> >> +}
> >> +
> >> +static pfn_t kvm_get_pfn_for_page_fault(struct kvm *kvm, gfn_t gfn,
> >> + int write_fault, int *host_writable)
> >> +{
> >> + unsigned long addr;
> >> + struct page *page;
> >> +
> >> + if (!write_fault) {
> >> + addr = gfn_to_hva(kvm, gfn);
> >> + if (kvm_is_error_hva(addr)) {
> >> + get_page(bad_page);
> >> + return page_to_pfn(bad_page);
> >> + }
> >> +
> >> + page = get_user_page_and_protection(addr, host_writable);
> >> + if (page)
> >> + return page_to_pfn(page);
> >> + }
> >> +
> >> + *host_writable = 1;
> >> + return kvm_get_pfn_for_gfn(kvm, gfn);
> >> +}
> >> +
> > kvm_get_pfn_for_gfn() returns fault_page if page is mapped RO, so caller
> > of kvm_get_pfn_for_page_fault() and kvm_get_pfn_for_gfn() will get
> > different results when called on the same page. Not good.
> > kvm_get_pfn_for_page_fault() logic should be folded into
> > kvm_get_pfn_for_gfn().
> >
>
>
> The different results are the things we just need.
How so? Users of kvm_get_pfn_for_gfn() will think that page is invalid
and may report misconfiguration to userspace and users of
kvm_get_pfn_for_page_fault() will think that the access to page is OK.
There are no many users of kvm_get_pfn_for_gfn() and may be your patch
replace all of them with kvm_get_pfn_for_page_fault(), but this just
strengthen the point that they should be merged.
> We don't want to copy and write a page which is mapped RO when
> only read fault.
I don't see how returning inconsistent results helps us achieving that.
BTW since kvm_get_pfn_for_gfn() will never map RO page
get_user_page_and_protection() will never find any RO pages. Looks like
kvm_get_pfn_for_page_fault() is equivalent to kvm_get_pfn_for_gfn()
since !write_fault section will at best find mapped RW page.
--
Gleb.
prev parent reply other threads:[~2010-07-29 5:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-16 2:13 [PATCH 5/6] kvm, x86: use ro page and don't copy shared page Lai Jiangshan
2010-07-16 7:19 ` Gleb Natapov
2010-07-16 23:26 ` Marcelo Tosatti
2010-07-17 4:31 ` Gleb Natapov
2010-07-18 15:14 ` Avi Kivity
2010-07-18 15:23 ` Gleb Natapov
2010-07-18 15:31 ` Avi Kivity
2010-07-29 2:19 ` Lai Jiangshan
2010-07-29 2:15 ` Lai Jiangshan
2010-07-29 5:56 ` Gleb Natapov [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=20100729055641.GK31711@redhat.com \
--to=gleb@redhat.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=npiggin@suse.de \
/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.