Commit Graph

52 Commits

Author SHA1 Message Date
Bilal Elmoussaoui
fad00d3e3c vsock: Set edition to 2021
Similar to other crates

Signed-off-by: Bilal Elmoussaoui <belmouss@redhat.com>
2023-08-24 15:42:44 +05:30
Priyansh Rathi
decfd8bd73 vsock: Add VM groups in sibling communication
Restrict the VMs a given VM can communicate with by introducing VM groups.
A group is simply a list of names assigned to the device in the
configuration. A VM can communicate with another VM only if the list of
group names assigned to their devices have atleast one group name in
common.

Signed-off-by: Priyansh Rathi <techiepriyansh@gmail.com>
2023-08-07 16:38:10 +05:30
Priyansh Rathi
bd59ff2462 vsock: Allow optional fields in config file
Currently need to provide all the fields in the yaml config file,
otherwise the application panics. Modify this behaviour to allow not
specifying the optional fields to make it consistent with specifying the
configuration using only CLI arguments.

Signed-off-by: Priyansh Rathi <techiepriyansh@gmail.com>
2023-08-07 16:38:10 +05:30
Jeongik Cha
637969d0e7 vsock: Increase NUM_QUEUES to 3
In virtio standard, vsock uses 3 vqs. crosvm expects 3 vqs from
vhost-user-vsock impl, but this vhost-user-vsock device sets up
only 2 vqs because event vq isn't handled. And it causes crash in
crosvm. To avoid crash in crosvm, I increase NUM_QUEUES to 3

Signed-off-by: Jeongik Cha <jeongik@google.com>
2023-07-28 09:58:36 +05:30
Jeongik Cha
c2ba07dc06 vsock: add warning message for EVT_QUEUE_EVENT
EVT_QUEUE_EVENT is an unexpected message from current impl, so add
warning for that

Signed-off-by: Jeongik Cha <jeongik@google.com>
2023-07-28 09:58:36 +05:30
Jeongik Cha
f2acb05c33 vsock: Set BACKEND_EVENT based on NUM_QUEUES
BACKEND_EVENT value depends on NUM_QUEUES, because it is the next value
of NUM_QUEUES, so set it based on NUM_QUEUES

Signed-off-by: Jeongik Cha <jeongik@google.com>
2023-07-28 09:58:36 +05:30
Jeongik Cha
9f10349f99 vsock: always epoll_register with cloned stream fd
VsockConnection::stream which is cloned is always used for
epoll_register, except add_new_guest_conn. Only in add_new_guest_conn,
the original stream is used.

Because a stream's raw fd is used for the key of listener_map, it cannot
find proper listener after the first packet.

Signed-off-by: Jeongik Cha <jeongik@google.com>
2023-07-27 16:40:40 +05:30
Stefano Garzarella
df9094d94d vsock: rename the package to vhost-device-vsock
All other devices follow the "vhost-device-*" pattern, while for
vsock we used "vhost-user-vsock". Let's rename this as well to be
consistent.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2023-07-24 12:15:23 +05:30
Stefano Garzarella
540cc8758c vsock: add myself as an author
Harsha did most of the work, but I helped arrange the final
pieces and maintain it.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2023-07-24 12:15:23 +05:30
Priyansh Rathi
6feb938c50 vsock: Try processing raw packets on other events too
Currently, the `raw_pkts_queue` is processed only when a
`SIBLING_VM_EVENT` is received. But it may happen that the
`raw_pkts_queue` could not be processed completely due to insufficient
space in the RX virtqueue at that time. So, try to process raw packets on
other events too similar to what happens in the RX of standard packets.

Signed-off-by: Priyansh Rathi <techiepriyansh@gmail.com>
2023-07-20 13:29:13 +05:30
Priyansh Rathi
e55b520cb2 vsock: Resolve deadlock in sibling VM communication
The deadlock occurs when two sibling VMs simultaneously try to send each
other packets. The `VhostUserVsockThread`s corresponding to both the VMs
hold their own locks while executing `thread_backend.send_pkt` and then
try to lock each other to access their counterpart's `raw_pkts_queue`.
This ultimately results in a deadlock.

Resolved by separating the mutex over `raw_pkts_queue` from the mutex over
`VhostUserVsockThread`.

