Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932503AbWEVG4w (ORCPT ); Mon, 22 May 2006 02:56:52 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932519AbWEVG4v (ORCPT ); Mon, 22 May 2006 02:56:51 -0400 Received: from lmcgw.cs.sunysb.edu ([130.245.128.4]:46282 "EHLO smtp.lmc.cs.sunysb.edu") by vger.kernel.org with ESMTP id S932503AbWEVG4v (ORCPT ); Mon, 22 May 2006 02:56:51 -0400 Date: Mon, 22 May 2006 02:56:49 -0400 From: Giridhar Pemmasani To: Nick Piggin Cc: linux-kernel@vger.kernel.org Subject: Re: __vmalloc with GFP_ATOMIC causes 'sleeping from invalid context' In-Reply-To: <447155E5.8060406@yahoo.com.au> References: <20060522013648.6FCEAEE9EE@wolfe.lmc.cs.sunysb.edu> <447119B3.7000506@yahoo.com.au> <20060522055852.63940EE9EE@wolfe.lmc.cs.sunysb.edu> <4471551B.1070701@yahoo.com.au> <447155E5.8060406@yahoo.com.au> User-Agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (=?ISO-8859-4?Q?Shij=F2?=) APEL/10.6 MULE XEmacs/21.4 (patch 19) (Constant Variable) (i386-debian-linux) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Message-Id: <20060522065649.5C3E7EE9EE@wolfe.lmc.cs.sunysb.edu> Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4829 Lines: 131 On Mon, 22 May 2006 16:10:45 +1000, Nick Piggin said: > Nick Piggin wrote: >> Giridhar Pemmasani wrote: >> >>> On Mon, 22 May 2006 11:53:55 +1000, Nick Piggin >>> said: >>> >>> > Giridhar Pemmasani wrote: >> If __vmalloc is called in atomic >>> context with GFP_ATOMIC flags, >> __get_vm_area_node is called, >>> which calls kmalloc_node with >> GFP_KERNEL flags. This causes >>> 'sleeping function called from >> invalid context at >>> mm/slab.c:2729' with 2.6.16-rc4 kernel. A >> simple solution is >>> to use >>> >>> > I can't see what would cause this in either 2.6.16-rc4 or > >>> 2.6.17-rc4. What is the line? >>> >>> If someone calls __vmalloc in atomic context (with GFP_ATOMIC >>> flags): >> >> >> OK I misunderstood your comment. I was looking for the caller. >> Hmm, page_alloc.c does, but I don't know that it needs to be >> atomic -- what happens if we just make that allocation >> GFP_KERNEL? >> > OTOH, it doesn't seem to be particularly wrong to allow __vmalloc > GFP_ATOMIC allocations. The correct fix is to pass the gfp_mask > to kmalloc: if you're worried about breaking the API, introduce a > new __get_vm_area_node_mask() and implement __get_vm_area_node() > as a simple wrapper that passes in GFP_KERNEL. Here is an attempt at this. I also made __get_vm_area_node static. Signed-off-by: Giridhar Pemmasani diff -Naur linux.orig/include/linux/vmalloc.h linux/include/linux/vmalloc.h --- linux.orig/include/linux/vmalloc.h 2006-05-22 02:45:23.000000000 -0400 +++ linux/include/linux/vmalloc.h 2006-05-22 02:45:38.000000000 -0400 @@ -3,6 +3,7 @@ #include #include /* pgprot_t */ +#include /* bits in vm_struct->flags */ #define VM_IOREMAP 0x00000001 /* ioremap() and friends */ @@ -52,8 +53,15 @@ extern struct vm_struct *get_vm_area(unsigned long size, unsigned long flags); extern struct vm_struct *__get_vm_area(unsigned long size, unsigned long flags, unsigned long start, unsigned long end); -extern struct vm_struct *get_vm_area_node(unsigned long size, - unsigned long flags, int node); +extern struct vm_struct *get_vm_area_node_mask(unsigned long size, + unsigned long flags, int node, + gfp_t gfp_mask); +static inline struct vm_struct *get_vm_area_node(unsigned long size, + unsigned long flags, int node) +{ + return get_vm_area_node_mask(size, flags, node, GFP_KERNEL); +} + extern struct vm_struct *remove_vm_area(void *addr); extern struct vm_struct *__remove_vm_area(void *addr); extern int map_vm_area(struct vm_struct *area, pgprot_t prot, diff -Naur linux.orig/mm/vmalloc.c linux/mm/vmalloc.c --- linux.orig/mm/vmalloc.c 2006-05-19 01:22:00.000000000 -0400 +++ linux/mm/vmalloc.c 2006-05-22 02:45:49.000000000 -0400 @@ -157,8 +157,9 @@ return err; } -struct vm_struct *__get_vm_area_node(unsigned long size, unsigned long flags, - unsigned long start, unsigned long end, int node) +static struct vm_struct *__get_vm_area_node(unsigned long size, unsigned long flags, + unsigned long start, unsigned long end, + int node, gfp_t gfp_mask) { struct vm_struct **p, *tmp, *area; unsigned long align = 1; @@ -177,7 +178,7 @@ addr = ALIGN(start, align); size = PAGE_ALIGN(size); - area = kmalloc_node(sizeof(*area), GFP_KERNEL, node); + area = kmalloc_node(sizeof(*area), gfp_mask, node); if (unlikely(!area)) return NULL; @@ -233,7 +234,7 @@ struct vm_struct *__get_vm_area(unsigned long size, unsigned long flags, unsigned long start, unsigned long end) { - return __get_vm_area_node(size, flags, start, end, -1); + return __get_vm_area_node(size, flags, start, end, -1, GFP_KERNEL); } /** @@ -251,9 +252,11 @@ return __get_vm_area(size, flags, VMALLOC_START, VMALLOC_END); } -struct vm_struct *get_vm_area_node(unsigned long size, unsigned long flags, int node) +struct vm_struct *get_vm_area_node_mask(unsigned long size, unsigned long flags, + int node, gfp_t gfp_mask) { - return __get_vm_area_node(size, flags, VMALLOC_START, VMALLOC_END, node); + return __get_vm_area_node(size, flags, VMALLOC_START, VMALLOC_END, node, + gfp_mask); } /* Caller must hold vmlist_lock */ @@ -471,7 +474,7 @@ if (!size || (size >> PAGE_SHIFT) > num_physpages) return NULL; - area = get_vm_area_node(size, VM_ALLOC, node); + area = get_vm_area_node_mask(size, VM_ALLOC, node, gfp_mask); if (!area) return NULL; Thanks, Giri - 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/