Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751886AbaBKNUE (ORCPT ); Tue, 11 Feb 2014 08:20:04 -0500 Received: from mail-pd0-f182.google.com ([209.85.192.182]:35306 "EHLO mail-pd0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751053AbaBKNUC (ORCPT ); Tue, 11 Feb 2014 08:20:02 -0500 MIME-Version: 1.0 In-Reply-To: <20140211121426.GQ4250@linux.vnet.ibm.com> References: <20140102203320.GA27615@linux.vnet.ibm.com> <52F60699.8010204@iki.fi> <20140211121426.GQ4250@linux.vnet.ibm.com> Date: Tue, 11 Feb 2014 15:20:01 +0200 X-Google-Sender-Auth: cDBYYvMInj7uKHFLtJI6vrjdwEE Message-ID: Subject: Re: Memory allocator semantics From: Pekka Enberg To: Paul McKenney Cc: Christoph Lameter , "linux-mm@kvack.org" , LKML , Matt Mackall Content-Type: text/plain; charset=ISO-8859-1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 11, 2014 at 2:14 PM, Paul E. McKenney wrote: > In contrast, from kfree() to a kmalloc() returning some of the kfree()ed > memory, I believe the kfree()/kmalloc() implementation must do any needed > synchronization and ordering. But that is a different set of examples, > for example, this one: > > CPU 0 CPU 1 > p->a = 42; q = kmalloc(...); /* returning p */ > kfree(p); q->a = 5; > BUG_ON(q->a != 5); > > Unlike the situation with (A), (B), and (C), in this case I believe > that it is kfree()'s and kmalloc()'s responsibility to ensure that > the BUG_ON() never triggers. > > Make sense? I'm not sure... It's the caller's responsibility not to touch "p" after it's handed over to kfree() - otherwise that's a "use-after-free" error. If there's some reordering going on here, I'm tempted to blame the caller for lack of locking. Pekka -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/