Skip to content

virtio_console: add virtio console device#2973

Merged
jstarks merged 5 commits intomicrosoft:mainfrom
jstarks:virtio-console-mk2
Mar 16, 2026
Merged

virtio_console: add virtio console device#2973
jstarks merged 5 commits intomicrosoft:mainfrom
jstarks:virtio-console-mk2

Conversation

@jstarks
Copy link
Member

@jstarks jstarks commented Mar 13, 2026

Add a new virtio console device that bridges a guest serial port (/dev/hvc0) to any SerialIo backend.

The device uses two virtio queues — receiveq (host→guest) and transmitq (guest→host) — and supports the F_SIZE feature for reporting console dimensions. Multiport (F_MULTIPORT) is not supported.

The implementation handles backend disconnect/reconnect: when the SerialIo backend disconnects, TX descriptors are drained without forwarding until the backend reconnects.

Key changes:

  • virtio: add peek/consume API to VirtioQueue, allowing devices to inspect a descriptor chain before deciding whether to consume it. This complements the existing callback-based API and simplifies the console worker loop.

  • virtio: add VirtioDevice::enable() return type change from () to anyhow::Result<()>, allowing devices to report enablement failures to the transport layer.

  • virtio_console: new crate with device implementation, resolver, spec constants, and integration tests (9 tests covering TX, RX, large payloads, disconnect/reconnect, and disable/re-enable).

  • openvmm_entry: wire up --virtio-console CLI flag to instantiate the device with a serial backend.

@jstarks jstarks requested review from a team as code owners March 13, 2026 06:36
Copilot AI review requested due to automatic review settings March 13, 2026 06:36
@github-actions github-actions bot added the unsafe Related to unsafe code label Mar 13, 2026
@github-actions
Copy link

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new virtio-console device implementation (virtio device ID 3) that bridges a guest console (/dev/hvc0) to an existing SerialIo backend, and wires it into OpenVMM’s resource/CLI plumbing. It also extends the virtio queue API to support “peek then consume” descriptor handling and allows VirtioDevice::enable() to report failures.

Changes:

  • Introduce new virtio_console crate (device implementation, resolver, spec constants, and integration tests).
  • Extend virtio queue handling with a peek/consume API and refactor shared payload-reading helpers; change VirtioDevice::enable() to return anyhow::Result<()>.
  • Add --virtio-console CLI flag and resource wiring so the device can be instantiated with a serial backend.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
vm/devices/virtio/virtio_resources/src/lib.rs Adds a VirtioConsoleHandle resource type for configuring the new device.
vm/devices/virtio/virtio_console/src/lib.rs Implements the virtio-console device and its async worker loop using peek/consume queues.
vm/devices/virtio/virtio_console/src/resolver.rs Adds a resolver that instantiates VirtioConsoleDevice from resources.
vm/devices/virtio/virtio_console/src/spec.rs Defines virtio-console device ID, feature bit, and config layout helpers.
vm/devices/virtio/virtio_console/src/tests.rs Adds integration tests for RX/TX, disconnect/reconnect, and disable/re-enable scenarios.
vm/devices/virtio/virtio_console/Cargo.toml Declares the new crate and dependencies.
vm/devices/virtio/virtio/src/queue.rs Adds core support for peeking at available descriptors without advancing indices.
vm/devices/virtio/virtio/src/common.rs Adds PeekedWork + helpers and exposes VirtioQueue::{try_peek,poll_peek,peek}.
openvmm/openvmm_resources/src/lib.rs Registers the new VirtioConsoleResolver.
openvmm/openvmm_resources/Cargo.toml Adds virtio_console dependency.
openvmm/openvmm_entry/src/cli_args.rs Adds --virtio-console CLI flag.
openvmm/openvmm_entry/src/lib.rs Wires CLI flag into VM config construction and adds the virtio-console device resource.
Cargo.toml Adds virtio_console to workspace members/deps.
Cargo.lock Records the new workspace crate in the lockfile.

You can also share your feedback on Copilot code review. Take the survey.

@github-actions
Copy link

@github-actions github-actions bot added the Guide label Mar 13, 2026
@github-actions
Copy link

Copilot AI review requested due to automatic review settings March 13, 2026 20:37
@jstarks jstarks force-pushed the virtio-console-mk2 branch from a44079d to 9d94e34 Compare March 13, 2026 20:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new virtio-console device to OpenVMM that bridges a guest virtio console (/dev/hvc0) to the existing SerialIo backend ecosystem, plus the resource plumbing and CLI/docs wiring needed to instantiate it from openvmm_entry.

Changes:

  • Introduce virtio_console crate (device implementation, resolver, spec constants, integration tests).
  • Extend virtio queue API with peek/consume support and change VirtioDevice::enable to return anyhow::Result<()>.
  • Wire --virtio-console into openvmm_entry, register the resolver, and update the Guide CLI reference.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
vm/devices/virtio/virtio_resources/src/lib.rs Adds VirtioConsoleHandle resource type for instantiating the device.
vm/devices/virtio/virtio_console/src/lib.rs Implements the virtio-console device and async worker loop.
vm/devices/virtio/virtio_console/src/resolver.rs Adds a resource resolver that constructs the device from a serial backend resource.
vm/devices/virtio/virtio_console/src/spec.rs Defines virtio-console constants and config layout helper.
vm/devices/virtio/virtio_console/src/tests.rs Adds integration-style tests driving real virtio rings in guest memory.
vm/devices/virtio/virtio_console/Cargo.toml New crate manifest and dependencies.
vm/devices/virtio/virtio/src/queue/split.rs Refactors split-queue availability checks to support peek without consuming.
vm/devices/virtio/virtio/src/queue.rs Adds core peek/advance APIs (currently split-focused) and refactors work construction.
vm/devices/virtio/virtio/src/common.rs Adds shared payload read helpers and introduces PeekedWork + VirtioQueue::peek().
openvmm/openvmm_resources/src/lib.rs Registers the new virtio-console resolver.
openvmm/openvmm_resources/Cargo.toml Adds dependency on virtio_console.
openvmm/openvmm_entry/src/lib.rs Instantiates virtio-console via --virtio-console and adds the device to virtio bus.
openvmm/openvmm_entry/src/cli_args.rs Adds the new --virtio-console CLI flag.
Guide/src/reference/openvmm/management/cli.md Documents --virtio-console alongside other serial options.
Cargo.toml Adds virtio_console to workspace members/deps.
Cargo.lock Locks the new crate and dependency graph updates.

You can also share your feedback on Copilot code review. Take the survey.

@jstarks
Copy link
Member Author

jstarks commented Mar 15, 2026

Pulled peek changes out to #2992, will rebase once those are in.

@jstarks jstarks marked this pull request as draft March 15, 2026 06:42
@jstarks jstarks force-pushed the virtio-console-mk2 branch 2 times, most recently from bf01acd to ab4b54f Compare March 15, 2026 22:42
@jstarks jstarks marked this pull request as ready for review March 15, 2026 22:42
Copilot AI review requested due to automatic review settings March 15, 2026 22:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new virtio_console device to bridge a guest virtio-console port (/dev/hvc0) to existing SerialIo backends, with supporting virtio API updates and OpenVMM CLI plumbing.

Changes:

  • Introduces virtio_console crate (device implementation, resolver, spec constants, and integration tests).
  • Extends virtio core APIs (device enable() now returns anyhow::Result<()>; adds queue peek/consume API).
  • Wires a new --virtio-console CLI flag and updates the Guide CLI reference.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
vm/devices/virtio/virtio_resources/src/lib.rs Adds a VirtioConsoleHandle resource definition for the new device.
vm/devices/virtio/virtio_console/src/lib.rs Implements the virtio-console device + worker loop.
vm/devices/virtio/virtio_console/src/resolver.rs Adds resource resolver to instantiate VirtioConsoleDevice from resources.
vm/devices/virtio/virtio_console/src/spec.rs Defines virtio-console device ID, feature bits, and config layout.
vm/devices/virtio/virtio_console/src/tests.rs Adds integration tests covering RX/TX, large payloads, disconnect/reconnect, and re-enable.
vm/devices/virtio/virtio_console/Cargo.toml New crate manifest for virtio_console.
vm/devices/virtio/virtio/src/common.rs Updates virtio device trait docs (and enable() result signature).
openvmm/openvmm_resources/src/lib.rs Registers the virtio-console resolver.
openvmm/openvmm_resources/Cargo.toml Adds virtio_console dependency.
openvmm/openvmm_entry/src/lib.rs Instantiates virtio-console device when --virtio-console is provided.
openvmm/openvmm_entry/src/cli_args.rs Adds the --virtio-console CLI flag.
Guide/src/reference/openvmm/management/cli.md Documents the new CLI flag and serial backend usage.
Cargo.toml Adds virtio_console to workspace dependencies.
Cargo.lock Adds lockfile entry for virtio_console.
Comments suppressed due to low confidence (1)

Guide/src/reference/openvmm/management/cli.md:53

  • The doc says the BACKEND argument is the same for all serial devices, but the list below omits options that are accepted by SerialConfigCli (e.g. file=<path> and term[=<program>][,name=<windowtitle>]). Either expand this list to match the actual accepted values or soften the wording so it doesn’t imply the list is complete.
The `BACKEND` argument is the same for all serial devices:

  * `none`: Serial output is dropped.
  * `console`: Serial input is read and output is written to the console.
  * `stderr`: Serial output is written to stderr.
  * `listen=PATH`: A named pipe (on Windows) or Unix socket (on Linux) is set
      up to listen on the given path. Serial input and output is relayed to this
      pipe/socket.
  * `listen=tcp:IP:PORT`: As with `listen=PATH`, but listen for TCP
      connections on the given IP address and port. Typically IP will be
      127.0.0.1, to restrict connections to the current host.

You can also share your feedback on Copilot code review. Take the survey.

jstarks added 2 commits March 16, 2026 20:02
- Assert written > 0 after poll_write to catch AsyncWrite contract
  violations instead of spinning forever on Ok(0).
- Align --virtio-console help text with --com1 (add file overwrite note
  and full term syntax).
will-j-wright
will-j-wright previously approved these changes Mar 16, 2026
Copy link
Member

@chris-oo chris-oo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

Copilot AI review requested due to automatic review settings March 16, 2026 21:49
@jstarks jstarks force-pushed the virtio-console-mk2 branch from 65bb230 to dda3e20 Compare March 16, 2026 21:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new virtio-console device (virtio device ID 3) that bridges a guest console (/dev/hvc0) to an arbitrary SerialIo backend, wiring it into OpenVMM’s resource system and CLI.

Changes:

  • Introduces new virtio_console crate with device implementation, resolver, spec constants, and integration tests.
  • Adds a new virtio-console resource handle in virtio_resources and registers the resolver in openvmm_resources.
  • Adds --virtio-console <BACKEND> CLI flag and updates the OpenVMM Guide CLI reference.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
vm/devices/virtio/virtio_resources/src/lib.rs Adds VirtioConsoleHandle resource definition for virtio-console devices.
vm/devices/virtio/virtio_console/src/lib.rs Implements the virtio-console device and worker logic.
vm/devices/virtio/virtio_console/src/spec.rs Defines virtio-console spec constants and config layout.
vm/devices/virtio/virtio_console/src/resolver.rs Adds resource resolver to instantiate the device from resources.
vm/devices/virtio/virtio_console/src/tests.rs Adds integration tests exercising TX/RX, disconnect/reconnect, and re-enable flows.
vm/devices/virtio/virtio_console/Cargo.toml Declares the new crate and its dependencies.
vm/devices/virtio/virtio/src/common.rs Updates virtio device trait documentation around enable/disable behavior.
openvmm/openvmm_resources/src/lib.rs Registers the virtio-console resolver.
openvmm/openvmm_resources/Cargo.toml Adds virtio_console dependency.
openvmm/openvmm_entry/src/cli_args.rs Adds --virtio-console CLI option.
openvmm/openvmm_entry/src/lib.rs Wires CLI flag into VM config by adding the virtio-console device.
Guide/src/reference/openvmm/management/cli.md Documents the new --virtio-console flag and shared serial backend syntax.
Cargo.toml Adds virtio_console to workspace members/dependencies.
Cargo.lock Adds lockfile entries for the new crate.

You can also share your feedback on Copilot code review. Take the survey.

Copilot AI review requested due to automatic review settings March 16, 2026 22:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new virtio_console device to bridge a guest virtio console (/dev/hvc0) to an existing SerialIo backend, wiring it into resource resolution and the openvmm_entry CLI.

Changes:

  • Introduces the virtio_console crate (device, resolver, spec constants, integration tests).
  • Registers virtio-console as a virtio resource and resolver, and wires up --virtio-console CLI flag.
  • Updates the Guide CLI reference to document --virtio-console.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vm/devices/virtio/virtio_resources/src/lib.rs Adds a VirtioConsoleHandle resource type for instantiating the device with a serial backend.
vm/devices/virtio/virtio_console/src/lib.rs Implements the virtio-console device and worker loop (TX/RX, disconnect handling).
vm/devices/virtio/virtio_console/src/spec.rs Defines virtio-console device/spec constants and config-space layout helper.
vm/devices/virtio/virtio_console/src/resolver.rs Adds a resource resolver to build the device from a serial backend resource.
vm/devices/virtio/virtio_console/src/tests.rs Adds integration tests that drive real virtio queues against a mock serial backend.
vm/devices/virtio/virtio_console/Cargo.toml Adds the new crate’s dependencies and workspace lints.
vm/devices/virtio/virtio/src/common.rs Updates VirtioDevice docs for enable/disable lifecycle expectations.
openvmm/openvmm_resources/src/lib.rs Registers the virtio-console resolver.
openvmm/openvmm_resources/Cargo.toml Adds virtio_console dependency.
openvmm/openvmm_entry/src/lib.rs Instantiates virtio-console when --virtio-console is provided.
openvmm/openvmm_entry/src/cli_args.rs Adds --virtio-console CLI option.
Guide/src/reference/openvmm/management/cli.md Documents the new --virtio-console flag.
Cargo.toml / Cargo.lock Adds the new crate to the workspace and lockfile.

You can also share your feedback on Copilot code review. Take the survey.

@jstarks jstarks enabled auto-merge (squash) March 16, 2026 23:03
@jstarks jstarks merged commit e0ee064 into microsoft:main Mar 16, 2026
60 checks passed
@jstarks jstarks deleted the virtio-console-mk2 branch March 16, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Guide unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants