lib: sbi: fix PMU SSE event handling
cover lib: sbi: fix PMU SSE event handling
While reworking the Linux SSE support, it appears that the PMU event should not be available if the SSCOFPMF extension is not available since there would be no IRQ. The specification isn't really clear on that point so this is more like a RFC to check that. Ideally, the sse register call should allow to refuse registering an event if the dependencies are not satisfied but does not allow this yet.
Cl?ment L?ger (3):
lib: sbi: sse: Return a value from the register callback
lib: sbi: sse: Disable injection if callbacks are set
lib: sbi: pmu: Set a SSE register_cb() for event availability
include/sbi/sbi_sse.h | 2 +- lib/sbi/sbi_pmu.c | 11 +++++++++++ lib/sbi/sbi_sse.c | 19 +++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/3 lib: sbi: sse: Return a value from the register callback
Some events might not be available to registration due to missing dependencies (ISA extensions for instance). Return an 'int' from the register_cb() callback so that this can be handled.
--- include/sbi/sbi_sse.h | 2 +- lib/sbi/sbi_sse.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-)
include/sbi/sbi_sse.h +1 -1
@@ -36,7 +36,7 @@ struct sbi_sse_cb_ops {/** * Called when the SBI_EXT_SSE_REGISTER is invoked on the event. */ -void (*register_cb)(uint32_t event_id); +int (*register_cb)(uint32_t event_id);/** * Called when the SBI_EXT_SSE_UNREGISTER is invoked on the event.
lib/sbi/sbi_sse.c +14 -2
@@ -50,6 +50,15 @@ static const uint32_t supported_events[] = {#define EVENT_COUNT array_size(supported_events) +#define sse_event_invoke_cb_ret (_event, _cb, ...) \ + ({ \ + int __ret = 0; \ + if (_event->cb_ops && _event->cb_ops->_cb) \ + __ret = _event->cb_ops->_cb(_event->event_id, \ + ##__VA_ARGS__); \ + __ret; \ + }) +#define sse_event_invoke_cb (_event, _cb, ...) \ { \ if (_event->cb_ops && _event->cb_ops->_cb) \
@@ -423,16 +432,19 @@ static int sse_event_register(struct sbi_sse_event *e,unsigned long handler_entry_pc, unsigned long handler_entry_arg) { + int ret;if (sse_event_state (e) !=SBI_SSE_STATE_UNUSED )return SBI_EINVALID_STATE ; + ret =sse_event_invoke_cb_ret (e, register_cb); +if (ret) +return ret; + e->attrs.entry.pc = handler_entry_pc; e->attrs.entry.arg = handler_entry_arg;sse_event_set_state (e,SBI_SSE_STATE_REGISTERED ); -sse_event_invoke_cb (e, register_cb); -return 0 ; }
Signature · 1 line
2.45.2
PATCH 1/3 lib: sbi: sse: Return a value from the register callback
Quoted 56 lines · On Fri, Dec 6, 2024 at 1:00?PM Cl?ment L?ger <[email protected]> wrote:
Some events might not be available to registration due to missing dependencies (ISA extensions for instance). Return an 'int' from the
register_cb()callback so that this can be handled.Signed-off-by Cl?ment L?ger <[email protected]>--- include/sbi/sbi_sse.h | 2 +- lib/sbi/sbi_sse.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-)include/sbi/sbi_sse.h +1
-1@@ -36,7 +36,7 @@ struct sbi_sse_cb_ops {/** * Called when the SBI_EXT_SSE_REGISTER is invoked on the event. */ -void (*register_cb)(uint32_t event_id); +int (*register_cb)(uint32_t event_id);/** * Called when the SBI_EXT_SSE_UNREGISTER is invoked on the event. lib/sbi/sbi_sse.c +14
-0@@ -50,6 +50,15 @@ static const uint32_t supported_events[] = {#define EVENT_COUNT array_size(supported_events) +#define sse_event_invoke_cb_ret (_event, _cb, ...) \ + ({ \ + int __ret = 0; \ + if (_event->cb_ops && _event->cb_ops->_cb) \ + __ret = _event->cb_ops->_cb(_event->event_id, \ + ##__VA_ARGS__); \ + __ret; \ + }) +#define sse_event_invoke_cb (_event, _cb, ...) \ { \ if (_event->cb_ops && _event->cb_ops->_cb) \@@ -423,16 +432,19 @@ static int sse_event_register(struct sbi_sse_event *e,unsigned long handler_entry_pc, unsigned long handler_entry_arg) { + int ret;if (sse_event_state (e) !=SBI_SSE_STATE_UNUSED )return SBI_EINVALID_STATE ; + ret =sse_event_invoke_cb_ret (e, register_cb); +if (ret) +return ret; +
lib/sbi/sbi_sse.c static int sse_event_register(struct sbi_sse_event *e, · line 450
Quoted 10 lines
lib/sbi/sbi_sse.c +0
-2e->attrs.entry.pc = handler_entry_pc; e->attrs.entry.arg = handler_entry_arg;sse_event_set_state (e,SBI_SSE_STATE_REGISTERED ); -sse_event_invoke_cb (e, register_cb); -return 0 ; }
Quoted 3 lines
--
2.45.2
PATCH 1/3 lib: sbi: sse: Return a value from the register callback
In reply to Clément LégerHi Cl?ment,
Quoted 28 lines · Cl?ment L?ger
Some events might not be available to registration due to missing dependencies (ISA extensions for instance). Return an 'int' from the
register_cb()callback so that this can be handled.Signed-off-by Cl?ment L?ger <[email protected]>--- include/sbi/sbi_sse.h | 2 +- lib/sbi/sbi_sse.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-)include/sbi/sbi_sse.h +1
-1@@ -36,7 +36,7 @@ struct sbi_sse_cb_ops {/** * Called when the SBI_EXT_SSE_REGISTER is invoked on the event. */ -void (*register_cb)(uint32_t event_id); +int (*register_cb)(uint32_t event_id);/** * Called when the SBI_EXT_SSE_UNREGISTER is invoked on the event. lib/sbi/sbi_sse.c +0
-0
lib/sbi/sbi_sse.c static const uint32_t supported_events[] = { · line 56
Quoted 7 lines
lib/sbi/sbi_sse.c +4
-0@@ -50,6 +50,15 @@ static const uint32_t supported_events[] = {#define EVENT_COUNT array_size(supported_events) +#define sse_event_invoke_cb_ret (_event, _cb, ...) \ + ({ \ + int __ret = 0; \ + if (_event->cb_ops && _event->cb_ops->_cb) \
Shouldn't registration fail (except for the explicit "software injected" events) if no callback ops are registered (i.e. _event->cb_ops is NULL)? Right now OpenSBI has no support to generate RAS events, so those have no callback ops, but S-mode can still register and inject them.
Should we require callback ops to expose a SSE event? Should we remove an event ID from supported_events if the corresponding driver is not compiled in?
lib/sbi/sbi_sse.c static int sse_event_register(struct sbi_sse_event *e, · line 435
Quoted 13 lines
lib/sbi/sbi_sse.c +6
-0+ __ret = _event->cb_ops->_cb (_event->event_id, \ + ##__VA_ARGS__); \ + __ret; \ + }) +#define sse_event_invoke_cb (_event, _cb, ...) \ { \ if (_event->cb_ops && _event->cb_ops->_cb) \@@ -423,16 +432,19 @@ static int sse_event_register(struct sbi_sse_event *e,unsigned long handler_entry_pc, unsigned long handler_entry_arg) { + int ret;
minor: blank line needed here.
Since the issue described above is an existing issue:
Regards,
Samuel
Quoted 17 lines
lib/sbi/sbi_sse.c +4
-2if (sse_event_state (e) !=SBI_SSE_STATE_UNUSED )return SBI_EINVALID_STATE ; + ret =sse_event_invoke_cb_ret (e, register_cb); +if (ret) +return ret; + e->attrs.entry.pc = handler_entry_pc; e->attrs.entry.arg = handler_entry_arg;sse_event_set_state (e,SBI_SSE_STATE_REGISTERED ); -sse_event_invoke_cb (e, register_cb); -return 0 ; }
PATCH 1/3 lib: sbi: sse: Return a value from the register callback
Quoted 34 lines · Samuel Holland
Hi Cl?ment,
Quoted 31 lines · Cl?ment L?ger
Some events might not be available to registration due to missing dependencies (ISA extensions for instance). Return an 'int' from the
register_cb()callback so that this can be handled.Signed-off-by Cl?ment L?ger <[email protected]>--- include/sbi/sbi_sse.h | 2 +- lib/sbi/sbi_sse.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-)include/sbi/sbi_sse.h +1
-1@@ -36,7 +36,7 @@ struct sbi_sse_cb_ops {/** * Called when the SBI_EXT_SSE_REGISTER is invoked on the event. */ -void (*register_cb)(uint32_t event_id); +int (*register_cb)(uint32_t event_id);/** * Called when the SBI_EXT_SSE_UNREGISTER is invoked on the event. lib/sbi/sbi_sse.c +0
-0@@ -50,6 +50,15 @@ static const uint32_t supported_events[] = {#define EVENT_COUNT array_size(supported_events)
Quoted 9 lines
lib/sbi/sbi_sse.c static const uint32_t supported_events[] = { · line 56
Quoted 4 lines
lib/sbi/sbi_sse.c +4
-0+#define sse_event_invoke_cb_ret (_event, _cb, ...) \ + ({ \ + int __ret = 0; \ + if (_event->cb_ops && _event->cb_ops->_cb) \Shouldn't registration fail (except for the explicit "software injected" events) if no callback ops are registered (i.e.
_event->cb_opsis NULL)? Right now OpenSBI has no support to generate RAS events, so those have no callback ops, but S-mode can still register and inject them.
If registration fails, this would make the testing the "blank" SSE implementation more difficult to test (particularly priority handling) since only the global and local software injectable events would be available. But that is still possible. I mean, the spec does not say anything about that so we might assume whatever we want.
Quoted 4 lines
Should we require callback ops to expose a SSE event? Should we remove an event ID from
supported_eventsif the corresponding driver is not compiled in?
Quoted 15 lines
lib/sbi/sbi_sse.c static int sse_event_register(struct sbi_sse_event *e, · line 435
Quoted 13 lines
lib/sbi/sbi_sse.c +6
-0+ __ret = _event->cb_ops->_cb (_event->event_id, \ + ##__VA_ARGS__); \ + __ret; \ + }) +#define sse_event_invoke_cb (_event, _cb, ...) \ { \ if (_event->cb_ops && _event->cb_ops->_cb) \@@ -423,16 +432,19 @@ static int sse_event_register(struct sbi_sse_event *e,unsigned long handler_entry_pc, unsigned long handler_entry_arg) { + int ret;minor: blank line needed here.
Yes sure, I'll add it.
Thanks,
Cl?ment
Quoted 26 lines
Since the issue described above is an existing issue:
Reviewed-by Samuel Holland <[email protected]>Regards,
SamuelQuoted 17 lines
lib/sbi/sbi_sse.c +4
-2if (sse_event_state (e) !=SBI_SSE_STATE_UNUSED )return SBI_EINVALID_STATE ; + ret =sse_event_invoke_cb_ret (e, register_cb); +if (ret) +return ret; + e->attrs.entry.pc = handler_entry_pc; e->attrs.entry.arg = handler_entry_arg;sse_event_set_state (e,SBI_SSE_STATE_REGISTERED ); -sse_event_invoke_cb (e, register_cb); -return 0 ; }
PATCH 1/3 lib: sbi: sse: Return a value from the register callback
Quoted 47 lines · Cl?ment L?ger
Quoted 34 lines · Samuel Holland
Hi Cl?ment,
Quoted 31 lines · Cl?ment L?ger
Some events might not be available to registration due to missing dependencies (ISA extensions for instance). Return an 'int' from the
register_cb()callback so that this can be handled.Signed-off-by Cl?ment L?ger <[email protected]>--- include/sbi/sbi_sse.h | 2 +- lib/sbi/sbi_sse.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-)include/sbi/sbi_sse.h +1
-1@@ -36,7 +36,7 @@ struct sbi_sse_cb_ops {/** * Called when the SBI_EXT_SSE_REGISTER is invoked on the event. */ -void (*register_cb)(uint32_t event_id); +int (*register_cb)(uint32_t event_id);/** * Called when the SBI_EXT_SSE_UNREGISTER is invoked on the event. lib/sbi/sbi_sse.c +0
-0@@ -50,6 +50,15 @@ static const uint32_t supported_events[] = {#define EVENT_COUNT array_size(supported_events)Quoted 9 lines
lib/sbi/sbi_sse.c static const uint32_t supported_events[] = { · line 56
Quoted 4 lines
lib/sbi/sbi_sse.c +4
-0+#define sse_event_invoke_cb_ret (_event, _cb, ...) \ + ({ \ + int __ret = 0; \ + if (_event->cb_ops && _event->cb_ops->_cb) \Shouldn't registration fail (except for the explicit "software injected" events) if no callback ops are registered (i.e.
_event->cb_opsis NULL)? Right now OpenSBI has no support to generate RAS events, so those have no callback ops, but S-mode can still register and inject them.
Quoted 9 lines
If registration fails, this would make the testing the "blank" SSE implementation more difficult to test (particularly priority handling) since only the global and local software injectable events would be available. But that is still possible. I mean, the spec does not say anything about that so we might assume whatever we want.
Quoted 3 lines
Should we require callback ops to expose a SSE event? Should we remove an event ID from
supported_eventsif the corresponding driver is not compiled in?
Woops, forgot to answer that as well.
I guess you are actually right, exposing the event without being actually able to handle them is probably wrong. This means some driver would be able to request them but fails to receive any event. With the addition of SBI_ERR_NOT_SUPPORTED return value, we'll be able to handle that properly so I think we will go that way of refuse register for events that do not have a register_cb() callback.
Thanks,
Cl?ment
Quoted 50 lines
Quoted 16 lines
Quoted 10 lines
lib/sbi/sbi_sse.c +5
-0+ __ret = _event->cb_ops->_cb (_event->event_id, \ + ##__VA_ARGS__); \ + __ret; \ + }) +#define sse_event_invoke_cb (_event, _cb, ...) \ { \ if (_event->cb_ops && _event->cb_ops->_cb) \lib/sbi/sbi_sse.c static int sse_event_register(struct sbi_sse_event *e, · line 435
Quoted 4 lines
lib/sbi/sbi_sse.c +1
-0@@ -423,16 +432,19 @@ static int sse_event_register(struct sbi_sse_event *e,unsigned long handler_entry_pc, unsigned long handler_entry_arg) { + int ret;minor: blank line needed here.
Yes sure, I'll add it.
Thanks,
Cl?ment
Quoted 26 lines
Since the issue described above is an existing issue:
Reviewed-by Samuel Holland <[email protected]>Regards,
SamuelQuoted 17 lines
lib/sbi/sbi_sse.c +4
-2if (sse_event_state (e) !=SBI_SSE_STATE_UNUSED )return SBI_EINVALID_STATE ; + ret =sse_event_invoke_cb_ret (e, register_cb); +if (ret) +return ret; + e->attrs.entry.pc = handler_entry_pc; e->attrs.entry.arg = handler_entry_arg;sse_event_set_state (e,SBI_SSE_STATE_REGISTERED ); -sse_event_invoke_cb (e, register_cb); -return 0 ; }
PATCH 2/3 lib: sbi: sse: Disable injection if callbacks are set
In reply to Clément LégerOnce a 'driver' as registered callback for an event, disable event injection for that event to avoid messing up with the driver.
--- lib/sbi/sbi_sse.c | 3 +++ 1 file changed, 3 insertions(+)
lib/sbi/sbi_sse.c +3 -0
@@ -887,6 +887,9 @@ int sbi_sse_set_cb_ops(uint32_t event_id, const struct sbi_sse_cb_ops *cb_ops)return SBI_EINVAL ; e->cb_ops = cb_ops; +/* Do not mess with events that are handled by drivers */ + e->attrs.status &= ~BIT (SBI_SSE_ATTR_STATUS_INJECT_OFFSET ); +sse_event_put (e);return SBI_OK ;
Signature · 1 line
2.45.2
PATCH 2/3 lib: sbi: sse: Disable injection if callbacks are set
Quoted 4 lines · On Fri, Dec 6, 2024 at 1:00?PM Cl?ment L?ger <[email protected]> wrote:
Once a 'driver' as registered callback for an event, disable event injection for that event to avoid messing up with the driver.
Why ? To avoid DoS type attacks ?
Otherwise, I think inject is useful to test/debug the driver without actually triggering the hardware events which can generate the SSE.
Quoted 22 lines
Signed-off-by Cl?ment L?ger <[email protected]>--- lib/sbi/sbi_sse.c | 3 +++ 1 file changed, 3 insertions(+)lib/sbi/sbi_sse.c +3
-1@@ -887,6 +887,9 @@ int sbi_sse_set_cb_ops(uint32_t event_id, const struct sbi_sse_cb_ops *cb_ops)return SBI_EINVAL ; e->cb_ops = cb_ops; +/* Do not mess with events that are handled by drivers */ + e->attrs.status &= ~BIT (SBI_SSE_ATTR_STATUS_INJECT_OFFSET ); +sse_event_put (e);return SBI_OK ; --2.45.2
PATCH 2/3 lib: sbi: sse: Disable injection if callbacks are set
Quoted 10 lines · Atish Kumar Patra
Quoted 4 lines · On Fri, Dec 6, 2024 at 1:00?PM Cl?ment L?ger <[email protected]> wrote:
Once a 'driver' as registered callback for an event, disable event injection for that event to avoid messing up with the driver.
Why ? To avoid DoS type attacks ?
Otherwise, I think inject is useful to test/debug the driver without actually triggering the hardware events which can generate the SSE.
Agreed. I would prefer to modify the driver so it is safe to inject the events.
Quoted 23 lines
Quoted 22 lines
Signed-off-by Cl?ment L?ger <[email protected]>--- lib/sbi/sbi_sse.c | 3 +++ 1 file changed, 3 insertions(+)lib/sbi/sbi_sse.c +3
-1@@ -887,6 +887,9 @@ int sbi_sse_set_cb_ops(uint32_t event_id, const struct sbi_sse_cb_ops *cb_ops)return SBI_EINVAL ; e->cb_ops = cb_ops; +/* Do not mess with events that are handled by drivers */ + e->attrs.status &= ~BIT (SBI_SSE_ATTR_STATUS_INJECT_OFFSET ); +sse_event_put (e);return SBI_OK ; --2.45.2
PATCH 2/3 lib: sbi: sse: Disable injection if callbacks are set
Quoted 7 lines · Samuel Holland
Quoted 6 lines · Atish Kumar Patra
Quoted 4 lines · On Fri, Dec 6, 2024 at 1:00?PM Cl?ment L?ger <[email protected]> wrote:
Once a 'driver' as registered callback for an event, disable event injection for that event to avoid messing up with the driver.
Quoted 6 lines
Quoted 4 lines
Why ? To avoid DoS type attacks ?
Otherwise, I think inject is useful to test/debug the driver without actually triggering the hardware events which can generate the SSE.
Agreed. I would prefer to modify the driver so it is safe to inject the events.
Ok, so let's remove that patch ;)
Quoted 25 lines
Quoted 24 lines
Quoted 23 lines
Signed-off-by Cl?ment L?ger <[email protected]>--- lib/sbi/sbi_sse.c | 3 +++ 1 file changed, 3 insertions(+)lib/sbi/sbi_sse.c +3
-1@@ -887,6 +887,9 @@ int sbi_sse_set_cb_ops(uint32_t event_id, const struct sbi_sse_cb_ops *cb_ops)return SBI_EINVAL ; e->cb_ops = cb_ops; +/* Do not mess with events that are handled by drivers */ + e->attrs.status &= ~BIT (SBI_SSE_ATTR_STATUS_INJECT_OFFSET ); +sse_event_put (e);return SBI_OK ; --2.45.2
PATCH 2/3 lib: sbi: sse: Disable injection if callbacks are set
In reply to Atish Kumar PatraQuoted 10 lines · Atish Kumar Patra
Quoted 4 lines · On Fri, Dec 6, 2024 at 1:00?PM Cl?ment L?ger <[email protected]> wrote:
Once a 'driver' as registered callback for an event, disable event injection for that event to avoid messing up with the driver.
Why ? To avoid DoS type attacks ?
Otherwise, I think inject is useful to test/debug the driver without actually triggering the hardware events which can generate the SSE.
Yeah, this is not strictly necessary, but that does not seemed right to me to allow generating event without any real reason. This can be dropped if needed.
Cl?ment
Quoted 23 lines
Quoted 23 lines
Signed-off-by Cl?ment L?ger <[email protected]>--- lib/sbi/sbi_sse.c | 3 +++ 1 file changed, 3 insertions(+)lib/sbi/sbi_sse.c +3
-1@@ -887,6 +887,9 @@ int sbi_sse_set_cb_ops(uint32_t event_id, const struct sbi_sse_cb_ops *cb_ops)return SBI_EINVAL ; e->cb_ops = cb_ops; +/* Do not mess with events that are handled by drivers */ + e->attrs.status &= ~BIT (SBI_SSE_ATTR_STATUS_INJECT_OFFSET ); +sse_event_put (e);return SBI_OK ; --2.45.2
PATCH 3/3 lib: sbi: pmu: Set a SSE register_cb() for event availability
In reply to Clément LégerSince the SSE event can work only when the LCOFIP interrupt is available, check for the Sscofpmf extension to be available in the SSE register callback.
--- lib/sbi/sbi_pmu.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
lib/sbi/sbi_pmu.c +11 -0
@@ -1110,7 +1110,18 @@ static void pmu_sse_complete(uint32_t event_id)csr_set (CSR_MIE ,MIP_LCOFIP ); } +static int pmu_sse_register (uint32_t event_id) +{ +struct sbi_scratch *scratch =sbi_scratch_thishart_ptr (); + +if (!sbi_hart_has_extension (scratch,SBI_HART_EXT_SSCOFPMF )) +return SBI_ERR_FAILED ; + +return SBI_SUCCESS ; +} +static const struct sbi_sse_cb_ops pmu_sse_cb_ops = { + .register_cb = pmu_sse_register, .enable_cb = pmu_sse_enable, .disable_cb = pmu_sse_disable, .complete_cb = pmu_sse_complete,
Signature · 1 line
2.45.2
PATCH 3/3 lib: sbi: pmu: Set a SSE register_cb() for event availability
Quoted 37 lines · On Fri, Dec 6, 2024 at 1:00?PM Cl?ment L?ger <[email protected]> wrote:
Since the SSE event can work only when the LCOFIP interrupt is available, check for the Sscofpmf extension to be available in the SSE register callback.
Signed-off-by Cl?ment L?ger <[email protected]>--- lib/sbi/sbi_pmu.c | 11 +++++++++++ 1 file changed, 11 insertions(+)lib/sbi/sbi_pmu.c +11
-1@@ -1110,7 +1110,18 @@ static void pmu_sse_complete(uint32_t event_id)csr_set (CSR_MIE ,MIP_LCOFIP ); } +static int pmu_sse_register (uint32_t event_id) +{ +struct sbi_scratch *scratch =sbi_scratch_thishart_ptr (); + +if (!sbi_hart_has_extension (scratch,SBI_HART_EXT_SSCOFPMF )) +return SBI_ERR_FAILED ; + +return SBI_SUCCESS ; +} +static const struct sbi_sse_cb_ops pmu_sse_cb_ops = { + .register_cb = pmu_sse_register, .enable_cb = pmu_sse_enable, .disable_cb = pmu_sse_disable, .complete_cb = pmu_sse_complete, --2.45.2
Quoted 4 lines
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Signature · 2 lines
Regards, Atish
PATCH 3/3 lib: sbi: pmu: Set a SSE register_cb() for event availability
In reply to Clément LégerQuoted 3 lines · Cl?ment L?ger
Since the SSE event can work only when the LCOFIP interrupt is available, check for the Sscofpmf extension to be available in the SSE register callback.
Is this a hard limitation, or could the driver be made to work whenever sbi_pmu_irq_bit() returns a valid bit?
Since this accurately reflects the current implementation:
Quoted 28 lines
Signed-off-by Cl?ment L?ger <[email protected]>--- lib/sbi/sbi_pmu.c | 11 +++++++++++ 1 file changed, 11 insertions(+)lib/sbi/sbi_pmu.c +11
-0@@ -1110,7 +1110,18 @@ static void pmu_sse_complete(uint32_t event_id)csr_set (CSR_MIE ,MIP_LCOFIP ); } +static int pmu_sse_register (uint32_t event_id) +{ +struct sbi_scratch *scratch =sbi_scratch_thishart_ptr (); + +if (!sbi_hart_has_extension (scratch,SBI_HART_EXT_SSCOFPMF )) +return SBI_ERR_FAILED ; + +return SBI_SUCCESS ; +} +static const struct sbi_sse_cb_ops pmu_sse_cb_ops = { + .register_cb = pmu_sse_register, .enable_cb = pmu_sse_enable, .disable_cb = pmu_sse_disable, .complete_cb = pmu_sse_complete,
PATCH 3/3 lib: sbi: pmu: Set a SSE register_cb() for event availability
Quoted 7 lines · Samuel Holland
Quoted 3 lines · Cl?ment L?ger
Since the SSE event can work only when the LCOFIP interrupt is available, check for the Sscofpmf extension to be available in the SSE register callback.
Is this a hard limitation, or could the driver be made to work whenever
sbi_pmu_irq_bit()returns a valid bit?
Hi Samuel,
I guess you are right since that should also work for the ANDES platform that have a PMU IRQ but does not support SSCOFPMF. So it would be better to actually use sbi_pmu_irq_bit().
Thanks !
Cl?ment
Quoted 34 lines
Since this accurately reflects the current implementation:
Reviewed-by Samuel Holland <[email protected]>Quoted 28 lines
Signed-off-by Cl?ment L?ger <[email protected]>--- lib/sbi/sbi_pmu.c | 11 +++++++++++ 1 file changed, 11 insertions(+)lib/sbi/sbi_pmu.c +11
-0@@ -1110,7 +1110,18 @@ static void pmu_sse_complete(uint32_t event_id)csr_set (CSR_MIE ,MIP_LCOFIP ); } +static int pmu_sse_register (uint32_t event_id) +{ +struct sbi_scratch *scratch =sbi_scratch_thishart_ptr (); + +if (!sbi_hart_has_extension (scratch,SBI_HART_EXT_SSCOFPMF )) +return SBI_ERR_FAILED ; + +return SBI_SUCCESS ; +} +static const struct sbi_sse_cb_ops pmu_sse_cb_ops = { + .register_cb = pmu_sse_register, .enable_cb = pmu_sse_enable, .disable_cb = pmu_sse_disable, .complete_cb = pmu_sse_complete,
cover lib: sbi: fix PMU SSE event handling
In reply to Clément LégerQuoted 5 lines · On Fri, Dec 6, 2024 at 1:00?PM Cl?ment L?ger <[email protected]> wrote:
While reworking the Linux SSE support, it appears that the PMU event should not be available if the SSCOFPMF extension is not available since there would be no IRQ. The specification isn't really clear on that point so this is more like a RFC to check that. Ideally, the sse register call
Can you send a patch for SBI spec ? I think we can call it a local PMU overflow event
rather than a PMU.
We can add a note about the Sscofpmf dependency as well.
Quoted 21 lines
should allow to refuse registering an event if the dependencies are not satisfied but does not allow this yet.
Cl?ment L?ger (3):
lib: sbi: sse: Return a value from the register callback
lib: sbi: sse: Disable injection if callbacks are set
lib: sbi: pmu: Set a SSEregister_cb()for event availabilityinclude/sbi/sbi_sse.h | 2 +- lib/sbi/sbi_pmu.c | 11 +++++++++++ lib/sbi/sbi_sse.c | 19 +++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-)--
2.45.2--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Signature · 2 lines
Regards, Atish
cover lib: sbi: fix PMU SSE event handling
Quoted 10 lines · Atish Patra
Quoted 5 lines · On Fri, Dec 6, 2024 at 1:00?PM Cl?ment L?ger <[email protected]> wrote:
While reworking the Linux SSE support, it appears that the PMU event should not be available if the SSCOFPMF extension is not available since there would be no IRQ. The specification isn't really clear on that point so this is more like a RFC to check that. Ideally, the sse register call
Can you send a patch for SBI spec ? I think we can call it a local PMU overflow event
rather than a PMU.
Yes sure, that makes more sense. I'll also modify the possible return value for register to add NOT_SUPPORTED in case some dependencies are missing
Thanks,
Cl?ment
Quoted 27 lines
We can add a note about the Sscofpmf dependency as well.
Quoted 21 lines
should allow to refuse registering an event if the dependencies are not satisfied but does not allow this yet.
Cl?ment L?ger (3):
lib: sbi: sse: Return a value from the register callback
lib: sbi: sse: Disable injection if callbacks are set
lib: sbi: pmu: Set a SSEregister_cb()for event availabilityinclude/sbi/sbi_sse.h | 2 +- lib/sbi/sbi_pmu.c | 11 +++++++++++ lib/sbi/sbi_sse.c | 19 +++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-)--
2.45.2--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
cover lib: sbi: fix PMU SSE event handling
Quoted 10 lines · Cl?ment L?ger
Quoted 7 lines · Atish Patra
Quoted 5 lines · On Fri, Dec 6, 2024 at 1:00?PM Cl?ment L?ger <[email protected]> wrote:
While reworking the Linux SSE support, it appears that the PMU event should not be available if the SSCOFPMF extension is not available since there would be no IRQ. The specification isn't really clear on that point so this is more like a RFC to check that. Ideally, the sse register call
Quoted 7 lines
Quoted 3 lines
Can you send a patch for SBI spec ? I think we can call it a local PMU overflow event
rather than a PMU.Yes sure, that makes more sense. I'll also modify the possible return value for register to add
NOT_SUPPORTEDin case some dependencies are missing
While thinking about it, should we actually return ERR_INVALID_PARAM or add a new ERR_NOT_SUPPORTED if the event is not supported due to missing dependencies ? It seems like it is different but I'm not sure it adds any valuable information (ie, the caller is not going to do anything special about it)
Cl?ment
Quoted 33 lines
Thanks,
Cl?ment
Quoted 27 lines
We can add a note about the Sscofpmf dependency as well.
Quoted 21 lines
should allow to refuse registering an event if the dependencies are not satisfied but does not allow this yet.
Cl?ment L?ger (3):
lib: sbi: sse: Return a value from the register callback
lib: sbi: sse: Disable injection if callbacks are set
lib: sbi: pmu: Set a SSEregister_cb()for event availabilityinclude/sbi/sbi_sse.h | 2 +- lib/sbi/sbi_pmu.c | 11 +++++++++++ lib/sbi/sbi_sse.c | 19 +++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-)--
2.45.2--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
cover lib: sbi: fix PMU SSE event handling
Quoted 22 lines · On Mon, Dec 9, 2024 at 12:55?AM Cl?ment L?ger <[email protected]> wrote:
Quoted 10 lines · Cl?ment L?ger
Quoted 7 lines · Atish Patra
Quoted 5 lines · On Fri, Dec 6, 2024 at 1:00?PM Cl?ment L?ger <[email protected]> wrote:
While reworking the Linux SSE support, it appears that the PMU event should not be available if the SSCOFPMF extension is not available since there would be no IRQ. The specification isn't really clear on that point so this is more like a RFC to check that. Ideally, the sse register call
Quoted 7 lines
Quoted 3 lines
Can you send a patch for SBI spec ? I think we can call it a local PMU overflow event
rather than a PMU.Yes sure, that makes more sense. I'll also modify the possible return value for register to add
NOT_SUPPORTEDin case some dependencies are missing
Quoted 6 lines
While thinking about it, should we actually return
ERR_INVALID_PARAMor add a newERR_NOT_SUPPORTEDif the event is not supported due to missing dependencies ? It seems like it is different but I'm not sure it adds any valuable information (ie, the caller is not going to do anything special about it)
IMO, we should add ERR_NOT_SUPPORTED as ERR_INVALID_PARAM indicates that event_id
is not valid. But ERR_NOT_SUPPORTED will indicate that event_id is valid but the firmware doesn't support
this event for some reasons (e.g missing ISA dependency being one of them)
Quoted 36 lines
Cl?ment
Quoted 33 lines
Thanks,
Cl?ment
Quoted 27 lines
We can add a note about the Sscofpmf dependency as well.
Quoted 21 lines
should allow to refuse registering an event if the dependencies are not satisfied but does not allow this yet.
Cl?ment L?ger (3):
lib: sbi: sse: Return a value from the register callback
lib: sbi: sse: Disable injection if callbacks are set
lib: sbi: pmu: Set a SSEregister_cb()for event availabilityinclude/sbi/sbi_sse.h | 2 +- lib/sbi/sbi_pmu.c | 11 +++++++++++ lib/sbi/sbi_sse.c | 19 +++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-)--
2.45.2--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
cover lib: sbi: fix PMU SSE event handling
Quoted 30 lines · Atish Kumar Patra
Quoted 22 lines · On Mon, Dec 9, 2024 at 12:55?AM Cl?ment L?ger <[email protected]> wrote:
Quoted 10 lines · Cl?ment L?ger
Quoted 7 lines · Atish Patra
Quoted 5 lines · On Fri, Dec 6, 2024 at 1:00?PM Cl?ment L?ger <[email protected]> wrote:
While reworking the Linux SSE support, it appears that the PMU event should not be available if the SSCOFPMF extension is not available since there would be no IRQ. The specification isn't really clear on that point so this is more like a RFC to check that. Ideally, the sse register call
Quoted 7 lines
Quoted 3 lines
Can you send a patch for SBI spec ? I think we can call it a local PMU overflow event
rather than a PMU.Yes sure, that makes more sense. I'll also modify the possible return value for register to add
NOT_SUPPORTEDin case some dependencies are missingQuoted 6 lines
While thinking about it, should we actually return
ERR_INVALID_PARAMor add a newERR_NOT_SUPPORTEDif the event is not supported due to missing dependencies ? It seems like it is different but I'm not sure it adds any valuable information (ie, the caller is not going to do anything special about it)
Quoted 5 lines
IMO, we should add
ERR_NOT_SUPPORTEDasERR_INVALID_PARAMindicates thatevent_id
is not valid. ButERR_NOT_SUPPORTEDwill indicate thatevent_idis valid but the firmware doesn't support
this event for some reasons (e.g missing ISA dependency being one of them)
Ok, that seems like a sane behavior as well. I'll send a riscv-sbi-doc pr for that.
Cl?ment
Quoted 37 lines
Quoted 37 lines
Cl?ment
Quoted 33 lines
Thanks,
Cl?ment
Quoted 27 lines
We can add a note about the Sscofpmf dependency as well.
Quoted 21 lines
should allow to refuse registering an event if the dependencies are not satisfied but does not allow this yet.
Cl?ment L?ger (3):
lib: sbi: sse: Return a value from the register callback
lib: sbi: sse: Disable injection if callbacks are set
lib: sbi: pmu: Set a SSEregister_cb()for event availabilityinclude/sbi/sbi_sse.h | 2 +- lib/sbi/sbi_pmu.c | 11 +++++++++++ lib/sbi/sbi_sse.c | 19 +++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-)--
2.45.2--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi