public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* __vmalloc with GFP_ATOMIC causes 'sleeping from invalid context'
@ 2006-05-22  1:36 Giridhar Pemmasani
  2006-05-22  1:51 ` Arjan van de Ven
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Giridhar Pemmasani @ 2006-05-22  1:36 UTC (permalink / raw)
  To: linux-kernel


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
proper flags in __get_vm_area_node, depending on the context:

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-19 01:53:05.000000000 -0400
@@ -177,7 +177,10 @@
 	addr = ALIGN(start, align);
 	size = PAGE_ALIGN(size);
 
-	area = kmalloc_node(sizeof(*area), GFP_KERNEL, node);
+	if (in_atomic() || in_interrupt())
+		area = kmalloc_node(sizeof(*area), GFP_ATOMIC, node);
+	else
+		area = kmalloc_node(sizeof(*area), GFP_KERNEL, node);
 	if (unlikely(!area))
 		return NULL;
 

An alternate solution is to pass flags to __get_vm_area_node what was
passed to __vmalloc so it can call kmalloc_node with either GFP_KERNEL
or GFP_ATOMIC, but that changes signature of get_vm_area_node and
__get_vm_area_node which may affect other parts of kernel / modules.

Another point: In include/linux/kernel.h, might_resched() is defined
as

#ifdef CONFIG_PREEMPT_VOLUNTARY
extern int cond_resched(void);
# define might_resched() cond_resched()
#else
# define might_resched() do { } while (0)
#endif

Why is cond_resched() used only if CONFIG_PREEMPT_VOLUNTARY and not if
CONFIG_PREEMPT is enabled? i.e., shouldn't it be defined as

#if defined(CONFIG_PREEMPT_VOLUNTARY) || defined(CONFIG_PREEMPT)
extern int cond_resched(void);
# define might_resched() cond_resched()
#else
# define might_resched() do { } while (0)
#endif

Thanks,
Giri

^ permalink raw reply	[flat|nested] 20+ messages in thread
* __vmalloc with GFP_ATOMIC causes 'sleeping from invalid context'
@ 2006-10-23  6:13 Giridhar Pemmasani
  2006-10-23 10:38 ` Alan Cox
  0 siblings, 1 reply; 20+ messages in thread
From: Giridhar Pemmasani @ 2006-10-23  6:13 UTC (permalink / raw)
  To: linux-kernel; +Cc: pgiri


This is follow up of earlier patch:

http://marc.theaimsgroup.com/?l=linux-kernel&m=114833505625992&w=2

Apparently the patch has not been merged (yet), so resending it. The
patch is against 2.6.19-rc2.

Synopsis of patch: If __vmalloc is called to allocate memory with
GFP_ATOMIC in atomic context, the chain of calls results in
__get_vm_area_node allocating memory for vm_struct with GFP_KERNEL,
causing the 'sleeping from invalid context' warning. This patch fixes
it by passing the gfp flags along so __get_vm_area_node allocates
memory for vm_struct with the same flags.

Thanks,
Giri

diff -Naur linux-2.6.19-rc2.orig/include/linux/vmalloc.h linux-2.6.19-rc2/include/linux/vmalloc.h
--- linux-2.6.19-rc2.orig/include/linux/vmalloc.h	2006-10-23 01:43:35.000000000 -0400
+++ linux-2.6.19-rc2/include/linux/vmalloc.h	2006-10-23 01:45:24.000000000 -0400
@@ -60,7 +60,8 @@
 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);
+					  unsigned long flags, int node,
+					  gfp_t gfp_mask);
 extern struct vm_struct *remove_vm_area(void *addr);
 extern int map_vm_area(struct vm_struct *area, pgprot_t prot,
 			struct page ***pages);
diff -Naur linux-2.6.19-rc2.orig/mm/vmalloc.c linux-2.6.19-rc2/mm/vmalloc.c
--- linux-2.6.19-rc2.orig/mm/vmalloc.c	2006-10-23 01:43:55.000000000 -0400
+++ linux-2.6.19-rc2/mm/vmalloc.c	2006-10-23 01:45:24.000000000 -0400
@@ -160,13 +160,15 @@
 	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;
 	unsigned long addr;
 
+	BUG_ON(in_interrupt());
 	if (flags & VM_IOREMAP) {
 		int bit = fls(size);
 
@@ -180,7 +182,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;
 
@@ -236,7 +238,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);
 }
 
 /**
@@ -253,9 +255,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(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 */
@@ -484,7 +488,7 @@
 	if (!size || (size >> PAGE_SHIFT) > num_physpages)
 		return NULL;
 
-	area = get_vm_area_node(size, VM_ALLOC, node);
+	area = get_vm_area_node(size, VM_ALLOC, node, gfp_mask);
 	if (!area)
 		return NULL;
 

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2006-10-23 11:11 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-22  1:36 __vmalloc with GFP_ATOMIC causes 'sleeping from invalid context' Giridhar Pemmasani
2006-05-22  1:51 ` Arjan van de Ven
2006-05-22  6:01   ` Giridhar Pemmasani
2006-05-22  1:53 ` Nick Piggin
2006-05-22  5:58   ` Giridhar Pemmasani
2006-05-22  6:07     ` Nick Piggin
2006-05-22  6:10       ` Nick Piggin
2006-05-22  6:14         ` Nick Piggin
2006-05-22  7:08           ` Giridhar Pemmasani
2006-05-22  7:34             ` Nick Piggin
2006-05-22 14:55               ` Giridhar Pemmasani
2006-05-22  6:56         ` Giridhar Pemmasani
2006-05-22 21:56           ` Andrew Morton
2006-05-22 22:59             ` Giridhar Pemmasani
2006-05-22 11:18   ` Andi Kleen
2006-05-22 15:12     ` Giridhar Pemmasani
2006-05-22 11:47 ` Alan Cox
  -- strict thread matches above, loose matches on Subject: below --
2006-10-23  6:13 Giridhar Pemmasani
2006-10-23 10:38 ` Alan Cox
2006-10-23 11:11   ` Giridhar Pemmasani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox