From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753877AbbCPMqW (ORCPT ); Mon, 16 Mar 2015 08:46:22 -0400 Received: from foss.arm.com ([217.140.101.70]:56286 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753364AbbCPMqS (ORCPT ); Mon, 16 Mar 2015 08:46:18 -0400 Date: Mon, 16 Mar 2015 12:45:45 +0000 From: Mark Rutland To: Christoph Lameter Cc: "linux-kernel@vger.kernel.org" , Andrew Morton , Catalin Marinas , David Rientjes , Jesper Dangaard Brouer , Joonsoo Kim , Linus Torvalds , Pekka Enberg , Steve Capper Subject: [PATCHv2] mm/slub: fix lockups on PREEMPT && !SMP kernels Message-ID: <20150316124544.GG15066@leverpostej> References: <1426261632-8911-1-git-send-email-mark.rutland@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 13, 2015 at 04:29:23PM +0000, Christoph Lameter wrote: > On Fri, 13 Mar 2015, Mark Rutland wrote: > > > */ > > - do { > > - tid = this_cpu_read(s->cpu_slab->tid); > > - c = raw_cpu_ptr(s->cpu_slab); > > - } while (IS_ENABLED(CONFIG_PREEMPT) && unlikely(tid != c->tid)); > > + c = raw_cpu_ptr(s->cpu_slab); > > + tid = READ_ONCE(c->tid); > > > > Ok that works for the !SMP case. What about SMP and PREEMPT now? > > And yes code like this was deemed safe for years and the race condition is > very subtle and difficult to trigger (also given that PREEMPT is rarely > used these days). Do you mean if the READ_ONCE(c->tid) gives us a torn value that happens to be a future value of c->tid? Are you happy to retain the loop, but with the c->tid access replaced with READ_ONCE(c->tid)? If torn values are an issue for the raw access then the loop doesn't guarantee that c and tid were read on the same CPU as the comment above it implies. The cmpxchg saves us given the torn value would have to match some currently active tid, and I guess the loop saves a pointless cmpxchg when it does detect a mismatch. Mark.