Skip to content

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

Merged
RyanTheTide merged 1 commit into
aurora-wipfrom
fix/cd321x-irq-test-smp-races-v2
Oct 17, 2026
Merged

RyanTheTide merged 1 commit into
aurora-wipfrom
fix/cd321x-irq-test-smp-races-v2

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]>
@RyanTheTide
RyanTheTide merged commit 545d7e4 into aurora-wip Oct 17, 2026
@RyanTheTide
RyanTheTide deleted the fix/cd321x-irq-test-smp-races-v2 branch October 17, 2026 09:34
RyanTheTide added a commit that referenced this pull request Oct 17, 2026
Bring the 7.2.10 assembly to the tree of the canonical top-up #6
assembly, stacked on top-up #5 f34b5ae so that it is a
fast-forward of the published branch. The second parent is that
canonical assembly; the tree is identical to it.

Ported from aurora-wip, each with cherry-pick -x and its original
author:
- #347 KUNIT_ALL_TESTS=m modpost (3): the xHCI platform tests call the
  interrupt handler through the HC driver (170-usb), and module
  descriptions for the CD321x PM tests (170-usb) and the drm/apple
  KUnit test modules (200-dcp).
- #349 the CD321x IRQ test waits for the resume read before checking
  its retry (170-usb).
- #350 trusted keys keep a source that registers before
  init_trusted() (100-sep). Its test commit is already carried as
  76d70cc and is not duplicated.
- #351 SEP hwrng: recover the entropy exchange after a request times
  out, and hold entropy requests while the system sleeps (100-sep).
- #352 SEP SBIO: take a reply header only once it has landed, and
  poison it again once read and before each host send (100-sep).

Adaptations, each with a [ryan: ...] note in its commit:
- trusted-type.h: context only, the declaration goes above the
  7.2.10 CONFIG_TRUSTED_KEYS_DEBUG block;
- the CD321x IRQ test takes its data from tipd_hw_variants[], and its
  retry loop replaces the 7.2.10-only fix of the same race in
  11e0ce6.

The Co-Authored-By lines of the three #347 commits are dropped.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide added a commit that referenced this pull request Oct 18, 2026
A mux that holds a change up is retried until it goes through, and a
PHY that stays stuck is given up after 16 retries, said to be some two
minutes. That holds only while nothing else happens. A controller event
during the backoff brings the retry forward to the usual debounce, and
that retry counted against the 16 too, without making the hold-up any
shorter. With an event in every backoff, as a partner that keeps
renegotiating raises, the retries come about a second apart and the
port gave up after some 16.5 s. If the PHY then let go after the last
event, nothing applied the state again until a later event.

Limit a series by time instead: note when its first failure was, and
give up at the first failure two minutes or more after it. The start is
noted whenever a failure finds no series under way, so a series that
ended in any way, each of which clears its backoff, never lends its
start to the next. The state machine keeps to milliseconds, as for its
delays, and the driver passes jiffies_to_msecs(jiffies); the difference
is taken so that the clock may wrap.

Keep the count only as a bound on the warnings of a series. Ordinary
controller events bring retries about a second apart, debouncing both
the read and the update. Tunnel notifications skip the read debounce,
but the 500 ms update debounce alone keeps the limit of 240 from ending
a series before two minutes. Counting only the retries that the timer
runs would bound nothing that the time limit does not. The warning now
gives the retries and the time.

Correct the texts that promised about two minutes for a count. Also
make typec_mux_timeout_transient()'s kernel-doc say that it describes
the last request that failed with -ETIMEDOUT: one that fails with
-EBUSY before it owns the providers leaves the answer as it was. A
consumer asks only right after -ETIMEDOUT, so say so rather than change
the core. The query keeps its form, a flag on the handle; upstream would
rather have typec_mux_set() return the answer.

The new tests inject an event into every backoff while the PHY holds
the change up, and expect the port to give up only two minutes after
the first refusal, after some 120 retries rather than 16. With an event
every 1.5 s for well over a minute, after which the PHY lets go, the
next retry of the backoff must apply the safe and USB states with no
further event. The fixture runs works before their delay, so it makes a
series as old on the driver's clock as it is in the time of the tests.
The state machine tests cover the limit, a clock that wraps, retries a
second apart, the count and the fresh start after an event, and the
backoff test reads the backoff rather than the time left on its timer.
The apple-dcp host selftests pass the time of each failure and check
that retries a second apart do not end a series sooner.

