1273 Commits

Author SHA1 Message Date
Takashi Sakamoto
9197e5949a firewire: ohci: initialize page array to use alloc_pages_bulk() correctly
The call of alloc_pages_bulk() skips to fill entries of page array when
the entries already have values. While, 1394 OHCI PCI driver passes the
page array without initializing. It could cause invalid state at PFN
validation in vmap().

Fixes: f2ae92780a ("firewire: ohci: split page allocation from dma mapping")
Reported-by: John Ogness <john.ogness@linutronix.de>
Reported-and-tested-by: Harald Arnesen <linux@skogtun.org>
Reported-and-tested-by: David Gow <david@davidgow.net>
Closes: https://lore.kernel.org/lkml/87tsv1vig5.fsf@jogness.linutronix.de/
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2026-02-28 10:09:24 -08:00
Kees Cook
189f164e57 Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses
Conversion performed via this Coccinelle script:

  // SPDX-License-Identifier: GPL-2.0-only
  // Options: --include-headers-for-types --all-includes --include-headers --keep-comments
  virtual patch

  @gfp depends on patch && !(file in "tools") && !(file in "samples")@
  identifier ALLOC = {kmalloc_obj,kmalloc_objs,kmalloc_flex,
 		    kzalloc_obj,kzalloc_objs,kzalloc_flex,
		    kvmalloc_obj,kvmalloc_objs,kvmalloc_flex,
		    kvzalloc_obj,kvzalloc_objs,kvzalloc_flex};
  @@

  	ALLOC(...
  -		, GFP_KERNEL
  	)

  $ make coccicheck MODE=patch COCCI=gfp.cocci

Build and boot tested x86_64 with Fedora 42's GCC and Clang:

Linux version 6.19.0+ (user@host) (gcc (GCC) 15.2.1 20260123 (Red Hat 15.2.1-7), GNU ld version 2.44-12.fc42) #1 SMP PREEMPT_DYNAMIC 1970-01-01
Linux version 6.19.0+ (user@host) (clang version 20.1.8 (Fedora 20.1.8-4.fc42), LLD 20.1.8) #1 SMP PREEMPT_DYNAMIC 1970-01-01

Signed-off-by: Kees Cook <kees@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2026-02-22 08:26:33 -08:00
Linus Torvalds
323bbfcf1e Convert 'alloc_flex' family to use the new default GFP_KERNEL argument
This is the exact same thing as the 'alloc_obj()' version, only much
smaller because there are a lot fewer users of the *alloc_flex()
interface.

As with alloc_obj() version, this was done entirely with mindless brute
force, using the same script, except using 'flex' in the pattern rather
than 'objs*'.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2026-02-21 17:09:51 -08:00
Linus Torvalds
bf4afc53b7 Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
This was done entirely with mindless brute force, using

    git grep -l '\<k[vmz]*alloc_objs*(.*, GFP_KERNEL)' |
        xargs sed -i 's/\(alloc_objs*(.*\), GFP_KERNEL)/\1)/'

to convert the new alloc_obj() users that had a simple GFP_KERNEL
argument to just drop that argument.

Note that due to the extreme simplicity of the scripting, any slightly
more complex cases spread over multiple lines would not be triggered:
they definitely exist, but this covers the vast bulk of the cases, and
the resulting diff is also then easier to check automatically.

For the same reason the 'flex' versions will be done as a separate
conversion.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2026-02-21 17:09:51 -08:00
Kees Cook
69050f8d6d treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from
scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to
avoid scalar types (which need careful case-by-case checking), and
instead replace kmalloc-family calls that allocate struct or union
object instances:

Single allocations:	kmalloc(sizeof(TYPE), ...)
are replaced with:	kmalloc_obj(TYPE, ...)

Array allocations:	kmalloc_array(COUNT, sizeof(TYPE), ...)
are replaced with:	kmalloc_objs(TYPE, COUNT, ...)

Flex array allocations:	kmalloc(struct_size(PTR, FAM, COUNT), ...)
are replaced with:	kmalloc_flex(*PTR, FAM, COUNT, ...)

(where TYPE may also be *VAR)

The resulting allocations no longer return "void *", instead returning
"TYPE *".

Signed-off-by: Kees Cook <kees@kernel.org>
2026-02-21 01:02:28 -08:00
Linus Torvalds
d4a379a52c Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
Pull SCSI updates from James Bottomley:
 "Usual driver updates (qla2xxx, mpi3mr, mpt3sas, ufs) plus assorted
  cleanups and fixes.

  The biggest core change is the massive code motion in the sd driver to
  remove forward declarations and the most significant change is to
  enumify the queuecommand return"

* tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi: (78 commits)
  scsi: csiostor: Fix dereference of null pointer rn
  scsi: buslogic: Reduce stack usage
  scsi: ufs: host: mediatek: Require CONFIG_PM
  scsi: ufs: mediatek: Fix page faults in ufs_mtk_clk_scale() trace event
  scsi: smartpqi: Fix memory leak in pqi_report_phys_luns()
  scsi: mpi3mr: Make driver probing asynchronous
  scsi: ufs: core: Flush exception handling work when RPM level is zero
  scsi: efct: Use IRQF_ONESHOT and default primary handler
  scsi: ufs: core: Use a host-wide tagset in SDB mode
  scsi: qla2xxx: target: Add WQ_PERCPU to alloc_workqueue() users
  scsi: qla2xxx: Add WQ_PERCPU to alloc_workqueue() users
  scsi: qla4xxx: Add WQ_PERCPU to alloc_workqueue() users
  scsi: mpi3mr: Driver version update to 8.17.0.3.50
  scsi: mpi3mr: Fixed the W=1 compilation warning
  scsi: mpi3mr: Record and report controller firmware faults
  scsi: mpi3mr: Update MPI Headers to revision 39
  scsi: mpi3mr: Use negotiated link rate from DevicePage0
  scsi: mpi3mr: Avoid redundant diag-fault resets
  scsi: mpi3mr: Rename log data save helper to reflect threaded/BH context
  scsi: mpi3mr: Add module parameter to control threaded IRQ polling
  ...
2026-02-12 15:43:02 -08:00
Linus Torvalds
0d6dd4738d Merge tag 'firewire-updates-7.0' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394
Pull firewire updates from Takashi Sakamoto:

 - Refactor page allocation dedicated to 1394 OHCI IR/IT/AR DMA contexts

   Although 1394 OHCI specification does not impose any restriction on
   the memory size dedicated to these DMA contexts, 1394 OHCI PCI driver
   allocates pages for convenience when mapping them into either kernel
   space or userspace VMA. The driver previously used dma_alloc_pages()
   for both page allocation and mapping creation, even though this
   kernel API is rarely used. Following discussions questioning the
   page-oriented kernel API in the DMA layer, the driver has been
   refactored to avoid using this API. In addition, the use of private
   members in the allocated pages has been removed following
   long-standing concern.

 - Allocate variable-sized buffer for isochronous context header

   1394 OHCI PCI driver previously allocated a single page for
   isochronous context header. As a result, the buffer size for the
   header was fixed to PAGE_SIZE, which imposed a limitation on IEC
   61883-1/6 packet streaming engine. Consequently, the ALSA PCM devices
   provided by drivers for audio and music units in IEEE 1394 bus were
   constrained in the maximum size of buffer period (64 ms in most
   cases). This limitation is resolved by dynamically allocating the
   header buffer with an arbitrary size.

* tag 'firewire-updates-7.0' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394:
  ALSA: firewire: remove PCM buffer size constraint from isoc context header
  firewire: core: add fw_iso_context_create() variant with header storage size
  firewire: core: provide isoc header buffer size outside card driver
  firewire: ohci: allocate isoc context header by kvmalloc()
  firewire: core: add flags member for isochronous context structure
  firewire: ohci: use cleanup helper for isoc context header allocation
  firewire: ohci: code refactoring to use union for isoc multiple channel state
  firewire: ohci: refactor isoc single-channel state using a union
  firewire: core: add function variants for isochronous context creation
  firewire: ohci: fix index of pages for dma address to 1394 OHCI IT context
  firewire: ohci: stop using page private to store DMA mapping address
  firewire: ohci: split page allocation from dma mapping
  firewire: ohci: use MAX macro to guarantee minimum count of pages for AR contexts
  firewire: core: stop using page private to store DMA mapping address
  firewire: core: use common kernel API to allocate and release a batch of pages
  firewire: core: code refactoring with cleanup function for isoc pages
  firewire: core: use mutex instead of spinlock for client isochronous context
  firewire: core: move private function declaration from public header to internal header
2026-02-11 11:32:06 -08:00
Takashi Sakamoto
20e01bba2a firewire: core: fix race condition against transaction list
The list of transaction is enumerated without acquiring card lock when
processing AR response event. This causes a race condition bug when
processing AT request completion event concurrently.

This commit fixes the bug by put timer start for split transaction
expiration into the scope of lock. The value of jiffies in card structure
is referred before acquiring the lock.

Cc: stable@vger.kernel.org # v6.18
Fixes: b5725cfa41 ("firewire: core: use spin lock specific to timer for split transaction")
Reported-by: Andreas Persson <andreasp56@outlook.com>
Closes: https://github.com/alsa-project/snd-firewire-ctl-services/issues/209
Tested-by: Andreas Persson <andreasp56@outlook.com>
Link: https://lore.kernel.org/r/20260127223413.22265-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-01-29 08:03:55 +09:00
Bart Van Assche
0db3f51839 scsi: Change the return type of the .queuecommand() callback
In clang version 21.1 and later the -Wimplicit-enum-enum-cast warning
option has been introduced. This warning is enabled by default and can
be used to catch .queuecommand() implementations that return another
value than 0 or one of the SCSI_MLQUEUE_* constants. Hence this patch
that changes the return type of the .queuecommand() implementations from
'int' into 'enum scsi_qc_status'. No functionality has been changed.

Cc: Damien Le Moal <dlemoal@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Link: https://patch.msgid.link/20260115210357.2501991-6-bvanassche@acm.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2026-01-23 21:32:34 -05:00
Takashi Sakamoto
9bf71acd65 firewire: core: provide isoc header buffer size outside card driver
For single-channel isochronous contexts, the header storage size is
hard-coded to PAGE_SIZE. which is inconvenient for protocol
implementations requiring more space.

This commit refactors the code to obtain the header storage size outside
the 1394 OHCI driver.

Link: https://lore.kernel.org/r/20260117142823.440811-8-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-01-18 17:18:48 +09:00
Takashi Sakamoto
fc999c7b68 firewire: ohci: allocate isoc context header by kvmalloc()
Isochronous packet handling now runs in a workqueue context, where page
faults is acceptable.

This commit replaces __get_free_page() with kvmalloc() when allocating the
isochronous context header buffer.

Link: https://lore.kernel.org/r/20260117142823.440811-7-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-01-18 17:18:48 +09:00
Takashi Sakamoto
090ac65200 firewire: core: add flags member for isochronous context structure
This is minor code refactoring to add a flag member to the isochronous
context structure. At present, it is used only for the option to drop
packets when the context header overflows.

Link: https://lore.kernel.org/r/20260117142823.440811-6-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-01-18 17:18:48 +09:00
Takashi Sakamoto
ea6fdb1cbd firewire: ohci: use cleanup helper for isoc context header allocation
Some cleanup helpers are useful in error path after memory allocation for
header storage.

Link: https://lore.kernel.org/r/20260117142823.440811-5-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-01-18 17:18:48 +09:00
Takashi Sakamoto
c544c82989 firewire: ohci: code refactoring to use union for isoc multiple channel state
In 1394 OHCI driver, some members of struct iso_context are only used for
multi-channel isochronous contexts.

This commit uses a union for these members to clearly separate
multi-channel specific state.

Link: https://lore.kernel.org/r/20260117142823.440811-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-01-18 17:18:48 +09:00
Takashi Sakamoto
0fe92d5d2c firewire: ohci: refactor isoc single-channel state using a union
In 1394 OHCI driver, some members of struct iso_context are only used for
single-channel isochronous contexts.

This commit groups these members into a union.

