Remove the frontend appserver code
[akaros.git] / kern / src / syscall.c
index 999d118..d4ffa34 100644 (file)
@@ -23,8 +23,6 @@
 #include <kmalloc.h>
 #include <profiler.h>
 #include <stdio.h>
-#include <frontend.h>
-#include <colored_caches.h>
 #include <hashtable.h>
 #include <bitmask.h>
 #include <vfs.h>
@@ -105,17 +103,105 @@ static size_t systrace_fill_pretty_buf(struct systrace_record *trace,
        return len;
 }
 
+/* If some syscalls block, then they can really hurt the user and the
+ * kernel.  For instance, if you blocked another call because the trace queue is
+ * full, the 2LS will want to yield the vcore, but then *that* call would block
+ * too.  Since that caller was in vcore context, the core will just spin
+ * forever.
+ *
+ * Even worse, some syscalls operate on the calling core or current context,
+ * thus accessing pcpui.  If we block, then that old context is gone.  Worse, we
+ * could migrate and then be operating on a different core.  Imagine
+ * SYS_halt_core.  Doh! */
+static bool sysc_can_block(unsigned int sysc_num)
+{
+       switch (sysc_num) {
+       case SYS_proc_yield:
+       case SYS_fork:
+       case SYS_exec:
+       case SYS_pop_ctx:
+       case SYS_getvcoreid:
+       case SYS_halt_core:
+       case SYS_vc_entry:
+       case SYS_change_vcore:
+       case SYS_change_to_m:
+               return FALSE;
+       }
+       return TRUE;
+}
+
 /* Helper: spits out our trace to the various sinks. */
 static void systrace_output(struct systrace_record *trace,
                             struct strace *strace, bool entry)
 {
+       ERRSTACK(1);
        size_t pretty_len;
 
+       /* qio ops can throw, especially the blocking qwrite.  I had it block on the
+        * outbound path of sys_proc_destroy().  The rendez immediately throws. */
+       if (waserror()) {
+               poperror();
+               return;
+       }
        pretty_len = systrace_fill_pretty_buf(trace, entry);
-       if (strace)
-               qiwrite(strace->q, trace->pretty_buf, pretty_len);
+       if (strace) {
+               /* At this point, we're going to emit the exit trace.  It's just a
+                * question of whether or not we block while doing it. */
+               if (strace->drop_overflow || !sysc_can_block(trace->syscallno))
+                       qiwrite(strace->q, trace->pretty_buf, pretty_len);
+               else
+                       qwrite(strace->q, trace->pretty_buf, pretty_len);
+       }
        if (systrace_loud)
                printk("%s", trace->pretty_buf);
+       poperror();
+}
+
+static bool should_strace(struct proc *p, struct syscall *sysc)
+{
+       unsigned int sysc_num;
+
+       if (systrace_loud)
+               return TRUE;
+       if (!p->strace || !p->strace->tracing)
+               return FALSE;
+       /* TOCTTOU concerns - sysc is __user. */
+       sysc_num = ACCESS_ONCE(sysc->num);
+       if (qfull(p->strace->q)) {
+               if (p->strace->drop_overflow || !sysc_can_block(sysc_num)) {
+                       atomic_inc(&p->strace->nr_drops);
+                       return FALSE;
+               }
+       }
+       if (sysc_num > MAX_SYSCALL_NR)
+               return FALSE;
+       return test_bit(sysc_num, p->strace->trace_set);
+}
+
+/* Helper, copies len bytes from u_data to the trace->data, if there's room. */
+static void copy_tracedata_from_user(struct systrace_record *trace,
+                                     long u_data, size_t len)
+{
+       size_t copy_amt;
+
+       copy_amt = MIN(sizeof(trace->data) - trace->datalen, len);
+       copy_from_user(trace->data + trace->datalen, (void*)u_data, copy_amt);
+       trace->datalen += copy_amt;
+}
+
+/* Helper, snprintfs to the trace, if there's room. */
+static void snprintf_to_trace(struct systrace_record *trace, const char *fmt,
+                              ...)
+{
+       va_list ap;
+       int rc;
+
+       va_start(ap, fmt);
+       rc = vsnprintf((char*)trace->data + trace->datalen,
+                      sizeof(trace->data) - trace->datalen, fmt, ap);
+       va_end(ap);
+       if (!snprintf_error(rc, sizeof(trace->data) - trace->datalen))
+               trace->datalen += rc;
 }
 
 /* Starts a trace for p running sysc, attaching it to kthread.  Pairs with
@@ -124,31 +210,24 @@ static void systrace_start_trace(struct kthread *kthread, struct syscall *sysc)
 {
        struct proc *p = current;
        struct systrace_record *trace;
-       uintreg_t data_arg;
-       size_t data_len = 0;
 
        kthread->strace = 0;
-       if (!p->strace_on && !systrace_loud)
+       if (!should_strace(p, sysc))
                return;
-       trace = kmalloc(SYSTR_BUF_SZ, MEM_ATOMIC);
+       /* TODO: consider a block_alloc and qpass, though note that we actually
+        * write the same trace in twice (entry and exit). */
+       trace = kpages_alloc(SYSTR_BUF_SZ, MEM_ATOMIC);
        if (p->strace) {
-               /* We're using qiwrite below, which has no flow control.  We'll do it
-                * manually.  TODO: consider a block_alloc and qpass, though note that
-                * we actually write the same trace in twice (entry and exit).
-                * Alternatively, we can add another qio method that has flow control
-                * and non blocking. */
-               if (qfull(p->strace->q)) {
+               if (!trace) {
                        atomic_inc(&p->strace->nr_drops);
-                       kfree(trace);
                        return;
                }
-               if (!trace)
-                       atomic_inc(&p->strace->nr_drops);
                /* Avoiding the atomic op.  We sacrifice accuracy for less overhead. */
                p->strace->appx_nr_sysc++;
+       } else {
+               if (!trace)
+                       return;
        }
-       if (!trace)
-               return;
        /* if you ever need to debug just one strace function, this is
         * handy way to do it: just bail out if it's not the one you
         * want.
@@ -173,12 +252,32 @@ static void systrace_start_trace(struct kthread *kthread, struct syscall *sysc)
 
        switch (sysc->num) {
        case SYS_write:
-               data_arg = sysc->arg1;
-               data_len = sysc->arg2;
+               copy_tracedata_from_user(trace, sysc->arg1, sysc->arg2);
                break;
        case SYS_openat:
-               data_arg = sysc->arg1;
-               data_len = sysc->arg2;
+       case SYS_chdir:
+       case SYS_rmdir:
+       case SYS_nmount:
+               copy_tracedata_from_user(trace, sysc->arg1, sysc->arg2);
+               break;
+       case SYS_stat:
+       case SYS_lstat:
+       case SYS_access:
+       case SYS_unlink:
+       case SYS_mkdir:
+       case SYS_wstat:
+               copy_tracedata_from_user(trace, sysc->arg0, sysc->arg1);
+               break;
+       case SYS_link:
+       case SYS_symlink:
+       case SYS_rename:
+       case SYS_nbind:
+               copy_tracedata_from_user(trace, sysc->arg0, sysc->arg1);
+               snprintf_to_trace(trace, " -> ");
+               copy_tracedata_from_user(trace, sysc->arg2, sysc->arg3);
+               break;
+       case SYS_nunmount:
+               copy_tracedata_from_user(trace, sysc->arg2, sysc->arg3);
                break;
        case SYS_exec:
                trace->datalen = execargs_stringer(current,
@@ -199,11 +298,6 @@ static void systrace_start_trace(struct kthread *kthread, struct syscall *sysc)
                                                   sysc->arg3);
                break;
        }
-       if (data_len) {
-               trace->datalen = MIN(sizeof(trace->data), data_len);
-               copy_from_user(trace->data, (void*)data_arg, trace->datalen);
-       }
-
        systrace_output(trace, p->strace, TRUE);
 
        kthread->strace = trace;
@@ -215,8 +309,6 @@ static void systrace_finish_trace(struct kthread *kthread, long retval)
 {
        struct proc *p = current;
        struct systrace_record *trace;
-       long data_arg;
-       size_t data_len = 0;
 
        if (!kthread->strace)
                return;
@@ -228,17 +320,22 @@ static void systrace_finish_trace(struct kthread *kthread, long retval)
        if (!trace->datalen) {
                switch (trace->syscallno) {
                case SYS_read:
-                       data_arg = trace->arg1;
-                       data_len = retval < 0 ? 0 : retval;
+                       if (retval <= 0)
+                               break;
+                       copy_tracedata_from_user(trace, trace->arg1, retval);
+                       break;
+               case SYS_readlink:
+                       if (retval <= 0)
+                               break;
+                       copy_tracedata_from_user(trace, trace->arg0, trace->arg1);
+                       snprintf_to_trace(trace, " -> ");
+                       copy_tracedata_from_user(trace, trace->arg2, trace->arg3);
                        break;
                }
-               trace->datalen = MIN(sizeof(trace->data), data_len);
-               if (trace->datalen)
-                       copy_from_user(trace->data, (void*)data_arg, trace->datalen);
        }
 
        systrace_output(trace, p->strace, FALSE);
-       kfree(kthread->strace);
+       kpages_free(kthread->strace, SYSTR_BUF_SZ);
        kthread->strace = 0;
 }
 
@@ -246,13 +343,16 @@ static void systrace_finish_trace(struct kthread *kthread, long retval)
 
 static void alloc_sysc_str(struct kthread *kth)
 {
-       kth->name = kmalloc(SYSCALL_STRLEN, MEM_WAIT);
+       kth->name = kmalloc(SYSCALL_STRLEN, MEM_ATOMIC);
+       if (!kth->name)
+               return;
        kth->name[0] = 0;
 }
 
 static void free_sysc_str(struct kthread *kth)
 {
        char *str = kth->name;
+
        kth->name = 0;
        kfree(str);
 }
@@ -260,7 +360,9 @@ static void free_sysc_str(struct kthread *kth)
 #define sysc_save_str(...)                                                     \
 {                                                                              \
        struct per_cpu_info *pcpui = &per_cpu_info[core_id()];                     \
-       snprintf(pcpui->cur_kthread->name, SYSCALL_STRLEN, __VA_ARGS__);           \
+                                                                               \
+       if (pcpui->cur_kthread->name)                                              \
+               snprintf(pcpui->cur_kthread->name, SYSCALL_STRLEN, __VA_ARGS__);       \
 }
 
 #else
@@ -525,80 +627,6 @@ static int sys_nanosleep(struct proc *p,
        return 0;
 }
 
-// Writes 'val' to 'num_writes' entries of the well-known array in the kernel
-// address space.  It's just #defined to be some random 4MB chunk (which ought
-// to be boot_alloced or something).  Meant to grab exclusive access to cache
-// lines, to simulate doing something useful.
-static int sys_cache_buster(struct proc *p, uint32_t num_writes,
-                             uint32_t num_pages, uint32_t flags)
-{
-       #define BUSTER_ADDR             0xd0000000L  // around 512 MB deep
-       #define MAX_WRITES              1048576*8
-       #define MAX_PAGES               32
-       #define INSERT_ADDR     (UINFO + 2*PGSIZE) // should be free for these tests
-       uint32_t* buster = (uint32_t*)BUSTER_ADDR;
-       static spinlock_t buster_lock = SPINLOCK_INITIALIZER;
-       uint64_t ticks = -1;
-       page_t* a_page[MAX_PAGES];
-
-       /* Strided Accesses or Not (adjust to step by cachelines) */
-       uint32_t stride = 1;
-       if (flags & BUSTER_STRIDED) {
-               stride = 16;
-               num_writes *= 16;
-       }
-
-       /* Shared Accesses or Not (adjust to use per-core regions)
-        * Careful, since this gives 8MB to each core, starting around 512MB.
-        * Also, doesn't separate memory for core 0 if it's an async call.
-        */
-       if (!(flags & BUSTER_SHARED))
-               buster = (uint32_t*)(BUSTER_ADDR + core_id() * 0x00800000);
-
-       /* Start the timer, if we're asked to print this info*/
-       if (flags & BUSTER_PRINT_TICKS)
-               ticks = start_timing();
-
-       /* Allocate num_pages (up to MAX_PAGES), to simulate doing some more
-        * realistic work.  Note we don't write to these pages, even if we pick
-        * unshared.  Mostly due to the inconvenience of having to match up the
-        * number of pages with the number of writes.  And it's unnecessary.
-        */
-       if (num_pages) {
-               spin_lock(&buster_lock);
-               for (int i = 0; i < MIN(num_pages, MAX_PAGES); i++) {
-                       upage_alloc(p, &a_page[i],1);
-                       page_insert(p->env_pgdir, a_page[i], (void*)INSERT_ADDR + PGSIZE*i,
-                                   PTE_USER_RW);
-                       page_decref(a_page[i]);
-               }
-               spin_unlock(&buster_lock);
-       }
-
-       if (flags & BUSTER_LOCKED)
-               spin_lock(&buster_lock);
-       for (int i = 0; i < MIN(num_writes, MAX_WRITES); i=i+stride)
-               buster[i] = 0xdeadbeef;
-       if (flags & BUSTER_LOCKED)
-               spin_unlock(&buster_lock);
-
-       if (num_pages) {
-               spin_lock(&buster_lock);
-               for (int i = 0; i < MIN(num_pages, MAX_PAGES); i++) {
-                       page_remove(p->env_pgdir, (void*)(INSERT_ADDR + PGSIZE * i));
-                       page_decref(a_page[i]);
-               }
-               spin_unlock(&buster_lock);
-       }
-
-       /* Print info */
-       if (flags & BUSTER_PRINT_TICKS) {
-               ticks = stop_timing(ticks);
-               printk("%llu,", ticks);
-       }
-       return 0;
-}
-
 static int sys_cache_invalidate(void)
 {
        #ifdef CONFIG_X86
@@ -627,13 +655,11 @@ static size_t sys_getvcoreid(struct proc *p)
 /* Helper for proc_create and fork */
 static void inherit_strace(struct proc *parent, struct proc *child)
 {
-       if (parent->strace && parent->strace_inherit) {
+       if (parent->strace && parent->strace->inherit) {
                /* Refcnt on both, put in the child's ->strace. */
                kref_get(&parent->strace->users, 1);
                kref_get(&parent->strace->procs, 1);
                child->strace = parent->strace;
-               child->strace_on = TRUE;
-               child->strace_inherit = TRUE;
        }
 }
 
@@ -758,7 +784,6 @@ static error_t sys_proc_destroy(struct proc *p, pid_t pid, int exitcode)
                printd("[%d] destroying proc %d\n", p->pid, p_to_die->pid);
        }
        proc_destroy(p_to_die);
-       /* we only get here if we weren't the one to die */
        proc_decref(p_to_die);
        return 0;
 }
