fix(virtq): only enable_notification when about to stop consumption#6649
fix(virtq): only enable_notification when about to stop consumption#6649ihciah wants to merge 1 commit intocloud-hypervisor:mainfrom
Conversation
Signed-off-by: ihciah <ihciah@gmail.com>
|
Thanks for investigating this - why not open an PR against https://github.com/rust-vmm/vm-virtio/ with your new API and then that can be consumed here. |
|
Thanks for advise. I'll try to put it in rust-vmm recently. |
hi @ihciah, the intention for
This seems a real issue, thanks for pointing out. |
Are you going to propose a fix? |
|
What's the status of this PR - it doesn't apply now. If this is still an issue please open an issue so we can track. |
Problem
Current usage for virtqueue is like:
However, it will bring not only more guest memory write and fence cost, but also more guest kick count.
According to
virtio-queue's doc ofenable_notification, it advises:The
enable_notificationneeds to be called if and only if we are about to stop consuming the queue.Solution
I tried to change the code as the style suggested above, but it makes code confusing because there are many exit branches in complicated functions.
However, the caller must consume the queue until empty or it guarentees there would be another event source triggers the consumption like timer fd. So it's a good idea to add a function like
pop_desc_chain_with_notification, when it returns None, it means the notification is enabled. And the caller won't have to worry about when and whether toenable_notification.Implementation
The
Queueis not defined by us. So the only way to extend it is to adding a extension trait and implement it.I didn't find a proper crate to put it in, so I added a new crate called virtio-ext and put the trait and impl in, and replaced nearly all
pop_descriptor_chainwithenable_notificationtopop_desc_chain_with_notification.Another Fix(maybe?) about block.rs
During the replacing, I found the
enable_notificationat L395 of block.rs is redundant because it does not consume any descriptor. And when handlingCOMPLETION_EVENT, if the rate_limiter not pass, there would be no notification to guest(for completions that already pushed into the queue). Since the code is related and small, I fixed(maybe?) it in the same commit. I can split it into another PR if needed.I'm not familiar with the block device, if I'm wrong please point it out.