Cache colouring task_struct and kernel stack iconCache colouring task_struct and kernel stack 2.5.0-0.5

Cache colouring task_struct and kernel stack is a patch created to cache-colours both task_struct and kernel stack.
Cache colouring task_struct and kernel stack is a patch created to cache-colours both task_struct and kernel stack using a slab allocator for task_struct and initial stack pointer jittering for kernel stack. An extra structure is defined for task_struct allocations as long as a new init task structure :

[include/linux/sched.h]

#define TSK_TO_KSTACK(p) (((struct full_task_struct *) (p))->stack)
#define TSK_KSTACK_TOP(p) (((struct full_task_struct *) (p))->stack_top)
#define TSK_COUNT(p) (((struct full_task_struct *) (p))->count)

struct full_task_struct {
struct task_struct task;
atomic_t count;
unsigned long stack;
unsigned long stack_top;
};

struct init_task_struct {
unsigned long stack[INIT_TASK_SIZE/sizeof(long)];
struct full_task_struct ftsk;
};


So, each pointer to a task_struct is really a full_task_struct pointer that can be used to access other fields like task stack base, task stack top and task_struct use count. The stack to task_struct iverse lookup is done by storing the pointer of the stack's owner task_struct at the base of the stack :

[arch/??/kernel/process.c]

struct task_struct *alloc_task_struct(void)
{
struct full_task_struct *f = (struct full_task_struct *) kmem_cache_alloc(tsk_cache, GFP_KERNEL);

if (!f)
return NULL;
f->stack = __get_free_pages(GFP_KERNEL, 1);
if (!f->stack) {
kmem_cache_free(tsk_cache, f);
return NULL;
}
atomic_set(&f->count, 1);
*((struct task_struct **) f->stack) = (struct task_struct *) f;
return (struct task_struct *) f;
}


The initial stack frame pointer jittering is done by :

[arch/??/kernel/process.c]

#define STACK_COLOUR_BITS 3
#define STACK_COLOUR_MASK ((1 esp = esp;

p->thread.esp = TSK_KSTACK_TOP(p) = (unsigned long) childregs;
p->thread.esp0 = (unsigned long) (childregs+1);

p->thread.eip = (unsigned long) ret_from_fork;

savesegment(fs,p->thread.fs);
savesegment(gs,p->thread.gs);

unlazy_fpu(current);
struct_cpy(&p->thread.i387, ¤t->thread.i387);

return 0;
}


By using three stack color bits eight colors will be used for initial stack frame pointer jittering that should be enough for most cache architectures. Care has to be taken in increasing too much STACK_COLOUR_BITS because this can lead to kernel stack overflows ( for example a STACK_COLOUR_BITS set to 4 with a cache line size of 128 bytes like P4 will result in a maximum jitter of 2048 bytes by leaving only 6 Kb for the kernel stack ).

last updated on:
April 8th, 2008, 11:00 GMT
price:
FREE!
developed by:
Davide Libenzi
license type:
GPL (GNU General Public License) 
category:
ROOT \ Utilities

FREE!

In a hurry? Add it to your Download Basket!

user rating 10

UNRATED
2.9/5
 

0/5

Add your review!

SUBMIT