-
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
base: main
Are you sure you want to change the base?
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
abfb3a3 to
903cabf
Compare
epilys
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.
LGTM, a couple of non-code related nits
6164e22 to
2f600bd
Compare
|
Note that I changed the
|
Generally with bitflags crate you can do this outside of the bitflags macro call (since impl VhostUserMMapFlags {
pub const READABLE: Self = Self::empty();
}But I don't think it's necessary here, it looks okay currently. |
aesteve-rh
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.
LGTM. Thank you, @mtjhrc !
|
@aesteve-rh what is the status of the spec? |
|
It's been reviewed completely, waiting for a maintainer to pick it up. https://lore.kernel.org/all/20251111091058.879669-1-aesteve@redhat.com/ |
|
What @epilys said, just waiting. The last PULL from |
|
Thank you @mtjhrc for the work on this PR, just a minor comment otherwise LGTM. |
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 <aesteve@redhat.com> Co-authored-by: Matej Hrica <mhrica@redhat.com> Signed-off-by: Albert Esteve <aesteve@redhat.com> Signed-off-by: Matej Hrica <mhrica@redhat.com>
Add tests to assert return values (and existence) of default implemenation of VhostUserFrontendReqHandler and VhostUserFrontendReqHandlerMut trait methods. Signed-off-by: Matej Hrica <mhrica@redhat.com>
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 <mhrica@redhat.com>
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. |
| /// Flags specifying access permissions of memory mapping of a file | ||
| /// Use VhostUserMMapFlags::default() for a read-only mapping | ||
| pub struct VhostUserMMapFlags: u64 { | ||
| /// Read-write permission |
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.
nit: /// Read-write permission (0: read-only, 1: read-write)
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.
The comment is for WRITABLE constant, which is both read-write. Maybe (0: read-only, 1: read-write) could go in the struct doc?
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.
ah, I thought was a bitfields.
Or maybe /// Read-write permission (if not set, it's read-only), but I see we already have something in the struct doc, so really not a strong opinion on this, feel free to do nothing ;-)
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 mean what's best here, depends how the protocol evolves. I could theoretically imagine it becoming a real bitfield in the future with more options.
|
|
||
| /// Forward vhost-user memory map file request to the frontend. | ||
| fn shmem_map(&self, req: &VhostUserMMap, fd: &dyn AsRawFd) -> HandlerResult<u64> { | ||
| self.send_message(BackendReq::SHMEM_MAP, req, Some(&[fd.as_raw_fd()])) |
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.
In shared_object_*() functions above we check if the related feature is negotiated, should we do something similar also here?
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 guess we also need to add SHMEM to VhostUserProtocolFeatures as defined in https://lore.kernel.org/all/20251111091058.879669-4-aesteve@redhat.com/:
@@ -1064,6 +1086,7 @@ Protocol features
#define VHOST_USER_PROTOCOL_F_XEN_MMAP 17
#define VHOST_USER_PROTOCOL_F_SHARED_OBJECT 18
#define VHOST_USER_PROTOCOL_F_DEVICE_STATE 19
+ #define VHOST_USER_PROTOCOL_F_SHMEM 20
Front-end message types
-----------------------| // SAFETY: Safe because all fields of VhostUserMMap are POD. | ||
| unsafe impl ByteValued for VhostUserMMap {} | ||
|
|
||
| impl VhostUserMsgValidator for VhostUserMMap { |
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 add a test for this, as we do for other VhostUserMsgValidator implementations (e.g. check_user_memory(), check_user_memory_region(), etc.)
|
|
||
| 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.
@aesteve-rh thanks for that. If it's supposed to go into the spec, IMHO we can implement that already here. In the worst case, we can relax the requirement here if the spec will not require 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.
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)
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 think I'm also late to ask for packed in the spec/qemu... I have in my TODO to fix a couple of struct because of 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.
@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.
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!
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 aesteve@redhat.com 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.