-
Notifications
You must be signed in to change notification settings - Fork 85
vhost_user: Add support for SHMEM_MAP/UNMAP backend requests #251
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
Conversation
stefano-garzarella
left a comment
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.
Author and SoB are different, can you fix it, or add @aesteve-rh SoB if he is a co-author.
Please check also the coverage and add a line in the changelog.
80c4bf1 to
630cd66
Compare
|
I have addressed the feedback, you can take another look. Also, should I add some comment that this feature is not really "stable"? Or will this PR have to wait until it gets merged in QEMU? |
|
The coverage was too low, so I wanted to add a test for the default impl of the frontend request handlers, but I also added coverage for all the methods, since that seemed quite trivial. This has increased the coverage too much, so I had to increase the coverage config value. |
|
The code LGTM, but before merging this PR, I'd like to wait at least the spec merged in QEMU. WDYT? |
|
I understand the concern. I'm talking to @aesteve-rh to see if we can figure something out |
5f05fec to
bf692de
Compare
|
It's been reviewed completely, waiting for a maintainer to pick it up. |
|
What @epilys said, just waiting. The last PULL from |
|
Thank you @mtjhrc for the work on this PR, just a minor comment otherwise LGTM. |
Head branch was pushed to by a user without write access
@epilys @aesteve-rh great, thanks! @mtjhrc thanks for the work, I'll take a look hopefully tomorrow or on monday. |
vhost/src/vhost_user/message.rs
Outdated
|
|
||
| impl VhostUserMsgValidator for VhostUserMMap { | ||
| fn is_valid(&self) -> bool { | ||
| VhostUserMMapFlags::from_bits(self.flags).is_some() |
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.
Is self.len == 0 valid?
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.
Should we also check if padding is set to 0 like we do in VhostUserMemory ?
This is more for the future, where we can re-use the padding for something else. That said, in the spec I don't see any push on that :-(
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.
Is self.len == 0 valid?
It's not mentioned in the spec text, but in the current patches in QEMU it's rejected:
+VirtioSharedMemoryMapping *virtio_shared_memory_mapping_new(uint8_t shmid,
+ int fd,
+ uint64_t fd_offset,
+ uint64_t shm_offset,
+ uint64_t len,
+ bool allow_write)
+{
+ VirtioSharedMemoryMapping *mapping;
+ MemoryRegion *mr;
+ g_autoptr(GString) mr_name = g_string_new(NULL);
+ uint32_t ram_flags;
+ Error *local_err = NULL;
+
+ if (len == 0) {
+ error_report("Shared memory mapping size cannot be zero");
+ return NULL;
+ }
+Should we also check if padding is set to 0 like we do in VhostUserMemory ?
Sounds too strict IMHO... what if padding is filled with garbage bytes but the rest of the message is valid?
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.
IMO in the spec we should say that padding must be 0, so in the future we can potentially use it for something else. At least, this is what we usually do in Linux uAPI.
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.
IMO in the spec we should say that padding must be 0, so in the future we can potentially use it for something else. At least, this is what we usually do in Linux uAPI.
Just to be clear, this is not a blocker for this PR ;-)
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.
@germag for the spec part, would that be ok if I address that in a follow up? The patch has not been merged but after how long it took to have it ready, I do not want to cause delays. I have a few other comments to address, so I will make sure to send it and put you on cc.
Yes, I think it's fair, it was my fault not reviewing it on time, thanks!
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.
sorry if I'm misunderstanding this, I'm late for this, but uninit padding is not ok, it's a source of UB in rust, specially if the struct is
ByteValued, we already had that problem (and padding is not the same that volatile memory)
I don't see this being a problem here, we are not constructing uninitialized memory on the Rust side. The memory could be uninitiated on the sender side, but the sender writes the unilized bytes to a socket, and we override the whole ByteValued struct with the bytes received from the socket, hence we do initialize it (potentially to some unknown bytes from the socket though).
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.
And make it NonZero<_> while we're at it...
I can't change the type to type of len field to NonZero<u64> in VhostUserMMap, because that would cause UB when other party sends us 0 in the len field.
(I could change it to Option<NonZero<u64>, which should be FFI compatible with u64, but that won't really help anything)
I mean we kind of need two msg structs for each msg, one struct for over the wire protocol, that can contain invalid msgs, and one for high level usage that cannot, doesn't have useless fields like padding, uses fancy Option, NonZero... types. (or just have one struct and make the fields private, add a safe builder + getters...). I think this is a more general problem that should probably be addressed more globally.
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.
@mtjhrc good point. It's unnecessary, validation is fine also.
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.
I added the check that verifies that len cannot be zero. I also added a comment that we don't validate the padding because it's currently not specified in the spec.
b29a1cb to
f6eaaa2
Compare
Add request defintions and methods for using the new SHMEM_MAP/UNMAP backend requests. Note that at the time of writing this, these requests are part of this RFC in QEMU: https://mail.gnu.org/archive/html/qemu-devel/2024-06/msg05736.html Co-authored-by: Albert Esteve <[email protected]> Co-authored-by: Matej Hrica <[email protected]> Signed-off-by: Albert Esteve <[email protected]> Signed-off-by: Matej Hrica <[email protected]>
Add tests to assert return values (and existence) of default implementation of VhostUserFrontendReqHandler and VhostUserFrontendReqHandlerMut trait methods. Signed-off-by: Matej Hrica <[email protected]>
The last commit adds tests, that cover all of the default impls of functions, causing the coverage to increase too much - bump the value manually. Signed-off-by: Matej Hrica <[email protected]>
|
@mtjhrc LGTM, thanks for the work and the patience :-) |
Summary of the PR
This PR adds support for backend requests
SHMEM_MAPandSHMEM_UNMAP.This allows the device to memory map a file descriptor into a
Shared Memory Region.The
SHMEM_MAPandSHMEM_UNMAPare part of this QEMU RFC:I don't anticipate these specific requests to change much, the discussion for this RFC is mainly about a situation where one device is accessing shared memory mapped by another device.
These requests are required for implementing blob resource support in vhost-user-gpu.
The current gpu PR, doesn't implement blob resources and as such doesn't require this, but I am working on creating another PR with blob resource support.
This is based on a commit by Albert Esteve [email protected] in his branch/fork.
Requirements
Before submitting your PR, please make sure you addressed the following
requirements:
git commit -s), and the commit message has max 60 characters for thesummary and max 75 characters for each description line.
test.
Release" section of CHANGELOG.md (if no such section exists, please create one).
unsafecode is properly documented.