Skip to content

thunderbolt, pmdomain: apple: tests for the s2idle control channel and the PMP fast-die effort - #2901

Open
RyanTheTide wants to merge 2 commits into
integration/aurorafrom
test-coverage/tb-noirq-pmp-fast-die
Open

RyanTheTide wants to merge 2 commits into
integration/aurorafrom
test-coverage/tb-noirq-pmp-fast-die

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Two recently merged changes have no test:

Change

Tests only, two commits.

  • thunderbolt: four cases in the existing suite. They cover the packet types answered while suspended, the retain decision (suspend-to-idle, awake host router, an XDomain and no router behind any port), suspend/resume with a retained channel including a refused suspend, and the XDomain dispatch dropping service packets, responses and state-changing requests without calling a handler or queueing work.
  • pmdomain: apple: pmp-report: a new apple-pmp-fast-die suite of four cases on a report held in memory. They cover the lane bytes at both read widths, the lane bound, the "PMP is running" rule, lookup by node, reports without the entry, and the T8142 table against its entry numbers.

The only non-test change: tb_domain_event_cb(), tb_domain_retain_noirq_control() and tb_xdp_noirq_request() become VISIBLE_IF_KUNIT. Without CONFIG_KUNIT they are static as before.

Testing

  • KUnit on arm64 (qemu) with KASAN and lockdep: 91 tests, 91 passed, none skipped (thunderbolt 73, apple-pmp-start 14, apple-pmp-fast-die 4).
  • Negative controls: 28 single-line mutants of the code under test, each rebuilt and run. 27 are caught by the new cases. The one that passes swaps a 64-bit read for a 32-bit read of the same low bytes, which a report in memory cannot tell apart; the table case still pins the T8142 flag.
  • checkpatch.pl --strict clean on both patches; W=1 clean for the touched objects with and without CONFIG_KUNIT.

Still to run

Nothing on hardware: the tests need none. #2756 (G15 short-prefix VM order) is not covered here; its pick logic needs a live device to build its inputs, so a test would need a small refactor first.

Mutant table
Mutant Result Caught by
pmp-lane-shift caught pmp_fast_die_lanes_test, pmp_fast_die_running_test, pmp_fast_die_lookup_test
pmp-lane-bound caught pmp_fast_die_lanes_test, pmp_fast_die_running_test
pmp-no-running-check caught pmp_fast_die_running_test
pmp-running-any-ignored caught pmp_fast_die_running_test
pmp-running-any-always caught pmp_fast_die_running_test
pmp-wide-upper-half caught pmp_fast_die_lanes_test
pmp-wide-ignored passes (equivalent in memory) -
pmp-no-node-match caught pmp_fast_die_lookup_test
pmp-einval-before-eopnotsupp caught pmp_fast_die_lookup_test
pmp-t8142-fast-die-offset caught pmp_fast_die_t8142_test
pmp-t8142-not-wide caught pmp_fast_die_t8142_test
pmp-t8142-write-offset caught pmp_fast_die_t8142_test
pmp-t8142-lanes caught pmp_fast_die_t8142_test
pmp-t8142-no-match caught pmp_fast_die_t8142_test
tb-xdp-allows-properties-changed caught tb_test_noirq_xdp_request_types, tb_test_noirq_xdomain_filter
tb-xdp-refuses-link-state-status caught tb_test_noirq_xdp_request_types
tb-retain-ignores-remote caught tb_test_noirq_retain_decision
tb-retain-without-xdomain caught tb_test_noirq_retain_decision
tb-retain-ignores-quirk caught tb_test_noirq_retain_decision
tb-retain-ignores-platform caught tb_test_noirq_retain_decision
tb-event-filter-removed caught tb_test_noirq_suspend_resume_retained
tb-xdomain-accepts-responses caught tb_test_noirq_xdomain_filter
tb-xdomain-accepts-services caught tb_test_noirq_xdomain_filter
tb-xdomain-queues-any-request caught tb_test_noirq_xdomain_filter
tb-resume-keeps-flag caught tb_test_noirq_suspend_resume_retained
tb-suspend-never-flags caught tb_test_noirq_suspend_resume_retained
tb-retain-after-failed-suspend caught tb_test_noirq_suspend_resume_retained
tb-resume-starts-retained-ctl caught tb_test_noirq_suspend_resume_retained
How it was run
./tools/testing/kunit/kunit.py run --arch=arm64 --make_options LLVM=1 --jobs=8 --kunitconfig=<file>

kunitconfig: KUNIT, PCI, PM, SUSPEND, OF, ARCH_APPLE, USB4, USB4_KUNIT_TEST, APPLE_PMP_REPORT, APPLE_PMP_REPORT_START_KUNIT_TEST, DEBUG_KERNEL, PROVE_LOCKING, KASAN.

The test domain has no control channel, so a path that stops or starts a retained one is a NULL dereference that KASAN reports and KUnit records as a failed case.

Assisted-by: LLM (Claude:Opus 5.5), LLM (Claude:Fable 5.2)

A host router that stays awake through suspend-to-idle keeps its control
channel when every connection is another host, so that the peer's XDomain
discovery is still answered. Nothing tests which suspends retain the
channel or what gets through it while the domain is suspended.

Add four cases to the thunderbolt suite:

- tb_xdp_noirq_request() admits the UUID, properties and link state
  status requests and no other packet type;
- tb_domain_retain_noirq_control() retains only for a suspend-to-idle of a
  host router with QUIRK_NO_SYSTEM_SLEEP that has an XDomain and no router
  behind any port;
- tb_domain_suspend_noirq() and tb_domain_resume_noirq() leave a retained
  control channel alone, retain nothing when the connection manager
  refuses the suspend, and tb_domain_event_cb() drops every event but an
  XDomain request until the domain has resumed;
- tb_xdomain_handle_request() consumes service protocol packets,
  responses and state-changing discovery requests while retained, without
  calling a handler or queueing work.

The domain in these cases has no control channel, so a path that stops or
starts a retained one faults.

tb_domain_event_cb(), tb_domain_retain_noirq_control() and
tb_xdp_noirq_request() become VISIBLE_IF_KUNIT for this; they stay static
without CONFIG_KUNIT.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
apple_pmp_report_fast_die_effort() and the T8142 report layout have no
test. A wrong lane shift, a missed "PMP is running" check or a 32-bit read
of the T8142's 16-byte entry would hand a CPU cluster the wrong thermal
effort, or none.

Add the apple-pmp-fast-die suite, on a report in memory published the way
probe publishes it:

- each lane is one byte of the low word, read 32 or 64 bits wide, and a
  lane past the report's count is -EINVAL with nothing stored;
- a stopped PMP gives -EAGAIN, and status bits other than "ready" count
  as running only where the SoC's table says so;
- the report is found by its node (-EPROBE_DEFER when none is bound) and
  one without the entry gives -EOPNOTSUPP;
- the T8142 table matches its PMP's entry numbers: status 1, fast die 15
  (two lanes, wide), device requests 39, acknowledgments 47, DVFS 55..70.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Non-author review of f925bef + 005b8bb. Verdict: no blocker. I read the code; I didn't run the KUnit suites myself.

Checked and holding

  • The only non-test change is the visibility of tb_domain_event_cb(), tb_domain_retain_noirq_control() and tb_xdp_noirq_request(). Their prototypes are added inside the existing #if IS_ENABLED(CONFIG_KUNIT) block in tb.h, so they match VISIBLE_IF_KUNIT exactly: no missing-prototype warnings with KUnit on, and still static with it off. test.c links into thunderbolt.ko, so no EXPORT_SYMBOL_IF_KUNIT is needed. The pmp-report cases go into the existing pmp-report-start-test.c, behind the existing Kconfig symbol, and only its help text changes.
  • The mutant table is a good negative control: 27 of 28 mutants are caught, and the survivor is equivalent for a report held in memory.

Points

  1. Commit 1 says "the domain in these cases has no control channel, so a path that stops or starts a retained one faults". A NULL dereference as the failure signal takes down the whole KUnit run (an oops in kthread context) instead of reporting one failed case, and it depends on the code dereferencing the pointer first. A small stub tb_ctl, or a check on the state that would have been touched (KUNIT_EXPECT_* on the retained flag plus a counter in a test hook), turns those mutants into clean failures. The tb-resume-starts-retained-ctl mutant is presumably caught only by this fault today.
  2. Nit: the pmp T8142 case pins the table numbers (status 1, fast die 15, ...) that pmdomain: apple: pmp-report: add T8142 report and wire fast-die effort #2789 already put in the driver. That's fine as a change detector, but the test can't tell whether the numbers are right. A comment saying they mirror the driver table (not an independent source) keeps a future reader from treating the test as validation of the layout.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Adversarial pre-PR checklist (§1–§6) review at 005b8bbfd59868ec13d3804f92187553c05535c0 (CI: 7/7 green — kunit, host-tests, rust-build, source, and all 3 DWC3/ATC builds; MERGEABLE / CLEAN).

Verdict: APPROVE — 0 blockers. Ready for MERGETRAIN-LINUX4.

