Skip to content

fwTPM: remove the per-command delay in the mssim reply path - #664

Open
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:fwtpm_nodelay
Open

dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:fwtpm_nodelay

Conversation

@dgarske

@dgarske dgarske commented Nov 2, 2026

Copy link
Copy Markdown
Member

Description

Every fwTPM command over the mssim socket transport paid a fixed delay. DispatchAndRespond() sent a reply as three writes - size, response, acknowledgement - and that last four-byte write goes out while the response is still unacknowledged, so Nagle holds it until the peer's delayed-ACK timer expires. The time is spent waiting on a kernel timer, which is why a measurement taken around FWTPM_ProcessCommand() looked normal while the client round trip did not.

The SWTPM client sets TCP_NODELAY on the socket it connects, but that governs the client's own sends. The server never set it on the sockets it accepts.

  • SendMssimReply() sends size, response and acknowledgement as one segment with writev(). A custom I/O HAL has no vectored form and keeps the three sequential sends; FWTPM_NO_WRITEV selects that path, as do Windows and Zephyr.
  • SetSocketNoDelay() disables Nagle on both accepted sockets, command and platform. The platform port frames its replies the same way.

Either change removes the delay on its own. Both are kept because the fallback path still writes three times, and both are
advisory in the sense SO_REUSEADDR here already is: a failure costs latency, not correctness.

Fixes #663. Thank you @jerohavaz

Testing

test_fwtpm_mssim_reply_framing drives SendMssimReply() over a socketpair and asserts the wire stream is exactly size, response, zero ack; a FWTPM_NO_WRITEV build covers the sequential path through the same test. make check green against the fwTPM simulator, unit.test and run_examples.sh green against ibmswtpm2, and built over eleven configurations.

@dgarske dgarske self-assigned this Nov 2, 2026
Copilot AI balanced review requested due to automatic review settings November 2, 2026 23:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the changes to fwTPM MSSIM reply handling.

No open issues 🎉

What changed in this PR

This PR addresses #663 by removing the server-side socket behavior responsible for delayed fwTPM MSSIM replies, without changing the wire format.

Changes:

  • Uses writev() to send reply framing and payload together, retaining sequential sends for custom HALs and unsupported or disabled configurations.
  • Enables TCP_NODELAY on accepted command and platform sockets.
  • Adds a reply-framing test shared by vectored and sequential builds.
File Description
tests/​fwtpm_unit_tests.c Adds assertions for reply length, payload, and zero acknowledgement.
tests/​fwtpm_io_test_adapter.c Exposes the reply helper to unit tests.
src/​fwtpm/​fwtpm_io.c Adds vectored replies with partial-write handling and disables Nagle on accepted sockets.

Review effort: Balanced

@dgarske dgarske assigned wolfSSL-Bot and embhorn and unassigned dgarske Nov 3, 2026
@dgarske
dgarske requested a review from embhorn November 3, 2026 00:34
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.

fwTPM MSSIM: ~46 ms command latency resolved by server-side TCP_NODELAY

4 participants