summaryrefslogtreecommitdiff
path: root/lib/sbi/sbi_sse.c
AgeCommit message (Collapse)Author
20 hourslib: sbi: sse: clear SPV for non-virtualized eventsHEADmasterZhanpeng Zhang
SSE injection sets hstatus.SPV to the virtualization state of the interrupted context before entering the supervisor handler. This patch completes that existing requirement and does not change the SSE ABI. The existing code sets SPV when the interrupted context is virtualized, but leaves it unchanged otherwise. A stale SPV value can therefore make an event that interrupted host execution appear to have interrupted a guest. Event completion can then resume with virtualization enabled. Clear SPV when the interrupted context is not virtualized so the handler-visible state matches the interrupted context. This also lets supervisor software, such as the Linux PMU and perf code, reliably tell whether an SSE interrupted host or virtualized execution. Fixes: c8cdf01d8f3a ("lib: sbi: Add support for Supervisor Software Events extension") Signed-off-by: Zhanpeng Zhang <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2026-03-10lib: sbi: fix sse_event_inject() status settingCharlie Jenkins
sse_event_inject() currently sets all status bits to 1 except for SBI_SSE_ATTR_STATUS_PENDING_OFFSET which it sets to zero. Instead of overwriting all the values of the status bits, sse_event_inject() is only expected to clear SBI_SSE_ATTR_STATUS_PENDING_OFFSET. Fix sse_event_inject() to only do the clearing. Signed-off-by: Charlie Jenkins <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2025-12-16lib: sbi: Replace sbi_hart_pmp_xyz() and sbi_hart_map/unmap_addr()Anup Patel
The sbi_hart_pmp_xyz() and sbi_hart_map/unmap_addr() functions can now be replaced by various sbi_hart_protection_xyz() functions. Signed-off-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2025-03-27lib: sbi: sse: Add support for SSTATUS.SDTClément Léger
Similarly to what is done for SPELP, handle SSTATUS.SDT upon event injection. In order to mimick an interrupt, set SDT to 1 for injection and save its previous value in interrupted_flags[5:5]. Restore it upon completion. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2025-03-27lib: sbi: sse: Add support for SSTATUS.SPELPClément Léger
As raised during the ARC review, SPELP was not handled during the event injection process. Save it as part of the interrupted flags, clear it before injecting the event and restore it after completion. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2025-03-27lib: sbi: sse: Remove superfluous parenthesis around MSTATUS_* valuesClément Léger
For some reason, there was a pair of useless parenthesis around MSTATUS_* value usage. Remove them. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2025-03-27lib: sbi: sse: Rename STATUS* interrupted flags to SSTATUS*Clément Léger
As raised by Andrew on the kvm-unit-test review, this flags are meant to hold SSTATUS bits in the specification. Rename them to match that. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2025-03-27lib: sbi: sse: Return SBI_EDENIED for read only parameters.Clément Léger
The SSE specification did specified that read only parameters should return SBI_EBADRANGE but was modified recently to return SBI_EDENIED. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2025-03-27lib: sbi: sse: Remove printf from sbi_sse_exit()Clément Léger
This printf is mainly useful for debugging, remove it. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2025-03-27lib: sbi: sse: Update SSE event idsClément Léger
The latest specification added new high priority RAS events and renamed the PMU to PMU_OVERFLOW. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2025-03-23lib: sbi: Return SBI_EALREADY error code if SSE event is presentHimanshu Chauhan
Return SBI_EALREADY error code instead of SBI_EINVAL, in case an event is already added to the supported list. Signed-off-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2025-02-19lib: sbi: sse: fix invalid errors returned for sse_hart_mask/unmask()Clément Léger
When called twice, sse_hart_mask()/sse_hart_unmask() should return SBI_EALREADY_STOPPED/SBI_EALREADY_STARTED. This was currently inverted. Fixes: b919daf49582 ("lib: sbi: Add support to mask/unmask SSE events") Reported-by: Andrew Jones <[email protected]> Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2025-01-30lib: sbi: sse: return SBI_ENOTSUPP for unsupported eventsClément Léger
If a standard event was not found in the list of events that are handled by harts but belongs to the standard event list defined by the specification, return SBI_ENOTSUPP. Without that, we can not distinguish a non implemented standard event from a non valid one. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2025-01-30lib: sbi: sse: allow adding new eventsClément Léger
In order to allow events to be dynamically added, remove the existing static array of events and use a simply linked list of supported events. This allows us to move the cb_ops into this list and associated it with an event_id. Drivers can now register cb_ops before bringing up the sse core to handle additional events (platform ones for instance). sbi_sse_init() now allocates as many events as present in the linked list. Events can now be added with sbi_sse_add_event() which allows to add new supported events with some callback operations if any. If an event is not to be supported, then sbi_sse_add_event() should not be called. This approach currently consider that local events are to be supported on all harts (ie, they all support the same ISA or dependencies). If per-hart event availability needs to be supported, then, an is_supported() callback could be added later and called for each hart. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Samuel Holland <[email protected]>
2025-01-30lib: sbi: sse: return an error value from sse_event_get()Clément Léger
Since event support will be checked in the next commits, return a value from sse_event_get() to allow propagating it. This will be used to report SBI_ERR_NOT_SUPPORTED when an event isn't supported. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2024-12-15lib: sbi: sse: Fix a6 and a7 register content upon injectionClément Léger
The specification states that a6 contains the current hart id and a7 contains the entry argument. This was inverted in the current implementation. Reported-by: Andrew Jones <[email protected]> Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-10-25lib: sbi: send a double trap SSE event to supervisorClément Léger
In case the double trap handler is called and the double trap happened in supervisor mode, send a double trap SSE event. NOTE: this commit depends on the ratification of the new SSE event id for double trap [1]. Link: https://lists.riscv.org/g/tech-prs/message/985 [1] Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Samuel Holland <[email protected]>
2024-10-25lib: sbi: Add support to mask/unmask SSE eventsHimanshu Chauhan
Add functions to globally mask/unmask supervisor software events on the calling hart. Signed-off-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-09-26lib: sbi: Update sbi_domain_is_assigned_hart() to take a hart indexSamuel Holland
This removes redundant hartid to hartindex conversions from four call sites and provides a net reduction in code size. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-09-25lib: sbi_sse: Cache the event's target hart indexSamuel Holland
This avoids needing to map the target hartid to a hart index when enabling or disabling an event, and provides a net code size reduction. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24lib: sse: remove unused sse_inject_out() parameterClément Léger
This parameters was a remnant of a previous version, remove it now that it is unused. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-07-24lib: sbi: Allow forceful queueing of data in sbi_fifo_enqueue()Anup Patel
Extend sbi_fifo_enqueue() to allow forceful queueing by droping data from the tail. Signed-off-by: Anup Patel <[email protected]> Reviewed-By: Himanshu Chauhan <[email protected]>
2024-05-23lib: sbi: sse: handle missing writable attributesClément Léger
The spec states that a6, a7, flags and sepc are writable but the implementation was not allowing that. Add support for these 4 writable attributes. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-15lib: sbi: Put event after use in sbi_sse_exit() loopAnup Patel
Currently, the sbi_sse_exit() gets event in a loop but does not put it back after use. This results in global events remaining locked causing hangs on sub-sequent calls to sse_event_get() for global events. Fixes: c8cdf01d8f3a ("lib: sbi: Add support for Supervisor Software Events extension") Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Himanshu Chauhan <[email protected]>
2024-05-07lib: sbi: sse: check handler entry to belong to supervisor modeClé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(). Signed-off-by: Clément Léger <[email protected]> Reported-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07lib: sbi: sse: use PRV_S instead of hardcoded value for modeClément Léger
Rather then passing 1 to sbi_domain_check_addr_range() for supervisor mode, use PRV_S. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07lib: sbi: sse: call enable callback before sending IPIClé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. Signed-off-by: Clément Léger <[email protected]> Reported-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07lib: sbi: sse: remove superfluous sbi_list_empty() checkClé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. Signed-off-by: Clément Léger <[email protected]> Reported-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07lib: sbi: sse: simplify 32bits overflow checkClément Léger
Rather than checking 32bits overflow with some absolute value, check the value to be different from the cast itself. Signed-off-by: Clément Léger <[email protected]> Reported-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07lib: sbi: sse: rename sse_hart_unlock() to sse_enabled_event_unlock()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. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07lib: sbi: sse: fix typos, comments and spacing errorsClément Léger
Fix some errors spotted by Samuel while reviewing the SSE implementation. Signed-off-by: Clément Léger <[email protected]> Reported-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-04-10lib: sbi: sse_event_get() may return NULLHeinrich Schuchardt
sse_event_get() may return NULL. We should not dereference the return value in sbi_sse_exit() without checking. Fixes: c8cdf01d8f3a ("lib: sbi: Add support for Supervisor Software Events extension") Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-04-05lib: sbi: Add support for Supervisor Software Events extensionClément Léger
This extension [1] allows to deliver events from SBI to supervisor via a software mechanism. This extension defines events (either local or global) which are signaled by the SBI on specific signal sources (IRQ, exceptions, etc) and are injected to be executed in supervisor mode. [1] https://lists.riscv.org/g/tech-prs/message/798 Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]>