From: "Jan Beulich" Subject: Re: [PATCH v6 02/16] x86/hvm: remove multiple open coded 'chunking' loops Date: Wed, 08 Jul 2015 16:52:56 +0100 Message-ID: <559D6378020000780008E5EA@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> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZCree-0002sj-21 for xen-devel@lists.xenproject.org; Wed, 08 Jul 2015 15:53:00 +0000 In-Reply-To: <1435940733-20856-3-git-send-email-paul.durrant@citrix.com> 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: Andrew Cooper , Paul Durrant Cc: xen-devel@lists.xenproject.org, Keir Fraser List-Id: xen-devel@lists.xenproject.org >>> 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. > + rc = hvmemul_linear_to_phys(gla, &gpa, chunk, &one_rep, pfec, > + hvmemul_ctxt); The fact that &one_rep is being passed here also makes clear that we can't be dealing with an * situation. And if we were, "size" couldn't validly be "unsigned int". Jan