Patch "KVM: MMU: Fix infinite loop when there is no available mmu page" has been added to the 4.14-stable tree
Subsystems (3)
This is a note to let you know that I've just added the patch titled
KVM: MMU: Fix infinite loop when there is no available mmu page
to the 4.14-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
kvm-mmu-fix-infinite-loop-when-there-is-no-available-mmu-page.patch
and it can be found in the queue-4.14 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
ed52870f4676489124d8697fd00e6ae6c504e586Mon Sep 17 00:00:00 2001
From: Wanpeng Li <[email protected]>
Date: Mon, 4 Dec 2017 22:21:30 -0800
Subject: KVM: MMU: Fix infinite loop when there is no available mmu page
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
From: Wanpeng Li <[email protected]>
commit ed52870f4676489124d8697fd00e6ae6c504e586 upstream.
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 page for root page table.
--- arch/x86/kvm/mmu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/kvm/mmu.c +4 -4
@@ -3382,7 +3382,7 @@ static int mmu_alloc_direct_roots(structspin_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 );
@@ -3397,7 +3397,7 @@ static int mmu_alloc_direct_roots(structspin_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 );
@@ -3437,7 +3437,7 @@ static int mmu_alloc_shadow_roots(structspin_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 );
@@ -3474,7 +3474,7 @@ static int mmu_alloc_shadow_roots(structspin_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 );
Patches currently in stable-queue which might be from [email protected] are
queue-4.14/kvm-mmu-fix-infinite-loop-when-there-is-no-available-mmu-page.patch queue-4.14/kvm-x86-fix-load-rflags-w-o-the-fixed-bit.patch