From c2adfae1b1573db298426920d55d8da9f34d8c22 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 6 Aug 2024 15:41:34 +0200 Subject: [PATCH] revise vsock driver to support the new virtio interface --- src/drivers/net/gem.rs | 14 +- src/drivers/net/rtl8139.rs | 11 +- src/drivers/net/virtio/mod.rs | 1 - src/drivers/virtio/transport/mmio.rs | 10 +- src/drivers/virtio/transport/mod.rs | 25 +- src/drivers/vsock/mod.rs | 369 ++++++++++----------------- src/drivers/vsock/pci.rs | 2 +- src/executor/vsock.rs | 6 +- 8 files changed, 182 insertions(+), 256 deletions(-) diff --git a/src/drivers/net/gem.rs b/src/drivers/net/gem.rs index 19ab8486fc..f2060230e4 100644 --- a/src/drivers/net/gem.rs +++ b/src/drivers/net/gem.rs @@ -16,10 +16,14 @@ use tock_registers::{register_bitfields, register_structs}; use crate::arch::kernel::core_local::core_scheduler; use crate::arch::kernel::interrupts::*; +#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "pci")))] +use crate::arch::kernel::mmio as hardware; use crate::arch::mm::paging::virt_to_phys; use crate::arch::mm::VirtAddr; use crate::drivers::error::DriverError; use crate::drivers::net::NetworkDriver; +#[cfg(all(any(feature = "tcp", feature = "udp"), feature = "pci"))] +use crate::drivers::pci as hardware; use crate::executor::device::{RxToken, TxToken}; //Base address of the control registers @@ -202,14 +206,14 @@ fn gem_irqhandler() { debug!("Receive network interrupt"); - crate::executor::run(); - // PLIC end of interrupt crate::arch::kernel::interrupts::external_eoi(); if let Some(driver) = hardware::get_network_driver() { driver.lock().handle_interrupt() } + crate::executor::run(); + core_scheduler().reschedule(); } @@ -365,7 +369,7 @@ impl NetworkDriver for GEMDriver { } } - fn handle_interrupt(&mut self) -> bool { + fn handle_interrupt(&mut self) { let int_status = unsafe { (*self.gem).int_status.extract() }; let receive_status = unsafe { (*self.gem).receive_status.extract() }; @@ -409,8 +413,8 @@ impl NetworkDriver for GEMDriver { // handle incoming packets todo!(); } - // increment_irq_counter((32 + self.irq).into()); - ret + + //increment_irq_counter((32 + self.irq).into()); } } diff --git a/src/drivers/net/rtl8139.rs b/src/drivers/net/rtl8139.rs index c48637b494..dddedce8e8 100644 --- a/src/drivers/net/rtl8139.rs +++ b/src/drivers/net/rtl8139.rs @@ -17,6 +17,7 @@ use crate::arch::mm::VirtAddr; use crate::arch::pci::PciConfigRegion; use crate::drivers::error::DriverError; use crate::drivers::net::NetworkDriver; +use crate::drivers::pci as hardware; use crate::drivers::pci::PciDevice; use crate::executor::device::{RxToken, TxToken}; @@ -319,7 +320,7 @@ impl NetworkDriver for RTL8139Driver { } } - fn handle_interrupt(&mut self) -> bool { + fn handle_interrupt(&mut self) { increment_irq_counter(32 + self.irq); let isr_contents = unsafe { inw(self.iobase + ISR) }; @@ -340,18 +341,12 @@ impl NetworkDriver for RTL8139Driver { trace!("RTL88139: RX overflow detected!\n"); } - let ret = (isr_contents & ISR_ROK) == ISR_ROK; - - crate::executor::run(); - unsafe { outw( self.iobase + ISR, isr_contents & (ISR_RXOVW | ISR_TER | ISR_RER | ISR_TOK | ISR_ROK), ); } - - ret } } @@ -436,6 +431,8 @@ extern "x86-interrupt" fn rtl8139_irqhandler(stack_frame: ExceptionStackFrame) { debug!("Unable to handle interrupt!"); } + crate::executor::run(); + core_scheduler().reschedule(); crate::arch::x86_64::swapgs(&stack_frame); } diff --git a/src/drivers/net/virtio/mod.rs b/src/drivers/net/virtio/mod.rs index 6dbbcff019..ca88d50681 100644 --- a/src/drivers/net/virtio/mod.rs +++ b/src/drivers/net/virtio/mod.rs @@ -14,7 +14,6 @@ use alloc::boxed::Box; use alloc::vec::Vec; use core::mem::MaybeUninit; -use align_address::Align; use smoltcp::phy::{Checksum, ChecksumCapabilities}; use smoltcp::wire::{EthernetFrame, Ipv4Packet, Ipv6Packet, ETHERNET_HEADER_LEN}; use virtio::net::{ConfigVolatileFieldAccess, Hdr, HdrF}; diff --git a/src/drivers/virtio/transport/mmio.rs b/src/drivers/virtio/transport/mmio.rs index ce29e3bf1d..cf8b7f3114 100644 --- a/src/drivers/virtio/transport/mmio.rs +++ b/src/drivers/virtio/transport/mmio.rs @@ -381,13 +381,16 @@ pub(crate) fn init_device( match registers.as_ptr().device_id().read() { #[cfg(any(feature = "tcp", feature = "udp"))] virtio::Id::Net => { - match VirtioNetDriver::init(dev_id, registers, irq_no) { + match VirtioNetDriver::init(dev_id, registers) { Ok(virt_net_drv) => { + use crate::drivers::virtio::transport::VIRTIO_IRQ; + info!("Virtio network driver initialized."); // Install interrupt handler irq_install_handler(irq_no, virtio_irqhandler); #[cfg(not(target_arch = "riscv64"))] add_irq_name(irq_no, "virtio"); + let _ = VIRTIO_IRQ.try_insert(irq_no); Ok(VirtioDriver::Network(virt_net_drv)) } @@ -399,13 +402,16 @@ pub(crate) fn init_device( } #[cfg(feature = "vsock")] virtio::Id::Vsock => { - match VirtioVsockDriver::init(dev_id, registers, irq_no) { + match VirtioVsockDriver::init(dev_id, registers) { Ok(virt_net_drv) => { + use crate::drivers::virtio::transport::VIRTIO_IRQ; + info!("Virtio sock driver initialized."); // Install interrupt handler irq_install_handler(irq_no, virtio_irqhandler); #[cfg(not(target_arch = "riscv64"))] add_irq_name(irq_no, "virtio"); + let _ = VIRTIO_IRQ.try_insert(irq_no); Ok(VirtioDriver::Vsock(virt_vsock_drv)) } diff --git a/src/drivers/virtio/transport/mod.rs b/src/drivers/virtio/transport/mod.rs index 8484037400..26df517264 100644 --- a/src/drivers/virtio/transport/mod.rs +++ b/src/drivers/virtio/transport/mod.rs @@ -15,13 +15,19 @@ use hermit_sync::OnceCell; use crate::arch::kernel::core_local::increment_irq_counter; #[cfg(target_arch = "x86_64")] use crate::arch::kernel::interrupts::ExceptionStackFrame; -#[cfg(all(feature = "vsock", not(feature = "pci")))] +#[cfg(all( + any(feature = "vsock", feature = "tcp", feature = "udp"), + not(feature = "pci") +))] use crate::arch::kernel::mmio as hardware; #[cfg(target_arch = "aarch64")] use crate::arch::scheduler::State; #[cfg(any(feature = "tcp", feature = "udp"))] use crate::drivers::net::NetworkDriver; -#[cfg(all(feature = "vsock", feature = "pci"))] +#[cfg(all( + any(feature = "vsock", feature = "tcp", feature = "udp"), + feature = "pci" +))] use crate::drivers::pci as hardware; /// All virtio devices share the interrupt number `VIRTIO_IRQ` @@ -31,7 +37,7 @@ static VIRTIO_IRQ: OnceCell = OnceCell::new(); pub(crate) fn virtio_irqhandler(_state: &State) -> bool { debug!("Receive virtio interrupt"); - crate::executor::run(); + increment_irq_counter(32 + VIRTIO_IRQ.get().unwrap()); #[cfg(any(feature = "tcp", feature = "udp"))] if let Some(driver) = hardware::get_network_driver() { @@ -42,6 +48,10 @@ pub(crate) fn virtio_irqhandler(_state: &State) -> bool { if let Some(driver) = hardware::get_vsock_driver() { driver.lock().handle_interrupt(); } + + crate::executor::run(); + + true } #[cfg(target_arch = "x86_64")] @@ -54,7 +64,6 @@ pub(crate) extern "x86-interrupt" fn virtio_irqhandler(stack_frame: ExceptionSta increment_irq_counter(32 + VIRTIO_IRQ.get().unwrap()); - crate::executor::run(); crate::kernel::apic::eoi(); #[cfg(any(feature = "tcp", feature = "udp"))] @@ -67,6 +76,8 @@ pub(crate) extern "x86-interrupt" fn virtio_irqhandler(stack_frame: ExceptionSta driver.lock().handle_interrupt(); } + crate::executor::run(); + core_scheduler().reschedule(); crate::arch::x86_64::swapgs(&stack_frame); } @@ -78,10 +89,6 @@ pub(crate) fn virtio_irqhandler() { debug!("Receive virtio interrupt"); - increment_irq_counter(32 + VIRTIO_IRQ.get().unwrap()); - - crate::executor::run(); - // PLIC end of interrupt crate::arch::kernel::interrupts::external_eoi(); #[cfg(any(feature = "tcp", feature = "udp"))] @@ -94,5 +101,7 @@ pub(crate) fn virtio_irqhandler() { driver.lock().handle_interrupt(); } + crate::executor::run(); + core_scheduler().reschedule(); } diff --git a/src/drivers/vsock/mod.rs b/src/drivers/vsock/mod.rs index 1abb000d86..f1e2f6d37a 100644 --- a/src/drivers/vsock/mod.rs +++ b/src/drivers/vsock/mod.rs @@ -3,14 +3,13 @@ #[cfg(feature = "pci")] pub mod pci; -use alloc::rc::Rc; +use alloc::boxed::Box; use alloc::vec::Vec; -use core::cmp::Ordering; use core::mem; +use core::mem::MaybeUninit; -use align_address::Align; use pci_types::InterruptLine; -use virtio::vsock::{Event, Hdr}; +use virtio::vsock::Hdr; use virtio::FeatureBits; use crate::config::VIRTIO_MAX_QUEUE_SIZE; @@ -19,17 +18,59 @@ use crate::drivers::virtio::error::VirtioVsockError; use crate::drivers::virtio::transport::pci::{ComCfg, IsrStatus, NotifCfg}; use crate::drivers::virtio::virtqueue::split::SplitVq; use crate::drivers::virtio::virtqueue::{ - BuffSpec, BufferToken, BufferType, Bytes, Virtq, VqIndex, VqSize, + AvailBufferToken, BufferElem, BufferType, UsedBufferToken, Virtq, VqIndex, VqSize, }; #[cfg(feature = "pci")] use crate::drivers::vsock::pci::VsockDevCfgRaw; - -const MTU: usize = 65536; +use crate::mm::device_alloc::DeviceAlloc; + +fn fill_queue( + vq: &mut dyn Virtq, + num_packets: u16, + packet_size: u32, + poll_sender: async_channel::Sender, +) { + for _ in 0..num_packets { + let buff_tkn = match AvailBufferToken::new( + vec![], + vec![ + BufferElem::Sized(Box::::new_uninit_in(DeviceAlloc)), + BufferElem::Vector(Vec::with_capacity_in( + packet_size.try_into().unwrap(), + DeviceAlloc, + )), + ], + ) { + Ok(tkn) => tkn, + Err(_vq_err) => { + error!("Setup of network queue failed, which should not happen!"); + panic!("setup of network queue failed!"); + } + }; + + // BufferTokens are directly provided to the queue + // TransferTokens are directly dispatched + // Transfers will be awaited at the queue + match vq.dispatch( + buff_tkn, + Some(poll_sender.clone()), + false, + BufferType::Direct, + ) { + Ok(_) => (), + Err(err) => { + error!("{:#?}", err); + break; + } + } + } +} pub(crate) struct RxQueue { - vq: Option>, - poll_sender: async_channel::Sender, - poll_receiver: async_channel::Receiver, + vq: Option>, + poll_sender: async_channel::Sender, + poll_receiver: async_channel::Receiver, + packet_size: u32, } impl RxQueue { @@ -40,57 +81,37 @@ impl RxQueue { vq: None, poll_sender, poll_receiver, + packet_size: 8192u32 + mem::size_of::() as u32, } } - pub fn add(&mut self, vq: Rc) { - let num_buff: u16 = vq.size().into(); - let rx_size = (MTU + mem::size_of::()) - .align_up(core::mem::size_of::>()); - let spec = BuffSpec::Single(Bytes::new(rx_size).unwrap()); - - for _ in 0..num_buff { - let buff_tkn = match BufferToken::new(None, Some(spec.clone())) { - Ok(tkn) => tkn, - Err(_vq_err) => { - error!("Setup of vsock queue failed, which should not happen!"); - panic!("setup of vsock queue failed!"); - } - }; - - // BufferTokens are directly provided to the queue - // TransferTokens are directly dispatched - // Transfers will be awaited at the queue - match vq.dispatch_await( - buff_tkn, - self.poll_sender.clone(), - false, - BufferType::Direct, - ) { - Ok(_) => (), - Err(_) => { - error!("Descriptor IDs were exhausted earlier than expected."); - break; - } - } - } + pub fn add(&mut self, mut vq: Box) { + const BUFF_PER_PACKET: u16 = 2; + let num_packets: u16 = u16::from(vq.size()) / BUFF_PER_PACKET; + info!("num_packets {}", num_packets); + fill_queue( + vq.as_mut(), + num_packets, + self.packet_size, + self.poll_sender.clone(), + ); self.vq = Some(vq); } - pub fn enable_notifs(&self) { - if let Some(ref vq) = self.vq { + pub fn enable_notifs(&mut self) { + if let Some(ref mut vq) = self.vq { vq.enable_notifs(); } } - pub fn disable_notifs(&self) { - if let Some(ref vq) = self.vq { + pub fn disable_notifs(&mut self) { + if let Some(ref mut vq) = self.vq { vq.disable_notifs(); } } - fn get_next(&mut self) -> Option { + fn get_next(&mut self) -> Option { let transfer = self.poll_receiver.try_recv(); transfer @@ -103,8 +124,8 @@ impl RxQueue { .ok() } - fn poll(&self) { - if let Some(ref vq) = self.vq { + fn poll(&mut self) { + if let Some(ref mut vq) = self.vq { vq.poll(); } } @@ -113,40 +134,17 @@ impl RxQueue { where F: FnMut(&Hdr, &[u8]), { - const HEADER_SIZE: usize = mem::size_of::(); - while let Some(mut buffer_tkn) = self.get_next() { - let (_, recv_data_opt) = buffer_tkn.as_slices().unwrap(); - let mut recv_data = recv_data_opt.unwrap(); - - if recv_data.len() == 1 { - let packet = recv_data.pop().unwrap(); - - // drop packets with invalid packet size - if packet.len() < HEADER_SIZE { - panic!("Invalid packet size!"); - } - - if let Some(ref vq) = self.vq { - let header = unsafe { - core::mem::transmute::<[u8; HEADER_SIZE], Hdr>( - packet[..HEADER_SIZE].try_into().unwrap(), - ) - }; - - f(&header, &packet[HEADER_SIZE..]); - - buffer_tkn.reset(); - vq.dispatch_await( - buffer_tkn, - self.poll_sender.clone(), - false, - BufferType::Direct, - ) - .unwrap(); - } else { - panic!("Unable to get receive queue"); - } + let header = buffer_tkn + .used_recv_buff + .pop_front_downcast::() + .unwrap(); + let packet = buffer_tkn.used_recv_buff.pop_front_vec().unwrap(); + + if let Some(ref mut vq) = self.vq { + f(&header, &packet[..]); + + fill_queue(vq.as_mut(), 1, self.packet_size, self.poll_sender.clone()); } else { panic!("Invalid length of receive queue"); } @@ -155,141 +153,70 @@ impl RxQueue { } pub(crate) struct TxQueue { - vq: Option>, - poll_sender: async_channel::Sender, - poll_receiver: async_channel::Receiver, - ready_queue: Vec, + vq: Option>, + /// Indicates, whether the Driver/Device are using multiple + /// queues for communication. + packet_length: u32, } impl TxQueue { pub fn new() -> Self { - let (poll_sender, poll_receiver) = async_channel::unbounded(); - Self { vq: None, - poll_sender, - poll_receiver, - ready_queue: Vec::new(), + packet_length: 8192u32 + mem::size_of::() as u32, } } - pub fn add(&mut self, vq: Rc) { - let tx_size = (1514 + mem::size_of::()) - .align_up(core::mem::size_of::>()); - let buff_def = Bytes::new(tx_size).unwrap(); - let spec = BuffSpec::Single(buff_def); - let num_buff: u16 = vq.size().into(); - - for _ in 0..num_buff { - let mut buffer_tkn = BufferToken::new(Some(spec.clone()), None).unwrap(); - buffer_tkn - .write_seq(Some(&Hdr::default()), None::<&Hdr>) - .unwrap(); - self.ready_queue.push(buffer_tkn) - } - + pub fn add(&mut self, vq: Box) { self.vq = Some(vq); } - pub fn enable_notifs(&self) { - if let Some(ref vq) = self.vq { + pub fn enable_notifs(&mut self) { + if let Some(ref mut vq) = self.vq { vq.enable_notifs(); } } - pub fn disable_notifs(&self) { - if let Some(ref vq) = self.vq { + pub fn disable_notifs(&mut self) { + if let Some(ref mut vq) = self.vq { vq.disable_notifs(); } } - fn poll(&self) { - if let Some(ref vq) = self.vq { + fn poll(&mut self) { + if let Some(ref mut vq) = self.vq { vq.poll(); } } - /// Returns either a BufferToken and the corresponding index of the - /// virtqueue it is coming from. (Index in the TxQueues.vqs vector) - /// - /// OR returns None, if no BufferToken could be generated - fn get_tkn(&mut self, len: usize) -> Option<(BufferToken, usize)> { - // Check all ready token, for correct size. - // Drop token if not so - // - // All Tokens inside the ready_queue are coming from the main queue with index 0. - while let Some(mut tkn) = self.ready_queue.pop() { - let (send_len, _) = tkn.len(); - - match send_len.cmp(&len) { - Ordering::Less => {} - Ordering::Equal => return Some((tkn, 0)), - Ordering::Greater => { - tkn.restr_size(Some(len), None).unwrap(); - return Some((tkn, 0)); - } - } - } - - if self.poll_receiver.is_empty() { - self.poll(); - } - - while let Ok(mut buffer_token) = self.poll_receiver.try_recv() { - buffer_token.reset(); - let (send_len, _) = buffer_token.len(); - - match send_len.cmp(&len) { - Ordering::Less => {} - Ordering::Equal => return Some((buffer_token, 0)), - Ordering::Greater => { - buffer_token.restr_size(Some(len), None).unwrap(); - return Some((buffer_token, 0)); - } - } - } - - // As usize is currently safe as the minimal usize is defined as 16bit in rust. - let spec = BuffSpec::Single(Bytes::new(len).unwrap()); - - match BufferToken::new(Some(spec), None) { - Ok(tkn) => Some((tkn, 0)), - Err(_) => { - // Here it is possible if multiple queues are enabled to get another buffertoken from them! - // Info the queues are disabled upon initialization and should be enabled somehow! - None - } - } - } - /// Provides a slice to copy the packet and transfer the packet - /// to the send queue. The caller has to creatde the header + /// to the send queue. The caller has to create the header /// for the vsock interface. pub fn send_packet(&mut self, len: usize, f: F) -> R where F: FnOnce(&mut [u8]) -> R, { - if let Some((mut buff_tkn, _vq_index)) = self.get_tkn(len) { - let (send_ptrs, _) = buff_tkn.raw_ptrs(); - let (buff_ptr, _) = send_ptrs.unwrap()[0]; - - let buf_slice: &'static mut [u8] = - unsafe { core::slice::from_raw_parts_mut(buff_ptr, len) }; - let result = f(buf_slice); - - if let Some(ref vq) = self.vq { - vq.dispatch_await( - buff_tkn, - self.poll_sender.clone(), - false, - BufferType::Direct, - ) - .unwrap(); + // We need to poll to get the queue to remove elements from the table and make space for + // what we are about to add + if let Some(ref mut vq) = self.vq { + vq.poll(); + assert!(len < usize::try_from(self.packet_length).unwrap()); + let mut packet = Vec::with_capacity_in(len, DeviceAlloc); + let result = unsafe { + let result = f(MaybeUninit::slice_assume_init_mut( + packet.spare_capacity_mut(), + )); + packet.set_len(len); result - } else { - panic!("Unable to get token for send queue"); - } + }; + + let buff_tkn = AvailBufferToken::new(vec![BufferElem::Vector(packet)], vec![]).unwrap(); + + vq.dispatch(buff_tkn, None, false, BufferType::Direct) + .unwrap(); + + result } else { panic!("Unable to get send queue"); } @@ -297,9 +224,10 @@ impl TxQueue { } pub(crate) struct EventQueue { - vq: Option>, - poll_sender: async_channel::Sender, - poll_receiver: async_channel::Receiver, + vq: Option>, + poll_sender: async_channel::Sender, + poll_receiver: async_channel::Receiver, + packet_size: u32, } impl EventQueue { @@ -310,52 +238,33 @@ impl EventQueue { vq: None, poll_sender, poll_receiver, + packet_size: 1024u32, } } - pub fn add(&mut self, vq: Rc) { - let num_buff: u16 = vq.size().into(); - let event_size = mem::size_of::() - .align_up(core::mem::size_of::>()); - let spec = BuffSpec::Single(Bytes::new(event_size).unwrap()); - - for _ in 0..num_buff { - let buff_tkn = match BufferToken::new(None, Some(spec.clone())) { - Ok(tkn) => tkn, - Err(_vq_err) => { - error!("Setup of vsock queue failed, which should not happen!"); - panic!("setup of vsock queue failed!"); - } - }; - - // BufferTokens are directly provided to the queue - // TransferTokens are directly dispatched - // Transfers will be awaited at the queue - match vq.dispatch_await( - buff_tkn, - self.poll_sender.clone(), - false, - BufferType::Direct, - ) { - Ok(_) => (), - Err(_) => { - error!("Descriptor IDs were exhausted earlier than expected."); - break; - } - } - } - + /// Adds a given queue to the underlying vector and populates the queue with RecvBuffers. + /// + /// Queues are all populated according to Virtio specification v1.1. - 5.1.6.3.1 + fn add(&mut self, mut vq: Box) { + const BUFF_PER_PACKET: u16 = 2; + let num_packets: u16 = u16::from(vq.size()) / BUFF_PER_PACKET; + fill_queue( + vq.as_mut(), + num_packets, + self.packet_size, + self.poll_sender.clone(), + ); self.vq = Some(vq); } - pub fn enable_notifs(&self) { - if let Some(ref vq) = self.vq { + pub fn enable_notifs(&mut self) { + if let Some(ref mut vq) = self.vq { vq.enable_notifs(); } } - pub fn disable_notifs(&self) { - if let Some(ref vq) = self.vq { + pub fn disable_notifs(&mut self) { + if let Some(ref mut vq) = self.vq { vq.disable_notifs(); } } @@ -398,13 +307,13 @@ impl VirtioVsockDriver { self.com_cfg.set_failed(); } - pub fn disable_interrupts(&self) { + pub fn disable_interrupts(&mut self) { // For send and receive queues? // Only for receive? Because send is off anyway? self.recv_vq.disable_notifs(); } - pub fn enable_interrupts(&self) { + pub fn enable_interrupts(&mut self) { // For send and receive queues? // Only for receive? Because send is off anyway? self.recv_vq.enable_notifs(); @@ -482,7 +391,7 @@ impl VirtioVsockDriver { } // create the queues and tell device about them - self.recv_vq.add(Rc::new( + self.recv_vq.add(Box::new( SplitVq::new( &mut self.com_cfg, &self.notif_cfg, @@ -495,7 +404,7 @@ impl VirtioVsockDriver { // Interrupt for receiving packets is wanted self.recv_vq.enable_notifs(); - self.send_vq.add(Rc::new( + self.send_vq.add(Box::new( SplitVq::new( &mut self.com_cfg, &self.notif_cfg, @@ -509,7 +418,7 @@ impl VirtioVsockDriver { self.send_vq.disable_notifs(); // create the queues and tell device about them - self.event_vq.add(Rc::new( + self.event_vq.add(Box::new( SplitVq::new( &mut self.com_cfg, &self.notif_cfg, @@ -560,9 +469,9 @@ pub mod error { FailFeatureNeg(u16), /// Set of features does not adhere to the requirements of features /// indicated by the specification - FeatureRequirementsNotMet(virtio::net::F), + FeatureRequirementsNotMet(virtio::vsock::F), /// The first u64 contains the feature bits wanted by the driver. /// but which are incompatible with the device feature set, second u64. - IncompatibleFeatureSets(virtio::net::F, virtio::net::F), + IncompatibleFeatureSets(virtio::vsock::F, virtio::vsock::F), } } diff --git a/src/drivers/vsock/pci.rs b/src/drivers/vsock/pci.rs index dda855241b..536e4700de 100644 --- a/src/drivers/vsock/pci.rs +++ b/src/drivers/vsock/pci.rs @@ -26,7 +26,7 @@ impl VirtioVsockDriver { Some(VsockDevCfg { raw: dev_cfg, dev_id: cap.dev_id(), - features: virtio::net::F::empty(), + features: virtio::vsock::F::empty(), }) } diff --git a/src/executor/vsock.rs b/src/executor/vsock.rs index 124254b603..862f85ab60 100644 --- a/src/executor/vsock.rs +++ b/src/executor/vsock.rs @@ -55,7 +55,9 @@ impl WakerRegistration { /// Wake the registered waker, if any. pub fn wake(&mut self) { - self.waker.take().map(|w| w.wake()); + if let Some(w) = self.waker.take() { + w.wake() + } } } @@ -100,7 +102,7 @@ async fn vsock_run() { { raw.state = VsockState::ReceiveRequest; raw.remote_cid = header.src_cid.to_ne().try_into().unwrap(); - raw.remote_port = header.src_port.to_ne().try_into().unwrap(); + raw.remote_port = header.src_port.to_ne(); raw.waker.wake(); } else if (raw.state == VsockState::Connected || raw.state == VsockState::Shutdown)