OpenSBI Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Carlos López" <carlos.lopezr4096@gmail.com>
To: opensbi@lists.infradead.org
Cc: "Carlos López" <carlos.lopezr4096@gmail.com>
Subject: [PATCH v2 03/14] lib: sbi_fifo: add TSA annotations
Date: Wed,  9 Sep 2026 18:23:12 +0200	[thread overview]
Message-ID: <20260909162322.29778-5-carlos.lopezr4096@gmail.com> (raw)
In-Reply-To: <20260909162322.29778-2-carlos.lopezr4096@gmail.com>

Add Thread Safety Analysis (TSA) annotations for the FIFO
implementation. This consists of indicating which fields are protected
by a spinlock and annotating functionst that must be called under a
spinlock. sbi_fifo_init() must be excluded, as acquiring a spinlock
before it is initialized does not make sense.

Signed-off-by: Carlos López <carlos.lopezr4096@gmail.com>
---
 include/sbi/sbi_fifo.h |  6 +++---
 lib/sbi/sbi_fifo.c     | 11 ++++++++---
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/include/sbi/sbi_fifo.h b/include/sbi/sbi_fifo.h
index 89a2ea26a259..4ec10e05415e 100644
--- a/include/sbi/sbi_fifo.h
+++ b/include/sbi/sbi_fifo.h
@@ -15,12 +15,12 @@
 #include <sbi/sbi_types.h>
 
 struct sbi_fifo {
-	void *queue;
 	spinlock_t qlock;
+	void *queue PT_GUARDED_BY(&qlock);
 	u16 entry_size;
 	u16 num_entries;
-	u16 avail;
-	u16 tail;
+	u16 avail GUARDED_BY(&qlock);
+	u16 tail GUARDED_BY(&qlock);
 };
 
 #define SBI_FIFO_INITIALIZER(__queue_mem, __entries, __entry_size)	\
diff --git a/lib/sbi/sbi_fifo.c b/lib/sbi/sbi_fifo.c
index d07ebff4955c..88b8888d2e81 100644
--- a/lib/sbi/sbi_fifo.c
+++ b/lib/sbi/sbi_fifo.c
@@ -13,7 +13,7 @@
 #include <sbi/sbi_string.h>
 
 void sbi_fifo_init(struct sbi_fifo *fifo, void *queue_mem, u16 entries,
-		   u16 entry_size)
+		   u16 entry_size) NO_THREAD_SAFETY_ANALYSIS
 {
 	fifo->queue	  = queue_mem;
 	fifo->num_entries = entries;
@@ -25,6 +25,7 @@ void sbi_fifo_init(struct sbi_fifo *fifo, void *queue_mem, u16 entries,
 
 /* Note: must be called with fifo->qlock held */
 static inline bool __sbi_fifo_is_full(struct sbi_fifo *fifo)
+	MUST_HOLD(&fifo->qlock)
 {
 	return (fifo->avail == fifo->num_entries) ? true : false;
 }
@@ -58,7 +59,8 @@ int sbi_fifo_is_full(struct sbi_fifo *fifo)
 }
 
 /* Note: must be called with fifo->qlock held */
-static inline void  __sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data)
+static inline void __sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data)
+	MUST_HOLD(&fifo->qlock)
 {
 	u32 head;
 
@@ -91,7 +93,8 @@ static inline void  __sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data)
 }
 
 /* Note: must be called with fifo->qlock held */
-static inline void  __sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data)
+static inline void __sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data)
+	MUST_HOLD(&fifo->qlock)
 {
 	if (!data)
 		goto skip_data_copy;
@@ -126,6 +129,7 @@ skip_data_copy:
 
 /* Note: must be called with fifo->qlock held */
 static inline bool __sbi_fifo_is_empty(struct sbi_fifo *fifo)
+	MUST_HOLD(&fifo->qlock)
 {
 	return (fifo->avail == 0) ? true : false;
 }
@@ -146,6 +150,7 @@ int sbi_fifo_is_empty(struct sbi_fifo *fifo)
 
 /* Note: must be called with fifo->qlock held */
 static inline void __sbi_fifo_reset(struct sbi_fifo *fifo)
+	MUST_HOLD(&fifo->qlock)
 {
 	size_t size = (size_t)fifo->num_entries * fifo->entry_size;
 
-- 
2.51.0


-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

  parent reply	other threads:[~2026-09-09 16:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 16:23 [PATCH v2 00/14] Add clang Thread Safety Analysis (TSA) support Carlos López
2026-09-09 16:23 ` [PATCH v2 01/14] include: sbi: add thread safety analysis macros Carlos López
2026-09-09 16:23 ` [PATCH v2 02/14] lib: sbi_locks: annotate spinlock APIs for TSA Carlos López
2026-09-09 16:23 ` Carlos López [this message]
2026-09-09 16:23 ` [PATCH v2 04/14] lib: sbi_heap: add TSA annotations Carlos López
2026-09-09 16:23 ` [PATCH v2 05/14] lib: sbi_scratch: " Carlos López
2026-09-09 16:23 ` [PATCH v2 06/14] lib: rpmi: " Carlos López
2026-09-09 16:23 ` [PATCH v2 07/14] lib: sbi_timer: " Carlos López
2026-09-09 16:23 ` [PATCH v2 08/14] lib: htif: " Carlos López
2026-09-09 16:23 ` [PATCH v2 09/14] lib: sbi_domain: " Carlos López
2026-09-09 16:23 ` [PATCH v2 10/14] lib: sbi_sse: inline enable event locking Carlos López
2026-09-09 16:23 ` [PATCH v2 11/14] lib: sbi_sse: pass SSE hart state explicitly Carlos López
2026-09-09 16:23 ` [PATCH v2 12/14] lib: sbi_sse: add TSA annotations Carlos López
2026-09-09 16:23 ` [PATCH v2 13/14] lib: test: disable TSA for spinlock tests Carlos López
2026-09-09 16:23 ` [PATCH v2 14/14] Makefile: enable Thread Safety Analysis Carlos López

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=20260909162322.29778-5-carlos.lopezr4096@gmail.com \
    --to=carlos.lopezr4096@gmail.com \
    --cc=opensbi@lists.infradead.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