Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755153Ab0GZTKh (ORCPT ); Mon, 26 Jul 2010 15:10:37 -0400 Received: from e3.ny.us.ibm.com ([32.97.182.143]:43191 "EHLO e3.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755133Ab0GZTKf (ORCPT ); Mon, 26 Jul 2010 15:10:35 -0400 Message-ID: <4C4DDDA7.2000302@austin.ibm.com> Date: Mon, 26 Jul 2010 14:10:31 -0500 From: Nathan Fontenot User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.10) Gecko/20100527 Thunderbird/3.0.5 MIME-Version: 1.0 To: Dave Hansen CC: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@ozlabs.org, KAMEZAWA Hiroyuki , greg@kroah.com Subject: Re: [PATCH 4/8] v3 Allow memory_block to span multiple memory sections References: <4C451BF5.50304@austin.ibm.com> <4C451E1C.8070907@austin.ibm.com> <1279653481.9785.4.camel@nimitz> In-Reply-To: <1279653481.9785.4.camel@nimitz> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2342 Lines: 67 On 07/20/2010 02:18 PM, Dave Hansen wrote: > On Mon, 2010-07-19 at 22:55 -0500, Nathan Fontenot wrote: >> +static int add_memory_section(int nid, struct mem_section *section, >> + unsigned long state, enum mem_add_context context) >> +{ >> + struct memory_block *mem; >> + int ret = 0; >> + >> + mem = find_memory_block(section); >> + if (mem) { >> + atomic_inc(&mem->section_count); >> + kobject_put(&mem->sysdev.kobj); >> + } else >> + ret = init_memory_block(&mem, section, state); >> + >> if (!ret) { >> - if (context == HOTPLUG) >> + if (context == HOTPLUG && >> + atomic_read(&mem->section_count) == sections_per_block) >> ret = register_mem_sect_under_node(mem, nid); >> } > > I think the atomic_inc() can race with the atomic_dec_and_test() in > remove_memory_block(). > > Thread 1 does: > > mem = find_memory_block(section); > > Thread 2 does > > atomic_dec_and_test(&mem->section_count); > > and destroys the memory block, Thread 1 runs again: > > if (mem) { > atomic_inc(&mem->section_count); > kobject_put(&mem->sysdev.kobj); > } else > > but now mem got destroyed by Thread 2. You probably need to change > find_memory_block() to itself take a reference, and to use > atomic_inc_unless(). > I'm not sure I like that for a couple of reasons. I think there may still be a path through the find_memory_block() code that this race condition can occur. We could take a time sslice after the kobject_get and before getting the memory_block pointer. The second reason is that the node sysfs code calls find_memory_block() and it may be a bit kludgy to have callers of find_memory_block have to reduce the section_count after using it. With the way the memory_block structs are kept, retrieved via a kobject_get() call instead maintained on a local list, there may not be a solution that is foolproof without changing this. -Nathan > -- Dave > -- 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/