Commit graph

32 commits

Author SHA1 Message Date
Matej Hrica
9b24090faf Forward VHOST_USER_GPU_SET_SOCKET to VhostUserBackend impls
The VHOST_USER_GPU_SET_SOCKET is only handled when the feature gpu-socket
is enabled. This also introduces a GpuBackend for handling comunication
over the socket.
Signed-off-by: Matej Hrica <mhrica@redhat.com>
2024-07-23 14:50:25 +02:00
dependabot[bot]
48081ddad6 build(deps): update nix requirement from 0.28 to 0.29 in the vhost group
Updates the requirements on [nix](https://github.com/nix-rust/nix) to permit the latest version.

Updates `nix` to 0.29.0
- [Changelog](https://github.com/nix-rust/nix/blob/master/CHANGELOG.md)
- [Commits](https://github.com/nix-rust/nix/compare/v0.28.0...v0.29.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-27 09:59:25 +02:00
Albert Esteve
873a9b9bed CHANGELOG.md: Add shared object feature
Signed-off-by: Albert Esteve <aesteve@redhat.com>
2024-06-19 13:11:20 +02:00
Albert Esteve
94be3dfb7d vhost_user.backend_req: check shared_object flag
Check for VHOST_USER_PROTOCOL_F_SHARED_OBJECT flag
before allowing the backend to send SHARED_OBJECT_*
requests.

If it does have negotiated the protocol feature,
avoid sending the message and return error code
(i.e., !=0).

Signed-off-by: Albert Esteve <aesteve@redhat.com>
2024-06-19 13:11:20 +02:00
Eugenio Pérez
043d0d8fa2 vhost-user-backend: set event_idx boolean at set_features
A frontend can skip the call to set_vring_base, assuming the ring will
be initialized at 0.  If that frontend acknowledge EVENT_IDX vring and
VhostUserHandler backend will never know they need to use event idx.

Move the features configuration of the vring and the backend to set_features method.

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
2024-05-14 12:28:11 +02:00
Matias Ezequiel Vara Larsen
bd6bf1325b vhost-user-backend: Prepare v0.15.0 release
This release changes the dependency for virtio-queue to 0.12.0.

Signed-off-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>
2024-04-15 14:51:00 +02:00
dependabot[bot]
2a89b283fa build(deps): bump the vhost group with 1 update
Updates the requirements on [virtio-queue](https://github.com/rust-vmm/vm-virtio) to permit the latest version.

Updates `virtio-queue` to 0.12.0
- [Release notes](https://github.com/rust-vmm/vm-virtio/releases)
- [Commits](https://github.com/rust-vmm/vm-virtio/compare/virtio-queue-v0.11.0...virtio-queue-v0.12.0)

---
updated-dependencies:
- dependency-name: virtio-queue
  dependency-type: direct:production
  dependency-group: vhost
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-26 09:16:48 +01:00
German Maglione
e3de13040b vhost-user-backend: Prepare v0.14.0 release
This release adds support for live migration, adding
dirty pages tracking and initial postcopy support.

Signed-off-by: German Maglione <gmaglione@redhat.com>
2024-03-15 11:23:54 +01:00
German Maglione
0133c53d5d vhost: Prepare v0.11.0 release
This release adds support for live migration, adding
dirty pages tracking and initial postcopy support.

Signed-off-by: German Maglione <gmaglione@redhat.com>
2024-03-15 11:23:54 +01:00
German Maglione
6ce9d36b1e Add SET_LOG_BASE message support
If the backend has the VHOST_USER_PROTOCOL_F_LOG_SHMFD protocol feature
it will receive the VHOST_USER_SET_LOG_BASE message with a file
descriptor of the dirty-pages log memory region. This log covers all
known guest addresses, and must be manipulated atomically.

For further info please see
https://qemu-project.gitlab.io/qemu/interop/vhost-user.html#migration

Signed-off-by: German Maglione <gmaglione@redhat.com>
2024-03-11 17:21:15 +01:00
German Maglione
4443df57bb vhost-user-backend: Add vhost-user bitmap trait bounds
Any bitmap used in the vhost-user backend must implement the
BitmapReplace trait, which provides the functionality to replace the
internal bitmap in runtime.

This internal bitmap is required because in the vm-memory crate the
bitmap is expected to exist at the time of creating the memory regions,
and in the case of vhost-user the bitmap is added at runtime, also it
could be replaced at a later time. In addition, the vhost user protocol
does not specify whether the previous bitmap is still active after
replying to the VHOST_USER_SET_LOG_BASE message, so we must be sure
that the in-flight requests are using the new bitmap after the message
reply.

Signed-off-by: German Maglione <gmaglione@redhat.com>
2024-03-11 17:21:15 +01:00
German Maglione
d05f1b5e12 Add replaceable-mmapped bitmap support
The vhost user protocol supports live migration, and during live
migration, the vhost-user frontend needs to track the modifications the
vhost-user backend makes to the memory mapped regions, marking the
dirty pages in a log (i.e., a bitmap).

If the backend has the VHOST_USER_PROTOCOL_F_LOG_SHMFD protocol feature
it will receive the VHOST_USER_SET_LOG_BASE message with a file
descriptor of the dirty-pages log memory region. This log covers all
known guest addresses, and must be manipulated atomically.

For further info please see
https://qemu-project.gitlab.io/qemu/interop/vhost-user.html#migration

This commit adds support for creating an atomic-memory-mapped bitmap,
and being able to replace it in runtime. The vhost user protocol does
not specify whether the previous bitmap is still active after replying
to the VHOST_USER_SET_LOG_BASE message, so we use an RwLock to be sure
that the in-flight requests are using the new bitmap after the message
reply.

Signed-off-by: German Maglione <gmaglione@redhat.com>
2024-03-11 17:21:15 +01:00
dependabot[bot]
6241add2a7 build(deps): bump the vhost group with 1 update
Updates the requirements on [nix](https://github.com/nix-rust/nix) to permit the latest version.

Updates `nix` to 0.28.0
- [Changelog](https://github.com/nix-rust/nix/blob/master/CHANGELOG.md)
- [Commits](https://github.com/nix-rust/nix/compare/v0.27.0...v0.28.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-27 09:13:17 +01:00
dependabot[bot]
39e56d340e build(deps): bump the vhost group with 1 update
---
updated-dependencies:
- dependency-name: userfaultfd
  dependency-type: direct:production
  dependency-group: vhost
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-30 09:17:58 +01:00
Egor Lazarchuk
ee2ffdf890 doc: add postcopy feature description
New sections in README files describe what `postcopy`
feature enables and the limitation of using it with
`xen` feature.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
2024-01-24 16:25:52 +01:00
Egor Lazarchuk
a051b5c3b2 test: postcopy messages
Additional tests that trigger postcopy messages handling
on both frontend and backend side. To run successfully
they need access to /dev/userfaultfd.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
2024-01-24 16:25:52 +01:00
Egor Lazarchuk
0a221ab824 vhost-user-backend: handler supports POSTCOPY messages
New feature `postcopy` is introduced. It acts as a gate for a
new functionality.
This feature is not compatible with `xen` feature because `xen`
can map memory regions on demand and this does not work with uffd.

Now backend handler supports processing of POSTCOPY messages.
This is only available when `xen` feature is not in use.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
2024-01-24 16:25:52 +01:00
German Maglione
c142751048 Handle messages for internal state migration
Let's add the `VHOST_USER_PROTOCOL_F_DEVICE_STATE` feature flag, and
handling the messages to support tha backend internal state migration.

Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
Signed-off-by: German Maglione <gmaglione@redhat.com>
2024-01-23 11:31:32 +01:00
German Maglione
4e9bda15f1 vhost-user-backend: Add back-end's internal state API
If `VHOST_USER_PROTOCOL_F_DEVICE_STATE` has been negotiated, these
methods will be called on receiving the `SET_DEVICE_STATE_FD` and
`CHECK_DEVICE_STATE` messages.

Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
Signed-off-by: German Maglione <gmaglione@redhat.com>
2024-01-23 11:31:32 +01:00
Stefano Garzarella
06694741b8 vhost-user-backend: prepare v0.13.1 release
Fix a regression introduced by commit 7f326dd ("vhost-user-backend:
SET_FEATURES must not disable any ring").

SemVer compatibility checked:
$ cargo semver-checks check-release -p vhost-user-backend
     Parsing vhost-user-backend v0.13.1 (current)
     Parsing vhost-user-backend v0.13.0 (baseline, cached)
    Checking vhost-user-backend v0.13.0 -> v0.13.1 (minor change)
   Completed [   0.030s] 42 checks; 42 passed, 6 unnecessary

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2024-01-16 16:43:30 +01:00
German Maglione
2bba1c8ab1 vhost-user-backend: SET_VRING_KICK not disabling the vring
This was introduced in 7f326dd314, but
doesn't work with qemu versions < 7.2. SET_FEATURES is received before
SET_VRING_KICK, we will enable the vrings in set_features() and disabled
them later in set_vring_kick().

Currently, the libvhostuser in qemu disables the vring upon receiving
RESET_OWNER, but that message is currently deprecated. There is not a
sane place to disable the vring, since according to the spec we can only
do that upon receiving RESET_OWNER (deprecated), RESET_DEVICE (currently
not supported in this crate), and SET_VRING_ENABLE.

The current state of the vhost-user spec is a mess, we need a more
formal spec that just a wall of english.

Signed-off-by: German Maglione <gmaglione@redhat.com>
2024-01-16 16:10:03 +01:00
German Maglione
71821bd979 vhost-user-backend: Fix incorrect comment
According to the vhost-user spec (as the code shows) the vring status
must not be modified if `VHOST_USER_F_PROTOCOL_FEATURES` has been
negotiated.

Signed-off-by: German Maglione <gmaglione@redhat.com>
2024-01-16 16:10:03 +01:00
Stefano Garzarella
5186853e49 vhost-user-backend: prepare v0.13.0 release
Before this release, vhost-user devices using this crate were
limited to 32 memslots. This does not support well the integration
with virtio-mem.
For more details: https://issues.redhat.com/browse/RHEL-15317

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2024-01-12 17:56:26 +01:00
German Maglione
9d4fc177aa vhost-user-backend: bump up MAX_MEM_SLOTS to 509
Let's support up to 509 mem slots, just like vhost in the kernel usually
does. This is required to properly support memory hotplug, either using
multiple DIMMs (ACPI supports up to 256) or using virtio-mem.

The 509 used to be the KVM limit, it supported 512, but 3 were
used for internal purposes. Currently, KVM supports more than 512, but
it usually doesn't make use of more than ~260 (i.e., 256 DIMMs + boot
memory), except when other memory devices like PCI devices with BARs are
used. So, 509 seems to work well for vhost in the kernel.

Details can be found in the QEMU change that made virtio-mem consume
up to 256 mem slots across all virtio-mem devices. [1]

509 mem slots implies 509 VMAs/mappings in the worst case (even though,
in practice with virtio-mem we won't be seeing more than ~260 in most
setups).

With max_map_count under Linux defaulting to 64k, 509 mem slots
still correspond to less than 1% of the maximum number of mappings.
There are plenty left for the application to consume.

[1] https://lore.kernel.org/all/20230926185738.277351-1-david@redhat.com/

Signed-off-by: David Hildenbrand <david@redhat.com>
Signed-off-by: German Maglione <gmaglione@redhat.com>
2024-01-12 15:31:51 +01:00
Patrick Roy
c6c936d8a7 chore: Prepare vhost-user-backend 0.12.0 release.
Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
2024-01-08 11:44:32 +01:00
Patrick Roy
7e49b01d03 vhost: Prepare 0.10.0 release
This release only includes a dependency update, which is visible in the
public API through `VhostBackend::set_vring_kick` and
`VhostBackend::set_vring_call`.

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
2024-01-08 11:44:32 +01:00
Patrick Roy
ec6fdc230c Update vm-virtio to 0.11.0
Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
2024-01-08 11:44:32 +01:00
Patrick Roy
3008e5a241 build(deps): Update vm-memory to 0.14.0
Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
2024-01-08 11:44:32 +01:00
Patrick Roy
321085b2ea Update vmm-sys-util to 0.12.1
The update brings a fix for a security vulnerability behind
feature-gated code not used by vhost (the `with-serde` feature),
see GHSA-875g-mfp6-g7f9

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
2024-01-03 05:30:25 +01:00
Stefano Garzarella
f6f540494b vhost-user-backend: take reference to vring once
In many places we access the `VhostUserHandler::vrings` array many
times and at the beginning of each function we check the index to
avoid OOB.

It happened that we forgot about this check (see #211), so let's
avoid this error-prone pattern by taking the reference to the vring
using `Vec::get()`, and avoiding multiple indexing.

Suggested-by: Erik Schilling <erik.schilling@linaro.org>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2023-12-11 15:33:51 +01:00
Stefano Garzarella
38c442d058 vhost-user-backend: check index in set_vring_base()
VHostUserHandler::set_vring_base() lacks validation of the input
parameter `index`, which is used for indexing an internal vector and
could potentially lead to a Out-of-Bounds write resulting in a panic.

Closes #211

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2023-11-24 08:16:46 +01:00
Manos Pitsidianakis
dea7a3a7c1 Move all crates to workspace root
Having all the workspace crates under the crates/ directory is
unnecessary. Rust documentation itself recommends all crates to be in
the root directory:

https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html#creating-the-second-package-in-the-workspace

I paste the text content here, in case the online page ever changes or
becomes unavailable:

    ## Creating the Second Package in the Workspace

    Next, let’s create another member package in the workspace and call it add_one. Change the top-level Cargo.toml to specify the add_one path in the members list:

    Filename: Cargo.toml

    [workspace]

    members = [
        "adder",
        "add_one",
    ]

    Then generate a new library crate named add_one:

    $ cargo new add_one --lib
         Created library `add_one` package

    Your add directory should now have these directories and files:

    ├── Cargo.lock
    ├── Cargo.toml
    ├── add_one
    │   ├── Cargo.toml
    │   └── src
    │       └── lib.rs
    ├── adder
    │   ├── Cargo.toml
    │   └── src
    │       └── main.rs
    └── target

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-11-23 16:36:57 +01:00