From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH v3] KVM: x86 emulator: access GPRs on demand Date: Mon, 27 Aug 2012 13:24:46 -0700 Message-ID: <503BD78E.2090201@redhat.com> References: <1345128889-29672-1-git-send-email-avi@redhat.com> <20120817172938.GA21708@amt.cnet> <5030B2B4.8050100@redhat.com> <20120823081427.GA27248@amt.cnet> <20120826170414.GA21928@amt.cnet> <503BD71F.5090008@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: Marcelo Tosatti Return-path: Received: from mx1.redhat.com ([209.132.183.28]:52315 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754418Ab2H0UYr (ORCPT ); Mon, 27 Aug 2012 16:24:47 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q7RKOllQ000340 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 27 Aug 2012 16:24:47 -0400 In-Reply-To: <503BD71F.5090008@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 08/27/2012 01:22 PM, Avi Kivity wrote: > On 08/26/2012 10:04 AM, Marcelo Tosatti wrote: > > On Thu, Aug 23, 2012 at 05:14:27AM -0300, Marcelo Tosatti wrote: > > > On Sun, Aug 19, 2012 at 12:32:36PM +0300, Avi Kivity wrote: > > > > On 08/17/2012 08:29 PM, Marcelo Tosatti wrote: > > > > > On Thu, Aug 16, 2012 at 05:54:49PM +0300, Avi Kivity wrote: > > > > >> Instead of populating the the entire register file, read in registers > > > > >> as they are accessed, and write back only the modified ones. This > > > > >> saves a VMREAD and VMWRITE on Intel (for rsp, since it is not usually > > > > >> used during emulation), and a two 128-byte copies for the registers. > > > > >> > > > > > > > > > >> @@ -2715,14 +2764,17 @@ int emulator_task_switch(struct x86_emulate_ctxt *ctxt, > > > > >> { > > > > >> int rc; > > > > >> > > > > >> + invalidate_registers(ctxt); > > > > >> ctxt->_eip = ctxt->eip; > > > > >> ctxt->dst.type = OP_NONE; > > > > >> > > > > >> rc = emulator_do_task_switch(ctxt, tss_selector, idt_index, reason, > > > > >> has_error_code, error_code); > > > > >> > > > > >> - if (rc == X86EMUL_CONTINUE) > > > > >> + if (rc == X86EMUL_CONTINUE) { > > > > >> ctxt->eip = ctxt->_eip; > > > > >> + writeback_registers(ctxt); > > > > >> + } > > > > >> > > > > >> return (rc == X86EMUL_UNHANDLEABLE) ? EMULATION_FAILED : EMULATION_OK; > > > > >> } > > > > > > > > > > > > > > > No clear point when emulator register cache is active, when it is > > > > > not (AFAICS this patch does not invalidate registers on emulation start > > > > > (the above being one of the exceptions) does not clear valid bit on > > > > > writeback-to-vcpu-cache on emulation exit). > > > > > > > > It is cleared when emulation starts. For the non-insn-emulation entry > > > > points, there is an explicit invalidate. For the emulation entry point, > > > > there is a memset() that clears everything up to _regs, which includes > > > > the cache. This discrepancy isn't nice, but it preexists. I don't know > > > > whether we should decompose the memset() or not, it is rather efficient. > > > > > > > > > > > > > > Concern is that emulator can start with cached registers marked as valid > > > > > but in fact are invalid from previous emulation round. > > > > > > > > > > Maybe move invalidate() to init_emulate_ctxt? > > > > > > > > > > > > > See the memset() in init_decode_cache(). > > > > > > Right. Applied, thanks. > > > > Actually, had to revert because autotest was failing. > > > > Was it failing because of this patch? Or what? > I see, the rsp mask fix. -- I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.