diff --git a/arch/x86/kernel/include/arch-futex.h b/arch/x86/kernel/include/arch-futex.h new file mode 100644 index 00000000..decbc3d0 --- /dev/null +++ b/arch/x86/kernel/include/arch-futex.h @@ -0,0 +1,67 @@ +/** + * \file futex.h + * Licence details are found in the file LICENSE. + * + * \brief + * Futex adaptation to McKernel + * + * \author Balazs Gerofi \par + * Copyright (C) 2012 RIKEN AICS + * + * + * HISTORY: + * + */ +#ifndef _ARCH_FUTEX_H +#define _ARCH_FUTEX_H +#include + +#define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \ + asm volatile("1:\t" insn "\n" \ + "2:\t.section .fixup,\"ax\"\n" \ + "3:\tmov\t%3, %1\n" \ + "\tjmp\t2b\n" \ + "\t.previous\n" \ + _ASM_EXTABLE(1b, 3b) \ + : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \ + : "i" (-EFAULT), "0" (oparg), "1" (0)) + +#define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \ + asm volatile("1:\tmovl %2, %0\n" \ + "\tmovl\t%0, %3\n" \ + "\t" insn "\n" \ + "2:\tlock; cmpxchgl %3, %2\n" \ + "\tjnz\t1b\n" \ + "3:\t.section .fixup,\"ax\"\n" \ + "4:\tmov\t%5, %1\n" \ + "\tjmp\t3b\n" \ + "\t.previous\n" \ + _ASM_EXTABLE(1b, 4b) \ + _ASM_EXTABLE(2b, 4b) \ + : "=&a" (oldval), "=&r" (ret), \ + "+m" (*uaddr), "=&r" (tem) \ + : "r" (oparg), "i" (-EFAULT), "1" (0)) + +static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, + int newval) +{ +#ifdef __UACCESS__ + if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int))) + return -EFAULT; +#endif + + asm volatile("1:\tlock; cmpxchgl %3, %1\n" + "2:\t.section .fixup, \"ax\"\n" + "3:\tmov %2, %0\n" + "\tjmp 2b\n" + "\t.previous\n" + _ASM_EXTABLE(1b, 3b) + : "=a" (oldval), "+m" (*uaddr) + : "i" (-EFAULT), "r" (newval), "0" (oldval) + : "memory" + ); + + return oldval; +} + +#endif diff --git a/arch/x86/kernel/include/arch-memory.h b/arch/x86/kernel/include/arch-memory.h index 29ba527f..31bc9c96 100644 --- a/arch/x86/kernel/include/arch-memory.h +++ b/arch/x86/kernel/include/arch-memory.h @@ -40,10 +40,12 @@ #define LARGE_PAGE_P2ALIGN (LARGE_PAGE_SHIFT - PAGE_SHIFT) #define USER_END 0x0000800000000000UL +#define TASK_UNMAPPED_BASE 0x00002AAAAAA00000UL #define MAP_ST_START 0xffff800000000000UL #define MAP_VMAP_START 0xfffff00000000000UL #define MAP_FIXED_START 0xffffffff70000000UL #define MAP_KERNEL_START 0xffffffff80000000UL +#define STACK_TOP(region) ((region)->user_end) #define MAP_VMAP_SIZE 0x0000000100000000UL diff --git a/arch/x86/kernel/include/arch/cpu.h b/arch/x86/kernel/include/arch/cpu.h index efe16d8e..90e998ba 100644 --- a/arch/x86/kernel/include/arch/cpu.h +++ b/arch/x86/kernel/include/arch/cpu.h @@ -25,4 +25,13 @@ static inline void wmb(void) barrier(); } +static unsigned long read_tsc(void) +{ + unsigned int low, high; + + asm volatile("rdtsc" : "=a"(low), "=d"(high)); + + return (low | ((unsigned long)high << 32)); +} + #endif /* ARCH_CPU_H */ diff --git a/executer/kernel/mcctrl/Makefile.in b/executer/kernel/mcctrl/Makefile.in index 8b0c293b..2cbb4751 100644 --- a/executer/kernel/mcctrl/Makefile.in +++ b/executer/kernel/mcctrl/Makefile.in @@ -7,7 +7,7 @@ IHK_BASE=$(src)/../../../../ihk obj-m += mcctrl.o -ccflags-y := -I$(IHK_BASE)/linux/include -I$(IHK_BASE)/ikc/include -I$(IHK_BASE)/include -I$(src)/../../include -mcmodel=kernel -mno-red-zone -DMCEXEC_PATH=\"$(BINDIR)/mcexec\" -I@abs_builddir@ +ccflags-y := -I$(IHK_BASE)/linux/include -I$(IHK_BASE)/linux/include/ihk/arch/$(ARCH) -I$(IHK_BASE)/ikc/include -I$(IHK_BASE)/ikc/include/ikc/arch/$(ARCH) -I$(IHK_BASE)/include -I$(IHK_BASE)/include/arch/$(ARCH) -I$(src)/../../include -mcmodel=kernel -mno-red-zone -DMCEXEC_PATH=\"$(BINDIR)/mcexec\" -I@abs_builddir@ mcctrl-y := driver.o control.o ikc.o syscall.o procfs.o binfmt_mcexec.o mcctrl-y += sysfs.o sysfs_files.o diff --git a/executer/kernel/mcctrl/control.c b/executer/kernel/mcctrl/control.c index fddc84e0..820f4af9 100644 --- a/executer/kernel/mcctrl/control.c +++ b/executer/kernel/mcctrl/control.c @@ -34,7 +34,6 @@ #include #include #include -#include #include #include "config.h" #include "mcctrl.h" @@ -551,12 +550,12 @@ printk("mcexec_wait_syscall:stray wakeup\n"); #else while (1) { c = usrdata->channels + swd.cpu; - rdtscll(s); + ihk_get_tsc(s); if (!usrdata->remaining_job) { while (!(*c->param.doorbell_va)) { mb(); cpu_relax(); - rdtscll(w); + ihk_get_tsc(w); if (w > s + 1024UL * 1024 * 1024 * 10) { return -EINTR; } diff --git a/executer/kernel/mcctrl/mcctrl.h b/executer/kernel/mcctrl/mcctrl.h index 0354065e..8970dfdc 100644 --- a/executer/kernel/mcctrl/mcctrl.h +++ b/executer/kernel/mcctrl/mcctrl.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include "sysfs.h" diff --git a/kernel/host.c b/kernel/host.c index 0f7dca4d..c84cbeae 100644 --- a/kernel/host.c +++ b/kernel/host.c @@ -398,16 +398,19 @@ static int process_msg_prepare_process(unsigned long rphys) vm->region.user_start = pn->user_start; vm->region.user_end = pn->user_end; - /* TODO: review this code if(vm->region.user_end > USER_END) vm->region.user_end = USER_END; - vm->region.map_start = - (vm->region.user_start + - (vm->region.user_end - vm->region.user_start) / 3) & - LARGE_PAGE_MASK; - */ - vm->region.map_start = (USER_END / 3) & LARGE_PAGE_MASK; - vm->region.map_end = proc->vm->region.map_start; + if(vm->region.user_start != 0UL || + vm->region.user_end < TASK_UNMAPPED_BASE){ + vm->region.map_start = + (vm->region.user_start + + (vm->region.user_end - vm->region.user_start) / 3) & + LARGE_PAGE_MASK; + } + else{ + vm->region.map_start = TASK_UNMAPPED_BASE; + } + vm->region.map_end = vm->region.map_start; memcpy(proc->rlimit, pn->rlimit, sizeof(struct rlimit) * MCK_RLIM_MAX); /* TODO: Clear it at the proper timing */ diff --git a/kernel/include/futex.h b/kernel/include/futex.h index 1fcab9e0..a0239b79 100644 --- a/kernel/include/futex.h +++ b/kernel/include/futex.h @@ -99,6 +99,8 @@ #ifdef __KERNEL__ +#define __user + /* We don't deal with uaccess at the moment, because x86 can access * userspace directly, we rely on glibc and the app developers. */ @@ -106,42 +108,14 @@ #include #endif -#include #include - -#define __user +#include #if 0 #include #include #endif -#define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \ - asm volatile("1:\t" insn "\n" \ - "2:\t.section .fixup,\"ax\"\n" \ - "3:\tmov\t%3, %1\n" \ - "\tjmp\t2b\n" \ - "\t.previous\n" \ - _ASM_EXTABLE(1b, 3b) \ - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \ - : "i" (-EFAULT), "0" (oparg), "1" (0)) - -#define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \ - asm volatile("1:\tmovl %2, %0\n" \ - "\tmovl\t%0, %3\n" \ - "\t" insn "\n" \ - "2:\tlock; cmpxchgl %3, %2\n" \ - "\tjnz\t1b\n" \ - "3:\t.section .fixup,\"ax\"\n" \ - "4:\tmov\t%5, %1\n" \ - "\tjmp\t3b\n" \ - "\t.previous\n" \ - _ASM_EXTABLE(1b, 4b) \ - _ASM_EXTABLE(2b, 4b) \ - : "=&a" (oldval), "=&r" (ret), \ - "+m" (*uaddr), "=&r" (tem) \ - : "r" (oparg), "i" (-EFAULT), "1" (0)) - static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr) { int op = (encoded_op >> 28) & 7; @@ -206,28 +180,6 @@ static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr) return ret; } -static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, - int newval) -{ -#ifdef __UACCESS__ - if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int))) - return -EFAULT; -#endif - - asm volatile("1:\tlock; cmpxchgl %3, %1\n" - "2:\t.section .fixup, \"ax\"\n" - "3:\tmov %2, %0\n" - "\tjmp 2b\n" - "\t.previous\n" - _ASM_EXTABLE(1b, 3b) - : "=a" (oldval), "+m" (*uaddr) - : "i" (-EFAULT), "r" (newval), "0" (oldval) - : "memory" - ); - - return oldval; -} - #endif // __KERNEL__ #endif // _ASM_X86_FUTEX_H diff --git a/kernel/listeners.c b/kernel/listeners.c index 5d964e13..50be56e8 100644 --- a/kernel/listeners.c +++ b/kernel/listeners.c @@ -17,6 +17,7 @@ #include #include #include +#include //#define DEBUG_LISTENERS @@ -28,16 +29,6 @@ #define ekprintf(...) kprintf(__VA_ARGS__) #endif -static unsigned long read_tsc(void) -{ - unsigned int low, high; - - asm volatile("rdtsc" : "=a"(low), "=d"(high)); - - return (low | ((unsigned long)high << 32)); -} - - void testmem(void *v, unsigned long size) { unsigned long i, st, ed, s = 0; diff --git a/kernel/process.c b/kernel/process.c index 32d74a86..2fb3166e 100644 --- a/kernel/process.c +++ b/kernel/process.c @@ -1701,7 +1701,7 @@ int init_process_stack(struct thread *thread, struct program_load_desc *pn, int s_ind = 0; int arg_ind; unsigned long size; - unsigned long end = thread->vm->region.user_end; + unsigned long end; unsigned long start; int rc; unsigned long vrflag; @@ -1713,6 +1713,7 @@ int init_process_stack(struct thread *thread, struct program_load_desc *pn, struct process *proc = thread->proc; /* create stack range */ + end = STACK_TOP(&thread->vm->region); minsz = PAGE_SIZE; size = proc->rlimit[MCK_RLIMIT_STACK].rlim_cur & PAGE_MASK; if (size > (USER_END / 2)) {