diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2016-01-08 22:33:40 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2016-01-08 22:41:36 +0100 |
| commit | bb47c6540dc13ca4170b0bfb8623d8094a2b5139 (patch) | |
| tree | cf6e5477f6eac8ab969b5d682044f931915f2cdc /executor | |
| parent | c9b24b38c9978bea7e3548067b7e261524de4dd0 (diff) | |
sys: add kvm support
Diffstat (limited to 'executor')
| -rw-r--r-- | executor/executor.cc | 48 | ||||
| -rw-r--r-- | executor/syscalls.h | 172 |
2 files changed, 203 insertions, 17 deletions
diff --git a/executor/executor.cc b/executor/executor.cc index 93de7c459..d26e97457 100644 --- a/executor/executor.cc +++ b/executor/executor.cc @@ -303,8 +303,7 @@ retry: if (collide && (call_index % 2) == 0) { // Don't wait for every other call. // We already have results from the previous execution. - } - else if (flag_threaded) { + } else if (flag_threaded) { // Wait for call completion. uint64_t start = current_time_ms(); uint64_t now = start; @@ -335,8 +334,7 @@ retry: handle_completion(th); } } - } - else { + } else { // Execute directly. if (th != &threads[0]) fail("using non-main thread in non-thread mode"); @@ -356,7 +354,8 @@ thread_t* schedule_call(int n, int call_index, int call_num, uint64_t num_args, { // Figure out whether we need root privs for this call. bool root = false; - switch (syscalls[call_num].sys_nr) { + switch (syscalls[call_num] + .sys_nr) { case __NR_mount: case __NR_umount2: case __NR_syz_fuse_mount: @@ -380,7 +379,9 @@ thread_t* schedule_call(int n, int call_index, int call_num, uint64_t num_args, if (i == kMaxThreads) exitf("out of threads"); thread_t* th = &threads[i]; - debug("scheduling call %d [%s] on thread %d\n", call_index, syscalls[call_num].name, th->id); + debug("scheduling call %d [%s] on thread %d\n", call_index, syscalls[call_num] + .name, + th->id); if (th->ready || !th->done || !th->handled) fail("bad thread state in schedule: ready=%d done=%d handled=%d", th->ready, th->done, th->handled); th->copyout_pos = pos; @@ -400,13 +401,17 @@ thread_t* schedule_call(int n, int call_index, int call_num, uint64_t num_args, void handle_completion(thread_t* th) { - debug("completion of call %d [%s] on thread %d\n", th->call_index, syscalls[th->call_num].name, th->id); + debug("completion of call %d [%s] on thread %d\n", th->call_index, syscalls[th->call_num] + .name, + th->id); if (th->ready || !th->done || th->handled) fail("bad thread state in completion: ready=%d done=%d handled=%d", th->ready, th->done, th->handled); if (th->res != (uint64_t)-1) { - results[th->call_n].executed = true; - results[th->call_n].val = th->res; + results[th->call_n] + .executed = true; + results[th->call_n] + .val = th->res; for (bool done = false; !done;) { th->call_n++; uint64_t call_num = read_input(&th->copyout_pos); @@ -415,8 +420,10 @@ void handle_completion(thread_t* th) char* addr = (char*)read_input(&th->copyout_pos); uint64_t size = read_input(&th->copyout_pos); uint64_t val = copyout(addr, size); - results[th->call_n].executed = true; - results[th->call_n].val = val; + results[th->call_n] + .executed = true; + results[th->call_n] + .val = val; debug("copyout from %p\n", addr); break; } @@ -493,8 +500,7 @@ void execute_call(thread_t* th) char buf[128]; sprintf(buf, "/dev/pts/%d", ptyno); th->res = open(buf, th->args[1], 0); - } - else { + } else { th->res = -1; } break; @@ -586,7 +592,8 @@ void cover_open() if (ioctl(th->cover_fd, KCOV_INIT_TRACE, kCoverSize)) fail("cover enable write failed"); th->cover_data = (uint32_t*)mmap(NULL, kCoverSize * sizeof(th->cover_data[0]), PROT_READ | PROT_WRITE, MAP_SHARED, th->cover_fd, 0); - if ((void*)th->cover_data == MAP_FAILED) + if ((void*)th + ->cover_data == MAP_FAILED) fail("cover mmap failed"); } } @@ -703,8 +710,10 @@ uint64_t read_result(uint64_t** input_posp) if (idx >= kMaxCommands) fail("command refers to bad result %ld", idx); uint64_t arg = default_value; - if (results[idx].executed) { - arg = results[idx].val; + if (results[idx] + .executed) { + arg = results[idx] + .val; if (op_div != 0) arg = arg / op_div; arg += op_add; @@ -736,7 +745,12 @@ uint64_t current_time_ms() timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) fail("clock_gettime failed"); - return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; + return (uint64_t)ts + .tv_sec * + 1000 + + (uint64_t)ts + .tv_nsec / + 1000000; } // logical error (e.g. invalid input program) diff --git a/executor/syscalls.h b/executor/syscalls.h index 555c65b2f..8a8c98c86 100644 --- a/executor/syscalls.h +++ b/executor/syscalls.h @@ -713,6 +713,92 @@ call_t syscalls[] = { {"setsockopt$SCTP_PEER_ADDR_THLDS", 54}, {"setsockopt$SCTP_RECVRCVINFO", 54}, {"setsockopt$SCTP_RECVNXTINFO", 54}, + {"open$kvm", 2}, + {"ioctl$KVM_CREATE_VM", 16}, + {"ioctl$KVM_GET_MSR_INDEX_LIST", 16}, + {"ioctl$KVM_CHECK_EXTENSION", 16}, + {"ioctl$KVM_GET_VCPU_MMAP_SIZE", 16}, + {"ioctl$KVM_GET_SUPPORTED_CPUID", 16}, + {"ioctl$KVM_GET_EMULATED_CPUID", 16}, + {"ioctl$KVM_CREATE_VCPU", 16}, + {"ioctl$KVM_CHECK_EXTENSION_VM", 16}, + {"ioctl$KVM_SET_MEMORY_REGION", 16}, + {"ioctl$KVM_GET_DIRTY_LOG", 16}, + {"ioctl$KVM_CREATE_IRQCHIP", 16}, + {"ioctl$KVM_IRQ_LINE", 16}, + {"ioctl$KVM_GET_IRQCHIP", 16}, + {"ioctl$KVM_SET_IRQCHIP", 16}, + {"ioctl$KVM_XEN_HVM_CONFIG", 16}, + {"ioctl$KVM_GET_CLOCK", 16}, + {"ioctl$KVM_SET_CLOCK", 16}, + {"ioctl$KVM_SET_USER_MEMORY_REGION", 16}, + {"ioctl$KVM_SET_TSS_ADDR", 16}, + {"ioctl$KVM_ENABLE_CAP", 16}, + {"ioctl$KVM_SET_IDENTITY_MAP_ADDR", 16}, + {"ioctl$KVM_SET_BOOT_CPU_ID", 16}, + {"ioctl$KVM_PPC_GET_PVINFO", 16}, + {"ioctl$KVM_ASSIGN_PCI_DEVICE", 16}, + {"ioctl$KVM_DEASSIGN_PCI_DEVICE", 16}, + {"ioctl$KVM_ASSIGN_DEV_IRQ", 16}, + {"ioctl$KVM_DEASSIGN_DEV_IRQ", 16}, + {"ioctl$KVM_SET_GSI_ROUTING", 16}, + {"ioctl$KVM_ASSIGN_SET_MSIX_NR", 16}, + {"ioctl$KVM_ASSIGN_SET_MSIX_ENTRY", 16}, + {"ioctl$KVM_IOEVENTFD", 16}, + {"ioctl$KVM_ASSIGN_SET_INTX_MASK", 16}, + {"ioctl$KVM_SIGNAL_MSI", 16}, + {"ioctl$KVM_CREATE_PIT2", 16}, + {"ioctl$KVM_GET_PIT2", 16}, + {"ioctl$KVM_SET_PIT2", 16}, + {"ioctl$KVM_PPC_GET_SMMU_INFO", 16}, + {"ioctl$KVM_IRQFD", 16}, + {"ioctl$KVM_PPC_ALLOCATE_HTAB", 16}, + {"ioctl$KVM_S390_INTERRUPT", 16}, + {"ioctl$KVM_CREATE_DEVICE", 16}, + {"ioctl$KVM_SET_DEVICE_ATTR", 16}, + {"ioctl$KVM_GET_DEVICE_ATTR", 16}, + {"ioctl$KVM_HAS_DEVICE_ATTR", 16}, + {"ioctl$KVM_RUN", 16}, + {"ioctl$KVM_GET_REGS", 16}, + {"ioctl$KVM_SET_REGS", 16}, + {"ioctl$KVM_GET_SREGS", 16}, + {"ioctl$KVM_SET_SREGS", 16}, + {"ioctl$KVM_TRANSLATE", 16}, + {"ioctl$KVM_INTERRUPT", 16}, + {"ioctl$KVM_GET_MSRS", 16}, + {"ioctl$KVM_SET_MSRS", 16}, + {"ioctl$KVM_SET_CPUID", 16}, + {"ioctl$KVM_SET_SIGNAL_MASK", 16}, + {"ioctl$KVM_GET_FPU", 16}, + {"ioctl$KVM_SET_FPU", 16}, + {"ioctl$KVM_GET_VCPU_EVENTS", 16}, + {"ioctl$KVM_SET_VCPU_EVENTS", 16}, + {"ioctl$KVM_GET_DEBUGREGS", 16}, + {"ioctl$KVM_SET_DEBUGREGS", 16}, + {"ioctl$KVM_ENABLE_CAP_CPU", 16}, + {"ioctl$KVM_GET_MP_STATE", 16}, + {"ioctl$KVM_SET_MP_STATE", 16}, + {"ioctl$KVM_GET_XSAVE", 16}, + {"ioctl$KVM_SET_XSAVE", 16}, + {"ioctl$KVM_GET_XCRS", 16}, + {"ioctl$KVM_SET_XCRS", 16}, + {"ioctl$KVM_SET_TSC_KHZ", 16}, + {"ioctl$KVM_GET_TSC_KHZ", 16}, + {"ioctl$KVM_GET_LAPIC", 16}, + {"ioctl$KVM_SET_LAPIC", 16}, + {"ioctl$KVM_DIRTY_TLB", 16}, + {"ioctl$KVM_NMI", 16}, + {"ioctl$KVM_S390_UCAS_MAP", 16}, + {"ioctl$KVM_S390_UCAS_UNMAP", 16}, + {"ioctl$KVM_S390_VCPU_FAULT", 16}, + {"ioctl$KVM_SET_ONE_REG", 16}, + {"ioctl$KVM_GET_ONE_REG", 16}, + {"ioctl$KVM_KVMCLOCK_CTRL", 16}, + {"ioctl$KVM_S390_INTERRUPT_CPU", 16}, + {"ioctl$KVM_GET_REG_LIST", 16}, + {"ioctl$KVM_SET_GUEST_DEBUG", 16}, + {"ioctl$KVM_SMI", 16}, + {"open$xenevtchn", 2}, }; #endif @@ -1418,6 +1504,92 @@ call_t syscalls[] = { {"setsockopt$SCTP_PEER_ADDR_THLDS", 208}, {"setsockopt$SCTP_RECVRCVINFO", 208}, {"setsockopt$SCTP_RECVNXTINFO", 208}, + {"open$kvm", -1}, + {"ioctl$KVM_CREATE_VM", 29}, + {"ioctl$KVM_GET_MSR_INDEX_LIST", 29}, + {"ioctl$KVM_CHECK_EXTENSION", 29}, + {"ioctl$KVM_GET_VCPU_MMAP_SIZE", 29}, + {"ioctl$KVM_GET_SUPPORTED_CPUID", 29}, + {"ioctl$KVM_GET_EMULATED_CPUID", 29}, + {"ioctl$KVM_CREATE_VCPU", 29}, + {"ioctl$KVM_CHECK_EXTENSION_VM", 29}, + {"ioctl$KVM_SET_MEMORY_REGION", 29}, + {"ioctl$KVM_GET_DIRTY_LOG", 29}, + {"ioctl$KVM_CREATE_IRQCHIP", 29}, + {"ioctl$KVM_IRQ_LINE", 29}, + {"ioctl$KVM_GET_IRQCHIP", 29}, + {"ioctl$KVM_SET_IRQCHIP", 29}, + {"ioctl$KVM_XEN_HVM_CONFIG", 29}, + {"ioctl$KVM_GET_CLOCK", 29}, + {"ioctl$KVM_SET_CLOCK", 29}, + {"ioctl$KVM_SET_USER_MEMORY_REGION", 29}, + {"ioctl$KVM_SET_TSS_ADDR", 29}, + {"ioctl$KVM_ENABLE_CAP", 29}, + {"ioctl$KVM_SET_IDENTITY_MAP_ADDR", 29}, + {"ioctl$KVM_SET_BOOT_CPU_ID", 29}, + {"ioctl$KVM_PPC_GET_PVINFO", 29}, + {"ioctl$KVM_ASSIGN_PCI_DEVICE", 29}, + {"ioctl$KVM_DEASSIGN_PCI_DEVICE", 29}, + {"ioctl$KVM_ASSIGN_DEV_IRQ", 29}, + {"ioctl$KVM_DEASSIGN_DEV_IRQ", 29}, + {"ioctl$KVM_SET_GSI_ROUTING", 29}, + {"ioctl$KVM_ASSIGN_SET_MSIX_NR", 29}, + {"ioctl$KVM_ASSIGN_SET_MSIX_ENTRY", 29}, + {"ioctl$KVM_IOEVENTFD", 29}, + {"ioctl$KVM_ASSIGN_SET_INTX_MASK", 29}, + {"ioctl$KVM_SIGNAL_MSI", 29}, + {"ioctl$KVM_CREATE_PIT2", 29}, + {"ioctl$KVM_GET_PIT2", 29}, + {"ioctl$KVM_SET_PIT2", 29}, + {"ioctl$KVM_PPC_GET_SMMU_INFO", 29}, + {"ioctl$KVM_IRQFD", 29}, + {"ioctl$KVM_PPC_ALLOCATE_HTAB", 29}, + {"ioctl$KVM_S390_INTERRUPT", 29}, + {"ioctl$KVM_CREATE_DEVICE", 29}, + {"ioctl$KVM_SET_DEVICE_ATTR", 29}, + {"ioctl$KVM_GET_DEVICE_ATTR", 29}, + {"ioctl$KVM_HAS_DEVICE_ATTR", 29}, + {"ioctl$KVM_RUN", 29}, + {"ioctl$KVM_GET_REGS", 29}, + {"ioctl$KVM_SET_REGS", 29}, + {"ioctl$KVM_GET_SREGS", 29}, + {"ioctl$KVM_SET_SREGS", 29}, + {"ioctl$KVM_TRANSLATE", 29}, + {"ioctl$KVM_INTERRUPT", 29}, + {"ioctl$KVM_GET_MSRS", 29}, + {"ioctl$KVM_SET_MSRS", 29}, + {"ioctl$KVM_SET_CPUID", 29}, + {"ioctl$KVM_SET_SIGNAL_MASK", 29}, + {"ioctl$KVM_GET_FPU", 29}, + {"ioctl$KVM_SET_FPU", 29}, + {"ioctl$KVM_GET_VCPU_EVENTS", 29}, + {"ioctl$KVM_SET_VCPU_EVENTS", 29}, + {"ioctl$KVM_GET_DEBUGREGS", 29}, + {"ioctl$KVM_SET_DEBUGREGS", 29}, + {"ioctl$KVM_ENABLE_CAP_CPU", 29}, + {"ioctl$KVM_GET_MP_STATE", 29}, + {"ioctl$KVM_SET_MP_STATE", 29}, + {"ioctl$KVM_GET_XSAVE", 29}, + {"ioctl$KVM_SET_XSAVE", 29}, + {"ioctl$KVM_GET_XCRS", 29}, + {"ioctl$KVM_SET_XCRS", 29}, + {"ioctl$KVM_SET_TSC_KHZ", 29}, + {"ioctl$KVM_GET_TSC_KHZ", 29}, + {"ioctl$KVM_GET_LAPIC", 29}, + {"ioctl$KVM_SET_LAPIC", 29}, + {"ioctl$KVM_DIRTY_TLB", 29}, + {"ioctl$KVM_NMI", 29}, + {"ioctl$KVM_S390_UCAS_MAP", 29}, + {"ioctl$KVM_S390_UCAS_UNMAP", 29}, + {"ioctl$KVM_S390_VCPU_FAULT", 29}, + {"ioctl$KVM_SET_ONE_REG", 29}, + {"ioctl$KVM_GET_ONE_REG", 29}, + {"ioctl$KVM_KVMCLOCK_CTRL", 29}, + {"ioctl$KVM_S390_INTERRUPT_CPU", 29}, + {"ioctl$KVM_GET_REG_LIST", 29}, + {"ioctl$KVM_SET_GUEST_DEBUG", 29}, + {"ioctl$KVM_SMI", 29}, + {"open$xenevtchn", -1}, }; #endif |
