Commit Graph

918 Commits

Author SHA1 Message Date
dependabot[bot]
d3fa3a702e build(deps): bump rust-vmm-ci from be28ad8 to cf98097
Bumps [rust-vmm-ci](https://github.com/rust-vmm/rust-vmm-ci) from `be28ad8` to `cf98097`.
- [Commits](be28ad8e2c...cf9809721d)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-06 11:31:06 +05:30
Matias Ezequiel Vara Larsen
7a00d935f9 sound/test: add tests for device.rs
This commit adds tests in test_sound_thread_failure to test that
process_control() returns Err() in the following four conditions:
    * control request with a single descriptor
    * control request in which first descriptor is write-only
    * control request in which second descriptor is read-only
    * control request with less than three descriptors for control requests
      that require three, e.g., PcmInfo, ChmapInfo

Signed-off-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>
2023-11-02 16:19:54 +01:00
Manos Pitsidianakis
3416215092 sound: add virtualization in Cargo.toml categories
Previous commit added categories to Cargo.toml, but the only value was
`multimedia::audio`.

Thanks @stefano-garzarella for noticing I missed this.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-11-02 10:39:25 +01:00
Manos Pitsidianakis
a127c67578 CODEOWNERS: add epilys, remove mathieupoirier
Add self to CODEOWNERS to contribute with reviewing, merging other
PRs and maintaining the vhost-device-sound crate.

Also remove Mathieu Poirier, who is unavailable for maintainer duties at
this time.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-11-02 09:29:07 +00:00
Manos Pitsidianakis
90f547e98c sound: add clippy lint checks
Add basic lints to deny unidiomatic or potentially bad code.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-11-02 10:46:49 +05:30
Manos Pitsidianakis
75ca1ee428 sound: add package.categories field to Cargo.toml
Suggested by lint https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-11-02 10:46:49 +05:30
Manos Pitsidianakis
7255036df6 sound/pipewire: prevent unsigned sub overflow
A subtraction between unsigned integers is made, which by default panics
on overflow. However, we don't really need to know the difference, only
that it is not zero or less.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-11-02 10:46:49 +05:30
Dorinda Bassey
0f1eab60ec sound/pipewire: Add Pipewire Capture
Add pipewire capture to enable capturing for pipewire backend

Co-authored-by: Dorinda Bassey <dbassey@redhat.com>
Co-authored-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>

Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
2023-10-31 16:07:46 +05:30
Jeongik Cha
6d0f7f64e5 vsock: adding log for epoll_register error in send_pkt
like recv_pkt, added log for epoll_register error instead of panic
Signed-off-by: Jeongik Cha <jeongik@google.com>
2023-10-31 13:52:01 +05:30
Jeongik Cha
4b6451176d vsock: try epoll_modify before epoll_register in recv_pkt
in this context, epoll listener can be already registered via other TX
event, so let it try epoll_modify first to avoid 'silent' failure which
possibly drops packets.

Signed-off-by: Jeongik Cha <jeongik@google.com>
2023-10-31 13:52:01 +05:30
Dorinda Bassey
a2d9b2e721 sound: Improve function definition
instead of consume() fn name, use read_output() fn which
is more appropriate and in sync with the write_input() fn.

Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
2023-10-30 16:34:06 +05:30
dependabot[bot]
d09d501e1c build(deps): bump rust-vmm-ci from 0b9e2e2 to be28ad8
Bumps [rust-vmm-ci](https://github.com/rust-vmm/rust-vmm-ci) from `0b9e2e2` to `be28ad8`.
- [Commits](0b9e2e28ba...be28ad8e2c)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-30 09:57:25 +05:30
Stefano Garzarella
09e9da304c vsock: avoid circular references
We have the following circular references found by Li Zebin:
    VhostUserBackend ==> VhostUserVsockThread ==> VringEpollHandler

In addition to causing a resource leak, this causes also an error
after we merged commit 38caab2 ("vsock: Don't allow duplicate CIDs").
When the VM reboot or shutdown, the application exits with the
following error:

    [ERROR vhost_device_vsock] Could not create backend:
        CID already in use by another vsock device

This happened because we have these circular references and
VhostUserVsockThread::drop() is never invoked. So, we don't remove
the cid from the map.

Let's fix this problem by simply removing the reference to
VringEpollHandler from VhostUserVsockThread. In fact, we do not
need to keep the reference for the lifetime of VhostUserVsockThread,
as we only need to add the handlers once.

Let's also rename the fields to follow the current VhostUserDaemon
API.

Closes #438

Reported-by: Li Zebin <cutelizebin@gmail.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2023-10-27 16:13:37 +05:30
Manos Pitsidianakis
1921ec21d8 sound: Implement RX in ALSA backend
Add an RX code path that is similar to the existing TX code in the ALSA
backend.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-27 11:39:04 +01:00
Manos Pitsidianakis
d00014f5a6 sound: add Buffer::desc_len() method
Add a method to return the length of the descriptor memory region and
make `data_descriptor` field private.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-27 11:39:04 +01:00
Manos Pitsidianakis
31175bf66c sound: Add Direction enum
We use input/output direction values in many places, yet we lose Rust's
exhaustive static checks when matching for a stream's direction. This
commits adds a Direction enum and From/Into implementations for audio
backend respective direction types.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-27 16:04:31 +05:30
Stefano Garzarella
b2e3f0b1a7 Bump rust-vmm-ci manually to use rustvmm/dev:v28
This new version contains alsa and pipewire libraries to build
vhost-device-sound audio backends.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2023-10-26 15:07:38 +05:30
Manos Pitsidianakis
573e592037 sound: fix broken tests
Tests were not updated with changes in previous commits, so update them.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-25 12:53:44 +05:30
Albert Esteve
5993c1f6c1 staging: update coverage target
Signed-off-by: Albert Esteve <aesteve@redhat.com>
2023-10-24 19:09:41 +05:30
Manos Pitsidianakis
30d5cf4e10 sound: clean up and improve comments, definitions
- Add some documentation comments
- Rename TxState to IoState in preparation for RX implementation
- Fix inline rust code not being escaped properly in doc comments
- Rename some fields to make their function clearer
- Cleanup some error log messages
- Replace an old TODO comment about queue size with an explanation

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-24 11:08:26 +01:00
Manos Pitsidianakis
04f80fc8e9 sound: add latency_bytes field to IOMessage
The latency field specifies how long it will take until the device
finishes playing the I/O message's buffers.

Since the I/O message is dropped as soon as the last bytes are copied
over to the host's internal buffers, assume the message is dropped
almost after the host has started playing this buffer.

This solves the issue of a guest app exiting before the host has done
playing audio because it kept sending new buffers as fast as possible
without waiting (latency).

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-24 11:08:26 +01:00
Manos Pitsidianakis
2ba56bef25 sound/alsa: fix host hwparams calculation
The host's period and buffer sizes were not being calculated correctly.

This resulted in timing mismatches.

This commit calculates the correct sizes by taking the guest's
parameters into account.

Impossible cases when matching with stream parameters will lead to
unreachable!().

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-24 11:08:26 +01:00
Manos Pitsidianakis
84c58404b8 sound/alsa: fix consume() use for playback
Use of consume() method was incorrect. This commit fixes the buffer
bounds used with playback in ALSA.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-24 11:08:26 +01:00
Manos Pitsidianakis
c10b8e18c4 sound/alsa: stop actual playback after PCM_STOP
Queued buffers were played even after the guest issued PCM_STOP.

This commit:

- makes the ALSA worker threads respect the stopped status instead
- send a start signal to worker threads on PCM_START to handle
  pre-buffering
- reduce the time of playback callbacks holding the stream lock

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-24 11:08:26 +01:00
Manos Pitsidianakis
aa16ef0699 sound/pipewire: handle StreamWithIdNotFound consistently
When handling controlq messages, handle StreamWithIdNotFound the same
way on all methods:

- if we are passed a &mut ControlMessage, set it to
  VIRTIO_SND_S_BAD_MSG.
- if we are passed a stream_id, return StreamWithIdNotFound.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-24 11:08:26 +01:00
Manos Pitsidianakis
208a796061 sound/alsa: handle PCM state transition errors gracefully
Handle some state transition errors more gracefully by retrying ALSA
operations if possible. Also rewrite the PCM_RELEASE handler to make it
more clear.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-24 11:08:26 +01:00
Manos Pitsidianakis
33c977cc0f sound/alsa: Release buffers even on RELEASE err
If a PCM_RELEASE control request comes from the guest and the state
transition is invalid by spec standards, release the buffers anyway.
This doesn't change the current behavior.

When dealing with an unrelated vhost-user issue, the state transitions
became invalid because of unexpected errors in the virto-snd driver.
Making this change made the issue obvious while debugging. Plus, the
spec does not state rejecting a PCM lifecycle control request if the
transition is not possible. (The possible state transitions are
non-normative statements.)

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-24 11:08:26 +01:00
Albert Esteve
3921238555 video: add v4l2 mocks
Add v4l2 wrapper functions to be able
to mock (and test) v4l2r library responses
without the need of having a underlying video device.

Signed-off-by: Albert Esteve <aesteve@redhat.com>
2023-10-24 11:17:33 +02:00
Albert Esteve
cb4ec6ad12 video: fill readme
Complete the README file for the video crate
with the help information for the CLI, and a
working example to run and test the device.

Signed-off-by: Albert Esteve <aesteve@redhat.com>
2023-10-24 11:17:33 +02:00
Albert Esteve
f84ea414e3 video: add tests
Add test for all modules, with dev-dependencies
(including rstest [1] for parametrized tests), and
infrastructure.

[1] - https://docs.rs/rstest/latest/rstest/

Signed-off-by: Albert Esteve <aesteve@redhat.com>
2023-10-24 11:17:33 +02:00
Albert Esteve
72dc2e78f2 video: add v4l2-decoder backend
Add new v4l2-decoder backend, that
uses v4l2r [1] for interactions with the
video device in the host. Specialized for
Linux systems.

[1] - https://github.com/Gnurou/v4l2r

Signed-off-by: Albert Esteve <aesteve@redhat.com>
2023-10-24 11:17:33 +02:00
Albert Esteve
5edf1dfb7b video: initial skeleton
Initial skeleton for virtio-video crate.
This crate is based on the v3 of the virtio-video
specs patch[1].

It has a big part of the infrastructure
required, although not all commands are implemented,
and does not have any backend available.

Includes support for async responses to the driver
(through VIDEO_EVENT) to QueueResource messages.

[1] -
https://lists.oasis-open.org/archives/virtio-dev/202002/msg00002.html

Related: #364
Signed-off-by: Albert Esteve <aesteve@redhat.com>
2023-10-24 11:17:33 +02:00
Dorinda Bassey
1ccb3b6e58 sound/pipewire: add safety comments
Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
2023-10-24 14:19:24 +05:30
dependabot[bot]
c6f586d507 build(deps): bump rust-vmm-ci from 9751aaa to 4c55aa7
Bumps [rust-vmm-ci](https://github.com/rust-vmm/rust-vmm-ci) from `9751aaa` to `4c55aa7`.
- [Commits](9751aaa0d0...4c55aa732b)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-23 11:58:05 +05:30
dependabot[bot]
361cb51998 build(deps): bump the vhost-device group with 4 updates
Bumps the vhost-device group with 4 updates: [thiserror](https://github.com/dtolnay/thiserror), [hashbrown](https://github.com/rust-lang/hashbrown), [regex](https://github.com/rust-lang/regex) and [rustix](https://github.com/bytecodealliance/rustix).


Updates `thiserror` from 1.0.49 to 1.0.50
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](https://github.com/dtolnay/thiserror/compare/1.0.49...1.0.50)

Updates `hashbrown` from 0.14.1 to 0.14.2
- [Changelog](https://github.com/rust-lang/hashbrown/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/hashbrown/compare/v0.14.1...v0.14.2)

Updates `regex` from 1.10.1 to 1.10.2
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.10.1...1.10.2)

Updates `rustix` from 0.38.19 to 0.38.20
- [Release notes](https://github.com/bytecodealliance/rustix/releases)
- [Commits](https://github.com/bytecodealliance/rustix/compare/v0.38.19...v0.38.20)

---
updated-dependencies:
- dependency-name: thiserror
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: vhost-device
- dependency-name: hashbrown
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: vhost-device
- dependency-name: regex
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: vhost-device
- dependency-name: rustix
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: vhost-device
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-23 11:50:23 +05:30
Dorinda Bassey
cae9fd0f79 sound/test: add testing module for sound
add testing modules

Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
2023-10-20 18:35:29 +05:30
Dorinda Bassey
d04d6b42fc sound: Return error if no memory configured
Add option to return error if no memory is configured

Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
2023-10-20 18:35:29 +05:30
Dorinda Bassey
ab33111ecb sound/Cargo.toml: update dependencies
Update dependencies and add support for xen builds

Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
2023-10-20 18:35:29 +05:30
Stefano Garzarella
994ffe1864 staging: add custom pipelines to run CI tests
Let's use custom pipelines to run CI tests in the nested worskpace.

We have included all the tests we usually run in the main workspace
(rust-vmm-ci/.buildkite/test_description.json), except for "commit-format"
which also covers commits for staging crates.

Let's add a `staging\coverage_config_x86_64.json` for testing coverage of
crates in staging.

All staging tests have `soft_fail = true` to prevent failures in staging
from affecting the CI of the main workspace.

Closes #478

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2023-10-17 16:35:55 +05:30
Alex Bennée
eabf93f3d5 README.md: clearer language on staging devices
Lets be super clear and explicit about what it takes to include a
backend in the repository as well as the minimum requirements for
being included in staging.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2023-10-16 20:17:21 +05:30
Viresh Kumar
114cbe456b
Merge pull request #475 from epilys/virtio-sound-pr-2
Add vhost-user-sound crate
2023-10-16 18:20:15 +05:30
Manos Pitsidianakis
eb2e2227e4
Move vhost-device-sound to staging workspace
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-16 14:58:40 +03:00
Manos Pitsidianakis
3a089149be
Move crates/sound to vhost-device-sound
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-16 14:56:03 +03:00
Manos Pitsidianakis
de1c308c62
Rename vhost-user-sound to vhost-device-sound
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-16 14:53:32 +03:00
Manos Pitsidianakis
d40c707f2f
Merge remote-tracking branch 'upstream/main' into HEAD
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-16 14:48:56 +03:00
Manos Pitsidianakis
a1e013286f Move all crates to workspace root
Having all the workspace crates under the crates/ directory is
unnecessary. Rust documentation itself recommends all crates to be in
the root directory:

https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html#creating-the-second-package-in-the-workspace

I paste the text content here, in case the online page ever changes or
becomes unavailable:

    ## Creating the Second Package in the Workspace

    Next, let’s create another member package in the workspace and call it add_one. Change the top-level Cargo.toml to specify the add_one path in the members list:

    Filename: Cargo.toml

    [workspace]

    members = [
        "adder",
        "add_one",
    ]

    Then generate a new library crate named add_one:

    $ cargo new add_one --lib
         Created library `add_one` package

    Your add directory should now have these directories and files:

    ├── Cargo.lock
    ├── Cargo.toml
    ├── add_one
    │   ├── Cargo.toml
    │   └── src
    │       └── lib.rs
    ├── adder
    │   ├── Cargo.toml
    │   └── src
    │       └── main.rs
    └── target

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-16 12:03:57 +05:30
dependabot[bot]
26e787a038 build(deps): bump the vhost-device group with 6 updates
Bumps the vhost-device group with 6 updates:

| Package | From | To |
| --- | --- | --- |
| [serde](https://github.com/serde-rs/serde) | `1.0.188` | `1.0.189` |
| [aho-corasick](https://github.com/BurntSushi/aho-corasick) | `1.1.1` | `1.1.2` |
| [async-trait](https://github.com/dtolnay/async-trait) | `0.1.73` | `0.1.74` |
| [regex](https://github.com/rust-lang/regex) | `1.9.6` | `1.10.1` |
| [rustix](https://github.com/bytecodealliance/rustix) | `0.38.17` | `0.38.19` |
| [winnow](https://github.com/winnow-rs/winnow) | `0.5.16` | `0.5.17` |


Updates `serde` from 1.0.188 to 1.0.189
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.188...v1.0.189)

Updates `aho-corasick` from 1.1.1 to 1.1.2
- [Commits](https://github.com/BurntSushi/aho-corasick/compare/1.1.1...1.1.2)

Updates `async-trait` from 0.1.73 to 0.1.74
- [Release notes](https://github.com/dtolnay/async-trait/releases)
- [Commits](https://github.com/dtolnay/async-trait/compare/0.1.73...0.1.74)

Updates `regex` from 1.9.6 to 1.10.1
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.9.6...1.10.1)

Updates `rustix` from 0.38.17 to 0.38.19
- [Release notes](https://github.com/bytecodealliance/rustix/releases)
- [Commits](https://github.com/bytecodealliance/rustix/compare/v0.38.17...v0.38.19)

Updates `winnow` from 0.5.16 to 0.5.17
- [Changelog](https://github.com/winnow-rs/winnow/blob/main/CHANGELOG.md)
- [Commits](https://github.com/winnow-rs/winnow/compare/v0.5.16...v0.5.17)

---
updated-dependencies:
- dependency-name: serde
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: vhost-device
- dependency-name: aho-corasick
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: vhost-device
- dependency-name: async-trait
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: vhost-device
- dependency-name: regex
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: vhost-device
- dependency-name: rustix
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: vhost-device
- dependency-name: winnow
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: vhost-device
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-16 11:58:26 +05:30
Manos Pitsidianakis
54b5db72e0 Add new workspace under staging/ subdirectory
Add a new workspace for devices that have no final specification merged
into the virtio spec.

Closes #459

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2023-10-11 16:25:00 +05:30
Erik Schilling
25cba8ea70 gpio: drop no-longer required unsafe Send/Sync impls
With the refactoring before this commit, `PhysDevice` is `Sync` and
`Send` automatically. So let's drop the unsafe impls to prevent future
type changes to result in unsound behaviour (again).

Fixes: #442
Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
2023-10-11 14:52:09 +05:30
Erik Schilling
2e4a344c8e gpio: disallow concurrent use on PhysLineState
RwLock allows multiple concurrent readers. libgpiod, however, does not
offer thread-safety for any function - even if they look like innocent
getters. Therefore, libgpiod objects do not implement `Sync`.

Now, `PhysDevice` is incorrectly marked as `Sync`, giving multiple threads
access to thw RwLock - resulting in unsafe behaviour.

We fix this by just turning the `RwLock` into a `Mutex`.

Issue: #442
Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
2023-10-11 14:52:09 +05:30