From 8035bc12ec0edcb865b46877a729264529caf1a1 Mon Sep 17 00:00:00 2001 From: Frederick Mayle Date: Sun, 15 Oct 2023 03:50:34 +0000 Subject: Revert "Upgrade virtio-drivers to 0.7.1" Revert submission 2786927-fmayle-zerocopy-update Reason for revert: broke build Reverted changes: /q/submissionid:2786927-fmayle-zerocopy-update Change-Id: I796cf7b589bd9bdc9017b6a25fc0c69caf0feef4 --- .cargo_vcs_info.json | 2 +- Android.bp | 4 ++-- Cargo.toml | 7 +++---- Cargo.toml.orig | 6 +++--- METADATA | 6 +++--- src/device/blk.rs | 6 +++--- src/device/gpu.rs | 14 +++++++------- src/device/input.rs | 4 ++-- src/device/net.rs | 8 ++++---- src/device/socket/connectionmanager.rs | 15 ++++++--------- src/device/socket/protocol.rs | 6 +++--- src/device/socket/vsock.rs | 4 ++-- src/hal/fake.rs | 2 +- src/queue.rs | 11 ++++++----- 14 files changed, 46 insertions(+), 49 deletions(-) diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 9e70e06..c6e71f9 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "1be3d47bd665e32625cea4342766158faf847384" + "sha1": "fd54a1b1c3d7c8bfe59c5a4f0dbe1ea981328116" }, "path_in_vcs": "" } \ No newline at end of file diff --git a/Android.bp b/Android.bp index 87fa4dc..3734135 100644 --- a/Android.bp +++ b/Android.bp @@ -24,7 +24,7 @@ rust_library_rlib { name: "libvirtio_drivers", crate_name: "virtio_drivers", cargo_env_compat: true, - cargo_pkg_version: "0.7.1", + cargo_pkg_version: "0.7.0", srcs: ["src/lib.rs"], edition: "2018", features: ["alloc"], @@ -49,7 +49,7 @@ rust_test { name: "virtio-drivers_test_src_lib", crate_name: "virtio_drivers", cargo_env_compat: true, - cargo_pkg_version: "0.7.1", + cargo_pkg_version: "0.7.0", srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, diff --git a/Cargo.toml b/Cargo.toml index df47742..ab32372 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ [package] edition = "2018" name = "virtio-drivers" -version = "0.7.1" +version = "0.7.0" authors = [ "Jiajie Chen ", "Runji Wang ", @@ -36,11 +36,10 @@ version = "2.3.0" version = "0.4" [dependencies.zerocopy] -version = "0.7.5" -features = ["derive"] +version = "0.6.1" [dev-dependencies.zerocopy] -version = "0.7.5" +version = "0.6.1" features = ["alloc"] [features] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 181d481..9b216f6 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "virtio-drivers" -version = "0.7.1" +version = "0.7.0" license = "MIT" authors = [ "Jiajie Chen ", @@ -17,11 +17,11 @@ categories = ["hardware-support", "no-std"] [dependencies] log = "0.4" bitflags = "2.3.0" -zerocopy = { version = "0.7.5", features = ["derive"] } +zerocopy = "0.6.1" [features] default = ["alloc"] alloc = ["zerocopy/alloc"] [dev-dependencies] -zerocopy = { version = "0.7.5", features = ["alloc"] } +zerocopy = { version = "0.6.1", features = ["alloc"] } diff --git a/METADATA b/METADATA index 277043a..a684494 100644 --- a/METADATA +++ b/METADATA @@ -11,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/virtio-drivers/virtio-drivers-0.7.1.crate" + value: "https://static.crates.io/crates/virtio-drivers/virtio-drivers-0.7.0.crate" } - version: "0.7.1" + version: "0.7.0" license_type: NOTICE last_upgrade_date { year: 2023 month: 10 - day: 12 + day: 6 } } diff --git a/src/device/blk.rs b/src/device/blk.rs index bfdc5f8..a9ddfb2 100644 --- a/src/device/blk.rs +++ b/src/device/blk.rs @@ -7,7 +7,7 @@ use crate::volatile::{volread, Volatile}; use crate::{Error, Result}; use bitflags::bitflags; use log::info; -use zerocopy::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{AsBytes, FromBytes}; const QUEUE: u16 = 0; const QUEUE_SIZE: u16 = 16; @@ -419,7 +419,7 @@ impl Default for BlkReq { /// Response of a VirtIOBlk request. #[repr(C)] -#[derive(AsBytes, Debug, FromBytes, FromZeroes)] +#[derive(AsBytes, Debug, FromBytes)] pub struct BlkResp { status: RespStatus, } @@ -446,7 +446,7 @@ enum ReqType { /// Status of a VirtIOBlk request. #[repr(transparent)] -#[derive(AsBytes, Copy, Clone, Debug, Eq, FromBytes, FromZeroes, PartialEq)] +#[derive(AsBytes, Copy, Clone, Debug, Eq, FromBytes, PartialEq)] pub struct RespStatus(u8); impl RespStatus { diff --git a/src/device/gpu.rs b/src/device/gpu.rs index 6a49298..e19b780 100644 --- a/src/device/gpu.rs +++ b/src/device/gpu.rs @@ -8,7 +8,7 @@ use crate::{pages, Error, Result, PAGE_SIZE}; use alloc::boxed::Box; use bitflags::bitflags; use log::info; -use zerocopy::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{AsBytes, FromBytes}; const QUEUE_SIZE: u16 = 2; const SUPPORTED_FEATURES: Features = Features::RING_EVENT_IDX; @@ -66,8 +66,8 @@ impl VirtIOGpu { negotiated_features.contains(Features::RING_EVENT_IDX), )?; - let queue_buf_send = FromZeroes::new_box_slice_zeroed(PAGE_SIZE); - let queue_buf_recv = FromZeroes::new_box_slice_zeroed(PAGE_SIZE); + let queue_buf_send = FromBytes::new_box_slice_zeroed(PAGE_SIZE); + let queue_buf_recv = FromBytes::new_box_slice_zeroed(PAGE_SIZE); transport.finish_init(); @@ -338,7 +338,7 @@ bitflags! { } #[repr(transparent)] -#[derive(AsBytes, Clone, Copy, Debug, Eq, PartialEq, FromBytes, FromZeroes)] +#[derive(AsBytes, Clone, Copy, Debug, Eq, PartialEq, FromBytes)] struct Command(u32); impl Command { @@ -371,7 +371,7 @@ impl Command { const GPU_FLAG_FENCE: u32 = 1 << 0; #[repr(C)] -#[derive(AsBytes, Debug, Clone, Copy, FromBytes, FromZeroes)] +#[derive(AsBytes, Debug, Clone, Copy, FromBytes)] struct CtrlHeader { hdr_type: Command, flags: u32, @@ -402,7 +402,7 @@ impl CtrlHeader { } #[repr(C)] -#[derive(AsBytes, Debug, Copy, Clone, Default, FromBytes, FromZeroes)] +#[derive(AsBytes, Debug, Copy, Clone, Default, FromBytes)] struct Rect { x: u32, y: u32, @@ -411,7 +411,7 @@ struct Rect { } #[repr(C)] -#[derive(Debug, FromBytes, FromZeroes)] +#[derive(Debug, FromBytes)] struct RespDisplayInfo { header: CtrlHeader, rect: Rect, diff --git a/src/device/input.rs b/src/device/input.rs index 0d5799e..c277b64 100644 --- a/src/device/input.rs +++ b/src/device/input.rs @@ -8,7 +8,7 @@ use crate::volatile::{volread, volwrite, ReadOnly, WriteOnly}; use crate::Result; use alloc::boxed::Box; use core::ptr::NonNull; -use zerocopy::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{AsBytes, FromBytes}; /// Virtual human interface devices such as keyboards, mice and tablets. /// @@ -185,7 +185,7 @@ struct DevIDs { /// Both queues use the same `virtio_input_event` struct. `type`, `code` and `value` /// are filled according to the Linux input layer (evdev) interface. #[repr(C)] -#[derive(AsBytes, Clone, Copy, Debug, Default, FromBytes, FromZeroes)] +#[derive(AsBytes, Clone, Copy, Debug, Default, FromBytes)] pub struct InputEvent { /// Event type. pub event_type: u16, diff --git a/src/device/net.rs b/src/device/net.rs index b32cd72..522997e 100644 --- a/src/device/net.rs +++ b/src/device/net.rs @@ -9,7 +9,7 @@ use alloc::{vec, vec::Vec}; use bitflags::bitflags; use core::{convert::TryInto, mem::size_of}; use log::{debug, warn}; -use zerocopy::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{AsBytes, FromBytes}; const MAX_BUFFER_LEN: usize = 65535; const MIN_BUFFER_LEN: usize = 1526; @@ -370,7 +370,7 @@ type EthernetAddress = [u8; 6]; /// and buffers for incoming packets are placed in the receiveq1. . .receiveqN. /// In each case, the packet itself is preceded by a header. #[repr(C)] -#[derive(AsBytes, Debug, Default, FromBytes, FromZeroes)] +#[derive(AsBytes, Debug, Default, FromBytes)] pub struct VirtioNetHdr { flags: Flags, gso_type: GsoType, @@ -382,7 +382,7 @@ pub struct VirtioNetHdr { // payload starts from here } -#[derive(AsBytes, Copy, Clone, Debug, Default, Eq, FromBytes, FromZeroes, PartialEq)] +#[derive(AsBytes, Copy, Clone, Debug, Default, Eq, FromBytes, PartialEq)] #[repr(transparent)] struct Flags(u8); @@ -395,7 +395,7 @@ bitflags! { } #[repr(transparent)] -#[derive(AsBytes, Debug, Copy, Clone, Default, Eq, FromBytes, FromZeroes, PartialEq)] +#[derive(AsBytes, Debug, Copy, Clone, Default, Eq, FromBytes, PartialEq)] struct GsoType(u8); impl GsoType { diff --git a/src/device/socket/connectionmanager.rs b/src/device/socket/connectionmanager.rs index 8690ca3..1a6915f 100644 --- a/src/device/socket/connectionmanager.rs +++ b/src/device/socket/connectionmanager.rs @@ -8,7 +8,7 @@ use core::cmp::min; use core::convert::TryInto; use core::hint::spin_loop; use log::debug; -use zerocopy::FromZeroes; +use zerocopy::FromBytes; const PER_CONNECTION_BUFFER_CAPACITY: usize = 1024; @@ -226,13 +226,10 @@ impl VsockConnectionManager { Ok(bytes_read) } - /// Returns the number of bytes in the receive buffer available to be read by `recv`. - /// - /// When the available bytes is 0, it indicates that the receive buffer is empty and does not - /// contain any data. + /// Returns the number of bytes currently available in the recv buffer. pub fn recv_buffer_available_bytes(&mut self, peer: VsockAddr, src_port: u32) -> Result { let (_, connection) = get_connection(&mut self.connections, peer, src_port)?; - Ok(connection.buffer.used()) + Ok(connection.buffer.available()) } /// Sends a credit update to the given peer. @@ -316,7 +313,7 @@ struct RingBuffer { impl RingBuffer { pub fn new(capacity: usize) -> Self { Self { - buffer: FromZeroes::new_box_slice_zeroed(capacity), + buffer: FromBytes::new_box_slice_zeroed(capacity), used: 0, start: 0, } @@ -333,7 +330,7 @@ impl RingBuffer { } /// Returns the number of bytes currently free in the buffer. - pub fn free(&self) -> usize { + pub fn available(&self) -> usize { self.buffer.len() - self.used } @@ -341,7 +338,7 @@ impl RingBuffer { /// /// Returns true if they were added, or false if they were not. pub fn add(&mut self, bytes: &[u8]) -> bool { - if bytes.len() > self.free() { + if bytes.len() > self.available() { return false; } diff --git a/src/device/socket/protocol.rs b/src/device/socket/protocol.rs index 00ca7c0..ab0650b 100644 --- a/src/device/socket/protocol.rs +++ b/src/device/socket/protocol.rs @@ -9,7 +9,7 @@ use core::{ }; use zerocopy::{ byteorder::{LittleEndian, U16, U32, U64}, - AsBytes, FromBytes, FromZeroes, + AsBytes, FromBytes, }; /// Well-known CID for the host. @@ -46,7 +46,7 @@ pub struct VirtioVsockConfig { /// The message header for data packets sent on the tx/rx queues #[repr(packed)] -#[derive(AsBytes, Clone, Copy, Debug, Eq, FromBytes, FromZeroes, PartialEq)] +#[derive(AsBytes, Clone, Copy, Debug, Eq, FromBytes, PartialEq)] pub struct VirtioVsockHdr { pub src_cid: U64, pub dst_cid: U64, @@ -122,7 +122,7 @@ pub struct VsockAddr { } /// An event sent to the event queue -#[derive(Copy, Clone, Debug, Default, AsBytes, FromBytes, FromZeroes)] +#[derive(Copy, Clone, Debug, Default, AsBytes, FromBytes)] #[repr(C)] pub struct VirtioVsockEvent { // ID from the virtio_vsock_event_id struct in the virtio spec diff --git a/src/device/socket/vsock.rs b/src/device/socket/vsock.rs index 4578056..2e9978a 100644 --- a/src/device/socket/vsock.rs +++ b/src/device/socket/vsock.rs @@ -12,7 +12,7 @@ use alloc::boxed::Box; use core::mem::size_of; use core::ptr::{null_mut, NonNull}; use log::debug; -use zerocopy::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{AsBytes, FromBytes}; pub(crate) const RX_QUEUE_IDX: u16 = 0; pub(crate) const TX_QUEUE_IDX: u16 = 1; @@ -274,7 +274,7 @@ impl VirtIOSocket { // Allocate and add buffers for the RX queue. let mut rx_queue_buffers = [null_mut(); QUEUE_SIZE]; for (i, rx_queue_buffer) in rx_queue_buffers.iter_mut().enumerate() { - let mut buffer: Box<[u8; RX_BUFFER_SIZE]> = FromZeroes::new_box_zeroed(); + let mut buffer: Box<[u8; RX_BUFFER_SIZE]> = FromBytes::new_box_zeroed(); // Safe because the buffer lives as long as the queue, as specified in the function // safety requirement, and we don't access it until it is popped. let token = unsafe { rx.add(&[], &mut [buffer.as_mut_slice()]) }?; diff --git a/src/hal/fake.rs b/src/hal/fake.rs index f3737e2..fde129f 100644 --- a/src/hal/fake.rs +++ b/src/hal/fake.rs @@ -8,7 +8,7 @@ use core::{ alloc::Layout, ptr::{self, NonNull}, }; -use zerocopy::FromZeroes; +use zerocopy::FromBytes; #[derive(Debug)] pub struct FakeHal; diff --git a/src/queue.rs b/src/queue.rs index cc10325..3257b35 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -14,7 +14,7 @@ use core::mem::{size_of, take}; use core::ptr; use core::ptr::NonNull; use core::sync::atomic::{fence, Ordering}; -use zerocopy::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{AsBytes, FromBytes}; /// The mechanism for bulk data transport on virtio devices. /// @@ -104,7 +104,7 @@ impl VirtQueue { let avail = layout.avail_vaddr().cast(); let used = layout.used_vaddr().cast(); - let mut desc_shadow: [Descriptor; SIZE] = FromZeroes::new_zeroed(); + let mut desc_shadow: [Descriptor; SIZE] = FromBytes::new_zeroed(); // Link descriptors together. for i in 0..(size - 1) { desc_shadow[i as usize].next = i + 1; @@ -668,7 +668,7 @@ fn queue_part_sizes(queue_size: u16) -> (usize, usize, usize) { } #[repr(C, align(16))] -#[derive(AsBytes, Clone, Debug, FromBytes, FromZeroes)] +#[derive(AsBytes, Clone, Debug, FromBytes)] pub(crate) struct Descriptor { addr: u64, len: u32, @@ -723,7 +723,7 @@ impl Descriptor { } /// Descriptor flags -#[derive(AsBytes, Copy, Clone, Debug, Default, Eq, FromBytes, FromZeroes, PartialEq)] +#[derive(AsBytes, Copy, Clone, Debug, Default, Eq, FromBytes, PartialEq)] #[repr(transparent)] struct DescFlags(u16); @@ -818,6 +818,7 @@ pub(crate) fn fake_read_write_queue( handler: impl FnOnce(Vec) -> Vec, ) { use core::{ops::Deref, slice}; + use zerocopy::LayoutVerified; let available_ring = queue_driver_area as *const AvailRing; let used_ring = queue_device_area as *mut UsedRing; @@ -841,7 +842,7 @@ pub(crate) fn fake_read_write_queue( // Loop through all input descriptors in the indirect descriptor list, reading data from // them. - let indirect_descriptor_list: &[Descriptor] = zerocopy::Ref::new_slice( + let indirect_descriptor_list: &[Descriptor] = LayoutVerified::new_slice( slice::from_raw_parts(descriptor.addr as *const u8, descriptor.len as usize), ) .unwrap() -- cgit v1.2.3