Link: https://lore.kernel.org/r/20260117142823.440811-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-01-18 17:18:48 +09:00
Takashi Sakamoto
6b67470dce firewire: core: add function variants for isochronous context creation
The fw_iso_callback union was added by a commit ebe4560ed5 ("firewire:
Remove function callback casts") to remove function pointer cast.

That change affected the cdev layer of the core code, but it is more
convenient for fw_iso_context_create() to accept the union directly.

This commit renames and changes the existing function to take the union
argument, and add static inline wrapper functions as variants.

Link: https://lore.kernel.org/r/20260117142823.440811-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-01-18 17:18:48 +09:00
Takashi Sakamoto
a4cd9860fa firewire: ohci: fix index of pages for dma address to 1394 OHCI IT context
The index of pages for dma address was changed wrongly. This commit
corrents it.

Fixes: ef6bdffbb8 ("firewire: core: stop using page private to store DMA mapping address")
Link: https://lore.kernel.org/r/20260114131729.16133-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-01-15 21:33:36 +09:00
Takashi Sakamoto
993ab48006 firewire: ohci: stop using page private to store DMA mapping address
There is a long discussion about the use of private field in page
structure between Linux kernel developers.

This commit stop using page private to store DMA mapping address for
AR context, to prepare for mm future change.

Link: https://lore.kernel.org/r/20260110013911.19160-9-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-01-12 11:49:38 +09:00
Takashi Sakamoto
f2ae92780a firewire: ohci: split page allocation from dma mapping
1394 OHCI PCI driver had long been the only user of dma_alloc_pages().
Although tee subsystem recently started using it, they are still a few
users of the infrequently-used function.

In the discussion for dma-mapping function, Jason Gunthorpe shows his
opinion about the design of public API for the function. According to it,
the users provide physical address to the function, then receive DMA
mapping address, regardless of the location of mapping target.

With the above aspects, this commit eliminates the use of
dma_alloc_pages() from this subsystem.

Link: https://lore.kernel.org/lkml/20250905174324.GI616306@nvidia.com/
Link: https://lore.kernel.org/r/20260110013911.19160-8-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-01-12 11:49:38 +09:00
Takashi Sakamoto
e62b46cdd3 firewire: ohci: use MAX macro to guarantee minimum count of pages for AR contexts
The computation of page size for AR DMA context can be simplified by MAX
macro.

Link: https://lore.kernel.org/r/20260110013911.19160-7-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-01-12 11:49:38 +09:00
Takashi Sakamoto
ef6bdffbb8 firewire: core: stop using page private to store DMA mapping address
There is a long discussion about the use of private field in page
structure between Linux kernel developers.

This commit stop using page private to store DMA mapping address for
isochronous context, to prepare for mm future change.

Link: https://lore.kernel.org/r/20260110013911.19160-6-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-01-12 11:49:37 +09:00
Takashi Sakamoto
c2f60aa160 firewire: core: use common kernel API to allocate and release a batch of pages
The pair of alloc_pages_bulk() and release_pages() are convenient to
allocate and release a batch of pages.

This commit utilizes the pair to maintain pages for isochronous DMA
context.

Link: https://lore.kernel.org/r/20260110013911.19160-5-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-01-12 11:49:37 +09:00
Takashi Sakamoto
a69a9e630d firewire: core: code refactoring with cleanup function for isoc pages
This commit refactors the implementation to allocate pages for isochronous
DMA contexts with cleanup function.

Link: https://lore.kernel.org/r/20260110013911.19160-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-01-12 11:49:37 +09:00
Takashi Sakamoto
adc839ae7d firewire: core: use mutex instead of spinlock for client isochronous context
There is a restriction that the userspace client associated to a file
descriptor can hold one isochronous context. The client-level spinning
lock is used to guarantee it, however the lock is also used for
multi-purposes. Additionally, there is no need to use this type of lock,
and the mutex is available, instead.

Link: https://lore.kernel.org/r/20260110013911.19160-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-01-12 11:49:37 +09:00
Takashi Sakamoto
c91adaddb0 firewire: core: move private function declaration from public header to internal header
The fw_iso_buffer_lookup function is used by core module only, thus no
need to describe its prototype in kernel internal header.

Link: https://lore.kernel.org/r/20260110013911.19160-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-01-12 11:49:37 +09:00
Thomas Fourier
c48c0fd0e1 firewire: nosy: Fix dma_free_coherent() size
It looks like the buffer allocated and mapped in add_card() is done
with size RCV_BUFFER_SIZE which is 16 KB and 4KB.

Fixes: 286468210d ("firewire: new driver: nosy - IEEE 1394 traffic sniffer")
Co-developed-by: Thomas Fourier <fourier.thomas@gmail.com>
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
Co-developed-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/20251216165420.38355-2-fourier.thomas@gmail.com
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-12-26 22:04:03 +09:00
Linus Torvalds
205f1a0d18 Merge tag 'firewire-updates-6.19' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394
Pull firewire updates from Takashi Sakamoto:
 "This includes two changes for core functions, which affects all use
  cases of this subsystem:

   - Handle per-device interoperability quirks

     Some devices have quirks affecting interoperability. To identify
     such quirks at an early stages of device detection, the step for
     reading the configuration ROM contents has been changed. As a side
     effect, the entire detection process is now performed at the basic
     transaction speed (S100), without a trial to probe higher
     supported speeds.

     With this change, the following devices should now work with fewer
     issues:
      - TASCAM FW-1884, FW-1804, and FW-1082
      - MOTU Audio Express

   - Safer removals of host card

     There was a race condition between host card removal and handling
     of bus reset events in the workqueue. This appears to be a long
     standing issue, and recent changes to use more workqueues escalate
     it.

     To solve it, a new callback has been added to the 1394 OHCI PCI
     driver to unregister the interrupt sources and wait for workqueue
     completions when removing a card instance"

* tag 'firewire-updates-6.19' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394:
  firewire: core: abort pending transactions at card removal
  firewire: core: add WQ_UNBOUND to alloc_workqueue users
  firewire: core: clear sources of hardware interrupt at card removal
  firewire: core: code refactoring to find and pop transaction entry
  firewire: core: code refactoring to remove transaction entry
  firewire: core: use cleanup function to release cached configuration ROM
  ALSA: firewire-tascam: reserve resources for transferred isochronous packets at S400
  firewire: core: handle device quirk of TASCAM FW-1884/FW-1804/FW-1082
  firewire: core: determine transaction speed after detecting quirks
  firewire: core: code refactoring to compute transaction speed
  firewire: core: handle device quirk of MOTU Audio Express
  firewire: core: detect device quirk when reading configuration ROM
2025-12-04 12:26:36 -08:00
Takashi Sakamoto
1107aac1ad firewire: core: fix to update generation field in topology map
The generation field of topology map is updated after initialized by zero.
The updated value of generation field is always zero, and is against
specification.

This commit fixes the bug.

Fixes: 7d138cb269 ("firewire: core: use spin lock specific to topology map")
Link: https://lore.kernel.org/r/20251114144421.415278-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-11-16 21:30:26 +09:00
Ville Syrjälä
37339122a7 firewire: core: Initialize topology_map.lock
Lockdep barfs on the new uninitialized spinlock.
Initialize it.

protip: enable lockdep (CONFIG_PROVE_LOCKING=y) when
        doing locking changes

firewire_ohci 0000:02:01.1: added OHCI v1.10 device as card 0, 4 IR + 4 IT contexts, quirks 0x11
INFO: trying to register non-static key.
The code is fine but needs lockdep annotation, or maybe
you didn't initialize this object before use?
turning off the locking correctness validator.
CPU: 0 UID: 0 PID: 1042 Comm: irq/17-firewire Not tainted 6.17.0-rc2-cl-bisect2-00026-g7d138cb269db #136 PREEMPT
Hardware name: Dell Inc. Latitude E5400                  /0D695C, BIOS A19 06/13/2013
Call Trace:
 <TASK>
 dump_stack_lvl+0x6d/0xa0
 register_lock_class+0x783/0x790
 ? find_held_lock+0x2b/0x80
 ? __mod_timer+0x110/0x320
 ? __mod_timer+0x110/0x320
 __lock_acquire+0x405/0x2600
 lock_acquire+0xca/0x2e0
 ? fw_core_handle_bus_reset+0x888/0xca0 [firewire_core]
 ? fw_core_handle_bus_reset+0x878/0xca0 [firewire_core]
 ? fw_core_handle_bus_reset+0x878/0xca0 [firewire_core]
 _raw_spin_lock+0x2e/0x40
 ? fw_core_handle_bus_reset+0x888/0xca0 [firewire_core]
 fw_core_handle_bus_reset+0x888/0xca0 [firewire_core]
 handle_selfid_complete_event+0x35c/0x7a0 [firewire_ohci]
 ? irq_thread+0x8d/0x280
 irq_thread_fn+0x18/0x50
 irq_thread+0x15a/0x280
 ? irq_check_status_bit+0x100/0x100
 ? lockdep_hardirqs_on+0x78/0x100
 ? irq_finalize_oneshot.part.0+0xc0/0xc0
 ? irq_forced_thread_fn+0x60/0x60
 kthread+0x114/0x200
 ? kthreads_online_cpu+0x110/0x110
 ret_from_fork+0x158/0x1e0
 ? kthreads_online_cpu+0x110/0x110
 ret_from_fork_asm+0x11/0x20
 </TASK>

Reported-by: Erhard Furtner <erhard_f@mailbox.org>
Fixes: 7d138cb269 ("firewire: core: use spin lock specific to topology map")
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-11-14 23:18:50 +09:00
Takashi Sakamoto
036176d9db firewire: core: abort pending transactions at card removal
IEEE 1394 defines the split, concatenated, and unified transaction.
To support the split transaction, core function uses linked list to
maintain the transactions waiting for acknowledge packet. After clearing
sources of hardware interrupts, the acknowledge packet is no longer
handled, therefore it is required to abort the pending transactions.

This commit executes callback with RCODE_CANCELLED for the pending
transactions at card removal.

Link: https://lore.kernel.org/r/20251111223834.311287-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-11-14 04:30:58 +09:00
Marco Crivellari
ae1ef2fbb8 firewire: core: add WQ_UNBOUND to alloc_workqueue users
Currently if a user enqueues a work item using schedule_delayed_work() the
used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use
WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to
schedule_work() that is using system_wq and queue_work(), that makes use
again of WORK_CPU_UNBOUND.
This lack of consistency cannot be addressed without refactoring the API.

alloc_workqueue() treats all queues as per-CPU by default, while unbound
workqueues must opt-in via WQ_UNBOUND.

This default is suboptimal: most workloads benefit from unbound queues,
allowing the scheduler to place worker threads where they’re needed and
reducing noise when CPUs are isolated.

This continues the effort to refactor workqueue APIs, which began with
the introduction of new workqueues and a new alloc_workqueue flag in:

commit 128ea9f6cc ("workqueue: Add system_percpu_wq and system_dfl_wq")
commit 930c2ea566 ("workqueue: Add new WQ_PERCPU flag")

This change adds the WQ_UNBOUND flag to explicitly request
alloc_workqueue() to be unbound, because this specific workload has no
benefit being per-cpu.

With the introduction of the WQ_PERCPU flag (equivalent to !WQ_UNBOUND),
any alloc_workqueue() caller that doesn’t explicitly specify WQ_UNBOUND
must now use WQ_PERCPU.

Once migration is complete, WQ_UNBOUND can be removed and unbound will
become the implicit default.

Suggested-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Marco Crivellari <marco.crivellari@suse.com>
Link: https://lore.kernel.org/r/20251112120125.124578-1-marco.crivellari@suse.com
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-11-12 21:52:25 +09:00
Takashi Sakamoto
594a6a27fb firewire: core: clear sources of hardware interrupt at card removal
Due to the factors external to the system, hardware events may still be
handled while a card instance is being removed. The sources of hardware
IRQs should be cleared during card removal so that workqueues can be safely
destroyed.

This commit adds a disable callback to the underlying driver operations.
After this callback returns, the underlying driver guarantees that it
will no longer handle hardware events.

Link: https://lore.kernel.org/r/20251109065525.163464-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-11-09 15:59:14 +09:00
Takashi Sakamoto
fa2dc27100 firewire: core: code refactoring to find and pop transaction entry
The list operation to find and pop transaction entry appears several
times in transaction implementation, and can be replaced with a helper
functional macro.

Link: https://lore.kernel.org/r/20251101102131.925071-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-11-01 19:29:35 +09:00
Takashi Sakamoto
ddc021b58b firewire: core: code refactoring to remove transaction entry
The list operation to remove transaction entry appears several times in
transaction implementation and can be replaced with a helper function.

Link: https://lore.kernel.org/r/20251101102131.925071-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-11-01 19:29:35 +09:00
Nirbhay Sharma
73ba88fb04 firewire: init_ohci1394_dma: add missing function parameter documentation
Add missing kernel-doc parameter descriptions for five functions
in init_ohci1394_dma.c to fix documentation warnings when building
with W=1.

This patch addresses the following warnings:
- init_ohci1394_wait_for_busresets: missing @ohci description
- init_ohci1394_enable_physical_dma: missing @ohci description
- init_ohci1394_reset_and_init_dma: missing @ohci description
- init_ohci1394_controller: missing @num, @slot, @func descriptions
- setup_ohci1394_dma: missing @opt description

Tested with GCC 13.2.0 and W=1 flag. All documentation warnings
for these functions have been resolved.

Signed-off-by: Nirbhay Sharma <nirbhay.lkd@gmail.com>
Link: https://lore.kernel.org/r/20251024203219.101990-2-nirbhay.lkd@gmail.com
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-10-25 08:29:56 +09:00
Takashi Sakamoto
246aca5b2a firewire: core: fix __must_hold() annotation
The variable name passed to __must_hold() annotation is invalid.

This commit fixes it.

Fixes: 420bd7068c ("firewire: core: use spin lock specific to transaction")
Link: https://lore.kernel.org/r/20251023104349.415310-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-10-24 09:59:34 +09:00
Takashi Sakamoto
b330f98ff2 firewire: core: use cleanup function to release cached configuration ROM
When returning from read_config_rom() function, the allocated buffer and
the previous buffer for configuration ROM should be released. The cleanup
function is useful in the case.

This commit uses the cleanup function to remove goto statements.

Link: https://lore.kernel.org/r/20251020115810.92839-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-10-20 21:00:38 +09:00
Takashi Sakamoto
d52bb3daad firewire: core: handle device quirk of TASCAM FW-1884/FW-1804/FW-1082
TASCAM FW-1884/FW-1804/FW-1082 is too lazy to repspond to asynchronous
request at S400. The asynchronous transaction often results in timeout.
This is a problematic quirk.

This commit adds support for the quirk. When identifying the new quirk
flag, then the transaction speed is configured at S200.

Link: https://lore.kernel.org/r/20251018035532.287124-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-10-18 12:58:56 +09:00
Takashi Sakamoto
55b4e903a1 firewire: core: determine transaction speed after detecting quirks
Current implementation determines the maximum transaction speed supported
by the target device after reading bus information block of configuration
ROM. The read operations for root directory block are then performed at
the determined speed. However, some devices have quirks that cause issues
when transactions are performed at the determined speed.

In the first place, all devices are required to support the lowest speed
(S100) and must respond successfully to any read request within the
configuration ROM space. Therefore it is safe to postpone speed
determination until the entire configuration ROM has been read.

This commit moves the speed determination after reading root directory.

Link: https://lore.kernel.org/r/20251018035532.287124-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-10-18 12:58:55 +09:00
Takashi Sakamoto
665ad59b89 firewire: core: code refactoring to compute transaction speed
This commit refactors the helper function to read the content of
configuration ROM with the passed speed.

Link: https://lore.kernel.org/r/20251018035532.287124-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-10-18 12:58:55 +09:00
Takashi Sakamoto
15f9610fc9 firewire: core: handle device quirk of MOTU Audio Express
A commit 3a93d082ba ("ALSA: firewire-motu: add support for MOTU Audio
Express") describes a quirk of MOTU Audio Express. The device returns
acknowledge packet with 0x10 as the pending state of any types of
asynchronous request transaction. It is completely out of specification.

This commit implements handling for that device-specific quirk. The quirk
is detected after reading the root directory of configuration ROM. When
processing the acknowledge code in 1394 OHCI AT context event handler,
firewire-ohci module seeks the device instance of destination node by
traversing device hierarchy. If the device has the quirk, the acknowledge
code is replaced with the standard code.

The 1394 OHCI AT context events occur for outgoing asynchronous request
packets. The device traversal is safe since no new request initiators
exist after the fw_card_instance has been invalidated.

Link: https://lore.kernel.org/r/20251013140311.97159-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-10-13 23:07:25 +09:00
Takashi Sakamoto
5a43dc9f4e firewire: core: detect device quirk when reading configuration ROM
Every time the bus manager runs, the cached configuration ROM content of
the IRM device is investigated to detect device-specific quirks. This
detection can be performed in advance when reading the configuration ROM.

This commit adds device quirk flags to the fw_device structure, and
initializes them after reading the bus information block of the
configuration ROM. The quirk flags are immutable once the configuration
ROM has been read. Although they are likely accessed concurrently only by
the bus manager, this commit ensures safe access by preventing torn writes
and reads using the WRITE_ONCE()/READ_ONCE() macros.

Link: https://lore.kernel.org/r/20251013140311.97159-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-10-13 23:07:24 +09:00
Linus Torvalds
f07c3695bf Merge tag 'firewire-updates-6.18' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394
Pull firewire updates from Takashi Sakamoto:
 "This update includes the following changes:

   - Removal of the deprecated debug parameter from firewire-ohci module

   - Replacement of the module-local workqueue in 1394 OHCI PCI driver
     with a companion IRQ thread

   - Refactoring of bus management code

   - Additional minor code cleanup

  The existing tracepoints serve as an alternative to the removed debug
  parameter. The use of IRQ thread is experimental, as it handles 1394
  OHCI SelfIDComplete event only. It may be replaced in the future
  releases with another approach; e.g. by providing workqueue from core
  functionality"

* tag 'firewire-updates-6.18' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394: (43 commits)
  firewire: core: fix undefined reference error in ARM EABI
  Revert "firewire: core: disable bus management work temporarily during updating topology"
  Revert "firewire: core: shrink critical section of fw_card spinlock in bm_work"
  firewire: core: suppress overflow warning when computing jiffies from isochronous cycle
  firewire: core: minor code refactoring to delete useless local variable
  firewire: core; eliminate pick_me goto label
  firewire: core: code refactoring to split contention procedure for bus manager
  firewire: core: code refactoring for the case of generation mismatch
  firewire: core: use switch statement to evaluate transaction result to CSR_BUS_MANAGER_ID
  firewire: core: remove useless generation check
  firewire: core: use struct_size and flex_array_size in ioctl_add_descriptor
  firewire: core: shrink critical section of fw_card spinlock in bm_work
  firewire: core: disable bus management work temporarily during updating topology
  firewire: core: schedule bm_work item outside of spin lock
  firewire: core: annotate fw_destroy_nodes with must-hold-lock
  firewire: core: use spin lock specific to timer for split transaction
  firewire: core: use spin lock specific to transaction
  firewire: core: use spin lock specific to topology map
  firewire: core: maintain phy packet receivers locally in cdev layer
  firewire: core: use scoped_guard() to manage critical section to update topology
  ...
2025-10-01 12:52:43 -07:00
Takashi Sakamoto
40d4c76120 firewire: core: fix undefined reference error in ARM EABI
For ARM EABI, GCC generates a reference to __aeabi_uldivmod when compiling
a division of 64-bit integer with 32-bit integer. This function is not
available in Linux kernel. In such cases, helper macros are defined in
include/linux/math64.h.

This commit replaces the division with div_u64().

Fixes: 8ec6a8ec23 ("firewire: core: suppress overflow warning when computing jiffies from isochronous cycle")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202509270428.FZaO2PPq-lkp@intel.com/
Link: https://lore.kernel.org/r/20250928011910.581475-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-28 10:20:30 +09:00
Takashi Sakamoto
e216c49b3e Revert "firewire: core: disable bus management work temporarily during updating topology"
This reverts commit abe7159125.

The bus manager work item acquires the spin lock of fw_card again, thus
no need to serialize it against fw_core_handle_bus_reset().

Link: https://lore.kernel.org/r/20250924131823.262136-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-24 22:20:01 +09:00
Takashi Sakamoto
a6176b7b2a Revert "firewire: core: shrink critical section of fw_card spinlock in bm_work"
This reverts commit 582310376d.

The bus manager work has the race condition against fw_destroy_nodes()
called by fw_core_remove_card(). The acquition of spin lock of fw_card
is left as is again.

Link: https://lore.kernel.org/r/20250924131823.262136-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-24 22:20:01 +09:00
Takashi Sakamoto
8ec6a8ec23 firewire: core: suppress overflow warning when computing jiffies from isochronous cycle
The multiplication by USEC_PER_SEC (=1000000L) may trigger an overflow
warning with 32 bit storage. In the case of the subsystem the input value
ranges between 800 and 16000, thus the result always fits within 32 bit
storage.

This commit suppresses the warning by using widening conversion to 64 bit
storage before multiplication, then using narrowing conversion to 32 bit
storage.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202509170136.b5ZHaNAV-lkp@intel.com/
Fixes: 379b870c28 ("firewire: core: use helper macros instead of direct access to HZ")
Link: https://lore.kernel.org/r/20250924131140.261686-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-24 22:19:15 +09:00
Takashi Sakamoto
853a57ba26 firewire: core: fix overlooked update of subsystem ABI version
In kernel v6.5, several functions were added to the cdev layer. This
required updating the default version of subsystem ABI up to 6, but
this requirement was overlooked.

This commit updates the version accordingly.

Fixes: 6add87e976 ("firewire: cdev: add new version of ABI to notify time stamp at request/response subaction of transaction#")
Link: https://lore.kernel.org/r/20250920025148.163402-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-20 12:17:50 +09:00
Takashi Sakamoto
19e73f6594 firewire: core: minor code refactoring to delete useless local variable
The do_reset local variable has less merit. Let's remove it.

Link: https://lore.kernel.org/r/20250918235448.129705-7-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-19 08:58:34 +09:00
Takashi Sakamoto
9192c37929 firewire: core; eliminate pick_me goto label
This commit uses condition statements instead of pick_me goto label.

Link: https://lore.kernel.org/r/20250918235448.129705-6-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-19 08:58:34 +09:00