Commit 52fd24ca authored by Giridhar Pemmasani's avatar Giridhar Pemmasani Committed by Linus Torvalds
Browse files

[PATCH] __vmalloc with GFP_ATOMIC causes 'sleeping from invalid context'



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.

Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 6a2aae06
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -60,7 +60,8 @@ 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,
extern struct vm_struct *__get_vm_area(unsigned long size, unsigned long flags,
					unsigned long start, unsigned long end);
					unsigned long start, unsigned long end);
extern struct vm_struct *get_vm_area_node(unsigned long size,
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,
extern int map_vm_area(struct vm_struct *area, pgprot_t prot,
			struct page ***pages);
			struct page ***pages);
+11 −7
Original line number Original line Diff line number Diff line
@@ -160,13 +160,15 @@ int map_vm_area(struct vm_struct *area, pgprot_t prot, struct page ***pages)
	return err;
	return err;
}
}


struct vm_struct *__get_vm_area_node(unsigned long size, unsigned long flags,
static struct vm_struct *__get_vm_area_node(unsigned long size, unsigned long flags,
				unsigned long start, unsigned long end, int node)
					    unsigned long start, unsigned long end,
					    int node, gfp_t gfp_mask)
{
{
	struct vm_struct **p, *tmp, *area;
	struct vm_struct **p, *tmp, *area;
	unsigned long align = 1;
	unsigned long align = 1;
	unsigned long addr;
	unsigned long addr;


	BUG_ON(in_interrupt());
	if (flags & VM_IOREMAP) {
	if (flags & VM_IOREMAP) {
		int bit = fls(size);
		int bit = fls(size);


@@ -180,7 +182,7 @@ struct vm_struct *__get_vm_area_node(unsigned long size, unsigned long flags,
	addr = ALIGN(start, align);
	addr = ALIGN(start, align);
	size = PAGE_ALIGN(size);
	size = PAGE_ALIGN(size);


	area = kmalloc_node(sizeof(*area), GFP_KERNEL, node);
	area = kmalloc_node(sizeof(*area), gfp_mask, node);
	if (unlikely(!area))
	if (unlikely(!area))
		return NULL;
		return NULL;


@@ -236,7 +238,7 @@ out:
struct vm_struct *__get_vm_area(unsigned long size, unsigned long flags,
struct vm_struct *__get_vm_area(unsigned long size, unsigned long flags,
				unsigned long start, unsigned long end)
				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 @@ struct vm_struct *get_vm_area(unsigned long size, unsigned long flags)
	return __get_vm_area(size, flags, VMALLOC_START, VMALLOC_END);
	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 */
/* Caller must hold vmlist_lock */
@@ -487,7 +491,7 @@ static void *__vmalloc_node(unsigned long size, gfp_t gfp_mask, pgprot_t prot,
	if (!size || (size >> PAGE_SHIFT) > num_physpages)
	if (!size || (size >> PAGE_SHIFT) > num_physpages)
		return NULL;
		return NULL;


	area = get_vm_area_node(size, VM_ALLOC, node);
	area = get_vm_area_node(size, VM_ALLOC, node, gfp_mask);
	if (!area)
	if (!area)
		return NULL;
		return NULL;