From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [RFC PATCH] x86 emulator: emulate CPUID instruction Date: Sun, 21 Dec 2008 14:11:31 +0200 Message-ID: <494E3273.4050402@redhat.com> References: <20081215124355.009afdb5@frecb000711> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: Guillaume Thouvenin Return-path: Received: from mx2.redhat.com ([66.187.237.31]:57698 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751483AbYLUMLl (ORCPT ); Sun, 21 Dec 2008 07:11:41 -0500 In-Reply-To: <20081215124355.009afdb5@frecb000711> Sender: kvm-owner@vger.kernel.org List-ID: Guillaume Thouvenin wrote: > This patch emulates CPUID instruction. It should work but when I'm > testing it in kvm-userspace, the cpuid instruction seems to have no > effect (I mean eax == ebx == ecx == edx == 0x0). Should > kvm_cpuid_emulate() be modified? Is cpuid instruction correctly > implemented? > > It doesn't have any effect because writeback() writes back the cached registers back into vcpu->arch.regs, overwriting kvm_cpuid_emulate()'s effect. You need to first modify kvm_cpuid_emulate() to accept the registers as in/out parameters, and pass the emulator's registers which can be later written back. An alternative implementation can modify the emulator not to work on a temporarary copy, instead something like this: decode(): copy registers to backup store execute(): start executing if fail: copy registers from backup store to main state The later approach is more invasive, but has the advantage of speeding up the emulator (since usually emulation will succeed, so we don't need to writeback) -- error compiling committee.c: too many arguments to function