Skip to content

Commit

Permalink
Change IoVecBuffer[Mut] len to u32
Browse files Browse the repository at this point in the history
This commit changes the iovec len primitive to match descriptor chain's
(u32). This removes some ugly casting and potential overflow problems,
and allows us to upcast when needed in a non-lossy manor.

Signed-off-by: Brandon Pike <bpike@amazon.com>
  • Loading branch information
brandonpike authored and root committed Apr 24, 2024
1 parent fd40204 commit 9e7f47b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/vmm/src/devices/virtio/net/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ impl Net {
METRICS.mmds.rx_accepted.inc();

// MMDS frames are not accounted by the rate limiter.
Self::rate_limiter_replenish_op(rate_limiter, frame_iovec.len() as u64);
Self::rate_limiter_replenish_op(rate_limiter, u64::from(frame_iovec.len()));

// MMDS consumed the frame.
return Ok(true);
Expand All @@ -493,7 +493,7 @@ impl Net {
let _metric = net_metrics.tap_write_agg.record_latency_metrics();
match Self::write_tap(tap, frame_iovec) {
Ok(_) => {
let len = frame_iovec.len() as u64;
let len = u64::from(frame_iovec.len());
net_metrics.tx_bytes_count.add(len);
net_metrics.tx_packets_count.inc();
net_metrics.tx_count.inc();
Expand Down Expand Up @@ -618,7 +618,7 @@ impl Net {
continue;
}

if !Self::rate_limiter_consume_op(&mut self.tx_rate_limiter, buffer.len() as u64) {
if !Self::rate_limiter_consume_op(&mut self.tx_rate_limiter, u64::from(buffer.len())) {
tx_queue.undo_pop();
self.metrics.tx_rate_limiter_throttled.inc();
break;
Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/devices/virtio/rng/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl Entropy {

// It is ok to unwrap here. We are writing `iovec.len()` bytes at offset 0.
iovec.write_all_volatile_at(&rand_bytes, 0).unwrap();
Ok(iovec.len().try_into().unwrap())
Ok(iovec.len())
}

fn process_entropy_queue(&mut self) {
Expand All @@ -142,7 +142,7 @@ impl Entropy {
// Check for available rate limiting budget.
// If not enough budget is available, leave the request descriptor in the queue
// to handle once we do have budget.
if !Self::rate_limit_request(&mut self.rate_limiter, iovec.len() as u64) {
if !Self::rate_limit_request(&mut self.rate_limiter, u64::from(iovec.len())) {
debug!("entropy: throttling entropy queue");
METRICS.entropy_rate_limiter_throttled.inc();
self.queues[RNG_QUEUE].undo_pop();
Expand Down

0 comments on commit 9e7f47b

Please sign in to comment.