vhost-device/vhost-device-can
dependabot[bot] 9040bcb726 build(deps): bump the rust-vmm group across 2 directories with 6 updates
Bumps the rust-vmm group with 6 updates in the / directory:

| Package | From | To |
| --- | --- | --- |
| [vhost](https://github.com/rust-vmm/vhost) | `0.14.0` | `0.15.0` |
| [vhost-user-backend](https://github.com/rust-vmm/vhost) | `0.20.0` | `0.21.0` |
| [virtio-queue](https://github.com/rust-vmm/vm-virtio) | `0.16.0` | `0.17.0` |
| [vm-memory](https://github.com/rust-vmm/vm-memory) | `0.16.2` | `0.17.1` |
| [vmm-sys-util](https://github.com/rust-vmm/vmm-sys-util) | `0.14.0` | `0.15.0` |
| [virtio-vsock](https://github.com/rust-vmm/vm-virtio) | `0.10.0` | `0.11.0` |

Bumps the rust-vmm group with 5 updates in the /staging directory:

| Package | From | To |
| --- | --- | --- |
| [vhost](https://github.com/rust-vmm/vhost) | `0.14.0` | `0.15.0` |
| [vhost-user-backend](https://github.com/rust-vmm/vhost) | `0.20.0` | `0.21.0` |
| [virtio-queue](https://github.com/rust-vmm/vm-virtio) | `0.16.0` | `0.17.0` |
| [vm-memory](https://github.com/rust-vmm/vm-memory) | `0.16.2` | `0.17.1` |
| [vmm-sys-util](https://github.com/rust-vmm/vmm-sys-util) | `0.14.0` | `0.15.0` |

Updates `vhost` from 0.14.0 to 0.15.0
- [Release notes](https://github.com/rust-vmm/vhost/releases)
- [Commits](https://github.com/rust-vmm/vhost/compare/vhost-v0.14.0...vhost-v0.15.0)

Updates `vhost-user-backend` from 0.20.0 to 0.21.0
- [Release notes](https://github.com/rust-vmm/vhost/releases)
- [Commits](https://github.com/rust-vmm/vhost/compare/vhost-user-backend-v0.20.0...vhost-user-backend-v0.21.0)

Updates `virtio-queue` from 0.16.0 to 0.17.0
- [Release notes](https://github.com/rust-vmm/vm-virtio/releases)
- [Commits](https://github.com/rust-vmm/vm-virtio/compare/virtio-queue-v0.16.0...virtio-queue-v0.17.0)

Updates `vm-memory` from 0.16.2 to 0.17.1
- [Release notes](https://github.com/rust-vmm/vm-memory/releases)
- [Changelog](https://github.com/rust-vmm/vm-memory/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-vmm/vm-memory/compare/v0.16.2...v0.17.1)

Updates `vmm-sys-util` from 0.14.0 to 0.15.0
- [Release notes](https://github.com/rust-vmm/vmm-sys-util/releases)
- [Changelog](https://github.com/rust-vmm/vmm-sys-util/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-vmm/vmm-sys-util/compare/v0.14.0...v0.15.0)

Updates `virtio-vsock` from 0.10.0 to 0.11.0
- [Release notes](https://github.com/rust-vmm/vm-virtio/releases)
- [Commits](https://github.com/rust-vmm/vm-virtio/compare/virtio-vsock-v0.10.0...virtio-vsock-v0.11.0)

Updates `vhost` from 0.14.0 to 0.15.0
- [Release notes](https://github.com/rust-vmm/vhost/releases)
- [Commits](https://github.com/rust-vmm/vhost/compare/vhost-v0.14.0...vhost-v0.15.0)

Updates `vhost-user-backend` from 0.20.0 to 0.21.0
- [Release notes](https://github.com/rust-vmm/vhost/releases)
- [Commits](https://github.com/rust-vmm/vhost/compare/vhost-user-backend-v0.20.0...vhost-user-backend-v0.21.0)

Updates `virtio-queue` from 0.16.0 to 0.17.0
- [Release notes](https://github.com/rust-vmm/vm-virtio/releases)
- [Commits](https://github.com/rust-vmm/vm-virtio/compare/virtio-queue-v0.16.0...virtio-queue-v0.17.0)

Updates `vm-memory` from 0.16.2 to 0.17.1
- [Release notes](https://github.com/rust-vmm/vm-memory/releases)
- [Changelog](https://github.com/rust-vmm/vm-memory/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-vmm/vm-memory/compare/v0.16.2...v0.17.1)

Updates `vmm-sys-util` from 0.14.0 to 0.15.0
- [Release notes](https://github.com/rust-vmm/vmm-sys-util/releases)
- [Changelog](https://github.com/rust-vmm/vmm-sys-util/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-vmm/vmm-sys-util/compare/v0.14.0...v0.15.0)

Updates `vhost` from 0.14.0 to 0.15.0
- [Release notes](https://github.com/rust-vmm/vhost/releases)
- [Commits](https://github.com/rust-vmm/vhost/compare/vhost-v0.14.0...vhost-v0.15.0)

Updates `vhost-user-backend` from 0.20.0 to 0.21.0
- [Release notes](https://github.com/rust-vmm/vhost/releases)
- [Commits](https://github.com/rust-vmm/vhost/compare/vhost-user-backend-v0.20.0...vhost-user-backend-v0.21.0)

Updates `virtio-queue` from 0.16.0 to 0.17.0
- [Release notes](https://github.com/rust-vmm/vm-virtio/releases)
- [Commits](https://github.com/rust-vmm/vm-virtio/compare/virtio-queue-v0.16.0...virtio-queue-v0.17.0)

Updates `vm-memory` from 0.16.2 to 0.17.1
- [Release notes](https://github.com/rust-vmm/vm-memory/releases)
- [Changelog](https://github.com/rust-vmm/vm-memory/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-vmm/vm-memory/compare/v0.16.2...v0.17.1)

Updates `vmm-sys-util` from 0.14.0 to 0.15.0
- [Release notes](https://github.com/rust-vmm/vmm-sys-util/releases)
- [Changelog](https://github.com/rust-vmm/vmm-sys-util/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-vmm/vmm-sys-util/compare/v0.14.0...v0.15.0)

Updates `vhost` from 0.14.0 to 0.15.0
- [Release notes](https://github.com/rust-vmm/vhost/releases)
- [Commits](https://github.com/rust-vmm/vhost/compare/vhost-v0.14.0...vhost-v0.15.0)

Updates `vhost-user-backend` from 0.20.0 to 0.21.0
- [Release notes](https://github.com/rust-vmm/vhost/releases)
- [Commits](https://github.com/rust-vmm/vhost/compare/vhost-user-backend-v0.20.0...vhost-user-backend-v0.21.0)

Updates `virtio-queue` from 0.16.0 to 0.17.0
- [Release notes](https://github.com/rust-vmm/vm-virtio/releases)
- [Commits](https://github.com/rust-vmm/vm-virtio/compare/virtio-queue-v0.16.0...virtio-queue-v0.17.0)

Updates `vm-memory` from 0.16.2 to 0.17.1
- [Release notes](https://github.com/rust-vmm/vm-memory/releases)
- [Changelog](https://github.com/rust-vmm/vm-memory/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-vmm/vm-memory/compare/v0.16.2...v0.17.1)

Updates `vmm-sys-util` from 0.14.0 to 0.15.0
- [Release notes](https://github.com/rust-vmm/vmm-sys-util/releases)
- [Changelog](https://github.com/rust-vmm/vmm-sys-util/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-vmm/vmm-sys-util/compare/v0.14.0...v0.15.0)

---
updated-dependencies:
- dependency-name: vhost
  dependency-version: 0.15.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: vhost-user-backend
  dependency-version: 0.21.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: virtio-queue
  dependency-version: 0.17.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: vm-memory
  dependency-version: 0.17.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: vmm-sys-util
  dependency-version: 0.15.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: virtio-vsock
  dependency-version: 0.11.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: vhost
  dependency-version: 0.15.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: vhost-user-backend
  dependency-version: 0.21.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: virtio-queue
  dependency-version: 0.17.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: vm-memory
  dependency-version: 0.17.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: vmm-sys-util
  dependency-version: 0.15.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: vhost
  dependency-version: 0.15.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: vhost-user-backend
  dependency-version: 0.21.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: virtio-queue
  dependency-version: 0.17.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: vm-memory
  dependency-version: 0.17.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: vmm-sys-util
  dependency-version: 0.15.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: vhost
  dependency-version: 0.15.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: vhost-user-backend
  dependency-version: 0.21.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: virtio-queue
  dependency-version: 0.17.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: vm-memory
  dependency-version: 0.17.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
- dependency-name: vmm-sys-util
  dependency-version: 0.15.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-vmm
...

Signed-off-by: dependabot[bot] <support@github.com>
SG: adapted code to the new changes in vhost-user-backend and vm-memory:
  - used EventConsumer & EventNotifier instead of EventFd for exit_event
  - removed vm_memory::Error::InvalidGuestRegion
  - included vm_memory::Bytes needed for read_volatile_from
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2025-11-19 11:28:08 +02:00
..
src build(deps): bump the rust-vmm group across 2 directories with 6 updates 2025-11-19 11:28:08 +02:00
Cargo.toml build(deps): bump the rust-vmm group across 2 directories with 6 updates 2025-11-19 11:28:08 +02:00
CHANGELOG.md can: make features values conforming to the virtio spec 2025-10-10 17:06:07 +02:00
LICENSE-APACHE Move vhost-device-can on main workspace 2024-11-14 05:29:54 +02:00
LICENSE-BSD-3-Clause Move vhost-device-can on main workspace 2024-11-14 05:29:54 +02:00
README.md vhost-device-can: reformat synopsis and options 2025-09-12 14:22:27 +03:00

vhost-device-can - CAN emulation backend daemon

Description

This program is a vhost-user backend that emulates a VirtIO CAN device. The device's binary takes two (2) parameters: a socket, a 'can-devices' list. The socket is commonly used across all vhost-devices to communicate with the vhost-user frontend device. The 'can-devices' represents a list of CAN/FD devices appears in the host system which vhost-device-can will forward messages to and from the frontend side.

This program is tested with QEMU's vhost-user-device-pci device. Examples' section below.

Synopsis

vhost-device-can [OPTIONS] --socket-path <SOCKET> --can-devices <CAN_DEVICES>

Options

 -h, --help

  Print help.

 -s, --socket-path=PATH

  Location of vhost-user Unix domain sockets, this path will be suffixed with
  0,1,2..socket_count-1.

 -c, --socket-count=INT

  Number of guests (sockets) to attach to, default set to 1.

 -d, --can-devices='CAN/FD interfaces'

  CAN/FD device list at the host OS in the format:
      <can-_X_0> [<can_in_X_1>] ... [<can_in_X_N-1>]

  Note 1: Where N (the number of CAN/FD interfaces) is equal with the number
          provided via *socket_count* parameter.

      Example: --can-devices "can0 can1 can2"

Features

This device is still work-in-progress (WIP) and on virtio-spec v1.4 is based on virtio-can Linux's driver and QEMU's device presented in the following RFC:

Vhost-device-can have be been tested in scenarios with multiple QEMU's VMs using host's CAN/FD devices.

Limitations

  1. The transmission of a CAN/FD frame to a host interface always is done synchronously. This means that regardless the negotiation or not of the feature VIRTIO_CAN_F_LATE_TX_ACK, the backend will always wait for the transmission of the frame and after will mark the transmission request as used.
  2. Does not check for undefined flags in CAN/FD frame when send and receive a CAN/FD frame from the frontend (QEMU device).
  3. The host's CAN/FD devices should be already in UP state before staring the vhost-device-can (by using ip link set can0 [up,down]).
    • The control messages does not actually change host's device state
  4. Current version of the device has been tested only with vcan device.

Examples

Dependencies

For testing the device the required dependencies are:

Test the device

The daemon should be started first:

host# vhost-device-can --socket-path=can.sock --can-devices="vcan0"

The QEMU invocation needs to create a chardev socket the device can use to communicate as well as share the guests memory over a memfd.

There are two option for running QEMU with vhost-device-can:

  1. Using vhost-user-device-pci available upstream since QEMU v8.2.0:
host# qemu-system                                                                    \
    -m 4096                                                                          \
    -numa node,memdev=mem                                                            \
    -object memory-backend-memfd,id=mem,size=4G,share=on                             \
    -chardev socket,id=can0,path=/tmp/can.sock                                       \
    -device vhost-user-device-pci,chardev=can0,virtio-id=36,num_vqs=3,config_size=16 \
    ...
  1. Using vhost-user-can-pci:
host# qemu-system                                         \
    -m 4096                                               \
    -numa node,memdev=mem                                 \
    -object memory-backend-memfd,id=mem,size=4G,share=on  \
    -chardev socket,path=/tmp/can.sock,id=can0            \
    -device vhost-user-can-pci,chardev=can0,id=can        \
    ...

Note: For testing this scenario the reader needs to clone the QEMU version from the following repo which implements vhost-user-can device:

Multi-Guest case

Run vhost-device-can as:

./vhost-device-can --socket-path /tmp/can.sock  --socket-count 2 --can-devices "vcan0 vcan1"

This command will start the device and create two new sockets: /tmp/can.sock0 and /tmp/can.sock1.

From the other side we run two QEMU instances (VMs) with vhost-user-can:

host# qemu-system                                         \
    -m 4096                                               \
    -numa node,memdev=mem                                 \
    -object memory-backend-memfd,id=mem,size=4G,share=on  \
    -chardev socket,path=<SOCKET_PATH>,id=can0            \
    -device vhost-user-can-pci,chardev=can0,id=can        \
    ...

In the first instance of QEMU SOCKET_PATH would be: /tmp/can.sock0, and will use can0 (host interface) as sender and receiver. The second QEMU VM would have: SOCKET_PATH = /tmp/can.sock1, and will use can1 as receiver and can2 as sender.

License

This project is licensed under either of