Commit graph

42 commits

Author SHA1 Message Date
Albert Esteve
4db81adcd2 vhost: Adopt new backend naming
Following vhost-user specification, replace
all uses of master/slave with backend/frontend
in the vhost crate.

Signed-off-by: Albert Esteve <aesteve@redhat.com>
2023-09-13 13:00:10 +02:00
Li Zebin
5c9bef626c vhost: Fix clippy warnings.
use into() to convert bool into integer
rather than 'if enable { 1 } else { 0 }'

Signed-off-by: Li Zebin <cutelizebin@gmail.com>
2023-09-11 11:00:13 +02:00
Manish Goregaokar
10bf1e9123 Make VhostUserMsgValidator use ByteValued
`extract_request_body()` assumes these types are POD as a safety
invariant, which is only possible if `VhostUserMsgValidator` is itself
an `unsafe trait` or depends on an `unsafe trait` with the correct
invariants.

`VhostUserMemoryRegion` is the only type that implemented
`VhostUserMsgValidator` and did not yet implement `ByteValued`

Signed-off-by: Manish Goregaokar <manishsmail@gmail.com>
2023-08-28 18:24:57 +02:00
Stefano Garzarella
6ca88e160a vhost-user-backend: release v0.10.1
Commit 8a4ba9d ("vhost-user-backend: fetch 'used' index from guest")
fixes an issue introduced in v0.10.0 that affects all vhost-user
backends like virtiofsd [1] or rust-vmm's vhost-device.
I easily reproduced the problem with vhost-device-vsock as well:
just restart the guest kernel and the device no longer works.

[1] https://gitlab.com/virtio-fs/virtiofsd/-/issues/120

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2023-08-22 16:02:40 +08:00
German Maglione
8a4ba9d0c5 vhost-user-backend: fetch 'used' index from guest
commit 958cdec2b8 stopped GET_VRING_BASE
from resetting the vring. This was required because when the VM is
stopped/resumed the index will be 0 instead of the correct value.

However, after the guest driver changes, for instance, after reboot,
the 'used' index should be reset to 0. The bug fixed in that commit had
the unintended side effect of setting the 'used' index to 0 after a
driver change.

QEMU's vhost-user library sets the 'used' index when receiving
SET_VRING_ADDR, _probably_ to make sure that the VQ is configured.
Perhaps the appropriate place is when receiving the first kick.
A better solution would be to send the 'used' index in SET_VRING_BASE,
as is done when using packed VQs.

To keep compatibility with QEMU and just in case, any implementation
expects the 'used' index to be set when receiving SET_VRING_ADDR let's
fetch the 'used' index from the guest when receiving that message.

Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
Signed-off-by: German Maglione <gmaglione@redhat.com>
2023-08-09 13:55:22 +02:00
Stefano Garzarella
a1822baa6c vhost: update release v0.8.1 in Cargo.toml
In the previous commit I forgot to update the version in
vhost/Cargo.toml, let's set it to 0.8.1

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2023-07-17 14:31:19 +02:00
Stefano Garzarella
751f00b2f6 vhost: Release v0.8.1
We experienced a small dependency issue with the `vm-memory` crate
features, let's release this version to fix it.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2023-07-17 13:26:11 +02:00
Sergio Lopez
9306ce05a6 vhost: Always enable vm-memory/backend-mmap
Since 4029089f ('vhost: Add support for Xen memory mappings') the
feature backend-mmap of the vm-memory crate is no longer just a
dev-dependency, as we're unconditionally importing GuestMemoryMmap from
'src/backend.rs'. Make it a general build dependency.

Signed-off-by: Sergio Lopez <slp@redhat.com>
2023-07-16 16:58:21 +08:00
Stefano Garzarella
900b9a5c41 vhost: Release v0.8.0
Release a new version with Xen support.
We broke the build with the default features, but not yet made the
release, so this should be the real release.

Fixes: b128901 ("vhost: Release v0.8.0")
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2023-07-05 13:42:54 +02:00
Viresh Kumar
1ce5280417 vhost: Use vhost_user definitions from within #[cfg] block
The `vhost-user` feature isn't enabled by default and using it without
protection in backend.rs makes the vhost only build fails.

Fix it by protecting it with the `#[cfg]` block.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2023-07-05 13:42:54 +02:00
Viresh Kumar
8783a8dda0 vhost-user-backend: Release v0.10.0
Release a new version with Xen support.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2023-07-05 16:49:12 +08:00
Viresh Kumar
78f062ac0b vhost-user-backend: Add support for Xen memory mappings
Migrate to a newer version of the vhost and other dependencies and add
support for xen memory mappings. Add a corresponding xen feature for
vhost-user-backend crate.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2023-07-05 16:49:12 +08:00
Viresh Kumar
b128901ad3 vhost: Release v0.8.0
Release a new version with Xen support.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2023-07-05 16:49:12 +08:00
Viresh Kumar
c63c9b3c83 vhost: Enable XEN_MMAP protocol feature for xen
Automatically enable the VhostUserProtocolFeatures::XEN_MMAP feature for
backends for Xen specific builds. With these the backends don't need to
enable this feature and can directly support Xen.

Suggested-by: Erik Schilling <erik.schilling@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2023-07-05 16:49:12 +08:00
Viresh Kumar
4029089f75 vhost: Add support for Xen memory mappings
The vm-memory crate now supports Xen specific memory mappings via a
special feature: "xen".

Add a corresponding feature for vhost crate and add support for Xen
memory regions. Update various dependencies to align to the same version
of vm-memory crate.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2023-07-05 16:49:12 +08:00
Erik Schilling
3e6ba3cfb7 vhost-user-backend: de-duplicate match branches
No need to repeat the struct definition here. The only purpose is to
register an event_fd at epoll if one exists.

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
2023-07-04 11:19:29 +02:00
Viresh Kumar
fc2b99d35a vhost: Add VhostUserMemoryRegionInfo::new() for tests
A lot of tests are creating objects of this structure directly, it would
be better if they all use a function instead to do so.

This will also be beneficial for future commits where more fields will
be added to this structure.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2023-06-29 09:09:31 +02:00
Viresh Kumar
26fd3cea33 vhost_user: Simplify VhostUserSingleMemoryRegion
VhostUserSingleMemoryRegion contains an extra padding before
VhostUserMemoryRegion, and everything else remains the same. Lets reuse
the same structure instead of duplicating implementation here.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2023-06-29 09:09:31 +02:00
Viresh Kumar
dd4597ad8a vhost-user-backend: Don't create MmapRegion separately
GuestRegionMmap::from_range() can take care of creating the region as
well now, use it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2023-06-29 09:09:31 +02:00
German Maglione
958cdec2b8 get_vring_base should not reset the queue
The spec specifies that on receiving `GET_VRING_BASE` the backend should
stop the vring, but not that it must be reset. This is intended for
`VHOST_USER_RESET_DEVICE`, also in this case the spec makes a
difference between stopping and disabling the ring.

The spec also doesn't forbid to send `VHOST_USER_SET_VRING_ENABLE` to
enable the vring after receiving `GET_VRING_BASE` or sending more
`GET_VRING_BASE` messages, which would always respond 0. Moreover, qemu
doesn't reset the vring either.

Signed-off-by: German Maglione <gmaglione@redhat.com>
2023-06-28 16:56:46 +02:00
Viresh Kumar
29a7f8c68f vhost: Fix clippy::derivable-impls warnings
Clippy warns saying:

error: this `impl` can be derived

