Skip to content

[bug] Avoid holding the pipeline lock across management uart writes - #1206

Open
zeeshanlakhani wants to merge 1 commit into
masterfrom
zl/softnpu-mgmt-deadlock
Open

[bug] Avoid holding the pipeline lock across management uart writes#1206
zeeshanlakhani wants to merge 1 commit into
masterfrom
zl/softnpu-mgmt-deadlock

Conversation

@zeeshanlakhani

Copy link
Copy Markdown
Contributor

handle_management_message took the p4 pipeline mutex at the top of the function and held it while writing responses to the management uart, yielding whenever the one-byte FIFO was full. If a queue notify landed on a vcpu during that window, process_guest_packet blocked on the same mutex, the vcpu never returned from its PIO exit, and the guest could no longer drain the tty, deadlocking the entire guest.

Now, we take the lock only where table state is read or written, serialize dump responses before writing, and bound uart writes with a 30-second deadline so that a guest that stops reading the management tty cannot pin the handler thread.

A write that times out mid-response leaves a partial frame in the tty. The handler remembers this and terminates the stale frame with a newline before the next response, so framing recovers after one possibly garbled read.

Note: I ran into this issue on a long-running voxel session. The pre-fix binary reproduces it within minutes under a scadm polling loop, while the fixed one does not (A/B testing).

`handle_management_message` took the p4 pipeline mutex at the top of the
function and held it while writing responses to the management uart,
yielding whenever the one-byte FIFO was full. If a queue notify landed
on a vcpu during that window, `process_guest_packet` blocked on the same
mutex, the vcpu never returned from its PIO exit, and the guest could
no longer drain the tty, deadlocking the entire guest.

Now, we take the lock only where table state is read or written,
serialize dump responses before writing, and bound uart writes with
a 30-second deadline so that a guest that stops reading the management
tty cannot pin the handler thread.

A write that times out mid-response leaves a partial frame in the tty.
The handler remembers this and terminates the stale frame with a newline
before the next response, so framing recovers after one possibly garbled
read.

*Note*: I ran into this issue on a long-running voxel session. The
pre-fix binary reproduces it within minutes under a scadm polling
loop, while the fixed one does not (A/B testing).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant