Merge branch 'master' of postpeta.pccluster.org:mckernel into gdb

This commit is contained in:
Naoki Hamada
2014-07-31 10:31:45 +09:00
8 changed files with 135 additions and 28 deletions

View File

@@ -160,10 +160,6 @@ do_signal(unsigned long rc, void *regs0, struct process *proc, struct sig_pendin
for(w = pending->sigmask.__val[0], sig = 0; w; sig++, w >>= 1); for(w = pending->sigmask.__val[0], sig = 0; w; sig++, w >>= 1);
if(sig == SIGKILL || sig == SIGTERM)
terminate(0, sig, (ihk_mc_user_context_t *)regs->rsp);
irqstate = ihk_mc_spinlock_lock(&proc->sighandler->lock);
if(regs == NULL){ /* call from syscall */ if(regs == NULL){ /* call from syscall */
asm("movq %%gs:132, %0" : "=r" (regs)); asm("movq %%gs:132, %0" : "=r" (regs));
--regs; --regs;
@@ -171,6 +167,11 @@ do_signal(unsigned long rc, void *regs0, struct process *proc, struct sig_pendin
else{ else{
rc = regs->rax; rc = regs->rax;
} }
if(sig == SIGKILL || sig == SIGTERM)
terminate(0, sig, (ihk_mc_user_context_t *)regs->rsp);
irqstate = ihk_mc_spinlock_lock(&proc->sighandler->lock);
k = proc->sighandler->action + sig - 1; k = proc->sighandler->action + sig - 1;
if(k->sa.sa_handler == (void *)1){ if(k->sa.sa_handler == (void *)1){

View File

@@ -330,12 +330,13 @@ retry_alloc:
} }
wqhln->pid = pid; wqhln->pid = pid;
wqhln->req = 0;
init_waitqueue_head(&wqhln->wq_syscall); init_waitqueue_head(&wqhln->wq_syscall);
list_add_tail(&wqhln->list, &c->wq_list); list_add_tail(&wqhln->list, &c->wq_list);
} }
ihk_ikc_spinlock_unlock(&c->wq_list_lock, flags); ihk_ikc_spinlock_unlock(&c->wq_list_lock, flags);
c->req = 1; wqhln->req = 1;
wake_up(&wqhln->wq_syscall); wake_up(&wqhln->wq_syscall);
return 0; return 0;
@@ -388,6 +389,7 @@ retry_alloc:
} }
wqhln->pid = swd.pid; wqhln->pid = swd.pid;
wqhln->req = 0;
init_waitqueue_head(&wqhln->wq_syscall); init_waitqueue_head(&wqhln->wq_syscall);
irqflags = ihk_ikc_spinlock_lock(&c->wq_list_lock); irqflags = ihk_ikc_spinlock_lock(&c->wq_list_lock);
@@ -403,7 +405,11 @@ retry_alloc:
list_add_tail(&wqhln->list, &c->wq_list); list_add_tail(&wqhln->list, &c->wq_list);
ihk_ikc_spinlock_unlock(&c->wq_list_lock, irqflags); ihk_ikc_spinlock_unlock(&c->wq_list_lock, irqflags);
ret = wait_event_interruptible(wqhln->wq_syscall, c->req); ret = wait_event_interruptible(wqhln->wq_syscall, wqhln->req);
if (ret) {
return -EINTR;
}
/* Remove per-process wait queue head */ /* Remove per-process wait queue head */
irqflags = ihk_ikc_spinlock_lock(&c->wq_list_lock); irqflags = ihk_ikc_spinlock_lock(&c->wq_list_lock);
@@ -423,11 +429,6 @@ retry_alloc:
return -EINTR; return -EINTR;
} }
if (ret) {
return -EINTR;
}
c->req = 0;
#if 1 #if 1
mb(); mb();
if (!c->param.request_va->valid) { if (!c->param.request_va->valid) {

View File

@@ -100,6 +100,7 @@ struct wait_queue_head_list_node {
struct list_head list; struct list_head list;
wait_queue_head_t wq_syscall; wait_queue_head_t wq_syscall;
int pid; int pid;
int req;
}; };
struct mcctrl_channel { struct mcctrl_channel {
@@ -108,7 +109,6 @@ struct mcctrl_channel {
struct ikc_scd_init_param init; struct ikc_scd_init_param init;
void *dma_buf; void *dma_buf;
int req;
struct list_head wq_list; struct list_head wq_list;
ihk_spinlock_t wq_list_lock; ihk_spinlock_t wq_list_lock;
}; };

View File

@@ -255,6 +255,7 @@ retry_alloc:
/* Prepare per-process wait queue head */ /* Prepare per-process wait queue head */
wqhln->pid = current->tgid; wqhln->pid = current->tgid;
wqhln->req = 0;
init_waitqueue_head(&wqhln->wq_syscall); init_waitqueue_head(&wqhln->wq_syscall);
irqflags = ihk_ikc_spinlock_lock(&channel->wq_list_lock); irqflags = ihk_ikc_spinlock_lock(&channel->wq_list_lock);
@@ -271,7 +272,7 @@ retry_alloc:
ihk_ikc_spinlock_unlock(&channel->wq_list_lock, irqflags); ihk_ikc_spinlock_unlock(&channel->wq_list_lock, irqflags);
/* wait for response */ /* wait for response */
error = wait_event_interruptible(wqhln->wq_syscall, channel->req); error = wait_event_interruptible(wqhln->wq_syscall, wqhln->req);
/* Remove per-process wait queue head */ /* Remove per-process wait queue head */
irqflags = ihk_ikc_spinlock_lock(&channel->wq_list_lock); irqflags = ihk_ikc_spinlock_lock(&channel->wq_list_lock);
@@ -283,7 +284,6 @@ retry_alloc:
printk("remote_page_fault:interrupted. %d\n", error); printk("remote_page_fault:interrupted. %d\n", error);
goto out; goto out;
} }
channel->req = 0;
if (!req->valid) { if (!req->valid) {
printk("remote_page_fault:not valid\n"); printk("remote_page_fault:not valid\n");
} }

