From: "Jan Beulich" Subject: Re: [PATCHv3 3/4] xen: use ticket locks for spin locks Date: Thu, 23 Apr 2015 15:58:42 +0100 Message-ID: <553924C20200007800075518@mail.emea.novell.com> References: <1429611088-23950-1-git-send-email-david.vrabel@citrix.com> <1429611088-23950-4-git-send-email-david.vrabel@citrix.com> <20150423120302.GG10810@deinos.phlegethon.org> <553915BA0200007800075314@mail.emea.novell.com> <20150423144342.GC10824@deinos.phlegethon.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YlIaT-0003Ts-0L for xen-devel@lists.xenproject.org; Thu, 23 Apr 2015 14:58:45 +0000 In-Reply-To: <20150423144342.GC10824@deinos.phlegethon.org> 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: Tim Deegan Cc: Keir Fraser , Ian Campbell , Stefano Stabellini , Andrew Cooper , Jennifer Herbert , David Vrabel , xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org >>> On 23.04.15 at 16:43, wrote: > At 14:54 +0100 on 23 Apr (1429800874), Jan Beulich wrote: >> >>> On 23.04.15 at 14:03, wrote: >> > At 11:11 +0100 on 21 Apr (1429614687), David Vrabel wrote: >> >> void _spin_unlock(spinlock_t *lock) >> >> { >> >> + smp_mb(); >> >> preempt_enable(); >> >> LOCK_PROFILE_REL; >> >> - _raw_spin_unlock(&lock->raw); >> >> + lock->tickets.head++; >> > >> > This needs to be done with an explicit atomic (though not locked) >> > write; otherwise the compiler might use some unsuitable operation that >> > clobbers .tail as well. >> >> How do you imagine that to happen? An increment of one >> structure member surely won't modify any others. > > AIUI, the '++' could end up as a word-size read, modify, and word-size > write. If another CPU updates .tail parallel, that update could get > lost. Ah, right, compilers are allowed to do that, albeit normally wouldn't unless the architecture has no suitable loads/stores. Jan