Signed-off-by: Priyansh Rathi <techiepriyansh@gmail.com>
2023-07-20 13:29:13 +05:30
Viresh Kumar
bf75205478 crates: Don't warn for vhost_user::Error::Disconnected
The vhost_user::Error::Disconnected error code is returned by the
daemon if the VM is shutting down. Don't Warn the user in this case but
just point out that VM may be shutting down.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2023-07-20 13:06:31 +05:30
Erik Schilling
a9de87a1ce tree-wide: bubble up errors from daemon threads
There was a mix of just unwrapping (panicking) and catching and logging
errors. The unwrapping is not allowing for particulary pretty error
handling, so let's bubble the errors up by not crashing the thread,
but by just returning a Result<()> than is received when joining the
threads.

Not all .unwrap() uses were translated since a followup PR (#389) will
rework that code anyway (and get rid of the .unwrap() in the process).

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
2023-07-11 13:30:01 +05:30
Manos Pitsidianakis
8a1deef49a vsock: use tempfile in tests
Tests were run in a series before the previous commit because of a
testing failure (#232), and masked a bug. This is not necessary anymore
since the bug was fixed in the previous commit.

Instead of reverting to running the tests without the #[serial]
attribute, make every test self-contained by using unique temp
directories in each test run.

Test files that refer to sockets need to be unique because they risk
sharing filenames with other tests after refactoring. Since these tests
create/use/free resources, they should take care not to litter /tmp/ and
not share any file with other tests.

This commit uses a unique temp dir as location of test run files instead
of `/tmp/`. It adds a new dev-dependency, `tempfile`.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-07-11 13:01:41 +05:30
Manos Pitsidianakis
7f809eeab8 vsock: fix use-after-close RawFd unsafe {} use
Using a raw file descriptor in `stream_map` caused two `UnixStream`
instances have a shared single reference to the underlying stream
socket. Use UnixStream::try_clone instead which duplicates the file
descriptor while still referring to the same stream.

Fixes #232

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-07-11 13:01:41 +05:30
Ramyak Mehra
e24d3e52fc vsock: reduce credit update messages sent to guest
Earlier we were sending credit update messages to guest
everytime data was read, now we send it only if the available
space is less than 1/4th of the tx buffer size.

benchmarks:

host->guest[Gbps]

before   1.45
after    1.51

guest->host[Gbps]

before   5.68
after    6.07

Note: I did 3 runs of 10 secs and took average of all,
they are relative results.

Fixes #317

Signed-off-by: Ramyak Mehra <rmehra_be19@thapar.edu>

[SG: fixed S-o-b and small things in the commit description]

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2023-07-11 12:29:18 +05:30
Erik Schilling
7a371edc3e Add CHANGELOG.md to all crates
In order to prepare for an initial release of the crates, this adds a
CHANGELOG.md for tracking changes in the future releases.

The template was copied from the vhost crate [1].

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>

[1] 900b9a5c41/crates/vhost/CHANGELOG.md
2023-07-07 22:06:45 +05:30
Viresh Kumar
462a621485 Add support for Xen builds
Various rust-vmm dependencies now support Xen platforms under a new
feature `xen`. Add the same here for all the crates.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2023-07-06 16:37:36 +05:30
Erik Schilling
0bb783601e Symlink license files into crate folders
Once we publish crates to crates.io, only the crate subfolder is
uploaded. Symlink the license files in in order to include them during
packaging.

`cargo package` will replace the symlinks with the actual files during
packaging, so crates.io will include the license file.

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
2023-07-04 14:56:52 +05:30
Erik Schilling
2ebba0910c build(deps): switch to released virtio-bindings
This version brings the SCSI bindings and allows us to drop the git
dependency (which was complicating the packaging situation).

Thanks-to: Jiang Liu <gerry@linux.alibaba.com>
Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
2023-07-04 13:24:16 +05:30
Viresh Kumar
ad40227827 vsock: Fix build error with epoll-4.3.2
With epoll-4.3.2, bitflags moves to 2.3.3 from 1.3.2 and breaks the
build with following error:

error[E0369]: binary operation `!=` cannot be applied to type `Events`

Fix those by using the .bits() functions.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2023-07-03 13:37:19 +05:30
dependabot[bot]
41f4cb1ab2 build(deps): bump epoll from 4.3.1 to 4.3.2
Bumps [epoll](https://github.com/nathansizemore/epoll) from 4.3.1 to 4.3.2.
- [Release notes](https://github.com/nathansizemore/epoll/releases)
- [Commits](https://github.com/nathansizemore/epoll/commits)

---
updated-dependencies:
- dependency-name: epoll
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-03 13:37:19 +05:30
Priyansh Rathi
4346438bff vsock: Compare packet src_cid with the configured guest CID
Cross-check the packet `src_cid` with the CID configured for the guest.
This will forbid a VM from impersonating another.

Signed-off-by: Priyansh Rathi <techiepriyansh@gmail.com>
2023-07-03 11:33:13 +05:30
Priyansh Rathi
d6b953e958 vsock: Implement sibling VM communication
Adds support for communication between sibling VMs that use the
vhost-user-vsock devices from the same vhost-user-vsock application.

Tested with nc-vsock patched to set `.svm_flags = VMADDR_FLAG_TO_HOST`:

host$ vhost-user-vsock \
      --vm guest-cid=3,uds-path=/tmp/vm3.vsock,socket=/tmp/vhost3.socket \
      --vm guest-cid=4,uds-path=/tmp/vm4.vsock,socket=/tmp/vhost4.socket

vm_cid3$ nc-vsock -l 1234
vm_cid4$ nc-vsock 3 1234

Signed-off-by: Priyansh Rathi <techiepriyansh@gmail.com>
2023-07-03 11:33:13 +05:30
Priyansh Rathi
015ccff9fc vsock: Handle the single VM case same as multiple VMs
In future, we could add the ability to change the configuration at runtime
and allow new guests to be added even without having to restart the
daemon. So it is reasonable to not differentiate between the single and
multiple VM cases, even with only one guest.

Signed-off-by: Priyansh Rathi <techiepriyansh@gmail.com>
2023-07-03 11:33:13 +05:30
dependabot[bot]
a893caa0d6 build(deps): bump clap from 4.3.5 to 4.3.8
Bumps [clap](https://github.com/clap-rs/clap) from 4.3.5 to 4.3.8.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/v4.3.5...v4.3.8)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-26 11:22:46 +05:30
dependabot[bot]
93bdb73af2 build(deps): bump serial_test from 1.0.0 to 2.0.0
Bumps [serial_test](https://github.com/palfrey/serial_test) from 1.0.0 to 2.0.0.
- [Release notes](https://github.com/palfrey/serial_test/releases)
- [Commits](https://github.com/palfrey/serial_test/compare/v1.0.0...v2.0.0)

---
updated-dependencies:
- dependency-name: serial_test
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-14 12:55:57 +05:30
Priyansh Rathi
a4aabb15e1 vsock: Add support for multiple guests
Adds support for instantiating multiple `VhostUserVsockBackend`s parallely
to handle multiple guests. Extends the CLI interface to accept the config
for multiple VMs in addition to the yaml config file with the `--vm`
argument as follows:

vhost-user-vsock \
--vm guest_cid=3,socket=/tmp/vhost3.socket,uds_path=/tmp/vm3.vsock \
--vm guest_cid=4,socket=/tmp/vhost4.socket,uds_path=/tmp/vm4.vsock

Signed-off-by: Priyansh Rathi <techiepriyansh@gmail.com>
2023-06-08 13:09:16 +05:30
Viresh Kumar
675789ef69 Update versions of all rust-vmm crates
Update versions of all rust-vmm crates to get away with build issues.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2023-05-29 12:30:14 +05:30
dependabot[bot]
bea6e0981c build(deps): bump vhost from 0.6.0 to 0.7.0
Bumps [vhost](https://github.com/rust-vmm/vhost) from 0.6.0 to 0.7.0.
- [Release notes](https://github.com/rust-vmm/vhost/releases)
- [Commits](https://github.com/rust-vmm/vhost/compare/vhost-v0.6.0...vhost-v0.7.0)

---
updated-dependencies:
- dependency-name: vhost
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-29 12:30:14 +05:30
Li Zebin
d39e99cdd7 docs: fix the wrong file link in vsock README.md
Signed-off-by: Li Zebin <cutelizebin@gmail.com>
2023-05-22 09:37:33 +02:00
Sergio Lopez
9e8a4efdb9 vsock: close incoming UDS conns if we aren't ready
It's possible to receive an incoming UDS connection before the VMM has
contacted us to initialize the vrings.

In this case, close the incoming connection so the client is aware of we
aren't yet ready, and to avoid having a lingering incomplete connection
around.

Signed-off-by: Sergio Lopez <slp@redhat.com>
2023-05-22 08:21:34 +01:00
Sergio Lopez
b2fa8d91dd vsock: deal with process_tx error gracefully
It's possible to receive backend events before the VMM contacts us to
activate the vrings. Trying to call process_tx in this state will
trigger a NoMemoryConfigured error which will end crashing the worker
thread.

As NoMemoryConfigured is a transitory error, deal with it gracefully
printing a warning but continuing the normal execution.

Signed-off-by: Sergio Lopez <slp@redhat.com>
2023-05-22 08:21:34 +01:00
Yiyang Wu
500f617b24 vsock: Implement yaml config to support multiple vms setup
This commit aims to allow the vhost-user-vsock to
support local yaml configuration.

It introduces a new parameter '--config <CONFIG>' to allow user
to input a yaml configuration during startup and
uses config-rs to parse it.

Note that the configuration is currently made
conflicted to the original input parameters.

It introduces a new error -- ConfigParse inside the
crates/vsock/src/vhu_vsock.rs to support runtime error handling
and the new test_vsock_config_from_file() test.

It includes a new README.md with a parameter specification
and a config example in the Usage section.

It also introduces serde_deserialize(yaml) for VsockParam to let
config-rs directly pack the field specified in the array into the
VsockParam as suggested in config-rs. The serde crate is added to
crates/vsock/Cargo.toml correspondingly.

This commit also changes the original #[clap] into #[arg]
as suggested in clap-v4.

Signed-off-by: Yiyang Wu <toolmanp@outlook.com>
2023-05-09 15:38:03 +05:30
uran0sH
8efaa64ca3 vsock: make TX buffer size configurable
That buffer is used to store bytes coming from the guest before
sending them to the Unix domain socket. Some use cases might want
to increase or decrease this space, so it would be best to make it
user-customizable. Users can use "--tx-buffer-size=" to configure
TX buffer.

Fixes: #319

Signed-off-by: uran0sH <huangwenyuu@outlook.com>
2023-05-04 12:16:12 +05:30
dependabot[bot]
46b258ccec build(deps): bump clap from 4.1.14 to 4.2.4
Bumps [clap](https://github.com/clap-rs/clap) from 4.1.14 to 4.2.4.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/v4.1.14...v4.2.4)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-24 18:58:55 +05:30
Priyansh Rathi
f52cc9cfff vsock: Implement VhostUserBackend for VhostUserVsockBackend
Implement VhostUserBackend instead of VhostUserBackendMut for
VhostUserVsockBackend. VhostUserBackendMut trait is supposed to be used
for structures without interior mutability. But VhostUserVsockBackend
already uses Mutex to protect its threads, so it can implement the trait
with interior mutability (i.e. VhostUserBackend).

Signed-off-by: Priyansh Rathi <techiepriyansh@gmail.com>
2023-04-17 12:43:36 +05:30
Viresh Kumar
ea699c86de tests: Initialize queues properly
The virtio-queue crate doesn't allow invalid queue state since commit
d951283a8e88 ("don't allow processing descriptors for invalid q").

Initialize the queues properly to fix testing failures.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2023-02-28 14:44:14 +05:30
Alex Bennée
2857681557 Updates crates to use virtio_config bindings
Rather incongruously the common VIRTIO feature flags where part of the
net binding. Now that the new binding are out we can update them to
something generic.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2023-02-28 14:19:12 +05:30
dependabot[bot]
b32559eb72 build(deps): bump clap from 4.1.4 to 4.1.6
Bumps [clap](https://github.com/clap-rs/clap) from 4.1.4 to 4.1.6.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/v4.1.4...v4.1.6)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-20 12:09:24 +05:30
dependabot[bot]
ea09ebce2e build(deps): bump serial_test from 0.9.0 to 1.0.0
Bumps [serial_test](https://github.com/palfrey/serial_test) from 0.9.0 to 1.0.0.
- [Release notes](https://github.com/palfrey/serial_test/releases)
- [Commits](https://github.com/palfrey/serial_test/compare/v0.9.0...v1.0.0)

---
updated-dependencies:
- dependency-name: serial_test
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-13 10:39:24 +05:30
Stefano Garzarella
d1539d5274 vsock: require virtio-vsock 0.2.1
The 0.2.1 version of virtio-vsock crate contains a fix [1] needed to
properly work with the virtio-vsock driver provided by Linux v6.3 and
later (originally the new driver was supposed to be in v6.2, but it
was postponed).

The fix was just a quick workaround, but in the future more work will
be needed in the virtio-vsock crate to not have a Linux-only specific
implementation of VsockPacket, as described in this issue [2].

[1] https://github.com/rust-vmm/vm-virtio/pull/207
[2] https://github.com/rust-vmm/vm-virtio/issues/216

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2023-01-19 09:37:25 -07:00
Stefano Garzarella
42526a302c vsock/README: update the QEMU example
As pointed out in https://gitlab.com/qemu-project/qemu/-/issues/1337
`-numa` is not supported by all machine types, so let's update the
example using the `memory-backend` machine property.

Since we are modifying the QEMU example, let's provide only the
QEMU's vhost-user-vsock required options in the "Usage" section.
In addition we also probide a working example.

Let's also remove a spurious rust section at the bottom of the file
that does not add any useful information.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-12-05 21:18:25 +05:30
dependabot[bot]
443da37860 build(deps): bump env_logger from 0.9.3 to 0.10.0
Bumps [env_logger](https://github.com/rust-cli/env_logger) from 0.9.3 to 0.10.0.
- [Release notes](https://github.com/rust-cli/env_logger/releases)
- [Changelog](https://github.com/rust-cli/env_logger/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-cli/env_logger/compare/v0.9.3...v0.10.0)

---
updated-dependencies:
- dependency-name: env_logger
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-02 14:50:11 +05:30
Viresh Kumar
27f0f0b75b Update virtio crates to new versions
This is required to fix the errors with individual pull requests with
these crates.

Also update other dependencies with general `cargo update`.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2022-12-01 13:07:50 +05:30
dependabot[bot]
cf0f146414 build(deps): bump vmm-sys-util from 0.10.0 to 0.11.0
Bumps [vmm-sys-util](https://github.com/rust-vmm/vmm-sys-util) from 0.10.0 to 0.11.0.
- [Release notes](https://github.com/rust-vmm/vmm-sys-util/releases)
- [Changelog](https://github.com/rust-vmm/vmm-sys-util/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-vmm/vmm-sys-util/compare/v0.10.0...v0.11.0)

---
updated-dependencies:
- dependency-name: vmm-sys-util
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-01 13:07:50 +05:30
Viresh Kumar
c2e566c493 Switch to caret versions
Specify the dependencies with caret versions.

Fixes: rust-vmm/community#131
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2022-11-15 14:23:38 +00:00
Viresh Kumar
56b9ef46bb Add SAFETY comments
Add SAFETY comments to fix clippy warnings.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2022-11-09 13:05:04 +05:30
Stefano Garzarella
6c52f494a3 vsock: add license in the readme
We forgot to update the License section in the readme
template. So, let's specify that vsock crate is licensed
under Apache 2.0 OR BSD-3-Clause.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-27 11:19:40 -06:00
Stefano Garzarella
4f7ffd7d0b vsock: serialize tests as workaround
As pointed out in the issue #232, vsock tests fail randomly.
From an initial analysis, it appears that using `--test-threads=1`
never happens, but using a value greater than 1, the tests fails
after a while and almost always with the creation of UDS,
or EpollFD, or on epoll_ctl.

There should be something wrong with FDs when there are multiple
threads running tests (not sure if related to O_CLOEXEC).

This is just a workaround, we will revert this commit when we
identify the root cause.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-18 13:29:08 +05:30