Audit summary

  • Non-test surface: Minimal and clean — only marks tb_domain_event_cb(), tb_domain_retain_noirq_control(), and tb_xdp_noirq_request() VISIBLE_IF_KUNIT with matching declarations inside #if IS_ENABLED(CONFIG_KUNIT) in drivers/thunderbolt/tb.h (stays static when CONFIG_KUNIT=n; test.c links into thunderbolt).
  • Test correctness & hygiene:
    • drivers/thunderbolt/test.c: tb_test_noirq_alloc() skips cleanly if !IS_ENABLED(CONFIG_SUSPEND), saves/restores pm_suspend_global_flags and drops the domain device reference via kunit_add_action_or_reset(), and unregisters the synthetic protocol handler via KUnit action. All four cases match domain.c / xdomain.c semantics accurately.
    • drivers/pmdomain/apple/pmp-report-start-test.c: synthetic report is registered and removed via apple_pmp_reports_lock + list_del_rcu() + synchronize_rcu() in a KUnit action; covers 32/64-bit reads, lane bounds, running_any, -EPROBE_DEFER, -EOPNOTSUPP, and T8142 table offsets.
    • Strong negative control evidence: 91/91 arm64 QEMU KUnit tests pass with KASAN + lockdep, 27/28 single-line mutants caught, checkpatch --strict and W=1 clean with/without CONFIG_KUNIT.
  • Minor non-blocking nits: (1) relying on a NULL tb->ctl dereference to catch a mutant that touches a retained control channel will oops the KUnit thread rather than record a clean assertion failure; (2) pmp_fast_die_t8142_test() pins the driver table as a regression guard rather than validating hardware independently. Neither blocks merge.

§1–§6 Checklist Summary

  • §1 No model gating: Pass (tests only; no driver gating added).
  • §2 Production-ready: Pass (no hacks, no new params, CI 7/7 green).
  • §3 Safety: Pass (in-memory fake domain/report only; proper cleanup actions).
  • §4 Clean-room & attribution: Pass (both commits carry human author/committer + human Signed-off-by: only, zero AI trailers in commits, Assisted-by: in PR body).
  • §5 Evidence: Pass for scope (tests-only; hardware row N/A; thorough KUnit + KASAN/lockdep + 27/28 mutant verification).
  • §6 Naming: Pass.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Review at 005b8bb.

Second, non-author pass. I tried to break the tests by reading them against the code. I couldn't run KUnit: no buildslot came free in 30 minutes. Verdict: nits. Nothing blocks, but point 1 is the behaviour linux#2767 exists for, so it's worth fixing before merge.

  1. Only the packets that must be dropped are tested, never the ones that must get through. While the channel is retained, the cases check drops, but none checks that a discovery request still reaches the XDomain code. Two one-line mutants that stop a peer's discovery being answered during s2idle should, by my reading, pass every new case:
    • domain.c:344: drop && type != TB_CFG_PKG_XDOMAIN_REQ, so the event callback swallows everything while retained. tb_test_noirq_suspend_resume_retained only feeds non-XDomain types (dropped[], test.c:4521), and tb_test_noirq_xdomain_filter calls tb_xdomain_handle_request() directly, bypassing the callback.
    • xdomain.c:2701-2702: make return true unconditional while retained. The loop at test.c:4641 only sends refused types with the discovery UUID. Nothing sends UUID_REQUEST, PROPERTIES_REQUEST or LINK_STATE_STATUS_REQUEST while retained and expects it to be queued.
      I suspect they're missing because the admitted path queues work on tb->wq, which is NULL in the test domain. Give the domain an ordered workqueue (plus a destroy action) and a host UUID. Then send UUID_REQUEST with the discovery UUID while retained, check it took the domain reference (kref 2), and flush. Do the same through tb_domain_event_cb() with TB_CFG_PKG_XDOMAIN_REQ. Adding TB_CFG_PKG_XDOMAIN_RESP to dropped[] would cover the other half of the line-344 filter.
  2. On the first pass's point 1: a NULL tb_ctl oops doesn't take down the run here. lib/kunit/try-catch.c:76-83 records it as "try faulted" for that case and goes on. The costs are a tainted kernel for the rest of the run, tb->lock left held in that case, and a dead run under panic_on_oops. A stub ctl would still be nicer.
  3. The non-test lines are correct. The three prototypes sit inside #if IS_ENABLED(CONFIG_KUNIT) (tb.h:770-780), the same condition VISIBLE_IF_KUNIT uses, so a non-KUnit build is unchanged. test.o links into thunderbolt.o, so no EXPORT_SYMBOL_IF_KUNIT/MODULE_IMPORT_NS is needed. pm_suspend_global_flags is EXPORT_SYMBOL_GPL, so USB4=m links.
  4. Rules pass: no gates, no params. The T8142 names in pmp-report-start-test.c:563-568 are ADT PTD-range names already in the tree, and the offsets match apple_pmp_offsets_t8142. Human Signed-off-by only.
  5. The pmp suite follows apple_pmp_report_fast_die_effort() (pmp-report.c:369-397). BIT_ULL(36) really does test the 64-bit status read.

We'll post the KUnit numbers plus the two mutants above once a buildslot frees up (configs saved).

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.

2 participants