Re: __vmalloc with GFP_ATOMIC causes 'sleeping from invalid context'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 22 May 2006 14:56:35 -0700, Andrew Morton <[email protected]> said:

   > It was wrong for get_vm_area_node() to have assumed that it could
   > use GFP_KERNEL.

   > Please just change the top-level API of get_vm_area_node() to
   > take a gfp_t and don't worry about the get_vm_area_node_mask()
   > thing.

   > The only callers of get_vm_area_node() are in vmalloc.c anyway.
   > We could in fact make it static, but I guess exposing it as an
   > API call makes sense.

In addition, I added BUG_ON(in_interrupt()), as suggested by Nick
Piggin earlier. The patch is against 2.6.17-rc4.

Thanks,
Giri

Signed-off-by: Giridhar Pemmasani <[email protected]>

---

diff -Naur linux-2.6.17-rc4.orig/include/linux/vmalloc.h linux-2.6.17-rc4/include/linux/vmalloc.h
--- linux-2.6.17-rc4.orig/include/linux/vmalloc.h	2006-05-22 18:48:33.000000000 -0400
+++ linux-2.6.17-rc4/include/linux/vmalloc.h	2006-05-22 18:50:40.000000000 -0400
@@ -53,7 +53,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 struct vm_struct *__remove_vm_area(void *addr);
 extern int map_vm_area(struct vm_struct *area, pgprot_t prot,
diff -Naur linux-2.6.17-rc4.orig/mm/vmalloc.c linux-2.6.17-rc4/mm/vmalloc.c
--- linux-2.6.17-rc4.orig/mm/vmalloc.c	2006-05-22 18:48:40.000000000 -0400
+++ linux-2.6.17-rc4/mm/vmalloc.c	2006-05-22 18:47:09.000000000 -0400
@@ -157,13 +157,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);
 
@@ -177,7 +179,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 +235,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 +253,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 */
@@ -471,7 +475,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;
 

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux