当前位置:网站首页>Vhost kick & call principle
Vhost kick & call principle
2022-07-01 07:42:00 【yiyeguzhou100】
1. vhost vring Set up
VHOST_SET_VRING_KICK:
establish virtio Front end to vhost Back end notification mechanism ;
VHOST_SET_VRING_CALL:
establish vhost Back to virtio Front end notification mechanism ;
2. VHOST_SET_VRING_KICK principle
vhost The back-end driver uses , Such as vsock Registered packages kick function ,
vsock->vqs[VSOCK_VQ_TX].handle_kick = vhost_vsock_handle_tx_kick; // be used for host Receive package
vsock->vqs[VSOCK_VQ_RX].handle_kick = vhost_vsock_handle_rx_kick; // be used for host Contract awarding
The following steps explain evenfd And kick How to establish a connection between .
1) handle_kick Where did you register ?

VSOCK_VQ_RX = 0, /* for host to guest data */
VSOCK_VQ_TX = 1, /* for guest to host data */

vhost_poll_init call init_waitqueue_func_entry Set up (struct vhost_poll *) poll->wait.func = vhost_poll_wakeup; At the same time vhost_poll_func And poll table Make connections :(&poll->table) ->pt->_qproc = vhost_poll_func, Process below VHOST_SET_VRING_KICK when , call vhost_poll_start->vfs_poll->eventfd_poll->poll_wait when , Will execute pt->_qproc namely vhost_poll_func, This function will poll->work Added below as KICK Registered eventfd Waiting queue (ctx->wqh) in ,

vhost_poll_init->vhost_work_init, so handle_tick Registered to work->fn.

2) work->fn Where is it called ?
vhost_poll_wakeup -> "work->fn"( Namely vq Of handle_kick), but “work->fn” Only in vhost_dev No settings use_worker Will be called directly ,

If set use_worker( here vsock Just set up use_worker), Just call vhost_poll_queue Wake up worker, And then in worker Of handler In the implementation of work->fn(handle_kick),
vhost_poll_queue
vhost_work_queue
wake_up_process(dev->worker) // The corresponding vhost_dev Of work, Such as vsock->dev->worker
vhost_worker //worker handler
work->fn(work);Above worker Need to be in LKVM Call in ioctl VHOST_SET_OWNER Will be the corresponding vhost Driver creation worker.kernel vhost worker optimization commit: 01fcb1cbc
3) vhost_poll_wakeup When called ?
HOST received GUEST Of notify after (GUEST Write the correspondence virtio The equipment MMIO Spatial VIRTIO_MMIO_QUEUE_NOTIFY Field ),
from kvm_io_bus_write The function starts to determine whether the system is the virtio The equipment MMIO Spatial VIRTIO_MMIO_QUEUE_NOTIFY The address is registered eventfd, If you register, you can pass NOTIFY Address found registered evenfd, To get evenfd Corresponding struct eventfd_ctx *ctx structure ( Every eventfd The kernel corresponds to a eventfd_ctx structure ), And then get its waiting queue ctx->wqh, Get out of the queue work( In the above analysis vhost_poll_func Function has poll->work Has joined wqh It's in ) To perform its fn that will do (__wake_up_common To realize ),fn That is vhost_poll_wakeup, The complete call stack is as follows ,
vhost_work_queue
vhost_poll_wakeup
__wake_up_common
__wake_up_locked_key
eventfd_signal
ioeventfd_write
__kvm_io_bus_write
kvm_io_bus_write
kvm_{arch}_vcpu_exit
kvm_arch_vcpu_ioctl_run
kvm_vcpu_ioctl
sys_ioctl
ret_from_syscallIn the above steps ,vhost_poll_init call init_waitqueue_func_entry Set up poll->wait.func = vhost_poll_wakeup, So here vhost_poll_wakeup It is in the following logic that the call is triggered ,

4) LKVM How to register eventfd Of ?
- LKVM Side treatment
start-up GUEST Stage ,LKVM received guest Write MMIO Trigger settings QUEUE_PFN when , For the sake of QUEUE Corresponding to the device MMIO Spatial NITOFY Field settings eventfd,


- KERNEL Side treatment
vhost_vring_ioctl(VHOST_SET_VRING_KICK),


You know vq->kick As the corresponding eventfd Corresponding file, It can be seen from the above code , The eventfd file By ioctl adopt VHOST_SET_VRING_KICK Handed over .vhost_poll_start take eventfd Corresponding file Add to poll table In the middle ,

2. VHOST_SET_VRING_CALL principle
- LKVM Side treatment
gsi It's for irqfd Bound one guest Side interrupt number ,

- KERNEL Side treatment
1) Kernel processing KVM_IRQFD

kvm_irqfd->kvm_irqfd_assign Established inject And shutdown Two work, And set the processing function , Be responsible for reporting to guest Trigger injection interrupt and shutdown interrupt ,

At the same time kvm_irqfd_assign Function irqfd Waiting queue handler irqfd_wakeup;init_poll_funcptr Function will irqfd_ptable_queue_proc And irqfd Of poll table(irqfd->pt) binding ,

And then call vfs_poll(evenfd file Of poll The function is eventfd_poll),eventfd_poll Will call poll_wait(file, &ctx->wqh, wait) -> "p->_qproc(filp, &ctx->wqh, wait);", and _qproc It is registered above irqfd_ptable_queue_proc function , This function will call add_wait_queue(&ctx->wqh, &irqfd->wait) take irqfd->wait( namely wait_queue_entry_t) Add to evenfd Waiting queue wqh in , This is a crucial step . And the wait entry Registered func It is irqfd_wakeup, such irqfd and eventfd A two-way relationship is established .
At the same time, if you find that there are signals available now , Immediately call schedule_work, Scheduling execution irqfd->inject work, Execute interrupt injection ,

2) Kernel processing VHOST_SET_VRING_CALL
The kernel will be the same eventfd Set it to vq->call_ctx.ctx,

3) host towards guest Inject interrupt process
stay host Need to be informed guest Will call vhost_signal->eventfd_signal, The first parameter is the one set above evenfd Of ctx,

As with the introduction KICK The call stack is the same ,eventfd_signal Will finally execute evenfd ctx->wqh Queue work->fn, namely irqfd_wakeup, Execute... In this function schedule_work(&irqfd->inject) Used to inject interrupts .
Reference resources :
https://xzpeter.org/htmls/2017_12_07_kvm_irqfd/kvm_irqfd_implementation.html
The appended drawings :

KVM VHOST in irqfd Use - jack.chen - Blog Garden

边栏推荐
- 电脑有网络,但所有浏览器网页都打不开,是怎么回事?
- C language implementation [minesweeping game] full version (implementation source code)
- [Shenzhen IO] precise Food Scale (some understanding of assembly language)
- 组件的自定义事件②
- [MySQL learning notes27] stored procedure
- Jax's deep learning and scientific computing
- Detailed explanation of weback5 basic configuration
- 【mysql学习笔记26】视图
- 2022广东省安全员A证第三批(主要负责人)特种作业证考试题库模拟考试平台操作
- 【mysql学习笔记25】sql语句优化
猜你喜欢

LeetCode+ 71 - 75

微软宣布开源 (GODEL) 语言模型聊天机器人

Alibaba OSS postman invalid according to policy: policy condition failed: ["starts with", "key", "test/"]

如何制作专属的VS Code主题

ctfshow-web355,356(SSRF)

2022 mobile crane driver test exercises and online simulation test

Image style migration cyclegan principle

Conscience Amway universal wheel SolidWorks model material website

Software testing methods and techniques - overview of basic knowledge

【编程强训】删除公共字符(哈希映射)+组队竞赛(贪心)
随机推荐
The computer has a network, but all browser pages can't be opened. What's the matter?
PWN攻防世界int_overflow
继妹变继母,儿子与自己断绝关系,世界首富马斯克,为何这么惨?
【编程强训2】排序子序列+倒置字符串
赌上了绩效,赢了公司CTO,我要搭DevOps平台!
[programming compulsory training 3] find the longest consecutive number string in the string + the number that appears more than half of the times in the array
C# Newtonsoft. Use of job in JSON
如何制作专属的VS Code主题
2022 test questions and mock examinations for main principals of hazardous chemicals business units
[software] phantomjs screenshot
C language implementation [minesweeping game] full version (implementation source code)
Custom events of components ①
论文学习——水文时间序列相似性查询的分析与研究
2022 electrician (intermediate) recurrent training question bank and answers
[R language] two /n data merge functions
Minecraft 1.16.5 module development (51) tile entity
The database is locked. Is there a solution
【编程强训】删除公共字符(哈希映射)+组队竞赛(贪心)
How to create an exclusive vs Code theme
redisson使用全解——redisson官方文档+注释(中篇)