Page MenuHomeFreeBSD

ns8250: Check if flush via FCR succeeded
ClosedPublic

Authored by cperciva on Oct 13 2022, 6:11 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Dec 7, 9:09 AM
Unknown Object (File)
Nov 7 2024, 11:05 AM
Unknown Object (File)
Oct 20 2024, 10:45 AM
Unknown Object (File)
Sep 30 2024, 11:22 PM
Unknown Object (File)
Sep 30 2024, 4:08 AM
Unknown Object (File)
Sep 28 2024, 7:49 AM
Unknown Object (File)
Sep 27 2024, 1:31 PM
Unknown Object (File)
Sep 25 2024, 4:40 PM
Subscribers

Details

Summary

The emulated UART in the Firecracker VMM (aka the implementation in the
rust-vmm/vm-superio project) includes FIFOs but does not implement the
FCR register, which is used by ns8250_flush to flush the FIFOs.

Check the LSR to see if there is still data in the FIFOs and call
ns8250_drain if necessary.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

cperciva created this revision.

IMO it's worth putting a link to https://github.com/rust-vmm/vm-superio/issues/83 in here, with the intent that this workaround could eventually be removed again.

sys/dev/uart/uart_dev_ns8250.c
232

if (drain != 0) may be more style(9)ish

sys/dev/uart/uart_dev_ns8250.c
214

drain could be a bool since we don't use the bits set for anything.

sys/dev/uart/uart_dev_ns8250.c
214

I was about to make that comment before noticing we pass it to ns8250_drain() which does use the bits.

Add comment and change if (drain) to if (drain != 0).

Presumably it is possible for a character to arrive between successfully flushing the RX fifo and reading LSR_RXRDY, resulting in a bogus report that UART FCR is broken? IMO that's fine, but an argument for keeping this as a temporary workaround until rust-vmm is fixed.

Presumably it is possible for a character to arrive between successfully flushing the RX fifo and reading LSR_RXRDY, resulting in a bogus report that UART FCR is broken? IMO that's fine, but an argument for keeping this as a temporary workaround until rust-vmm is fixed.

Yes, a race condition is possible. Since we're flushing the FIFO anyway I don't think losing a character matters (it would have been lost in the flushing if it arrived a few microseconds earlier) but you're right that theoretically we could get a bogus warning.

I've made a note to remove this once rust-vmm has been fixed (after a reasonable window of time for deployment).

If we see these warnings on !FIRECRACKER systems, we could limit the workaround to FIRECRACKER kernels too.

sys/dev/uart/uart_dev_ns8250.c
240

Printing whilst trying to drain seems like an odd thing to do that might cause issues?..

In D36979#839868, @imp wrote:

If we see these warnings on !FIRECRACKER systems, we could limit the workaround to FIRECRACKER kernels too.

Yeah, I considered hiding it behind a machdep.broken_uart_fcr loader setting or similar, but figured that the cost (a single LSR read) was low enough and the rust-vmm bug might surface in other environments. Certainly if the warning shows up outside of Firecracker it's worth investigating.

sys/dev/uart/uart_dev_ns8250.c
240

I wondered about that, but the printf shows up on Firecracker so I concluded that it seemed to be ok.

This revision was not accepted when it landed; it landed in state Needs Review.Oct 18 2022, 6:03 AM
This revision was automatically updated to reflect the committed changes.