From: "Jan Beulich" Subject: Re: [PATCH v6 02/16] x86/hvm: remove multiple open coded 'chunking' loops Date: Thu, 09 Jul 2015 10:19:16 +0100 Message-ID: <559E58B4020000780008EA37@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> <559D534E.7030704@citrix.com> <559E36A4020000780008E90E@mail.emea.novell.com> <9AAE0902D5BC7E449B7C8E4E778ABCD02F4B0D84@AMSPEX01CL02.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 1ZD7zD-0001Si-4x for xen-devel@lists.xenproject.org; Thu, 09 Jul 2015 09:19:19 +0000 In-Reply-To: <9AAE0902D5BC7E449B7C8E4E778ABCD02F4B0D84@AMSPEX01CL02.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: Andrew Cooper , Paul Durrant Cc: "xen-devel@lists.xenproject.org" , "Keir(Xen.org)" List-Id: xen-devel@lists.xenproject.org >>> On 09.07.15 at 10:15, wrote: >> -----Original Message----- >> From: Jan Beulich [mailto:JBeulich@suse.com] >> Sent: 09 July 2015 07:54 >> To: Andrew Cooper >> Cc: Paul Durrant; 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 08.07.15 at 18:43, wrote: >> > On 08/07/2015 16:57, Paul Durrant 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. >> > >> > The original version of the code asserted that size was less than >> > PAGE_SIZE around here. This is not true in the general case, given a >> > for loop like this and can in principle be hit if we ever got into a >> > position of emulating an xsave instruction to an MMIO region. >> >> That's a hypothetical future extension to XSAVE, isn't it? I.e. only >> when AVX-1024 eventually arrives ... >> >> > This specific example is not as far fetched as it seems. The VM >> > instrospection people are looking to emulate more and more instructions, >> > while the GVT-g are working on the mmio_write_dm side of things which >> > causes real RAM to be treated as MMIO from Xens point of view. >> >> ... and when we really think we need to support XSAVEing to MMIO >> or MMIO-like memory (which I doubt we will). >> >> > If we had some blanket sanity checks for size at the top of the >> > emulation calltree it would be less of an issue, but we don't and I have >> > a nagging feeing that assumptions like this are going to bite us in an >> > XSA-kind-of-way. >> >> Hence the ASSERT() against PAGE_SIZE that originally was there. >> > > Is there any harm in leaving the function as-is so that it can cope with size > > PAGE_SIZE in future? Well, not a big problem, but I generally prefer any unneeded conditionals to be removed. Considering that you and Andrew agree with one another, I guess I'll give in. Jan