From: "Jan Beulich" Subject: Re: [PATCHv3 1/4] x86: provide xadd() Date: Tue, 21 Apr 2015 11:36:35 +0100 Message-ID: <553644530200007800074374@mail.emea.novell.com> References: <1429611088-23950-1-git-send-email-david.vrabel@citrix.com> <1429611088-23950-2-git-send-email-david.vrabel@citrix.com> 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 1YkVXi-0005rz-EZ for xen-devel@lists.xenproject.org; Tue, 21 Apr 2015 10:36:38 +0000 In-Reply-To: <1429611088-23950-2-git-send-email-david.vrabel@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: David Vrabel Cc: Keir Fraser , Ian Campbell , Stefano Stabellini , Andrew Cooper , Jennifer Herbert , Tim Deegan , xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org >>> On 21.04.15 at 12:11, wrote: > +static always_inline unsigned long __xadd( > + volatile void *ptr, unsigned long v, int size) > +{ > + switch ( size ) > + { > + case 1: > + asm volatile ( "lock; xaddb %b0,%1" > + : "+r" (v), "+m" (*__xg((volatile void *)ptr)) > + :: "memory"); > + return v; This doesn't seem to guarantee to return the old value: When the passed in v has more than 8 significant bits (which will get ignored as input), nothing will zap those bits from the register. Same for the 16-bit case obviously. > +#define xadd(ptr, v) ({ \ > + __xadd((ptr), (unsigned long)(v), sizeof(*(ptr))); \ > + }) Assuming only xadd() is supposed to be used directly, perhaps the easiest would be to cast v to typeof(*(ptr)) (instead of unsigned long) here? Also note that there's still a superfluous pair of parentheses left here. Jan