内存虚拟化,qemu这块需要理解pc_memory_init(在这里会调用kvm_region_add ---> kvm_set_user_memory_region)和memory_listener_register(这里只是注册)
先注册memory listener,然后如果其他设备添加了region,memory.c会回调这些listener,然后就kvm_set_phys_mem,走到kvm module中set slot了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | (gdb) bt #0 kvm_region_add (listener=0x555555c5efe0 <kvm_memory_listener>, section=0x7fffffffde60) at /home/pizhi/oschina/qemu/kvm-all .c:832 #1 0x000055555562219f in address_space_update_topology_pass ([email protected]=0x555555caae00 <address_space_memory>, [email protected]= true , new_view=<optimized out>, new_view=<optimized out>, old_view=0x555556995750, old_view=0x555556995750) at /home/pizhi/oschina/qemu/memory .c:790 #2 0x00005555556246c0 in address_space_update_topology (as=0x555555caae00 <address_space_memory>) at /home/pizhi/oschina/qemu/memory .c:805 #3 memory_region_transaction_commit () at /home/pizhi/oschina/qemu/memory.c:845 #4 0x000055555565debd in pc_cpus_init (cpu_model=0x55555587bd2d "qemu64", [email protected]=0x55555699b680) at /home/pizhi/oschina/qemu/hw/i386/pc .c:1159 #5 0x000055555565fb7d in pc_init1 (machine=0x5555569726c0, kvmclock_enabled=1, pci_enabled=1) at /home/pizhi/oschina/qemu/hw/i386/pc_piix .c:150 #6 0x00005555555e5de1 in main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at vl.c:4276 |