From 1cf0bd5a78efaa122f4b433dbc9b06480bab45a7 Mon Sep 17 00:00:00 2001 From: Masamichi Takagi Date: Mon, 15 Jun 2020 13:27:26 +0900 Subject: [PATCH] TO RESET: add debug instruments, map Linux areas for tofu Change-Id: I09880cad3b87182cb663d414041254817c254759 --- executer/kernel/mcctrl/driver.c | 1 - kernel/cls.c | 3 + kernel/host.c | 4 ++ kernel/include/cls.h | 3 + kernel/mem.c | 32 +++++++++- kernel/syscall.c | 110 +++++++++++++++++++++++++++++++- 6 files changed, 148 insertions(+), 5 deletions(-) diff --git a/executer/kernel/mcctrl/driver.c b/executer/kernel/mcctrl/driver.c index 1f9573fc..70eac7f2 100644 --- a/executer/kernel/mcctrl/driver.c +++ b/executer/kernel/mcctrl/driver.c @@ -235,7 +235,6 @@ void (*mcctrl_zap_page_range)(struct vm_area_struct *vma, struct inode_operations *mcctrl_hugetlbfs_inode_operations; - static int symbols_init(void) { #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,17,0) diff --git a/kernel/cls.c b/kernel/cls.c index ad256d25..bfa669c3 100644 --- a/kernel/cls.c +++ b/kernel/cls.c @@ -82,6 +82,9 @@ void preempt_enable(void) //arch_cpu_stop(); //cpu_halt(); +#ifdef ENABLE_FUGAKU_HACKS + panic("panic: negative preemption??"); +#endif } } #endif diff --git a/kernel/host.c b/kernel/host.c index 64a05efb..64f6a7b6 100644 --- a/kernel/host.c +++ b/kernel/host.c @@ -788,7 +788,11 @@ out_remote_pf: syscall_channel_send(resp_channel, &pckt); rc = do_kill(NULL, info.pid, info.tid, info.sig, &info.info, 0); +#ifndef ENABLE_FUGAKU_HACKS dkprintf("SCD_MSG_SEND_SIGNAL: do_kill(pid=%d, tid=%d, sig=%d)=%d\n", info.pid, info.tid, info.sig, rc); +#else + kprintf("SCD_MSG_SEND_SIGNAL: do_kill(pid=%d, tid=%d, sig=%d)=%d\n", info.pid, info.tid, info.sig, rc); +#endif ret = 0; break; diff --git a/kernel/include/cls.h b/kernel/include/cls.h index 6df5837a..316068d6 100644 --- a/kernel/include/cls.h +++ b/kernel/include/cls.h @@ -106,6 +106,9 @@ struct cpu_local_var { ihk_spinlock_t migq_lock; struct list_head migq; int in_interrupt; +#ifdef ENABLE_FUGAKU_HACKS + int in_page_fault; +#endif int no_preempt; int timer_enabled; unsigned long nr_ctx_switches; diff --git a/kernel/mem.c b/kernel/mem.c index 9ea3a4eb..377c3315 100644 --- a/kernel/mem.c +++ b/kernel/mem.c @@ -954,6 +954,9 @@ static void query_free_mem_interrupt_handler(void *priv) } kprintf("McKernel free pages in total: %d\n", pages); +#ifdef ENABLE_FUGAKU_HACKS + panic("PANIC"); +#endif if (find_command_line("memdebug")) { extern void kmalloc_memcheck(void); @@ -1346,7 +1349,13 @@ static void unhandled_page_fault(struct thread *thread, void *fault_addr, if (!(reason & PF_USER)) { cpu_local_var(kernel_mode_pf_regs) = regs; +#ifndef ENABLE_FUGAKU_HACKS panic("panic: kernel mode PF"); +#else + kprintf("panic: kernel mode PF"); + for (;;) cpu_pause(); + //panic("panic: kernel mode PF"); +#endif } //dkprintf("now dump a core file\n"); @@ -1382,6 +1391,20 @@ static void page_fault_handler(void *fault_addr, uint64_t reason, void *regs) __FUNCTION__, fault_addr, reason, regs); preempt_disable(); +#ifdef ENABLE_FUGAKU_HACKS + ++cpu_local_var(in_page_fault); + if (cpu_local_var(in_page_fault) > 1) { + kprintf("%s: PF in PF??\n", __func__); + cpu_disable_interrupt(); + if (!(reason & PF_USER)) { + cpu_local_var(kernel_mode_pf_regs) = regs; + panic("panic: kernel mode PF in PF"); + } + while (1) { + panic("PANIC"); + } + } +#endif cpu_enable_interrupt(); @@ -1451,9 +1474,9 @@ out_linux: preempt_enable(); #ifdef ENABLE_FUGAKU_DEBUG - kprintf("%s: sending SIGSTOP to TID: %d\n", __func__, thread->tid); - do_kill(thread, thread->proc->pid, thread->tid, SIGSTOP, NULL, 0); - goto out; + //kprintf("%s: sending SIGSTOP to TID: %d\n", __func__, thread->tid); + //do_kill(thread, thread->proc->pid, thread->tid, SIGSTOP, NULL, 0); + //goto out; #endif memset(&info, '\0', sizeof info); @@ -1484,6 +1507,9 @@ out_linux: out_ok: #endif error = 0; +#ifdef ENABLE_FUGAKU_HACKS + --cpu_local_var(in_page_fault); +#endif preempt_enable(); out: dkprintf("%s: addr: %p, reason: %lx, regs: %p -> error: %d\n", diff --git a/kernel/syscall.c b/kernel/syscall.c index 96ea656b..3aeedb56 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -204,6 +204,14 @@ long do_syscall(struct syscall_request *req, int cpu) ++thread->in_syscall_offload; } +#ifdef ENABLE_FUGAKU_HACKS +#if 0 + if (req->number == __NR_write && req->args[0] == 1) { + return req->args[2]; + } +#endif +#endif + /* The current thread is the requester */ req->rtid = cpu_local_var(current)->tid; @@ -1930,6 +1938,10 @@ do_mmap(const uintptr_t addr0, const size_t len0, const int prot, __FUNCTION__, proc->straight_va, range->pgshift); ptattr = arch_vrflag_to_ptattr(range->flag, PF_POPULATE, NULL); + +#ifdef ENABLE_FUGAKU_HACKS + if (1) { // Un-safe mapping of covering physical range +#endif error = ihk_mc_pt_set_range(proc->vm->address_space->page_table, proc->vm, (void *)range->start, @@ -1956,6 +1968,90 @@ do_mmap(const uintptr_t addr0, const size_t len0, const int prot, proc->straight_pa, psize, proc->straight_map_threshold); + +#ifdef ENABLE_FUGAKU_HACKS + } + else { // Safe mapping of only LWK memory ranges + size_t max_pgsize = 0; + size_t min_pgsize = 0xFFFFFFFFFFFFFFFF; + + /* + * Iterate LWK phsyical memory chunks and map them to their + * corresponding offset in the straight range using the largest + * suitable pages. + */ + for (i = 0; i < ihk_mc_get_nr_memory_chunks(); ++i) { + unsigned long start, end, pa; + void *va, *va_end; + size_t pgsize; + int pg2align; + + ihk_mc_get_memory_chunk(i, &start, &end, NULL); + va = proc->straight_va + (start - straight_pa_start); + va_end = va + (end - start); + pa = start; + + while (va < va_end) { + pgsize = (va_end - va) + 1; +retry: + error = arch_get_smaller_page_size(NULL, pgsize, + &pgsize, &pg2align); + if (error) { + ekprintf("%s: arch_get_smaller_page_size() failed" + " during straight mapping: %d\n", + __func__, error); + proc->straight_va = 0; + goto straight_out; + } + + /* Are virtual or physical not page aligned for this size? */ + if (((unsigned long)va & (pgsize - 1)) || + (pa & (pgsize - 1))) { + goto retry; + } + + error = ihk_mc_pt_set_range( + proc->vm->address_space->page_table, + proc->vm, + va, + va + pgsize, + pa, + ptattr, + pg2align + PAGE_SHIFT, + range, + 0); + + if (error) { + kprintf("%s: ihk_mc_pt_set_range() failed" + " during straight mapping: %d\n", + __func__, error); + proc->straight_va = 0; + goto straight_out; + } + + if (pgsize > max_pgsize) + max_pgsize = pgsize; + + if (pgsize < min_pgsize) + min_pgsize = pgsize; + + va += pgsize; + pa += pgsize; + } + } + + region->map_end = (unsigned long)proc->straight_va + + proc->straight_len; + proc->straight_pa = straight_pa_start; + kprintf("%s: straight mapping: 0x%lx:%lu @ " + "min_pgsize: %lu, max_pgsize: %lu\n", + __FUNCTION__, + proc->straight_va, + proc->straight_len, + min_pgsize, + max_pgsize); + } +#endif } straight_out: @@ -2284,8 +2380,15 @@ straight_out: range->straight_start = (unsigned long)proc->straight_va + (straight_phys - proc->straight_pa); +#ifndef ENABLE_FUGAKU_HACKS dkprintf("%s: range 0x%lx:%lu is straight starting at 0x%lx\n", - __FUNCTION__, addr, len, range->straight_start); + __FUNCTION__, addr, len, range->straight_start); +#else + dkprintf("%s: range 0x%lx:%lu is straight starting at 0x%lx" + " (phys: 0x%lx)\n", + __FUNCTION__, addr, len, range->straight_start, + straight_phys); +#endif if (!zero_at_free) { memset((void *)phys_to_virt(straight_phys), 0, len); } @@ -2435,6 +2538,11 @@ SYSCALL_DECLARE(munmap) out: dkprintf("[%d]sys_munmap(%lx,%lx): %d\n", ihk_mc_get_processor_id(), addr, len0, error); +#ifdef ENABLE_FUGAKU_HACKS + if (error) { + kprintf("%s: error: %d\n", __func__, error); + } +#endif return error; }