Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ciprian Costea <ciprianmarian.costea@oss.nxp.com>
To: Marc Kleine-Budde <mkl@pengutronix.de>,
	Vincent Mailhol <mailhol@kernel.org>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Claudiu Beznea <claudiu.beznea@tuxon.dev>,
	Haibo Chen <haibo.chen@nxp.com>
Cc: linux-can@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, NXP S32 Linux Team <s32@nxp.com>,
	imx@lists.linux.dev, Enric Balletbo <eballetb@redhat.com>,
	Ciprian Marian Costea <ciprianmarian.costea@oss.nxp.com>
Subject: [PATCH v7 0/4] can: rx-offload: allow more than one receive source
Date: Fri,  2 Oct 2026 09:11:59 +0200	[thread overview]
Message-ID: <20261002071203.1287650-1-ciprianmarian.costea@oss.nxp.com> (raw)

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



             reply	other threads:[~2026-10-02  7:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-02  7:11 Ciprian Costea [this message]
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-05  9:46     ` Ciprian Marian Costea
2026-10-05 10:48     ` Marc Kleine-Budde
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261002071203.1287650-1-ciprianmarian.costea@oss.nxp.com \
    --to=ciprianmarian.costea@oss.nxp.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=eballetb@redhat.com \
    --cc=haibo.chen@nxp.com \
    --cc=imx@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=nicolas.ferre@microchip.com \
    --cc=s32@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox