Skip to content

[Joshua's agent] HID: dockchannel-hid: accept the T6050 multi-touch report size (draft) - #1737

Draft
joshuaswarren wants to merge 2 commits into
aurora-silicon:integration/aurorafrom
joshuaswarren:w88/hid-report-pad
Draft

joshuaswarren wants to merge 2 commits into
aurora-silicon:integration/aurorafrom
joshuaswarren:w88/hid-report-pad

Conversation

@joshuaswarren

@joshuaswarren joshuaswarren commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

[Joshua's agent] Draft. Rebased onto integration/aurora a88bb04. Compiles; not booted in this form.

The 14-inch M5 Max trackpad (T6050 multi-touch) declares its raw report as one Report Size item of 0x80000 bits, which hid-core refuses. On this base that part is already handled for a 4-byte Report Size: dchid_parse() clamps it (0768762, written for the K116s firmware). So on this base the gain of this PR is the pad, plus the clamp that allocates the pad's buffer. In two commits:

  1. The clamp moves to dchid_handle_descriptor(), where the descriptor is copied, and covers Report Size items of 2 to 4 bytes. It allocates the pad buffer there, when a clamp happens (next commit). The clamp in dchid_parse() can no longer change anything, so it is removed, function and call. The KUnit case for the clamp is in this commit. This commit used to be the first commit of [Joshua's agent] HID: magicmouse: parse the 0x5a MTP report of the K114c #1568; the same clamp was in both PRs, so it lives here only.
  2. After the clamp, hid-core expects 2048-byte reports and drops the real ones (about 437 bytes) with "Event data for report 0 was too short (2048 vs 437)". Short reports are now copied into a zero-padded buffer and passed to hid_safe_input_report() with the true length.

If the pad buffer cannot be allocated, the descriptor is dropped (the same state a failed copy of it leaves) and the failure is logged, so the interface does not come up with reports it would drop.

Buffer choice: one 2 KiB buffer per interface, allocated with devm only when a clamp happens. Each interface runs its reports on its own ordered workqueue, so one buffer needs no lock. A kzalloc per report would add an allocation on the touch hot path for no gain.

Not covered (reviewers' notes, left as they are):

  • No test covers the K116s path.
  • The pad and its allocation-failure branch have no test.
  • The pad assumes the clamped report is the only report of its interface, with Report Count 1; a descriptor with more than one such field would need more than this.

Merge order: this lands before #1568 (the 0x5a parser) and before #1605 (the touch reset); both need the interface to parse and its reports to arrive.

Validated on, and reach

What ran where:

  • 13-inch M1 MacBook, build only, at this head: dockchannel-hid.o builds with gcc 16.1.1 and W=1, no warnings (my build; a reviewer's used gcc 12.2), with the KUnit case compiled in (CONFIG_KUNIT=y, CONFIG_HID_DOCKCHANNEL_PARSER_KUNIT_TEST=y), on a 16K-page arm64 config. The first commit alone builds the same way. The KUnit case was not run: it needs a kernel boot or UML, which I did not do.
  • Not booted at this head on any Mac. The clamp and pad, in earlier forms, were in the boots reported on [Joshua's agent] HID: magicmouse: parse the 0x5a MTP report of the K114c #1568: the 14-inch M5 Max MacBook Pro (K114c, 929 frames, X from -5896 to 5875) and a K114s reported there by a second tester. Those ran old heads, on a base without the dchid_parse() clamp, not this one. The pad commit was reported earlier as compiled only and not booted.

Applies beyond the M4: the clamp applies to any dockchannel-hid interface that declares an oversized Report Size item. The pad applies to every interface that was clamped, so it now also applies to the K116s trackpad, which the dchid_parse() clamp already served without it. NOT CHECKED on a K116s: whether the padded buffer changes anything there. No M4 or other model checked.

m tester run (omarchy-m-testing.org): feature row Trackpad. The tester needs the hardware; no tester run is linked to this change.

…rives

The multi-touch interface of the 14-inch M5 Max MacBook Pro (t6050)
declares its raw touch report as a single Report Size item of 0x80000
bits. hid-core rejects any Report Size above 16384 with "invalid
report_size 524288", so the interface cannot parse.

hid-magicmouse consumes these reports in raw_event() and never uses the
parsed field layout. Clamp each Report Size item in the copied descriptor
to the hid-core limit, and log the clamp once per item.

dchid_parse() already clamps a 4-byte Report Size of the K116s firmware
(0768762). This clamp runs earlier, in dchid_handle_descriptor(), on
Report Size items of 2 to 4 bytes, so that item is never left for the one
in dchid_parse(). The next commit allocates its buffer for short reports
here, when a clamp happens. The clamp in dchid_parse() can no longer change
anything and is removed.

A KUnit case feeds a descriptor with a long item whose data looks like a
Report Size prefix, a normal Report Size and the oversized one, and checks
that only the oversized item changes.

Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
hid-core refuses a report buffer smaller than the size its parsed layout
implies. After the Report Size clamp that size is 2048 bytes, while the
T6050 multi-touch firmware sends reports of about 437 bytes, so every
report logged "Event data for report 0 was too short" and was dropped.

Copy short reports into a zero-padded per-interface buffer and pass the
true length to hid_safe_input_report(). The buffer exists only on
interfaces that were clamped, and only that interface's ordered workqueue
uses it, so it needs no locking.

If the buffer cannot be allocated, the descriptor is dropped, the same state a failed copy of it leaves, and the
failure is logged.
@axboe

axboe commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Data point from a K116s (16" M5 Pro OLED): the same invalid report_size 524288 parse failure happens there without a clamp, on both hid-generic and magicmouse (seen today on integration/aurora 10dca1d).

I have been running a one-commit clamp in dockchannel-hid on that machine for a few days with a working trackpad. The clamp alone was not enough there: the K116s trackpad sends a different frame layout ("Trackpad26"), so hid-magicmouse needed support for it as well. Both patches went to @sithglan in my K116s series but are not in a PR yet. I can test this PR on the K116s if that helps.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

[Joshua's agent] Thank you, that is useful: the same 524288 report size on the K116s says the clamp belongs in dockchannel-hid for the whole T6050 family, not only the 14-inch M5 Max. Yes please, a run of this PR on the K116s would help. With only this patch we expect the parse error gone, and the trackpad still needing your Trackpad26 support in hid-magicmouse; if you see anything else, that is what we want to know.

@axboe

axboe commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Ran this PR on the K116s (16" M5 Pro OLED, 27.2 stub). dockchannel-hid.ko built from the two commits here (c715edf, 99a8061) against my running kernel (integration/aurora aa68b3c plus my K116s series), loaded from updates/ in place of my own clamp. Two boots:

This PR alone (hid-magicmouse without the Trackpad26 support of #1830):

dockchannel-hid 294b30000.input: multi-touch: clamping Report Size 524288 to 16384
dockchannel-hid 294b30000.input: Interface keyboard is now ready
magicmouse 0019:05AC:0362.0002: input,hidraw2: HOST HID v7.10 Mouse [Apple MTP multi-touch] on 294b30000.input.1 (multi-touch)
dockchannel-hid 294b30000.input: Interface multi-touch is now ready

The parse failure is gone, the keyboard works and the multi-touch input device registers. No pointer and no clicks, and nothing arrives on the event device. As you expected.

This PR plus the hid-magicmouse commit of #1830: the trackpad works. 20 s of use gave about 22000 events on the event device: positions, touch major/minor, orientation and pressure on three slots, 5 physical clicks, two- and three-finger contacts. No "too short" message.

One difference from the clamp in #1830: with this PR the log has, once per boot,

magicmouse 0019:05AC:0362.0002: hid_field_extract() called with n (16384) > 32! (kworker/u72:0)

I do not get that line with my clamp, which clamps to the same 16384 bits but does not pad. My guess is that the padded report is now long enough for the HID core to walk the field once before hid-magicmouse's raw_event handler claims the frames; I have not confirmed that. It had no visible effect.

So either clamp works for the K116s. I am fine dropping mine from #1830 in favour of this one; the magicmouse commit is needed either way.

@joshuaswarren joshuaswarren changed the title HID: dockchannel-hid: accept the T6050 multi-touch report size [Joshua's agent] HID: dockchannel-hid: accept the T6050 multi-touch report size (draft) Nov 15, 2026
@joshuaswarren

Copy link
Copy Markdown
Contributor Author

GREEN on b8a54f3
Model: zai/glm-5.3

Both commits match the body, and the KUnit case is the strong part: the expected bytes pin the two behaviors that matter - the oversized Report Size item (0x80000) comes out as 16384, and Report-Size-looking data inside a long item (0xfe 02 ...) is left untouched, so the clamp cannot corrupt an unrelated operand. The pad commit's design is argued, not asserted: one devm buffer per interface allocated only when a clamp happened, lock-free because each interface runs its reports on its own ordered workqueue - the reasoning holds, and passing the true length to hid_safe_input_report keeps the short-report semantics honest. Merge order (before #1568 and #1605) is stated with the reason. The Validated-on section is the honest form throughout: build-only with the KUnit case compiled in and explicitly not run, the old-head boots attributed to the old heads, the pad's earlier clang-compile-only status kept, and the reach limited to interfaces that actually declare an oversized item.

Model: zai/glm-5.3 (live from lane_models.py this turn).

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

GREEN on b8a54f3

Independent review. No blocking items. I did not boot a Mac, so nothing here confirms real touch reports.

What I ran, on a checkout of this head:

Non-blocking notes:

  1. The pad commit has no test. The KUnit case covers only the clamp. I could not find a case that would fail if the pad branch in dchid_handle_report() were removed. A case that feeds a short report to a clamped interface would cover it.
  2. The devm_kzalloc() result is not checked. If it fails, iface->pad stays NULL, the clamp still happens, and every real report is dropped by hid-core again with no message of its own. Log the failure, or skip the clamp when the buffer is missing.
  3. The pad assumes Report Count 1. The buffer is 2048 bytes, which is 16384 bits. A descriptor that clamps the size and then declares a larger Report Count would still expect more bytes than the pad has. The T6050 trackpad is not known to do that, so I did not count it as a defect.
  4. Compiler version. The body says gcc 16.1.1. I built with 12.2, with no warnings.

Model: anthropic/claude-sonnet

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

GREEN on 97cfe1f
Model: zai/glm-5.3

Re-review at the checked-allocation head (the compare confirms only the pad commit changed, one file, and the clamp commit is untouched). Every exit of dchid_clamp_report_sizes is covered and none leaves a bad state: the two truncated-descriptor returns leave the tail untouched as before (0), the normal end returns 0, and the devm_kzalloc failure returns -ENOMEM - with the allocation ordered before the descriptor bytes are rewritten, so no half-clamped descriptor exists even transiently. The caller drops the descriptor on the error and logs it, which the body states in exactly the kmemdup-equivalence terms the diff implements: the interface does not come up holding reports it would drop. The body's new sentence matches the code path for path. The pad use stays guarded on the buffer existing and on the report actually being short, with full-length reports passing through unpadded. Everything from the previous verdict (the KUnit byte-level pins, the buffer reasoning, the validation attribution) carries.

Model: zai/glm-5.3 (live from lane_models.py this turn).

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

GREEN on 97cfe1f

Re-review of the changed pad commit. The clamp commit 387c0d5 is unchanged. No blocking items. I did not boot a Mac.

What I checked, at this head:

  • A NULL hid_desc after the new failure. iface->hid_desc is read in three places: the use_ring guard in dchid_handle_init(), dchid_parse(), and the descriptor handler itself. With use_ring, the guard stops the interface from being created. Without use_ring, creation still runs and dchid_parse() passes a NULL pointer with length 0. The old clamp loop does nothing on length 0. hid_open_report() then rejects it with rejecting 0-sized report descriptor and -EINVAL, hid_add_device() fails, and dchid_create_interface_work() logs it and clears iface->hid. That is the same state a failed devm_kmemdup() leaves, and nothing else dereferences the descriptor.
  • KUnit. Same arm64 qemu kernel as before: dchid_report_size_clamp_test passes, 19 tests ran, 18 passed and 1 skipped (CONFIG_UCLAMP_TASK).
  • Build. hid-magicmouse.o and dockchannel-hid.o (with the KUnit cases compiled in) build with W=1 and no warnings, gcc 12.2.
  • Body against the diff. The gcc sentence now says the author built with 16.1.1 and a reviewer's build used 12.2, which is what I used. The allocation sentence matches the code: a failed buffer allocation logs, drops the descriptor and returns before any Report Size byte is changed.

Non-blocking notes:

  1. The base already has a clamp. dchid_clamp_report_size() (singular, in dchid_parse(), added for the K116s firmware) already clamps a 4-byte Report Size above 16384 bits. This PR clamps in dchid_handle_descriptor(), which runs earlier and is the only place hid_desc is set. So the old function can no longer change anything and is dead code after this PR. Please delete it and its call, so only one clamp is left. This was already true at the previous head and I missed it in my first review. The same fact makes two sentences in the body and in the clamp commit message stale on this base: the interface does not "fail to parse" for a 0x80000 item, because the old clamp handles it at parse time. What this PR adds on this base is the pad, plus the clamp that allocates it.
  2. The failure path and the pad have no test. The KUnit case covers only the clamp. A case that feeds a short report to a clamped interface would cover the pad, and the ENOMEM branch would need a failing allocator.
  3. The pad assumes Report Count 1. The buffer is 2048 bytes. A clamped descriptor with a larger Report Count would still expect more bytes than the pad has.

Model: anthropic/claude-sonnet

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

GREEN on d43ac77
Model: zai/glm-5.3

Re-review at the base-claim head. Verified against both trees: the base a88bb04 clamps a 4-byte Report Size in dchid_parse (the K116s commit), the singular dchid_clamp_report_size had exactly one caller (the dchid_parse line), and at this head both the function and its call are gone with the plural, buffer-allocating clamp now running in dchid_handle_descriptor where the descriptor is copied - the claims in the rewritten commit message and body match the diff exactly, including the corrected framing that on this base the gain is the pad plus the allocating clamp. The pad commit is byte-identical in content to the previous head (message unchanged, allocation check and all four exits verified last review). Nothing else referenced the removed function (it was static with its single call site). The KUnit case moves with the clamp commit.

Model: zai/glm-5.3 (live from lane_models.py this turn).

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

Addendum on d43ac77: the K116s 4-byte coverage question checked against both trees. The old singular clamp matched only the 4-byte form (type 1, tag 7, size 4, i.e. the 0x77 item); the new clamp matches (prefix & 0xfc) == 0x74 with n >= 2, which is the 2-byte and 4-byte Report Size items (0x76 and 0x77, with n==3 mapped to 4) - a strict superset, running earlier at the descriptor copy. A K116s descriptor that the old path clamped is clamped identically by the new one, and a 2-byte oversized item that the old path ignored is now caught too.

Model: zai/glm-5.3 (live from lane_models.py this turn).

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

GREEN on d43ac77

Re-review of the rebuilt stack. No blocking items. I did not boot a Mac.

What I checked, at this head:

  • The old clamp is gone. git grep for clamp_report_size finds only the new dchid_clamp_report_sizes(): its definition and its one call in dchid_handle_descriptor(). dchid_parse() now only calls hid_parse_report(). iface->hid_desc is set in one place (the copy in dchid_handle_descriptor()), and the new clamp runs on it right there, so no descriptor reaches dchid_parse() unclamped.
  • The new clamp covers everything the old one did. The old one matched a global Report Size item with a 4-byte value (prefix 0x77) above 16384 and set it to 16384 in place. The new one matches prefix 0x74 to 0x77 with a size of 2 to 4 bytes, applies the same limit, and writes the same value. The long-item skip is the same. The bounds check i + 1 + n > len is the old i + 4 < len for a 4-byte item. So the K116s item is handled the same way, and 2- and 3-byte items are now handled as well.
  • KUnit. Same arm64 qemu kernel as before: dchid_report_size_clamp_test passes, and 19 tests ran with 18 passed and 1 skipped (CONFIG_UCLAMP_TASK). With this head's test file and the base driver code, the test fails and the other 11 parser cases pass.
  • Build. hid-magicmouse.o and dockchannel-hid.o build with W=1 and no warnings, gcc 12.2, at the head and at the first commit alone.
  • Messages and body against the code. The clamp commit message and the body say what the code does: the clamp moved to the descriptor copy, 2- to 4-byte items, the old one removed (function and call), and 07687621d1 is the earlier K116s clamp. The "trackpad never registered" wording is gone. The body's reach paragraph says the pad now also applies to the K116s and that this is not checked there, which is what the code does. The gcc sentence (the author's 16.1.1, a reviewer's 12.2) is right for my build. The allocation-failure paragraph matches the code, which I reviewed at the previous head. The pad commit's hunks are unchanged.

Non-blocking notes:

  1. K116s is not covered by a test. The pad now also runs there, as the body says. The Trackpad26 path reads the frames in raw_event() first, so I expect no change, but nothing here shows it. A K116s boot would settle it.
  2. The pad and the ENOMEM branch have no test, as before.
  3. The pad assumes Report Count 1. The buffer is 2048 bytes.

Model: anthropic/claude-sonnet

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