Skip to content

Handle custom HVCs in platform code#30

Merged
m4tx merged 3 commits intomainfrom
unknown_hvc
Mar 30, 2026
Merged

Handle custom HVCs in platform code#30
m4tx merged 3 commits intomainfrom
unknown_hvc

Conversation

@m4tx
Copy link
Copy Markdown
Collaborator

@m4tx m4tx commented Mar 27, 2026

Add handle_hvc to the Platform trait, enabling custom EL2 HVC calls for specific platforms. Unhandled HVCs are properly trapped and routed to this method. If a platform doesn't handle the HVC, it now returns SMCCC_NOT_SUPPORTED (-1) to the guest instead of panicking.

Added a dummy HVC (0xFF00_0000) to the QEMU platform implementation for testing purposes. The integration_test (formerly called isolation_test) validates both successful dummy HVC execution and expected failure for unknown HVCs.

Add `handle_hvc` to the `Platform` trait, enabling custom EL2 HVC
calls for specific platforms. Unhandled HVCs are properly trapped
and routed to this method. If a platform doesn't handle the HVC,
it now returns SMCCC_NOT_SUPPORTED (-1) to the guest instead of
panicking.

Added a dummy HVC (0xFF00_0000) to the QEMU platform implementation
for testing purposes. The `integration_test` (formerly called
`isolation_test`) validates both successful dummy HVC execution
and expected failure for unknown HVCs.
@m4tx m4tx requested review from qperret2 and qwandor March 27, 2026 16:18
if function_id == 0xFF00_0000 {
// SAFETY: We only modify the state of the x0 register as an answer to the
// guest call.
let regs = unsafe { register_state.get_mut() };
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to provide a safe abstraction for platforms to handle HVCs. Maybe rather than passing the RegisterStateRef you could pass a mutable reference to the subset of registers which the SMCCC allows to be changed by an HVC call? I guess this handler shouldn't need to change the FP, SP, ELR or SPSR, right?

Copy link
Copy Markdown
Collaborator Author

@m4tx m4tx Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair - I changed the API so that handle_hvc now return a custom error. The nice part is that some of the logic can be shared with the PSCI proxy code.

Let me know if this makes sense.

@m4tx m4tx requested a review from qwandor March 30, 2026 14:08
@m4tx m4tx merged commit 2f599cf into main Mar 30, 2026
10 checks passed
@m4tx m4tx deleted the unknown_hvc branch March 30, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants