-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
M-mode interrupt virtualization #186
Comments
@Wesdcv does that make sense to you? I tried to summarize my understanding of our discussion, but let me know if you think I forgot anything/something seems off. |
Yes, great analysis, thanks! I think there is one thing that worries me somewhat: Assuming the firmware runs unvirtualized. It gets a trap - goes into trap handler, disables further interrupts, deals with trap cause (writes to mm register) - that's a "good" scenario. The firmware is theoretically under no obligation to disable interrupts (which Miralis reflects in physical registers) in the trap handler, or to clear the interrupt bit - so if the bit wasn't cleared, it should trap again. Upd: |
Yes you are right, before returning to the firmware we might need to check if an interrupt needs to be injected (interrupts are enabled + And regarding Miralis, it simply never enables them, so they stay disabled forever^^ |
Following our discussion with @Wesdcv I am opening this issue to track the progress on M-mode interrupt virtualization.
Context
Non-delegated interrupts need to be fully virtualized. A non-delegated interrupt will necessarily trap to Miralis because Miralis is the M-mode software. If the corresponding interrupt bit is not set to 0 returning to the firmware or the payload will trap back to Miralis right away, effectively causing an infinite loop on the hart. Disabling the interrupt in
mie
is not an option, because there would be no trap for the next interrupt which would prevent Miralis from injecting the interrupt back into the firmware.Delegated interrupts do not have this issue, because the OS can handle them without trapping to Miralis. According to the specification all interrupt delegated bits in
mideleg
can be hardwired to 1 except the M-mode interrupt bits. The M-mode interrupts areMEI
,MTI
, andMSI
.Virtualizing interrupts requires virtualizing the device emitting the interrupt (e.g. the PLIC and CLINT for M-mode interrupts), but we want to limit the virtualization of devices as much as possible. As a result we should force delegation of all non M-mode interrupts.
Life cycle of virtualized interrupts
Consider an interrupt MXI that is virtualized.
mideleg.MXI
is set to 0.mie.MXI == vmie.MXI
.mip.MXI == 1
) Miralis setsvmip.MXI
to 1 and deactivates the interrupt. This requires to write to a memory mapped device (e.g. CLINT or PLIC). Note that this device must be virtualized, and thus is not directly accessible by the firmware or the payload. If the interrupt is enabled for the firmware it must be injected, otherwise it must be injected whenever the interrupts become enabled again.vmip.MXI
to 0.mie.MXI
bit ifvmip.MXI
is already 1. This prevent Miralis from trapping again if another interrupts arrives but the previous one has not yet be handled by the firmware. Miralis restoresmie.MXI
to 1 once the firmware disablesvmip.MXI
by writing to the virtualized device.vmip.MXI == 1
,vmie.MXI == 1
, andvmstatus.MIE == 1
), and inject one if that is the case.M-mode interrupt virtualization TODO list:
vmideleg
.MEI
MTI
MSI
The text was updated successfully, but these errors were encountered: