From: Alexander Graf Subject: [PATCH] nested SVM: don't run into endless loop Date: Thu, 18 Dec 2008 13:30:57 +0100 Message-ID: <1229603457-11140-1-git-send-email-agraf@suse.de> To: kvm@vger.kernel.org Return-path: Received: from ns1.suse.de ([195.135.220.2]:47178 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750796AbYLRMa7 (ORCPT ); Thu, 18 Dec 2008 07:30:59 -0500 Received: from Relay1.suse.de (relay-ext.suse.de [195.135.221.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id ED6D445794 for ; Thu, 18 Dec 2008 13:30:57 +0100 (CET) Sender: kvm-owner@vger.kernel.org List-ID: With the emulation optimization after clgi, we can potentially run into an endless loop thanks to while(true). While this should never occur in practise, except for when the emulation is broken or really awkward code is executed in the VM, this wasn't a problem so far. Signed-off-by: Alexander Graf --- arch/x86/kvm/svm.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index f67ca16..bf901e7 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -1848,6 +1848,8 @@ static int stgi_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) static int clgi_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) { + int loopcount = 0; + if (nested_svm_check_permissions(svm)) return 1; @@ -1862,7 +1864,7 @@ static int clgi_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) /* Let's try to emulate as many instructions as possible in GIF=0 */ - while(true) { + while(++loopcount < 100) { int er; er = emulate_instruction(&svm->vcpu, kvm_run, 0, 0, 0); -- 1.5.6