Skip to content

soc: apple: sep: add HDCP 2.2 transmitter client (ep 0x0e) - #3256

Merged
RyanTheTide merged 3 commits into
mainfrom
feat/sep-hdcp-client
Nov 27, 2026
Merged

RyanTheTide merged 3 commits into
mainfrom
feat/sep-hdcp-client

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What:
Add the in-kernel Apple SEP HDCP 2.2 transmitter client for SEP endpoint 0x0e (hdcp), exposing a narrow C interface (include/linux/apple-sep-hdcp.h) for the display driver (drm/apple) to run HDCP 2.2 authentication without any key material leaving the enclave.

  • include/linux/apple-sep-hdcp.h: declares the per-channel transmitter API (apple_sep_hdcp_open, ake_cert, ake_h_prime, ake_pairing, lc_init, lc_l_prime, ske, repeater_list, repeater_stream, finish, set_encryption, close, available) carrying only clear-text HDCP 2.2 protocol fields (never km, ks, kd, or device keys), plus inline -ENODEV/false/no-op stubs when CONFIG_APPLE_SEP_HDCP_INTERFACE is disabled.
  • drivers/soc/apple/hdcp.rs: implements endpoint 0x0e discovery (descriptor + OOL layout config check), persistent 16 KiB OOL buffers, runtime sparse-aware interface-channel enumeration (0x27/0x28 bitmask from per-interface channel IDs, no hardcoded per-SoC channel table), closed 26-command wire table, per-channel protocol state machine (first pairing, stored km, bounded locality-check and repeater stream-manage retries, repeater ReceiverID list and V'/V, finish, encryption on/off, teardown from any open state), outbound OOL repoison/await-written synchronisation and buffer scrubbing, -EAGAIN before PHASE_READY or under sleep gating, non-secret reply-word diagnostics on failed commands, and endpoint quarantine on unanswered commands.
  • drivers/soc/apple/hdcp_shim.c & shim.h: built-in C registration shim matching the fv_shim.c pattern, with argument validation, kfree_sensitive/memzero_explicit buffer hygiene, and output zeroing on error.
  • drivers/soc/apple/sep.rs: wires discovery, dispatch, kernel API registration/unregistration, waitqueue wake, and retaining registered ool_hdcp buffers on remove().
  • Tests: Rust KUnit suite apple_sep_hdcp (13 cases, incl. sparse channel tables), C KUnit suite apple_sep_hdcp_shim (6 cases), and tools/aurora-sep/tests/test_hdcp_client.py wired into .github/workflows/sep-source.yml.

Tested:

  • Hardware row at c02408de Mac mini (J473, T8112, 7.3.0-aurora-hdcp9, all 10 PR files byte-identical): PASS — real SEP ep 0x0e first-pairing and 5x stored-km sessions (Open/Prepare/Start/GetRtx, PutCert, PutRrx, QueryStoredKm NotStored -> Stored, GetEkpubKm, PutHContext, PutHPrime verified, PutPairing, GetRn, LcStart, PutLPrime verified, GetEks, GetRiv, Close), s2idle 1/1, 0 SEP errors, 0 AVCs, 0 failed units, Enforcing; restored to 7.3.0-aurora-fleet89.
  • Hardware row at c02408de MacBook Pro 16" (J616s, T6040, 7.3.0-aurora-hdcp9, all 10 PR files byte-identical): PASS — sparse channel table (0..5, 7..14, skipping 6) enumerated cleanly, 5 live AKE sessions on channel 7 (GetRtx, PutCert, PutRrx, QueryStoredKm, GetEkpubKm, Close), s2idle 1/1, existing SEP endpoints (Touch ID, xART, trusted-keys, hwrng) healthy, 0 SEP errors, 0 failed units, Enforcing; restored to 7.3.0-aurora-fleet89.
  • ARM64 QEMU KUnit (sep.kunitconfig, LLVM=1): apple_sep_hdcp 13/13 PASS, apple_sep_hdcp_shim 6/6 PASS, full apple_sep* 336/336 PASS (0 warnings in new/changed files).
  • Modular arm64 build (CONFIG_APPLE_SEP=m, CONFIG_APPLE_SEP_KUNIT_TEST=n, fleet89 config, LLVM=1): drivers/soc/apple/apple-sep.o and hdcp_shim.o compile cleanly.
  • Stub header cross-compile check (CONFIG_APPLE_SEP_HDCP_INTERFACE=n, clang -target aarch64-linux-gnu -Wall -Werror): PASS.
  • Host tests: all sep-source.yml Python tests + test_hdcp_client.py (4/4 under python3 and python3 -O) + test_log_ratelimit.py (5/5) + tools/asahi/run-host-tests.py --only sep (23/23): PASS.
  • scripts/checkpatch.pl --strict: 0 errors, 0 code warnings, 0 checks.

Risk:
two-way · all Macs with Apple SEP (apple-sep, CONFIG_APPLE_SEP_HDCP_INTERFACE). Nothing sends messages on endpoint 0x0e until a display driver consumer opens a session; existing SEP endpoints are untouched.

Not yet:

  • End-to-end HDCP 2.2 repeater list/stream/link-encryption proof with drm/apple DCP relay (tracked by the display HDCP driver PR stacking on this interface).

Declare the in-kernel API through which the display driver drives HDCP 2.2
transmitter authentication on the Apple SEP (endpoint 0x0e). Only clear-text
protocol fields (r_tx, cert_rx, r_rx, Ekpub(km)/stored km, H', pairing
Ekh(km), r_n, L', Edkey(ks), r_iv, ReceiverID list, V'/V, stream type, M')
cross this boundary; km, ks, kd and device keys never leave the enclave.

Provide inline -ENODEV/false/no-op stubs when CONFIG_APPLE_SEP_HDCP_INTERFACE
is disabled so display driver builds without CONFIG_APPLE_SEP link cleanly.

Signed-off-by: Ryan Murray <[email protected]>
Implement the Apple SEP HDCP 2.2 transmitter endpoint (0x0e, 'hdcp') in
drivers/soc/apple/hdcp.rs and expose it to the display driver through the
built-in C shim (hdcp_shim.c) backing include/linux/apple-sep-hdcp.h.

- Validate the endpoint's discovery descriptor and OOL layout config word
  before use; allocate persistent 16 KiB inbound/outbound OOL buffers and
  retain registered buffers on remove().
- Enumerate the enclave's HDCP interface channels at runtime with commands
  0x27 and 0x28 rather than hard-coding a per-SoC channel count.
- Enforce the closed 26-command wire table and per-channel HDCP 2.2 state
  machine (first-time pairing, stored km, bounded locality-check and
  repeater stream-manage retries, repeater ReceiverID list and V'/V,
  finish, encryption on/off, teardown from any open state).
- Synchronise outbound OOL reads with repoison/await-written, scrub buffers
  after each exchange, return -EAGAIN while SEP bring-up or sleep gating is
  active, and quarantine the endpoint until reset if a command goes
  unanswered.
- Add Rust KUnit suite apple_sep_hdcp (13 cases), C KUnit suite
  apple_sep_hdcp_shim (6 cases), and host check test_hdcp_client.py wired
  into sep-source.yml.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide requested review from a team and DjDeveloperr as code owners November 26, 2026 14:29
@github-actions github-actions Bot added area:platform Area from CODEOWNERS (bot) area:release Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at c02408de: not ready yet

Check Detail
CI at head no failing: pr-text / pr-text, pr-text / pr-text, KUnit prores, KUnit scaler, KUnit macsmc, KUnit clpc
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at c02408de
Conflicts ok none
PR text ok Risk: two-way · all Macs with Apple SEP (apple-sep, CONFIG_APPLE_SEP_HDCP_INTERFACE). Nothing sends messages on endpoint 0x0e until a display driver consumer opens a session; existing SEP endpoints are untouched.

Areas: area:platform, area:release

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

…plies

Command 0x28 (GetChannelInfo) is indexed by interface slot 0..count-1
from command 0x27, while info[0] carries the interface's actual HDCP
channel ID. On T6040 the 14 interfaces advertise channel IDs 0..5 and
7..14 (skipping channel 6), so requiring info[0] == index rejected
enumeration with -EIO on every attempt.

Record the enumerated channel IDs in a bitmask so sparse channel sets
are validated accurately against hardware-reported IDs, extend KUnit
with a sparse-table case, and log unexpected reply words (status/length
only, never payload bytes) plus OOL registration failures.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

RyanTheTide commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Exact-head hardware rows at c02408dec10fbbf05170532a1e0ace5da778639a (combined 7.3.0-aurora-hdcp9 kernel carrying all 10 PR #3256 files byte-identically, git diff c02408dec10fb..a160e18c95c3 = 0 lines):

  • c02408de Mac mini (J473, T8112) 7.3.0-aurora-hdcp9: PASS — apple_sep ready in 3121 ms (12 endpoints incl. hdcp), OOL registered, 0x27/0x28 contiguous channel table enumerated; real SEP ep 0x0e executed full first-pairing and 5x stored-km sessions on channel 7 (Open/Prepare/Start/GetRtx, PutCert, PutRrx, QueryStoredKm NotStored -> Stored, GetEkpubKm 128 B RSA-OAEP, PutHContext, PutHPrime verified status 0, PutPairing stored, GetRn, LcStart, PutLPrime verified status 0, GetEks, GetRiv, Close) plus AKE on channel 5; s2idle 1/1 PASS; 0 SEP errors, 0 -EIO, 0 quarantine, 0 AVCs, 0 failed units, SELinux Enforcing; restored and verified on 7.3.0-aurora-fleet89.
  • c02408de MacBook Pro 16" (J616s, T6040) 7.3.0-aurora-hdcp9: PASS — apple_sep ready in 3116 ms (12 endpoints incl. hdcp; Touch ID, xART, trusted-keys, hwrng healthy), OOL registered, 0x27/0x28 sparse channel table (0..5, 7..14, skipping absent channel 6) enumerated cleanly; 5 live AKE sessions on channel 7 (Open/Prepare/Start/GetRtx, PutCert, PutRrx, QueryStoredKm, GetEkpubKm 128 B RSA-OAEP, Close) + s2idle 1/1 PASS; 0 SEP errors, 0 -EIO, 0 quarantine, 0 failed units, SELinux Enforcing; restored and verified on 7.3.0-aurora-fleet89.

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Nov 26, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Non-author adversarial review at c02408de (merge train). Verdict: MERGE once CI is green. The KUnit and pr-text runs were cancelled by the runners, not failed, and are re-running.

Blockers: none.

Checked

  • Untrusted SEP replies:
    • The reply length must equal the command's fixed output size from the table, or the reply is Malformed and nothing is read. Reads happen after ool_await_written and a repoison.
    • The channel count is bounded to 1..32, and each info[0] must be below 32 before the shift.
    • The receiver list is 1..31 whole IDs in both the shim and Rust; inputs are at most 4 KiB into 16 KiB buffers.
    • I found no overflow or out-of-bounds copy.
  • Late replies and teardown:
    • There is one exchange in flight. A timeout quarantines the endpoint, so a late reply can't be matched to the next command.
    • The shim holds the registration rwsem across every op, and remove() unregisters before freeing. Registered OOL buffers are kept on remove, so there is no DMA use-after-free.
  • Secrets: no km, ks or kd crosses the interface. Logs show only the mailbox word. In/out buffers are wiped after every exchange, and the shim uses memzero_explicit/kfree_sensitive and zeroes outputs on error.
  • Fails closed:
    • Success needs status 0 and the exact length. A refused verify returns -EACCES, anything else -EIO.
    • L' retries are capped at 1024 and M' at 2. Any other failure fails the session.
    • "No stored km" is accepted only for the stored-km query, and first pairing can't skip Pairing.
  • Rules:
    • There's no chip, board or firmware gate. Channels come from 0x27/0x28 at runtime, and the endpoint is found by its hdcp name.
    • There's no module or cmdline parameter and no magic delays. The 1 s value is a reply timeout; the spec's 200 ms is left to the caller.
    • The commit and comment text has no wording about Apple-binary RE: argument values are observed values, and field sizes come from the HDCP 2.2 spec.
  • Rows: J473 (first pairing + 5 stored-km sessions, s2idle) and J616s (sparse channels 0..5/7..14, s2idle, other SEP endpoints healthy), both at this head.

Non-blocking follow-ups

  1. hdcp.rs close() resets the local slot even when Close never reached the SEP: send() returns -EAGAIN under the sleep gate, or the step() failure path after Open. The enclave may still hold that session, so the next Open on the channel could be refused until reboot. Whether that happens depends on how the SEP treats a re-Open, so I'm not sure. Consider keeping the slot "closing" and retrying Close on the next Open.
  2. sep.rs remove() calls hdcp_wq.notify_all() without holding hdcp_rx, so a waiter can miss the wake. Waits are capped at 1 s and later sends get -ENODEV. That means a slower unbind and possibly a spurious "quarantined" log, not a crash.
  3. apple-sep-hdcp.h: -ENODEV covers both "no SEP" and "SEP module not loaded yet", and -EAGAIN covers about 3 s of bring-up. There's no -EPROBE_DEFER or ready notification. Please document that consumers (drm: apple: HDCP 2.2 with the standard Content Protection properties #3302) must treat both as retry-later.
  4. One global call_lock and no per-channel ownership. Two consumers on the same apple,hdcp-channels value would share a session.
  5. The protocol order allows GetRiv -> Finish for a repeater; the consumer has to enforce the repeater step. There's one stream per session, so a repeater's periodic stream-manage or MST gets -EPROTO. Please document both.
  6. KUnit only: the shim test can take the global registration before the SEP probes, so the real SEP gets -EBUSY for that boot.
  7. Comment nit at hdcp.rs:52: "15 on T6040", but the J616s row shows 14 (0..5, 7..14).

@RyanTheTide
RyanTheTide merged commit 7de24c5 into main Nov 27, 2026
37 of 46 checks passed
RyanTheTide added a commit that referenced this pull request Nov 27, 2026
Resolve the on_discovery() conflict with the HDCP client (#3256):
keep the PR's late-discovery refresh of the attach-only endpoints
and main's hdcp_discovered() call.

Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide added a commit that referenced this pull request Nov 27, 2026
Resolve the remove() conflict with the HDCP client (#3256): wake
both the xars and hdcp waiters. The auto-merged parts keep the
hdcp and xars OOL buffers and discovery hooks side by side.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide deleted the feat/sep-hdcp-client branch November 27, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform Area from CODEOWNERS (bot) area:release Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant