Commit Graph

264 Commits

Author SHA1 Message Date
Sebastien Boeuf
47be87c7cc virtio-devices: vhost_user: Don't set features before ACK from guest
The VIRTIO features should not be set before they are acked from the
guest. This code was only present to overcome a vhost crate limitation
that was expecting the VIRTIO features to be set before we could fetch
and set the protocol features.

The vhost crate has been recently fixed by removing the limitation,
therefore there's no need for this workaround in the Cloud Hypervisor
codebase anymore.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-05-24 00:34:46 +02:00
Sebastien Boeuf
f583f993ee virtio-devices: Remove the need for net_util in the crate
Everything that was shared in the net_util.rs file has been now moved to
the net_util crate. The only remaining bit was only used by the
virtio-net implementation, that is why this commit moves this code to
virtio-net, and since there's nothing left in net_util.rs, it can be
removed.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-05-21 14:39:56 +02:00
Sebastien Boeuf
bcb1dfb86f virtio-devices: net: Rely on net_util crate for control queue
Since the net_util crate contains the common code needed for processing
the control queue, let's use it and remove the duplicate from inside the
virtio-devices crate.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-05-21 14:39:56 +02:00
Sebastien Boeuf
d7a69f8aa1 net_util: Move virtio-net helpers to net_util crate
Moving helpers to the net_util crate since we don't want virtio-net
common code to be split between two places. The net_util crate should be
the only place to host virtio-net common code.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-05-21 14:39:56 +02:00
Sebastien Boeuf
f36b5f3e3c virtio-devices: vhost_user: Factorize features negotiation
Factorize the virtio features and vhost-user protocol features
negotiation through a common function that blk, fs and net
implementations can directly rely on.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-05-21 12:03:54 +02:00
Sebastien Boeuf
cdaa4d3ad7 virtio-devices: vhost_user: Set features once acknowledged by guest
Make sure the virtio features are set upon device activation. At the
time the device is activated, we know the guest acknowledged the
features, which mean it's safe to set them back to the backend.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-05-21 12:03:54 +02:00
Sebastien Boeuf
8c73af048a virtio-devices: vhost_user: fs: Cleanup device creation
Prepare the device creation so that it can be factorized in a follow up
commit.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-05-21 12:03:54 +02:00
Sebastien Boeuf
e2121c5d75 virtio-devices: vhost_user: net: Cleanup device creation
Prepare the device creation so that it can be factorized in a follow up
commit.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-05-21 12:03:54 +02:00
Sebastien Boeuf
9a7199a116 virtio-devices: vhost_user: blk: Cleanup device creation
Prepare the device creation so that it can be factorized in a follow up
commit.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-05-21 12:03:54 +02:00
Rob Bradford
c05010887f virtio-devices: seccomp: Cleanup unused seccomp filter entries
The threads in question are no longer created and so no longer need
seccomp rules for them.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-05-19 18:21:47 +02:00
Sebastien Boeuf
334aa8c941 virtio-devices: vhost_user: Don't set features twice
The virtio features are negotiated and set at the time the device is
created, hence there's no need to set the features again while going
through the vhost-user setup that is performed upon queue activation.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-05-19 18:21:47 +02:00
Sebastien Boeuf
5d2df70a79 virtio-devices: vhost_user: net: Remove control queue
Now that the control queue is correctly handled by the backend, there's
no need to handle it as well from the VMM.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-05-19 18:21:47 +02:00
Dayu Liu
8160c2884b docs: Fix some typos in docs and comments
Fix some typos or misspellings without functional change.

Signed-off-by: Dayu Liu <liu.dayu@zte.com.cn>
2021-05-18 17:19:12 +01:00
Sebastien Boeuf
355e7468e4 virtio-devices: vhost-user: Don't run threads for net and block
Some refactoring is performed in order to always expect the irqfd to be
provided by VirtioInterrupt trait. In case no irqfd is available, we
simply fail initializing the vhost-user device. This allows for further
simplification since we can assume the interrupt will always be
triggered directly by the vhost-user backend without proxying through
the VMM. This allows for complete removal of the dedicated thread for
both block and net.

