DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [RFC] eal: enable thread safety analysis for recursive lock
Date: Mon, 18 May 2026 09:34:26 -0700	[thread overview]
Message-ID: <20260518163500.583397-1-stephen@networkplumber.org> (raw)

The recursive spinlock API was annotated with
__rte_no_thread_safety_analysis on each definition, with no capability
annotations on any declaration. As a result, callers received no
static checking: fields marked __rte_guarded_by() on a recursive
spinlock were not verified, and rte_spinlock_recursive_t was not
recognized as a capability at all.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/eal/include/generic/rte_spinlock.h | 28 +++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/lib/eal/include/generic/rte_spinlock.h b/lib/eal/include/generic/rte_spinlock.h
index 5d810b682a..e489f846f6 100644
--- a/lib/eal/include/generic/rte_spinlock.h
+++ b/lib/eal/include/generic/rte_spinlock.h
@@ -195,7 +195,7 @@ rte_spinlock_trylock_tm(rte_spinlock_t *sl)
 /**
  * The rte_spinlock_recursive_t type.
  */
-typedef struct {
+typedef struct __rte_capability("recursive_spinlock") {
 	rte_spinlock_t sl; /**< the actual spinlock */
 	RTE_ATOMIC(int) user; /**< core id using lock, -1 for unused */
 	int count; /**< count of time this lock has been called */
@@ -219,6 +219,32 @@ static inline void rte_spinlock_recursive_init(rte_spinlock_recursive_t *slr)
 	slr->count = 0;
 }
 
+/*
+ * TSA models the recursive spinlock as a single capability: callers
+ * get the same __rte_guarded_by() checking as the non-recursive API.
+ * Nested acquires by the owner are invisible to the analyzer — TSA
+ * has no model for re-entrance, so mismatched recursive lock/unlock
+ * counts remain a runtime concern.
+ *
+ * The definitions use __rte_no_thread_safety_analysis because the
+ * inner rte_spinlock_lock() is conditional on the owner check, which
+ * TSA cannot reason about. Annotations on the declarations are what
+ * callers see.
+ */
+
+static inline void
+rte_spinlock_recursive_lock(rte_spinlock_recursive_t *slr)
+	__rte_acquire_capability(slr);
+
+static inline void
+rte_spinlock_recursive_unlock(rte_spinlock_recursive_t *slr)
+	__rte_release_capability(slr);
+
+__rte_warn_unused_result
+static inline int
+rte_spinlock_recursive_trylock(rte_spinlock_recursive_t *slr)
+	__rte_try_acquire_capability(true, slr);
+
 /**
  * Take the recursive spinlock.
  *
-- 
2.53.0


                 reply	other threads:[~2026-05-18 16:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260518163500.583397-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox