Skip to content

Commit

Permalink
sh: Support kernel stacks smaller than a page.
Browse files Browse the repository at this point in the history
This follows the powerpc commit f6a6168
'[POWERPC] Fix kernel stack allocation alignment'.

SH has traditionally forced the thread order to be relative to the page
size, so there were never any situations where the same bug was
triggered by slub. Regardless, the usage of > 8kB stacks for the larger
page sizes is overkill, so we switch to using slab allocations there,
as per the powerpc change.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
  • Loading branch information
Paul Mundt committed Sep 20, 2008
1 parent b817f7e commit c15c5f8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
32 changes: 14 additions & 18 deletions arch/sh/include/asm/thread_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,12 @@ struct thread_info {
#define PREEMPT_ACTIVE 0x10000000

#if defined(CONFIG_4KSTACKS)
#define THREAD_SIZE_ORDER (0)
#elif defined(CONFIG_PAGE_SIZE_4KB)
#define THREAD_SIZE_ORDER (1)
#elif defined(CONFIG_PAGE_SIZE_8KB)
#define THREAD_SIZE_ORDER (1)
#elif defined(CONFIG_PAGE_SIZE_16KB)
#define THREAD_SIZE_ORDER (0)
#elif defined(CONFIG_PAGE_SIZE_64KB)
#define THREAD_SIZE_ORDER (0)
#define THREAD_SHIFT 12
#else
#error "Unknown thread size"
#define THREAD_SHIFT 13
#endif

#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
#define THREAD_SIZE (1 << THREAD_SHIFT)
#define STACK_WARN (THREAD_SIZE >> 3)

/*
Expand Down Expand Up @@ -94,15 +86,19 @@ static inline struct thread_info *current_thread_info(void)
return ti;
}

/* thread information allocation */
#if THREAD_SHIFT >= PAGE_SHIFT

#define THREAD_SIZE_ORDER (THREAD_SHIFT - PAGE_SHIFT)

#else /* THREAD_SHIFT < PAGE_SHIFT */

#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR

/* thread information allocation */
#ifdef CONFIG_DEBUG_STACK_USAGE
#define alloc_thread_info(ti) kzalloc(THREAD_SIZE, GFP_KERNEL)
#else
#define alloc_thread_info(ti) 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 */

#endif /* __ASSEMBLY__ */

Expand Down
29 changes: 29 additions & 0 deletions arch/sh/mm/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,35 @@ void free_initrd_mem(unsigned long start, unsigned long end)
}
#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 */

#ifdef CONFIG_MEMORY_HOTPLUG
int arch_add_memory(int nid, u64 start, u64 size)
{
Expand Down

0 comments on commit c15c5f8

Please sign in to comment.