From: "Jan Beulich" Subject: Re: [PATCH v6 02/16] x86/hvm: remove multiple open coded 'chunking' loops Date: Wed, 08 Jul 2015 17:18:51 +0100 Message-ID: <559D698B020000780008E639@mail.emea.novell.com> References: <1435940733-20856-1-git-send-email-paul.durrant@citrix.com> <1435940733-20856-3-git-send-email-paul.durrant@citrix.com> <559D6378020000780008E5EA@mail.emea.novell.com> <9AAE0902D5BC7E449B7C8E4E778ABCD02F4A5B79@AMSPEX01CL03.citrite.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZCs3i-0005dC-2F for xen-devel@lists.xenproject.org; Wed, 08 Jul 2015 16:18:54 +0000 In-Reply-To: <9AAE0902D5BC7E449B7C8E4E778ABCD02F4A5B79@AMSPEX01CL03.citrite.net> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Paul Durrant Cc: Andrew Cooper , "Keir(Xen.org)" , "xen-devel@lists.xenproject.org" List-Id: xen-devel@lists.xenproject.org >>> On 08.07.15 at 17:57, wrote: >> -----Original Message----- >> From: xen-devel-bounces@lists.xen.org [mailto:xen-devel- >> bounces@lists.xen.org] On Behalf Of Jan Beulich >> Sent: 08 July 2015 16:53 >> To: Andrew Cooper; Paul Durrant >> Cc: xen-devel@lists.xenproject.org; Keir (Xen.org) >> Subject: Re: [Xen-devel] [PATCH v6 02/16] x86/hvm: remove multiple open >> coded 'chunking' loops >> >> >>> On 03.07.15 at 18:25, wrote: >> > +static int hvmemul_linear_mmio_access( >> > + unsigned long gla, unsigned int size, uint8_t dir, uint8_t *buffer, >> > + uint32_t pfec, struct hvm_emulate_ctxt *hvmemul_ctxt, bool_t >> known_gpfn) >> > +{ >> > + struct hvm_vcpu_io *vio = ¤t->arch.hvm_vcpu.hvm_io; >> > + unsigned long offset = gla & ~PAGE_MASK; >> > + unsigned int chunk; >> > + paddr_t gpa; >> > + unsigned long one_rep = 1; >> > + int rc; >> > + >> > + chunk = min_t(unsigned int, size, PAGE_SIZE - offset); >> > + >> > + if ( known_gpfn ) >> > + gpa = pfn_to_paddr(vio->mmio_gpfn) | offset; >> > + else >> > + { >> > + rc = hvmemul_linear_to_phys(gla, &gpa, chunk, &one_rep, pfec, >> > + hvmemul_ctxt); >> > + if ( rc != X86EMUL_OKAY ) >> > + return rc; >> > + } >> > + >> > + for ( ;; ) >> > + { >> > + rc = hvmemul_phys_mmio_access(gpa, chunk, dir, buffer); >> > + if ( rc != X86EMUL_OKAY ) >> > + break; >> > + >> > + gla += chunk; >> > + buffer += chunk; >> > + size -= chunk; >> > + >> > + if ( size == 0 ) >> > + break; >> > + >> > + ASSERT((gla & ~PAGE_MASK) == 0); >> >> Does this really matter for the code below? >> >> > + chunk = min_t(unsigned int, size, PAGE_SIZE); >> >> Iirc Andrew had asked for this, but I still don't see why: "size" is the >> width of an instruction operand, and hence won't even come close >> to PAGE_SIZE. >> > > I'll let Andrew answer that one. I've already ping-ponged once on this. > > I guess it makes it safer if someone were to try to use this function for > another purpose in future? I can't see such future use, and hence can't see why we should make this slower than it needs to be. Jan