[glsdk/meta-ti-glsdk.git] / recipes-kernel / linux / linux-ti33x-psp-3.2 / 3.2.19 / 0032-Fix-blocking-allocations-called-very-early-during-bo.patch
1 From 193433aeaf9380a822cd4bf7f5777e70b2e86550 Mon Sep 17 00:00:00 2001
2 From: Linus Torvalds <torvalds@linux-foundation.org>
3 Date: Mon, 21 May 2012 12:52:42 -0700
4 Subject: [PATCH 032/117] Fix blocking allocations called very early during
5 bootup
7 commit 31a67102f4762df5544bc2dfb34a931233d2a5b2 upstream.
9 During early boot, when the scheduler hasn't really been fully set up,
10 we really can't do blocking allocations because with certain (dubious)
11 configurations the "might_resched()" calls can actually result in
12 scheduling events.
14 We could just make such users always use GFP_ATOMIC, but quite often the
15 code that does the allocation isn't really aware of the fact that the
16 scheduler isn't up yet, and forcing that kind of random knowledge on the
17 initialization code is just annoying and not good for anybody.
19 And we actually have a the 'gfp_allowed_mask' exactly for this reason:
20 it's just that the kernel init sequence happens to set it to allow
21 blocking allocations much too early.
23 So move the 'gfp_allowed_mask' initialization from 'start_kernel()'
24 (which is some of the earliest init code, and runs with preemption
25 disabled for good reasons) into 'kernel_init()'. kernel_init() is run
26 in the newly created thread that will become the 'init' process, as
27 opposed to the early startup code that runs within the context of what
28 will be the first idle thread.
30 So by the time we reach 'kernel_init()', we know that the scheduler must
31 be at least limping along, because we've already scheduled from the idle
32 thread into the init thread.
34 Reported-by: Steven Rostedt <rostedt@goodmis.org>
35 Cc: David Rientjes <rientjes@google.com>
36 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
37 Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
38 ---
39 init/main.c | 7 ++++---
40 1 file changed, 4 insertions(+), 3 deletions(-)
42 diff --git a/init/main.c b/init/main.c
43 index 217ed23..cb08fea2 100644
44 --- a/init/main.c
45 +++ b/init/main.c
46 @@ -563,9 +563,6 @@ asmlinkage void __init start_kernel(void)
47 early_boot_irqs_disabled = false;
48 local_irq_enable();
50 - /* Interrupts are enabled now so all GFP allocations are safe. */
51 - gfp_allowed_mask = __GFP_BITS_MASK;
52 -
53 kmem_cache_init_late();
55 /*
56 @@ -798,6 +795,10 @@ static int __init kernel_init(void * unused)
57 * Wait until kthreadd is all set-up.
58 */
59 wait_for_completion(&kthreadd_done);
60 +
61 + /* Now the scheduler is fully set up and can do blocking allocations */
62 + gfp_allowed_mask = __GFP_BITS_MASK;
63 +
64 /*
65 * init can allocate pages on any node
66 */
67 --
68 1.7.9.5