Skip to contentSkip to conversation

lib: sbi: sse: fixes after review

PATCH New Clément Léger 3 participants 16 messages Apr 9, 2024 – May 7, 2024

lore
Share & tools
lore
#0 lore raw

cover lib: sbi: sse: fixes after review

This small series addresses a few comments from Samuel that were made after the series was merged.

Cl?ment L?ger (7):
lib: sbi: sse: fix typos, comments and spacing errors
lib: sbi: sse: rename sse_hart_unlock() to sse_enabled_event_unlock()
lib: sbi: sse: simplify 32bits overflow check
lib: sbi: sse: remove superfluous sbi_list_empty() check
lib: sbi: sse: call enable callback before sending IPI
lib: sbi: sse: use PRV_S instead of hardcoded value for mode
lib: sbi: sse: check handler entry to belong to supervisor mode

 include/sbi/sbi_ecall_interface.h | 24 +++++++-------
 lib/sbi/sbi_sse.c                 | 53 ++++++++++++++++---------------
 2 files changed, 40 insertions(+), 37 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/7 lib: sbi: sse: fix typos, comments and spacing errors

Fix some errors spotted by Samuel while reviewing the SSE implementation.

---
 include/sbi/sbi_ecall_interface.h | 24 ++++++++++++------------
 lib/sbi/sbi_sse.c                 | 22 +++++++++++-----------
 2 files changed, 23 insertions(+), 23 deletions(-)
