Re: [PATCH net-next v2] net: dlink: add synchronization for stats update

From: Moon Yeounsu
Date: Fri May 02 2025 - 19:51:13 EST


Thank you for reviewing my patch!

On Wed, Apr 30, 2025 at 6:35 AM Jakub Kicinski <kuba@xxxxxxxxxx> wrote:
> I could be wrong but since this code runs in IRQ context I believe
> you need to use spin_lock_irqsave() here. Or just spin_lock() but
> not sure, and spin_lock_irqsave() always works..

If my understanding is correct, then it seems I was mistaken and you were right.

I misunderstood that the same form of locking function should always
be used for a given lock. However, as you pointed out,
`spin_[un]lock()` seems to be the correct choice in this case.
This is because the `tx_error()` function is only called from
`rio_interrupt()`, which runs in IRQ context. (There are no other call
paths.) In this context, there's no need to enable or disable IRQs at
all.

Also, I believe that `spin_lock_irq()` in `get_stats()` should be
changed to `spin_lock_irqsave()` since `get_stats()` can be called
from IRQ context (via `rio_interrupt()` -> `rio_error()` ->
`get_stats()`). In my view, calling `spin_unlock_irq()` in this
context could be risky, as it would re-enable local IRQs via
local_irq_enable().

There are two ways to lock the `get_stats()` function: either add a
new parameter to check whether it's in IRQ context, or simply use
`spin_lock_irqsave()`. I found that `rio_free_tx()` behaves like the
first case. I'd appreciate your opinion on which approach would be
preferable here.

Thanks again for your feedback.

Best regards,
Moon Yeounsu