Commit Graph

108 Commits

Author SHA1 Message Date
dependabot[bot]
51c5bc0431 build(deps): bump clap from 4.3.23 to 4.4.3
Bumps [clap](https://github.com/clap-rs/clap) from 4.3.23 to 4.4.3.
- [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.23...v4.4.3)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-13 17:10:17 +02:00
Erik Schilling
313ca7c0f2 gpio: silence (valid) clippy warning for now
This is a valid issue, but resolving takes some time. Meanwhile, we do
not want to block the CI.

Issue #442 was filed to track finding a real fix.

This should be reverted once the real fix happens.

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
2023-09-13 15:58:52 +01:00
Milan Zamazal
c0a5c39b99 scmi: Add some notes on testing to README
Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
923fa4312a scmi: Add CHANGELOG.md
Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
07cbe73dc8 scmi: Improve output on backend configuration error
Print a properly formatted error to both the log and terminal.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
0261d315ac scmi: Improve command line processing
When a device help is requested with `-d help', the socket argument is
still required.  This patch:

- replaces `-d help' with --help-devices;
- stops requiring the socket argument in such a case;
- prints help in case of command line parsing errors.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
847b3f44a6 scmi: Add source code docstrings
Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
b84bf46d68 scmi: Add scale & offset to the accelerator in the kernel
To be able to test scaling in guests running on hosts with the dummy
IIO module.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
458f168639 scmi: Add support for industrial I/O devices
Industrial I/O (IIO) devices are present in /sys/bus/iio/devices/ on
Linux.  This patch makes them accessible to the guests via the sensor
SCMI protocol.

The implementation no way covers all the possible IIO devices.  It
supports some basic stuff, other sensors can be added as needed.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
c1637e94b8 scmi: Use new_device for ScmiDevice constructors
Instead of `new', which should be reserved for direct constructors.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
789288c372 scmi: Add sensor device initialization function
Implementation accessing real sensors will need to set up the device
instance.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
cbb0449d43 scmi: Refactor unit handling
Make unit handling better SCMI compliant.  Let's distinguish between
scalar sensors and axis sensors and report the units in the
appropriate SCMI commands.  Also, let's change the unit type to u8 to
correspond to the number of unit bits in SCMI.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
58ddb26d5b scmi: Use separate modules for device implementations
For a better readability once we start adding more devices.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
ca8f181bcd scmi: Refactor device specification and creation
Making the device configuration polymorphic requires the device struct
to exist before the device parameters are checked and assigned to the
struct fields.  Which means wrapping the struct fields by Option
unnecessarily or introducing other data confusion.

Let's extract the device configuration from traits to plain functions
in order to keep the device struct's unencumbered.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
73c536df2e scmi: Provide help for devices
Writing `--device help' on the command line will list all the
available devices and their parameters.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
4014a6366f scmi: Kernel instructions and changes for IIO added
Followup patches will allow connecting vhost-user-scmi to industrial
I/O devices.  On host without IIO devices, it’s possible to use
emulated devices for testing.  This patch documents how to use them
and also provides a slightly customized IIO dummy kernel module.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
e0fdfa4c38 scmi: Refactor devices.rs for sensor code reuse
Different sensors will have similar handling.  Let’s extract generic
parts from FakeSensor implementation into a reusable code, within the
limits of Rust.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
3d1cc5b370 scmi: Add a command line option for defining devices
The code already contains support for creating devices that can serve
as SCMI-accessible sensors and a sample fake devices.  But to actually
use the device, the code must be modified.

This patch adds a command line option to define the devices on start.
The format of the option value is in the QEMU style:
DEVICE,PROPERTY=VALUE,…

For example:

  --device fake,name=fake1 fake,name=fake2

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
bc7faf7685 scmi: Add sensor management protocol
This patch implements the necessary parts of the SCMI sensor
management protocol, required either by the SCMI standard or by Linux
VIRTIO SCMI drivers to function correctly.  A part of this
implementation is a fake sensor device, which is useful for both unit
testing here and a testing with a real guest OS.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
5b0b8c3753 scmi: Implement SCMI base protocol
Implementation of the mandatory parts of the SCMI base protocol.  This
allows the daemon to communicate with the guest SCMI VIRTIO device,
although not yet providing any useful functionality.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Milan Zamazal
9513ed841c scmi: Initial skeleton
This patch adds support for a SCMI vhost-user device.  It implements
the basic skeleton of the vhost-user daemon and of SCMI processing.
It doesn’t provide any real functionality yet, adding it will be the
subject of followup patches.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Bilal Elmoussaoui
ee2abe6df0 scsi: Bump num_enum
Signed-off-by: Bilal Elmoussaoui <belmouss@redhat.com>
2023-08-24 15:42:44 +05:30
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
Bilal Elmoussaoui
05cfece5f8 i2c: Don't take a mut ref for reqs
Fixing a nightly clippy warning

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
dependabot[bot]
005bdfa17a build(deps): bump num_enum from 0.5.11 to 0.6.1
Bumps [num_enum](https://github.com/illicitonion/num_enum) from 0.5.11 to 0.6.1.
- [Commits](https://github.com/illicitonion/num_enum/compare/0.5.11...0.6.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-31 10:37:24 +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
6305c66f22 scsi: replaced some leftover of vhost-user-scsi
There was some reference left in the documentation and sources to
"vhost-user-scsi" that we had changed during the rebase.
Let's change them to "vhost-device-scsi".

Everything should be safe.

We leave "vhost-user-scsi" in
crates/scsi/src/scsi/emulation/response_data.rs because it looks like
an identifier with some constant size. We will fix in the future.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2023-07-24 12:15:23 +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
Stefano Garzarella
66e1173d6d rng: fix clippy warning
`timer` variable does not need to be mutable as clippy reported:

    warning: variable does not need to be mutable
       --> crates/rng/src/vhu_rng.rs:127:17
        |
    127 |             let mut timer = &mut self.timer;

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
3cab62ea02 rng: also pretty print configuration errors
If the parsed commandline options cannot be converted into a
`VuRngConfig` we would only get a .unwrap() error message.

Chain this before the check of the daemon launch.

Suggested-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
2023-07-11 13:30:01 +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
Erik Schilling
2b1b3644da tree-wide: drop the Eq trait from Error
I plan to add some wrapper errors around vhost errors. These end up
nesting other errors all the way to std::error::Error, which has no
Eq trait.

The implementations were only used for comparisions in tests. While
there is a assert_matches!() in nightly [1] it seems unlikely that
further testing lib additions are getting standarized soon (or ever).

One could use assert!(matches!()), but that would worsen the error
messages for test failures. Hence, during review [2] we agreed on
introducing the assert_matches crate. It got no dependencies and
allows us to keep the good error messages while not needing to depend
on nightly.

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

[1] https://doc.rust-lang.org/std/assert_matches/macro.assert_matches.html
[2] https://github.com/rust-vmm/vhost-device/pull/388#discussion_r1257831748
2023-07-11 13:30:01 +05:30
Erik Schilling
9332a933f8 tree-wide: actually pretty-print error messages
We setup pretty-printing with all the thiserror-based Error structs, but
then only bubble the error up to the main, where it just gets printed
with the `Debug` trait.

This "catches" the error in the main and performs pretty printing using
the `Display` trait.

Before:

    Error: FailedCreatingListener(SocketError(Os { code: 98, kind:
        AddrInUse, message: "Address already in use" }))

After:

    [2023-07-06T17:20:47Z ERROR vhost_device_scsi] Failed creating
        listener: socket error: Address already in use (os error 98)

vhost-device-vsock is a bit special since it does not let error messages
bubble up to the main. It also does .unwrap() in most places, but it
_does_  pretty print errors during the main request handling part.

Had to slightly adjust the coverage since we have no tests for the main
functions.

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