eventfd

virtio中,guest和vhost通过evnetfd通知对方,见(Virtio ring and virtio-net)。

REF:

Qemu-kvm的ioeventfd创建与触发的大致流程

virtio的eventfd机制浅析 ( ioctl(KVM_IOEVENTFD, struct kvm_ioeventfd)  )

QEMU下的EVENTFD机制及源代码分析 (huatong写的,还写了很多不错的文章

代码分析(Rng为例)

1. Rng的activate会启动一个thread,run RngEpollHandler

queue_evts 会通过activate 传给 RngEpollHandler

2. RngEpollHandler run, 实现了epool QUEUE_AVAIL_EVENT 和 KILL_EVENT, 进行处理。

queue处理完成后,还会通知signal_used_queue

3. write_bar的时候会 activate

4. rust-vmm/kvm-ioctls 的VmFd通过register_ioevent注册event

/// Registers an event to be signaled whenever a certain address is written to.
///
/// See the documentation for `KVM_IOEVENTFD`.

5.  ioeventfds 会遍历queue_evts

6. vm初始化,add_virtio_pci_deviceregister_ioevent

irqfd

VHOST通过irqfd通知guest。irqfd需要绑定一个eventfd.

rust-vmm/kvm-ioctls 的VmFd通过register_irqfd注册irqfd

REF:

KVM VHOST中irqfd的使用

关于Linux虚拟化技术KVM的科普 科普二(KVM虚拟机代码揭秘)  (一共写了5个科普)

KVM中断虚拟化主要依赖于VT-x技术,VT-x主要提供了两种中断事件机制,分别是中断退出>
和中断注入。

中断退出:指虚拟机发生中断时,主动式的客户机发生VM-Exit,这样能够在主机中实现对>
客户机中断的注入。

中断注入:是指将中断写入VMCS对应的中断信息位,来实现中断的注入,当中断完成后通过
读取中断的返回信息来分析中断是否正确。

中断注入的标志性函数kvm_set_irq,是中断注入的最开始。

Qemu-kvm模拟APIC Timer中断

qemu-kvm 中斷虛擬化代碼分析

qemu-kvm 中断虚拟化 (qemu-kvm 中断虚拟化)

KVM中断虚拟化浅析

kvm 中断以及io虚拟化

KVM 中断系统结构关系

qemu-kvm 中断虚拟化代码分析

代码分析(Rng为例子)

1. VirtioPciDevice 有个 interrupt_cb   field

2. assign_pin_irq 和 assign_msix用来设置interrupt_cb

assign_msix 注入中断 (msi_cb)(InterruptParameters { msix: Some(entry) })

// In case the vector control register associated with the entry
// has its first bit set, this means the vector is masked and the
// device should not inject the interrupt.
// Instead, the Pending Bit Array table is updated to reflect there
// is a pending interrupt for this specific vector.

3. vm初始化,add_virtio_pci_device是会 assign_pin_irq 和 assign_msix ,register_irqfd

4. msi_cb 和 irq_cb 的参数都是 InterruptParameters 类型,就是一个MsixTableEntry

signal_msi返回msi_cb

irq_cb会调用service_irq来注入中断

service_irq 调用rust-vmm/kvm-ioctls 的VmFd的signal_msi方法注入中断

5. MsixConfig 实现了 read_table 和 write_table

MsixConfig包括table_entries, pba_entries, interrupt_cb和masked字段。

write_table会调用inject_msix_and_clear_pba注入中断

5.1 write_config_register 也会调用 set_msg_ctl 注入中断

6.  VirtioPciDevice new的时候会new msix_config

7.  read_bar的时候会read_table, write_bar的时候会write_table

8. 对于VFIO来说,会设置中断路由, update_msi_interrupt_routes(调用了set_kvm_routes)

Interrupt.update_msi -> VfioMsix.update  -> set_msg_ctl -> inject_msix_and_clear_pba

vmm-sys-util

rust-vmm 的 vmm-sys-util 实现了很多utilities, 包括eventfd,ioctrl,poll,signal.

实现了eventfd的new, write, read, clone等基本操作。

https://github.com/rust-vmm/vmm-sys-util/tree/master/src

FYI:

PBA (Pending Bit Array)

MSI-HOWTO.txt

最新文章

  1. thinkphp分页
  2. mac android studio 编译时报Class JavaLaunchHelper is implemented in both
  3. [CareerCup] 1.6 Rotate Image 翻转图像
  4. 【JavsScript】一个元素绑定多个事件
  5. A*算法解决八数码问题 Java语言实现
  6. 伪造 UDP 包源 IP 地址
  7. POJ 1679:The Unique MST(次小生成树&&Kruskal)
  8. Directx11学习笔记【七】 游戏定时器的实现
  9. Django:之中间件、微信接口和单元测试
  10. MySQL XtraBackup备份脚本
  11. BZOJ2002(分块)
  12. linux 安装nginx 详解
  13. 好代码是管出来的——使用Jenkins搭建CI服务器
  14. iptables之语法
  15. Python 扫盲
  16. 通过动态SQL语句创建游标
  17. python 全栈开发,Day54(node.js初识)
  18. docker--从仓库下载镜像到推送自己的项目到仓库步骤详解
  19. sorted()排序详解
  20. Kindle一周使用感受

热门文章

  1. Java爬虫https网页内容报错SSLHandshakeException信任(忽略)所有SSL证书
  2. Visual Studio 2019 使用.Net Core 3.0 二
  3. Golang slice和map的申明和初始化
  4. Sqlmap注入工具
  5. Stack布局中定位的方式
  6. js中逻辑或的作用
  7. JavaWeb 之 EL表达式
  8. Android为TV端助力之弹出软键盘方式
  9. 利用chocolatey软件包管理工具安装yarn,比npm更快更稳定
  10. Java-最常用的Java日志框架整理