当前位置:网站首页>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# Newtonsoft.Json中JObject的使用

Redisson uses the full solution - redisson official document + comments (Part 2)

良心安利万向轮 SolidWorks模型素材网站

Custom events of components ②

AUTOSAR learning record (1) – ECUM_ Init

【目标检测】目标检测界的扛把子YOLOv5(原理详解+修炼指南)
![C language implementation [Sanzi chess game] (step analysis and implementation source code)](/img/3b/d32b46292ed20f31a6e1db97349df1.png)
C language implementation [Sanzi chess game] (step analysis and implementation source code)
![[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

The H5 page has set the font thickness style, but the wechat access style in Huawei mobile phone doesn't take effect?

奥迪AUDI EDI 项目中供应商需要了解哪些信息?
随机推荐
[MySQL learning notes 25] SQL statement optimization
[lingo] solve quadratic programming
PWN attack and defense world int_ overflow
[microservice openfeign] feign's log record
Eigen矩阵运算库快速上手
Custom events of components ②
Alibaba OSS postman invalid according to policy: policy condition failed: ["starts with", "key", "test/"]
Those high-frequency written tests and interview questions in [Jianzhi offer & Niuke 101] - linked list
Understanding of Turing test and Chinese Room
三极管是一项伟大的发明
Browser local storage
2022 mobile crane driver test exercises and online simulation test
C language implementation [minesweeping game] full version (implementation source code)
MATLAB之基础知识
redisson使用全解——redisson官方文檔+注釋(上篇)
PWN攻防世界int_overflow
base64
iNFTnews | 从《雪崩》到百度“希壤”,元宇宙30年的16件大事
Redisson uses the full solution - redisson official document + comments (Part 2)
论文学习——水文时间序列相似性查询的分析与研究