public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Avi Kivity <avi@redhat.com>, LKML <linux-kernel@vger.kernel.org>,
	KVM <kvm@vger.kernel.org>
Subject: Re: [PATCH 2/5] KVM: MMU: simplify mmu_set_spte
Date: Wed, 21 Nov 2012 07:23:26 +0800	[thread overview]
Message-ID: <50AC10EE.8000008@linux.vnet.ibm.com> (raw)
In-Reply-To: <20121120221853.GA31427@amt.cnet>

On 11/21/2012 06:18 AM, Marcelo Tosatti wrote:

>>>> -			child = page_header(pte & PT64_BASE_ADDR_MASK);
>>>> -			drop_parent_pte(child, sptep);
>>>> -			kvm_flush_remote_tlbs(vcpu->kvm);
>>>
>>> How come its safe to drop this case?
>>
>> We use "if (pfn != spte_to_pfn(*sptep))" to simplify the thing.
>> There are two cases:
>> 1) the sptep is not the last mapping.
>>    under this case, sptep must point to a shadow page table, that means
>>    spte_to_pfn(*sptep)) is used by KVM module, and 'pfn' is used by userspace.
>>    so, 'if' condition must be satisfied, the sptep will be dropped.
>>
>>    Actually, This is the origin case:
>>   | if (level > PT_PAGE_TABLE_LEVEL &&
>>   |	    !is_large_pte(*sptep))"
>>
>> 2) the sptep is the last mapping.
>>    under this case, the level of spte (sp.level) must equal the 'level' which
>>    we pass to mmu_set_spte. If they point to the same pfn, it is 'remap', otherwise
>>    we drop it.
>>
>> I think this is safe. :)
> 
> mmu_page_zap_pte takes care of it, OK.
> 
> What if was_rmapped=true but gfn is different? Say if the spte comes
> from an unsync shadow page, the guest modifies that shadow page (but
> does not invalidate it with invlpg), then faults. gfn can still point
> to the same gfn (but in that case, with your patch,
> page_header_update_slot is not called.

Marcelo,

Page fault path and other sync/prefetch paths will reread guest page table,
then it get a different target pfn.

The scenario is like this:

gfn1 = pfn1, gfn2 = pfn2
gpte = pfn1, spte is shadowed by gpte and it is a unsync spte

Guest                               Host
                                     spte = (gfn1, pfn1)

modify gpte to let it point to gfn2
                                    spte = (gfn1, pfn1)
page-fault on gpte
                                    intercept the page-fault, then
                                    want to update spte to (gfn2, pfn2)

                                    in mmu_set_spte, we can detect
                                    pfn2 != pfn1, then drop it.

Hmm, the interesting thing is what if different gfns map to the same pfn.
For example, spte1 is shadowed by gfn1 and spte2 is shadowed by pfn2, both
gfn1 and gfn2 map to pfn, the code (including the current code) will set
spte1 to the gfn2's rmap and spte2 to the gfn1's rmap. But i think it is ok.





  reply	other threads:[~2012-11-20 23:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-05 12:09 [PATCH 1/5] KVM: MMU: cleanup mapping-level Xiao Guangrong
2012-11-05 12:10 ` [PATCH 2/5] KVM: MMU: simplify mmu_set_spte Xiao Guangrong
2012-11-12 23:12   ` Marcelo Tosatti
2012-11-13  8:39     ` Xiao Guangrong
2012-11-20 22:18       ` Marcelo Tosatti
2012-11-20 23:23         ` Xiao Guangrong [this message]
2012-11-20 23:51           ` Marcelo Tosatti
2012-11-21  3:19             ` Xiao Guangrong
2012-11-05 12:11 ` [PATCH 3/5] KVM: MMU: simplify set_spte Xiao Guangrong
2012-11-20 22:24   ` Marcelo Tosatti
2012-11-20 23:26     ` Xiao Guangrong
2012-11-05 12:12 ` [PATCH 4/5] KVM: MMU: move adjusting softmmu pte access to FNAME(page_fault) Xiao Guangrong
2012-11-20 22:27   ` Marcelo Tosatti
2012-11-20 23:28     ` Xiao Guangrong
2012-11-05 12:12 ` [PATCH 5/5] KVM: MMU: remove pt_access in mmu_set_spte Xiao Guangrong

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=50AC10EE.8000008@linux.vnet.ibm.com \
    --to=xiaoguangrong@linux.vnet.ibm.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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