第二回KVM読書会

3,711 views
3,596 views

Published on

第二回KVM読書会のスライドです. Intel-VT と Linux KVM の概要についてまとめました.

0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,711
On SlideShare
0
From Embeds
0
Number of Embeds
14
Actions
Shares
0
Downloads
130
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide

第二回KVM読書会

  1. 1. KVM Tsuyoshi Ozawa @ Univ. of Tsukuba Twitter oza_x86 2009 8 30
  2. 2. 1. Intel-VT 2. KVM ( 2) 2009 8 30
  3. 3. Intel-VT 2009 8 30
  4. 4. 2009 8 30
  5. 5. Intel-VT 1. 2.VM CPU x86 2009 8 30
  6. 6. x86 ( ) Ring3 = User Mode Ring2 Ring1 (0 ) Ring0 OS Ring 0 Kernel Mode Ring3 OS 2009 8 30
  7. 7. 1. 2. 2009 8 30
  8. 8. Ring3 Ring0 Ring3 Ring2 Ring1 Ring0 Kernel Mode User Mode 2009 8 30
  9. 9. Ring3 Ring0 Ring3 Ring2 out Ring1 Ring0 Kernel Mode User Mode 2009 8 30
  10. 10. Ring3 Ring0 Ring3 Ring2 out Ring1 Ring0 Kernel Mode ( ) User Mode 2009 8 30
  11. 11. Ring3 Ring0 Ring3 = User Mode Ring2 out Ring1 Ring0 Kernel Mode 2009 8 30
  12. 12. VM CPU etc... 2009 8 30
  13. 13. VM Kernel Kernel Mode Mode CPU 2009 8 30
  14. 14. ? 2009 8 30
  15. 15. Xen VMWare Ring3 Ring2 Ring1 = Guest Kerel Ring0 HyperVisor OS 2009 8 30
  16. 16. Xen VMWare Ring 1 Ring 2 Ring 1 Kernel Kernel Mode Mode Hypervirsor on Guest kernel on CPU 2009 8 30
  17. 17. Intel-VT 2009 8 30
  18. 18. Intel-VT Kernel Kernel Mode Mode Hypervirsor on Guest kernel on CPU 2009 8 30
  19. 19. Intel-VT Guest OS Kernel Kernel Mode Mode Hypervirsor on Guest kernel on CPU 2009 8 30
  20. 20. Intel-VT CPU . Kernel Kernel Mode Mode Hypervirsor on Guest kernel on CPU 2009 8 30
  21. 21. Intel-VT VMX Root Mode Kernel Kernel Mode Mode Hypervirsor on Guest kernel on CPU 2009 8 30
  22. 22. VMX Root Mode VMXON Kernel . Mode A20 VT Hypervirsor on 2009 8 30
  23. 23. VMX Root Mode VMXOFF Kernel Mode VT . VT Hypervirsor on 2009 8 30
  24. 24. Intel-VT VMX non Root Mode Kernel Kernel Mode Mode Hypervirsor on Guest kernel on CPU 2009 8 30
  25. 25. Intel-VT VMX non Root Mode Kernel Kernel Mode Mode VMEntry Hypervirsor on Guest kernel on CPU 2009 8 30
  26. 26. VMEntry VMLAUNCH VMRESUME VMX non Root Mode 2009 8 30
  27. 27. Intel-VT VMExit Kernel Kernel Mode Mode Hypervirsor on Guest kernel on CPU 2009 8 30
  28. 28. VMExit VMMCALL + VMX non Root Mode 2009 8 30
  29. 29. • . RDTSC ( ) • VMCS 2009 8 30
  30. 30. VMCS Kernel Mode Memory VMCS Hypervirsor on 2009 8 30
  31. 31. VMCS Virtual Machine Control Structure 4KB 2009 8 30
  32. 32. VMCS •Virtual Machine Control Structure •4KB • VM etc... 2009 8 30
  33. 33. VMCS VMPTRST Current VMCS 2009 8 30
  34. 34. VMPTRST Kernel Mode Memory VMCS VMCS Hypervirsor on 2009 8 30
  35. 35. Current VMCS VMPTRLD Current VMCS 2009 8 30
  36. 36. VMPTRST Kernel Mode Memory VMCS Current VMCS Hypervirsor on 2009 8 30
  37. 37. VMCLEAR VMCS 2009 8 30
  38. 38. VMCLEAR Kernel Mode Memory VMCS Hypervirsor on 2009 8 30
  39. 39. VMCS VMREAD/VMWRITE 2009 8 30
  40. 40. VMWRITE Kernel Mode Memory VMCS Hypervirsor on 2009 8 30
  41. 41. VMREAD Kernel Mode Memory VMCS Hypervirsor on 2009 8 30
  42. 42. Intel ( ) 2009 8 30
  43. 43. KVM 2009 8 30
  44. 44. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  45. 45. 2009 8 30
  46. 46. VMX VMX NonRoot Root Mode Mode 2009 8 30
  47. 47. 2009 8 30
  48. 48. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  49. 49. VMX non Root Mode 2009 8 30
  50. 50. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  51. 51. User Qemu KVM Program Qemu Linux Guest KVM Kernel Kernel 2009 8 30
  52. 52. ./qemu -hda disk1.img (-hda ) 2009 8 30
  53. 53. User Qemu Program $ ./qemu -hda disk1 Linux Guest KVM Kernel Kernel 2009 8 30
  54. 54. User Qemu Program Qemu Linux Guest KVM Kernel Kernel 2009 8 30
  55. 55. Qemu 2009 8 30
  56. 56. User Qemu Program IOCTL Linux Guest KVM Kernel Kernel 2009 8 30
  57. 57. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  58. 58. 2009 8 30
  59. 59. User Qemu Program Linux Guest KVM VT Kernel Kernel 2009 8 30
  60. 60. VMX non Root Mode 2009 8 30
  61. 61. vmlaunch vmresume 2009 8 30
  62. 62. User Qemu Program vmlaunch / vmresume Linux Guest KVM Kernel Kernel 2009 8 30
  63. 63. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  64. 64. VMX non root Mode 2009 8 30
  65. 65. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  66. 66. 2009 8 30
  67. 67. VMX non Root Mode IO 2009 8 30
  68. 68. 2009 8 30
  69. 69. outb %ax 2009 8 30
  70. 70. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  71. 71. User Qemu Program Linux Guest KVM Kernel Kernel outb %ax 2009 8 30
  72. 72. VMX Root Mode 2009 8 30
  73. 73. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  74. 74. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  75. 75. 2009 8 30
  76. 76. Qemu 2009 8 30
  77. 77. User Qemu Program IOCTL return Linux Guest KVM Kernel Kernel 2009 8 30
  78. 78. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  79. 79. User Qemu Program io Linux Guest KVM Kernel Kernel 2009 8 30
  80. 80. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  81. 81. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  82. 82. 2009 8 30
  83. 83. IOCTL CPU 2009 8 30
  84. 84. User Qemu Program IOCTL Linux Guest KVM Kernel Kernel 2009 8 30
  85. 85. 2009 8 30
  86. 86. ... 2009 8 30
  87. 87. User Qemu Program IOCTL Linux Guest KVM Kernel Kernel vmlaunch vmresume 2009 8 30
  88. 88. 2009 8 30
  89. 89. 2009 8 30
  90. 90. outb %ax 2009 8 30
  91. 91. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  92. 92. User Qemu Program Linux Guest KVM Kernel Kernel outb %ax 2009 8 30
  93. 93. VMX non Root Mode IO 2009 8 30
  94. 94. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  95. 95. User Qemu Program Linux Guest KVM Kernel Kernel outb %ax 2009 8 30
  96. 96. 2009 8 30
  97. 97. "jne .Llaunched nt" __ex(ASM_VMX_VMLAUNCH) "nt" "jmp .Lkvm_vmx_return nt" ".Llaunched: " __ex(ASM_VMX_VMRESUME) "nt" ".Lkvm_vmx_return: " vmlaunch /* */ vmresume ... ... 2009 8 30
  98. 98. "jne .Llaunched nt" __ex(ASM_VMX_VMLAUNCH) "nt" "jmp .Lkvm_vmx_return nt" ".Llaunched: " __ex(ASM_VMX_VMRESUME) "nt" ".Lkvm_vmx_return: " /* */ ... 2009 8 30
  99. 99. 2009 8 30
  100. 100. 2009 8 30
  101. 101. out 2009 8 30
  102. 102. out in . 2009 8 30
  103. 103. Intel-VT 2009 8 30
  104. 104. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  105. 105. 2009 8 30
  106. 106. Qemu 2009 8 30
  107. 107. User Qemu Program IOCTL return Linux Guest KVM Kernel Kernel 2009 8 30
  108. 108. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  109. 109. int kvm_cpu_exec(){ ... 461 ret = kvm_vcpu_ioctl(env, KVM_RUN, 0); 478 switch (run->exit_reason) { 479 case KVM_EXIT_IO: 481 ret = kvm_handle_io(env, run->io.port, 482 (uint8_t *)run + run>io.data_offset, 483 run->io.direction, 484 run->io.size, 485 run->io.count); 486 break; case KVM_EXIT_MMIO: .... ... 2009 8 30
  110. 110. outb 2009 8 30
  111. 111. int kvm_cpu_exec(){ ... // 461 ret = kvm_vcpu_ioctl(env, KVM_RUN, 0); 478 switch (run->exit_reason) { 479 case KVM_EXIT_IO: 481 ret = kvm_handle_io(env, run->io.port, 482 (uint8_t *)run + run>io.data_offset, 483 run->io.direction, 484 run->io.size, 485 run->io.count); 486 break; case KVM_EXIT_MMIO: outb .... ... 2009 8 30
  112. 112. 2009 8 30
  113. 113. IO 2009 8 30
  114. 114. User Qemu Program io Linux Guest KVM Kernel Kernel 2009 8 30
  115. 115. 2009 8 30
  116. 116. out 2009 8 30
  117. 117. outb %al 2009 8 30
  118. 118. outb %al 2009 8 30
  119. 119. ( ) 2009 8 30
  120. 120. int kvm_cpu_exec(){ ... // 461 ret = kvm_vcpu_ioctl(env, KVM_RUN, 0); 478 switch (run->exit_reason) { 479 case KVM_EXIT_IO: 481 ret = kvm_handle_io(env, run->io.port, 482 (uint8_t *)run + run>io.data_offset, 483 run->io.direction, 484 run->io.size, 485 run->io.count); 486 break; case KVM_EXIT_MMIO: .... ... 2009 8 30
  121. 121. kvm_handle_io cpu_outb ioport_write 2009 8 30
  122. 122. static void ioport_write(int index, uint32_t address, uint32_t data) { static IOPortWriteFunc *default_func[3] = { default_ioport_writeb, default_ioport_writew, default_ioport_writel }; IOPortWriteFunc *func = ioport_write_table[index][address]; if (!func) func = default_func[index]; func(ioport_opaque[address], address, data); } ioport_write_table 2009 8 30
  123. 123. ( ) 2009 8 30
  124. 124. User Qemu Program io Linux Guest KVM Kernel Kernel 2009 8 30
  125. 125. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  126. 126. User Qemu Program Linux Guest KVM Kernel Kernel 2009 8 30
  127. 127. 2009 8 30
  128. 128. IOCTL CPU 2009 8 30
  129. 129. 2009 8 30
  130. 130. 378 static int kvm_main_loop_cpu(CPUState *env) 379 { 394 while (1) { 395 while (!has_work(env)) 396 kvm_main_loop_wait(env, 1000); 397 if (env->interrupt_request & (CPU_INTERRUPT_HARD | CPU_INTERRUPT_NMI)) 398 env->halted = 0; // . .... 404 } 405 if (!env->halted && !env->kvm_cpu_state.init) { 406 kvm_cpu_exec(env); // } } 413 } 2009 8 30
  131. 131. User Qemu Program IOCTL Linux Guest KVM Kernel Kernel 2009 8 30
  132. 132. 2009 8 30
  133. 133. ... 2009 8 30
  134. 134. User Qemu Program IOCTL Linux Guest KVM Kernel Kernel vmlaunch vmresume 2009 8 30
  135. 135. 2009 8 30
  136. 136. ? 2009 8 30

×