Re: [PATCH net-next v5] net: dlink: add support for reporting stats via `ethtool -S` and `ip -s -s link show`

From: Moon Yeounsu
Date: Mon Mar 31 2025 - 12:41:14 EST


First of all, I apologize for my late reply.
To be honest, I didn't fully understand the code I wrote.

The reason I initially decided to use `spin_lock_irqsave()` was that
most of the other stat-related code was using it.
So when I received your reply, I didn't understand why `spin_lock_bh()`
should be used. That's why I started reviewing interrupts and locks again.

As a result, my response got delayed. However, I believe I should take
full responsibility for the code I wrote.

I still don't fully understand interrupts and locks,
as the IRQ subsystem is vast and complex.

On Tue, Dec 10, 2024 at 07:15:19PM -0800, Jakub Kicinski wrote:
> On Mon, 9 Dec 2024 18:28:27 +0900 Moon Yeounsu wrote:
> > + unsigned long flags;
> > +
> > + spin_lock_irqsave(&np->stats_lock, flags);
>
> I believe spin_lock_bh() is sufficient here, no need to save IRQ flags.
>

Anyway, base on what I have learned, I believe `spin_lock_irq()`
should be used in this context instead of `spin_lock_bh()`.

The reason is that the `get_stats()` function can be called from
an interrupt context (in the top-half).

If my understanding is correct, calling `spin_lock_bh()` in the
top-half may lead to a deadlock.

The calling sequence is as follows:
1. `rio_interrupt()` (registered via `request_irq()`)
2. `rio_error()`
3. `get_stats()`

> > + u64 collisions = np->single_collisions + np->multi_collisions;
> > + u64 tx_frames_abort = np->tx_frames_abort;
> > + u64 tx_carrier_errors = np->tx_carrier_sense_errors;
>
> Please don't mix code and variable declarations.

I'll fix it as well.
Thank you for pointing that out.

> --
> pw-bot: cr

If I am mistaken, please let me know.

Thank you for reviewing my patch!