Derive them instead to fix those.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2023-06-28 22:49:13 +08:00
Stefano Garzarella
a48da0890c vhost: add safety comments on unsafe blocks
In rust-vmm-ci we are enabling `clippy::undocumented_unsafe_blocks` as
errors, so let's comment all unsafe blocks to avoid failures in the
CI.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2023-06-28 22:49:13 +08:00
Bo Chen
bdc6f2ab2b vhost: vdpa: Provide custom set_vring_addr() implementation
Unlike other vhost backends (e.g. vhost-net and vhost-vsock), vDPA
backends can not work with host virtual address (HVA), instead they
expect I/O virtual address (IOVA). The IOVA can be mapped 1:1 with
guest physical address (GPA) when no IOMMU is involved. This is why
the default implementation of `set_vring_addr()` from Trait
`VhostBackend` is no longer working with vDPA backends. To solve this
issue, this patch provides a custom `set_vring_addr()` implementation
for Trait `VhostKernVdpa`.

Fixes: #164

Signed-off-by: Bo Chen <chen.bo@intel.com>
2023-06-06 09:56:50 +02:00
Sergio Lopez
03d31fae7a Release vhost v0.7.0 and vhost-user-backend v0.9.0
Set up the stage to release vhost v0.7.0 and vhost-user-backend v0.9.0
to accommodate to the new vm-memory, virtio-bindings and virtio-queue
releases.

Signed-off-by: Sergio Lopez <slp@redhat.com>
2023-05-19 10:23:30 +02:00
Sergio Lopez
a66bd0d69c Bulk update dependencies across workspace
vhost:
 - vm-memory 0.10.0 -> 0.11.0

vhost-user-backend:
 - virtio-bindings 0.1.0 -> 0.2.0
 - virtio-queue 0.7.0 -> 0.8.0
 - vm-memory 0.10.0 -> 0.11.0

Signed-off-by: Sergio Lopez <slp@redhat.com>
2023-05-19 10:23:30 +02:00
German Maglione
1d2368e5f6 Fix return value of GET_VRING_BASE message
When the frontend sends the `GET_VRING_BASE` message, we should return
 the vring's last available index and stop the vring. To return the
 correct value we should not reset the queue before getting its value,
 otherwise we will always return 0.

Signed-off-by: German Maglione <gmaglione@redhat.com>
2023-05-17 12:56:00 +02:00
Xuewei Niu
7e76859b3e Fix set_vring_addr issues
`VhostBackend::set_vring_addr()` receives a vring config data which
contains the addresses of desc table, used ring and avail ring.
`VhostBackend::is_valid()` checks the addresses in the guest address space.
`VHOST_SET_VRING_ADDR` uses the addresses in the host address space.
However, the method doesn't convert those addresses.

