Skip to content

fix(tty): preserve raw flags across termios ABI conversions - #2267

Open
fslongjin wants to merge 1 commit into
DragonOS-Community:masterfrom
fslongjin:codex/issue-1906
Open

fix(tty): preserve raw flags across termios ABI conversions#2267
fslongjin wants to merge 1 commit into
DragonOS-Community:masterfrom
fslongjin:codex/issue-1906

Conversation

@fslongjin

Copy link
Copy Markdown
Member

Summary

TTY attribute setters silently discard flag bits absent from the kernel bitflags definitions. For example, a raw TCSETS request containing 0x80000000 loses that bit on readback, and legacy TCSETA updates cannot preserve it. Linux 6.6 copies the raw flag words and preserves the upper 16 bits when merging legacy settings.

Preserve raw bits in both termios ABI conversions and use difference() when inheriting old hardware settings, so bitflags complement semantics do not truncate them again. Existing driver normalization, baud-rate handling, locking, and flush/drain ordering remain intact.

Extend the existing dunitest suite with coverage for all six setters, legacy control-character preservation, flush versus non-flush behavior, EFAULT without attribute/input changes, page-boundary termio access and zeroed padding, and console stdin settings.

Validation

  • Before the fix: 25/26 termios tests passed; the new raw-flag regression failed for all six setters.
  • After the fix, QEMU x86_64: tty_termios 26/26, tty_tcflush 6/6, tty_pty_hangup 36/36, and the existing C termios smoke test passed.
  • A ttyS0 console passed stdin TCSAFLUSH and legacy setter checks; a real apt install of a local package completed with exit status 0 without the TCSAFLUSH error.
  • All five added tests passed on host Linux using a PTY.
  • Kernel build, Rust formatting, and whitespace checks passed.

Related: #1906. The original missing-ioctl support was implemented by #2141; this change fixes the remaining raw-flag preservation gap.

TCSETS and the legacy TCSETA family discard flag bits that are not named
in the kernel bitflags definitions. This differs from Linux 6.6, which
copies the raw flag words and preserves the upper 16 bits when merging
legacy termio settings.

Preserve all four raw flag words at both ABI conversion boundaries while
leaving hardware normalization to the existing driver callbacks. Keep
legacy control-character merging and baud-rate extraction unchanged.

Use bitflags difference() when restoring old hardware settings after an
unsupported driver callback. Unlike the bitflags complement operator,
it preserves unnamed bits outside the software-controlled mask, matching
tty_termios_copy_hw().

Extend the existing dunitest suite to cover all six set commands, raw
flag preservation, legacy control-character tails, input flush behavior,
EFAULT without state changes, the 18-byte page-boundary termio ABI and
zeroed padding, and console stdin settings.

Validation:
- Reproduced raw flag loss before the fix: 25 of 26 tty_termios tests
  passed, with only the new flag-preservation case failing.
- After the fix, QEMU x86_64 passed tty_termios (26), tty_tcflush (6),
  tty_pty_hangup (36), and the existing C termios smoke test.
- Verified TCSAFLUSH and legacy settings on ttyS0 stdin, plus a successful
  apt install of a local test package without the TCSAFLUSH error.
- All five added tests passed on host Linux with a PTY.
- Kernel build, Rust formatting and whitespace checks passed.

Signed-off-by: longjin <[email protected]>
@fslongjin

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-08T04:23:44.176891Z 6066874 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added the Bug fix A bug is fixed in this pull request label Sep 8, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 6066874483

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

Labels

Bug fix A bug is fixed in this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant