Skip to content

usb: typec: tipd: cd321x: don't race the resume read in the IRQ test - #348

Closed
RyanTheTide wants to merge 1 commit into
aurora-wipfrom
fix/cd321x-irq-test-smp-races
Closed

RyanTheTide wants to merge 1 commit into
aurora-wipfrom
fix/cd321x-irq-test-smp-races

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

cd321x_ack_retry_across_sleep_test (from #338) flaked under -smp 2, failing at cd321x-irq-test.c:329. It's the same class as the race #338 already fixed in cd321x_test_recover():

  • cd321x_complete() queues the resume read with mod_delayed_work(…, 0), and the test asserted that the read was still pending;
  • on SMP, a worker can already be running it, which clears the pending bit, or have finished it.

Fix (test only, +9/−1)

After tipd_complete(), the test now waits for the resume read with flush_work(&resume_work.work), then checks that it made exactly one event read. The existing retry loop runs unchanged.

It uses flush_work(), not flush_delayed_work(): if the read has already finished and armed its next retry on a ≥1 s timer, flush_delayed_work() would run that retry at once, giving 2 reads instead of 1. flush_work() covers all three states (queued, running, finished).

Audit: every other delayed_work_pending()/timer assertion in cd321x-irq-test.c is deterministic, or follows a timer at least 500 ms away. cd321x-pm-test.c has none.

Testing

Run Result
tipd kunitconfig, -smp 2, 20 runs 20/20 (43/43 each)
tipd-spmi kunitconfig, -smp 2, 20 runs 20/20 (48/48 each)
tipd, -smp 4, 10 runs 10/10
base, -smp 2, 20 runs (control) 19/20, the natural flake at line 329
  • Race probe (driver-side sleep, not committed): the base fails every run at exactly line 329; the fix passes.
  • Mutants: each fails at its expected line.
  • The rest: apple-dcp run.py 55/55, and checkpatch with 0 errors.

🤖 Generated with Claude Code

cd321x_ack_retry_across_sleep_test() asserted that the resume read was
pending right after tipd_complete(). The driver queues that read with no
delay, so on an SMP test machine a worker can already be running it, with
the pending bit clear, and the test fails although the driver behaved
correctly. With two CPUs it failed in 1 of 20 runs.

Wait for the resume read with flush_work() instead. Unlike
flush_delayed_work(), it does not run early the retry that the read
schedules, so the loop that follows still sees exactly one retry pending
after each read. Check that the resume read tried to read the events.

The other pending and timer checks in the test look either at work that
nothing can queue at that point, or at a retry scheduled at least 500 ms
ahead. Not queueing the resume read, or giving up the retry after the
cable-state budget, still makes the test fail, and now so does queueing
the resume read late.

Fixes: 7e97f2f ("usb: typec: tipd: cd321x: Never leave interrupt events unacknowledged")
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Superseded by #349: the same tree, with the commit trailers corrected to the house Assisted-by/Signed-off-by block. The branch is kept.

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