当前位置:网站首页>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

边栏推荐
- Kickback -- find the first palindrome character in a group of characters
- Caesar
- 力扣——求一组字符中的第一个回文字符
- Ctfhub port scan (SSRF)
- Vscode automatically formats code according to eslint specification
- 继妹变继母,儿子与自己断绝关系,世界首富马斯克,为何这么惨?
- 2022 test question bank and simulation test of tea master (primary) operation certificate
- 良心安利万向轮 SolidWorks模型素材网站
- 在券商账户上买基金安全吗
- C# Newtonsoft.Json中JObject的使用
猜你喜欢

1286_FreeRTOS的任务优先级设置实现分析

Mysql与Redis一致性解决方案

Eigen矩阵运算库快速上手

2022广东省安全员A证第三批(主要负责人)特种作业证考试题库模拟考试平台操作

Understanding of Turing test and Chinese Room

Félicitations pour l'inscription réussie de wuxinghe

论文学习——水文时间序列相似性查询的分析与研究

Redisson uses the complete solution - redisson official documents + Notes (Part 1)
![[recommendation system] breakthrough and imagination of deep location interactive network dpin for meituan takeout recommendation scenario](/img/10/ed857892d2e0ea72e100a4008e6d69.png)
[recommendation system] breakthrough and imagination of deep location interactive network dpin for meituan takeout recommendation scenario

她就是那个「别人家的HR」|ONES 人物
随机推荐
力扣——求一组字符中的第一个回文字符
Jax's deep learning and scientific computing
[MySQL learning notes27] stored procedure
Redisson watchdog mechanism, redisson watchdog performance problems, redisson source code analysis
[MySQL learning notes 25] SQL statement optimization
2022危险化学品经营单位主要负责人试题及模拟考试
[MySQL learning notes 26] view
What information does the supplier need to know about Audi EDI project?
微软宣布开源 (GODEL) 语言模型聊天机器人
1286_FreeRTOS的任务优先级设置实现分析
Image style migration cyclegan principle
热烈祝贺五行和合酒成功挂牌
Is it safe and reliable for Huatai Securities to open an account? How to open Huatai Securities Account
redisson使用全解——redisson官方文檔+注釋(上篇)
MATLAB之基础知识
redisson使用全解——redisson官方文档+注释(中篇)
如何让两融交易更极速
Todolist classic case ①
We found a huge hole in MySQL: do not judge the number of rows affected by update!!!
LeetCode+ 71 - 75