Skip to content

Commit

Permalink
fix(devices): device features
Browse files Browse the repository at this point in the history
Signed-off-by: João Peixoto <[email protected]>
  • Loading branch information
joaopeixoto13 committed Sep 19, 2024
1 parent 8d4e205 commit 5fa9019
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/virtio/src/block/virtio/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use event_manager::{
use std::borrow::{Borrow, BorrowMut};
use std::sync::{Arc, Mutex};
use virtio_bindings::virtio_blk::{VIRTIO_BLK_F_FLUSH, VIRTIO_BLK_F_RO};
use virtio_bindings::virtio_config::VIRTIO_F_IN_ORDER;
use virtio_blk::stdio_executor::StdIoBackend;
use virtio_device::{VirtioConfig, VirtioDeviceActions, VirtioDeviceType, VirtioMmioDevice};
use virtio_queue::Queue;
Expand Down Expand Up @@ -94,7 +95,7 @@ impl VirtioDeviceT for VirtioBlock {
}

fn device_features(config: &DeviceConfig) -> Result<u64> {
let mut features = 0;
let mut features = VIRTIO_F_IN_ORDER as u64;

// Set the read-only feature.
if config.read_only.unwrap() {
Expand Down
3 changes: 2 additions & 1 deletion src/virtio/src/console/virtio/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use event_manager::{
};
use std::borrow::{Borrow, BorrowMut};
use std::sync::{Arc, Mutex};
use virtio_bindings::virtio_config::VIRTIO_F_IN_ORDER;
use virtio_console::console::Console;
use virtio_device::{VirtioConfig, VirtioDeviceActions, VirtioDeviceType, VirtioMmioDevice};
use virtio_queue::Queue;
Expand Down Expand Up @@ -74,7 +75,7 @@ impl VirtioDeviceT for VirtioConsole {
}

fn device_features(_config: &DeviceConfig) -> Result<u64> {
Ok(0)
Ok(VIRTIO_F_IN_ORDER as u64)
}

fn config_space(_config: &DeviceConfig) -> Result<Vec<u8>> {
Expand Down
9 changes: 2 additions & 7 deletions src/virtio/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ use vm_device::device_manager::IoManager;
use vm_memory::{guest_memory::FileOffset, GuestAddress, MmapRegion};
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};

use virtio_bindings::virtio_config::{
VIRTIO_F_IN_ORDER, VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_VERSION_1,
};

/// This feature enables the used_event and the avail_event (Notification Suppression).
pub const VIRTIO_F_RING_EVENT_IDX: u32 = 29;
use virtio_bindings::virtio_config::{VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_VERSION_1};

/// Type alias for the subscriber.
pub type Subscriber = Arc<Mutex<dyn MutEventSubscriber + Send>>;
Expand Down Expand Up @@ -269,7 +264,7 @@ pub trait VirtioDeviceT {
.unwrap();

// Define the generic device features.
let device_features = 1 << VIRTIO_F_VERSION_1 | 1 << VIRTIO_F_IOMMU_PLATFORM | 1 << VIRTIO_F_IN_ORDER /*| 1 << VIRTIO_F_RING_EVENT_IDX*/;
let device_features = 1 << VIRTIO_F_VERSION_1 | 1 << VIRTIO_F_IOMMU_PLATFORM;

Ok((device_features, queues_converted))
}
Expand Down
10 changes: 6 additions & 4 deletions src/virtio/src/net/vhost/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,13 @@ impl VirtioDeviceActions for VhostNet {
// Set the current process as the owner of the file descriptor.
self.net.set_owner().unwrap();

// Get the device features.
let supported_backend_features = self.net.get_features().unwrap();

// Set the device features.
let features = self.net.get_features().unwrap();
println!("Get Features: {:x}", features);
println!("Set Features: {:x}", self.vhost.features());
self.net.set_features(self.vhost.features()).unwrap();
self.net
.set_features(self.vhost.features() & supported_backend_features)
.unwrap();

// Update the memory table.
self.net
Expand Down
7 changes: 6 additions & 1 deletion src/virtio/src/vsock/vhost/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,13 @@ impl VirtioDeviceActions for VhostVsockDevice {
// Set the current process as the owner of the file descriptor.
self.vsock.set_owner().unwrap();

// Get the device features.
let supported_backend_features = self.vsock.get_features().unwrap();

// Set the device features.
self.vsock.set_features(self.vhost.features()).unwrap();
self.vsock
.set_features(self.vhost.features() & supported_backend_features)
.unwrap();

// Update the memory table.
self.vsock
Expand Down

0 comments on commit 5fa9019

Please sign in to comment.