KVM中ioeventfd創建與觸發的大致流程(十四)

在使用virtio-blk的情況時,virtio notify使用的ioeventfd機制,原因是爲了提高性能,能夠較快速的回到guest中運行。具體是如何建立這個ioeventfd的呢?流程理出來了,細節沒看:

1、在guest中,virtio-blk的初始化或者說是在探測virtio-blk之前

virtio_dev_probe
 |-->add_status
      |-->dev->config->set_status[vp_set_status]
           |-->iowrite8(status, vp_dev->ioaddr + VIRTIO_PCI_STATUS)

這裏就產生VM exit到Qemu中了,而在Qemu中有如下的處理:
2、Qemu中建立ioeventfd的處理流程:

virtio_pci_config_write
 |-->virtio_ioport_write
      |-->virtio_pci_start_ioeventfd
          |-->virtio_pci_set_host_notifier_internal
              |-->virtio_queue_set_host_notifier_fd_handler
              |-->memory_region_add_eventfd
                  |-->memory_region_transaction_commit
                      |-->address_space_update_ioeventfds
                          |-->address_space_add_del_ioeventfds
                              |-->eventfd_add[kvm_mem_ioeventfd_add]
                                  |-->kvm_set_ioeventfd_mmio
                                      |-->kvm_vm_ioctl(...,KVM_IOEVENTFD,...)

最後這一步就切換到kvm內核模塊中來通過KVM_IOEVENT來建立ioeventfd:
3、kvm內核模塊中建立ioeventfd:

kvm_ioeventfd
|-->kvm_assign_ioeventfd

在這個流程中爲某段區域建立了一個ioeventfd,這樣的話guest在操作這塊區域的時候就會觸發ioeventfd(這是fs的eventfd機制),從而通知到Qemu,Qemu的main loop原先是阻塞的,現在有ioevent發生之後就可以得到運行了,也就可以做對virtio-blk相應的處理了。

那麼當guest對該塊區域內存區域進行寫的時候,勢必會先exit到kvm內核模塊中,kvm內核模塊又是怎麼知道這塊區域是註冊了event的呢?是怎麼個流程呢?
只使用EPT的情況下,guest對一塊屬於MMIO的區域進行讀寫操作引起的exit在kvm中對應的處理函數是handle_ept_misconfig,下面就看下具體的流程:

handle_ept_misconfig
|-->x86_emulate_instruction
    |-->x86_emulate_insn
         |-->writeback
              |-->segmented_write
                  |-->write_emulated[emulator_write_emulated]
                       |-->emulator_read_write
                            |-->emulator_read_write_onepage
                                 |-->ops->read_write_mmio[write_mmio]
                                          |-->vcpu_mmio_write
                                               |-->kvm_io_bus_write
                                                   |-->__kvm_io_bus_write
                                                       |-->kvm_iodevice_write
                                                           |-->ops->write[ioeventfd_write]

在ioeventfd_write函數中會調用文件系統eventfd機制的eventfd_signal函數來觸發相應的事件。
上述就是整個ioeventfd從創建到觸發的流程!!!!

原文鏈接:https://blog.csdn.net/LPSTC123/article/details/45111949

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章