Repair two existing test races exposed while qualifying this change on
ed289aa. The IRQ test joins the immediate resume read and checks
that retries attempt acknowledgment, rather than requiring work to stay
pending. The host teardown fixture ends its observation at the lock
that fences the selected removal: direct xHCI teardown may proceed once
the host mutex is dropped, while the controller mutex is still held.
Force that interleaving and check that the PHY and root accesses have
finished before removal can proceed.

[ryan: rebased onto #355 — kept HPD v2 and #349 test changes;
 combined the ceiling retry race checks, clock shims and new cases.]

[ryan: split by topic: only the tipd, Type-C mux and ATC PHY part; the
apple-dcp selftests part is in 200-dcp]

Fixes: 70f7c21 ("phy: apple: atc: Route the PIPE from the Type-C mux on a fixed-hub port")
(cherry picked from commit 6f715d4 ("usb: typec: tipd: Limit the retries of a held mux by time, not count"))
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide added a commit that referenced this pull request Oct 18, 2026
A mux that holds a change up is retried until it goes through, and a
PHY that stays stuck is given up after 16 retries, said to be some two
minutes. That holds only while nothing else happens. A controller event
during the backoff brings the retry forward to the usual debounce, and
that retry counted against the 16 too, without making the hold-up any
shorter. With an event in every backoff, as a partner that keeps
renegotiating raises, the retries come about a second apart and the
port gave up after some 16.5 s. If the PHY then let go after the last
event, nothing applied the state again until a later event.

Limit a series by time instead: note when its first failure was, and
give up at the first failure two minutes or more after it. The start is
noted whenever a failure finds no series under way, so a series that
ended in any way, each of which clears its backoff, never lends its
start to the next. The state machine keeps to milliseconds, as for its
delays, and the driver passes jiffies_to_msecs(jiffies); the difference
is taken so that the clock may wrap.

Keep the count only as a bound on the warnings of a series. Ordinary
controller events bring retries about a second apart, debouncing both
the read and the update. Tunnel notifications skip the read debounce,
but the 500 ms update debounce alone keeps the limit of 240 from ending
a series before two minutes. Counting only the retries that the timer
runs would bound nothing that the time limit does not. The warning now
gives the retries and the time.

Correct the texts that promised about two minutes for a count. Also
make typec_mux_timeout_transient()'s kernel-doc say that it describes
the last request that failed with -ETIMEDOUT: one that fails with
-EBUSY before it owns the providers leaves the answer as it was. A
consumer asks only right after -ETIMEDOUT, so say so rather than change
the core. The query keeps its form, a flag on the handle; upstream would
rather have typec_mux_set() return the answer.

The new tests inject an event into every backoff while the PHY holds
the change up, and expect the port to give up only two minutes after
the first refusal, after some 120 retries rather than 16. With an event
every 1.5 s for well over a minute, after which the PHY lets go, the
next retry of the backoff must apply the safe and USB states with no
further event. The fixture runs works before their delay, so it makes a
series as old on the driver's clock as it is in the time of the tests.
The state machine tests cover the limit, a clock that wraps, retries a
second apart, the count and the fresh start after an event, and the
backoff test reads the backoff rather than the time left on its timer.
The apple-dcp host selftests pass the time of each failure and check
that retries a second apart do not end a series sooner.

Repair two existing test races exposed while qualifying this change on
ed289aa. The IRQ test joins the immediate resume read and checks
that retries attempt acknowledgment, rather than requiring work to stay
pending. The host teardown fixture ends its observation at the lock
that fences the selected removal: direct xHCI teardown may proceed once
the host mutex is dropped, while the controller mutex is still held.
Force that interleaving and check that the PHY and root accesses have
finished before removal can proceed.

[ryan: rebased onto #355 — kept HPD v2 and #349 test changes;
 combined the ceiling retry race checks, clock shims and new cases.]

[ryan: split by topic: only the apple-dcp selftests part; the tipd,
Type-C mux and ATC PHY part is in 170-usb]

Fixes: 70f7c21 ("phy: apple: atc: Route the PIPE from the Type-C mux on a fixed-hub port")
(cherry picked from commit 6f715d4 ("usb: typec: tipd: Limit the retries of a held mux by time, not count"))
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
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