From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gleb Natapov Subject: Re: [PATCH v2 28/30] KVM: x86 emulator: restart string instruction without going back to a guest. Date: Sun, 14 Mar 2010 20:06:25 +0200 Message-ID: <20100314180625.GB5406@redhat.com> References: <1268583675-3101-1-git-send-email-gleb@redhat.com> <1268583675-3101-29-git-send-email-gleb@redhat.com> <4B9D1545.2020902@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: mtosatti@redhat.com, kvm@vger.kernel.org To: Avi Kivity Return-path: Received: from mx1.redhat.com ([209.132.183.28]:35620 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757271Ab0CNSG1 (ORCPT ); Sun, 14 Mar 2010 14:06:27 -0400 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 o2EI6QlK024212 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 14 Mar 2010 14:06:27 -0400 Content-Disposition: inline In-Reply-To: <4B9D1545.2020902@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Sun, Mar 14, 2010 at 06:56:37PM +0200, Avi Kivity wrote: > On 03/14/2010 06:21 PM, Gleb Natapov wrote: > >Currently when string instruction is only partially complete we go back > >to a guest mode, guest tries to reexecute instruction and exits again > >and at this point emulation continues. Avoid all of this by restarting > >instruction without going back to a guest mode, but return to a guest > >mode on each page boundary to allow interrupt injection. Pending > >exception causes immediate guest entry too. > > > >@@ -2913,6 +2917,8 @@ writeback: > > c->dst.ptr = (unsigned long *) > > register_address(c, es_base(ctxt), > > c->regs[VCPU_REGS_RDI]); > >+ if (!(c->regs[VCPU_REGS_RDI]& ~PAGE_MASK)) > >+ ctxt->restart = false; > > } > > What if rdi is odd and operand size != 1? > Will change to if ((c->regs[VCPU_REGS_RDI]& ~PAGE_MASK) < c->dst.bytes) > Suggest simply reentering every N executions. > This restart mechanism is, in fact, needed for ins read ahead to work. After reading ahead from IO port we need to avoid entering decoder until entire cache is consumed otherwise decoder will clear cache and data will be lost. So we can't just enter guest in arbitrary times, only when read ahead cache is empty. Since read ahead is never done across page boundary this is save place to re-enter guest. -- Gleb.