From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH 02/24] KVM: Provide callback to get/set control registers in emulator ops. Date: Tue, 09 Mar 2010 16:18:09 +0200 Message-ID: <4B9658A1.6000207@redhat.com> References: <1268143762-4000-1-git-send-email-gleb@redhat.com> <1268143762-4000-3-git-send-email-gleb@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: Gleb Natapov Return-path: Received: from mx1.redhat.com ([209.132.183.28]:62075 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752768Ab0CIOSL (ORCPT ); Tue, 9 Mar 2010 09:18:11 -0500 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o29EIAaI006390 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 9 Mar 2010 09:18:11 -0500 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o29EIAKG028416 for ; Tue, 9 Mar 2010 09:18:10 -0500 In-Reply-To: <1268143762-4000-3-git-send-email-gleb@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: 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. > +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. -- error compiling committee.c: too many arguments to function