vhost-user-fs is a bit more complex as it requires the slave request
protocol feature in order to support DAX. That's why we still need the
VMM to interfere and therefore run a dedicated thread for it.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-05-13 09:16:27 +01:00
Rob Bradford
496ceed1d0 misc: Remove unnecessary "extern crate"
Now all crates use edition = "2018" then the majority of the "extern
crate" statements can be removed. Only those for importing macros need
to remain.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-05-12 17:26:11 +02:00
Rob Bradford
bd724fc304 virtio-devices: Stop deriving unnecessary traits
These structs only need to derive Versionize now.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-05-12 17:26:11 +02:00
Rob Bradford
6e6f66de2e build: Bulk upgrade dependencies including fuzz
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-05-12 13:57:16 +01:00
Rob Bradford
b8f5911c4e misc: Remove unused errors from public interface
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-05-11 13:37:19 +02:00
Rob Bradford
c400702272 virtio-devices: Version state structures
Version the state for device state for the virtio devices.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-05-10 14:40:27 +01:00
Rob Bradford
0d3c5c966b virtio-devices: mem: Address clippy issue
error: all if blocks contain the same code at the start
   --> virtio-devices/src/mem.rs:508:9
    |
508 | /         if plug {
509 | |             let handlers =
    self.dma_mapping_handlers.lock().unwrap();
    |
|_____________________________________________________________________^
    |
    = note: `-D clippy::branches-sharing-code` implied by `-D warnings`
    = help: for further information visit
https://rust-lang.github.io/rust-clippy/master/index.html#branches_sharing_code
help: consider moving the start statements out like this
    |
508 |         let handlers = self.dma_mapping_handlers.lock().unwrap();
509 |         if plug {
    |

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-05-07 14:31:57 +02:00
Rob Bradford
18012d9ee8 virtio-devices: iommu: Address clippy issue
error: usage of `contains_key` followed by `insert` on a `BTreeMap`
   --> virtio-devices/src/iommu.rs:439:17
    |
439 | /                 if !mappings.contains_key(&domain) {
440 | |                     mappings.insert(domain, BTreeMap::new());
441 | |                 }
    | |_________________^ help: try this:
`mappings.entry(domain).or_insert_with(|| BTreeMap::new());`
    |
    = note: `-D clippy::map-entry` implied by `-D warnings`
    = help: for further information visit
https://rust-lang.github.io/rust-clippy/master/index.html#map_entry

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-05-07 14:31:57 +02:00
Rob Bradford
a6da5f9e77 virtio-devices: vsock: Address clippy issue
Issue from beta version of clippy:

  --> virtio-devices/src/vsock/csm/txbuf.rs:69:34
   |
69 |                 Box::new(unsafe {mem::MaybeUninit::<[u8;
   Self::SIZE]>::uninit().assume_init()}));
   |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[deny(clippy::uninit_assumed_init)]` on by default
   = help: for further information visit
https://rust-lang.github.io/rust-clippy/master/index.html#uninit_assumed_init

Fix backported Firecracker a8c9dffad439557081f3435a7819bf89b87870e7.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-05-07 14:31:57 +02:00
Rob Bradford
c418074360 virtio-devices: vhost_user: fs: Don't reference packed struct
error: reference to packed field is unaligned
  --> virtio-devices/src/vhost_user/fs.rs:85:21
   |
85 |                     fs.flags[i].bits() as i32,
   |                     ^^^^^^^^^^^
   |
   = note: `-D unaligned-references` implied by `-D warnings`
   = 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: Rob Bradford <robert.bradford@intel.com>
2021-05-07 14:31:57 +02:00
Yi Wang
1adcf5225b virtio-device: fix some misspelled words in comment
Fix some trivial spelling problem.
No functional change.

Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
2021-05-07 09:07:36 +02:00
Sebastien Boeuf
b5c6b04b36 virtio-devices, vmm: vhost: net: Add client mode support
Adding the support for an OVS vhost-user backend to connect as the
vhost-user client. This means we introduce with this patch a new
option to our `--net` parameter. This option is called 'server' in order
to ask the VMM to run as the server for the vhost-user socket.

Fixes #1745

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-05-05 16:05:51 +02:00
Rob Bradford
656b9f97f9 virtio-devices: net: Loop over enabled queue pairs when activating
In some situations (booting with OVMF) fewer queues will be enabled
therefore we should iterate over the number of enabled queues (as passed
into VirtioDevice::activate()) rather than the number of create tap
devices.

Fixes: #2578

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-05-05 10:19:38 +02:00
Rob Bradford
51a93bc635 virtio-devices: net: Add support for VIRTIO_NET_F_CTRL_GUEST_OFFLOADS
This allows the guest to reprogram the offload settings and mitigates
issues where the Linux kernel tries to reprogram the queues even when
the feature is not advertised.

Fixes: #2528

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-04-29 10:02:10 +02:00
Rob Bradford
9ef1a68539 virtio-devices: net: Remove unnecessary Option<> around tap
This doesn't serve any benefit and just makes the code more complex.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-04-29 10:02:10 +02:00
Rob Bradford
fbc7011346 virtio-devices: net: Tolerate unsupported control queue commands
Rather than erroring out and stalling the queue instead report an error
message if the command is invalid and return an error to the guest via
the status field.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-04-29 10:02:10 +02:00
Rob Bradford
2f2bd927b3 virtio-devices: net: Remove unnecessary Clone for NetCtrl
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-04-29 10:02:10 +02:00
Rob Bradford
bd90938f08 virtio-devices: Rename CtrlVirtio to NetCtrl
This better represents its purpose.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-04-29 10:02:10 +02:00
Rob Bradford
4806357f52 virtio-devices: net: Cleanup the MQ handling in the control queue
Cleanup the control queue handling in preparation for supporting
alternative commands.

Note that this change does not make the MQ handling spec compliant.
According to the specification MQ should only be enabled once the number
of queue pairs the guest would like to use has been specified. The only
improvement towards the specication in this change is correct error
handling if the guest specifies an inappropriate number of queues (out
of range.)

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-04-29 10:02:10 +02:00
dependabot-preview[bot]
1bad026377 build(deps): bump libc from 0.2.93 to 0.2.94
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.93 to 0.2.94.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.93...0.2.94)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-04-28 07:02:14 +00:00
Rob Bradford
375382cb08 virtio-devices: net: Advertise full set of offload features
This is based on the offload features that can be configured on the tap.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-04-26 18:40:05 +02:00
Rob Bradford
f213083386 virtio-devices: net: Set tap offload features based on those negotiated
Configure the tap offload features to match those that the guest has
acknowledged. The function for converting virtio to tap features came
from crosvm:
4786cee521/devices/src/virtio/net.rs (115)

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-04-26 18:40:05 +02:00
Rob Bradford
dab1cab4a7 virtio-devices: Simplify device state to support Versionize
In order to support using Versionize for state structures it is necessary
to use simpler, primitive, data types in the state definitions used for
snapshot restore.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-04-23 14:24:16 +01:00
Rob Bradford
da58b65997 virtio-devices: net: Support rebooting when tap fd specfied
Duplicate the fd that is specified in the config so that be used again
after a reboot. When rebooting we destroy all VM state and restore from
the config.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-04-22 12:19:01 +02:00
Rob Bradford
bfc65bff2a virtio-devices: transport: Naturally align capability PCI bar
The PCI bar should be naturally aligned i.e. aligned to the size of the
bar itself.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-04-21 16:11:54 +01:00
Rob Bradford
85f7913bb3 virtio-devices: pci_device: Deserialise section directly to state
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-04-20 18:58:37 +02:00
Rob Bradford
0c1c8881ef virtio-devices, block_util: Automatically serialized packed structs
With current serde_derive it is possible to #[derive(Serialize)] on
packed structures if they implement Copy. This allows the removal of the
manual equivalent code.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-04-16 13:27:03 +01:00
Rob Bradford
6f5d4702d4 misc: Simplify snapshot/restore by using helper functions
Simplify snapshot & restore code by using generics to specify helper
functions that take / make a Serialize / Deserialize struct

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-04-08 16:17:14 +01:00
dependabot-preview[bot]
23411d45ba build(deps): bump libc from 0.2.92 to 0.2.93
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.92 to 0.2.93.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.92...0.2.93)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-04-06 17:03:25 +00:00
dependabot-preview[bot]
d052b9ec12 build(deps): bump seccomp from v0.22.0 to v0.24.2
Bumps [seccomp](https://github.com/firecracker-microvm/firecracker) from v0.22.0 to v0.24.2.
- [Release notes](https://github.com/firecracker-microvm/firecracker/releases)
- [Changelog](5ba819d7b7/CHANGELOG.md)
- [Commits](cc5387637c...5ba819d7b7)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-04-05 21:34:34 +01:00
Bo Chen
32ad4982dd virtio-devices: Add rate limiter for the RX queue of virtio-net
Fixes: #1286

Signed-off-by: Bo Chen <chen.bo@intel.com>
2021-03-30 19:47:43 +02:00
Bo Chen
b176ddfe2a virtio-devices, vmm: Add rate limiter for the TX queue of virtio-net
Partially fixes: #1286

Signed-off-by: Bo Chen <chen.bo@intel.com>
2021-03-30 19:47:43 +02:00
Bo Chen
bfa37f89c4 virtio-devices: net: Refactor 'handle_tx_event'
This patch moves out the actual processing on the TX queue from the
`handle_tx_event()` function into a separate function,
e.g. `process_tx()`. This allows us to resume the TX queue processing
without reading from the TX queue EventFd, which is needed for rate
limiting support.

No functional change.

Signed-off-by: Bo Chen <chen.bo@intel.com>
2021-03-30 19:47:43 +02:00
Bo Chen
ee871278ee virtio-devices: Move the 'rate_limiter' module to its own crate
To support I/O throttling on virt-net devices, we need to use the
'rate_limiter' module from the 'net_utils' crate. Given the
'virtio-devices' crate has dependency on the 'net_utils', we will need
to move the 'rate_limiter' module out of the 'virtio-devices' crate to
avoid circular dependency issue. Considering the 'rate_limiter' is not
virtio specific and could be reused for non virtio devices, we move it
to its own crate.

Signed-off-by: Bo Chen <chen.bo@intel.com>
2021-03-30 19:47:43 +02:00
dependabot-preview[bot]
b8311cac38 build(deps): bump libc from 0.2.91 to 0.2.92
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.91 to 0.2.92.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.91...0.2.92)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-30 12:09:56 +00:00
Gaelan Steele
b16fdb1b3a virtio-devices: use Option::map
It's more concise, more idiomatic Rust, and satisfies nightly clippy.

Signed-off-by: Gaelan Steele <gbs@canishe.com>
2021-03-29 09:55:29 +02:00
Rob Bradford
827229d8e4 pci: Address Rust 1.51.0 clippy issue (upper_case_acroynms)
warning: name `IORegion` contains a capitalized acronym
   --> pci/src/configuration.rs:320:5
    |
320 |     IORegion = 0x01,
    |     ^^^^^^^^ help: consider making the acronym lowercase, except the initial letter (notice the capitalization): `IoRegion`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-03-26 11:32:09 +00:00