Skip to contentSkip to conversation

Add support for Supervisor Software Events extension

RFC PATCH Superseded Clément Léger 4 participants 6 messages Nov 30, 2023 – Dec 5, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Add support for Supervisor Software Events extension

The SBI Supervisor Software Events (SSE) extensions provides a mechanism to inject software events from an SBI implementation to supervisor software such that it preempts all other supervisor level traps and interrupts [1].

Various events are defined and can be send asynchronously to supervisor software (RAS, PMU, DEBUG, Asynchronous page fault) from SBI as well as platform specific events. Events can be either local (per-hart) or global. Events can be nested on top of each other based on priority and can interrupt the supervisor mode at any time.

This PR adds support for this extension. First commit modifies interrupts handling to pass the sbi traps regs through interrupt handlers in order to inject SSE events from this context. Second one add the SSE support itself.

A RFC for Linux which uses this extension is available at [2].

Cl?ment L?ger (2):
lib: sbi: provides regs to sbi_ipi_process()
lib: sbi: add support for Supervisor Software Events extension

 include/sbi/sbi_ecall_interface.h |  36 +-
 include/sbi/sbi_error.h           |   4 +
 include/sbi/sbi_ipi.h             |   6 +-
 include/sbi/sbi_sse.h             | 222 +++++++
 lib/sbi/Kconfig                   |   4 +
 lib/sbi/objects.mk                |   4 +
 lib/sbi/sbi_ecall.c               |   7 +-
 lib/sbi/sbi_ecall_sse.c           |  61 ++
 lib/sbi/sbi_init.c                |  13 +
 lib/sbi/sbi_ipi.c                 |  12 +-
 lib/sbi/sbi_sse.c                 | 963 ++++++++++++++++++++++++++++++
 lib/sbi/sbi_tlb.c                 |   2 +-
 lib/sbi/sbi_trap.c                |   4 +-
 lib/utils/irqchip/imsic.c         |   2 +-
 14 files changed, 1327 insertions(+), 13 deletions(-)
 create mode 100644 include/sbi/sbi_sse.h
 create mode 100644 lib/sbi/sbi_ecall_sse.c
 create mode 100644 lib/sbi/sbi_sse.c
Signature · 1 line
2.42.0
#1 lore raw

RFC PATCH 1/2 lib: sbi: provides regs to sbi_ipi_process()

In order to implement SSE on IPI notifications, provides regs to sbi_ipi_process(). This will be used in two cases, global event triggered from one cpu to another and ipi injection to a specific hart.

---
 include/sbi/sbi_ipi.h     |  6 ++++--
 lib/sbi/sbi_ipi.c         | 12 +++++++-----
 lib/sbi/sbi_tlb.c         |  2 +-
 lib/sbi/sbi_trap.c        |  4 ++--
 lib/utils/irqchip/imsic.c |  2 +-
 5 files changed, 15 insertions(+), 11 deletions(-)
include/sbi/sbi_ipi.h +4 -2
index d396233..0b32194 100644
@@ -11,6 +11,7 @@
 #define __SBI_IPI_H__
 
 #include <sbi/sbi_types.h>
+#include <sbi/sbi_trap.h>
 
 /* clang-format off */
 
@@ -68,7 +69,8 @@ struct sbi_ipi_event_ops {
 	 * Note: This is a mandatory callback and it is called on the
 	 * remote HART after IPI is triggered.
 	 */
-	void (* process)(struct sbi_scratch *scratch);
+	void (* process)(struct sbi_scratch *scratch,
+			 struct sbi_trap_regs *regs);
 };
 
 int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data);
@@ -83,7 +85,7 @@ void sbi_ipi_clear_smode(void);
 
 int sbi_ipi_send_halt(ulong hmask, ulong hbase);
 
-void sbi_ipi_process(void);
+void sbi_ipi_process(struct sbi_trap_regs *regs);
 
 int sbi_ipi_raw_send(u32 hartindex);
 
lib/sbi/sbi_ipi.c +7 -5
index 0bf446a..7fa6113 100644
@@ -170,7 +170,8 @@ void sbi_ipi_event_destroy(u32 event)
 	ipi_ops_array[event] = NULL;
 }
 
-static void sbi_ipi_process_smode(struct sbi_scratch *scratch)
+static void sbi_ipi_process_smode(struct sbi_scratch *scratch,
+				  struct sbi_trap_regs *regs)
 {
 	csr_set(CSR_MIP, MIP_SSIP);
 }
@@ -192,7 +193,8 @@ void sbi_ipi_clear_smode(void)
 	csr_clear(CSR_MIP, MIP_SSIP);
 }
 
-static void sbi_ipi_process_halt(struct sbi_scratch *scratch)
+static void sbi_ipi_process_halt(struct sbi_scratch *scratch,
+				 struct sbi_trap_regs *regs)
 {
 	sbi_hsm_hart_stop(scratch, true);
 }
@@ -209,7 +211,7 @@ int sbi_ipi_send_halt(ulong hmask, ulong hbase)
 	return sbi_ipi_send_many(hmask, hbase, ipi_halt_event, NULL);
 }
 
-void sbi_ipi_process(void)
+void sbi_ipi_process(struct sbi_trap_regs *regs)
 {
 	unsigned long ipi_type;
 	unsigned int ipi_event;
@@ -228,7 +230,7 @@ void sbi_ipi_process(void)
 		if (ipi_type & 1UL) {
 			ipi_ops = ipi_ops_array[ipi_event];
 			if (ipi_ops && ipi_ops->process)
-				ipi_ops->process(scratch);
+				ipi_ops->process(scratch, regs);
 		}
 		ipi_type = ipi_type >> 1;
 		ipi_event++;
@@ -333,7 +335,7 @@ void sbi_ipi_exit(struct sbi_scratch *scratch)
 	csr_clear(CSR_MIE, MIP_MSIP);
 
 	/* Process pending IPIs */
-	sbi_ipi_process();
+	sbi_ipi_process(NULL);
 
 	/* Platform exit */
 	sbi_platform_ipi_exit(sbi_platform_ptr(scratch));
lib/sbi/sbi_tlb.c +1 -1
index dad9508..80e7bdf 100644
@@ -229,7 +229,7 @@ static bool tlb_process_once(struct sbi_scratch *scratch)
 	return false;
 }
 
-static void tlb_process(struct sbi_scratch *scratch)
+static void tlb_process(struct sbi_scratch *scratch, struct sbi_trap_regs *regs)
 {
 	while (tlb_process_once(scratch));
 }
lib/sbi/sbi_trap.c +2 -2
index dbf307c..d574ab1 100644
@@ -206,7 +206,7 @@ static int sbi_trap_nonaia_irq(struct sbi_trap_regs *regs, ulong mcause)
 		sbi_timer_process();
 		break;
 	case IRQ_M_SOFT:
-		sbi_ipi_process();
+		sbi_ipi_process(regs);
 		break;
 	case IRQ_M_EXT:
 		return sbi_irqchip_process(regs);
@@ -229,7 +229,7 @@ static int sbi_trap_aia_irq(struct sbi_trap_regs *regs, ulong mcause)
 			sbi_timer_process();
 			break;
 		case IRQ_M_SOFT:
-			sbi_ipi_process();
+			sbi_ipi_process(regs);
 			break;
 		case IRQ_M_EXT:
 			rc = sbi_irqchip_process(regs);
lib/utils/irqchip/imsic.c +1 -1
index 36ef66c..a207dbc 100644
@@ -149,7 +149,7 @@ static int imsic_external_irqfn(struct sbi_trap_regs *regs)
 
 		switch (mirq) {
 		case IMSIC_IPI_ID:
-			sbi_ipi_process();
+			sbi_ipi_process(regs);
 			break;
 		default:
 			sbi_printf("%s: unhandled IRQ%d\n",
Signature · 1 line
2.42.0
#2 lore raw

RFC PATCH 2/2 lib: sbi: add support for Supervisor Software Events extension

In reply to Clément Léger

This extension [1] allows to deliver events from SBI to supervisor via a software mecanism. This extensions defines events (either local or global) which are signaled by the SBI on specific signal sources (IRQ, traps, etc) and are injected to be executed in supervisor mode.

[1] https://lists.riscv.org/g/tech-prs/message/515

---
 include/sbi/sbi_ecall_interface.h |  36 +-
 include/sbi/sbi_error.h           |   4 +
 include/sbi/sbi_sse.h             | 222 +++++++
 lib/sbi/Kconfig                   |   4 +
 lib/sbi/objects.mk                |   4 +
 lib/sbi/sbi_ecall.c               |   7 +-
 lib/sbi/sbi_ecall_sse.c           |  61 ++
 lib/sbi/sbi_init.c                |  13 +
 lib/sbi/sbi_sse.c                 | 963 ++++++++++++++++++++++++++++++
 9 files changed, 1312 insertions(+), 2 deletions(-)
 create mode 100644 include/sbi/sbi_sse.h
 create mode 100644 lib/sbi/sbi_ecall_sse.c
 create mode 100644 lib/sbi/sbi_sse.c
include/sbi/sbi_ecall_interface.h +35 -1
index 1fe469e..f510039 100644
@@ -32,6 +32,7 @@
 #define SBI_EXT_DBCN				0x4442434E
 #define SBI_EXT_SUSP				0x53555350
 #define SBI_EXT_CPPC				0x43505043
+#define SBI_EXT_SSE				0x535345
 
 /* SBI function IDs for BASE extension*/
 #define SBI_EXT_BASE_GET_SPEC_VERSION		0x0
@@ -290,6 +291,36 @@ enum sbi_cppc_reg_id {
 	SBI_CPPC_NON_ACPI_LAST		= SBI_CPPC_TRANSITION_LATENCY,
 };
 
+/* SBI Function IDs for SSE extension */
+#define SBI_EXT_SSE_GET_ATTR		0x00000000
+#define SBI_EXT_SSE_SET_ATTR		0x00000001
+#define SBI_EXT_SSE_REGISTER		0x00000002
+#define SBI_EXT_SSE_UNREGISTER		0x00000003
+#define SBI_EXT_SSE_ENABLE		0x00000004
+#define SBI_EXT_SSE_DISABLE		0x00000005
+#define SBI_EXT_SSE_COMPLETE		0x00000006
+#define SBI_EXT_SSE_INJECT		0x00000007
+
+/* SBI SSE Event Attributes. */
+#define SBI_SSE_ATTR_STATE		0x00000000
+#define SBI_SSE_ATTR_PRIO		0x00000001
+#define SBI_SSE_ATTR_ALLOW_INJECT	0x00000002
+#define SBI_SSE_ATTR_HART_ID		0x00000003
+#define SBI_SSE_ATTR_PENDING		0x00000004
+
+/* SBI SSE Event IDs. */
+#define SBI_SSE_EVENT_LOCAL_RAS		0x00000000
+#define SBI_SSE_EVENT_GLOBAL_RAS	0x00008000
+#define SBI_SSE_EVENT_LOCAL_ASYNC_PF	0x00010000
+#define SBI_SSE_EVENT_LOCAL_PMU		0x00010001
+#define SBI_SSE_EVENT_LOCAL_DEBUG      	0xffff3fff
+#define SBI_SSE_EVENT_GLOBAL_DEBUG	0xffffbfff
+
+#define SBI_SSE_EVENT_GLOBAL		(1 << 15)
+#define SBI_SSE_EVENT_PLATFORM		(1 << 14)
+
+#define SBI_SSE_COMPLETE_FLAG_EVENT_DISABLE	(1 << 0)
+
 /* SBI base specification related macros */
 #define SBI_SPEC_VERSION_MAJOR_OFFSET		24
 #define SBI_SPEC_VERSION_MAJOR_MASK		0x7f
@@ -309,8 +340,11 @@ enum sbi_cppc_reg_id {
 #define SBI_ERR_ALREADY_AVAILABLE		-6
 #define SBI_ERR_ALREADY_STARTED			-7
 #define SBI_ERR_ALREADY_STOPPED			-8
+#define SBI_ERR_INVALID_STATE			-10
+#define SBI_ERR_BAD_RANGE			-11
+#define SBI_ERR_BUSY				-12
 
-#define SBI_LAST_ERR				SBI_ERR_ALREADY_STOPPED
+#define SBI_LAST_ERR				SBI_ERR_BUSY
 
 /* clang-format on */
 
include/sbi/sbi_error.h +4 -0
index dd65e14..3cff248 100644
@@ -23,6 +23,9 @@
 #define SBI_EALREADY		SBI_ERR_ALREADY_AVAILABLE
 #define SBI_EALREADY_STARTED	SBI_ERR_ALREADY_STARTED
 #define SBI_EALREADY_STOPPED	SBI_ERR_ALREADY_STOPPED
+#define SBI_EINVALID_STATE	SBI_ERR_INVALID_STATE
+#define SBI_EBAD_RANGE		SBI_ERR_BAD_RANGE
+#define SBI_EBUSY		SBI_ERR_BUSY
 
 #define SBI_ENODEV		-1000
 #define SBI_ENOSYS		-1001
@@ -34,6 +37,7 @@
 #define SBI_ETRAP		-1007
 #define SBI_EUNKNOWN		-1008
 #define SBI_ENOENT		-1009
+#define SBI_EJUMP		-1010
 
 /* clang-format on */
 
include/sbi/sbi_sse.h new file +222 -0

222 lines not on this page · raw message

lib/sbi/Kconfig +4 -0
index 477775e..1b713e9 100644
@@ -46,4 +46,8 @@ config SBI_ECALL_VENDOR
 	bool "Platform-defined vendor extensions"
 	default y
 
+config SBI_ECALL_SSE
+       bool "SSE extension"
+       default y
+
 endmenu
lib/sbi/objects.mk +4 -0
index c699187..011c824 100644
@@ -52,6 +52,9 @@ libsbi-objs-$(CONFIG_SBI_ECALL_LEGACY) += sbi_ecall_legacy.o
 carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_VENDOR) += ecall_vendor
 libsbi-objs-$(CONFIG_SBI_ECALL_VENDOR) += sbi_ecall_vendor.o
 
+carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_SSE) += ecall_sse
+libsbi-objs-$(CONFIG_SBI_ECALL_SSE) += sbi_ecall_sse.o
+
 libsbi-objs-y += sbi_bitmap.o
 libsbi-objs-y += sbi_bitops.o
 libsbi-objs-y += sbi_console.o
@@ -71,6 +74,7 @@ libsbi-objs-y += sbi_misaligned_ldst.o
 libsbi-objs-y += sbi_platform.o
 libsbi-objs-y += sbi_pmu.o
 libsbi-objs-y += sbi_scratch.o
+libsbi-objs-y += sbi_sse.o
 libsbi-objs-y += sbi_string.o
 libsbi-objs-y += sbi_system.o
 libsbi-objs-y += sbi_timer.o
lib/sbi/sbi_ecall.c +6 -1
index 3eb4f0a..e7c1d1b 100644
@@ -116,7 +116,12 @@ int sbi_ecall_handler(struct sbi_trap_regs *regs)
 		ret = SBI_ENOTSUPP;
 	}
 
-	if (ret == SBI_ETRAP) {
+	if (ret == SBI_EJUMP) {
+		/* We don't want to modify register content since they could
+		 * have been modified by the handler.
+		 */
+		return 0;
+	} else if (ret == SBI_ETRAP) {
 		trap.epc = regs->mepc;
 		sbi_trap_redirect(regs, &trap);
 	} else {
lib/sbi/sbi_ecall_sse.c new file +61 -0

61 lines not on this page · raw message

lib/sbi/sbi_init.c +13 -0
index e723553..5aa9992 100644
@@ -23,6 +23,7 @@
 #include <sbi/sbi_irqchip.h>
 #include <sbi/sbi_platform.h>
 #include <sbi/sbi_pmu.h>
+#include <sbi/sbi_sse.h>
 #include <sbi/sbi_system.h>
 #include <sbi/sbi_string.h>
 #include <sbi/sbi_timer.h>
@@ -312,6 +313,12 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
 	if (rc)
 		sbi_hart_hang();
 
+        rc = sbi_sse_init(scratch, true);
+        if (rc) {
+                sbi_printf("%s: sse init failed (error %d)\n", __func__, rc);
+                sbi_hart_hang();
+        }
+
 	rc = sbi_pmu_init(scratch, true);
 	if (rc) {
 		sbi_printf("%s: pmu init failed (error %d)\n",
@@ -432,6 +439,10 @@ static void __noreturn init_warm_startup(struct sbi_scratch *scratch,
 	if (rc)
 		sbi_hart_hang();
 
+	rc = sbi_sse_init(scratch, false);
+	if (rc)
+		sbi_hart_hang();
+
 	rc = sbi_pmu_init(scratch, false);
 	if (rc)
 		sbi_hart_hang();
@@ -636,6 +647,8 @@ void __noreturn sbi_exit(struct sbi_scratch *scratch)
 
 	sbi_platform_early_exit(plat);
 
+	sbi_sse_exit(scratch);
+
 	sbi_pmu_exit(scratch);
 
 	sbi_timer_exit(scratch);
lib/sbi/sbi_sse.c new file +963 -0

963 lines not on this page · raw message

Signature · 1 line
2.42.0
#3 lore raw

RFC PATCH 2/2 lib: sbi: add support for Supervisor Software Events extension

? 2023-11-30???? 10:13 +0100?Cl?ment L?ger???

Quoted 10 lines

This extension [1] allows to deliver events from SBI to supervisor via a software mecanism. This extensions defines events (either local or global) which are signaled by the SBI on specific signal sources (IRQ, traps, etc) and are injected to be executed in supervisor mode.

[1] https://lists.riscv.org/g/tech-prs/message/515

---

include/sbi/sbi_sse.h line 176

Quoted 6 lines
include/sbi/sbi_sse.h new file +6 -0
+struct sbi_sse_cb_ops {
+	/**
+	 * Called when hart_id is changed on the event.
+	 */
+	void (*set_hartid_cb)(uint32_t event_id, unsigned long hart_id);
+

Maybe should add a callback before running. This callback can be used to? access sensitive resources, such as keys.

Quoted 13 lines
include/sbi/sbi_sse.h new file +13 -0
+	/**
+	 * Called when the SBI_EXT_SSE_COMPLETE is invoked on the event.
+	 */
+	void (*complete_cb)(uint32_t event_id);
+
+	/**
+	 * Called when the SBI_EXT_SSE_REGISTER is invoked on the event.
+	 */
+	void (*register_cb)(uint32_t event_id);
+
+	/**
+	 * Called when the SBI_EXT_SSE_UNREGISTER is invoked on the event.
+	 */

include/sbi/sbi_sse.h

Quoted 10 lines
include/sbi/sbi_sse.h new file +9 -0
+	void (*unregister_cb)(uint32_t event_id);
+};
+
 
+static void sse_event_set_state(struct sbi_sse_event *e,
+				enum sbi_sse_state new_state)
+{
+	enum sbi_sse_state prev_state = e->state;
+
+	e->state = new_state;

Do not change before checking.

Quoted 11 lines
lib/sbi/sbi_sse.c new file +11 -0
+	switch (new_state) {
+		case SSE_STATE_UNUSED:
+			if (prev_state == SSE_STATE_REGISTERED)
+				return;
+		break;
+		case SSE_STATE_REGISTERED:
+			if (prev_state == SSE_STATE_UNUSED ||
+			??? prev_state == SSE_STATE_ENABLED) {
+				return;
+			}
+		break;

lib/sbi/sbi_sse.c line 167

Quoted 10 lines
lib/sbi/sbi_sse.c new file +10 -0
+		case SSE_STATE_ENABLED:
+			if (prev_state == SSE_STATE_REGISTERED ||
+			??? prev_state == SSE_STATE_RUNNING)
+				return;
+		break;
+		case SSE_STATE_RUNNING:
+			if (prev_state == SSE_STATE_ENABLED)
+				return;
+		break;
+	}

This state machine is characterized by the difference between the old and new states being 1. So the code can be simplified as follows:

	if ((new_state - prev_state == 1) || (prev_state - new_state == 1)) {
		e->state = new_state;
		return;
	}
Quoted 33 lines
lib/sbi/sbi_sse.c new file +32 -0
+
+	sbi_panic("Invalid SSE state transition: %d -> %d\n", prev_state,
+		? new_state);
+}
+
 
+
+static int sse_event_set_hart_id(struct sbi_sse_event *e, uint32_t event_id,
+				 unsigned long new_hartid)
+{
+	int hstate;
+	unsigned int hartid = (uint32_t) new_hartid;
+	struct sbi_domain * hd = sbi_domain_thishart_ptr();
+
+	if (!sse_event_is_global(e))
+		return SBI_EDENIED;
+
+	if (e->state == SSE_STATE_RUNNING)
+		return SBI_EBUSY;
+
+	if (!sbi_domain_is_assigned_hart(hd, new_hartid))
+		return SBI_EINVAL;
+
+	hstate = sbi_hsm_hart_get_state(hd, hartid);
+	if (hstate != SBI_HSM_STATE_STARTED)
+		return SBI_EINVAL;
+
+	if (new_hartid == e->hartid)
+		return SBI_OK;
+
+	if (e->state >= SSE_STATE_ENABLED)
+		sse_event_remove_from_list(e);
+

lib/sbi/sbi_sse.c line 306

Quoted 10 lines
lib/sbi/sbi_sse.c new file +10 -0
+	e->hartid = hartid;
+
+	if (e->cb_ops && e->cb_ops->set_hartid_cb)
+		 e->cb_ops->set_hartid_cb(event_id, e->hartid);
+
+	if (e->state >= SSE_STATE_ENABLED)
+		sse_event_add_to_list(e);
+
+	if (e->pending)
+		sbi_ipi_send_many(BIT(e->hartid), 0, sse_ipi_inject_event, NULL);

hartid can't big then XLEN. change to:

		sbi_ipi_send_many(1, e->hartid, sse_ipi_inject_event, NULL);
Quoted 14 lines
lib/sbi/sbi_sse.c new file +13 -0
+
+	return 0;
+}
+
 
+
+static int sse_ipi_inject_send(unsigned long hartid, uint32_t event_id)
+{
+	int ret;
+	struct sbi_scratch *remote_scratch = NULL;
+	struct sse_ipi_inject_data evt = {event_id};
+	struct sbi_fifo *sse_inject_fifo_r;
+
+	remote_scratch = sbi_hartid_to_scratch(hartid);

lib/sbi/sbi_sse.c line 581

Quoted 10 lines
lib/sbi/sbi_sse.c new file +10 -0
+	if (!remote_scratch)
+		return SBI_EINVAL;
+	sse_inject_fifo_r = sbi_scratch_offset_ptr(remote_scratch,
+						?? sse_inject_fifo_off);
+
+	ret = sbi_fifo_enqueue(sse_inject_fifo_r, &evt);
+	if (ret)
+		return SBI_EFAIL;
+
+	ret = sbi_ipi_send_many(BIT(hartid), 0, sse_ipi_inject_event, NULL);

hartid can't big then XLEN. change to:

	ret = sbi_ipi_send_many(1, hartid, sse_ipi_inject_event, NULL);
Quoted 12 lines
lib/sbi/sbi_sse.c new file +7 -0
+	if (ret)
+		return SBI_EFAIL;
+
+	return SBI_OK;
+}
+
 
+}
Signature · 1 line
2.42.0

Regards,
Xiang W

#4 lore raw

cover Add support for Supervisor Software Events extension

In reply to Clément Léger
Quoted 11 lines · Cl?ment L?ger

The SBI Supervisor Software Events (SSE) extensions provides a mechanism to inject software events from an SBI implementation to supervisor software such that it preempts all other supervisor level traps and interrupts [1].

Various events are defined and can be send asynchronously to supervisor software (RAS, PMU, DEBUG, Asynchronous page fault) from SBI as well as platform specific events. Events can be either local (per-hart) or global. Events can be nested on top of each other based on priority and can interrupt the supervisor mode at any time.

Quoted 3 lines

This PR adds support for this extension. First commit modifies interrupts handling to pass the sbi traps regs through interrupt handlers in order to inject SSE events from this context. Second one add the SSE support itself.

Cross-posting my response from github

I've a general comment on design of SSE which interferes with security. This is kind of a TOCTOU issue between kernel (less priv) and opensbi (more priv)

If a control flow integrity scheme (software or hardware assisted) is implemented to ensure control safety of kernel indirect branches, then SSE provides a mechanism using an attacker can exercise free branches. I believe software base kCFI support for riscv is already in mainline.

During time of event registration, kernel provides physical address of context. This context structure acts as context to be used for event inject in S (and along with PC, SP and other registers) Context to be used where interrupted context of S will be saved away so that it can be restored later once injected event has finished its course This entire context buffer is mapped in kernel space and thus is vulnerable to memory corruption. If any CFI scheme is implemented, its expected that an attacker has "write what anywhere" bug. Thus this design allows an attacker to corrupt this context and use mechanisms to trigger events that will make M mode to inject events in kernel and thereby allowing free branches (which goes against CFI schemes ) in kernel.

Without understanding limitations of opensbi, I would like to propose a solution

During registration, opensbi makes a copy of context structure. Similarly interrupted context can also live in protected region in M mode memory Let me know what you think.

Quoted 32 lines

A RFC for Linux which uses this extension is available at [2].

Cl?ment L?ger (2):
lib: sbi: provides regs to sbi_ipi_process()
lib: sbi: add support for Supervisor Software Events extension

include/sbi/sbi_ecall_interface.h |  36 +-
include/sbi/sbi_error.h           |   4 +
include/sbi/sbi_ipi.h             |   6 +-
include/sbi/sbi_sse.h             | 222 +++++++
lib/sbi/Kconfig                   |   4 +
lib/sbi/objects.mk                |   4 +
lib/sbi/sbi_ecall.c               |   7 +-
lib/sbi/sbi_ecall_sse.c           |  61 ++
lib/sbi/sbi_init.c                |  13 +
lib/sbi/sbi_ipi.c                 |  12 +-
lib/sbi/sbi_sse.c                 | 963 ++++++++++++++++++++++++++++++
lib/sbi/sbi_tlb.c                 |   2 +-
lib/sbi/sbi_trap.c                |   4 +-
lib/utils/irqchip/imsic.c         |   2 +-
14 files changed, 1327 insertions(+), 13 deletions(-)

create mode 100644 include/sbi/sbi_sse.h
create mode 100644 lib/sbi/sbi_ecall_sse.c
create mode 100644 lib/sbi/sbi_sse.c

Signature · 1 line
2.42.0
#5 lore raw

cover Add support for Supervisor Software Events extension

In reply to Clément Léger
Quoted 12 lines · Cl?ment L?ger

The SBI Supervisor Software Events (SSE) extensions provides a mechanism to inject software events from an SBI implementation to supervisor software such that it preempts all other supervisor level traps and interrupts [1].

Various events are defined and can be send asynchronously to supervisor software (RAS, PMU, DEBUG, Asynchronous page fault) from SBI as well as platform specific events. Events can be either local (per-hart) or global. Events can be nested on top of each other based on priority and can interrupt the supervisor mode at any time.

Quoted 7 lines

This PR adds support for this extension. First commit modifies interrupts handling to pass the sbi traps regs through interrupt handlers in order to inject SSE events from this context. Second one add the SSE support itself.

A RFC for Linux which uses this extension is available at [2].

This is the proposal from many months ago which I objected to. Have there been any changes to the spec to not tie the SBI?s binary interface too closely to the ISA and preclude the existence of extensions that introduce new state SSE would need to save and restore? I was under the impression from your talk a few weeks ago at LPC, which even mentioned my comments explicitly, that was being worked on, yet here we are with a new patch that doesn?t change the spec one bit.

Jess