From: "Jan Beulich" Subject: Re: [PATCH] MCE: Fix race condition in mctelem_reserve Date: Wed, 22 Jan 2014 12:21:00 +0000 Message-ID: <52DFC5BC0200007800115C92@nat28.tlf.novell.com> References: <1390387834.32296.1.camel@hamster.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1390387834.32296.1.camel@hamster.uk.xensource.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: Frediano Ziglio Cc: Liu Jinsong , Christoph Egger , David Vrabel , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org >>> On 22.01.14 at 11:50, Frediano Ziglio wrote: > These lines (in mctelem_reserve) > > > newhead = oldhead->mcte_next; > if (cmpxchgptr(freelp, oldhead, newhead) == oldhead) { > > are racy. After you read the newhead pointer it can happen that another > flow (thread or recursive invocation) change all the list but set head > with same value. So oldhead is the same as *freelp but you are setting > a new head that could point to whatever element (even already used). > > This patch use instead a bit array and atomic bit operations. > > Actually it use unsigned long instead of bitmap type as testing for > all zeroes is easier. Except you never test for all zeroes. All of the operations you use (with the exception of find_first_set_bit(), which would need replacing by find_first_bit()) are suitable to be used on bitmaps, so I really don't see why this can't be a proper bitmap. Jan