martins3 / loongson-dune Goto Github PK
View Code? Open in Web Editor NEW:zap: Process virtualization based on KVM. More useable, stable and practical than Stanford Dune.
:zap: Process virtualization based on KVM. More useable, stable and practical than Stanford Dune.
printf 还是正常工作
getpid 有时候还是正常返回的
syscall 没有被调用
多次调用的结果不相同
如果在进入到 dune 之前进行函数调用,那么就是正确运行
为什么 gettimeofday 不是在 vdso 中间的 ?
测试 tlbrefill 的方法,分配 1 GB 的空间,然后全部访问一次
I don't know why the guest can't continue in the exception context, it has to be redirected to the next instruction of syscall.
calling a function which demands a huge stack will cause gup fail
void get_writesize(){
printf("get_writesize\n");
char read[4096];
printf("read : %p\n", read);
char buf[0x3d000];
printf("buf location %p", buf);
}
➜ test git:(main) ✗ sudo ./stack
Info: open /dev/kvm
Info: KVM_GET_API_VERSION
Info: KVM_CREATE_VM
Info: KVM_SET_USER_MEMORY_REGION
Info: ebase address : fff4310000
--- Process Map Dump ---
heee
after open
after fread
after setvbuf
0x000000012001c000-0xffffffffffffffff ---S ffffffffffffffff
0x0000000120028000-0x000000012002c000 RWXP 00018000 /home/loongson/dune/test/stack
0x00000001207c4000-0x00000001207c8000 ---P 00000000 [heap]
0x00000001207c8000-0x00000001207cc000 RWXP 00000000 [heap]
0x000000fff430c000-0x000000fff4314000 RWXP 00000000
0x000000fff4314000-0x000000fff431c000 RWXS 00000000 anon_inode:kvm-vcpu:0
0x000000fff431c000-0x000000fff4320000 RWXP 00000000
0x000000fffbac4000-0x000000fffbae8000 RWXP 00000000 [stack]
0x000000fffbff4000-0x000000fffbff8000 R-XP 00000000
0x000000fffe178000-0x000000fffe180000 R--P 00000000 [vvar]
0x000000fffe180000-0x000000fffe184000 R-XP 00000000 [vdso]
[256480.819242] kvm [3289]: huxueshi trace enter kvm_vz_vcpu_run:3584 cause=40008020
[256480.819250] kvm [3289]: kvm_mips_handle_exit: cause: 0x1080000c, PC: 120007804, kvm_run: 000000001af98063, kvm_vcpu: 0000000042c2abdb cause=40008020
[256480.819253] kvm [3289]: TLB ST fault: cause 0x1080000c, status 0x740000a0, PC: 00000000f229a1c2, BadVaddr: 0xfffbaa5650
[256480.819257] kvm [3289]: Failed to find VMA for hva 0xfffbaa4000
[256480.819260] kvm [3289]: update_pc(): New PC: 0x120007808
[256480.819263] kvm [3289]: [0x120007808] OP_SD: eaddr: 0xfffbaa5650, gpr: 0x120032610, data: 0x120032610
[256480.819267] kvm [3289]: kvm_mips_handle_exit : cause register = 40008020 exit_reason=6
[256480.819269] kvm [3289]: huxueshi trace leave kvm_vz_vcpu_run:3586 cause=40008020
Yes, it breaks out of the stack boundary, the stack size is 0x24000
因为 child 在创建出来虚拟机之前就会收到信号,在模拟的 fork 返回的位置,信号处理函数正确执行,之后模拟并没有这个信号的干扰。
kvm_vz_vcpu_run
instead of everytime vmexit
mapped
and unmapped
ept
and guest page tablehost_loop
just like another thread, so it works just like two threads run in parallel.hello world
We only care about the syscall, that's all!
if (current->flags & PF_VCPU)
kvm_vz_vcpu_save_wired(vcpu);
what should be inited and how?
currently, I just want to do a following how dune works:
[182208.357867] kvm [22087]: kvm_mips_handle_exit : cause register = 40008000 exit_reason=0
[182208.357926] kvm [22087]: kvm_mips_handle_exit: cause: 0x10804000, PC: 1200018c8, kvm_run: 00000000a3f95d25, kvm_vcpu: 000000001c3b428a cause=40008000
[182208.357931] kvm [22087]: [0]EXCCODE_INT @ 1200018c8
[182208.357934] kvm [22087]: kvm_mips_handle_exit : cause register = 40008000 exit_reason=0
[182208.361137] kvm [22087]: kvm_mips_handle_exit: cause: 0xd0808000, PC: 1200018d4, kvm_run: 00000000a3f95d25, kvm_vcpu: 000000001c3b428a cause=40008000
[182208.361139] kvm [22087]: [0]EXCCODE_INT @ 1200018d4
[182208.361142] kvm [22087]: kvm_mips_handle_exit : cause register = 40008000 exit_reason=0
[182208.365043] kvm [22087]: kvm_mips_handle_exit: cause: 0x50808000, PC: 1200018c8, kvm_run: 00000000a3f95d25, kvm_vcpu: 000000001c3b428a cause=40008000
[182208.365045] kvm [22087]: [0]EXCCODE_INT @ 1200018c8
[182208.365048] kvm [22087]: kvm_mips_handle_exit : cause register = 40008000 exit_reason=0
[182208.368950] kvm [22087]: kvm_mips_handle_exit: cause: 0x50808000, PC: 1200018c8, kvm_run: 00000000a3f95d25, kvm_vcpu: 000000001c3b428a cause=40008000
[182208.368952] kvm [22087]: [0]EXCCODE_INT @ 1200018c8
[182208.368957] kvm [22087]: kvm_mips_handle_exit : cause register = 40008000 exit_reason=0
[182208.371330] kvm [22087]: kvm_mips_handle_exit: cause: 0x10804000, PC: 1200018c8, kvm_run: 00000000a3f95d25, kvm_vcpu: 000000001c3b428a cause=40008000
[182208.371332] kvm [22087]: [0]EXCCODE_INT @ 1200018c8
cmdline="dune-fork09 "
contacts=""
analysis=exit
<<<test_output>>>
Info: open /dev/kvm
Info: KVM_GET_API_VERSION
Info: KVM_CREATE_VM
Info: KVM_SET_USER_MEMORY_REGION
Info: ebase address : fff6ea0000
fork09 0 TINFO : OPEN_MAX is 1024
fork09 0 TINFO : first file descriptor is 6
fork09 0 TINFO : Parent reporting 1023 files open
�[36m Error: unable to open /dev/kvm
�[0m�[36m Error: setup_vm_with_one_cpu
�[0m�[31m Fatal: dup_vm
�[0m Info: open /dev/kvm
Info: KVM_GET_API_VERSION
Info: KVM_CREATE_VM
Info: KVM_SET_USER_MEMORY_REGION
Info: ebase address : fff6ea0000
in /home/maritns3/core/loongson-dune/cross/arch/mips/kernel/scall64-64.S
EXPORT(sys_call_table)
PTR sys_read /* 5000 */
PTR sys_write
PTR sys_open
PTR sys_close
PTR sys_newstat
PTR sys_newfstat /* 5005 */
PTR sys_newlstat
PTR sys_poll
PTR sys_lseek
PTR sys_mips_mmap
PTR sys_mprotect /* 5010 */
PTR sys_munmap
PTR sys_brk
PTR sys_rt_sigaction
PTR sys_rt_sigprocmask
PTR sys_ioctl /* 5015 */
PTR sys_pread64
PTR sys_pwrite64
PTR sys_readv
PTR sys_writev
PTR sys_access /* 5020 */
PTR sysm_pipe
PTR sys_select
Everybody started with sys_
but pipe started with sysm_
/home/maritns3/core/musl/src/unistd/mips64/pipe.s
.set noreorder
.global pipe
.type pipe,@function
pipe:
lui $3, %hi(%neg(%gp_rel(pipe)))
daddiu $3, $3, %lo(%neg(%gp_rel(pipe)))
daddu $3, $3, $25
li $2, 5021
syscall
beq $7, $0, 1f
nop
ld $25, %got_disp(__syscall_ret)($3)
jr $25
dsubu $4, $0, $2
1: sw $2, 0($4)
sw $3, 4($4)
move $2, $0
jr $ra
nop
savereg.c
, we should use m
instead of r
, so we will not pollute the regsiterSometimes, it will crash.
.no at
#include <stdio.h>
int
main(void)
{
asm("jmp label");
puts("You should not see this.");
asm("label:");
return 0;
}
unsigned int x;
asm volatile ("move %0, $ra" : "=r" (x));
asm volatile ("sw $ra, %0" : "=m" (x));
The most tricky part is about CSR initialization, which we can refer to Stanford dune.
void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack)
{
unsigned long random_factor = 0UL;
if (current->flags & PF_RANDOMIZE)
random_factor = arch_mmap_rnd();
if (mmap_is_legacy(rlim_stack)) {
mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
mm->get_unmapped_area = arch_get_unmapped_area;
} else {
mm->mmap_base = mmap_base(random_factor, rlim_stack);
mm->get_unmapped_area = arch_get_unmapped_area_topdown;
}
}
Legacy or not makes a difference?
Although dune can't make the program which is a parameter of syscall exec run in a virtualization environment, making the program run correctly without too many limitations is always better.
tst_test.c:1313: TINFO: Timeout per run is 0h 05m 00s
Info: KVM_CREATE_VM
Info: KVM_CREATE_VCPU
prctl04.c:213: TINFO: kernel support PR_GET/SET_SECCOMP
Info: KVM_CREATE_VM
Info: KVM_CREATE_VCPU
prctl04.c:197: TPASS: SECCOMP_MODE_STRICT doesn't permit GET_SECCOMP call
Info: KVM_CREATE_VM
Info: KVM_CREATE_VCPU
prctl04.c:199: TFAIL: SECCOMP_MODE_STRICT doesn't permit read(2) write(2) and _exit(2)
Info: KVM_CREATE_VM
Info: KVM_CREATE_VCPU
prctl04.c:197: TPASS: SECCOMP_MODE_STRICT doesn't permit close(2)
Info: KVM_CREATE_VM
Info: KVM_CREATE_VCPU
prctl04.c:197: TPASS: SECCOMP_MODE_FILTER doestn't permit GET_SECCOMP call
Info: KVM_CREATE_VM
Info: KVM_CREATE_VCPU
prctl04.c:199: TFAIL: SECCOMP_MODE_FILTER doesn't permit close(2)
Info: KVM_CREATE_VM
Info: KVM_CREATE_VCPU
prctl04.c:197: TPASS: SECCOMP_MODE_FILTER doesn't permit exit()
Info: KVM_CREATE_VM
Info: KVM_CREATE_VCPU
prctl04.c:199: TFAIL: SECCOMP_MODE_FILTER doesn't permit exit()
pr_err("KVM_CREATE_VM");
的错误。Maybe we insert too many log for debugging.
Maybe we should set up a standard interface for developers to port to another system.
从 vcpu_load 的位置切换到 kvm_vz_vcpu_run 大大的减少了发生错误的情况,但是还是存在一些这种情况。
➜ mmap git:(master) sudo ./dune-mmap16
Info: top = fffb800000, limit = 800000
Info: open /dev/kvm
Info: KVM_GET_API_VERSION
Info: KVM_CREATE_VM
Info: KVM_SET_USER_MEMORY_REGION
Info: ebase address : fff6620000
mmap16 0 TINFO : Found free device 0 '/dev/loop0'
mmap16 0 TINFO : Formatting /dev/loop0 with ext4 opts='-b 1024' extra opts='10240'
mmap16 1 TBROK : mmap16.c:168: mkfs.ext4 failed with exit code 128
mmap16 2 TBROK : mmap16.c:168: Remaining cases broken
I expected it failed with "unsupported syscall", but didn't
syscalls-ipc is just subset of syscalls
dune-fork09
inotify09 is much more slowly than works
HYPCALL
instruction works, just GCC doesn't support it
It's used for debugging the fork syscall, there is no need to worry about it, but cpu_id is more critical.
There are many fail cases about mmap.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.