From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: Re: [PATCHv3 1/4] x86: provide xadd() Date: Tue, 21 Apr 2015 13:36:30 +0100 Message-ID: <5536444E.2080807@citrix.com> References: <1429611088-23950-1-git-send-email-david.vrabel@citrix.com> <1429611088-23950-2-git-send-email-david.vrabel@citrix.com> <553644530200007800074374@mail.emea.novell.com> 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 1YkXPw-0003TA-7D for xen-devel@lists.xenproject.org; Tue, 21 Apr 2015 12:36:44 +0000 In-Reply-To: <553644530200007800074374@mail.emea.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 , David Vrabel Cc: Keir Fraser , Ian Campbell , Stefano Stabellini , Andrew Cooper , Tim Deegan , Jennifer Herbert , xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org On 21/04/15 11:36, Jan Beulich wrote: >>>> 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? I don't see how this helps. Did you perhaps mean cast the result? #define xadd(ptr, v) ({ \ (typeof *(ptr))__xadd(ptr, (unsigned long)(v), \ sizeof(*(ptr))); \ }) David