From: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
To: Avi Kivity <avi@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
LKML <linux-kernel@vger.kernel.org>, KVM <kvm@vger.kernel.org>
Subject: Re: [PATCH v3 03/11] KVM: x86: retry non-page-table writing instruction
Date: Wed, 14 Sep 2011 02:24:18 +0800 [thread overview]
Message-ID: <4E6F9FD2.4010407@cn.fujitsu.com> (raw)
In-Reply-To: <4E6F34CF.1060302@redhat.com>
On 09/13/2011 06:47 PM, Avi Kivity wrote:
> On 08/30/2011 05:35 AM, Xiao Guangrong wrote:
>> If the emulation is caused by #PF and it is non-page_table writing instruction,
>> it means the VM-EXIT is caused by shadow page protected, we can zap the shadow
>> page and retry this instruction directly
>>
>> The idea is from Avi
>>
>>
>> int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len);
>> +bool page_table_writing_insn(struct x86_emulate_ctxt *ctxt);
>
> Please use the usual x86_ prefix used in the emulator interface.
>
OK, will fix.
>> @@ -3720,10 +3721,18 @@ void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
>> kvm_mmu_commit_zap_page(vcpu->kvm,&invalid_list);
>> }
>>
>> +static bool is_mmio_page_fault(struct kvm_vcpu *vcpu, gva_t addr)
>> +{
>> + if (vcpu->arch.mmu.direct_map || mmu_is_nested(vcpu))
>> + return vcpu_match_mmio_gpa(vcpu, addr);
>> +
>> + return vcpu_match_mmio_gva(vcpu, addr);
>> +}
>> +
>> int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u32 error_code,
>> void *insn, int insn_len)
>> {
>> - int r;
>> + int r, emulation_type = EMULTYPE_RETRY;
>> enum emulation_result er;
>>
>> r = vcpu->arch.mmu.page_fault(vcpu, cr2, error_code, false);
>> @@ -3735,7 +3744,10 @@ int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u32 error_code,
>> goto out;
>> }
>>
>> - er = x86_emulate_instruction(vcpu, cr2, 0, insn, insn_len);
>> + if (is_mmio_page_fault(vcpu, cr2))
>> + emulation_type = 0;
>> +
>> + er = x86_emulate_instruction(vcpu, cr2, emulation_type, insn, insn_len);
>>
>> switch (er) {
>> case EMULATE_DONE:
>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>> index 6b37f18..1afe59e 100644
>> --- a/arch/x86/kvm/x86.c
>> +++ b/arch/x86/kvm/x86.c
>> @@ -4814,6 +4814,50 @@ static bool reexecute_instruction(struct kvm_vcpu *vcpu, gva_t gva)
>> return false;
>> }
>>
>> +static bool retry_instruction(struct x86_emulate_ctxt *ctxt,
>> + unsigned long cr2, int emulation_type)
>> +{
>> + if (!vcpu->arch.mmu.direct_map&& !mmu_is_nested(vcpu))
>> + gpa = kvm_mmu_gva_to_gpa_write(vcpu, cr2, NULL);
>
> If mmu_is_nested() cr2 is an ngpa, we have to translate it to a gpa, no?
>
Yeah, will fix it.
And this bug also exists in the current code: it always uses L2 gpa to emulate
write operation.
I guess the reason that it is not triggered is: the gpa of L2's shadow page can
not be touched by L2, it means no page table is write-protected by L2.
> btw, I don't see mmu.direct_map initialized for nested npt?
>
nested_svm_vmrun() -> nested_svm_init_mmu_context():
static int nested_svm_init_mmu_context(struct kvm_vcpu *vcpu)
{
int r;
r = kvm_init_shadow_mmu(vcpu, &vcpu->arch.mmu);
vcpu->arch.mmu.set_cr3 = nested_svm_set_tdp_cr3;
vcpu->arch.mmu.get_cr3 = nested_svm_get_tdp_cr3;
vcpu->arch.mmu.get_pdptr = nested_svm_get_tdp_pdptr;
vcpu->arch.mmu.inject_page_fault = nested_svm_inject_npf_exit;
vcpu->arch.mmu.shadow_root_level = get_npt_level();
vcpu->arch.walk_mmu = &vcpu->arch.nested_mmu;
return r;
}
It is initialized in kvm_init_shadow_mmu :-)
next prev parent reply other threads:[~2011-09-13 18:21 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-30 2:34 [PATCH v3 01/11] KVM: MMU: avoid pte_list_desc running out in kvm_mmu_pte_write Xiao Guangrong
2011-08-30 2:34 ` [PATCH v3 02/11] KVM: x86: tag the instructions which are used to write page table Xiao Guangrong
2011-08-30 2:35 ` [PATCH v3 03/11] KVM: x86: retry non-page-table writing instruction Xiao Guangrong
2011-09-13 10:47 ` Avi Kivity
2011-09-13 18:24 ` Xiao Guangrong [this message]
2011-09-14 9:53 ` Avi Kivity
2011-09-14 10:19 ` Xiao Guangrong
2011-09-15 4:56 ` Xiao Guangrong
2011-08-30 2:35 ` [PATCH v3 04/11] KVM: x86: cleanup port-in/port-out emulated Xiao Guangrong
2011-08-30 2:35 ` [PATCH v3 05/11] KVM: MMU: do not mark accessed bit on pte write path Xiao Guangrong
2011-09-13 10:53 ` Avi Kivity
2011-09-13 18:29 ` Xiao Guangrong
2011-09-14 9:55 ` Avi Kivity
2011-09-15 13:11 ` Marcelo Tosatti
2011-08-30 2:36 ` [PATCH v3 06/11] KVM: MMU: cleanup FNAME(invlpg) Xiao Guangrong
2011-09-13 11:00 ` Avi Kivity
2011-09-13 18:31 ` Xiao Guangrong
2011-09-14 9:57 ` Avi Kivity
2011-08-30 2:36 ` [PATCH v3 07/11] KVM: MMU: fast prefetch spte on invlpg path Xiao Guangrong
2011-08-30 2:37 ` [PATCH v3 08/11] KVM: MMU: remove unnecessary kvm_mmu_free_some_pages Xiao Guangrong
2011-08-30 2:37 ` [PATCH v3 09/11] KVM: MMU: split kvm_mmu_pte_write function Xiao Guangrong
2011-08-30 2:37 ` [PATCH v3 10/11] KVM: MMU: fix detecting misaligned accessed Xiao Guangrong
2011-08-30 2:38 ` [PATCH v3 11/11] KVM: MMU: improve write flooding detected Xiao Guangrong
2011-09-13 11:07 ` Avi Kivity
2011-09-13 19:19 ` Xiao Guangrong
2011-09-14 9:59 ` Avi Kivity
2011-09-13 9:51 ` [PATCH v3 01/11] KVM: MMU: avoid pte_list_desc running out in kvm_mmu_pte_write Avi Kivity
2011-09-13 10:24 ` Xiao Guangrong
2011-09-13 10:50 ` Avi Kivity
2011-09-13 19:31 ` 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=4E6F9FD2.4010407@cn.fujitsu.com \
--to=xiaoguangrong@cn.fujitsu.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