-
Notifications
You must be signed in to change notification settings - Fork 29
VirtIO 1.0 and multi-queue support #998
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,145 @@ | ||||||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||||||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||||||
| // file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||||||
|
|
||||||
| #![allow(non_camel_case_types)] | ||||||
|
|
||||||
| use libc::size_t; | ||||||
| use std::ffi::c_void; | ||||||
|
|
||||||
| const fn vna_ioc(ioc: i32) -> i32 { | ||||||
| const V: i32 = b'V' as i32; | ||||||
| const C: i32 = b'C' as i32; | ||||||
| V << 16 | C << 8 | ioc | ||||||
| } | ||||||
|
|
||||||
| pub const VNA_IOC_CREATE: i32 = vna_ioc(0x01); | ||||||
| pub const VNA_IOC_DELETE: i32 = vna_ioc(0x02); | ||||||
| pub const VNA_IOC_VERSION: i32 = vna_ioc(0x03); | ||||||
| pub const VNA_IOC_DEFAULT_PARAMS: i32 = vna_ioc(0x04); | ||||||
|
|
||||||
| pub const VNA_IOC_RING_INIT: i32 = vna_ioc(0x10); | ||||||
| pub const VNA_IOC_RING_RESET: i32 = vna_ioc(0x11); | ||||||
| pub const VNA_IOC_RING_KICK: i32 = vna_ioc(0x12); | ||||||
| pub const VNA_IOC_RING_SET_MSI: i32 = vna_ioc(0x13); | ||||||
| pub const VNA_IOC_RING_INTR_CLR: i32 = vna_ioc(0x14); | ||||||
| pub const VNA_IOC_RING_SET_STATE: i32 = vna_ioc(0x15); | ||||||
| pub const VNA_IOC_RING_GET_STATE: i32 = vna_ioc(0x16); | ||||||
| pub const VNA_IOC_RING_PAUSE: i32 = vna_ioc(0x17); | ||||||
|
|
||||||
| pub const VNA_IOC_INTR_POLL: i32 = vna_ioc(0x20); | ||||||
| pub const VNA_IOC_SET_FEATURES: i32 = vna_ioc(0x21); | ||||||
| pub const VNA_IOC_GET_FEATURES: i32 = vna_ioc(0x22); | ||||||
| pub const VNA_IOC_SET_NOTIFY_IOP: i32 = vna_ioc(0x23); | ||||||
| pub const VNA_IOC_SET_PROMISC: i32 = vna_ioc(0x24); | ||||||
| pub const VNA_IOC_GET_PARAMS: i32 = vna_ioc(0x25); | ||||||
| pub const VNA_IOC_SET_PARAMS: i32 = vna_ioc(0x26); | ||||||
| pub const VNA_IOC_GET_MTU: i32 = vna_ioc(0x27); | ||||||
| pub const VNA_IOC_SET_MTU: i32 = vna_ioc(0x28); | ||||||
| pub const VNA_IOC_SET_NOTIFY_MMIO: i32 = vna_ioc(0x29); | ||||||
|
|
||||||
| /// VirtIO 1.2 queue pair support. | ||||||
| pub const VNA_IOC_GET_PAIRS: i32 = vna_ioc(0x30); | ||||||
| pub const VNA_IOC_SET_PAIRS: i32 = vna_ioc(0x31); | ||||||
| pub const VNA_IOC_GET_USEPAIRS: i32 = vna_ioc(0x32); | ||||||
| pub const VNA_IOC_SET_USEPAIRS: i32 = vna_ioc(0x33); | ||||||
|
|
||||||
| #[cfg(test)] | ||||||
| mod test { | ||||||
| use super::*; | ||||||
|
|
||||||
| #[test] | ||||||
| fn test_vna_ioc() { | ||||||
| assert_eq!(vna_ioc(0x22), 0x00_56_43_22); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| pub const VIONA_MIN_QPAIRS: usize = 1; | ||||||
| pub const VIONA_MAX_QPAIRS: usize = 0x100; | ||||||
|
|
||||||
| const fn howmany(x: usize, y: usize) -> usize { | ||||||
| assert!(y > 0); | ||||||
| x.div_ceil(y) | ||||||
| } | ||||||
|
|
||||||
| #[repr(C)] | ||||||
| pub struct vioc_create { | ||||||
| pub c_linkid: u32, | ||||||
| pub c_vmfd: i32, | ||||||
| } | ||||||
|
|
||||||
| #[repr(C)] | ||||||
| #[derive(Default)] | ||||||
| pub struct vioc_ring_init { | ||||||
| pub ri_index: u16, | ||||||
| pub ri_qsize: u16, | ||||||
| pub _pad: [u16; 2], | ||||||
| pub ri_qaddr_desc: u64, | ||||||
| pub ri_qaddr_avail: u64, | ||||||
| pub ri_qaddr_used: u64, | ||||||
| } | ||||||
|
|
||||||
| #[repr(C)] | ||||||
| #[derive(Default)] | ||||||
| pub struct vioc_ring_msi { | ||||||
| pub rm_index: u16, | ||||||
| pub _pad: [u16; 3], | ||||||
| pub rm_addr: u64, | ||||||
| pub rm_msg: u64, | ||||||
| } | ||||||
|
|
||||||
| #[repr(C)] | ||||||
| #[derive(Default)] | ||||||
| pub struct vioc_intr_poll { | ||||||
| pub vip_nrings: u16, | ||||||
| pub vip_status: [u32; howmany(VIONA_MAX_QPAIRS, 32)], | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you have the padding explicitly shown in other structures here do you want to do the same for the hole here? |
||||||
| } | ||||||
|
|
||||||
| #[repr(C)] | ||||||
| #[derive(Default)] | ||||||
| pub struct vioc_nofity_mmio { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| pub vim_address: u64, | ||||||
| pub vim_size: u32, | ||||||
| } | ||||||
|
|
||||||
| #[repr(C)] | ||||||
| #[derive(Default)] | ||||||
| pub struct vioc_ring_state { | ||||||
| pub vrs_index: u16, | ||||||
| pub vrs_avail_idx: u16, | ||||||
| pub vrs_used_idx: u16, | ||||||
| pub vrs_qsize: u16, | ||||||
| pub vrs_qaddr_desc: u64, | ||||||
| pub vrs_qaddr_avail: u64, | ||||||
| pub vrs_qaddr_used: u64, | ||||||
| } | ||||||
|
|
||||||
| pub const VIONA_PROMISC_NONE: i32 = 0; | ||||||
| pub const VIONA_PROMISC_MULTI: i32 = 1; | ||||||
| pub const VIONA_PROMISC_ALL: i32 = 2; | ||||||
| #[cfg(feature = "falcon")] | ||||||
| pub const VIONA_PROMISC_ALL_VLAN: i32 = 3; | ||||||
|
|
||||||
| #[repr(C)] | ||||||
| #[derive(Default)] | ||||||
| pub struct vioc_get_params { | ||||||
| pub vgp_param: *mut c_void, | ||||||
| pub vgp_param_sz: size_t, | ||||||
| } | ||||||
|
|
||||||
| #[repr(C)] | ||||||
| #[derive(Default)] | ||||||
| pub struct vioc_set_params { | ||||||
| pub vsp_param: *mut c_void, | ||||||
| pub vsp_param_sz: size_t, | ||||||
| pub vsp_error: *mut c_void, | ||||||
| pub vsp_error_sz: size_t, | ||||||
| } | ||||||
|
|
||||||
| /// This is the viona interface version which viona_api expects to operate | ||||||
| /// against. All constants and structs defined by the crate are done so in | ||||||
| /// terms of that specific version. | ||||||
| pub const VIONA_CURRENT_INTERFACE_VERSION: u32 = 6; | ||||||
|
|
||||||
| /// Maximum size of packed nvlists used in viona parameter ioctls | ||||||
| pub const VIONA_MAX_PARAM_NVLIST_SZ: usize = 4096; | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,9 @@ use std::io::{Error, ErrorKind, Result}; | |
| use std::os::fd::*; | ||
| use std::os::unix::fs::MetadataExt; | ||
|
|
||
| pub use viona_api_sys::*; | ||
| mod ffi; | ||
|
|
||
| pub use ffi::*; | ||
|
|
||
| // Hide libnvpair usage when not building on illumos to avoid linking errors | ||
| #[cfg(target_os = "illumos")] | ||
|
|
@@ -23,7 +25,7 @@ impl VionaFd { | |
| let this = Self::open()?; | ||
|
|
||
| let mut vna_create = vioc_create { c_linkid: link_id, c_vmfd: vm_fd }; | ||
| let _ = unsafe { this.ioctl(ioctls::VNA_IOC_CREATE, &mut vna_create) }?; | ||
| let _ = unsafe { this.ioctl(VNA_IOC_CREATE, &mut vna_create) }?; | ||
| Ok(this) | ||
| } | ||
|
|
||
|
|
@@ -109,7 +111,7 @@ impl VionaFd { | |
|
|
||
| /// Query the API version exposed by the kernel VMM. | ||
| pub fn api_version(&self) -> Result<u32> { | ||
| let vers = self.ioctl_usize(ioctls::VNA_IOC_VERSION, 0)?; | ||
| let vers = self.ioctl_usize(VNA_IOC_VERSION, 0)?; | ||
|
|
||
| // We expect and demand a positive version number from the | ||
| // VNA_IOC_VERSION interface. | ||
|
|
@@ -129,16 +131,18 @@ impl VionaFd { | |
| const fn ioctl_usize_safe(cmd: i32) -> bool { | ||
| matches!( | ||
| cmd, | ||
| ioctls::VNA_IOC_DELETE | ||
| | ioctls::VNA_IOC_RING_RESET | ||
| | ioctls::VNA_IOC_RING_KICK | ||
| | ioctls::VNA_IOC_RING_PAUSE | ||
| | ioctls::VNA_IOC_RING_INTR_CLR | ||
| | ioctls::VNA_IOC_VERSION | ||
| | ioctls::VNA_IOC_SET_NOTIFY_IOP | ||
| | ioctls::VNA_IOC_SET_PROMISC | ||
| | ioctls::VNA_IOC_GET_MTU | ||
| | ioctls::VNA_IOC_SET_MTU, | ||
| VNA_IOC_DELETE | ||
| | VNA_IOC_RING_RESET | ||
| | VNA_IOC_RING_KICK | ||
| | VNA_IOC_RING_PAUSE | ||
| | VNA_IOC_RING_INTR_CLR | ||
| | VNA_IOC_VERSION | ||
| | VNA_IOC_SET_NOTIFY_IOP | ||
| | VNA_IOC_SET_PROMISC | ||
| | VNA_IOC_GET_MTU | ||
| | VNA_IOC_SET_MTU | ||
| | VNA_IOC_SET_PAIRS | ||
| | VNA_IOC_SET_USEPAIRS, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both GET_PAIRS and GET_USEPAIRS should also be safe in terms of not requiring copyin/copyout. |
||
| ) | ||
| } | ||
| } | ||
|
|
@@ -191,7 +195,14 @@ fn minor(meta: &std::fs::Metadata) -> u32 { | |
| #[repr(u32)] | ||
| #[derive(Copy, Clone)] | ||
| pub enum ApiVersion { | ||
| /// Add support for getting/setting MTU | ||
| /// Adds support for multiqueue and per-queue interrupt | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit - the per-queue interrupt polling already existed, this version of the API just changed the data structure to accommodate up to 0x200 queues compactly as a result of multi-queue. |
||
| /// polling. | ||
| V6 = 6, | ||
|
|
||
| /// Adds support for VirtIO 1.2 (modern) virtqueues. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically modern queues came in with VirtIO 1.0 |
||
| V5 = 5, | ||
|
|
||
| /// Adds support for getting/setting MTU | ||
| V4 = 4, | ||
|
|
||
| /// Adds support for interface parameters | ||
|
|
@@ -205,7 +216,7 @@ pub enum ApiVersion { | |
| } | ||
| impl ApiVersion { | ||
| pub const fn current() -> Self { | ||
| Self::V4 | ||
| Self::V6 | ||
| } | ||
| } | ||
| impl PartialEq<ApiVersion> for u32 { | ||
|
|
||
This file was deleted.
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.
Perhaps a comment here to say that this limit comes from viona and is deliberately far lower than that allowed by the spec (0x8000)? 256 queue pairs should be enough for anyone.. or something