Study guides · Advanced

Arm exception levels: guest and hypervisor responsibilities

Separate privilege, exception routing, and execution state before following a guest through EL1 and EL2.

Ask Logeia about this articleTry the three questionsReview your answers

Updated

On this page
  1. One CPU can execute different contexts
  2. State the configuration being taught
  3. Read CurrentEL without misreading its encoding
  4. A cause is different from a destination
  5. Distinguish architectural entry from software saving
  6. Attach a reason to each transition
  7. Exercise: privilege is not scheduling priority
  8. Ask Logeia about this articleCheck your understanding

One CPU can execute different contexts

A guest and its hypervisor do not necessarily own separate physical CPUs. Begin with the context in which the current instruction executes. This lesson uses guest applications at EL0, the guest kernel at EL1, and virtualization management at EL2. The exception level describes privilege and architectural context; it does not specify execution speed or allocated CPU time. Scheduling is a separate decision.

For example, progressing one ordinary guest arithmetic instruction does not require handing control back to the hypervisor after every operation. A virtualization configuration selects the operations and events requiring intervention. Distinguish this from an emulator that models instructions in software. When reading a trace, ask whether a step is ordinary guest execution or a selected boundary crossing; the same final arithmetic answer does not establish that both mechanisms took the same path.

State the configuration being taught

The common EL0/application, EL1/OS, and EL2/hypervisor arrangement is a useful starting point, not a universal deployment rule. EL3, security states, and configurations that host an OS at EL2 require additional explanation. The model here deliberately excludes them. Distinct levels alone do not create complete isolation: translation tables, their ownership, and device access also matter.

The trust model is another independent axis. In an ordinary VM arrangement, management code is trusted while access between guests is constrained. A page hidden from another guest is not necessarily hidden from the hypervisor. Before considering confidential-computing extensions, write down which actor is being protected from which other actor. Privilege level names alone neither specify that threat model nor establish protection against a malicious management layer.

ContextLevel in this lessonResponsibility
Guest applicationEL0Execute application instructions
Guest OSEL1Manage guest processes and stage 1
HypervisorEL2Manage guest state and stage 2

Read CurrentEL without misreading its encoding

CurrentEL encodes the level in bits 3:2. For example, EL1 corresponds to 0x4 and EL2 to 0x8; the raw value is not the decimal level number. The demonstration shows both forms. Access to system registers also depends on the current context, so this is not an instruction that an ordinary application may freely use to inspect every privileged detail.

A small test can decode a supplied value using (0x8 >> 2) & 3 and check that the result is 2. This calculation does not read CurrentEL from the machine running Python. It checks the interpretation of an already supplied value. Keep acquisition, bit extraction, and architectural interpretation as three distinct steps. A correct decoder paired with an incorrectly acquired value would still produce a misleading claim about the executing machine.

python
def decode_current_el(raw):
    return (raw >> 2) & 3

assert decode_current_el(0x4) == 1
assert decode_current_el(0x8) == 2
print(decode_current_el(0x8))

A cause is different from a destination

System calls, selected privileged operations, and external interrupts may all interrupt normal instruction flow. They do not all go to EL2. The exception class, source level, and routing configuration determine the recipient. In this configuration, ordinary guest system calls belong to the guest OS, while selected EL1 operations can be handled at EL2. A guest exception is not sufficient evidence that the hypervisor handled it.

The MMIO demonstration specifically selects an EL1 store trapped by stage 2 and handled at EL2. Do not silently reuse that routing for a normal EL0-to-EL1 guest system call. Both cross privilege-related boundaries, but they have different triggers, information, and handlers. Two arrows that look similar in a diagram need not represent interchangeable operations. Label the cause and configuration alongside the source and destination levels when comparing them.

Distinguish architectural entry from software saving

For an exception taken to EL2, ELR_EL2, SPSR_EL2, and ESR_EL2 help identify the return context and exception cause. Individual syndrome fields have validity conditions. Exception entry does not automatically save every general-purpose register into a software context object. The trace separates architectural updates from registers explicitly saved by the entry code.

The EL2 suffix on a register is not a guarantee that all guest state is already aggregated there. The handler also needs usable storage and a stack that its own saves will not corrupt. Distinct patterns in general registers reveal swapped save slots more effectively than initializing every register to zero. This connects the architectural exception description to software context layout without pretending that one saved syndrome value is a complete guest checkpoint.

Attach a reason to each transition

Start with a guest kernel at EL1. An ordinary operation remains there; an operation covered by the chosen trap configuration enters EL2. Show the before/after level, operation, classification, return location, and saved state. The result explains which rule applied. This is a concept model of selected paths, not a claim that every AArch64 instruction or routing combination was executed.

Record one baseline input and configuration before changing a single condition. Replacing an operation and changing the trap configuration for that same operation are different experiments. Preserve the unchanged assumptions as well as the observed levels. These records later become reproducible test cases when the concept model is replaced with architecture-specific code. They also prevent treating a changed demonstration input as evidence that a different real hardware routing rule was measured.

Exercise: privilege is not scheduling priority

Suppose A executes at EL1 and B at EL2, while A receives more CPU time. It is incorrect to infer that B must run longer because its level is higher. Then decode CurrentEL=0x8: bits 3:2 give EL2. Finally, distinguish an ordinary guest system call into the guest OS from an operation routed to EL2 by the virtualization configuration.

As an extension, list operations allowed in the guest, operations handled at EL2, and unsupported operations. Give unsupported cases an explicit stop outcome rather than an empty cell that suggests success. A strong answer names both the condition causing the transition and a condition under which it would not happen. That reasoning, rather than memorizing level numbers, is the prerequisite for the guest entry and exit lesson that follows.

Try the interactive model

Guest output and MMIO traps

Loading demo checkpoint…

Reading and practice are recorded separately in this browser, for each language.

Choose a learning path