mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Giridhar Pemmasani <giri@lmc.cs.sunysb.edu>
To: linux-kernel@vger.kernel.org
Subject: __vmalloc with GFP_ATOMIC causes 'sleeping from invalid context'
Date: Sun, 21 May 2006 21:36:48 -0400	[thread overview]
Message-ID: <20060522013648.6FCEAEE9EE@wolfe.lmc.cs.sunysb.edu> (raw)


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

             reply	other threads:[~2006-05-22  1:36 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-22  1:36 Giridhar Pemmasani [this message]
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
2006-10-23  6:13 Giridhar Pemmasani
2006-10-23 10:38 ` Alan Cox
2006-10-23 11:11   ` Giridhar Pemmasani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060522013648.6FCEAEE9EE@wolfe.lmc.cs.sunysb.edu \
    --to=giri@lmc.cs.sunysb.edu \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®