include/sbi/sbi_ecall_interface.h +12 -12
index a511e0b..2600b66 100644
@@ -344,36 +344,36 @@ enum sbi_sse_attr_id {
 #define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP	BIT(3)
 
 enum sbi_sse_state {
-	SBI_SSE_STATE_UNUSED     = 0,
-	SBI_SSE_STATE_REGISTERED = 1,
-	SBI_SSE_STATE_ENABLED    = 2,
-	SBI_SSE_STATE_RUNNING    = 3,
+	SBI_SSE_STATE_UNUSED		= 0,
+	SBI_SSE_STATE_REGISTERED	= 1,
+	SBI_SSE_STATE_ENABLED		= 2,
+	SBI_SSE_STATE_RUNNING		= 3,
 };
 
 /* SBI SSE Event IDs. */
 #define SBI_SSE_EVENT_LOCAL_RAS			0x00000000
-#define	SBI_SSE_EVENT_LOCAL_PLAT_0_START	0x00004000
+#define SBI_SSE_EVENT_LOCAL_PLAT_0_START	0x00004000
 #define SBI_SSE_EVENT_LOCAL_PLAT_0_END		0x00007fff
 #define SBI_SSE_EVENT_GLOBAL_RAS		0x00008000
-#define	SBI_SSE_EVENT_GLOBAL_PLAT_0_START	0x00004000
+#define SBI_SSE_EVENT_GLOBAL_PLAT_0_START	0x00004000
 #define SBI_SSE_EVENT_GLOBAL_PLAT_0_END		0x00007fff
 
 #define SBI_SSE_EVENT_LOCAL_PMU			0x00010000
-#define	SBI_SSE_EVENT_LOCAL_PLAT_1_START	0x00014000
+#define SBI_SSE_EVENT_LOCAL_PLAT_1_START	0x00014000
 #define SBI_SSE_EVENT_LOCAL_PLAT_1_END		0x00017fff
-#define	SBI_SSE_EVENT_GLOBAL_PLAT_1_START	0x0001c000
+#define SBI_SSE_EVENT_GLOBAL_PLAT_1_START	0x0001c000
 #define SBI_SSE_EVENT_GLOBAL_PLAT_1_END		0x0001ffff
 
-#define	SBI_SSE_EVENT_LOCAL_PLAT_2_START	0x00024000
+#define SBI_SSE_EVENT_LOCAL_PLAT_2_START	0x00024000
 #define SBI_SSE_EVENT_LOCAL_PLAT_2_END		0x00027fff
-#define	SBI_SSE_EVENT_GLOBAL_PLAT_2_START	0x0002c000
+#define SBI_SSE_EVENT_GLOBAL_PLAT_2_START	0x0002c000
 #define SBI_SSE_EVENT_GLOBAL_PLAT_2_END		0x0002ffff
 
 #define SBI_SSE_EVENT_LOCAL_SOFTWARE		0xffff0000
-#define	SBI_SSE_EVENT_LOCAL_PLAT_3_START	0xffff4000
+#define SBI_SSE_EVENT_LOCAL_PLAT_3_START	0xffff4000
 #define SBI_SSE_EVENT_LOCAL_PLAT_3_END		0xffff7fff
 #define SBI_SSE_EVENT_GLOBAL_SOFTWARE		0xffff8000
-#define	SBI_SSE_EVENT_GLOBAL_PLAT_3_START	0xffffc000
+#define SBI_SSE_EVENT_GLOBAL_PLAT_3_START	0xffffc000
 #define SBI_SSE_EVENT_GLOBAL_PLAT_3_END		0xffffffff
 
 #define SBI_SSE_EVENT_GLOBAL_BIT		(1 << 15)
lib/sbi/sbi_sse.c +11 -11
index a686692..39b4588 100644
@@ -128,7 +128,7 @@ struct sse_hart_state {
 	 *
 	 * When an event is in a state >= ENABLED, then it is inserted in the
 	 * this enabled_event_list and thus can only be removed from this
-	 * list upon disable ecall or on complete with ONE_SHOT flag.
+	 * list upon disable ecall or on complete with ONESHOT flag.
 	 */
 	struct sbi_dlist enabled_event_list;
 
@@ -202,7 +202,7 @@ static struct sse_hart_state *sse_get_hart_state(struct sbi_sse_event *e)
 	return sse_get_hart_state_ptr(s);
 }
 
-static struct sse_global_event *sse_get_global_event(struct sbi_sse_event* e)
+static struct sse_global_event *sse_get_global_event(struct sbi_sse_event *e)
 {
 	return container_of(e, struct sse_global_event, event);
 }
@@ -552,11 +552,11 @@ static bool sse_event_check_inject(struct sbi_sse_event *e,
 				   struct sbi_trap_regs *regs)
 {
 	/*
-	* List of event is ordered by priority, stop at first running
-	* event since all other events after this one are of lower
-	* priority. This means an event of higher priority is already
-	* running.
-	*/
+	 * List of event is ordered by priority, stop at first running
+	 * event since all other events after this one are of lower
+	 * priority. This means an event of higher priority is already
+	 * running.
+	 */
 	if (sse_event_state(e) == SBI_SSE_STATE_RUNNING) {
 		return true;
 	}
@@ -882,10 +882,10 @@ int sbi_sse_read_attrs(uint32_t event_id, uint32_t base_attr_id,
 
 	/*
 	 * Copy all attributes at once since struct sse_event_attrs is matching
-	 * the SBI_SSE_ATTR_* attributes. While WRITE_ATTR attribute is not used
-	 * in s-mode sse handling path, READ_ATTR is used to retrieve the value
-	 * of registers when interrupted. Rather than doing multiple SBI calls,
-	 * a single one is done allowing to retrieve them all at once.
+	 * the SBI_SSE_ATTR_* attributes. READ_ATTR is used in SSE handling path
+	 * to retrieve the value of registers when interrupted. Rather than
+	 * doing multiple SBI calls a single one is done allowing to retrieve
+	 * them all at once.
 	 */
 	e_attrs = (unsigned long *)&e->attrs;
 	attrs = (unsigned long *)output_phys_lo;
Signature · 1 line
2.43.0
#2 lore raw

PATCH 1/7 lib: sbi: sse: fix typos, comments and spacing errors

Quoted 5 lines · On Tue, Apr 9, 2024 at 3:32?PM Cl?ment L?ger <[email protected]> wrote:

Fix some errors spotted by Samuel while reviewing the SSE implementation.

LGTM.

Regards,
Anup

Quoted 120 lines
---
 include/sbi/sbi_ecall_interface.h | 24 ++++++++++++------------
 lib/sbi/sbi_sse.c                 | 22 +++++++++++-----------
 2 files changed, 23 insertions(+), 23 deletions(-)
include/sbi/sbi_ecall_interface.h +12 -12
index a511e0b..2600b66 100644
@@ -344,36 +344,36 @@ enum sbi_sse_attr_id {
 #define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP    BIT(3)
 
 enum sbi_sse_state {
-       SBI_SSE_STATE_UNUSED     = 0,
-       SBI_SSE_STATE_REGISTERED = 1,
-       SBI_SSE_STATE_ENABLED    = 2,
-       SBI_SSE_STATE_RUNNING    = 3,
+       SBI_SSE_STATE_UNUSED            = 0,
+       SBI_SSE_STATE_REGISTERED        = 1,
+       SBI_SSE_STATE_ENABLED           = 2,
+       SBI_SSE_STATE_RUNNING           = 3,
 };
 
 /* SBI SSE Event IDs. */
 #define SBI_SSE_EVENT_LOCAL_RAS                        0x00000000
-#define        SBI_SSE_EVENT_LOCAL_PLAT_0_START        0x00004000
+#define SBI_SSE_EVENT_LOCAL_PLAT_0_START       0x00004000
 #define SBI_SSE_EVENT_LOCAL_PLAT_0_END         0x00007fff
 #define SBI_SSE_EVENT_GLOBAL_RAS               0x00008000
-#define        SBI_SSE_EVENT_GLOBAL_PLAT_0_START       0x00004000
+#define SBI_SSE_EVENT_GLOBAL_PLAT_0_START      0x00004000
 #define SBI_SSE_EVENT_GLOBAL_PLAT_0_END                0x00007fff
 
 #define SBI_SSE_EVENT_LOCAL_PMU                        0x00010000
-#define        SBI_SSE_EVENT_LOCAL_PLAT_1_START        0x00014000
+#define SBI_SSE_EVENT_LOCAL_PLAT_1_START       0x00014000
 #define SBI_SSE_EVENT_LOCAL_PLAT_1_END         0x00017fff
-#define        SBI_SSE_EVENT_GLOBAL_PLAT_1_START       0x0001c000
+#define SBI_SSE_EVENT_GLOBAL_PLAT_1_START      0x0001c000
 #define SBI_SSE_EVENT_GLOBAL_PLAT_1_END                0x0001ffff
 
-#define        SBI_SSE_EVENT_LOCAL_PLAT_2_START        0x00024000
+#define SBI_SSE_EVENT_LOCAL_PLAT_2_START       0x00024000
 #define SBI_SSE_EVENT_LOCAL_PLAT_2_END         0x00027fff
-#define        SBI_SSE_EVENT_GLOBAL_PLAT_2_START       0x0002c000
+#define SBI_SSE_EVENT_GLOBAL_PLAT_2_START      0x0002c000
 #define SBI_SSE_EVENT_GLOBAL_PLAT_2_END                0x0002ffff
 
 #define SBI_SSE_EVENT_LOCAL_SOFTWARE           0xffff0000
-#define        SBI_SSE_EVENT_LOCAL_PLAT_3_START        0xffff4000
+#define SBI_SSE_EVENT_LOCAL_PLAT_3_START       0xffff4000
 #define SBI_SSE_EVENT_LOCAL_PLAT_3_END         0xffff7fff
 #define SBI_SSE_EVENT_GLOBAL_SOFTWARE          0xffff8000
-#define        SBI_SSE_EVENT_GLOBAL_PLAT_3_START       0xffffc000
+#define SBI_SSE_EVENT_GLOBAL_PLAT_3_START      0xffffc000
 #define SBI_SSE_EVENT_GLOBAL_PLAT_3_END                0xffffffff
 
 #define SBI_SSE_EVENT_GLOBAL_BIT               (1 << 15)
lib/sbi/sbi_sse.c +11 -12
index a686692..39b4588 100644
@@ -128,7 +128,7 @@ struct sse_hart_state {
         *
         * When an event is in a state >= ENABLED, then it is inserted in the
         * this enabled_event_list and thus can only be removed from this
-        * list upon disable ecall or on complete with ONE_SHOT flag.
+        * list upon disable ecall or on complete with ONESHOT flag.
         */
        struct sbi_dlist enabled_event_list;
 
@@ -202,7 +202,7 @@ static struct sse_hart_state *sse_get_hart_state(struct sbi_sse_event *e)
        return sse_get_hart_state_ptr(s);
 }
 
-static struct sse_global_event *sse_get_global_event(struct sbi_sse_event* e)
+static struct sse_global_event *sse_get_global_event(struct sbi_sse_event *e)
 {
        return container_of(e, struct sse_global_event, event);
 }
@@ -552,11 +552,11 @@ static bool sse_event_check_inject(struct sbi_sse_event *e,
                                   struct sbi_trap_regs *regs)
 {
        /*
-       * List of event is ordered by priority, stop at first running
-       * event since all other events after this one are of lower
-       * priority. This means an event of higher priority is already
-       * running.
-       */
+        * List of event is ordered by priority, stop at first running
+        * event since all other events after this one are of lower
+        * priority. This means an event of higher priority is already
+        * running.
+        */
        if (sse_event_state(e) == SBI_SSE_STATE_RUNNING) {
                return true;
        }
@@ -882,10 +882,10 @@ int sbi_sse_read_attrs(uint32_t event_id, uint32_t base_attr_id,
 
        /*
         * Copy all attributes at once since struct sse_event_attrs is matching
-        * the SBI_SSE_ATTR_* attributes. While WRITE_ATTR attribute is not used
-        * in s-mode sse handling path, READ_ATTR is used to retrieve the value
-        * of registers when interrupted. Rather than doing multiple SBI calls,
-        * a single one is done allowing to retrieve them all at once.
+        * the SBI_SSE_ATTR_* attributes. READ_ATTR is used in SSE handling path
+        * to retrieve the value of registers when interrupted. Rather than
+        * doing multiple SBI calls a single one is done allowing to retrieve
+        * them all at once.
         */
        e_attrs = (unsigned long *)&e->attrs;
        attrs = (unsigned long *)output_phys_lo;
--

2.43.0

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

#3 lore raw

PATCH 2/7 lib: sbi: sse: rename sse_hart_unlock() to sse_enabled_event_unlock()

In reply to Clément Léger

There was a naming incoherency between enabled events list lock/unlock. Rename sse_hart_unlock() to sse_enabled_event_unlock() to be coherent and reword comments above lock()/unlock() functions.

---
 lib/sbi/sbi_sse.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/sbi/sbi_sse.c +5 -5
index 39b4588..d54c125 100644
@@ -208,7 +208,7 @@ static struct sse_global_event *sse_get_global_event(struct sbi_sse_event *e)
 }
 
 /**
- * If event is global, must be called under global event lock
+ * If event is global, must be called under enabled event lock
  */
 static void sse_enabled_event_lock(struct sbi_sse_event *e)
 {
@@ -219,9 +219,9 @@ static void sse_enabled_event_lock(struct sbi_sse_event *e)
 }
 
 /**
- * If event is global, must be called under global event lock
+ * If event is global, must be called under enabled event lock
  */
-static void sse_hart_unlock(struct sbi_sse_event *e)
+static void sse_enabled_event_unlock(struct sbi_sse_event *e)
 {
 	struct sse_hart_state *shs;
 
@@ -753,7 +753,7 @@ int sbi_sse_enable(uint32_t event_id)
 
 	sse_enabled_event_lock(e);
 	ret = sse_event_enable(e);
-	sse_hart_unlock(e);
+	sse_enabled_event_unlock(e);
 	sse_event_put(e);
 
 	return ret;
@@ -770,7 +770,7 @@ int sbi_sse_disable(uint32_t event_id)
 
 	sse_enabled_event_lock(e);
 	ret = sse_event_disable(e);
-	sse_hart_unlock(e);
+	sse_enabled_event_unlock(e);
 
 	sse_event_put(e);
 
Signature · 1 line
2.43.0
#4 lore raw

PATCH 2/7 lib: sbi: sse: rename sse_hart_unlock() to sse_enabled_event_unlock()

Quoted 6 lines · On Tue, Apr 9, 2024 at 3:32?PM Cl?ment L?ger <[email protected]> wrote:

There was a naming incoherency between enabled events list lock/unlock. Rename sse_hart_unlock() to sse_enabled_event_unlock() to be coherent and reword comments above lock()/unlock() functions.

LGTM.

Regards,
Anup

Quoted 50 lines
---
 lib/sbi/sbi_sse.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/sbi/sbi_sse.c +5 -6
index 39b4588..d54c125 100644
@@ -208,7 +208,7 @@ static struct sse_global_event *sse_get_global_event(struct sbi_sse_event *e)
 }
 
 /**
- * If event is global, must be called under global event lock
+ * If event is global, must be called under enabled event lock
  */
 static void sse_enabled_event_lock(struct sbi_sse_event *e)
 {
@@ -219,9 +219,9 @@ static void sse_enabled_event_lock(struct sbi_sse_event *e)
 }
 
 /**
- * If event is global, must be called under global event lock
+ * If event is global, must be called under enabled event lock
  */
-static void sse_hart_unlock(struct sbi_sse_event *e)
+static void sse_enabled_event_unlock(struct sbi_sse_event *e)
 {
        struct sse_hart_state *shs;
 
@@ -753,7 +753,7 @@ int sbi_sse_enable(uint32_t event_id)
 
        sse_enabled_event_lock(e);
        ret = sse_event_enable(e);
-       sse_hart_unlock(e);
+       sse_enabled_event_unlock(e);
        sse_event_put(e);
 
        return ret;
@@ -770,7 +770,7 @@ int sbi_sse_disable(uint32_t event_id)
 
        sse_enabled_event_lock(e);
        ret = sse_event_disable(e);
-       sse_hart_unlock(e);
+       sse_enabled_event_unlock(e);
 
        sse_event_put(e);
 
--

2.43.0

#5 lore raw

PATCH 3/7 lib: sbi: sse: simplify 32bits overflow check

In reply to Clément Léger

Rather than checking 32bits overflow with some absolute value, check the value to be different from the cast itself.

---
 lib/sbi/sbi_sse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sbi/sbi_sse.c +1 -1
index d54c125..cd8a539 100644
@@ -344,7 +344,7 @@ static int sse_event_set_attr_check(struct sbi_sse_event *e, uint32_t attr_id,
 		break;
 	case SBI_SSE_ATTR_PRIO:
 #if __riscv_xlen > 32
-		if (val > 0xFFFFFFFFUL) {
+		if (val != (uint32_t)val) {
 			ret = SBI_EINVAL;
 			break;
 		}
Signature · 1 line
2.43.0
#6 lore raw

PATCH 3/7 lib: sbi: sse: simplify 32bits overflow check

Quoted 6 lines · On Tue, Apr 9, 2024 at 3:32?PM Cl?ment L?ger <[email protected]> wrote:

Rather than checking 32bits overflow with some absolute value, check the value to be different from the cast itself.

LGTM.

Regards,
Anup

Quoted 25 lines
---
 lib/sbi/sbi_sse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sbi/sbi_sse.c +1 -2
index d54c125..cd8a539 100644
@@ -344,7 +344,7 @@ static int sse_event_set_attr_check(struct sbi_sse_event *e, uint32_t attr_id,
                break;
        case SBI_SSE_ATTR_PRIO:
 #if __riscv_xlen > 32
-               if (val > 0xFFFFFFFFUL) {
+               if (val != (uint32_t)val) {
                        ret = SBI_EINVAL;
                        break;
                }
--

2.43.0

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

#7 lore raw

PATCH 4/7 lib: sbi: sse: remove superfluous sbi_list_empty() check

In reply to Clément Léger

The list loop below that check is actually not looping if the list is empty so there was no need for this check.

---
 lib/sbi/sbi_sse.c | 3 ---
 1 file changed, 3 deletions(-)
lib/sbi/sbi_sse.c +0 -3
index cd8a539..61d1f78 100644
@@ -578,9 +578,6 @@ void sbi_sse_process_pending_events(struct sbi_trap_regs *regs)
 
 	spin_lock(&state->enabled_event_lock);
 
-	if (sbi_list_empty(&state->enabled_event_list))
-		goto out;
-
 	sbi_list_for_each_entry(e, &state->enabled_event_list, node) {
 		ret = sse_event_check_inject(e, regs);
 		if (ret)
Signature · 1 line
2.43.0
#8 lore raw

PATCH 4/7 lib: sbi: sse: remove superfluous sbi_list_empty() check

Quoted 6 lines · On Tue, Apr 9, 2024 at 3:32?PM Cl?ment L?ger <[email protected]> wrote:

The list loop below that check is actually not looping if the list is empty so there was no need for this check.

LGTM.

Regards,
Anup

Quoted 26 lines
---
 lib/sbi/sbi_sse.c | 3 ---
 1 file changed, 3 deletions(-)
lib/sbi/sbi_sse.c +0 -4
index cd8a539..61d1f78 100644
@@ -578,9 +578,6 @@ void sbi_sse_process_pending_events(struct sbi_trap_regs *regs)
 
        spin_lock(&state->enabled_event_lock);
 
-       if (sbi_list_empty(&state->enabled_event_list))
-               goto out;
-
        sbi_list_for_each_entry(e, &state->enabled_event_list, node) {
                ret = sse_event_check_inject(e, regs);
                if (ret)
--

2.43.0

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

#9 lore raw

PATCH 5/7 lib: sbi: sse: call enable callback before sending IPI

In reply to Clément Léger

Move the enable callback call before sending the IPI. Even though the event is locked and no race condition can happen, this is more logical.

---
 lib/sbi/sbi_sse.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/sbi/sbi_sse.c +3 -3
index 61d1f78..8b448bf 100644
@@ -686,12 +686,12 @@ static int sse_event_enable(struct sbi_sse_event *e)
 	sse_event_set_state(e, SBI_SSE_STATE_ENABLED);
 	sse_event_add_to_list(e);
 
-	if (sse_event_pending(e))
+	sse_event_invoke_cb(e, enable_cb);
+
+	if (sse_event_is_global(e) && sse_event_pending(e))
 		sbi_ipi_send_many(1, e->attrs.hartid, sse_ipi_inject_event,
 				  NULL);
 
-	sse_event_invoke_cb(e, enable_cb);
-
 	return SBI_OK;
 }
 
Signature · 1 line
2.43.0
#10 lore raw

PATCH 5/7 lib: sbi: sse: call enable callback before sending IPI

Quoted 6 lines · On Tue, Apr 9, 2024 at 3:32?PM Cl?ment L?ger <[email protected]> wrote:

Move the enable callback call before sending the IPI. Even though the event is locked and no race condition can happen, this is more logical.

LGTM.

Regards,
Anup

Quoted 32 lines
---
 lib/sbi/sbi_sse.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/sbi/sbi_sse.c +3 -4
index 61d1f78..8b448bf 100644
@@ -686,12 +686,12 @@ static int sse_event_enable(struct sbi_sse_event *e)
        sse_event_set_state(e, SBI_SSE_STATE_ENABLED);
        sse_event_add_to_list(e);
 
-       if (sse_event_pending(e))
+       sse_event_invoke_cb(e, enable_cb);
+
+       if (sse_event_is_global(e) && sse_event_pending(e))
                sbi_ipi_send_many(1, e->attrs.hartid, sse_ipi_inject_event,
                                  NULL);
 
-       sse_event_invoke_cb(e, enable_cb);
-
        return SBI_OK;
 }
 
--

2.43.0

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

#11 lore raw

PATCH 6/7 lib: sbi: sse: use PRV_S instead of hardcoded value for mode

In reply to Clément Léger

Rather then passing 1 to sbi_domain_check_addr_range() for supervisor mode, use PRV_S.

---
 lib/sbi/sbi_sse.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/sbi/sbi_sse.c +2 -2
index 8b448bf..85137c2 100644
@@ -837,8 +837,8 @@ int sbi_sse_attr_check(uint32_t base_attr_id, uint32_t attr_count,
 		return SBI_EINVALID_ADDR;
 
 	if (!sbi_domain_check_addr_range(sbi_domain_thishart_ptr(), phys_lo,
-					 sizeof(unsigned long) * attr_count, 1,
-					 access))
+					 sizeof(unsigned long) * attr_count,
+					 PRV_S, access))
 		return SBI_EINVALID_ADDR;
 
 	return SBI_OK;
Signature · 1 line
2.43.0
#12 lore raw

PATCH 6/7 lib: sbi: sse: use PRV_S instead of hardcoded value for mode

Quoted 5 lines · On Tue, Apr 9, 2024 at 3:32?PM Cl?ment L?ger <[email protected]> wrote:

Rather then passing 1 to sbi_domain_check_addr_range() for supervisor mode, use PRV_S.

LGTM.

Regards,
Anup

Quoted 27 lines
---
 lib/sbi/sbi_sse.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/sbi/sbi_sse.c +2 -3
index 8b448bf..85137c2 100644
@@ -837,8 +837,8 @@ int sbi_sse_attr_check(uint32_t base_attr_id, uint32_t attr_count,
                return SBI_EINVALID_ADDR;
 
        if (!sbi_domain_check_addr_range(sbi_domain_thishart_ptr(), phys_lo,
-                                        sizeof(unsigned long) * attr_count, 1,
-                                        access))
+                                        sizeof(unsigned long) * attr_count,
+                                        PRV_S, access))
                return SBI_EINVALID_ADDR;
 
        return SBI_OK;
--

2.43.0

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

#13 lore raw

PATCH 7/7 lib: sbi: sse: check handler entry to belong to supervisor mode

In reply to Clément Léger

When registering an SSE event, check for the handler_entry_pc to belong to supervisor mode domain using sbi_domain_check_addr_range().

---
 lib/sbi/sbi_sse.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/sbi/sbi_sse.c +6 -0
index 85137c2..8724f76 100644
@@ -959,6 +959,12 @@ int sbi_sse_register(uint32_t event_id, unsigned long handler_entry_pc,
 	if (handler_entry_pc & 0x1)
 		return SBI_EINVAL;
 
+	if (!sbi_domain_check_addr_range(sbi_domain_thishart_ptr(),
+					 handler_entry_pc,
+					 sizeof(unsigned long), PRV_S,
+					 SBI_DOMAIN_EXECUTE))
+		return SBI_EINVALID_ADDR;
+
 	e = sse_event_get(event_id);
 	if (!e)
 		return SBI_EINVAL;
Signature · 1 line
2.43.0
#14 lore raw

PATCH 7/7 lib: sbi: sse: check handler entry to belong to supervisor mode

Quoted 6 lines · On Tue, Apr 9, 2024 at 3:32?PM Cl?ment L?ger <[email protected]> wrote:

When registering an SSE event, check for the handler_entry_pc to belong to supervisor mode domain using sbi_domain_check_addr_range().

LGTM.

Regards,
Anup

Quoted 29 lines
---
 lib/sbi/sbi_sse.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/sbi/sbi_sse.c +6 -1
index 85137c2..8724f76 100644
@@ -959,6 +959,12 @@ int sbi_sse_register(uint32_t event_id, unsigned long handler_entry_pc,
        if (handler_entry_pc & 0x1)
                return SBI_EINVAL;
 
+       if (!sbi_domain_check_addr_range(sbi_domain_thishart_ptr(),
+                                        handler_entry_pc,
+                                        sizeof(unsigned long), PRV_S,
+                                        SBI_DOMAIN_EXECUTE))
+               return SBI_EINVALID_ADDR;
+
        e = sse_event_get(event_id);
        if (!e)
                return SBI_EINVAL;
--

2.43.0

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

Applied
#15 lore raw

cover lib: sbi: sse: fixes after review

In reply to Clément Léger
Quoted 4 lines · On Tue, Apr 9, 2024 at 3:32?PM Cl?ment L?ger <[email protected]> wrote:

This small series addresses a few comments from Samuel that were made after the series was merged.

Quoted 8 lines

Cl?ment L?ger (7):
lib: sbi: sse: fix typos, comments and spacing errors
lib: sbi: sse: rename sse_hart_unlock() to sse_enabled_event_unlock()
lib: sbi: sse: simplify 32bits overflow check
lib: sbi: sse: remove superfluous sbi_list_empty() check
lib: sbi: sse: call enable callback before sending IPI
lib: sbi: sse: use PRV_S instead of hardcoded value for mode
lib: sbi: sse: check handler entry to belong to supervisor mode

Applied this series to the riscv/opensbi repo.

Thanks,
Anup

Quoted 13 lines
 include/sbi/sbi_ecall_interface.h | 24 +++++++-------
 lib/sbi/sbi_sse.c                 | 53 ++++++++++++++++---------------
 2 files changed, 40 insertions(+), 37 deletions(-)

--
2.43.0

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