Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [High] NMI Deadlock / Lock Reentrancy on 32-bit architectures
--

commit 29c9d40bef06feb46125ab67ac5762b58ace9c11
Author: Tobias Schaffner <[email protected]>

rv: add per-edge dwell-time statistics primitive

Add a small primitive that records, per automaton edge, how long the
monitor dwelled before taking it with a count, a sum and a maximum.
The counters are kept in local64_t variables so a monitor's hot path
can update them without disabling interrupts.

> diff --git a/include/linux/rv_edge_stat.h b/include/linux/rv_edge_stat.h
> new file mode 100644
> index 0000000000000..751de8074dcc3
> --- /dev/null
> +++ b/include/linux/rv_edge_stat.h

[ ... ]

> +static __always_inline
> +void rv_edge_stat_account(struct rv_edge_stat *s, u64 dwell_ns)
> +{
> +     s64 max;
> +
> +     local64_inc(&s->count);
> +     local64_add(dwell_ns, &s->sum_ns);
> +
> +     /* Keep the largest dwell; retry only if a nested update raced us. */
> +     max = local64_read(&s->max_ns);
> +     while (dwell_ns > (u64)max) {
> +             s64 prev = local64_cmpxchg(&s->max_ns, max, dwell_ns);

[Severity: High]
Could this cause an NMI deadlock on 32-bit architectures?

The commit message notes these counters are lock-free, but on 32-bit platforms
lacking native 64-bit atomics (e.g., ARMv6 or RISC-V 32 with
CONFIG_GENERIC_ATOMIC64=y), local64_t operations fall back to atomic64_t. 

The generic atomic64 implementation uses a hashed array of spinlocks acquired
via local_irq_save(), which disables regular interrupts but not NMIs.

If an NMI interrupts rv_edge_stat_account() while it holds one of these
non-reentrant spinlocks, and the NMI handler triggers an RV monitor event
that hashes to the same lock, would the CPU deadlock attempting to acquire
the already-held spinlock?

Does this implementation need an explicit check to abort if
IS_ENABLED(CONFIG_GENERIC_ATOMIC64) && in_nmi(), similar to the protection
used in the trace ring buffer?

> +
> +             if (prev == max)
> +                     break;
> +             max = prev;
> +     }
> +}
> +
> +#endif /* _LINUX_RV_EDGE_STAT_H */

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to