diff options
author | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2008-04-18 02:56:17 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2008-04-24 06:57:33 -0400 |
commit | f6a616800e68b61807d0f7bb0d5dc70665ef8046 (patch) | |
tree | 62f8224cb6a7da0bc203de1be8a7f3485f4b583b | |
parent | 8c9843e57a7d9d7a090d6467a0f1f3afb8031527 (diff) |
[POWERPC] Fix kernel stack allocation alignment
The powerpc kernel stacks need to be naturally aligned, as they
contain the thread info at the bottom, which is obtained by
clearing the low bits of the stack pointer.
However, when using 64K pages, the stack is smaller than a page,
so we use kmalloc to allocate it, but that doesn't provide the
alignment guarantee we need.
It appeared to work so far... until one enables SLUB debugging
which then returns unaligned pointers. Ooops...
This fixes it by using a slab cache with enforced alignment. It
relies on my previous patch that adds a thread_info_cache_init()
callback.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
-rw-r--r-- | arch/powerpc/kernel/process.c | 31 | ||||
-rw-r--r-- | include/asm-powerpc/thread_info.h | 8 |
2 files changed, 33 insertions, 6 deletions
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index 703100d5e458..6caad17ea72e 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c | |||
@@ -1033,3 +1033,34 @@ void ppc64_runlatch_off(void) | |||
1033 | } | 1033 | } |
1034 | } | 1034 | } |
1035 | #endif | 1035 | #endif |
1036 | |||
1037 | #if THREAD_SHIFT < PAGE_SHIFT | ||
1038 | |||
1039 | static struct kmem_cache *thread_info_cache; | ||
1040 | |||
1041 | struct thread_info *alloc_thread_info(struct task_struct *tsk) | ||
1042 | { | ||
1043 | struct thread_info *ti; | ||
1044 | |||
1045 | ti = kmem_cache_alloc(thread_info_cache, GFP_KERNEL); | ||
1046 | if (unlikely(ti == NULL)) | ||
1047 | return NULL; | ||
1048 | #ifdef CONFIG_DEBUG_STACK_USAGE | ||
1049 | memset(ti, 0, THREAD_SIZE); | ||
1050 | #endif | ||
1051 | return ti; | ||
1052 | } | ||
1053 | |||
1054 | void free_thread_info(struct thread_info *ti) | ||
1055 | { | ||
1056 | kmem_cache_free(thread_info_cache, ti); | ||
1057 | } | ||
1058 | |||
1059 | void thread_info_cache_init(void) | ||
1060 | { | ||
1061 | thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE, | ||
1062 | THREAD_SIZE, 0, NULL); | ||
1063 | BUG_ON(thread_info_cache == NULL); | ||
1064 | } | ||
1065 | |||
1066 | #endif /* THREAD_SHIFT < PAGE_SHIFT */ | ||
diff --git a/include/asm-powerpc/thread_info.h b/include/asm-powerpc/thread_info.h index 40d5f98c44fc..d030f5ce39ad 100644 --- a/include/asm-powerpc/thread_info.h +++ b/include/asm-powerpc/thread_info.h | |||
@@ -80,12 +80,8 @@ struct thread_info { | |||
80 | 80 | ||
81 | #else /* THREAD_SHIFT < PAGE_SHIFT */ | 81 | #else /* THREAD_SHIFT < PAGE_SHIFT */ |
82 | 82 | ||
83 | #ifdef CONFIG_DEBUG_STACK_USAGE | 83 | extern struct thread_info *alloc_thread_info(struct task_struct *tsk); |
84 | #define alloc_thread_info(tsk) kzalloc(THREAD_SIZE, GFP_KERNEL) | 84 | extern void free_thread_info(struct thread_info *ti); |
85 | #else | ||
86 | #define alloc_thread_info(tsk) kmalloc(THREAD_SIZE, GFP_KERNEL) | ||
87 | #endif | ||
88 | #define free_thread_info(ti) kfree(ti) | ||
89 | 85 | ||
90 | #endif /* THREAD_SHIFT < PAGE_SHIFT */ | 86 | #endif /* THREAD_SHIFT < PAGE_SHIFT */ |
91 | 87 | ||