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 support for VHOST_USER_GPU_SET_SOCKET #239

Merged
merged 15 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .buildkite/rust-vmm-ci-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,63 +22,63 @@
},
{
"test_name": "unittests-gnu-all-with-xen",
"command": "cargo test --workspace --no-default-features --features test-utils,vhost-vsock,vhost-kern,vhost-vdpa,vhost-net,vhost-user,vhost-user-frontend,vhost-user-backend,xen",
"command": "cargo test --workspace --no-default-features --features test-utils,vhost-vsock,vhost-kern,vhost-vdpa,vhost-net,vhost-user,vhost-user-frontend,gpu-socket,vhost-user-backend,xen",
"platform": [
"x86_64",
"aarch64"
]
},
{
"test_name": "unittests-gnu-all-without-xen",
"command": "cargo test --workspace --no-default-features --features test-utils,vhost-vsock,vhost-kern,vhost-vdpa,vhost-net,vhost-user,vhost-user-frontend,vhost-user-backend,postcopy",
"command": "cargo test --workspace --no-default-features --features test-utils,vhost-vsock,vhost-kern,vhost-vdpa,vhost-net,vhost-user,vhost-user-frontend,gpu-socket,vhost-user-backend,postcopy",
"platform": [
"x86_64",
"aarch64"
]
},
{
"test_name": "unittests-musl-all-with-xen",
"command": "cargo test --workspace --target {target_platform}-unknown-linux-musl --no-default-features --features test-utils,vhost-vsock,vhost-kern,vhost-vdpa,vhost-net,vhost-user,vhost-user-frontend,vhost-user-backend,xen",
"command": "cargo test --workspace --target {target_platform}-unknown-linux-musl --no-default-features --features test-utils,vhost-vsock,vhost-kern,vhost-vdpa,vhost-net,vhost-user,vhost-user-frontend,gpu-socket,vhost-user-backend,xen",
"platform": [
"x86_64",
"aarch64"
]
},
{
"test_name": "unittests-musl-all-without-xen",
"command": "cargo test --workspace --target {target_platform}-unknown-linux-musl --no-default-features --features test-utils,vhost-vsock,vhost-kern,vhost-vdpa,vhost-net,vhost-user,vhost-user-frontend,vhost-user-backend,postcopy",
"command": "cargo test --workspace --target {target_platform}-unknown-linux-musl --no-default-features --features test-utils,vhost-vsock,vhost-kern,vhost-vdpa,vhost-net,vhost-user,vhost-user-frontend,gpu-socket,vhost-user-backend,postcopy",
"platform": [
"x86_64",
"aarch64"
]
},
{
"test_name": "clippy-all-with-xen",
"command": "cargo clippy --workspace --bins --examples --benches --all-targets --no-default-features --features test-utils,vhost-vsock,vhost-kern,vhost-vdpa,vhost-net,vhost-user,vhost-user-frontend,vhost-user-backend,xen -- -D warnings -D clippy::undocumented_unsafe_blocks",
"command": "cargo clippy --workspace --bins --examples --benches --all-targets --no-default-features --features test-utils,vhost-vsock,vhost-kern,vhost-vdpa,vhost-net,vhost-user,vhost-user-frontend,gpu-socket,vhost-user-backend,xen -- -D warnings -D clippy::undocumented_unsafe_blocks",
"platform": [
"x86_64",
"aarch64"
]
},
{
"test_name": "clippy-all-without-xen",
"command": "cargo clippy --workspace --bins --examples --benches --all-targets --no-default-features --features test-utils,vhost-vsock,vhost-kern,vhost-vdpa,vhost-net,vhost-user,vhost-user-frontend,vhost-user-backend,postcopy -- -D warnings -D clippy::undocumented_unsafe_blocks",
"command": "cargo clippy --workspace --bins --examples --benches --all-targets --no-default-features --features test-utils,vhost-vsock,vhost-kern,vhost-vdpa,vhost-net,vhost-user,vhost-user-frontend,gpu-socket,vhost-user-backend,postcopy -- -D warnings -D clippy::undocumented_unsafe_blocks",
"platform": [
"x86_64",
"aarch64"
]
},
{
"test_name": "check-warnings-all-with-xen",
"command": "RUSTFLAGS=\"-D warnings\" cargo check --all-targets --workspace --no-default-features --features test-utils,vhost-vsock,vhost-kern,vhost-vdpa,vhost-net,vhost-user,vhost-user-frontend,vhost-user-backend,xen",
"command": "RUSTFLAGS=\"-D warnings\" cargo check --all-targets --workspace --no-default-features --features test-utils,vhost-vsock,vhost-kern,vhost-vdpa,vhost-net,vhost-user,vhost-user-frontend,gpu-socket,vhost-user-backend,xen",
"platform": [
"x86_64",
"aarch64"
]
},
{
"test_name": "check-warnings-all-without-xen",
"command": "RUSTFLAGS=\"-D warnings\" cargo check --all-targets --workspace --no-default-features --features test-utils,vhost-vsock,vhost-kern,vhost-vdpa,vhost-net,vhost-user,vhost-user-frontend,vhost-user-backend,postcopy",
"command": "RUSTFLAGS=\"-D warnings\" cargo check --all-targets --workspace --no-default-features --features test-utils,vhost-vsock,vhost-kern,vhost-vdpa,vhost-net,vhost-user,vhost-user-frontend,gpu-socket,vhost-user-backend,postcopy",
"platform": [
"x86_64",
"aarch64"
Expand Down
1 change: 1 addition & 0 deletions vhost-user-backend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

### Added
- [[#241]](https://github.com/rust-vmm/vhost/pull/241) Add shared objects support
- [[#239]](https://github.com/rust-vmm/vhost/pull/239) Add support for `VHOST_USER_GPU_SET_SOCKET`

### Changed
- [[#240]](https://github.com/rust-vmm/vhost/pull/240) Move the set of event_idx property from set_vring_base callback to set_features one
Expand Down
1 change: 1 addition & 0 deletions vhost-user-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ license = "Apache-2.0"
[features]
xen = ["vm-memory/xen", "vhost/xen"]
postcopy = ["vhost/postcopy", "userfaultfd"]
gpu-socket = ["vhost/gpu-socket"]

[dependencies]
libc = "0.2.39"
Expand Down
37 changes: 37 additions & 0 deletions vhost-user-backend/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ use vm_memory::bitmap::Bitmap;
use vmm_sys_util::epoll::EventSet;
use vmm_sys_util::eventfd::EventFd;

#[cfg(feature = "gpu-socket")]
use vhost::vhost_user::GpuBackend;

use super::vring::VringT;
use super::GM;

Expand Down Expand Up @@ -84,6 +87,14 @@ pub trait VhostUserBackend: Send + Sync {
/// function.
fn set_backend_req_fd(&self, _backend: Backend) {}

#[cfg(feature = "gpu-socket")]
/// Set handler for communicating with the frontend by the gpu specific backend communication
/// channel.
///
/// This method only exits when the crate feature gpu-socket is enabled, because this is only
/// useful for a gpu device.
fn set_gpu_socket(&self, _gpu_backend: GpuBackend);

/// Get the map to map queue index to worker thread index.
///
/// A return value of [2, 2, 4] means: the first two queues will be handled by worker thread 0,
Expand Down Expand Up @@ -194,6 +205,14 @@ pub trait VhostUserBackendMut: Send + Sync {
/// function.
fn set_backend_req_fd(&mut self, _backend: Backend) {}

#[cfg(feature = "gpu-socket")]
/// Set handler for communicating with the frontend by the gpu specific backend communication
/// channel.
///
/// This method only exits when the crate feature gpu-socket is enabled, because this is only
/// useful for a gpu device.
fn set_gpu_socket(&mut self, gpu_backend: GpuBackend);

/// Get the map to map queue index to worker thread index.
///
/// A return value of [2, 2, 4] means: the first two queues will be handled by worker thread 0,
Expand Down Expand Up @@ -299,6 +318,11 @@ impl<T: VhostUserBackend> VhostUserBackend for Arc<T> {
self.deref().set_backend_req_fd(backend)
}

#[cfg(feature = "gpu-socket")]
fn set_gpu_socket(&self, gpu_backend: GpuBackend) {
self.deref().set_gpu_socket(gpu_backend)
}

fn queues_per_thread(&self) -> Vec<u64> {
self.deref().queues_per_thread()
}
Expand Down Expand Up @@ -376,6 +400,11 @@ impl<T: VhostUserBackendMut> VhostUserBackend for Mutex<T> {
self.lock().unwrap().set_backend_req_fd(backend)
}

#[cfg(feature = "gpu-socket")]
fn set_gpu_socket(&self, gpu_backend: GpuBackend) {
self.lock().unwrap().set_gpu_socket(gpu_backend)
}

fn queues_per_thread(&self) -> Vec<u64> {
self.lock().unwrap().queues_per_thread()
}
Expand Down Expand Up @@ -456,6 +485,11 @@ impl<T: VhostUserBackendMut> VhostUserBackend for RwLock<T> {
self.write().unwrap().set_backend_req_fd(backend)
}

#[cfg(feature = "gpu-socket")]
fn set_gpu_socket(&self, gpu_backend: GpuBackend) {
self.write().unwrap().set_gpu_socket(gpu_backend)
}

fn queues_per_thread(&self) -> Vec<u64> {
self.read().unwrap().queues_per_thread()
}
Expand Down Expand Up @@ -576,6 +610,9 @@ pub mod tests {

fn set_backend_req_fd(&mut self, _backend: Backend) {}

#[cfg(feature = "gpu-socket")]
fn set_gpu_socket(&mut self, _gpu_backend: GpuBackend) {}

fn queues_per_thread(&self) -> Vec<u64> {
vec![1, 1]
}
Expand Down
8 changes: 8 additions & 0 deletions vhost-user-backend/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ use vhost::vhost_user::message::{
VhostUserMemoryRegion, VhostUserProtocolFeatures, VhostUserSingleMemoryRegion,
VhostUserVirtioFeatures, VhostUserVringAddrFlags, VhostUserVringState,
};
#[cfg(feature = "gpu-socket")]
use vhost::vhost_user::GpuBackend;
use vhost::vhost_user::{
Backend, Error as VhostUserError, Result as VhostUserResult, VhostUserBackendReqHandlerMut,
};

use virtio_bindings::bindings::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
use virtio_queue::{Error as VirtQueError, QueueT};
use vm_memory::mmap::NewBitmap;
Expand Down Expand Up @@ -552,6 +555,11 @@ where
self.backend.set_backend_req_fd(backend);
}

#[cfg(feature = "gpu-socket")]
fn set_gpu_socket(&mut self, gpu_backend: GpuBackend) {
self.backend.set_gpu_socket(gpu_backend);
}

fn get_inflight_fd(
&mut self,
_inflight: &vhost::vhost_user::message::VhostUserInflight,
Expand Down
5 changes: 5 additions & 0 deletions vhost-user-backend/tests/vhost-user-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use std::thread;
use vhost::vhost_user::message::{
VhostUserConfigFlags, VhostUserHeaderFlag, VhostUserInflight, VhostUserProtocolFeatures,
};
#[cfg(feature = "gpu-socket")]
use vhost::vhost_user::GpuBackend;
use vhost::vhost_user::{Backend, Frontend, Listener, VhostUserFrontend};
use vhost::{VhostBackend, VhostUserMemoryRegionInfo, VringConfigData};
use vhost_user_backend::{VhostUserBackendMut, VhostUserDaemon, VringRwLock};
Expand Down Expand Up @@ -77,6 +79,9 @@ impl VhostUserBackendMut for MockVhostBackend {
Ok(())
}

#[cfg(feature = "gpu-socket")]
fn set_gpu_socket(&mut self, _gpu_backend: GpuBackend) {}

fn update_memory(&mut self, atomic_mem: GuestMemoryAtomic<GuestMemoryMmap>) -> Result<()> {
let mem = atomic_mem.memory();
let region = mem.find_region(GuestAddress(0x100000)).unwrap();
Expand Down
1 change: 1 addition & 0 deletions vhost/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

### Added
- [[#241]](https://github.com/rust-vmm/vhost/pull/241) Add shared objects support
- [[#239]](https://github.com/rust-vmm/vhost/pull/239) Add support for `VHOST_USER_GPU_SET_SOCKET`

### Changed
- [[#243]](https://github.com/rust-vmm/vhost/pull/243) Ignore unknown bits in `VHOST_USER_GET_PROTOCOL_FEATURES` response.
Expand Down
1 change: 1 addition & 0 deletions vhost/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ vhost-net = ["vhost-kern"]
vhost-user = []
vhost-user-frontend = ["vhost-user"]
vhost-user-backend = ["vhost-user"]
gpu-socket = ["vhost-user"]
xen = ["vm-memory/xen"]
postcopy = []

Expand Down
2 changes: 1 addition & 1 deletion vhost/src/vhost_user/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<S: VhostUserBackendReqHandler> BackendListener<S> {
pub fn accept(&mut self) -> Result<Option<BackendReqHandler<S>>> {
if let Some(fd) = self.listener.accept()? {
return Ok(Some(BackendReqHandler::new(
Endpoint::<FrontendReq>::from_stream(fd),
Endpoint::<VhostUserMsgHeader<FrontendReq>>::from_stream(fd),
self.backend.take().unwrap(),
)));
}
Expand Down
10 changes: 6 additions & 4 deletions vhost/src/vhost_user/backend_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::{Error, HandlerResult, Result, VhostUserFrontendReqHandler};
use vm_memory::ByteValued;

struct BackendInternal {
sock: Endpoint<BackendReq>,
sock: Endpoint<VhostUserMsgHeader<BackendReq>>,

// Protocol feature VHOST_USER_PROTOCOL_F_REPLY_ACK has been negotiated.
reply_ack_negotiated: bool,
Expand Down Expand Up @@ -86,7 +86,7 @@ pub struct Backend {
}

impl Backend {
fn new(ep: Endpoint<BackendReq>) -> Self {
fn new(ep: Endpoint<VhostUserMsgHeader<BackendReq>>) -> Self {
Backend {
node: Arc::new(Mutex::new(BackendInternal {
sock: ep,
Expand Down Expand Up @@ -114,7 +114,9 @@ impl Backend {

/// Create a new instance from a `UnixStream` object.
pub fn from_stream(sock: UnixStream) -> Self {
Self::new(Endpoint::<BackendReq>::from_stream(sock))
Self::new(Endpoint::<VhostUserMsgHeader<BackendReq>>::from_stream(
sock,
))
}

/// Set the negotiation state of the `VHOST_USER_PROTOCOL_F_REPLY_ACK` protocol feature.
Expand Down Expand Up @@ -218,7 +220,7 @@ mod tests {
fn test_backend_req_recv_negative() {
let (p1, p2) = UnixStream::pair().unwrap();
let backend = Backend::from_stream(p1);
let mut frontend = Endpoint::<BackendReq>::from_stream(p2);
let mut frontend = Endpoint::<VhostUserMsgHeader<BackendReq>>::from_stream(p2);

let len = mem::size_of::<VhostUserSharedMsg>();
let mut hdr = VhostUserMsgHeader::new(
Expand Down
Loading