From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gleb Natapov Subject: Re: [PATCH 02/24] KVM: Provide callback to get/set control registers in emulator ops. Date: Tue, 9 Mar 2010 16:24:38 +0200 Message-ID: <20100309142438.GP16909@redhat.com> References: <1268143762-4000-1-git-send-email-gleb@redhat.com> <1268143762-4000-3-git-send-email-gleb@redhat.com> <4B9658A1.6000207@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org To: Avi Kivity Return-path: Received: from mx1.redhat.com ([209.132.183.28]:53896 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752542Ab0CIOYl (ORCPT ); Tue, 9 Mar 2010 09:24:41 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o29EOex1023649 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 9 Mar 2010 09:24:41 -0500 Content-Disposition: inline In-Reply-To: <4B9658A1.6000207@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Tue, Mar 09, 2010 at 04:18:09PM +0200, Avi Kivity wrote: > On 03/09/2010 04:09 PM, Gleb Natapov wrote: > >Use this callback instead of directly call kvm function. Also rename > >realmode_(set|get)_cr to emulator_(set|get)_cr since function has nothing > >to do with real mode. > > > > > >+ ulong (*get_cr)(int cr, struct kvm_vcpu *vcpu); > >+ void (*set_cr)(int cr, ulong val, struct kvm_vcpu *vcpu); > > }; > > Note, passing a vcpu means we are still tightly coupled to kvm. Can > be fixed later. > Yes, that is on my todo. > >+static unsigned long emulator_get_cr(int cr, struct kvm_vcpu *vcpu) > >+{ > >+ unsigned long value; > >+ > >+ switch (cr) { > >+ case 0: > >+ value = kvm_read_cr0(vcpu); > >+ break; > >+ case 2: > >+ value = vcpu->arch.cr2; > >+ break; > >+ case 3: > >+ value = vcpu->arch.cr3; > >+ break; > >+ case 4: > >+ value = kvm_read_cr4(vcpu); > >+ break; > >+ case 8: > >+ value = kvm_get_cr8(vcpu); > >+ break; > >+ default: > >+ vcpu_printf(vcpu, "%s: unexpected cr %u\n", __func__, cr); > >+ return 0; > > This printk is triggerable by guest code (as the patch didn't > introduce this, it can be fixed later). > > The emulator should #UD on unrecognised control registers. inject #UD on access to non-existing CR patch does this. -- Gleb.