Commit graph

110 commits

Author SHA1 Message Date
Laura Loghin
a4802f6362 update coverage
The coverage test started failing in the following PR:
https://github.com/rust-vmm/vhost/pull/73, which only
modified the codeowners file. It is probably a kcov bug.

Signed-off-by: Laura Loghin <lauralg@amazon.com>
2021-09-02 15:40:44 +03:00
dependabot[bot]
d19202c3bf build(deps): bump rust-vmm-ci from a00c7d2 to 1311bfa
Bumps [rust-vmm-ci](https://github.com/rust-vmm/rust-vmm-ci) from `a00c7d2` to `1311bfa`.
- [Release notes](https://github.com/rust-vmm/rust-vmm-ci/releases)
- [Commits](a00c7d2f1b...1311bfa03f)

---
updated-dependencies:
- dependency-name: rust-vmm-ci
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-02 15:40:44 +03:00
Stefano Garzarella
af637585b8 CODEOWNERS: add stefano-garzarella
Add myself to CODEOWNERS to help with reviews and maintaining
this code.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2021-08-31 16:48:22 +08:00
Alyssa Ross
ccaf8c56bf vhost_user: enforce ByteValued for recv-d structs
Converting arbitrary bytes into an arbitrary Rust value is unsafe.
For example, it's unsafe to create a String that isn't valid UTF-8.
But the various internal recv* functions didn't restrict their return
types enough to enforce this invariant, making them unsafe without
being properly marked.

To fix this, we tighten up the bounds of the functions to enforce that
their return types are ByteValued, meaning that they can only be used
to create types that are safe to initialize with arbitrary data such
as might be received over a socket.

It's worth asking how these functions could have been unsafe in the
first place, since they don't contain any unsafe blocks themselves.
The answer is that the functions that recv into iovecs are also unsafe
but not correctly marked.  I'm preparing further patches to fix that
up, but it's a lot of work so I've separated out this change in the
hope of getting it in first and making the diff for the next one
smaller.

This internal tightening shouldn't result in any public API changes.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
2021-08-11 22:17:42 +08:00
Liu Jiang
14d754c5c7 Fix an error in license statement
"Apache-2.0 or BSD-3-Clause" is not an valid license statement and is
rejected by cargo. So change it to "Apache-2.0 OR BSD-3-Clause".

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-08-06 10:23:50 +02:00
Liu Jiang
56ad2ae4dd Prepare for release v0.1
Rename LICENSE-BSD-Chromium as LICENSE-BSD-Google to match the
reference in source file. Also remoce LICENSE-BSD-3-Clause, all code
contributed by Alibaba is licensed under Apache 2.0.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-08-05 17:51:35 +02:00
Alyssa Ross
2fe5de96f0 vhost_user: fix struct name in Debug impl
I think this might have been a remnant of the example in the fmt
documentation![1]

[1]: https://doc.rust-lang.org/stable/core/fmt/trait.Debug.html#examples

Signed-off-by: Alyssa Ross <hi@alyssa.is>
2021-08-05 10:28:58 +02:00
Sebastien Boeuf
37a6a8e464 Fix set_log_base() implementation for vhost-user
The SET_LOG_BASE implementation was incomplete as it didn't include the
ability to send the shared memory region information along with the file
descriptor.

This is required to perform proper dirty page logging with a vhost-user
device.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-08-04 16:44:05 +08:00
Sebastien Boeuf
868181c1fa Derive Default, Clone and Copy for VringConfigData
It is helpful for the consumer of this crate to be able clone and copy
the VringConfigData structure, as well as being able to initialize it
only partially thanks to the Default trait.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-08-04 09:55:52 +02:00
dependabot[bot]
9a1aa0b3c7 build(deps): bump rust-vmm-ci from 7693628 to a00c7d2
Bumps [rust-vmm-ci](https://github.com/rust-vmm/rust-vmm-ci) from `7693628` to `a00c7d2`.
- [Release notes](https://github.com/rust-vmm/rust-vmm-ci/releases)
- [Commits](7693628035...a00c7d2f1b)

---
updated-dependencies:
- dependency-name: rust-vmm-ci
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-03 09:50:08 +01:00
Liu Jiang
0c607bb299 update vm-memory requirement from 0.2.0 to 0.5.0
build(deps): update vm-memory requirement from 0.2.0 to 0.5.0
Updates the requirements on
[vm-memory](https://github.com/rust-vmm/vm-memory) to permit the latest
version.

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-07-29 18:37:01 +08:00
dependabot[bot]
0ed4dd50ef build(deps): bump rust-vmm-ci from d2ab3c0 to 7693628
Bumps [rust-vmm-ci](https://github.com/rust-vmm/rust-vmm-ci) from `d2ab3c0` to `7693628`.
- [Release notes](https://github.com/rust-vmm/rust-vmm-ci/releases)
- [Commits](d2ab3c0908...7693628035)

---
updated-dependencies:
- dependency-name: rust-vmm-ci
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-29 15:06:24 +08:00
wanglei01
488b3adc2f fix warning: unaligned_references
fix warning, when compiling with 1.53.0
```
warning: reference to packed field is unaligned
   --> src/vhost_user/message.rs:252:53
    |
252 |   unsafe { std::mem::transmute_copy::<u32, R>(&self.request) }
    |                                               ^^^^^^^^^^^^^
    |
    = note: `#[warn(unaligned_references)]` on by default
    = warning: this was previously accepted by the compiler but is being
      phased out; it will become a hard error in a future release!
    = note: for more information, see issue #82523
      <https://github.com/rust-lang/rust/issues/82523>
    = note: fields of packed structs are not properly aligned, and
      creating a misaligned reference is undefined behavior (even if
      that reference is never dereferenced)
```

Signed-off-by: wanglei <wllenyj@linux.alibaba.com>
2021-07-29 08:53:15 +02:00
Harshavardhan Unnibhavi
c1f77c778b Inflight I/O: Make struct members public
Signed-off-by: Harshavardhan Unnibhavi <harshanavkis@gmail.com>
2021-07-26 17:07:02 +08:00
Harshavardhan Unnibhavi
99fbfc9692 x86_64 coverage: reduce by 0.6
Signed-off-by: Harshavardhan Unnibhavi <harshanavkis@gmail.com>
2021-07-21 10:43:29 +02:00
Harshavardhan Unnibhavi
18ae8a991d Inflight I/O: Make structs and members public
Signed-off-by: Harshavardhan Unnibhavi <harshanavkis@gmail.com>
2021-07-21 10:43:29 +02:00
Keiichi Watanabe
12fa07029b vhost_user: Move utility function to mod.rs
Move take_single_file() to mod.rs as it is used in both master feature
and slave feature so that we can build the master feature without the
slave feature.

Signed-off-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-07-07 17:27:32 +02:00
Harshavardhan Unnibhavi
4c8a94065c x86_64 coverage: reduce by 0.8
Signed-off-by: Harshavardhan Unnibhavi <harshanavkis@gmail.com>
2021-07-07 14:30:54 +02:00
Harshavardhan Unnibhavi
39a98eaa80 Inflight I/O: Packed virtqueues queue regions
Signed-off-by: Harshavardhan Unnibhavi <harshanavkis@gmail.com>
2021-07-07 14:30:54 +02:00
Harshavardhan Unnibhavi
b273fd9f1e Inflight I/O: Split virtqueues queue regions
Signed-off-by: Harshavardhan Unnibhavi <harshanavkis@gmail.com>
2021-07-07 14:30:54 +02:00
dependabot[bot]
50b41b8477 build(deps): bump rust-vmm-ci from 6591890 to d2ab3c0
Bumps [rust-vmm-ci](https://github.com/rust-vmm/rust-vmm-ci) from `6591890` to `d2ab3c0`.
- [Release notes](https://github.com/rust-vmm/rust-vmm-ci/releases)
- [Commits](6591890ee1...d2ab3c0908)

---
updated-dependencies:
- dependency-name: rust-vmm-ci
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-02 11:16:05 +03:00
Keiichi Watanabe
9982541776 vhost_user: Stop passing around RawFd
Use `File` or `dyn AsRawFd` instead of `RawFd` to handle ownership
easily.
Fixes #37.

Signed-off-by: Keiichi Watanabe <keiichiw@chromium.org>
Change-Id: I6c79d73d1a54163d4612b0ca4d30bf7bd53f9b0f
2021-06-23 09:52:42 +02:00
Chirantan Ekbote
1a03a2aca7 Add SlaveReqHandler::from_stream
A device process may already have a connected socket to the VMM, for
example by inheriting one end of a socketpair() created by the parent
process.  Add a method to create a SlaveReqHandler directly from a
connected socket.

Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
2021-06-22 19:46:09 +08:00
dependabot[bot]
4a604d774f build(deps): bump rust-vmm-ci from 24d66cd to 6591890
Bumps [rust-vmm-ci](https://github.com/rust-vmm/rust-vmm-ci) from `24d66cd` to `6591890`.
- [Release notes](https://github.com/rust-vmm/rust-vmm-ci/releases)
- [Commits](24d66cdae6...6591890ee1)
2021-06-22 13:06:10 +02:00
Keiichi Watanabe
77b5aaf915 coverage: Update coverage_score
Signed-off-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-06-22 13:06:10 +02:00
Keiichi Watanabe
d980408824 pipeline: Bump docker version for custom clippy
Signed-off-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-06-22 13:06:10 +02:00
Keiichi Watanabe
4757091c61 vhost_user: Allow clippy::upper_case_acronyms
Allow enum names whose characters are all upper case such as `NOOP`.
This change is needed to uprev bump rust-vmm-ci's version at #46.

Signed-off-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-06-22 13:06:10 +02:00
Alex Bennée
2e4396c9cc slave_req_handler: relax reply_ack_flag test
In reality the real guest may never see the
VHOST_USER_F_PROTOCOL_FEATURES bit during the device feature
negotiation. It is explicitly marked as UNUSED in the VirtIO spec so
the it would be perfectly valid for it to be ignored by the virtio
driver. The vhost-user spec explicitly states about the GET/SET
PROTOCOL FEATURES messages:

   Slave that reported ``VHOST_USER_F_PROTOCOL_FEATURES`` must
   support this message even before ``VHOST_USER_SET_FEATURES`` was
   called.

which implies the final acked feature set shouldn't impact on the
negotiated VHOST_USER_PROTOCOL_F_REPLY_ACK feature. This prevents a
hang with the QEMU remote end which makes it's determination to ask
for a reply based only on the negotiated protocol feature set:

    virtio_has_feature(dev->protocol_features,
                       VHOST_USER_PROTOCOL_F_REPLY_ACK);

Let's be liberal in what we accept.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Cc: Michael S. Tsirkin <mst@redhat.com>
2021-06-17 15:19:00 +02:00
Sebastien Boeuf
e294ed66fc vhost_user: Fix NEED_REPLY for all messages
Except the list of commands from which we can expect a reply, all the
other commands should be able to reply with an acknowledgment if being
asked for.

For the commands such as SET_PROTOCOL_FEATURES, which usually happens
before the protocol features negotiation is complete, we should also be
able to reply with an ACK if needed. Indeed, the protocol features
negotiation could have happened earlier, which means we might expect a
reply ACK from GET_FEATURES command if this happens later on.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-06-16 14:53:09 +02:00
Sebastien Boeuf
a8ff939161 vhost_user: Add Inflight I/O tracking support
The inflight I/O tracking feature is useful for handling crashes and
disconnections from the backend. It allows the backend to rely on a
buffer that was shared earlier with the VMM to restore to the previous
state it was before the crash.

This feature depends on the availability of the protocol feature
VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD, and it implements both
VHOST_USER_GET_INFLIGHT_FD and VHOST_USER_SET_INFLIGHT_FD messages.

Fixes #43

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-06-11 13:51:37 +02:00
Sebastien Boeuf
30ba3e7bbe vhost_user: Add header flags support
Introduce a new method set_flags() in order to let the caller define the
expected set of flags that should be applied to the header for the
following messages.

Fixes #40

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-06-08 10:35:35 +02:00
Sebastien Boeuf
e4ba734144 vhost_user: Fix get/set protocol features
Based on the specification, one can call into
VHOST_USER_GET_PROTOCOL_FEATURES or VHOST_USER_SET_PROTOCOL_FEATURES
before VHOST_USER_SET_FEATURES.

The current code is wrong as it expects the VIRTIO features to be
already acknowledged at the time the protocol features are get/set.

Quote from the spec for both VHOST_USER_GET_PROTOCOL_FEATURES and
VHOST_USER_SET_PROTOCOL_FEATURES:

    Slave that reported VHOST_USER_F_PROTOCOL_FEATURES must support this
    message even before VHOST_USER_SET_FEATURES was called.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-05-21 10:43:08 +02:00
Keiichi Watanabe
f338330bd7 Add custom pipeline yaml for wider clippy coverage
Fixes #25.

Signed-off-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-05-18 16:01:08 +08:00
dependabot-preview[bot]
e5b930b73a Upgrade to GitHub-native Dependabot 2021-05-11 16:44:51 +03:00
Daniel Verkamp
cc4da710ac vhost_user: implement From instead of Into
Implementing From<...> provides the equivalent Into<..> automatically,
so this form is preferred.

Fixes the clippy from_over_into warning:

https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into

Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
2021-05-10 06:47:59 +02:00
Keiichi Watanabe
c4cd1d375e vhost_user: Fix check for SET_VRING_ENABLE
We should allow to receive SET_VRING_ENABLE request with non-zero index
even if MQ protocol feature is disabled because some device can have
multiple queues without the MQ feature.
e.g. virtio-net means that it supports multiple pairs of tx/rx queues.
So, the slave must support at least one pair of queues regardless of
whether MQ is supported.

Instead, make it check if VHOST_USER_F_PROTOCOL_FEATURES has been
negotiated.

Signed-off-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-04-28 16:39:47 +08:00
Stefano Garzarella
0e9fed2d75 Fix typos in the error messages
Replace 'virtque' with 'virtqueue' and 'talbe' with 'table'.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2021-04-05 10:43:33 +03:00
Dylan Reid
88aafc03a8 vhost_user: config offset matches qemu
Modify the interpretation of the set and get config offset field to
match qemu. The wording in the vhost user spec is ambiguous, bet lets
defer to qemu's implementation so vhost based devices can be used with
qemu as a VMM. Fixes #29.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: Ib1b909d02c3b7dab1964799f0a4d960f1ef308fa
2021-03-29 18:11:16 +08:00
dependabot-preview[bot]
05cd8b2ad3 build(deps): bump rust-vmm-ci from ebc7016 to 24d66cd
Bumps [rust-vmm-ci](https://github.com/rust-vmm/rust-vmm-ci) from `ebc7016` to `24d66cd`.
- [Release notes](https://github.com/rust-vmm/rust-vmm-ci/releases)
- [Commits](ebc701641f...24d66cdae6)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-18 14:17:10 +00:00
Sebastien Boeuf
ee3e872270 vhost_user: Add support for REM_MEM_REG
Adding support for a new message REM_MEM_REG. This command request an
existing memory region to be removed and unmapped from the vhost-user
backend.

It is designed for supporting memory hot-unplug, rather than using
SET_MEM_TABLE, which is less efficient as it would remap all remaining
regions.

It is only available if the protocol feature
VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS has been negotiated.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-03-10 23:37:29 +08:00
Sebastien Boeuf
7e3ab1af4e vhost_user: Add support for ADD_MEM_REG
Adding support for a new message ADD_MEM_REG. This command request a new
region to be added and mapped by the vhost-user backend.

It is designed for supporting memory hotplug, avoiding the limitation
from SET_MEM_TABLE (supports only 8 regions).

It is only available if the protocol feature
VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS has been negotiated.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-03-10 23:37:29 +08:00
Sebastien Boeuf
e7d46d6980 vhost_user: Add support for GET_MAX_MEM_SLOTS
Add the support for GET_MAX_MEM_SLOTS command. This requests the
vhost-user backend to provide the maximum amount of memory slots
that can be supported.

It is only available if the protocol feature
VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS has been negotiated.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-03-10 23:37:29 +08:00
Sebastien Boeuf
0bfb5a3180 vhost_user: Update list of message types
The vhost-user specification moved forward by adding more message types.
This commit extends the list according to the latest specification.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-03-10 23:37:29 +08:00
Dylan Reid
7784304860 Allow using Path/PathBuf for initialization
Instead of taking a `&str` for the path of the sockets, take
`AsRef<Path>`. This way users can pass `PathBuf`, `Path`, `String`, or
`&str`.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
2021-03-07 22:46:34 +01:00
Keiichi Watanabe
62fd4ec5a4 Fix clippy erros and warnings
Make `cargo clippy --all-features --all-targets` pass.

Signed-off-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-03-03 19:33:56 +08:00
Liu Jiang
576694bcfb Prepare for publishing to crates.io
Prepare for publishing to crates.io,
1) update README.md
2) update Cargo.toml
3) set code owners

It should be ready for publishing now.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-03-01 12:50:56 +01:00
Liu Jiang
e543bf2a8d vhost_user: add more negative unit test cases
Add more negative unit test cases to improve code coverage.
Also add two helper functions to simplify code.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-03-01 12:50:56 +01:00
Liu Jiang
ec6eae722e vhost_user: add more unit test cases
Add more unit test cases for vhost-user protocol.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-03-01 12:50:56 +01:00
Liu Jiang
56b823482b vhost_user: use read_aligned() to access data
Use std::ptr::read_aligned() to safely access data buffer instead of
directly accessing data struct in data buffer.

Also enforce stricter message size validation.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-03-01 12:50:56 +01:00
Liu Jiang
74c353bb5f vhost_user: add VhostUserSlaveReqHandlerMut trait
Rename the original VhostUserSlaveReqHandler trait as
VhostUserSlaveReqHandlerMut, and add another VhostUserSlaveReqHandler
trait with interior mutability.

This also help to simplify caller implementations.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-03-01 12:50:56 +01:00