Add support for GET_SHMEM_CONFIG message to retrieve
VirtIO Shared Memory Regions configuration.
This is useful when the frontend is unaware of specific
backend type and configuration of the memory layout.
Based on the patch [1] which is just waiting for being
merged.
[1] -
https://lore.kernel.org/all/20251111091058.879669-1-aesteve@redhat.com/
Signed-off-by: Albert Esteve <aesteve@redhat.com>
By registering the file descriptors only when the queue is ready and
enabled. This fixes a race in which a buffer could be added to the queue
and the kick sent after registration but before it being enabled which
causes the kick to be lost and the event never delivered to the backend.
This was particularly prevalent when restoring a snapshot.
Signed-off-by: Jorge E. Moreira <jemoreira@google.com>
When running tests in parallel (e.g. in CI), set_guest_cid() can fail
with EADDRINUSE if another test or VM already claimed the same CID.
From the test's perspective this is still a successful outcome: the
ioctl was issued correctly and the kernel rejected it for a valid
reason, so the code path is exercised either way.
Rather than complicating the test by retrying with different CIDs,
skip the assertion gracefully.
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
This code was incorrectly assuming that it was a plain ack but instead
the backend code in this repository (and the QEMU behaviour) is to
expect a full struct of reply.
Fixes: #217
Signed-off-by: Rob Bradford <rbradford@meta.com>
When it returns an error then the reply message is not sent and the
frontend hangs expecting a reply. This bug in the test becomes clear
when the correct reply size is read in the frontend for set_log_base.
Signed-off-by: Rob Bradford <rbradford@meta.com>
Some methods acquire the mutex lock twice: once to check feature flags
and again when calling send_message(), this is inefficient and also
racy, so acquire the lock once and reuse the guard for both operations.
Remove send_message() wrapper method now unused.
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Rename the `node` field to `inner` and remove the `node()` helper method,
replacing all usages with direct `self.inner.lock().unwrap()` calls for
better explicitness.
Suggested-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Add a From trait implementation to convert vhost_user::Error to io::Error.
This allows using the ? operator for cleaner error handling in methods
that return io::Result.
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
As reported in https://github.com/rust-vmm/vm-memory/pull/369,
vm-memory 0.17.2:
breaks the vhost-user-backend crate, whose vring types require some
type `M: GuestAddressSpace` with the expectation that `M::memory()`
will return something that derefs to an `0.17::GuestMemory`"
So let's pin vm-memory to 0.17.1 for now while waiting for 0.17.3 release
that will include that fix.
Signed-off-by: Stefano Garzarella <sgarzare@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>
Add tests to assert return values (and existence) of default implementation
of VhostUserFrontendReqHandler and VhostUserFrontendReqHandlerMut trait
methods.
Signed-off-by: Matej Hrica <mhrica@redhat.com>
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>
Bumps [rust-vmm-ci](https://github.com/rust-vmm/rust-vmm-ci) from `1b48931` to `b4bb768`.
- [Commits](1b48931447...b4bb7687a1)
---
updated-dependencies:
- dependency-name: rust-vmm-ci
dependency-version: b4bb7687a11bc6bdb07a37b71d2795b9fe77863f
dependency-type: direct:production
...
Signed-off-by: dependabot[bot] <support@github.com>
[SG: adapted coverage value that changed a bit with the new rust in the CI]
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Instruct the docs.rs documentation builder to pass --cfg
RUTSDOC_disable_feature_compat_errors in RUSTFLAGS when building
documentation, so that builds dont fail because of compile_error!() and
incompatible features [1].
[1]: https://docs.rs/crate/vhost/0.14.0/builds/2193201
Signed-off-by: Patrick Roy <patrick.roy@linux.dev>
Introduce a dummy feature to hack around `cargo doc --all-features`
always hitting the compile_error!(...) in vhost/src/lib.rs about
incompatible features.
This is happening because when documenting vhost-user-backend, cargo
does not pass --cfg doc to dependencies, meaning the cfg(not(doc))
attribute that is supposed to eliminate this compile_error!() invokation
when building docs does not actually trigger. Hence cargo doc fails.
Introduce a custom cfg, which we tell docs.rs to set during
documentation build, which disables the compile_error!(). Our CI also
sets this flag for the rustdoc step (via an ugly `sed` in the pipeline
definition). This cfg is also set by rust-vmm-ci for the cargo doc step.
Note that we need both cfg(not(doc)) and
cfg(not(RUTSDOC_disable_feature_compat_errors)), because lib.rs gets
processed twice, onces by rustc (where the --cfg is passed via
RUSTFLAGS), and once by rustdoc itself, where RUSTFLAGS are ignored, and
instead the cfg(doc) macro comes into play (but rustdoc is only ran on
the crate for which we are actually generating docs, not the
dependencies).
Signed-off-by: Patrick Roy <patrick.roy@linux.dev>
Now that rust-vmm-ci uses cargo-all-features, we can deal with the
incompatiblity of the xen and postcopy features by simply marking them
as incompatible in Cargo.toml, instead of needing to define separate CI
steps.
note: this commit currently symlinks rust-vmm-ci-tests.json to
rust-vmm-ci/.buildkite/test_descriptions.json, and removes all tests
from custom-tests.json. This is to illustrate that the new setup works
without changes to the buildkite pipeline. Once that is confirmed, the
pipeline should be updated to just use the rust-vmm-ci test generaiton
routine, and the entire .buildkite directory can be removed.
Signed-off-by: Patrick Roy <patrick.roy@linux.dev>
Set it up so that it does not try to combine the xen and postcopy
features, and also ignore the test-only test_utils feature.
Signed-off-by: Patrick Roy <patrick.roy@linux.dev>
By using ioctl_with_ref() instead of ioctl_with_mut_ref(), we attempted
to mutate through an immutable reference, so rustc was well within its
rights to assume that `vring_state` does not change across the ioctl
call, and hence optimize the return value of the function to simply be
the value that `vring_state.num` was initialized to (which is 0).
Signed-off-by: Patrick Roy <patrick.roy@linux.dev>
The vhost-device devices all call VhostUserDaemon::serve in a loop, to
handle reconnections. This is not ideal, because a new listener is
created each loop iteration, which means that each time, the old
socket is unlinked and a new one is created. This means that there's
a potential race where a frontend attempts to connect to the backend
before the new socket is created.
A more robust way to achieve this would be to have the devices create
their own listeners, and pass the same one to VhostUserDaemon::start
on each loop iteration, instead of letting VhostUserDaemon::serve
create it repeatedly. This was not previously possible though,
because VhostUserDaemon::start consumed the listener, even though it
didn't need to.
Because it's now possible to call VhostUserDaemon::start multiple
times with the same socket, I've removed the TODO about handling
reconnection.
Signed-off-by: Alyssa Ross <hi@alyssa.is>
warning: hiding a lifetime that's elided elsewhere is confusing
--> vhost/src/vhost_user/frontend.rs:131:13
|
131 | fn node(&self) -> MutexGuard<FrontendInternal> {
| ^^^^^ ---------------------------- the same lifetime is hidden here
| |
| the lifetime is elided here
|
= help: the same lifetime is referred to in inconsistent ways, making the signature confusing
= note: `#[warn(mismatched_lifetime_syntaxes)]` on by default
help: use `'_` for type paths
|
131 | fn node(&self) -> MutexGuard<'_, FrontendInternal> {
| +++
Signed-off-by: Alyssa Ross <hi@alyssa.is>
Eventfd is Linux-specific. To support more platforms, we replace it with
the EventNotifier/EventConsumer abstractions.
EventSender and EventReceiver are wrappers that encapsulate eventfd functionality
Use pipefd to replace eventfd in the test.
Signed-off-by: Wenyu Huang <huangwenyuu@outlook.com>
Update to v0.15.0 which supports sock_ctrl_msg on POSIX and adds
a cross platform event notification that uses EventFd when available
or pipe().
Because sock_ctrl_msg modifies the recv_with_fds, we need to modify the test
in vhost/src/vhost-user/connection.rs at the same time
Signed-off-by: Wenyu Huang <huangwenyuu@outlook.com>
It was already possible to do this as follows:
unsafe { Listener::from_raw_fd(listener.into_raw_fd()) }
This just factors the From implementation out of the FromRawFd
implementation so it's possible to do the conversion without an
unnecessary unsafe in application code.
Signed-off-by: Alyssa Ross <hi@alyssa.is>
clippy in the new rust toolchain (1.87) in our CI is highlighting
something to improve.
Mostly done with `cargo clippy --fix` + silence
`clippy::match_overlapping_arm` since EWOULDBLOCK equals to EGAIN on
linux.
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Building docs (as on docs.rs) has been broken since 8ee8739. This commit
introduces POSTCOPY and made this feature mutually exclusive with xen.
As docs are build for all features the corresponding check will be
triggered and the docs can not be built.
This patch extends the check to allow both "postcopy" and "xen" to be
enabled when building docs.
Signed-off-by: Christian Speich <christian@spei.ch>
There are several typos when using "truncate" on some messages and on the error type \`FileTruncateError\`.
Signed-off-by: Nelson Wong <wong.nel@protonmail.com>
There is a new warning reported by nightly compiler about mismatched
lifetime syntaxes. Add the missing lifetime where ever required.
Signed-off-by: Jinank Jain <jinankjain@microsoft.com>