14.7 Prediction isolation on a world switch
A “world switch” here is any point where one piece of software hands the PE to another it does not trust. Examples are EL3 switching Non-secure and Secure (or Realm), a hypervisor switching VMs, an SPMC switching partitions, a Trusted OS switching TAs, and an OS switching processes. The question for each is the same: can prediction state left by the outgoing software steer speculation in the incoming software? The architecture answers it in three layers:
- Automatic isolation between hardware-described contexts, promised by
FEAT_CSV2/CSV2_2/CSV2_3(branch prediction) andFEAT_CSV3(faulting loads, 14.6). - Software-defined sub-contexts with
SCXTNUM_ELx, for isolation the hardware context cannot express. - Explicit restriction instructions in
FEAT_SPECRES/SPECRES2, for cases where a context identity is reused or where a predictor is not covered by layer 1.
Vector-entry mitigations for cores that lack layer 1 (BHB loops, SMCCC_ARCH_WORKAROUND_1/3) are in 14.4.
Layer 1: what CSV2 already gives you
The hardware-described context (14.1) is made of the Security state, the Exception level, the VMID where stage 2 applies, the ASID where the regime uses one, and, with FEAT_CSV2_2, SCXTNUM_ELx. On a CSV2 core, branch targets trained in one such context cannot exploitatively control speculation in another. Consequences:
- Non-secure ↔ Secure through EL3 is isolated for branch targets, because the Security state and EL differ. EL3 does not need to flush anything for branch-target prediction on a CSV2 core.
- Two VMs with different VMIDs are isolated, and so are two processes with different ASIDs.
- Two partitions or TAs that end up with the same VMID or ASID are not isolated, and neither is an ASID or VMID number reused for a new tenant after roll-over. As far as the hardware context is concerned, they are the same context. That is the gap layer 3 fills.
- CSV2 speaks about branch target prediction. Branch history is CSV2_3’s concern (14.4). Data value prediction and cache prefetch prediction are named separately by SPECRES.
Layer 2: SCXTNUM_ELx
SCXTNUM_EL0, SCXTNUM_EL1, SCXTNUM_EL2 and SCXTNUM_EL3 are 64-bit “software context number” registers. Software writes a value, and with FEAT_CSV2_2 (ID_AA64PFR0_EL1.CSV2 = 0b0010 or higher) the value becomes part of the hardware-described context for that EL. Two sandboxes in one process, such as a browser’s site-isolated JIT compartments, can then be separated without separate ASIDs.
ID_AA64PFR0_EL1.CSV2 | ID_AA64PFR1_EL1.CSV2_frac | SCXTNUM_ELx present? | Part of the context? |
|---|---|---|---|
0b0001 | 0b0000 or 0b0001 (CSV2_1p1) | No | — |
0b0001 | 0b0010 (CSV2_1p2) | Yes | No: the registers exist but give no isolation |
0b0010 (CSV2_2) or 0b0011 (CSV2_3) | — | Yes | Yes |
The CSV2_1p2 row is a trap. Software that writes SCXTNUM_EL0 there gets a working register and no protection. Decide from CSV2, not from whether the MSR succeeds.
Access controls follow the usual pattern of arriving trapped (2.6):
| Control | Effect when it blocks |
|---|---|
SCR_EL3.EnSCXT (bit 25) = 0 | EL0–EL2 accesses trap to EL3 (or are UNDEFINED where the register’s accessibility pseudocode selects that, via EL3SDDUndef()) |
HCR_EL2.EnSCXT (bit 53) = 0 | EL1 and EL0 accesses trap to EL2 (when EL2 is enabled) |
SCTLR_ELx.TSCXT (bit 20) = 1 | EL0 accesses to SCXTNUM_EL0 trap |
HFGRTR_EL2/HFGWTR_EL2.SCXTNUM_EL0/SCXTNUM_EL1 (FEAT_FGT) | Fine-grained traps to EL2 |
Bring-up note: Once EL3 sets
SCR_EL3.EnSCXT,SCXTNUM_EL0/EL1/EL2become per-world state, and EL3 must save and restore them on every world switch, like any other EL1/EL2 system register. Otherwise the Secure world inherits, and can read, the Non-secure world’s values, and the reverse. TF-A setsEnSCXTonly whenis_feat_csv2_2_supported(), and saves and restores all three in its EL1/EL2 context code. A port that enablesEnSCXTin a hand-rolled SCR value without extending the context is a cross-world leak of software state, and also of the isolation it was meant to provide. Their reset value is UNKNOWN, so initialise them before first entry to each world.
Few production stacks use SCXTNUM today. Linux does not program it for user space, and KVM traps guest access. For firmware the main obligations are therefore not to break it, by context-switching it, and not to rely on it for isolation that VMIDs, ASIDs or Security states already give.
Layer 3: FEAT_SPECRES restriction instructions
FEAT_SPECRES (ID_AA64ISAR1_EL1.SPECRES, bits [43:40], 0b0001) adds three SYS-space instructions. FEAT_SPECRES2 (SPECRES = 0b0010) adds a fourth. FEAT_SPECRES is permitted from v8.0 and mandatory from v8.5. FEAT_SPECRES2 is permitted from v8.0 and mandatory from v8.9/v9.4. The ID_AA64ISAR1_EL1.SPECRES description states both directly: from Armv8.5 the value 0b0000 is not permitted, and from Armv8.9 the value 0b0001 is not permitted. Cross-check against DDI0487 A2 for the issue you target.
| Instruction | Restricts |
|---|---|
CFP RCTX, Xt | Control-flow prediction (branch targets, history, return prediction) |
DVP RCTX, Xt | Data value prediction |
CPP RCTX, Xt | Cache prefetch prediction |
COSP RCTX, Xt (SPECRES2) | Other speculative prediction, meaning anything not covered by the three above |
GNU as needs +predres (and +predres2 for COSP).
The guarantee (paraphrasing the CFP description, the others are analogous): predictions determined by the actions of code in the target context before the instruction cannot be used to exploitatively control speculative execution after the instruction is complete and synchronized. Note what the descriptor names. It names the context whose learned state is to be neutralised, not the context to be protected. Whatever ran under that context identity earlier can no longer steer what runs afterwards, including a new owner of the same identity. That is exactly the identity-reuse gap left by layer 1. The implementation may invalidate entries, retag them or ignore them; the architecture does not say which.
The RCTX descriptor in Xt
| Bits | Field | Meaning |
|---|---|---|
| [63:49] | RES0 | |
| [48] | GVMID | 1 = all VMIDs (EL0/EL1 targets) |
| [47:32] | VMID | Target VMID when GVMID = 0 and the target is EL1, or EL0 outside the EL2&0 host regime |
| [31:28] | RES0 | |
| [27] | NSE | With FEAT_RME, selects the Security state together with NS |
| [26] | NS | Without RME: 0 = Secure, 1 = Non-secure |
| [25:24] | EL | Target EL: 0b00 EL0 … 0b11 EL3 |
| [23:17] | RES0 | |
| [16] | GASID | 1 = all ASIDs (EL0 target) |
| [15:0] | ASID | Target ASID when GASID = 0 |
Rules that matter in practice:
- Completion is local and needs a sequence. The effect is guaranteed only after a
DSBcovering reads and writes on the PE that executed it, followed by a context synchronization event. There is no broadcast form. A hypervisor recycling a VMID has to run the sequence on every PE that may have run the old tenant, typically lazily, on each PE’s next use of the new VMID generation, the same way a VMID roll-over TLB flush is handled. - A lower EL cannot target a higher one. Executed at an EL below the target EL, or for an unimplemented EL and Security state combination, the instruction is a NOP. There are further NOP cases for
NS/NSEat EL3. EL1 can therefore clean up for its own EL0/EL1 contexts, but not for EL2 or EL3. - Traps: at EL0, with
SCTLR_EL1.EnRCTX(bit 10) = 0 they trap to EL1 (or to EL2 whenHCR_EL2.TGE= 1) with EC0x18, not UNDEFINED; in the EL2&0 host regime,SCTLR_EL2.EnRCTX= 0 traps them to EL2. At EL1 they trap to EL2 under nested virtualization (HCR_EL2.NV) and throughHFGITR_EL2.CFPRCTX/DVPRCTX/CPPRCTXwith FEAT_FGT. - They are meant to be rare. Arm expects use “on the roll-over of an ASID or VMID”, not on every context switch.
// EL2: VMID generation roll-over, run on each PE before first use of the
// new generation. Target: all VMIDs, EL1, Non-secure.
mov x0, #(1 << 48) // GVMID = 1
orr x0, x0, #(1 << 26) // NS = 1
orr x0, x0, #(0b01 << 24) // EL = EL1
cfp rctx, x0
dvp rctx, x0
cpp rctx, x0
orr x1, x0, #(1 << 16) // same, EL0 with GASID = 1
and x1, x1, #~(0b11 << 24) // EL = EL0
cfp rctx, x1
dvp rctx, x1
cpp rctx, x1
dsb sy
isb
When EL3 or a hypervisor must issue them
| Situation | Who | Needed? |
|---|---|---|
| NS ↔ Secure (or Realm) world switch on a CSV2 core, contexts persistent | EL3 | No. The Security state already separates the contexts |
| Same, on a pre-CSV2 core | EL3 | Such cores are pre-v8.5 and usually lack SPECRES too, so use the 14.4 vector mitigations. Where SPECRES is present, EL3 could in principle target the Non-secure EL1/EL0 contexts on entry, but Arm says RCTX “should not be used on every context switch” |
| VMID roll-over or reuse for a different VM | EL2 (KVM, Hafnium-style SPMC at S-EL2, RMM at R-EL2 for Realm VMIDs) | Yes, all four (COSP with SPECRES2), on every PE, before the new tenant runs |
| ASID roll-over or reuse for a different process or TA | EL1 OS or Trusted OS | Yes, with GASID = 1 or the reused ASID |
| A Secure partition or payload replaced in place (new image, same S-EL1 context, same VMID or no EL2) | EL3 or SPMC | Yes, for the reused context, since it is the same identity with a new owner |
| Live firmware activation that replaces the EL3 image | EL3 | Not mandated anywhere, but by the same reasoning it is identity reuse for EL3 itself. Issue with EL = 0b11 from the new image |
| Sandboxes within one process | User runtime | Not RCTX. Use distinct SCXTNUM_EL0 values on CSV2_2 cores |
Security note: “Isolated by the Security state” is only as good as the identifiers below it. In the Secure world, OP-TEE or an SPMC that gives every TA or partition a distinct ASID or VMID gets layer 1 isolation between them for free. One that runs several partitions with the same VMID, or recycles ASIDs, needs RCTX on reuse. If you review an SPMC, ask how VMIDs are allocated and what happens when a partition is restarted.
Reading which mitigations a core needs
No single register gives the answer. Combine four sources, in this order:
- ID registers, the architectural promises. Probe these on every core type; never assume them from a version number (1.1).
| Field | Value means | Mitigation you can drop or must use |
|---|---|---|
ID_AA64PFR0_EL1.CSV2 [59:56] | ≥1 branch targets isolated; 2 adds SCXTNUM; 3 adds history | ≥1: no BTB flush on entry; 3: no BHB loop (14.4) |
ID_AA64PFR1_EL1.CSV2_frac [35:32] | 1p1/1p2 refinements | 1p2: SCXTNUM present but not isolating |
ID_AA64PFR0_EL1.CSV3 [63:60] | 1 = Meltdown-safe | No KPTI or S-EL0 unmapping for variant 3 (14.6) |
ID_AA64PFR1_EL1.SSBS [7:4] | 1 SSBS, 2 SSBS2 | Use DSSBS/PSTATE.SSBS instead of chicken bits (14.5) |
ID_AA64ISAR1_EL1.SB [39:36] | SB instruction | SB instead of DSB+ISB (14.3) |
ID_AA64ISAR1_EL1.SPECRES [43:40] | 1 CFP/DVP/CPP, 2 adds COSP | RCTX available for identity reuse |
ID_AA64MMFR1_EL1.ECBHB [63:60] | Restrictions on branch-history speculation around exceptions | No BHB sequence on entry (14.4) |
ID_AA64ISAR2_EL1.CLRBHB [31:28] | CLRBHB instruction | Single-instruction BHB clear (14.4) |
ID_AA64MMFR2_EL1.E0PD [63:60] | E0PD, and CSV3 implied | KPTI for KASLR not needed |
A value of 0 in CSV2 or CSV3 means not disclosed, not vulnerable. That is where the other sources come in.
- Arm’s security bulletins, the Speculative Processor Vulnerability list for each CVE, indexed by core. They are the authority for older cores that report 0.
- The TRM and SDEN for the exact MIDR variant and revision. These give the IMPLEMENTATION DEFINED parts: the BHB loop count k, chicken bits for v4, the CVE-2024-7881 prefetcher disable, and errata in the mitigations themselves, such as the SSBS self-synchronisation erratum in 14.5 (1.3).
- The firmware contract:
SMCCC_ARCH_FEATURESforSMCCC_ARCH_WORKAROUND_1/2/3/4, which tells a lower EL what EL3 has already done, plus the TF-A CPU library’sWORKAROUND_CVE_*build flags, which show what EL3 will do (12.3).
Validation note: Build the four-source table once per SoC and check it against the running system in both directions. Dump the ID fields above on every core type from EL3 at boot, and compare them with the sanitised values Linux reports (
/sys/devices/system/cpu/vulnerabilities/*, plusCPU featuresandSSBS/SBhwcaps). A mismatch usually means a heterogeneous cluster where one core lacks a feature the boot core has. For SCXTNUM, write distinct values in the Secure and Non-secure worlds and check that each world reads back its own value after a round trip through EL3. A failure means the context code is missing them. For RCTX, an architectural test can only check that the instructions execute without trapping at the intended EL, trap with EC0x18from EL0 whenSCTLR_EL1.EnRCTX= 0, and are NOPs when the target EL is above the executing EL. Their effect is visible only in a predictor-training test on silicon or RTL. In that test, theBR_MIS_PRED(0x10) count for a victim branch should return to its untrained level afterCFP RCTXand theDSB/ISB(16.5).
Checkpoint
Q14.7.1 On a FEAT_CSV2_2 core, an SPMC at S-EL2 restarts a crashed Secure partition by reloading its image into the same memory and reusing its VMID. Which action restores prediction isolation between the old and new instance?
- A. None. The Security state already separates them
- B.
TLBI VMALLS12E1for that VMID, because TLB invalidation also invalidates branch predictors - C.
CFP/DVP/CPPRCTX(andCOSPwith SPECRES2) targeting that VMID at EL1 and EL0, thenDSBandISB, on each PE that may have run the old instance - D. Write a new value to
SCXTNUM_EL3
Answer
C. The old and new instances share every element of the hardware-described context, so CSV2 does not separate them. RCTX stops predictions learned in the named context before the instruction from steering later execution. It completes only locally, after a DSB, and takes effect after a context synchronization event. A is the tempting answer, but the Security state is the same for both instances. TLB maintenance has no architectural effect on predictors. SCXTNUM_EL3 affects only EL3’s own context.
Read more: Arm ARM (DDI0487), CFP RCTX; Restrictions on the effects of speculation
Q14.7.2 A core reports ID_AA64PFR0_EL1.CSV2 = 0b0001 and ID_AA64PFR1_EL1.CSV2_frac = 0b0010. A JIT runtime writes a different SCXTNUM_EL0 per sandbox, and the MSRs succeed. What isolation does it get between sandboxes?
- A. Full branch-target isolation, because the registers are implemented
- B. None from SCXTNUM. On CSV2_1p2 the registers exist but are not part of the hardware-described context
- C. Isolation for branch history, but not for branch targets
- D. Isolation only if
SCTLR_EL1.TSCXTis 1
Answer
B. Only FEAT_CSV2_2 and later make SCXTNUM_ELx part of the context. CSV2_1p2 provides the registers alone. A is the tempting answer, because the register works and the protection silently does not. TSCXT = 1 would trap EL0 accesses, not enable isolation.
Read more: Arm ARM (DDI0487), ID_AA64PFR1_EL1.CSV2_frac; SCXTNUM_EL0
Q14.7.3 A Non-secure EL1 kernel executes CFP RCTX with EL = 0b11 (EL3) after a firmware update, intending to clear EL3’s predictions. What happens?
- A. EL3’s control-flow predictions are restricted on this PE after
DSB+ISB - B. The instruction traps to EL3, which performs it on the kernel’s behalf
- C. EL3’s predictions are restricted on all PEs in the Inner Shareable domain
- D. It executes as a NOP, because a lower EL cannot target a higher EL’s context
Answer
D. RCTX executed at an EL below the target EL is treated as a NOP. Only EL3 can clean up for EL3, for example as part of its own activation sequence. A is what the kernel intended. C is wrong twice: there is no broadcast form, and the instruction would not target EL3 from EL1 in any case.
Read more: Arm ARM (DDI0487), CFP RCTX, Control Flow Prediction Restriction by Context