[PATCH v3 2/3] spinlock: add debug checks in recursive unlock
Robin Jarry
rjarry at redhat.com
Tue May 19 13:47:39 CEST 2026
Thomas Monjalon, May 19, 2026 at 12:34:
> The recursive unlock assumes that the caller owns the lock.
> This behavior will be checked when RTE_ENABLE_ASSERT is on.
> There is an additional check for the count which should be positive
> if no corruption happened.
>
> Signed-off-by: Thomas Monjalon <thomas at monjalon.net>
> ---
> v3: new patch in the series
> ---
> lib/eal/include/generic/rte_spinlock.h | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/lib/eal/include/generic/rte_spinlock.h b/lib/eal/include/generic/rte_spinlock.h
> index ffdcb8fa3d..e7cd18a8e2 100644
> --- a/lib/eal/include/generic/rte_spinlock.h
> +++ b/lib/eal/include/generic/rte_spinlock.h
> @@ -21,6 +21,7 @@
> #ifdef RTE_FORCE_INTRINSICS
> #include <rte_common.h>
> #endif
> +#include <rte_debug.h>
> #include <rte_lock_annotations.h>
> #include <rte_pause.h>
> #include <rte_stdatomic.h>
> @@ -245,6 +246,8 @@ static inline void rte_spinlock_recursive_lock(rte_spinlock_recursive_t *slr)
> static inline void rte_spinlock_recursive_unlock(rte_spinlock_recursive_t *slr)
> __rte_no_thread_safety_analysis
> {
> + RTE_ASSERT(rte_atomic_load_explicit(&slr->owner, rte_memory_order_relaxed) == rte_gettid());
> + RTE_ASSERT(slr->count > 0);
> if (--(slr->count) == 0) {
> rte_atomic_store_explicit(&slr->owner, -1, rte_memory_order_relaxed);
> rte_spinlock_unlock(&slr->sl);
Acked-by: Robin Jarry <rjarry at redhat.com>
More information about the dev
mailing list