From patchwork Mon Aug 9 18:38:46 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Fontenot X-Patchwork-Id: 61301 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from bilbo.ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 18E48B774F for ; Tue, 10 Aug 2010 04:39:53 +1000 (EST) Received: by ozlabs.org (Postfix) id 2483FB75FA; Tue, 10 Aug 2010 04:38:53 +1000 (EST) Delivered-To: linuxppc-dev@ozlabs.org Received: from e9.ny.us.ibm.com (e9.ny.us.ibm.com [32.97.182.139]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "e9.ny.us.ibm.com", Issuer "Equifax" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id A10C9B75C0 for ; Tue, 10 Aug 2010 04:38:52 +1000 (EST) Received: from d01relay05.pok.ibm.com (d01relay05.pok.ibm.com [9.56.227.237]) by e9.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id o79ILZFM017186 for ; Mon, 9 Aug 2010 14:21:35 -0400 Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay05.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o79IcnEq137330 for ; Mon, 9 Aug 2010 14:38:49 -0400 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o79IcmaN020411 for ; Mon, 9 Aug 2010 14:38:49 -0400 Received: from [9.76.215.50] (sig-9-76-215-50.mts.ibm.com [9.76.215.50]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o79IckjP020296; Mon, 9 Aug 2010 14:38:47 -0400 Message-ID: <4C604B36.4070603@austin.ibm.com> Date: Mon, 09 Aug 2010 13:38:46 -0500 From: Nathan Fontenot User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6 MIME-Version: 1.0 To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@ozlabs.org Subject: [PATCH 4/8] v5 Add mutex for add/remove of memory blocks References: <4C60407C.2080608@austin.ibm.com> In-Reply-To: <4C60407C.2080608@austin.ibm.com> Cc: Greg KH , KAMEZAWA Hiroyuki , Dave Hansen X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Add a new mutex for use in adding and removing of memory blocks. This is needed to avoid any race conditions in which the same memory block could be added and removed at the same time. Signed-off-by: Nathan Fontenot --- drivers/base/memory.c | 7 +++++++ 1 file changed, 7 insertions(+) Index: linux-2.6/drivers/base/memory.c =================================================================== --- linux-2.6.orig/drivers/base/memory.c 2010-08-09 07:49:04.000000000 -0500 +++ linux-2.6/drivers/base/memory.c 2010-08-09 07:50:20.000000000 -0500 @@ -27,6 +27,8 @@ #include #include +static DEFINE_MUTEX(mem_sysfs_mutex); + #define MEMORY_CLASS_NAME "memory" static struct sysdev_class memory_sysdev_class = { @@ -485,6 +487,8 @@ static int add_memory_block(int nid, str if (!mem) return -ENOMEM; + mutex_lock(&mem_sysfs_mutex); + mem->start_phys_index = __section_nr(section); mem->state = state; atomic_inc(&mem->section_count); @@ -508,6 +512,7 @@ static int add_memory_block(int nid, str ret = register_mem_sect_under_node(mem, nid); } + mutex_unlock(&mem_sysfs_mutex); return ret; } @@ -516,6 +521,7 @@ int remove_memory_block(unsigned long no { struct memory_block *mem; + mutex_lock(&mem_sysfs_mutex); mem = find_memory_block(section); if (atomic_dec_and_test(&mem->section_count)) { @@ -528,6 +534,7 @@ int remove_memory_block(unsigned long no unregister_memory(mem, section); } + mutex_unlock(&mem_sysfs_mutex); return 0; }