aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Mayle <fmayle@google.com>2023-10-14 01:33:14 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-10-14 01:33:14 +0000
commitfe36f5bf2e5f75c0ae4bba59871963b4ccff043e (patch)
tree8a6733a0b48a9e51fcee8984d4b1fe34336d65ea
parente9cbf328fc05836907d05715e39da52f83ce9061 (diff)
parentd48cff7bae109f37173aa167ade462e9d571a23e (diff)
downloadvirtio-drivers-fe36f5bf2e5f75c0ae4bba59871963b4ccff043e.tar.gz
Upgrade virtio-drivers to 0.7.1 am: a97b0487fd am: 6890e57813 am: 7b0a8c4591 am: cd6ae3b861 am: d48cff7bae
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/virtio-drivers/+/2769743 Change-Id: I6323fa9f13c3c480256dba476079b95864f97915 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--Android.bp4
-rw-r--r--Cargo.toml7
-rw-r--r--Cargo.toml.orig6
-rw-r--r--METADATA6
-rw-r--r--src/device/blk.rs6
-rw-r--r--src/device/gpu.rs14
-rw-r--r--src/device/input.rs4
-rw-r--r--src/device/net.rs8
-rw-r--r--src/device/socket/connectionmanager.rs15
-rw-r--r--src/device/socket/protocol.rs6
-rw-r--r--src/device/socket/vsock.rs4
-rw-r--r--src/hal/fake.rs2
-rw-r--r--src/queue.rs11
14 files changed, 49 insertions, 46 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index c6e71f9..9e70e06 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,6 +1,6 @@
{
"git": {
- "sha1": "fd54a1b1c3d7c8bfe59c5a4f0dbe1ea981328116"
+ "sha1": "1be3d47bd665e32625cea4342766158faf847384"
},
"path_in_vcs": ""
} \ No newline at end of file
diff --git a/Android.bp b/Android.bp
index 3734135..87fa4dc 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.0",
+ cargo_pkg_version: "0.7.1",
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.0",
+ cargo_pkg_version: "0.7.1",
srcs: ["src/lib.rs"],
test_suites: ["general-tests"],
auto_gen_config: true,
diff --git a/Cargo.toml b/Cargo.toml
index ab32372..df47742 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,7 +12,7 @@
[package]
edition = "2018"
name = "virtio-drivers"
-version = "0.7.0"
+version = "0.7.1"
authors = [
"Jiajie Chen <noc@jiegec.ac.cn>",
"Runji Wang <wangrunji0408@163.com>",
@@ -36,10 +36,11 @@ version = "2.3.0"
version = "0.4"
[dependencies.zerocopy]
-version = "0.6.1"
+version = "0.7.5"
+features = ["derive"]
[dev-dependencies.zerocopy]
-version = "0.6.1"
+version = "0.7.5"
features = ["alloc"]
[features]
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 9b216f6..181d481 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "virtio-drivers"
-version = "0.7.0"
+version = "0.7.1"
license = "MIT"
authors = [
"Jiajie Chen <noc@jiegec.ac.cn>",
@@ -17,11 +17,11 @@ categories = ["hardware-support", "no-std"]
[dependencies]
log = "0.4"
bitflags = "2.3.0"
-zerocopy = "0.6.1"
+zerocopy = { version = "0.7.5", features = ["derive"] }
[features]
default = ["alloc"]
alloc = ["zerocopy/alloc"]
[dev-dependencies]
-zerocopy = { version = "0.6.1", features = ["alloc"] }
+zerocopy = { version = "0.7.5", features = ["alloc"] }
diff --git a/METADATA b/METADATA
index a684494..277043a 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.0.crate"
+ value: "https://static.crates.io/crates/virtio-drivers/virtio-drivers-0.7.1.crate"
}
- version: "0.7.0"
+ version: "0.7.1"
license_type: NOTICE
last_upgrade_date {
year: 2023
month: 10
- day: 6
+ day: 12
}
}
diff --git a/src/device/blk.rs b/src/device/blk.rs
index a9ddfb2..bfdc5f8 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};
+use zerocopy::{AsBytes, FromBytes, FromZeroes};
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)]
+#[derive(AsBytes, Debug, FromBytes, FromZeroes)]
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, PartialEq)]
+#[derive(AsBytes, Copy, Clone, Debug, Eq, FromBytes, FromZeroes, PartialEq)]
pub struct RespStatus(u8);
impl RespStatus {
diff --git a/src/device/gpu.rs b/src/device/gpu.rs
index e19b780..6a49298 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};
+use zerocopy::{AsBytes, FromBytes, FromZeroes};
const QUEUE_SIZE: u16 = 2;
const SUPPORTED_FEATURES: Features = Features::RING_EVENT_IDX;
@@ -66,8 +66,8 @@ impl<H: Hal, T: Transport> VirtIOGpu<H, T> {
negotiated_features.contains(Features::RING_EVENT_IDX),
)?;
- let queue_buf_send = FromBytes::new_box_slice_zeroed(PAGE_SIZE);
- let queue_buf_recv = FromBytes::new_box_slice_zeroed(PAGE_SIZE);
+ let queue_buf_send = FromZeroes::new_box_slice_zeroed(PAGE_SIZE);
+ let queue_buf_recv = FromZeroes::new_box_slice_zeroed(PAGE_SIZE);
transport.finish_init();
@@ -338,7 +338,7 @@ bitflags! {
}
#[repr(transparent)]
-#[derive(AsBytes, Clone, Copy, Debug, Eq, PartialEq, FromBytes)]
+#[derive(AsBytes, Clone, Copy, Debug, Eq, PartialEq, FromBytes, FromZeroes)]
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)]
+#[derive(AsBytes, Debug, Clone, Copy, FromBytes, FromZeroes)]
struct CtrlHeader {
hdr_type: Command,
flags: u32,
@@ -402,7 +402,7 @@ impl CtrlHeader {
}
#[repr(C)]
-#[derive(AsBytes, Debug, Copy, Clone, Default, FromBytes)]
+#[derive(AsBytes, Debug, Copy, Clone, Default, FromBytes, FromZeroes)]
struct Rect {
x: u32,
y: u32,
@@ -411,7 +411,7 @@ struct Rect {
}
#[repr(C)]
-#[derive(Debug, FromBytes)]
+#[derive(Debug, FromBytes, FromZeroes)]
struct RespDisplayInfo {
header: CtrlHeader,
rect: Rect,
diff --git a/src/device/input.rs b/src/device/input.rs
index c277b64..0d5799e 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};
+use zerocopy::{AsBytes, FromBytes, FromZeroes};
/// 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)]
+#[derive(AsBytes, Clone, Copy, Debug, Default, FromBytes, FromZeroes)]
pub struct InputEvent {
/// Event type.
pub event_type: u16,
diff --git a/src/device/net.rs b/src/device/net.rs
index 522997e..b32cd72 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};
+use zerocopy::{AsBytes, FromBytes, FromZeroes};
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)]
+#[derive(AsBytes, Debug, Default, FromBytes, FromZeroes)]
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, PartialEq)]
+#[derive(AsBytes, Copy, Clone, Debug, Default, Eq, FromBytes, FromZeroes, PartialEq)]
#[repr(transparent)]
struct Flags(u8);
@@ -395,7 +395,7 @@ bitflags! {
}
#[repr(transparent)]
-#[derive(AsBytes, Debug, Copy, Clone, Default, Eq, FromBytes, PartialEq)]
+#[derive(AsBytes, Debug, Copy, Clone, Default, Eq, FromBytes, FromZeroes, PartialEq)]
struct GsoType(u8);
impl GsoType {
diff --git a/src/device/socket/connectionmanager.rs b/src/device/socket/connectionmanager.rs
index 1a6915f..8690ca3 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::FromBytes;
+use zerocopy::FromZeroes;
const PER_CONNECTION_BUFFER_CAPACITY: usize = 1024;
@@ -226,10 +226,13 @@ impl<H: Hal, T: Transport> VsockConnectionManager<H, T> {
Ok(bytes_read)
}
- /// Returns the number of bytes currently available in the recv buffer.
+ /// 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.
pub fn recv_buffer_available_bytes(&mut self, peer: VsockAddr, src_port: u32) -> Result<usize> {
let (_, connection) = get_connection(&mut self.connections, peer, src_port)?;
- Ok(connection.buffer.available())
+ Ok(connection.buffer.used())
}
/// Sends a credit update to the given peer.
@@ -313,7 +316,7 @@ struct RingBuffer {
impl RingBuffer {
pub fn new(capacity: usize) -> Self {
Self {
- buffer: FromBytes::new_box_slice_zeroed(capacity),
+ buffer: FromZeroes::new_box_slice_zeroed(capacity),
used: 0,
start: 0,
}
@@ -330,7 +333,7 @@ impl RingBuffer {
}
/// Returns the number of bytes currently free in the buffer.
- pub fn available(&self) -> usize {
+ pub fn free(&self) -> usize {
self.buffer.len() - self.used
}
@@ -338,7 +341,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.available() {
+ if bytes.len() > self.free() {
return false;
}
diff --git a/src/device/socket/protocol.rs b/src/device/socket/protocol.rs
index ab0650b..00ca7c0 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,
+ AsBytes, FromBytes, FromZeroes,
};
/// 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, PartialEq)]
+#[derive(AsBytes, Clone, Copy, Debug, Eq, FromBytes, FromZeroes, PartialEq)]
pub struct VirtioVsockHdr {
pub src_cid: U64<LittleEndian>,
pub dst_cid: U64<LittleEndian>,
@@ -122,7 +122,7 @@ pub struct VsockAddr {
}
/// An event sent to the event queue
-#[derive(Copy, Clone, Debug, Default, AsBytes, FromBytes)]
+#[derive(Copy, Clone, Debug, Default, AsBytes, FromBytes, FromZeroes)]
#[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 2e9978a..4578056 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};
+use zerocopy::{AsBytes, FromBytes, FromZeroes};
pub(crate) const RX_QUEUE_IDX: u16 = 0;
pub(crate) const TX_QUEUE_IDX: u16 = 1;
@@ -274,7 +274,7 @@ impl<H: Hal, T: Transport> VirtIOSocket<H, T> {
// 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]> = FromBytes::new_box_zeroed();
+ let mut buffer: Box<[u8; RX_BUFFER_SIZE]> = FromZeroes::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 fde129f..f3737e2 100644
--- a/src/hal/fake.rs
+++ b/src/hal/fake.rs
@@ -8,7 +8,7 @@ use core::{
alloc::Layout,
ptr::{self, NonNull},
};
-use zerocopy::FromBytes;
+use zerocopy::FromZeroes;
#[derive(Debug)]
pub struct FakeHal;
diff --git a/src/queue.rs b/src/queue.rs
index 3257b35..cc10325 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};
+use zerocopy::{AsBytes, FromBytes, FromZeroes};
/// The mechanism for bulk data transport on virtio devices.
///
@@ -104,7 +104,7 @@ impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE> {
let avail = layout.avail_vaddr().cast();
let used = layout.used_vaddr().cast();
- let mut desc_shadow: [Descriptor; SIZE] = FromBytes::new_zeroed();
+ let mut desc_shadow: [Descriptor; SIZE] = FromZeroes::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)]
+#[derive(AsBytes, Clone, Debug, FromBytes, FromZeroes)]
pub(crate) struct Descriptor {
addr: u64,
len: u32,
@@ -723,7 +723,7 @@ impl Descriptor {
}
/// Descriptor flags
-#[derive(AsBytes, Copy, Clone, Debug, Default, Eq, FromBytes, PartialEq)]
+#[derive(AsBytes, Copy, Clone, Debug, Default, Eq, FromBytes, FromZeroes, PartialEq)]
#[repr(transparent)]
struct DescFlags(u16);
@@ -818,7 +818,6 @@ pub(crate) fn fake_read_write_queue<const QUEUE_SIZE: usize>(
handler: impl FnOnce(Vec<u8>) -> Vec<u8>,
) {
use core::{ops::Deref, slice};
- use zerocopy::LayoutVerified;
let available_ring = queue_driver_area as *const AvailRing<QUEUE_SIZE>;
let used_ring = queue_device_area as *mut UsedRing<QUEUE_SIZE>;
@@ -842,7 +841,7 @@ pub(crate) fn fake_read_write_queue<const QUEUE_SIZE: usize>(
// Loop through all input descriptors in the indirect descriptor list, reading data from
// them.
- let indirect_descriptor_list: &[Descriptor] = LayoutVerified::new_slice(
+ let indirect_descriptor_list: &[Descriptor] = zerocopy::Ref::new_slice(
slice::from_raw_parts(descriptor.addr as *const u8, descriptor.len as usize),
)
.unwrap()