* [PATCH 2/3] [POWERPC] Fix kernel stack allocation alignment
@ 2008-04-18 6:56 Benjamin Herrenschmidt
2008-04-18 7:06 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Benjamin Herrenschmidt @ 2008-04-18 6:56 UTC (permalink / raw)
To: Andrew Morton, Paul Mackerras; +Cc: Linux-Arch, linuxppc-dev, linux-kernel
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),
we use kmalloc to allocate it, which doesn't provide that guarantee.
It appeared to work so far... until one enables SLUB debugging
which then returns unaligned pointers. Ooops...
This patch fixes it by using a slab cache with enforced alignment
for those. It replies on my previous patch that adds a
thread_info_cache_init() callback.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
Note that m32r seems to also have this problem.
arch/powerpc/kernel/process.c | 31 +++++++++++++++++++++++++++++++
include/asm-powerpc/thread_info.h | 8 ++------
2 files changed, 33 insertions(+), 6 deletions(-)
--- linux-work.orig/arch/powerpc/kernel/process.c 2008-04-17 14:33:26.000000000 +1000
+++ linux-work/arch/powerpc/kernel/process.c 2008-04-18 13:11:23.000000000 +1000
@@ -1038,3 +1038,34 @@ void ppc64_runlatch_off(void)
}
}
#endif
+
+#if THREAD_SHIFT < PAGE_SHIFT
+
+static struct kmem_cache *thread_info_cache;
+
+struct thread_info *alloc_thread_info(struct task_struct *tsk)
+{
+ struct thread_info *ti;
+
+ ti = kmem_cache_alloc(thread_info_cache, GFP_KERNEL);
+ if (unlikely(ti == NULL))
+ return NULL;
+#ifdef CONFIG_DEBUG_STACK_USAGE
+ memset(ti, 0, THREAD_SIZE);
+#endif
+ return ti;
+}
+
+void free_thread_info(struct thread_info *ti)
+{
+ kmem_cache_free(thread_info_cache, ti);
+}
+
+void thread_info_cache_init(void)
+{
+ thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE,
+ THREAD_SIZE, 0, NULL);
+ BUG_ON(thread_info_cache == NULL);
+}
+
+#endif /* THREAD_SHIFT < PAGE_SHIFT */
Index: linux-work/include/asm-powerpc/thread_info.h
===================================================================
--- linux-work.orig/include/asm-powerpc/thread_info.h 2007-09-28 11:42:10.000000000 +1000
+++ linux-work/include/asm-powerpc/thread_info.h 2008-04-18 13:11:44.000000000 +1000
@@ -80,12 +80,8 @@ struct thread_info {
#else /* THREAD_SHIFT < PAGE_SHIFT */
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define alloc_thread_info(tsk) kzalloc(THREAD_SIZE, GFP_KERNEL)
-#else
-#define alloc_thread_info(tsk) kmalloc(THREAD_SIZE, GFP_KERNEL)
-#endif
-#define free_thread_info(ti) kfree(ti)
+extern struct thread_info *alloc_thread_info(struct task_struct *tsk);
+extern void free_thread_info(struct thread_info *ti);
#endif /* THREAD_SHIFT < PAGE_SHIFT */
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 2/3] [POWERPC] Fix kernel stack allocation alignment
2008-04-18 6:56 [PATCH 2/3] [POWERPC] Fix kernel stack allocation alignment Benjamin Herrenschmidt
@ 2008-04-18 7:06 ` Andrew Morton
2008-04-18 8:18 ` Benjamin Herrenschmidt
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2008-04-18 7:06 UTC (permalink / raw)
To: Benjamin Herrenschmidt
Cc: Linux-Arch, linuxppc-dev, Paul Mackerras, linux-kernel
On Fri, 18 Apr 2008 16:56:17 +1000 Benjamin Herrenschmidt <benh@kernel.crashing.org> wrote:
> 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),
> we use kmalloc to allocate it, which doesn't provide that guarantee.
>
> It appeared to work so far... until one enables SLUB debugging
> which then returns unaligned pointers. Ooops...
>
> This patch fixes it by using a slab cache with enforced alignment
> for those. It replies on my previous patch that adds a
> thread_info_cache_init() callback.
>
> ...
>
> +void thread_info_cache_init(void)
> +{
> + thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE,
> + THREAD_SIZE, 0, NULL);
> + BUG_ON(thread_info_cache == NULL);
> +}
so... the "0" defeats all of SLAB_DEBUG_FREE, SLAB_RED_ZONE, SLAB_POISON
and SLAB_STORE_USER, if the comment in slab.h is to be believed.
Was that overkill?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 2/3] [POWERPC] Fix kernel stack allocation alignment
2008-04-18 7:06 ` Andrew Morton
@ 2008-04-18 8:18 ` Benjamin Herrenschmidt
0 siblings, 0 replies; 3+ messages in thread
From: Benjamin Herrenschmidt @ 2008-04-18 8:18 UTC (permalink / raw)
To: Andrew Morton; +Cc: Linux-Arch, linuxppc-dev, Paul Mackerras, linux-kernel
> so... the "0" defeats all of SLAB_DEBUG_FREE, SLAB_RED_ZONE, SLAB_POISON
> and SLAB_STORE_USER, if the comment in slab.h is to be believed.
>
> Was that overkill?
Well, I copied over from something else, looks like there's a -lot- of 0
users here...
Shouldn't there be some kind of SLAB_DEFAULT that contain those things ?
Ben.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-04-18 8:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-18 6:56 [PATCH 2/3] [POWERPC] Fix kernel stack allocation alignment Benjamin Herrenschmidt
2008-04-18 7:06 ` Andrew Morton
2008-04-18 8:18 ` Benjamin Herrenschmidt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).