Commit graph

144 commits

Author SHA1 Message Date
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
Liu Jiang
21b89b2ff5 vhost_user: fix a bug in SlaveReqHandler
An acknowlege reply message should be sent iif:
1) the VHOST_USER_PROTOCOL_F_REPLY_ACK feature is nogotiated,
2) the NEED_REPLY in header.flags is set.

Also enforce stricter validation for message size.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-03-01 12:50:56 +01:00
Liu Jiang
9e22e2fe2f vhost_user: refine connection implementation
Refine connection implementation by:
1) using "payload: &[u8]" for send_message_with_payload()
2) enabling all unit test cases

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-03-01 12:50:56 +01:00
Liu Jiang
dc452e5aeb vhost_user: fix bugs and refine message defintion
Fix two bugs:
1) in VhostUserConfigFlags definition
2) in validating VhostUserConfig

Refine vhost-user message definition by:
1) validate offset of VhostUserConfig
2) better documentation
3) more unit tests

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-03-01 12:50:56 +01:00
Liu Jiang
dcb79ab156 vhost_user: refine the SlaveFsCacheReq struct
Refine the SlaveFsCacheReq struct by:
1) honoring the negotiation result of VHOST_USER_PROTOCOL_F_REPLY_ACK,
2) better documentation,
3) adding unit test cases.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-03-01 12:50:56 +01:00
Liu Jiang
3b497e1fbe vhost-user: refine the MasterReqHandler trait
Refine the MasterReqHandler trait with:
1) better documentation,
2) abstracting as MasterReqHandler and MasterReqHandlerMut,
3) honoring the negotiation state of VHOST_USER_PROTOCOL_F_REPLY_ACK,
4) enhancing set_failed() to clear the error state,
5) validating field `size` in the received message header,
6) reading struct by std::ptr::read_unaligned instead of directly
   access the underlying buffer,

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-03-01 12:50:56 +01:00
Liu Jiang
fa089424f1 vhost_user: use sock_ctrl_msg from vmm-sys-util
Now the sock_ctrl_msg from the vmm-sys-util crate is ready for use,
so replace the locally copied version.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-03-01 12:50:56 +01:00
Liu Jiang
0a8b244934 vhost_kern/vsock: implemnt VhostVsock
Refine VhostVsock trait definition, and implement it for kernel
based vsock driver.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-03-01 12:50:56 +01:00
Liu Jiang
07eee11be3 vhost_kern: add more unit test cases
Add more unit test cases for vhost-kern submodule.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-03-01 12:50:56 +01:00
Liu Jiang
97421f754d Upgrade to rust 2018 edition
Upgrade Cargo.toml to rust edition 2018. Also introduce a helper
feature flag "vhost-user" to simplify code.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-03-01 12:50:56 +01:00
Liu Jiang
a7847dcf7d Update .gitignore file
Ignore build, build_kcov and .idea directories under the root.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-03-01 12:50:56 +01:00
Liu Jiang
d748d5bdcf Introduce VhostBackendMut trait
Originally the VhostBackend trait is designed to take a mutable self,
which causes a common usage pattern Arc<RwLock<T: VhostBackend>>.
This pattern may enforce serialization among multiple threads. So
rename the original VhostBackend as VhostBackendMut, and introduce a
new VhostBackend trait with interior mutability to improve performance
by removing the serialization.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2021-03-01 12:50:56 +01:00
dependabot-preview[bot]
8c6919bf60 build(deps): bump rust-vmm-ci from e58ea74 to ebc7016
Bumps [rust-vmm-ci](https://github.com/rust-vmm/rust-vmm-ci) from `e58ea74` to `ebc7016`.
- [Release notes](https://github.com/rust-vmm/rust-vmm-ci/releases)
- [Commits](e58ea7445a...ebc701641f)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-24 07:53:25 +00:00
Liu Jiang
6ccc681e7e vhost-user: enlarge supported number of vrings
Enlarge VHOST_USER_MAX_VRINGS from 0xff to 0x8000, there's devices
needing more vrings than 0xff.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2020-12-14 12:15:40 +01:00
Liu Jiang
fec84606e5 vhost-kern: fix a typo
vhost_SET_BACKEND should be VHOST_NET_SET_BACKEND.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2020-12-14 12:15:40 +01:00
Liu Jiang
a687687eb0 vhost-kern: upgrade to latest vm-memory crate
Use the new GuestAddressSpace trait to simplify the implementation,
avoiding carrying on a lifetime parameter.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2020-12-14 12:15:40 +01:00
Liu Jiang
ce094b25d2 vhost-kern: treat addrs in VringConfigData as HVA
The ring addresses in VringConfigData are host virtual addresses,
and the kernel vhost drivers also expect those addresses as HVA.
So it's wrong to validate/translate those addresses as GPA.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2020-12-14 12:15:40 +01:00