From: Ian Campbell Subject: Re: [PATCH 2/4] fix XENMEM_add_to_physmap preemption handling Date: Fri, 20 Dec 2013 09:02:37 +0000 Message-ID: <1387530157.1025.57.camel@dagon.hellion.org.uk> References: <52B1BF76020000780010EC02@nat28.tlf.novell.com> <52B1C0AB020000780010EC23@nat28.tlf.novell.com> <1387389545.28680.104.camel@kazak.uk.xensource.com> <52B4054C020000780010F5CE@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Vtvyk-0007A9-0q for xen-devel@lists.xenproject.org; Fri, 20 Dec 2013 09:02:42 +0000 In-Reply-To: <52B4054C020000780010F5CE@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jan Beulich Cc: xen-devel , Tim Deegan , Keir Fraser , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org On Fri, 2013-12-20 at 07:52 +0000, Jan Beulich wrote: > >>> On 18.12.13 at 18:59, Ian Campbell wrote: > > On Wed, 2013-12-18 at 14:35 +0000, Jan Beulich wrote: > >> J > >> /* Check for continuation if it's not the last interation. */ > >> - if ( xatp->size > 0 && hypercall_preempt_check() ) > >> + if ( xatp->size > ++done && hypercall_preempt_check() ) > > > > Hiding the loop increment inside the preemption checking is a bit subtle > > (it took me a while to find it). Can't it go either before or after this > > loop? With a suitable +/- 1 to the rc below if necessary. > > It could, but I find it quite natural to be together with the check. If it were the loop termination check or something then I would agree, but this is effectively some other arbitrary check within the loop (even if it does happen to exit, it's not the primary loop termination condition). > >> @@ -724,6 +731,12 @@ long do_memory_op(unsigned long cmd, XEN > >> { > >> struct xen_add_to_physmap xatp; > >> > >> + BUILD_BUG_ON((typeof(xatp.size))-1 > (UINT_MAX >> MEMOP_EXTENT_SHIFT)); > > > > What does "typeof(xatp.size)-1" evaluate to? typeof can't return an int, > > cant it? > > Properly parenthesized this is ((uint16_t)-1), i.e. 0xffff Ah! Yes, I misread that rather badly. > (typeof() doesn't produce a value, but a type). I know, that's why I was so confused when it looked like it was being treated as a value! > >> + > >> + /* Check for faked input. */ > > > > Faked as in "malicious" or faked as in "something we made up for > > continuation purposes" ? > > As in "malicious" (or buggy), i.e. the caller passing an out of range > "cmd" to HYPERVISOR_memory_op. Do you have any better wording > in mind? "Check for malicious or buggy input" would do the job. (with or without "or buggy") Ian.