Commit graph

12 commits

Author SHA1 Message Date
Greg Kroah-Hartman
a93862fa67 thunderbolt: Fixes for v7.3-rc6
This includes following USB4/Thunderbolt fixes:
 
   - Fix XDomain property parser to reject oversized properties
     responses.
   - Revert a quirk that causes deadlock at shutdown.
   - Fix USB4STREAM to announce FMODE_NOWAIT.
   - Add a quirk that disables CL states for Anker Prime TB5 dock to
     avoid link instability.
 
 All these have been in linux-next with no reported issues.
 -----BEGIN PGP SIGNATURE-----
 
 iQJUBAABCgA+FiEEVTdhRGBbNzLrSUBaAP2fSd+ZWKAFAmq95EYgHG1pa2Eud2Vz
 dGVyYmVyZ0BsaW51eC5pbnRlbC5jb20ACgkQAP2fSd+ZWKDxSA/7BoS4mbjriWkU
 UNH1POY3ZON53KvXmMzdTsfs5cYyQYEg7RDaBAXMc48wKn4dR6Y6wFpYgE7f5muk
 F4j2AzDTQ7B4jog4tq5hWvz65TxmtTypFBPvUBmbi/JcWnTN/K6JJTaHwTfzVF2C
 ZCXllGqQMN0ItTjwhN1hX+4xXykv5MvA8FT94olebY7x/RasPLHbgf8e2ZCMarUq
 YUhNkA4WPed6Fx2pe3HlNa9gbMDlfS7l/ZjaU18iB3QRA/o0xnoA1f8iWIuHsMdE
 FeRpp2xdVZsrsb1z6csi4Z5kabjg1aSjaV979TXxTA35tf7nplq4XwKgLGOkxt2p
 WQpQ6UctlBRzLVPakdCtRVLfQFE9UQ4kCmapEAUWj44VWqNk70GBqYkh5wG7Tlpp
 XdHEEU+hABw7+XKCBwZ3F30MePeMjHYDcsA67cUu0tkaZ8TM6DPgoeSxwtk1tNMo
 6ACtRGQOoFE0eYUthgg573JUSRJTiDq4BrTnc78uNyE5RKSOMFMZ5wVzaYlls9li
 hAw47ZPFh6/aKf59hu5Po9beA0iYXTX5Bf1RIHt7Q2Wu5RpM83xHEsy8XzCMwf//
 2xw79F+RiSzONujhfaBxckb92YImGmX6NXJuGw490rqs0MqfSbZl180yLpo11+Ag
 yHbVaYOe1o9TlEQJJKYVaVXI+cV+u2M=
 =btJS
 -----END PGP SIGNATURE-----

Merge tag 'thunderbolt-for-v7.3-rc6' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt into usb-linus

Mika writes:

thunderbolt: Fixes for v7.3-rc6

This includes following USB4/Thunderbolt fixes:

  - Fix XDomain property parser to reject oversized properties
    responses.
  - Revert a quirk that causes deadlock at shutdown.
  - Fix USB4STREAM to announce FMODE_NOWAIT.
  - Add a quirk that disables CL states for Anker Prime TB5 dock to
    avoid link instability.

All these have been in linux-next with no reported issues.

* tag 'thunderbolt-for-v7.3-rc6' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt:
  thunderbolt: Disable CL states for the Anker Prime TB5 dock
  thunderbolt: stream: Announce support for FMODE_NOWAIT
  Revert "thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers"
  thunderbolt: Reject oversized XDomain properties responses
