-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add vhost-vdpa support (in-kernel) #33
Conversation
47c64b0
to
a4a3ea3
Compare
The tests fail because /dev/vhost-vdpa-0 doesn't exist and I should load the kernel modules. Where is the best place? In the test itself? |
@andreeaflorescu Is there anyway to load specific kernel modules on the CI machines? The vhost unit test cases have dependency on vhost-xxx/vdpa drivers. |
@jiangliu if we can't load kernel modules, maybe I can replace the tests without involving the vdpa simulator. But would be cool to use it. |
Can we do this in a reproducible way? The CI machines are started from a fresh image nightly, so it would be nice if this can be done via the CI. Is it enough to call a command before running the tests? Do we need a specific kernel? |
If you mean the kernel issue, it is now fixed and landed to stable kernels too.
Yep, we need at least Linux 5.7, but from Linux 5.11 the kernel module changed the name. So, from Linux 5.7 to Linux 5.10 we should do the following:
with Linux >= 5.11:
|
That's sad, the CI machine runs Linux 5.4:
It might take a while to upgrade to a newer Linux version because the machines are refreshed nightly, and we would need to recreate the images. I'll create an internal (AWS) ticket to upgrade the images. Is there something that we can do in the meantime to not block this PR? |
:-(
If you agree, I can simply skip the tests if |
@andreeaflorescu @jiangliu what do you think? We can also add some tests without involving the kernel module, but VhostKernVdpa mainly provides a wrapper around the IOCTLs, so I'm not sure they are useful. |
@stefano-garzarella I synced with @jiangliu on Slack and we decided the following:
Does that sound good? |
@andreeaflorescu yep, I agree on both :-) Thanks for the help! |
13c1c2f
to
12a74fc
Compare
@jiangliu @andreeaflorescu just pushed new changes:
CI fails with diff --git a/coverage_config_x86_64.json b/coverage_config_x86_64.json
index 2b2c164..3a95f1c 100644
--- a/coverage_config_x86_64.json
+++ b/coverage_config_x86_64.json
@@ -1 +1 @@
-{"coverage_score": 81.2, "exclude_path": "src/vhost_kern/", "crate_features": "vhost-user-master,vhost-user-slave"}
+{"coverage_score": 80.6, "exclude_path": "src/vhost_kern/", "crate_features": "vhost-user-master,vhost-user-slave"} |
Sure, it's ok to patch the coverage_cofnig_x86_64.json. |
@jiangliu thanks! done :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requires a rebase, but otherwise LGTM.
@slp thanks! The only conflict so far is the coverage. |
@stefano-garzarella If possible, please do a rebase. |
a25fea1
to
e668682
Compare
@jiangliu @andreeaflorescu Do you think it's okay now or do I need to make more changes? Thanks! :-) |
@stefano-garzarella we added vdpa support on the CI host, so now I think we can also add a specialized CI pipeline to run the tests you're adding. I can add a POC with how to add the specialized pipeline and we can work together to integrate it. How does that sound? |
@andreeaflorescu yeah!
It sounds great :-) feel free to reach me on rust-vmm slack workspace (user: sgarzare) to sync our works. |
2b98e23
to
69e7629
Compare
69e7629
to
37d94f6
Compare
VHOST_ACCESS_* and VHOST_IOTLB_* constants are assigned to c_uchar fields and VHOST_IOTLB_MSG to a c_int field. Let's set the proper types to avoid casts when assigning them. Signed-off-by: Stefano Garzarella <[email protected]>
These two new VHOST_IOTLB message types are supported by vhost-vdpa. Signed-off-by: Stefano Garzarella <[email protected]>
Add structs and tests for the C 'struct vhost_msg_v2' type supported by vhost-kern. Signed-off-by: Stefano Garzarella <[email protected]>
vhost-kern support these ioctls to set/get backend features related to IOTLB message support. Signed-off-by: Stefano Garzarella <[email protected]>
Add new VhostKernFeatures trait to handle the backend features supported by the backend and acked by the fronted. Signed-off-by: Stefano Garzarella <[email protected]>
This new VhostIotlbBackend trait will be implemented by the backends that support IOTLB messages. Add also VhostIotlbMsg struct and related enums to handle IOTLB messages properly. Signed-off-by: Stefano Garzarella <[email protected]>
Implement VhostIotlbBackend trait for vhost_kern handling both vhost_msg and vhost_msg_v2 messages according to acked backend features. Signed-off-by: Stefano Garzarella <[email protected]>
Add ioctls, structs, and test needed to support vhost-vdpa. Signed-off-by: Stefano Garzarella <[email protected]>
Add new VhostVdpa trait to handle vhost-vdpa devices and a new vhost-vdpa building feature. vhost-vdpa devices is based on vhost backend, for this reason VhostVdpa trait requires VhostBackend. Signed-off-by: Stefano Garzarella <[email protected]>
Add a vhost-vdpa in-kernel implementation of VhostVdpa trait. Tests are serialized since the device supports only a single user at a time. Signed-off-by: Stefano Garzarella <[email protected]>
Add dma_map/dma_unmap functions in VhostVdpa trait and implement them in VhostKernVdpa using the IOTLB messages support provided by VhostIotlbBackend. Add also a specific test in vhost_kern/vdpa.rs. Signed-off-by: Stefano Garzarella <[email protected]>
vDPA simulators are available since Linux 5.7. The CI may have an older kernel, so to avoid CI failures, for now we skip the tests if we don't find the device. Signed-off-by: Stefano Garzarella <[email protected]>
37d94f6
to
e41a1ca
Compare
CI failures are not related to this PR, but should be fixed after merging #69 |
/// # Arguments | ||
/// * `buffer` - Buffer containing the raw data received from the vhost-based backend. | ||
/// * `msg` - IOTLB message parsed. | ||
fn parse_iotlb_msg<T: Sized + VhostIotlbMsgParser>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems the parse_iotlb_msg() should be common for all vDPA backends, because it parses spec-defined messages. So should we implement it as a public function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it is common for all vhost_kern backends, indeed it's implemented in src/vhost_kern/mod.rs
.
Do you mean that can be common also for vhost_user backends, so better to implement here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel it's common for all vhost-kern drivers, so it should be implemented as an pub function at vhost-kern module, and no need to implement as a trait method.
Not sure whether it will be used by vhost-user drivers, especially vdpa-user servers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I get your point now. I'll fix it.
About vdpa-user, there is an ongoing effort for VDUSE, but it is still under development.
I asked to the author and they plan to publish also Rust API for it in rust-vmm, let's see :-)
use vmm_sys_util::ioctl::{ioctl_with_mut_ref, ioctl_with_ptr, ioctl_with_ref}; | ||
|
||
use std::alloc::{alloc, dealloc, Layout}; | ||
use std::mem; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Group all std dependencies together by moving it near to line 9?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I'll fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would also be great to give a simple introduction about vDPA as the module documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep sure, I'll add an introduction!
fn get_config(&self, offset: u32, buffer: &mut [u8]) -> Result<()> { | ||
let buffer_len = buffer.len(); | ||
let layout = | ||
Layout::from_size_align(mem::size_of::<vhost_vdpa_config>() + buffer_len, 1).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use vmm_sys_util::fam_struct here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh absolutely, I didn't know it. I'll give it a try,
This PR add the vhost-vdpa support (in-kernel).
Since it requires IOTLB message support for DMA map/unmap features, the first patches added that support to vhost-kern (VHOST_IOTLB, VHOST_BACKEND, vhost_msg_vs), let me know if you prefer a separated PR for that.
While writing the tests, I found an issue in the kernel. The patches are upstream 1 2 but not landed in stable kernels yet, so I left the vdpa.set_config_call() commented in the test to avoid kernel panics.
I tested with Linux v5.10 and I used vdpa_sim module (net device):
Then
/dev/vhost-vdpa-0
is available and you can run the tests.Signed-off-by: Stefano Garzarella [email protected]