* [PATCH net-next 0/2] mlxsw: Fix teardown order of CQ NAPI instances
@ 2026-11-16 10:16 Petr Machata
2026-11-16 10:16 ` [PATCH net-next 1/2] mlxsw: pci: Process EQ in the IRQ handler instead of a tasklet Petr Machata
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Petr Machata @ 2026-11-16 10:16 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev
Cc: Ido Schimmel, Petr Machata, mlxsw
There are the following principal objects for processing of hardware
events: event queue (EQ), completion queues (CQ), and receive and send
queues (RDQ, SDQ). RDQ and SDQ are then configured with a CQ to which
they report completion, and CQ is configured with an EQ, to which it
reports completion events. The order of configuration is therefore EQ,
then CQs, then RDQs and SDQs.
Further, there are NAPI contexts for processing CQ events and working
with either RDQ, or SDQ, a tasklet for processing EQ and scheduling
per-CQ NAPI contexts, and an IRQ handler that schedules the tasklet.
The order of configuration thus must be, first the NAPI contexts
(associated with CQs), then the tasklet (associated with the EQ), then
the IRQ handler.
The code however initializes the queue together with the scheduled
entity that processes that queue, in order of the queue configuration.
Thus is the tasklet initialized prior to NAPI contexts, even though it
refers to these NAPIs. This is actually a problem during destruction,
when the tasklet is destroyed after the queues that it refers to, and
SDQ and RDQ are destroyed prior to the respective NAPI context that
they are processed by.
IRQ handler is then set up as first, and torn down as last, which
is correct.
In this patchset address the ordering issue as follows.
- Patch #1 folds the current tasklet processing directly into the IRQ
handler. This is possible, because the amount of work is relatively
small and strictly bounded. The heavy lifting is done in NAPI queues
scheduled from this code, and the indirection through tasklet does
not bring much. The reason to actually do it is because it
simplifies the whole situation, and because the tasklet interface is
deprecated (see include/linux/interrupt.h).
- In patch #2, per-queue start and stop callbacks are introduced.
These are invoked after the queues themselves are initialized (and,
respectively, before they are deinitialized), and are used to set up
the NAPI context after all relevant resources are ready, and to tear
them down first before tearing down the resources they consume.
Petr Machata (2):
mlxsw: pci: Process EQ in the IRQ handler instead of a tasklet
mlxsw: pci: Fix teardown order of CQ NAPI instances
drivers/net/ethernet/mellanox/mlxsw/pci.c | 77 ++++++++++++++++-------
1 file changed, 55 insertions(+), 22 deletions(-)
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next 1/2] mlxsw: pci: Process EQ in the IRQ handler instead of a tasklet
2026-11-16 10:16 [PATCH net-next 0/2] mlxsw: Fix teardown order of CQ NAPI instances Petr Machata
@ 2026-11-16 10:16 ` Petr Machata
2026-11-16 10:16 ` [PATCH net-next 2/2] mlxsw: pci: Fix teardown order of CQ NAPI instances Petr Machata
2026-11-16 10:21 ` [PATCH net-next 0/2] mlxsw: " netdev-bot+sinfo
2 siblings, 0 replies; 5+ messages in thread
From: Petr Machata @ 2026-11-16 10:16 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev
Cc: Ido Schimmel, Petr Machata, mlxsw
mlxsw_pci_eq_irq_handler() schedules a tasklet, which then reads the EQ and
schedules NAPI instances for the CQs that have pending events. The actual
completion processing itself is done by NAPI.
The EQ processing is bounded by half of the EQ size (see credits in
mlxsw_pci_eq_tasklet()), and all it does is to ring two doorbells and call
napi_schedule(), both of which are safe to do from a hard IRQ context. The
EQ is only re-armed at the end, so the handler cannot be re-entered.
The tasklet therefore does not really serve a useful purpose: neither
structurally, nor with regards to permissible runtime operations, nor with
regards to amount of time spent in IRQ. It is just an extra deferral layer.
Drop the tasklet and do the work directly in the IRQ handler. Change
napi_schedule() to napi_schedule_irqoff() to leverage the fact that
interrupts are already masked.
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
---
drivers/net/ethernet/mellanox/mlxsw/pci.c | 31 ++++++++---------------
1 file changed, 11 insertions(+), 20 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci.c b/drivers/net/ethernet/mellanox/mlxsw/pci.c
index dceb69945d26..b2a7f568c74a 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/pci.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/pci.c
@@ -88,9 +88,6 @@ struct mlxsw_pci_queue {
struct napi_struct napi;
struct page_pool *page_pool;
} cq;
- struct {
- struct tasklet_struct tasklet;
- } eq;
struct {
struct mlxsw_pci_queue *cq;
} rdq;
@@ -1111,16 +1108,19 @@ static char *mlxsw_pci_eq_sw_eqe_get(struct mlxsw_pci_queue *q)
return elem;
}
-static void mlxsw_pci_eq_tasklet(struct tasklet_struct *t)
+static irqreturn_t mlxsw_pci_eq_irq_handler(int irq, void *dev_id)
{
unsigned long active_cqns[BITS_TO_LONGS(MLXSW_PCI_CQS_MAX)];
- struct mlxsw_pci_queue *q = from_tasklet(q, t, u.eq.tasklet);
- struct mlxsw_pci *mlxsw_pci = q->pci;
- int credits = q->count >> 1;
+ struct mlxsw_pci *mlxsw_pci = dev_id;
+ struct mlxsw_pci_queue *q;
u8 cqn, cq_count;
int items = 0;
+ int credits;
char *eqe;
+ q = mlxsw_pci_eq_get(mlxsw_pci);
+ credits = q->count >> 1;
+
memset(&active_cqns, 0, sizeof(active_cqns));
while ((eqe = mlxsw_pci_eq_sw_eqe_get(q))) {
@@ -1132,7 +1132,7 @@ static void mlxsw_pci_eq_tasklet(struct tasklet_struct *t)
}
if (!items)
- return;
+ return IRQ_HANDLED;
mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q);
mlxsw_pci_queue_doorbell_arm_consumer_ring(mlxsw_pci, q);
@@ -1140,8 +1140,10 @@ static void mlxsw_pci_eq_tasklet(struct tasklet_struct *t)
cq_count = mlxsw_pci->num_cqs;
for_each_set_bit(cqn, active_cqns, cq_count) {
q = mlxsw_pci_cq_get(mlxsw_pci, cqn);
- napi_schedule(&q->u.cq.napi);
+ napi_schedule_irqoff(&q->u.cq.napi);
}
+
+ return IRQ_HANDLED;
}
static int mlxsw_pci_eq_init(struct mlxsw_pci *mlxsw_pci, char *mbox,
@@ -1176,7 +1178,6 @@ static int mlxsw_pci_eq_init(struct mlxsw_pci *mlxsw_pci, char *mbox,
err = mlxsw_cmd_sw2hw_eq(mlxsw_pci->core, mbox, q->num);
if (err)
return err;
- tasklet_setup(&q->u.eq.tasklet, mlxsw_pci_eq_tasklet);
mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q);
mlxsw_pci_queue_doorbell_arm_consumer_ring(mlxsw_pci, q);
return 0;
@@ -1730,16 +1731,6 @@ static void mlxsw_pci_fw_area_fini(struct mlxsw_pci *mlxsw_pci)
kfree(mlxsw_pci->fw_area.items);
}
-static irqreturn_t mlxsw_pci_eq_irq_handler(int irq, void *dev_id)
-{
- struct mlxsw_pci *mlxsw_pci = dev_id;
- struct mlxsw_pci_queue *q;
-
- q = mlxsw_pci_eq_get(mlxsw_pci);
- tasklet_schedule(&q->u.eq.tasklet);
- return IRQ_HANDLED;
-}
-
static int mlxsw_pci_mbox_alloc(struct mlxsw_pci *mlxsw_pci,
struct mlxsw_pci_mem_item *mbox)
{
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next 2/2] mlxsw: pci: Fix teardown order of CQ NAPI instances
2026-11-16 10:16 [PATCH net-next 0/2] mlxsw: Fix teardown order of CQ NAPI instances Petr Machata
2026-11-16 10:16 ` [PATCH net-next 1/2] mlxsw: pci: Process EQ in the IRQ handler instead of a tasklet Petr Machata
@ 2026-11-16 10:16 ` Petr Machata
2026-11-16 10:21 ` [PATCH net-next 0/2] mlxsw: " netdev-bot+sinfo
2 siblings, 0 replies; 5+ messages in thread
From: Petr Machata @ 2026-11-16 10:16 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev
Cc: Ido Schimmel, Petr Machata, mlxsw, Myeonghun Pak, Ijae Kim,
Jiale Yao
In his report (see the link below), Myeonghun Pak <mhun512@gmail.com>
writes:
> mlxsw_pci_eq_irq_handler() schedules the EQ tasklet. The tasklet reads
> the EQ ring and schedules CQ NAPI instances. The CQ poll callbacks, in
> turn, dereference the RDQ or SDQ associated with the CQ.
>
> mlxsw_pci_fini() unregisters the IRQ and immediately tears down the
> asynchronous queues in RDQ, SDQ, CQ, EQ order. free_irq() waits for IRQ
> handlers, but not for a tasklet already scheduled by one. In addition,
> mlxsw_pci_cq_fini() disables each CQ NAPI only after all RDQs and SDQs
> have been freed. A pending tasklet or NAPI poll can therefore access
> freed queue storage.
The previous patch folded the tasklet into the IRQ handler, which takes
care of the first half of the problem: free_irq() in mlxsw_pci_fini() now
guarantees that nothing schedules CQ NAPI instances anymore. The second
half remains. A NAPI poll that was scheduled right before free_irq(), or
is currently running, can still dereference the RDQ or SDQ of its CQ, which
mlxsw_pci_aqs_fini() frees before the CQ, and where napi_disable() is
currently called.
In this patch, introduce a process-related duals to init / fini per-queue
callbacks: start and stop. Only CQ needs them for now, to manage the NAPI
instances. Invoke them at the end of mlxsw_pci_aqs_init() and at the
beginning of mlxsw_pci_aqs_fini(), respectively, so that NAPI is enabled
only once all queues are set up, and disabled before any of them is
destroyed. This also keeps napi_enable() and napi_disable() paired on error
paths of mlxsw_pci_aqs_init().
In his report, Myeonghun Pak notes that the issue was originally discovered
by static analysis.
Cc: Myeonghun Pak <mhun512@gmail.com>
Cc: Ijae Kim <ae878000@gmail.com>
Cc: Jiale Yao <yaojiale02@163.com>
Reported-by: Myeonghun Pak <mhun512@gmail.com>
Link: https://lore.kernel.org/netdev/20260721125753.35944-1-mhun512@gmail.com/
Reported-by: Jiale Yao <yaojiale02@163.com>
Link: https://lore.kernel.org/netdev/20261018040653.534066-1-yaojiale02@163.com/
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
---
drivers/net/ethernet/mellanox/mlxsw/pci.c | 46 ++++++++++++++++++++++-
1 file changed, 44 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci.c b/drivers/net/ethernet/mellanox/mlxsw/pci.c
index b2a7f568c74a..dc6cad5637d6 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/pci.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/pci.c
@@ -1059,7 +1059,6 @@ static int mlxsw_pci_cq_init(struct mlxsw_pci *mlxsw_pci, char *mbox,
if (err)
goto err_page_pool_init;
- napi_enable(&q->u.cq.napi);
mlxsw_pci_queue_doorbell_consumer_ring(mlxsw_pci, q);
mlxsw_pci_queue_doorbell_arm_consumer_ring(mlxsw_pci, q);
return 0;
@@ -1074,12 +1073,23 @@ static void mlxsw_pci_cq_fini(struct mlxsw_pci *mlxsw_pci,
{
enum mlxsw_pci_cq_type cq_type = mlxsw_pci_cq_type(mlxsw_pci, q);
- napi_disable(&q->u.cq.napi);
mlxsw_pci_cq_page_pool_fini(q, cq_type);
mlxsw_pci_cq_napi_teardown(q);
mlxsw_cmd_hw2sw_cq(mlxsw_pci->core, q->num);
}
+static void mlxsw_pci_cq_start(struct mlxsw_pci *mlxsw_pci,
+ struct mlxsw_pci_queue *q)
+{
+ napi_enable(&q->u.cq.napi);
+}
+
+static void mlxsw_pci_cq_stop(struct mlxsw_pci *mlxsw_pci,
+ struct mlxsw_pci_queue *q)
+{
+ napi_disable(&q->u.cq.napi);
+}
+
static u16 mlxsw_pci_cq_elem_count(const struct mlxsw_pci_queue *q)
{
return q->u.cq.v == MLXSW_PCI_CQE_V2 ? MLXSW_PCI_CQE2_COUNT :
@@ -1198,6 +1208,10 @@ struct mlxsw_pci_queue_ops {
struct mlxsw_pci_queue *q);
void (*fini)(struct mlxsw_pci *mlxsw_pci,
struct mlxsw_pci_queue *q);
+ void (*start)(struct mlxsw_pci *mlxsw_pci,
+ struct mlxsw_pci_queue *q);
+ void (*stop)(struct mlxsw_pci *mlxsw_pci,
+ struct mlxsw_pci_queue *q);
u16 (*elem_count_f)(const struct mlxsw_pci_queue *q);
u8 (*elem_size_f)(const struct mlxsw_pci_queue *q);
u16 elem_count;
@@ -1225,6 +1239,8 @@ static const struct mlxsw_pci_queue_ops mlxsw_pci_cq_ops = {
.pre_init = mlxsw_pci_cq_pre_init,
.init = mlxsw_pci_cq_init,
.fini = mlxsw_pci_cq_fini,
+ .start = mlxsw_pci_cq_start,
+ .stop = mlxsw_pci_cq_stop,
.elem_count_f = mlxsw_pci_cq_elem_count,
.elem_size_f = mlxsw_pci_cq_elem_size
};
@@ -1349,6 +1365,28 @@ static void mlxsw_pci_queue_group_fini(struct mlxsw_pci *mlxsw_pci,
kfree(queue_group->q);
}
+static void mlxsw_pci_queue_group_start(struct mlxsw_pci *mlxsw_pci,
+ const struct mlxsw_pci_queue_ops *q_ops)
+{
+ struct mlxsw_pci_queue_type_group *queue_group;
+ int i;
+
+ queue_group = mlxsw_pci_queue_type_group_get(mlxsw_pci, q_ops->type);
+ for (i = 0; i < queue_group->count; i++)
+ q_ops->start(mlxsw_pci, &queue_group->q[i]);
+}
+
+static void mlxsw_pci_queue_group_stop(struct mlxsw_pci *mlxsw_pci,
+ const struct mlxsw_pci_queue_ops *q_ops)
+{
+ struct mlxsw_pci_queue_type_group *queue_group;
+ int i;
+
+ queue_group = mlxsw_pci_queue_type_group_get(mlxsw_pci, q_ops->type);
+ for (i = 0; i < queue_group->count; i++)
+ q_ops->stop(mlxsw_pci, &queue_group->q[i]);
+}
+
static int mlxsw_pci_aqs_init(struct mlxsw_pci *mlxsw_pci, char *mbox)
{
struct pci_dev *pdev = mlxsw_pci->pdev;
@@ -1426,6 +1464,8 @@ static int mlxsw_pci_aqs_init(struct mlxsw_pci *mlxsw_pci, char *mbox)
goto err_rdqs_init;
}
+ mlxsw_pci_queue_group_start(mlxsw_pci, &mlxsw_pci_cq_ops);
+
return 0;
err_rdqs_init:
@@ -1439,6 +1479,8 @@ static int mlxsw_pci_aqs_init(struct mlxsw_pci *mlxsw_pci, char *mbox)
static void mlxsw_pci_aqs_fini(struct mlxsw_pci *mlxsw_pci)
{
+ mlxsw_pci_queue_group_stop(mlxsw_pci, &mlxsw_pci_cq_ops);
+
mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_rdq_ops);
mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_sdq_ops);
mlxsw_pci_queue_group_fini(mlxsw_pci, &mlxsw_pci_cq_ops);
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next 0/2] mlxsw: Fix teardown order of CQ NAPI instances
2026-11-16 10:16 [PATCH net-next 0/2] mlxsw: Fix teardown order of CQ NAPI instances Petr Machata
2026-11-16 10:16 ` [PATCH net-next 1/2] mlxsw: pci: Process EQ in the IRQ handler instead of a tasklet Petr Machata
2026-11-16 10:16 ` [PATCH net-next 2/2] mlxsw: pci: Fix teardown order of CQ NAPI instances Petr Machata
@ 2026-11-16 10:21 ` netdev-bot+sinfo
2026-11-16 12:59 ` Petr Machata
2 siblings, 1 reply; 5+ messages in thread
From: netdev-bot+sinfo @ 2026-11-16 10:21 UTC (permalink / raw)
To: Petr Machata
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, Ido Schimmel, mlxsw
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
- What hardware the change was tested on. For driver fixes please
mention the device (and if relevant firmware version) used for
testing, or say that the change was not tested on real hardware.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next 0/2] mlxsw: Fix teardown order of CQ NAPI instances
2026-11-16 10:21 ` [PATCH net-next 0/2] mlxsw: " netdev-bot+sinfo
@ 2026-11-16 12:59 ` Petr Machata
0 siblings, 0 replies; 5+ messages in thread
From: Petr Machata @ 2026-11-16 12:59 UTC (permalink / raw)
To: netdev-bot+sinfo
Cc: Petr Machata, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, netdev, Ido Schimmel, mlxsw
netdev-bot+sinfo@kernel.org writes:
> This is an automated message. This series looks like a fix, but its
> commit messages seem to be missing some information:
>
> - Whether the issue was actually triggered, or is only theoretical
> (e.g. found by LLM and not proven at runtime). If it was triggered
> please include the symptoms, like the stack trace or kernel messages.
In Myeonghun Pak's original report, linked from patch #2 and available
online, the issue is claimed to have been discovered by static analysis.
A second report that came later does not declare the discovery method,
but given the circumstances, it is almost certainly not organic either.
We have not attempted to trigger the issue. When pointed out as such,
the code is obviously wrong.
> - What hardware the change was tested on. For driver fixes please
> mention the device (and if relevant firmware version) used for
> testing, or say that the change was not tested on real hardware.
The patches were tested across supported Spectrum machines as part of
our internal regression for about a week.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-16 13:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 10:16 [PATCH net-next 0/2] mlxsw: Fix teardown order of CQ NAPI instances Petr Machata
2026-11-16 10:16 ` [PATCH net-next 1/2] mlxsw: pci: Process EQ in the IRQ handler instead of a tasklet Petr Machata
2026-11-16 10:16 ` [PATCH net-next 2/2] mlxsw: pci: Fix teardown order of CQ NAPI instances Petr Machata
2026-11-16 10:21 ` [PATCH net-next 0/2] mlxsw: " netdev-bot+sinfo
2026-11-16 12:59 ` Petr Machata
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox