mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v7 0/4] can: rx-offload: allow more than one receive source
@ 2026-10-02  7:11 Ciprian Costea
  2026-10-02  7:12 ` [PATCH v7 1/4] can: at91_can: release the rx-offload on teardown Ciprian Costea
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Ciprian Costea @ 2026-10-02  7:11 UTC (permalink / raw)
  To: Marc Kleine-Budde, Vincent Mailhol, Nicolas Ferre,
	Alexandre Belloni, Claudiu Beznea, Haibo Chen
  Cc: linux-can, linux-arm-kernel, linux-kernel, NXP S32 Linux Team,
	imx, Enric Balletbo, Ciprian Marian Costea

From: Ciprian Marian Costea <ciprianmarian.costea@oss.nxp.com>

On S32G2, flexcan uses the same IRQ handler for all four interrupt
lines, so the handlers can run concurrently on different CPUs. They all
fill the same lockless skb_irq_queue, which can get corrupted.

This series gives each IRQ line its own rx-offload source with its own
skb_irq_queue. struct can_rx_offload now describes one source, and the
skb_queue and NAPI shared by all sources move into the new struct
can_rx_offload_queue. The primary source is added as before and embeds
the shared queue. Extra sources are attached to it with
can_rx_offload_add_source().

The IRQ side stays lockless, as each source has a single producer. The
finish helpers move the skbs into the shared skb_queue under its lock.
With more than one source in timestamp mode they are sorted in, so the
timestamp order is kept across IRQ lines.

The rx-offload API is unchanged, so only flexcan is converted.

Patch 1 is an independent at91_can fix. Patch 2 moves skb_queue and napi
into struct can_rx_offload_queue, with no functional change. Patch 3
adds support for more than one source, and patch 4 uses it in flexcan.

Tested on S32G274A-RDB2 (can0 <-> can1, CAN FD + classic, IRQ lines pinned
to different CPUs).

Changes since v6:

- Moved skb_queue and napi into struct can_rx_offload_queue instead of
  adding struct can_rx_offload_irq, so other drivers are not touched
  (Haibo).
- Renamed "per-IRQ context" to "source", added
  can_rx_offload_add_source() and reworked the comments (Max).
- Split the rx-offload change into two patches.
- at91_can: add Acked-by: Max Staudt <max@enpas.org>

Changes since v5:

- Replaced the per-CPU skb_irq_queue, which does not work in preemptible
  context, with a per-IRQ receive context, as suggested by Marc Kleine-Budde.
- Added patch 3 with the flexcan conversion. The bus off and error lines get
  their own context too, not only the mailbox lines.
- Moved the at91_can fix to its own patch.
- Dropped the gs_usb can_rx_offload_add_manual() return value check, the
  NULL pointer dereference it guarded against went away with the per-CPU
  allocation.
- Dropped Haibo's Reviewed-by from the rx-offload patch, since it was
  rewritten.
- Added Assisted-by tags.

Changes since v4:
- rx-offload: expand the comment above the for_each_possible_cpu() loop
  in can_rx_offload_threaded_irq_finish() to add the single-producer
  assumption (IRQ requested with IRQF_ONESHOT / handler non-reentrant).
  Suggested by Haibo Chen.
- rx-offload: add Reviewed-by: Haibo Chen <haibo.chen@nxp.com>

Changes since v3:

- In gs_usb driver, check the can_rx_offload_add_manual() return value,
  the same NULL-deref the per-CPU change exposes.

Changes since v2:

- at91_can: also add can_rx_offload_del() on the register_candev() error
  path and check the can_rx_offload_add_timestamp() return value.

Changes since v1:

- The enqueue helpers used this_cpu_ptr() without disabling preemption.
  All four enqueue helpers now use get_cpu_ptr()/put_cpu_ptr().
- Guard can_rx_offload_del() against skb_irq_queue == NULL.
- Fix 'at91_can' memory leak by adding missing 'can_rx_offload_del'.

Ciprian Marian Costea (4):
  can: at91_can: release the rx-offload on teardown
  can: rx-offload: move skb_queue and napi into struct
    can_rx_offload_queue
  can: rx-offload: allow more than one receive source
  can: flexcan: use one rx-offload source per IRQ line

 drivers/net/can/at91_can.c             |  12 +-
 drivers/net/can/dev/rx-offload.c       | 185 +++++++++++++++++++------
 drivers/net/can/flexcan/flexcan-core.c |  86 +++++++++---
 drivers/net/can/flexcan/flexcan.h      |   3 +
 include/linux/can/rx-offload.h         |  27 +++-
 5 files changed, 252 insertions(+), 61 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-10-03 21:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-02  7:11 [PATCH v7 0/4] can: rx-offload: allow more than one receive source Ciprian Costea
2026-10-02  7:12 ` [PATCH v7 1/4] can: at91_can: release the rx-offload on teardown Ciprian Costea
2026-10-02  7:12 ` [PATCH v7 2/4] can: rx-offload: move skb_queue and napi into struct can_rx_offload_queue Ciprian Costea
2026-10-02  7:12 ` [PATCH v7 3/4] can: rx-offload: allow more than one receive source Ciprian Costea
2026-10-03 21:36   ` netdev-bot+sashiko
2026-10-02  7:12 ` [PATCH v7 4/4] can: flexcan: use one rx-offload source per IRQ line Ciprian Costea
2026-10-03 21:36   ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®