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 11/14] lib: sbi_sse: pass SSE hart state explicitly
Date: Wed,  9 Sep 2026 18:23:20 +0200	[thread overview]
Message-ID: <20260909162322.29778-13-carlos.lopezr4096@gmail.com> (raw)
In-Reply-To: <20260909162322.29778-2-carlos.lopezr4096@gmail.com>

In preparation to add TSA annotations, pass the SSE hart state owning an
event, instead of relying on sse_get_hart_state() to retrieve it from
the event itself. This makes the relationship more explicit, and will
allow the compiler to reason about the state of locks.

Signed-off-by: Carlos López <carlos.lopezr4096@gmail.com>
---
 lib/sbi/sbi_sse.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
index 3d1601674e07..39e52752b024 100644
--- a/lib/sbi/sbi_sse.c
+++ b/lib/sbi/sbi_sse.c
@@ -328,9 +328,9 @@ static void sse_event_remove_from_list(struct sbi_sse_event *e)
 /**
  * Must be called under owner hart lock
  */
-static void sse_event_add_to_list(struct sbi_sse_event *e)
+static void sse_event_add_to_list(struct sse_hart_state *state,
+				   struct sbi_sse_event *e)
 {
-	struct sse_hart_state *state = sse_get_hart_state(e);
 	struct sbi_sse_event *tmp;
 
 	sbi_list_for_each_entry(tmp, &state->enabled_event_list, node) {
@@ -346,7 +346,8 @@ static void sse_event_add_to_list(struct sbi_sse_event *e)
 /**
  * Must be called under owner hart lock
  */
-static int sse_event_disable(struct sbi_sse_event *e)
+static int sse_event_disable(struct sse_hart_state *shs,
+			      struct sbi_sse_event *e)
 {
 	if (sse_event_state(e) != SBI_SSE_STATE_ENABLED)
 		return SBI_EINVALID_STATE;
@@ -778,13 +779,14 @@ static int sse_inject_event(uint32_t event_id, unsigned long hartid)
 /**
  * Must be called under owner hart lock
  */
-static int sse_event_enable(struct sbi_sse_event *e)
+static int sse_event_enable(struct sse_hart_state *shs,
+			     struct sbi_sse_event *e)
 {
 	if (sse_event_state(e) != SBI_SSE_STATE_REGISTERED)
 		return SBI_EINVALID_STATE;
 
 	sse_event_set_state(e, SBI_SSE_STATE_ENABLED);
-	sse_event_add_to_list(e);
+	sse_event_add_to_list(shs, e);
 
 	sse_event_invoke_cb(e, enable_cb);
 
@@ -795,7 +797,8 @@ static int sse_event_enable(struct sbi_sse_event *e)
 	return SBI_OK;
 }
 
-static int sse_event_complete(struct sbi_sse_event *e,
+static int sse_event_complete(struct sse_hart_state *shs,
+			      struct sbi_sse_event *e,
 			      struct sbi_trap_regs *regs,
 			      struct sbi_ecall_return *out)
 {
@@ -807,7 +810,7 @@ static int sse_event_complete(struct sbi_sse_event *e,
 
 	sse_event_set_state(e, SBI_SSE_STATE_ENABLED);
 	if (e->attrs.config & SBI_SSE_ATTR_CONFIG_ONESHOT)
-		sse_event_disable(e);
+		sse_event_disable(shs, e);
 
 	sse_event_invoke_cb(e, complete_cb);
 
@@ -830,7 +833,7 @@ int sbi_sse_complete(struct sbi_trap_regs *regs, struct sbi_ecall_return *out)
 		 * the one that needs to be completed
 		 */
 		if (sse_event_state(tmp) == SBI_SSE_STATE_RUNNING) {
-			ret = sse_event_complete(tmp, regs, out);
+			ret = sse_event_complete(state, tmp, regs, out);
 			break;
 		}
 	}
@@ -851,7 +854,7 @@ int sbi_sse_enable(uint32_t event_id)
 
 	shs = sse_get_hart_state(e);
 	spin_lock(&shs->enabled_event_lock);
-	ret = sse_event_enable(e);
+	ret = sse_event_enable(shs, e);
 	spin_unlock(&shs->enabled_event_lock);
 	sse_event_put(e);
 
@@ -870,7 +873,7 @@ int sbi_sse_disable(uint32_t event_id)
 
 	shs = sse_get_hart_state(e);
 	spin_lock(&shs->enabled_event_lock);
-	ret = sse_event_disable(e);
+	ret = sse_event_disable(shs, e);
 	spin_unlock(&shs->enabled_event_lock);
 
 	sse_event_put(e);
-- 
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 ` [PATCH v2 03/14] lib: sbi_fifo: add TSA annotations Carlos López
2026-09-09 16:23 ` [PATCH v2 04/14] lib: sbi_heap: " 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 ` Carlos López [this message]
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-13-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