Skip to content

Commit 8f9e89e

Browse files
committed
fix(virtq): address code review
Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
1 parent 16de50c commit 8f9e89e

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

src/hyperlight_common/src/virtq/access.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub trait MemOps {
5353
///
5454
/// # Safety
5555
///
56-
/// The caller must ensure `paddr` is valid and points to at least `dst.len()` bytes.
56+
/// The caller must ensure `addr` is valid and points to at least `dst.len()` bytes.
5757
fn read(&self, addr: u64, dst: &mut [u8]) -> Result<usize, Self::Error>;
5858

5959
/// Write bytes to physical memory.
@@ -69,7 +69,7 @@ pub trait MemOps {
6969
///
7070
/// # Safety
7171
///
72-
/// The caller must ensure `paddr` is valid and points to at least `src.len()` bytes.
72+
/// The caller must ensure `addr` is valid and points to at least `src.len()` bytes.
7373
fn write(&self, addr: u64, src: &[u8]) -> Result<usize, Self::Error>;
7474

7575
/// Load a u16 with acquire semantics.

src/hyperlight_common/src/virtq/desc.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl Descriptor {
174174
///
175175
/// # Invariant
176176
///
177-
/// The caller must ensure that `base` is valid for writes of Descriptor
177+
/// The caller must ensure that `addr` is valid for writes of Descriptor
178178
pub fn write_release<M: MemOps>(&self, mem: &M, addr: u64) -> Result<(), M::Error> {
179179
mem.write_val(addr + Self::ADDR_OFFSET as u64, self.addr)?;
180180
mem.write_val(addr + Self::LEN_OFFSET as u64, self.len)?;
@@ -189,7 +189,7 @@ impl Descriptor {
189189
#[derive(Debug, Clone, Copy)]
190190
pub struct DescTable {
191191
base_addr: u64,
192-
size: usize,
192+
len: usize,
193193
}
194194

195195
impl DescTable {
@@ -199,20 +199,20 @@ impl DescTable {
199199
///
200200
/// # Safety
201201
///
202-
/// - `base` must be valid for reads and writes of `size` descriptors
203-
/// - `base` must be properly aligned for `Descriptor`
204-
/// - `size` must not exceed `u16::MAX`
202+
/// - `base_addr` must be valid for reads and writes of `len` descriptors
203+
/// - `base_addr` must be properly aligned for `Descriptor`
204+
/// - `len` must not exceed `u16::MAX`
205205
/// - memory must remain valid for the lifetime of this table
206-
pub unsafe fn from_raw_parts(base_addr: u64, size: usize) -> Self {
206+
pub unsafe fn from_raw_parts(base_addr: u64, len: usize) -> Self {
207207
assert!(base_addr.is_multiple_of(Descriptor::ALIGN as u64));
208-
assert!(size <= u16::MAX as usize);
208+
assert!(len <= u16::MAX as usize);
209209

210-
Self { base_addr, size }
210+
Self { base_addr, len }
211211
}
212212

213213
/// Get view into descriptor at index or None if idx is out of bounds
214214
pub fn desc_addr(&self, idx: u16) -> Option<u64> {
215-
if idx >= self.size as u16 {
215+
if idx >= self.len as u16 {
216216
return None;
217217
}
218218

@@ -221,12 +221,12 @@ impl DescTable {
221221

222222
/// Get number of descriptors in table
223223
pub fn len(&self) -> usize {
224-
self.size
224+
self.len
225225
}
226226

227227
/// Is the descriptor table empty?
228228
pub fn is_empty(&self) -> bool {
229-
self.size == 0
229+
self.len == 0
230230
}
231231

232232
pub const fn default_len() -> usize {

src/hyperlight_common/src/virtq/event.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ bitflags! {
4242
#[repr(C)]
4343
#[derive(Clone, Copy, Debug, Pod, Zeroable, PartialEq, Eq, Hash)]
4444
pub struct EventSuppression {
45-
// bits 0-14: offset, bit 15: wrap
46-
pub off_wrap: u16,
47-
// bits 0-1: flags, bits 2-15: reserved
48-
pub flags: u16,
45+
/// bits 0-14: offset, bit 15: wrap
46+
off_wrap: u16,
47+
/// bits 0-1: flags, bits 2-15: reserved
48+
flags: u16,
4949
}
5050

5151
const _: () = assert!(core::mem::size_of::<EventSuppression>() == 4);

0 commit comments

Comments
 (0)