From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: KVM: x86: use kvm_set_cr3/cr4 in ioctl_set_sregs Date: Thu, 16 Apr 2009 12:23:56 +0300 Message-ID: <49E6F92C.2000202@redhat.com> References: <20090415221042.GA20127@amt.cnet> <49E6F2AF.9050300@redhat.com> <20090416091042.GA6709@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm To: Marcelo Tosatti Return-path: Received: from mx2.redhat.com ([66.187.237.31]:60499 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752464AbZDPJYA (ORCPT ); Thu, 16 Apr 2009 05:24:00 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n3G9O09Q016477 for ; Thu, 16 Apr 2009 05:24:00 -0400 In-Reply-To: <20090416091042.GA6709@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: Marcelo Tosatti wrote: > Humpf. And something like this? Or GP# instead of triple fault? > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 148cde2..3e63bac 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -3986,7 +3986,10 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, > > vcpu->arch.cr2 = sregs->cr2; > mmu_reset_needed |= vcpu->arch.cr3 != sregs->cr3; > - vcpu->arch.cr3 = sregs->cr3; > + if (gfn_to_memslot(vcpu->kvm, sregs->cr3 >> PAGE_SHIFT)) > + vcpu->arch.cr3 = sregs->cr3; > + else > + set_bit(KVM_REQ_TRIPLE_FAULT, &vcpu->requests); > > kvm_set_cr8(vcpu, sregs->cr8); > Well, that plugs the hole. Triple fault is better than #GP IMO. We're still missing checks on reserved bits, etc., but that can come later. -- Do not meddle in the internals of kernels, for they are subtle and quick to panic.