View File

@@ -116,6 +116,7 @@ int main_loop(int fd, int cpu, pthread_mutex_t *lock);
static int fd; static int fd;
static char *altroot; static char *altroot;
static const char rlimit_stack_envname[] = "MCKERNEL_RLIMIT_STACK"; static const char rlimit_stack_envname[] = "MCKERNEL_RLIMIT_STACK";
static int ischild;
pid_t gettid(void) pid_t gettid(void)
{ {
@@ -341,6 +342,12 @@ int load_elf_desc(char *filename, struct program_load_desc **desc_p)
FILE *interp = NULL; FILE *interp = NULL;
char *interp_path; char *interp_path;
struct program_load_desc *desc; struct program_load_desc *desc;
int ret = 0;
if ((ret = access(filename, X_OK)) != 0) {
fprintf(stderr, "Error: %s is not an executable?\n", filename);
return ret;
}
fp = fopen(filename, "rb"); fp = fopen(filename, "rb");
if (!fp) { if (!fp) {
@@ -1106,8 +1113,10 @@ int main_loop(int fd, int cpu, pthread_mutex_t *lock)
sig = w.sr.args[0] & 0x7f; sig = w.sr.args[0] & 0x7f;
term = (w.sr.args[0] & 0xff00) >> 8; term = (w.sr.args[0] & 0xff00) >> 8;
if(isatty(2)){ if(isatty(2)){
if(sig) if(sig){
fprintf(stderr, "Terminate by signal %d\n", sig); if(!ischild)
fprintf(stderr, "Terminate by signal %d\n", sig);
}
else if(term) else if(term)
__dprintf("Exit status: %d\n", term); __dprintf("Exit status: %d\n", term);
} }
@@ -1163,6 +1172,7 @@ int main_loop(int fd, int cpu, pthread_mutex_t *lock)
case 0: { case 0: {
int i; int i;
ischild = 1;
/* Reopen device fd */ /* Reopen device fd */
close(fd); close(fd);
fd = open(dev, O_RDWR); fd = open(dev, O_RDWR);
@@ -1214,21 +1224,84 @@ int main_loop(int fd, int cpu, pthread_mutex_t *lock)
/* Execve phase */ /* Execve phase */
switch (w.sr.args[0]) { switch (w.sr.args[0]) {
int ret = -1;
struct program_load_desc *desc; struct program_load_desc *desc;
struct remote_transfer trans; struct remote_transfer trans;
int error;
int found;
char path[2048];
char *filename;
int ret;
/* Load descriptor phase */ /* Load descriptor phase */
case 1: case 1:
if (load_elf_desc((char *)w.sr.args[1], &desc) != 0) {
ret = -1;
found = 0;
filename = (char *)w.sr.args[1];
/* Is filename a single component without path? */
if (strncmp(filename, "/", 1)
&& !strchr(filename, '/')) {
char *token, *string, *tofree;
char *PATH = getenv("COKERNEL_PATH");
if (!PATH) {
PATH = getenv("PATH");
}
__dprintf("PATH: %s\n", PATH);
/* strsep() modifies string! */
tofree = string = strdup(PATH);
if (string == NULL) {
printf("error: copying PATH, not enough memory?\n");
goto return_execve1;
}
while ((token = strsep(&string, ":")) != NULL) {
error = snprintf(path, sizeof(path),
"%s/%s", token, filename);
if (error < 0 || error >= sizeof(path)) {
fprintf(stderr, "execve(): array too small?\n");
continue;
}
error = access(path, X_OK);
if (error == 0) {
found = 1;
break;
}
}
free(tofree);
}
else {
error = snprintf(path, sizeof(path), "%s", filename);
if (error < 0 || error >= sizeof(path)) {
fprintf(stderr, "execve(): array too small?\n");
goto return_execve1;
}
found = 1;
}
if (!found) {
fprintf(stderr, fprintf(stderr,
"execve(): error loading ELF for file %s\n", "execve(): error finding file %s\n", filename);
(char *)w.sr.args[1]); goto return_execve1;
}
__dprintf("execve(): path to binary: %s\n", path);
if ((ret = load_elf_desc(path, &desc)) != 0) {
fprintf(stderr,
"execve(): error loading ELF for file %s\n", path);
goto return_execve1; goto return_execve1;
} }
__dprintf("execve(): load_elf_desc() for %s OK, num sections: %d\n", __dprintf("execve(): load_elf_desc() for %s OK, num sections: %d\n",
w.sr.args[1], desc->num_sections); path, desc->num_sections);
/* Copy descriptor to co-kernel side */ /* Copy descriptor to co-kernel side */
trans.userp = (void*)desc; trans.userp = (void*)desc;
@@ -1246,7 +1319,7 @@ int main_loop(int fd, int cpu, pthread_mutex_t *lock)
} }
__dprintf("execve(): load_elf_desc() for %s OK\n", __dprintf("execve(): load_elf_desc() for %s OK\n",
w.sr.args[1]); path);
/* We can't be sure next phase will succeed */ /* We can't be sure next phase will succeed */
/* TODO: what shall we do with fp in desc?? */ /* TODO: what shall we do with fp in desc?? */
@@ -1260,6 +1333,7 @@ return_execve1:
/* Copy program image phase */ /* Copy program image phase */
case 2: case 2:
ret = -1;
/* Alloc descriptor */ /* Alloc descriptor */
desc = malloc(w.sr.args[2]); desc = malloc(w.sr.args[2]);
if (!desc) { if (!desc) {
@@ -1279,7 +1353,7 @@ return_execve1:
goto return_execve1; goto return_execve1;
} }
printf("execve(): transfer ELF desc OK\n"); __dprintf("execve(): transfer ELF desc OK\n");
transfer_image(fd, desc); transfer_image(fd, desc);
__dprintf("execve(): image transferred\n"); __dprintf("execve(): image transferred\n");

View File

@@ -84,6 +84,9 @@
//#define USE_LARGE_PAGES //#define USE_LARGE_PAGES
#endif #endif
#define USER_STACK_NR_PAGES 8192
#define KERNEL_STACK_NR_PAGES 25
#include <waitq.h> #include <waitq.h>
#include <futex.h> #include <futex.h>
#include <rlimit.h> #include <rlimit.h>

View File

@@ -43,9 +43,6 @@
#endif #endif
#define USER_STACK_NR_PAGES 8192
#define KERNEL_STACK_NR_PAGES 25
extern long do_arch_prctl(unsigned long code, unsigned long address); extern long do_arch_prctl(unsigned long code, unsigned long address);
static void insert_vm_range_list(struct process_vm *vm, static void insert_vm_range_list(struct process_vm *vm,
struct vm_range *newrange); struct vm_range *newrange);
@@ -1787,6 +1784,7 @@ static void do_migrate(void)
ihk_mc_spinlock_lock_noirq(&cur_v->migq_lock); ihk_mc_spinlock_lock_noirq(&cur_v->migq_lock);
list_for_each_entry_safe(req, tmp, &cur_v->migq, list) { list_for_each_entry_safe(req, tmp, &cur_v->migq, list) {
int cpu_id; int cpu_id;
int old_cpu_id;
struct cpu_local_var *v; struct cpu_local_var *v;
/* 0. check if migration is necessary */ /* 0. check if migration is necessary */
@@ -1808,9 +1806,17 @@ static void do_migrate(void)
double_rq_lock(cur_v, v); double_rq_lock(cur_v, v);
list_del(&req->proc->sched_list); list_del(&req->proc->sched_list);
cur_v->runq_len -= 1; cur_v->runq_len -= 1;
old_cpu_id = req->proc->cpu_id;
req->proc->cpu_id = cpu_id; req->proc->cpu_id = cpu_id;
list_add_tail(&req->proc->sched_list, &v->runq); list_add_tail(&req->proc->sched_list, &v->runq);
v->runq_len += 1; v->runq_len += 1;
/* update cpu_set of the VM for remote TLB invalidation */
cpu_clear(old_cpu_id, &req->proc->vm->cpu_set,
&req->proc->vm->cpu_set_lock);
cpu_set(cpu_id, &req->proc->vm->cpu_set,
&req->proc->vm->cpu_set_lock);
if (v->runq_len == 1) if (v->runq_len == 1)
ihk_mc_interrupt_cpu(get_x86_cpu_local_variable(cpu_id)->apic_id, 0xd1); ihk_mc_interrupt_cpu(get_x86_cpu_local_variable(cpu_id)->apic_id, 0xd1);
double_rq_unlock(cur_v, v); double_rq_unlock(cur_v, v);

View File

@@ -1228,6 +1228,11 @@ SYSCALL_DECLARE(execve)
/* Unmap all memory areas of the process, userspace will be gone */ /* Unmap all memory areas of the process, userspace will be gone */
free_process_memory_ranges(cpu_local_var(current)); free_process_memory_ranges(cpu_local_var(current));
ihk_mc_init_user_process(&cpu_local_var(current)->ctx,
&cpu_local_var(current)->uctx,
((char *)cpu_local_var(current)) +
KERNEL_STACK_NR_PAGES * PAGE_SIZE, desc->entry, 0);
/* Create virtual memory ranges and update args/envs */ /* Create virtual memory ranges and update args/envs */
if (prepare_process_ranges_args_envs(cpu_local_var(current), desc, desc, if (prepare_process_ranges_args_envs(cpu_local_var(current), desc, desc,
PTATTR_NO_EXECUTE | PTATTR_WRITABLE | PTATTR_FOR_USER, PTATTR_NO_EXECUTE | PTATTR_WRITABLE | PTATTR_FOR_USER,
@@ -1236,6 +1241,18 @@ SYSCALL_DECLARE(execve)
panic(""); panic("");
} }
/* Clear host user space PTEs */
request.number = __NR_munmap;
request.args[0] = cpu_local_var(current)->vm->region.user_start;
request.args[1] = cpu_local_var(current)->vm->region.user_end -
cpu_local_var(current)->vm->region.user_start;
dkprintf("execve(): requesting host PTE clear\n");
if (do_syscall(&request, ctx, ihk_mc_get_processor_id(), 0)) {
kprintf("execve(): ERROR: clearing PTEs in host process\n");
panic("");
}
/* Request host to transfer ELF image */ /* Request host to transfer ELF image */
request.number = __NR_execve; request.number = __NR_execve;
request.args[0] = 2; /* 2nd phase - transfer ELF image */ request.args[0] = 2; /* 2nd phase - transfer ELF image */
@@ -1250,8 +1267,13 @@ SYSCALL_DECLARE(execve)
panic(""); panic("");
} }
dkprintf("execve(): returning to new process\n"); /* Switch to new execution context */
dkprintf("execve(): switching to new process\n");
ihk_mc_switch_context(NULL, &cpu_local_var(current)->ctx,
cpu_local_var(current));
/* Never reach here */
return 0; return 0;
} }