From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Wanpeng Li <kernellwp@gmail.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Radim Krčmář" <rkrcmar@redhat.com>,
"Wanpeng Li" <wanpeng.li@hotmail.com>
Subject: Re: [PATCH v2 1/2] KVM: MMU: Fix infinite loop when there is no available mmu page
Date: Wed, 6 Dec 2017 06:12:37 -0500 [thread overview]
Message-ID: <20171206111237.GB28047@char.us.oracle.com> (raw)
In-Reply-To: <1512552510-13858-1-git-send-email-wanpeng.li@hotmail.com>
On Wed, Dec 06, 2017 at 01:28:30AM -0800, Wanpeng Li wrote:
> From: Wanpeng Li <wanpeng.li@hotmail.com>
>
> The below test case can cause infinite loop in kvm when ept=0.
>
> #include <unistd.h>
> #include <sys/syscall.h>
> #include <string.h>
> #include <stdint.h>
> #include <linux/kvm.h>
> #include <fcntl.h>
> #include <sys/ioctl.h>
>
> long r[5];
> int main()
> {
> r[2] = open("/dev/kvm", O_RDONLY);
> r[3] = ioctl(r[2], KVM_CREATE_VM, 0);
> r[4] = ioctl(r[3], KVM_CREATE_VCPU, 7);
> ioctl(r[4], KVM_RUN, 0);
> }
>
> It doesn't setup the memory regions, mmu_alloc_shadow/direct_roots() in
> kvm return 1 when kvm fails to allocate root page table which can result
> in beblow infinite loop:
>
> vcpu_run() {
> for (;;) {
> r = vcpu_enter_guest()::kvm_mmu_reload() returns 1
> if (r <= 0)
> break;
> if (need_resched())
> cond_resched();
> }
> }
>
> This patch fixes it by returning -ENOSPC when there is no available kvm mmu
No space left?
Why not ENXIO ?
> page for root page table.
>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Fixes: 26eeb53cf0f (KVM: MMU: Bail out immediately if there is no available mmu page)
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
> ---
> v1 -> v2:
> * cleanup patch description
>
> arch/x86/kvm/mmu.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> index c9aaa18..89da688 100644
> --- a/arch/x86/kvm/mmu.c
> +++ b/arch/x86/kvm/mmu.c
> @@ -3395,7 +3395,7 @@ static int mmu_alloc_direct_roots(struct kvm_vcpu *vcpu)
> spin_lock(&vcpu->kvm->mmu_lock);
> if(make_mmu_pages_available(vcpu) < 0) {
> spin_unlock(&vcpu->kvm->mmu_lock);
> - return 1;
> + return -ENOSPC;
> }
> sp = kvm_mmu_get_page(vcpu, 0, 0,
> vcpu->arch.mmu.shadow_root_level, 1, ACC_ALL);
> @@ -3410,7 +3410,7 @@ static int mmu_alloc_direct_roots(struct kvm_vcpu *vcpu)
> spin_lock(&vcpu->kvm->mmu_lock);
> if (make_mmu_pages_available(vcpu) < 0) {
> spin_unlock(&vcpu->kvm->mmu_lock);
> - return 1;
> + return -ENOSPC;
> }
> sp = kvm_mmu_get_page(vcpu, i << (30 - PAGE_SHIFT),
> i << 30, PT32_ROOT_LEVEL, 1, ACC_ALL);
> @@ -3450,7 +3450,7 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu)
> spin_lock(&vcpu->kvm->mmu_lock);
> if (make_mmu_pages_available(vcpu) < 0) {
> spin_unlock(&vcpu->kvm->mmu_lock);
> - return 1;
> + return -ENOSPC;
> }
> sp = kvm_mmu_get_page(vcpu, root_gfn, 0,
> vcpu->arch.mmu.shadow_root_level, 0, ACC_ALL);
> @@ -3487,7 +3487,7 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu)
> spin_lock(&vcpu->kvm->mmu_lock);
> if (make_mmu_pages_available(vcpu) < 0) {
> spin_unlock(&vcpu->kvm->mmu_lock);
> - return 1;
> + return -ENOSPC;
> }
> sp = kvm_mmu_get_page(vcpu, root_gfn, i << 30, PT32_ROOT_LEVEL,
> 0, ACC_ALL);
> --
> 2.7.4
>
prev parent reply other threads:[~2017-12-06 11:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-06 9:28 Wanpeng Li
2017-12-06 11:12 ` Konrad Rzeszutek Wilk [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=20171206111237.GB28047@char.us.oracle.com \
--to=konrad.wilk@oracle.com \
--cc=kernellwp@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=wanpeng.li@hotmail.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