2026-10-01 13:26:31 +02:00
Mika Westerberg
47c73a43c1 thunderbolt: stream: Announce support for FMODE_NOWAIT
Commit 42bc693533 ("thunderbolt: stream: Support IOCB_NOWAIT in
non-blocking I/O as well") added support for IOCB_NOWAIT but forgot to
actually announce it as part of the file->f_mode. Add this now so users
such as io_uring can actually take advantage of IOCB_NOWAIT.

Fixes: 42bc693533 ("thunderbolt: stream: Support IOCB_NOWAIT in non-blocking I/O as well")
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2026-09-24 12:30:23 +02:00
Kees Cook
3a2c4d55e3 treewide: refresh kmalloc_obj() conversions
This is another run of the Coccinelle script for converting kmalloc()
family of allocations to kmalloc_obj() via the existing rules in
scripts/coccinelle/api/kmalloc_objs.cocci

This catches both the set of kmalloc() uses added since the first
kmalloc_obj() conversions in v7.0 and adds a large group missed in the
first pass due to Coccinelle not interacting well with the cleanup.h
scoped_...() family of macros[1]. I worked around this with spatch's
"--macro-file" argument to a file with all the scoped_...() macros mapped
to Coccinelle's YACFE_ITERATOR[2] as that was the closest viable control
flow indicator I could find.

Build tested allmodconfig on x86, arm64, arm, loongarch, mips, powerpc,
riscv, and s390 with no new warnings.

Link: https://lore.kernel.org/lkml/202609021314.8A9C0B8@keescook/ [1]
Link: https://github.com/coccinelle/coccinelle/blob/master/standard.h [2]
Signed-off-by: Kees Cook <kees+treewide@kernel.org>
2026-09-04 21:37:00 -07:00
Greg Kroah-Hartman
e1e6e541c5 thunderbolt: Changes for v7.3 merge window
This includes following USB4/Thunderbolt changes for the v7.3 merge
 window:
 
   - Assert Downstream Port Reset for Thunderbolt 3 devices during
     shutdown to avoid unnecessary delays over warm reset.
   - Tidy up Thunderbolt service ->probe callbacks.
   - USB4STREAM improvements.
   - AMD host interface quirk to fix Tx ring hang on teardown of a DMA tunnel.
   - Minor fixes and cleanups.
 
 All these have been in linux-next with no reported issues.
 -----BEGIN PGP SIGNATURE-----
 
 iQJUBAABCgA+FiEEVTdhRGBbNzLrSUBaAP2fSd+ZWKAFAmp9hRsgHG1pa2Eud2Vz
 dGVyYmVyZ0BsaW51eC5pbnRlbC5jb20ACgkQAP2fSd+ZWKBbRQ/9FCNtTLJH9Ef0
 fZqu6xdGK0gtC9Y0voY7Mt/FbBB9FpAOFXSfprfTVpLzWqhP5ugqFEFF6UqgoX5e
 ScZAxVr1XYA2Sbqn2Qmjaz+dmw0ip2GAIiST+q2lOPJVDsTOeqhFyjDg/xV/D317
 MJ3F4RFfAZsMcxBqo0ZqZs/gkPdX/rEw45yR0/+Lke/jyjzYE+oqC38a/WDR8MLJ
 RVfk0nylnw346l5EmDsbFY16GF1ra8ntG+wOFU8cPHL2VpMV5HlW8aKG7iNe8/LT
 mgG1RfUmm10MY3vrxuoIozUg742BBLZe28LJcVTLvk0TwbJaA4/6+zr+ZUDbbKnY
 JZR5PasIvP3Tth/JgEv3K5/mUG/iMCdY+iyQ/aRnhqcbtR8XkifK2yD3MuQLROrR
 QOJrEffZ8hq45tcR9k3xg/xOU1gQ0wFUdmQb5m0rbKE81CaEw/+8rAR676hYjlTQ
 xLxOlBbHdUsaUAw547uvrTOh98khb/AARiAa5J52I9xaHVyghR1M2NUMb18QmScJ
 SVutj2Fe+gk8fSkk+Dl7aCmI2KULMWcME+oGWi8Eh3el0WKpVmQjuh8PbDmJ8Is1
 43uFEYXGvt7n98cdIKDqK56bcTDbHmdZwGU1HV1hUwJbmzdEVcpdTowVGhQ5jb+P
 0Eu1dX7elFMpZiP165uiL5Wf04Tg31A=
 =FJ+H
 -----END PGP SIGNATURE-----

Merge tag 'thunderbolt-for-v7.3-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt into usb-next

Mika writes:

thunderbolt: Changes for v7.3 merge window

This includes following USB4/Thunderbolt changes for the v7.3 merge
window:

  - Assert Downstream Port Reset for Thunderbolt 3 devices during
    shutdown to avoid unnecessary delays over warm reset.
  - Tidy up Thunderbolt service ->probe callbacks.
  - USB4STREAM improvements.
  - AMD host interface quirk to fix Tx ring hang on teardown of a DMA tunnel.
  - Minor fixes and cleanups.

All these have been in linux-next with no reported issues.

* tag 'thunderbolt-for-v7.3-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt:
  thunderbolt: Clamp DMA tunnel credits to what a hop register can hold
  thunderbolt: Use min() for the DMA path credit cap
  thunderbolt: debugfs: Replace get_zeroed_page() with kzalloc()
  thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers
  thunderbolt: stream: Add support for busy polling
  thunderbolt: Make interrupt optional for rings
  thunderbolt: stream: Support IOCB_NOWAIT in non-blocking I/O as well
  thunderbolt: stream: Fix possible short reads/writes
  thunderbolt: stream: Restore consumer if copying from iter fails
  thunderbolt: Remove redundant dev_err_probe()
  docs: admin-guide: thunderbolt: Fix sentence structure
  thunderbolt: xdomain: Notify peers after enumeration
  thunderbolt: Drop comma after device id array terminator
  thunderbolt: Assert that a service driver has a probe callback
  thunderbolt: Stop passing matched device ID to .probe()
  thunderbolt: Assert downstream port reset on shutdown
2026-08-19 10:01:59 +02:00
Mika Westerberg
e120d14d03 thunderbolt: stream: Add support for busy polling
Using interrupts and scheduling workers increase latency so latency
critical applications may want to avoid that. Make this possible in
USB4STREAM by adding a new ConfigFS attribute: busy_poll that, when
activated switches the rings to polling mode. The cost for lower latency
is that this burns more CPU cycles and things like poll(2) cannot be
used.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2026-08-05 05:53:57 +02:00
Mika Westerberg
42bc693533 thunderbolt: stream: Support IOCB_NOWAIT in non-blocking I/O as well
For read_iter/write_iter() it is also possible to pass IOCB_NOWAIT with
the kiocb to indicate non-blocking read/write. For instance io_uring
does this. So take this into account on read and write paths.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2026-08-05 05:53:57 +02:00
Mika Westerberg
af73a21a8e thunderbolt: stream: Fix possible short reads/writes
Since copy_page_{to|from}_iter() advances the iterator and makes
iov_iter_count() reflect the remaining bytes, subtracting nbytes from it
makes it count it twice resulting in possible short reads/writes on a
read/write spanning multiple frames.

Fix this by using iov_iter_count() directly.

Fixes: 6db21d817b ("thunderbolt: Add support for USB4STREAM")
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2026-08-05 05:53:57 +02:00
Mika Westerberg
039701ea3d thunderbolt: stream: Restore consumer if copying from iter fails
In tbstream_dev_alloc_tx() if copying data from iterator fails we leave
the consumer pointer as is wasting one entry in the ring. Fix this by
restoring the consumer back in case of failure.

Fixes: 6db21d817b ("thunderbolt: Add support for USB4STREAM")
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2026-08-05 05:53:57 +02:00
Uwe Kleine-König (The Capable Hub)
9990c493ef thunderbolt: Drop comma after device id array terminator
The usual style for other device id arrays doesn't have a comma after
the initializer.

Signed-off-by: Uwe Kleine-König (The Capable Hub) <u.kleine-koenig@baylibre.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2026-07-27 11:59:44 +02:00
Uwe Kleine-König (The Capable Hub)
45f104755a thunderbolt: Stop passing matched device ID to .probe()
No driver makes use of that parameter, so drop it and don't spend the
effort to determine the matching entry.

Signed-off-by: Uwe Kleine-König (The Capable Hub) <u.kleine-koenig@baylibre.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2026-07-27 11:59:44 +02:00
Xu Rao
97b228e596 thunderbolt: stream: Unmap buffers with mapped size
The size passed to dma_unmap_page() must match the size used for the
corresponding dma_map_page() call.

Stream RX and TX buffers are mapped with TB_MAX_FRAME_SIZE when the
buffer pools are allocated. However, tbstream_ring_free() currently uses
tb_ring_frame_size() as the unmap size.

That helper returns the current frame payload size, not the DMA mapping
size. On the TX path, tbstream_dev_alloc_tx() stores a shorter payload
length in frame.size when the payload is smaller than TB_MAX_FRAME_SIZE.
This happens for a short final DATA frame, and also for the CLOSE frame,
which is allocated with SZ_256.

In those cases the buffer was mapped with TB_MAX_FRAME_SIZE, but
tb_ring_frame_size() returns the shorter frame payload length. This makes
the dma_unmap_page() size differ from the original dma_map_page() size.

Use TB_MAX_FRAME_SIZE when unmapping stream buffers so the unmap size
matches the DMA mapping size used by the buffer allocation paths.

Signed-off-by: Xu Rao <raoxu@uniontech.com>
Fixes: 6db21d817b ("thunderbolt: Add support for USB4STREAM")
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2026-07-27 11:58:54 +02:00
Mika Westerberg
6db21d817b thunderbolt: Add support for USB4STREAM
Introduce USB4STREAM protocol and Linux implementation. This allows two
(or more) hosts to transfer data directly over Thunderbolt/USB4 cable
through a character device without need to go through the network stack.

Any application that supports read(2) and write(2) in some form should
be able to use the device without changes. The data is sent out to the
other side over a tunnel inside Thunderbolt/USB4 fabric. The character
device is called /dev/tbstreamX where X is the minor number starting
from 0.

All stream devices need to be configured first. This is done through
ConfigFS interface. There can be multiple streams at the same time (this
depends on number of DMA rings and available HopIDs) and a single stream
supports traffic in both directions. For example there could be an
application that uses one stream as control channel and another one as
bi-directional data channel.

A real use-case for this is to take a backup as a part of recovery
initramfs tooling (no need to setup networking or have ssh or similar
tooling as part of the initramfs). Say we want to backup the disk of
host1 to host2. First Thunderbolt/USB4 cable is connected between the
hosts (there can be devices in the middle too) then the receiving side
configures the stream:

  host2 # mkdir /sys/kernel/config/thunderbolt/stream/0-1.0
  host2 # mkdir /sys/kernel/config/thunderbolt/stream/0-1.0/backup
  host2 # echo -1 > /sys/kernel/config/thunderbolt/stream/0-1.0/backup/in_hopid
  host2 # echo -1 > /sys/kernel/config/thunderbolt/stream/0-1.0/backup/out_hopid

We use automatic HopID allocation (writing -1 to HopIDs) for simplicity.
From this point forward the /dev/tbstream0 can be used pretty much as
regular file:

  host2 # dd if=/dev/tbstream0 of=/tmp/host1.nvme0n1.backup-$(date +%F) bs=256k

The host that is being backed up then configures the stream accordingly:

  host1 # mkdir /sys/kernel/config/thunderbolt/stream/0-503.0
  host1 # mkdir /sys/kernel/config/thunderbolt/stream/0-503.0/backup

Here we take advantage of the fact that host2 also announces the active
streams through XDomain properties so the name "backup" gives us the
HopIDs. It is also possible to configure them manually in the same way
we did for host2.

Then it is just a matter of copying the data over:

  host1 # dd if=/dev/nvme0n1 of=/dev/tbstream0 bs=256k

Similarly it is possible to transfer parts of the filesystem. For
example copy contents of mydir over to the host2:

  host2 # gunzip < /dev/tbstream0 | tar xf -
  host1 # tar cf - mydir | gzip > /dev/tbstream0

Other end of the spectrum use-case is "borrowing" laptop (host1) camera
to desktop (host2):

  host2 # gst-launch-1.0 filesrc location=/dev/tbstream0 ! jpegdec ! videoconvert ! \
                         autovideosink

  host1 # gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,width=1920,height=1080 ! \
                         jpegenc quality=90 ! filesink location=/dev/tbstream0

Once the streams are no longer needed they can be removed:

  host1 # cd /sys/kernel/config/thunderbolt/stream/
  host1 # rmdir -p 0-503.0/backup

  host2 # cd /sys/kernel/config/thunderbolt/stream
  host2 # rmdir -p 0-1.0/backup

Co-developed-by: Alan Borzeszkowski <alan.borzeszkowski@linux.intel.com>
Signed-off-by: Alan Borzeszkowski <alan.borzeszkowski@linux.intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2026-05-19 14:20:18 +02:00