Skip to content
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

Merged
merged 13 commits into from
Sep 15, 2021
Merged

Conversation

stefano-garzarella
Copy link
Member

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):

modprobe vhost-vdpa
modprobe vdpa-sim   # vdpa-sim-net on Linux v5.11+

cargo test --features=vhost-kern,vhost-vdpa

Then /dev/vhost-vdpa-0 is available and you can run the tests.

Signed-off-by: Stefano Garzarella [email protected]

@stefano-garzarella
Copy link
Member Author

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?

@jiangliu
Copy link
Member

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.

@stefano-garzarella
Copy link
Member Author

@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.

@andreeaflorescu
Copy link
Member

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?

@stefano-garzarella
Copy link
Member Author

Can we do this in a reproducible way?

If you mean the kernel issue, it is now fixed and landed to stable kernels too.

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?

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:

modprobe vhost-vdpa
modprobe vdpa-sim

with Linux >= 5.11:

modprobe vhost-vdpa
modprobe vdpa-sim-net

@andreeaflorescu
Copy link
Member

That's sad, the CI machine runs Linux 5.4:

~$ uname -sr
Linux 5.4.0-1048-aws

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?

@stefano-garzarella
Copy link
Member Author

That's sad, the CI machine runs Linux 5.4:

:-(

~$ uname -sr
Linux 5.4.0-1048-aws

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 /dev/vhost-vdpa-0 is not found.

@stefano-garzarella
Copy link
Member Author

If you agree, I can simply skip the tests if /dev/vhost-vdpa-0 is not found.

@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.

@andreeaflorescu
Copy link
Member

@stefano-garzarella I synced with @jiangliu on Slack and we decided the following:

  • for now we skip the tests if /dev/vhost-vdpa-0 is not found (as you suggested)
  • we open an issue to track the update of the CI machine (I can do that)

Does that sound good?

@stefano-garzarella
Copy link
Member Author

@stefano-garzarella I synced with @jiangliu on Slack and we decided the following:

* for now we skip the tests if `/dev/vhost-vdpa-0` is not found (as you suggested)

* we open an issue to track the update of the CI machine (I can do that)

Does that sound good?

@andreeaflorescu yep, I agree on both :-)
I'll update this PR next week.

Thanks for the help!

@stefano-garzarella
Copy link
Member Author

@jiangliu @andreeaflorescu just pushed new changes:

  • uncommented the function that produced the kernel panic (vdpa.set_config_call) since the fixes are merged in all stable branches
  • skipped tests if /dev/vhost-vdpa-0 is not found (added a single commit for this, so we can revert it when we have a new kernel in the CI)

CI fails with AssertionError: Coverage drops by 0.60%., since the new traits are implemented only for vhost_kern can I patch coverage_config_x86_64.json in this way?

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"}

@jiangliu
Copy link
Member

@jiangliu @andreeaflorescu just pushed new changes:

  • uncommented the function that produced the kernel panic (vdpa.set_config_call) since the fixes are merged in all stable branches
  • skipped tests if /dev/vhost-vdpa-0 is not found (added a single commit for this, so we can revert it when we have a new kernel in the CI)

CI fails with AssertionError: Coverage drops by 0.60%., since the new traits are implemented only for vhost_kern can I patch coverage_config_x86_64.json in this way?

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.

@stefano-garzarella
Copy link
Member Author

@jiangliu thanks! done :-)

slp
slp previously approved these changes Jun 17, 2021
Copy link
Collaborator

@slp slp left a 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.

@stefano-garzarella
Copy link
Member Author

Requires a rebase, but otherwise LGTM.

@slp thanks!

The only conflict so far is the coverage.
Should I rebase or can it be fixed during the merge?

@slp
Copy link
Collaborator

slp commented Jun 17, 2021

Requires a rebase, but otherwise LGTM.

@slp thanks!

The only conflict so far is the coverage.
Should I rebase or can it be fixed during the merge?

@stefano-garzarella If possible, please do a rebase.

slp
slp previously approved these changes Jun 17, 2021
@stefano-garzarella
Copy link
Member Author

@jiangliu @andreeaflorescu Do you think it's okay now or do I need to make more changes?
If okay can we merge it?

Thanks! :-)

@andreeaflorescu
Copy link
Member

@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?

@stefano-garzarella
Copy link
Member Author

@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.

@andreeaflorescu yeah!

I can add a POC with how to add the specialized pipeline and we can work together to integrate it. How does that sound?

It sounds great :-) feel free to reach me on rust-vmm slack workspace (user: sgarzare) to sync our works.

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]>
@stefano-garzarella
Copy link
Member Author

CI failures are not related to this PR, but should be fixed after merging #69

@slp
Copy link
Collaborator

slp commented Sep 15, 2021

CI failures are not related to this PR, but should be fixed after merging #69

With #69, all tests pass.

/// # Arguments
/// * `buffer` - Buffer containing the raw data received from the vhost-based backend.
/// * `msg` - IOTLB message parsed.
fn parse_iotlb_msg<T: Sized + VhostIotlbMsgParser>(
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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;
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'll fix.

Copy link
Member

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.

Copy link
Member Author

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();
Copy link
Member

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?

Copy link
Member Author

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,

@jiangliu jiangliu merged commit 354dd56 into rust-vmm:main Sep 15, 2021
@stefano-garzarella
Copy link
Member Author

@jiangliu @slp thanks for merging!
I'll fix the remaining points in another PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants