Skip to content

openhcl, opentmk: use uart_16550 for 16550 serial ports - #4645

Open
Philipp Schuster (phip1611) wants to merge 2 commits into
microsoft:mainfrom
phip1611:uart_16550
Open

Philipp Schuster (phip1611) wants to merge 2 commits into
microsoft:mainfrom
phip1611:uart_16550

Conversation

@phip1611

@phip1611 Philipp Schuster (phip1611) commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Replace the hand-rolled 16550 drivers in OpenHCL (boot shim, sidecar) and opentmk with the uart_16550 crate. All serial output now goes through one maintained driver; the TDX and SNP boot logs plug in their tdcall/GHCB port I/O as custom backends.

Why

I maintain uart_16550. It got a major overhaul this year with a focus on real hardware, and it already runs in Patina, Microsoft's Rust UEFI firmware (patina#1694). Compared to the replaced drivers, it:

  • Resets the full line state (DLAB, divisor, 8N1, break). The old OpenHCL driver never touched LCR, so a DLAB left set by firmware meant no output at all.
  • Detects missing devices via the scratch register. The boot logger turns off cleanly instead of writing to nothing (or panicking, under TDX).
  • Verifies the FIFO and falls back to byte-by-byte transmission on 16450 and early 16550 chips.
  • Behaves like Linux: it discards stale input and sets DTR, RTS, and OUT2 (opentmk never set them; OpenHCL also set OUT1).

Inside VMs, the output doesn't change visibly; the gains show up on physical or quirky UARTs.

Behavior changes

  • The boot shim now programs the baud rate, using the current-speed from the device tree that Linux also uses.
  • A failed TDCALL port read returns all ones (as with SNP) instead of panicking, so the device is treated as absent.

Notes

  • uart_16550 is a git dependency on its main branch, as the required changes are not released yet. This is temporary until the next release.

LLM Disclosure: I used an LLM for assistance to navigate the repository. All changes verified manually. I did not run any integration tests of openvmm.

Copilot AI balanced review requested due to automatic review settings October 10, 2026 12:04
@github-actions github-actions Bot added the unsafe Related to unsafe code label Oct 10, 2026
@github-actions

Copy link
Copy Markdown

⚠️ 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

OpenHCL now ignores the advertised serial speed and always reconfigures COM3 to 115200 baud.

1 open finding
What changed in this PR

Replaces hand-written x86 16550 serial drivers in OpenHCL and OpenTMK with the shared uart_16550 crate.

Changes:

  • Adds shared UART configuration and PIO-backed serial handling.
  • Adds TDX and SNP custom UART backends.
  • Updates dependencies and removes legacy serial implementations.
File Description
Cargo.toml Adds the temporary uart_16550 Git dependency.
Cargo.lock Locks UART and updated transitive dependencies.
opentmk/​opentmk_executor/​Cargo.toml Adds the UART dependency.
opentmk/​opentmk_executor/​src/​serial.rs Migrates executor serial I/O.
opentmk/​opentmk_core/​Cargo.toml Adds the UART dependency.
opentmk/​opentmk_core/​src/​tmk_logger.rs Migrates the COM2 logger.
opentmk/​opentmk_core/​src/​arch/​x86_64/​serial.rs Replaces the custom serial driver.
openhcl/​sidecar/​Cargo.toml Adds the UART dependency.
openhcl/​sidecar/​src/​arch/​x86_64/​mod.rs Migrates sidecar COM3 output.
openhcl/​openhcl_boot/​Cargo.toml Adds the UART dependency.
openhcl/​openhcl_boot/​src/​boot_logger.rs Migrates boot logging and initialization.
openhcl/​openhcl_boot/​src/​arch/​x86_64/​tdx.rs Implements the TDX UART backend.
openhcl/​openhcl_boot/​src/​arch/​x86_64/​snp.rs Implements the SNP UART backend.
openhcl/​minimal_rt/​Cargo.toml Adds the UART dependency.
openhcl/​minimal_rt/​src/​arch/​mod.rs Updates architecture exports.
openhcl/​minimal_rt/​src/​arch/​x86_64/​serial.rs Provides shared COM3 construction and configuration.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread openhcl/openhcl_boot/src/boot_logger.rs Outdated
Copilot AI balanced review requested due to automatic review settings October 10, 2026 12:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The TDX backend can panic on a host-controlled UART read failure during boot.

2 open findings

🧠 Review effort: Balanced

Comment thread openhcl/openhcl_boot/src/arch/x86_64/tdx.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The boot logger hard-codes 115200 baud while Linux continues using the host-advertised serial speed.

2 open findings

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 11, 2026 10:03
@phip1611
Philipp Schuster (phip1611) force-pushed the uart_16550 branch 2 times, most recently from bd2267d to 2529bd4 Compare October 11, 2026 10:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Low-level boot and confidential-VM serial paths require human review and hardware-backed validation.

0 open findings

2 resolved since last review

🧠 Review effort: Balanced

@smalis-msft

Steven Malis (smalis-msft) commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Hi Philipp, and thanks for the contributions.

I'm hesitant to take this change, as we've had situations in the past where we've needed to do weird non-standard things in our devices for compatibility reasons, and those sorts of changes wouldn't make sense to upstream into a common shared crate. That said, I don't think we've ever had a need to do that with serial, since it's a pretty well-defined case. We'll discuss this internally.

@smalis-msft

Copy link
Copy Markdown
Contributor

We discussed and are happy to take this once the updated version is released so it's no longer a git dependency.

Copilot AI balanced review requested due to automatic review settings October 16, 2026 14:21
@phip1611
Philipp Schuster (phip1611) marked this pull request as ready for review October 16, 2026 14:21
@phip1611
Philipp Schuster (phip1611) requested a review from a team as a code owner October 16, 2026 14:21
@phip1611

Copy link
Copy Markdown
Contributor Author

cool. I just released v0.9.0 - I've updated the PR.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Early-boot hardware initialization and confidential-VM I/O changes need human review and integration validation.

0 open findings

🧠 Review effort: Balanced

Comment thread opentmk/opentmk_core/Cargo.toml
Comment thread openhcl/openhcl_boot/src/arch/x86_64/tdx.rs
Comment thread opentmk/opentmk_executor/src/serial.rs Outdated
use opentmk_core::arch::serial::Serial;
pub use opentmk_core::arch::serial::SerialPort;
#[cfg(target_arch = "x86_64")]
use {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: keep usings unmerged

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

applies to other files too

@smalis-msft

Copy link
Copy Markdown
Contributor

Other than the one style nit I think this LGTM

@github-actions

Copy link
Copy Markdown

@smalis-msft

Steven Malis (smalis-msft) commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

30 Petri tests failed (1 unstable)

Gotta love those broken SNP tests. You don't need to do anything for them, that's our (longstanding) bug

Comment thread openhcl/minimal_rt/src/arch/x86_64/serial.rs
Replace the local 16550 driver with the uart_16550 crate, so we share
one maintained and hardware-tested driver instead of carrying our own.

Unlike the old driver, uart_16550 checks that the device is present,
verifies that the FIFO works, and asserts DTR and RTS. The old driver
left DTR and RTS unset, so a remote using hardware flow control would
not send to us.
Replace minimal_rt's 16550 driver with the uart_16550 crate. The TDX
and SNP boot logs plug in their port I/O as custom backends, so all
serial output goes through the same driver.

uart_16550 is also more robust on real or quirky devices. It resets the
whole line state (DLAB, word length, parity, break) instead of relying
on what firmware left behind. It detects a missing device via the
scratch register instead of writing to nothing. It checks that the FIFO
actually works and otherwise falls back to sending byte by byte. It
also discards stale input and sets the modem control lines like Linux.

Unlike the old driver, uart_16550 programs the baud rate. The boot
logger uses the speed that the host advertises in the device tree,
which is also passed to Linux, so both agree on it.

A failed TDCALL port read now returns all ones, as with SNP, instead of
panicking. The host controls that result, and the driver then treats
the device as absent.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Early-boot and confidential-VM serial changes need human review and platform integration validation, which was not performed.

No open issues 🎉

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants