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>
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
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>
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>
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>
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>
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>
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>
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>
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>
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
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Use the new GuestAddressSpace trait to simplify the implementation,
avoiding carrying on a lifetime parameter.
Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
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>