@@ -793,6 +818,7 @@ static ssize_t sys_fork(env_t* e)
 {
        uintptr_t temp;
        int ret;
+       struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
 
        // TODO: right now we only support fork for single-core processes
        if (e->state != PROC_RUNNING_S) {
@@ -812,13 +838,9 @@ static ssize_t sys_fork(env_t* e)
                set_errno(EINVAL);
                return -1;
        }
+       assert(pcpui->cur_proc == pcpui->owning_proc);
        copy_current_ctx_to(&env->scp_ctx);
 
-       env->cache_colors_map = cache_colors_map_alloc();
-       for (int i = 0; i < llc_cache->num_colors; i++)
-               if (GET_BITMASK_BIT(e->cache_colors_map,i))
-                       cache_color_alloc(llc_cache, env->cache_colors_map);
-
        /* Make the new process have the same VMRs as the older.  This will copy the
         * contents of non MAP_SHARED pages to the new VMRs. */
        if (duplicate_vmrs(e, env)) {
@@ -836,7 +858,6 @@ static ssize_t sys_fork(env_t* e)
        switch_back(env, temp);
 
        /* Copy some state from the original proc into the new proc. */
-       env->heap_top = e->heap_top;
        env->env_flags = e->env_flags;
 
        inherit_strace(e, env);
@@ -844,7 +865,7 @@ static ssize_t sys_fork(env_t* e)
        /* In general, a forked process should be a fresh process, and we copy over
         * whatever stuff is needed between procinfo/procdata. */
        *env->procdata = *e->procdata;
-       env->procinfo->heap_bottom = e->procinfo->heap_bottom;
+       env->procinfo->program_end = e->procinfo->program_end;
 
        /* FYI: once we call ready, the proc is open for concurrent usage */
        __proc_ready(env);
@@ -952,6 +973,7 @@ static int sys_exec(struct proc *p, char *path, size_t path_l,
        }
        /* Preemptively copy out the cur_ctx, in case we fail later (easier on
         * cur_ctx if we do this now) */
+       assert(pcpui->cur_proc == pcpui->owning_proc);
        copy_current_ctx_to(&p->scp_ctx);
        /* Check the size of the argenv array, error out if too large. */
        if ((argenv_l < sizeof(struct argenv)) || (argenv_l > ARG_MAX)) {
@@ -999,7 +1021,7 @@ static int sys_exec(struct proc *p, char *path, size_t path_l,
        proc_replace_binary_path(p, t_path);
        proc_set_progname(p, argc ? argv[0] : NULL);
        proc_init_procdata(p);
-       p->procinfo->heap_bottom = 0;
+       p->procinfo->program_end = 0;
        /* When we destroy our memory regions, accessing cur_sysc would PF */
        pcpui->cur_kthread->sysc = 0;
        unmap_and_destroy_vmrs(p);
@@ -1333,6 +1355,19 @@ static int sys_self_notify(struct proc *p, uint32_t vcoreid,
        return 0;
 }
 
+static int sys_send_event(struct proc *p, struct event_queue *ev_q,
+                          struct event_msg *u_msg, uint32_t vcoreid)
+{
+       struct event_msg local_msg = {0};
+
+       if (memcpy_from_user(p, &local_msg, u_msg, sizeof(struct event_msg))) {
+               set_errno(EINVAL);
+               return -1;
+       }
+       send_event(p, ev_q, &local_msg, vcoreid);
+       return 0;
+}
+
 /* Puts the calling core into vcore context, if it wasn't already, via a
  * self-IPI / active notification.  Barring any weird unmappings, we just send
  * ourselves a __notify. */
@@ -1454,21 +1489,23 @@ static int sys_pop_ctx(struct proc *p, struct user_context *ctx)
        return 0;
 }
 
-/* Initializes a process to run virtual machine contexts, returning the number
- * initialized, optionally setting errno */
-static int sys_vmm_setup(struct proc *p, unsigned int nr_guest_pcores,
-                         struct vmm_gpcore_init *gpcis, int flags)
+static int sys_vmm_add_gpcs(struct proc *p, unsigned int nr_more_gpcs,
+                            struct vmm_gpcore_init *gpcis)
 {
-       int ret;
        ERRSTACK(1);
+       struct vmm *vmm = &p->vmm;
 
+       qlock(&vmm->qlock);
        if (waserror()) {
+               qunlock(&vmm->qlock);
                poperror();
                return -1;
        }
-       ret = vmm_struct_init(p, nr_guest_pcores, gpcis, flags);
+       __vmm_struct_init(p);
+       __vmm_add_gpcs(p, nr_more_gpcs, gpcis);
+       qunlock(&vmm->qlock);
        poperror();
-       return ret;
+       return nr_more_gpcs;
 }
 
 static int sys_vmm_poke_guest(struct proc *p, int guest_pcoreid)
@@ -1476,6 +1513,55 @@ static int sys_vmm_poke_guest(struct proc *p, int guest_pcoreid)
        return vmm_poke_guest(p, guest_pcoreid);
 }
 
+static int sys_vmm_ctl(struct proc *p, int cmd, unsigned long arg1,
+                       unsigned long arg2, unsigned long arg3,
+                       unsigned long arg4)
+{
+       ERRSTACK(1);
+       int ret;
+       struct vmm *vmm = &p->vmm;
+
+       /* Protects against concurrent setters and for gets that are not atomic
+        * reads (say, multiple exec ctls). */
+       qlock(&vmm->qlock);
+       if (waserror()) {
+               qunlock(&vmm->qlock);
+               poperror();
+               return -1;
+       }
+       __vmm_struct_init(p);
+       switch (cmd) {
+       case VMM_CTL_GET_EXITS:
+               if (vmm->amd)
+                       error(ENOTSUP, "AMD VMMs unsupported");
+               ret = vmx_ctl_get_exits(&vmm->vmx);
+               break;
+       case VMM_CTL_SET_EXITS:
+               if (arg1 & ~VMM_CTL_ALL_EXITS)
+                       error(EINVAL, "Bad vmm_ctl_exits %x (%x)", arg1,
+                             VMM_CTL_ALL_EXITS);
+               if (vmm->amd)
+                       error(ENOTSUP, "AMD VMMs unsupported");
+               ret = vmx_ctl_set_exits(&vmm->vmx, arg1);
+               break;
+       case VMM_CTL_GET_FLAGS:
+               ret = vmm->flags;
+               break;
+       case VMM_CTL_SET_FLAGS:
+               if (arg1 & ~VMM_CTL_ALL_FLAGS)
+                       error(EINVAL, "Bad vmm_ctl flags.  Got 0x%lx, allowed 0x%lx\n",
+                             arg1, VMM_CTL_ALL_FLAGS);
+               vmm->flags = arg1;
+               ret = 0;
+               break;
+       default:
+               error(EINVAL, "Bad vmm_ctl cmd %d", cmd);
+       }
+       qunlock(&vmm->qlock);
+       poperror();
+       return ret;
+}
+
 /* Pokes the ksched for the given resource for target_pid.  If the target pid
  * == 0, we just poke for the calling process.  The common case is poking for
  * self, so we avoid the lookup.
@@ -1648,11 +1734,6 @@ static intreg_t sys_close(struct proc *p, int fd)
        return retval;
 }
 
-/* kept around til we remove the last ufe */
-#define ufe(which,a0,a1,a2,a3) \
-       frontend_syscall_errno(p,APPSERVER_SYSCALL_##which,\
-                          (int)(a0),(int)(a1),(int)(a2),(int)(a3))
-
 static intreg_t sys_fstat(struct proc *p, int fd, struct kstat *u_stat)
 {
        struct kstat *kbuf;
@@ -2524,7 +2605,6 @@ static intreg_t sys_tap_fds(struct proc *p, struct fd_tap_req *tap_reqs,
 const struct sys_table_entry syscall_table[] = {
        [SYS_null] = {(syscall_t)sys_null, "null"},
        [SYS_block] = {(syscall_t)sys_block, "block"},
-       [SYS_cache_buster] = {(syscall_t)sys_cache_buster, "buster"},
        [SYS_cache_invalidate] = {(syscall_t)sys_cache_invalidate, "wbinv"},
        [SYS_reboot] = {(syscall_t)reboot, "reboot!"},
        [SYS_getpcoreid] = {(syscall_t)sys_getpcoreid, "getpcoreid"},
@@ -2532,7 +2612,7 @@ const struct sys_table_entry syscall_table[] = {
        [SYS_proc_create] = {(syscall_t)sys_proc_create, "proc_create"},
        [SYS_proc_run] = {(syscall_t)sys_proc_run, "proc_run"},
        [SYS_proc_destroy] = {(syscall_t)sys_proc_destroy, "proc_destroy"},
-       [SYS_yield] = {(syscall_t)sys_proc_yield, "proc_yield"},
+       [SYS_proc_yield] = {(syscall_t)sys_proc_yield, "proc_yield"},
        [SYS_change_vcore] = {(syscall_t)sys_change_vcore, "change_vcore"},
        [SYS_fork] = {(syscall_t)sys_fork, "fork"},
        [SYS_exec] = {(syscall_t)sys_exec, "exec"},
@@ -2545,14 +2625,16 @@ const struct sys_table_entry syscall_table[] = {
        [SYS_provision] = {(syscall_t)sys_provision, "provision"},
        [SYS_notify] = {(syscall_t)sys_notify, "notify"},
        [SYS_self_notify] = {(syscall_t)sys_self_notify, "self_notify"},
+       [SYS_send_event] = {(syscall_t)sys_send_event, "send_event"},
        [SYS_vc_entry] = {(syscall_t)sys_vc_entry, "vc_entry"},
        [SYS_halt_core] = {(syscall_t)sys_halt_core, "halt_core"},
 #ifdef CONFIG_ARSC_SERVER
        [SYS_init_arsc] = {(syscall_t)sys_init_arsc, "init_arsc"},
 #endif
        [SYS_change_to_m] = {(syscall_t)sys_change_to_m, "change_to_m"},
-       [SYS_vmm_setup] = {(syscall_t)sys_vmm_setup, "vmm_setup"},
+       [SYS_vmm_add_gpcs] = {(syscall_t)sys_vmm_add_gpcs, "vmm_add_gpcs"},
        [SYS_vmm_poke_guest] = {(syscall_t)sys_vmm_poke_guest, "vmm_poke_guest"},
+       [SYS_vmm_ctl] = {(syscall_t)sys_vmm_ctl, "vmm_ctl"},
        [SYS_poke_ksched] = {(syscall_t)sys_poke_ksched, "poke_ksched"},
        [SYS_abort_sysc] = {(syscall_t)sys_abort_sysc, "abort_sysc"},
        [SYS_abort_sysc_fd] = {(syscall_t)sys_abort_sysc_fd, "abort_sysc_fd"},
@@ -2659,6 +2741,7 @@ void run_local_syscall(struct syscall *sysc)
        }
        pcpui->cur_kthread->sysc = sysc;        /* let the core know which sysc it is */
        systrace_start_trace(pcpui->cur_kthread, sysc);
+       pcpui = &per_cpu_info[core_id()];       /* reload again */
        alloc_sysc_str(pcpui->cur_kthread);
        /* syscall() does not return for exec and yield, so put any cleanup in there
         * too. */
@@ -2668,6 +2751,7 @@ void run_local_syscall(struct syscall *sysc)
        pcpui = &per_cpu_info[core_id()];
        free_sysc_str(pcpui->cur_kthread);
        systrace_finish_trace(pcpui->cur_kthread, sysc->retval);
+       pcpui = &per_cpu_info[core_id()];       /* reload again */
        /* Some 9ns paths set errstr, but not errno.  glibc will ignore errstr.
         * this is somewhat hacky, since errno might get set unnecessarily */
        if ((current_errstr()[0] != 0) && (!sysc->err))