From: "Jan Beulich" Subject: Re: [PATCH v6 09/16] x86/hvm: limit reps to avoid the need to handle retry Date: Thu, 09 Jul 2015 14:38:14 +0100 Message-ID: <559E9566020000780008ED75@mail.emea.novell.com> References: <1435940733-20856-1-git-send-email-paul.durrant@citrix.com> <1435940733-20856-10-git-send-email-paul.durrant@citrix.com> <559E6387020000780008EAB5@mail.emea.novell.com> <9AAE0902D5BC7E449B7C8E4E778ABCD02F4B52C9@AMSPEX01CL02.citrite.net> <559E7F61020000780008EBE9@mail.emea.novell.com> <9AAE0902D5BC7E449B7C8E4E778ABCD02F4B556A@AMSPEX01CL02.citrite.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZDC1p-0004t9-SJ for xen-devel@lists.xenproject.org; Thu, 09 Jul 2015 13:38:17 +0000 In-Reply-To: <9AAE0902D5BC7E449B7C8E4E778ABCD02F4B556A@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: Paul Durrant Cc: Andrew Cooper , "Keir(Xen.org)" , "xen-devel@lists.xenproject.org" List-Id: xen-devel@lists.xenproject.org >>> On 09.07.15 at 14:50, wrote: >> From: Jan Beulich [mailto:JBeulich@suse.com] >> Sent: 09 July 2015 13:04 >> >>> On 09.07.15 at 13:11, wrote: >> >> From: Jan Beulich [mailto:JBeulich@suse.com] >> >> Sent: 09 July 2015 11:05 >> >> >>> On 03.07.15 at 18:25, wrote: >> >> > @@ -287,17 +271,56 @@ static int hvmemul_do_io_addr( >> >> > bool_t is_mmio, paddr_t addr, unsigned long *reps, >> >> > unsigned int size, uint8_t dir, bool_t df, paddr_t ram_gpa) >> >> > { >> >> > - struct page_info *ram_page; >> >> > + struct vcpu *v = current; >> >> > + unsigned long ram_gmfn = paddr_to_pfn(ram_gpa); >> >> > + unsigned int page_off = ram_gpa & (PAGE_SIZE - 1); >> >> > + struct page_info *ram_page[2]; >> >> > + int nr_pages = 0; >> >> >> >> unsigned int >> > >> > No, it's intentionally signed because the unwind code at the end of the >> > function is: >> > >> > while ( --nr_pages >= 0 ) >> > hvmemul_release_page(ram_page[nr_pages]); >> > >> > I.e. the loop terminates when nr_pages gets to -1. >> >> while ( nr_pages-- ) >> hvmemul_release_page(ram_page[nr_pages]); >> > > But that wouldn't be correct, since the loop would try to release > ram_page[1] and ram_page[0] in the case where only ram_page[0] had been > acquired. It would have to be: > > while ( nr_pages ) > hvmemul_release_page(ram_page[--nr_pages]); Unless you need the value of nr_pages after the loop, I can't see the difference between your and my proposal - the decrement in both cases happens between determining whether to continue the loop and accessing the intended array element. > which I'll do, since you so dislike signed ints. Sounds like you're not understanding why. Just look at the generated code when using signed vs unsigned int as array index. Jan