To address this issue, the addresses passed by the config are checked in
the guest address space. Then, they are converted by
`VringConfigData::to_vhost_vring_addr()` into the host address space to
setup the vring on the kernel.

Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
2023-05-12 17:37:38 +08:00
Viresh Kumar
ef9ae28a6a vhost_user: Slave requests aren't only FS specific
There are a lot of slave requests supported by vhost-user protocol, it
isn't just about FS_MAP and FS_UNMAP. Rename the files and declarations
to slave request specific names.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2023-03-03 22:21:45 +08:00
dependabot[bot]
9b6c40035f build(deps): update nix requirement from 0.25 to 0.26
Updates the requirements on [nix](https://github.com/nix-rust/nix) to permit the latest version.
- [Release notes](https://github.com/nix-rust/nix/releases)
- [Changelog](https://github.com/nix-rust/nix/blob/master/CHANGELOG.md)
- [Commits](https://github.com/nix-rust/nix/compare/v0.25.0...v0.26.1)

---
updated-dependencies:
- dependency-name: nix
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-12 09:54:26 +01:00
Alyssa Ross
9e5396942f vhost-user-backend: add repository metadata
I was surprised I couldn't click through to the source from
<https://lib.rs/crates/vhost-user-backend>.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
2023-01-04 14:01:46 +01:00
Alyssa Ross
0152e88b42 vhost_user: fix UB on invalid master request
Since VhostUserMsgHeader implements ByteValued, it is supposed to be
safe to construct from any correctly-sized arbitrary byte array.
But that means we can do this:

	let bytes = b"\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00";
	let header = VhostUserMsgHeader::<MasterReq>::from_slice(bytes).unwrap();
	header.get_code()

constructing an invalid MasterReq, using only functions that are
marked as safe.  Constructing an invalid enum value is undefined
behavior in Rust, so this API is unsound.  This wasn't considered by
the safety comment in VhostUserMsgHeader::get_code, which only
considered the safety of requests that were valid enum variants.

If the vhost-user frontend process sends a message that the backend
doesn't recognise, that's exactly what will happen, so the UB can be
triggered from an external process (but a trusted one).

To fix this, we need to check whether the value is valid _before_
converting it.  Req::is_valid is changed to be a non-instance method,
so it can be called before constructing the Req.
VhostUserMsgHeader::get_code is changed to return a Result, to
accomodate the case where the request number is not a valid value for
R.

Signed-off-by: Alyssa Ross <alyssa.ross@unikie.com>
2023-01-02 15:13:49 +01:00
Alyssa Ross
7a874476e8 Fix clippy 0.1.66 warnings
Signed-off-by: Alyssa Ross <hi@alyssa.is>
2023-01-02 15:13:49 +01:00
Alyssa Ross
9ee9bfd889 vhost_user: remove unsafe blocks in send functions
Now that the values being sent here are properly required to be
ByteValued, we can use the safe functions provided by ByteValued to
convert them into slices, rather than using slice::from_raw_parts.

Signed-off-by: Alyssa Ross <alyssa.ross@unikie.com>
2023-01-02 14:59:52 +01:00
Alyssa Ross
f2ae51182d vhost_user: fix unsound send_message functions
These functions were unsound because it was previously possible to
trigger UB with them, but they were not marked as unsafe.

Struct padding in Rust is uninitialized.  So if a struct with padding
had been passed to either of these functions as the body, it would
have resulted in an uninitialized read, which is undefined behavior in
Rust.

By restricting body values to be ByteValued, we avoid this, because
types implementing ByteValued are guaranteed to be convertible to and
from byte slices.

We then need to declare some types to be ByteValued, so that they can
continue to be sent over the socket.

Signed-off-by: Alyssa Ross <alyssa.ross@unikie.com>
2023-01-02 14:59:52 +01:00
Alyssa Ross
38660d2a25 vhost_user: add Error::Disconnected
It's important to be able to tell the difference between a client
cleanly disconnecting (e.g. if a VM is shut down), and a partial
message transmission.  To do this, introduce a new Disconnected error
variant, to be used only when recvmsg() returns 0 when trying to
receive a header, indicating the client disconnected after the last
message.

Signed-off-by: Alyssa Ross <alyssa.ross@unikie.com>
2023-01-02 14:53:54 +01:00
Alex Bennée
3cf778e04b vhost-user-backend: use InactiveFeature error
There is a better error to use when we haven't negotiated a VirtIO
feature. Lets use it.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2022-12-06 09:20:03 +01:00
wanglei01
75f7ad24f1 vhost-user-backend: release v0.8.0
Signed-off-by: wanglei01 <wllenyj@linux.alibaba.com>
2022-11-29 17:15:22 +01:00
wanglei01
313de9b61b vhost: release v0.6.0
Signed-off-by: wanglei01 <wllenyj@linux.alibaba.com>
2022-11-29 17:15:22 +01:00
Rob Bradford
240fc2966c {vhost, vhost-user-backend}: Update rust-vmm dependencies
Update dependencies to use recommended versions and version syntax.

See: rust-vmm/community#136

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2022-11-17 13:01:48 +01:00
Viresh Kumar
b1f572160d vhost-user-backend: Update path to vhost crate
Reference the local path instead of via crates.io.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2022-10-11 12:28:25 +05:30
Viresh Kumar
40006d0b39 Merge remote-tracking branch 'vhost-user-backend/main' into workspace
This merges vhost-user-backend into this workspace along with its git
history.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2022-10-11 12:27:44 +05:30
Viresh Kumar
d4c021dea3 Convert to a workspace
Convert the vhost git repository into a crate, which hosts vhost crate
for now. Support for vhost-user-backend and other crates will be added
later on.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2022-10-11 11:59:25 +05:30