-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Use u32 for Vsock related buffer sizes #4788
Conversation
69625c1
to
71f0957
Compare
11764b9
to
4958f44
Compare
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.
Hi, thanks for picking this up! After looking at this and #4637 again, I'm starting to think that changing everything in iovec.rs to u32 might not be that good an idea after all, with how much try_into() it introduces because of usize<->u32 conversations (the main goal for this exercise of using u32 was that I was hoping we'd eliminate try_into()s).
Could you drop all changes outside of the vsock
module from this PR, and do the usize<->u32 thing inside {write,read}_at_offset_from
in packet.rs
, without any changes in iovec.rs? It should look something like
pub fn read_at_offset_from<T: ReadVolatile + Debug>(
&mut self,
src: &mut T,
offset: u32,
count: u32,
) -> Result<u32, VsockError> {
match self.buffer {
VsockPacketBuffer::Tx(_) => Err(VsockError::UnwritableDescriptor),
VsockPacketBuffer::Rx(ref mut buffer) => {
if count
> buffer.len()
.saturating_sub(VSOCK_PKT_HDR_SIZE)
.saturating_sub(offset)
{
return Err(VsockError::GuestMemoryBounds);
}
buffer
.write_volatile_at(src, (offset + VSOCK_PKT_HDR_SIZE) as usize, count as usize)
.map_err(|err| VsockError::GuestMemoryMmap(GuestMemoryError::from(err)))
.and_then(|read| read.try_into().map_err(|_| VsockError::DescChainOverflow))
}
}
}
As an aside (I can't leave a comment on it), in connection.rs in line 241, you can do
diff --git a/src/vmm/src/devices/virtio/vsock/csm/connection.rs b/src/vmm/src/devices/virtio/vsock/csm/connection.rs
index 9fe744058..c1ed4eeb0 100644
--- a/src/vmm/src/devices/virtio/vsock/csm/connection.rs
+++ b/src/vmm/src/devices/virtio/vsock/csm/connection.rs
@@ -237,8 +237,7 @@ where
// length of the read data.
// Safe to unwrap because read_cnt is no more than max_len, which is bounded
// by self.peer_avail_credit(), a u32 internally.
- pkt.set_op(uapi::VSOCK_OP_RW)
- .set_len(u32::try_from(read_cnt).unwrap());
+ pkt.set_op(uapi::VSOCK_OP_RW).set_len(read_cnt);
METRICS.rx_bytes_count.add(read_cnt as u64);
}
self.rx_cnt += Wrapping(pkt.len());
:)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4788 +/- ##
=======================================
Coverage 84.32% 84.32%
=======================================
Files 249 249
Lines 27512 27513 +1
=======================================
+ Hits 23200 23201 +1
Misses 4312 4312
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
1fc7511
to
559bea7
Compare
Sorry, I'll try and fix this, looks like I forgot the DCO and the rebase changed a bunch more commits than mine |
2974da3
to
73b4698
Compare
Use u32 for all Vsock related buffers instead of usize, the Virtio specification states that lengths of virtio-buffers fit into a u32. Signed-off-by: River Phillips <riverphillips1@gmail.com>
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.
Thanks! Sorry for the late response, I was out most of last week. I've gone ahead and squashed your commits, everything else looks good to me!
Changes
Use u32 for all Vsock reletated buffers instead of usize, since the Virtio specification states that lengths of virtio-buffers fit into u32
Reason
Close #4627
License Acceptance
By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md
.PR Checklist
PR.
CHANGELOG.md
.TODO
s link to an issue.contribution quality standards.
rust-vmm
.