15.3 Firmware responsibilities
FP, SVE and SME follow the rule set out in 2.6: the feature arrives trapped or disabled, and each higher Exception level must enable it for the levels below. EL3 is at the top of that chain. Its registers reset to UNKNOWN values, so nothing works until EL3 writes them. EL3 also owns the hard part, because all worlds share one register file and only EL3 sees every world switch. This section covers what EL3 and EL2 must program, how TF-A organises the per-world state, and what a missing bit looks like. 17.3 has the full FEAT_-to-enable-bit table; only the FP/SVE/SME rows are covered here.
The EL3 controls
| Feature | Present if | EL3 enable | Also program | Trap when missing |
|---|---|---|---|---|
| FP/Advanced SIMD | ID_AA64PFR0_EL1.FP/AdvSIMD ≠ 0b1111 | CPTR_EL3.TFP=0 (bit 10) | EC 0x07 to EL3 | |
| SVE | ID_AA64PFR0_EL1.SVE ≠ 0 | CPTR_EL3.EZ=1 (bit 8) | ZCR_EL3.LEN (VL cap) | EC 0x19 to EL3 |
| SME | ID_AA64PFR1_EL1.SME ≠ 0 | CPTR_EL3.ESM=1 (bit 12) | SMCR_EL3.LEN, .FA64 | EC 0x1D, SMTC 0, to EL3 |
| SME2 (ZT0) | ID_AA64PFR1_EL1.SME ≥ 2 | SMCR_EL3.EZT0=1 (bit 30) | EC 0x1D, SMTC 4, to EL3 | |
TPIDR2_EL0 | SME | SCR_EL3.EnTP2=1 (bit 41) | EC 0x18 to EL3 | |
FPMR | ID_AA64PFR2_EL1.FPMR ≠ 0 | SCR_EL3.EnFPM=1 (bit 50) | EC 0x18 to EL3 (direct access); an FP8 instruction is UNDEFINED instead (EC 0x00, taken to the current EL, or EL1/EL2 from EL0) |
Several details in this table are commonly got wrong:
- Opposite polarities.
TFPtraps when 1.EZandESMenable when 1. A zeroedCPTR_EL3therefore enables FP but traps SVE and SME. - The traps also apply to EL3 itself. The pseudocode for these checks tests
CPTR_EL3whatever the current EL is. WithEZ=0, anMSR ZCR_EL3or an SVE instruction executed at EL3 traps to EL3. So the order is: writeCPTR_EL3, thenISB, then programZCR_EL3/SMCR_EL3. The same applies toESMandSMCR_EL3. ZCR_EL3.LENandSMCR_EL3.LENcap every lower EL. EL3 should normally set the maximum value,0xF, and leave lower ELs to restrict further. A lower cap at EL3 is a platform decision: TF-A exposes it asSVE_VECTOR_LEN. One reason to use it is a system whose cores support different VLs, because Linux requires every CPU to support the vector lengths it has already committed to and rejects a late CPU that does not.- SVE implies FP. SVE instructions are checked against the FP controls as well (15.2), so
EZ=1withTFP=1still traps SVE, with EC0x07. FA64is a policy choice, not a fix. Setting it where FEAT_SME_FA64 is implemented lets streaming code use the full A64 ISA. Where it is not implemented the bit is RES0, so firmware must checkID_AA64SMFR0_EL1.FA64rather than set it blindly.
A minimal cold- and warm-boot sequence, before any lower EL runs, looks like this:
mrs x0, id_aa64pfr0_el1
mrs x1, id_aa64pfr1_el1
mov x2, #0 // CPTR_EL3 resets UNKNOWN: build it from zero
// TFP = 0: FP/SIMD not trapped
// (TAM/TTA/TCPAC policy: see 17.2)
ubfx x3, x0, #32, #4 // ID_AA64PFR0_EL1.SVE
cbz x3, 1f
orr x2, x2, #(1 << 8) // EZ = 1
1: ubfx x4, x1, #24, #4 // ID_AA64PFR1_EL1.SME
cbz x4, 2f
orr x2, x2, #(1 << 12) // ESM = 1
2: msr cptr_el3, x2
isb // CPTR_EL3 write visible before ZCR/SMCR access
cbz x3, 3f
mov x5, #0xf
msr S3_6_C1_C2_0, x5 // ZCR_EL3.LEN = max
3: cbz x4, 4f
mov x5, #0xf // SMCR_EL3.LEN = max
mrs x6, S3_0_C0_C4_5 // ID_AA64SMFR0_EL1
tbz x6, #63, 5f // FA64 implemented?
orr x5, x5, #(1 << 31) // FA64 = 1 (policy choice)
5: cmp x4, #2 // SME2 or later?
b.lo 6f
orr x5, x5, #(1 << 30) // EZT0 = 1
6: msr S3_6_C1_C2_6, x5 // SMCR_EL3
4: isb
SCR_EL3.EnTP2 and EnFPM are per-world values. They belong in the SCR_EL3 that EL3 installs before each ERET, not in a one-off write at boot. Both CPTR_EL3 and these SCR_EL3 bits must be reprogrammed on every warm boot, because they are lost when the core powers down (17.4).
EL2: present or unused
When a hypervisor runs at EL2, it owns CPTR_EL2, ZCR_EL2, SMCR_EL2 and HCRX_EL2.EnFPM, and it typically uses them for lazy switching of guest state (15.1). EL3’s only job is to leave EL2 able to use them. When EL2 is implemented but no EL2 software will run, and the Normal world enters at EL1, EL3 must program EL2 itself, because the EL2 controls still apply to EL1 and EL0 and they reset to UNKNOWN values. TF-A does this under INIT_UNUSED_NS_EL2.
Bring-up note: With
HCR_EL2.E2H=0,CPTR_EL2bits [9:0] and 12–13 are RES1 except where a feature gives them a meaning: bit 8 isTZwhen SVE is implemented and bit 12 isTSMwhen SME is implemented. Firmware that writes “the RES1 mask” from the register description therefore setsTZ=1andTSM=1, and traps SVE and SME. TF-A writes that mask and then clearsTZexplicitly insve_init_el2_unused(). If an EL1 kernel takes EC0x19or0x1Dto an EL2 that nobody installed, look here first.
Per-world context in TF-A
TF-A splits EL3-owned state into two kinds. Per-world values are identical on every CPU for a given world and live in per_world_context[] (lib/el3_runtime/aarch64/context_mgmt.c). They are currently ctx_cptr_el3 and ctx_mpam3_el3. Per-CPU, per-world values live in each cpu_context_t. They include the SCR_EL3 image that carries EnTP2 and EnFPM. While EL3 itself runs, TF-A installs a separate root context: CPTR_EL3 has TFP=1, so stray FP use in EL3 C code traps, and EZ=1/ESM=1, so EL3 can still access ZCR_EL3/SMCR_EL3. On exit, TF-A writes the target world’s ctx_cptr_el3 before the ERET.
The feature modules set the per-world values:
| Function | Effect |
|---|---|
sve_init_el3() | ZCR_EL3.LEN from SVE_VECTOR_LEN |
sve_enable_per_world() / sve_disable_per_world() | set / clear CPTR_EL3.EZ for a world |
sme_init_el3() | SMCR_EL3.LEN = max, FA64 and EZT0 if implemented |
sme_enable_per_world() / sme_disable_per_world() | set ESM / clear ESM and EZ |
sme_enable(ctx) / sme_disable(ctx) | set / clear SCR_EL3.EnTP2 in a CPU context |
The build options choose the policy:
| Option | Meaning |
|---|---|
ENABLE_SVE_FOR_NS, ENABLE_SME_FOR_NS, ENABLE_SME2_FOR_NS | Enable the feature for the Normal world (SME requires SVE). Values 0/1/2 follow the FEATURE_DETECTION convention: 2 means “check the ID register at runtime”. |
ENABLE_SVE_FOR_SWD, ENABLE_SME_FOR_SWD | Also enable it for the Secure world. The SPMC or Secure OS must then manage the state. |
ENABLE_FEAT_FPMR | Set SCR_EL3.EnFPM |
CTX_INCLUDE_FPREGS | EL3 saves and restores V0–V31, FPSR, FPCR on world switch |
CTX_INCLUDE_SVE_REGS | EL3 saves Z, P and FFR at SVE_VECTOR_LEN. Requires ENABLE_SVE_FOR_SWD, and is mandatory when CTX_INCLUDE_FPREGS and ENABLE_SVE_FOR_NS are both set |
SVE_VECTOR_LEN | The ZCR_EL3 cap, default 2048 |
The default Secure-world policy is worth reading closely. With ENABLE_SVE_FOR_SWD=0, TF-A clears EZ (and ESM) for the Secure world but leaves TFP=0. Secure code can still execute FP/Advanced SIMD instructions, and each such write zeroes the upper bits of the Normal world’s Z registers (15.1). The policy is safe only if the Secure world never touches FP, or saves it at the full SVE width (which needs SVE enabled for it, ENABLE_SVE_FOR_SWD=1), or EL3 does (CTX_INCLUDE_SVE_REGS, which also requires ENABLE_SVE_FOR_SWD=1). TF-A’s documentation recommends doing the save in the lower EL, because the EL3 buffers are large: at a VL of 2048 bits, each world needs about 8.7 KB per CPU for SVE alone.
When the SPMD sits between the worlds, a cheaper option exists. SMCCC v1.3 defines bit 16 of the function ID as the SVE live-state hint. A caller that sets it declares that no SVE state above the 128-bit V registers, and no P or FFR state, needs preserving across the call. The SPMD reads the hint (is_sve_hint_set()), passes it to the SPMC, and uses it to skip the wide part of the save. For Realms, TF-A enables SVE and SME in the Realm world’s CPTR_EL3, and the RMM saves and restores whatever Normal-world state it overwrites (12.4).
SME across a world switch
TF-A’s SIMD context (simd_regs_t) covers V/Z, P, FFR, FPSR, FPCR and, for AArch32, FPEXC32. It does not cover SVCR, ZA, ZT0 or FPMR. The SME state is left to the lower-EL managers. This has three consequences for anyone porting a Secure OS or SPMC to an SME part:
- An
SMCcan arrive withPSTATE.SM=1and/orPSTATE.ZA=1, because exceptions do not change them (15.2). The Secure world then starts in streaming mode. Its first Advanced SIMD vector instruction traps (SMTC 1, unless FA64 is enabled), and a Z-register save runs at SVL instead of VL. - A Secure-world
SMSTOPthat leaves streaming mode zeroes the Normal world’s Z, P, FFR andFPMRand rewrites itsFPSR. A Secure-worldSMSTOP ZAdiscards the Normal world’s ZA. Either must be preceded by a save, at SVL, of everything the Normal world could own. TPIDR2_EL0is an EL0 register that EL3 does not switch. A Secure world that runs S-EL0 code using SME must save and restore it, or the Normal world’s lazy-save chain is corrupted.
The simplest correct policy for most products is the default: Secure and Realm code that does not need SME does not get it (ESM=0 for that world), and whichever manager first uses FP state in another world saves the Normal world’s state at the widest length currently in effect.
What a missing bit looks like
| Symptom | Likely cause |
|---|---|
Normal-world kernel hangs or panics at EL3 during early boot, with an unhandled EC 0x19 in the EL3 crash dump | CPTR_EL3.EZ=0 while Linux probes SVE: it reads ZCR_EL1 and executes RDVL at boot if the ID registers report SVE |
EC 0x1D with SMTC 0 at EL3 | CPTR_EL3.ESM=0 with ID_AA64PFR1_EL1.SME reporting SME |
EC 0x18 at EL3 with the TPIDR2_EL0 or FPMR encoding in the ISS | SCR_EL3.EnTP2 or EnFPM missing from that world’s SCR_EL3 |
Works on cold boot, fails after CPU_SUSPEND or hotplug | Enable bits written once at boot, not restored on the warm-boot path |
| Normal-world SVE data randomly loses its high bits | A Secure or Realm service uses FP with no SVE-width save anywhere |
| Linux reports a smaller VL than the core supports | ZCR_EL3.LEN/SVE_VECTOR_LEN or SMCR_EL3.LEN capped at EL3, or a hypervisor cap in ZCR_EL2 |
Linux sanitises the ID registers (1.1), but it trusts them. If the ID register reports SVE and EL3 traps it, the kernel does not degrade gracefully: it takes the trap at the first probe. A hypervisor can hide the feature from a guest by trapping and emulating ID_AA64PFR0_EL1 (HCR_EL2.TID3). EL3 cannot hide a feature from EL2 that way unless FEAT_IDTE3 is implemented (17.3). The practical rule is therefore: enable every feature that the ID registers advertise, or make the platform’s ID values match what you enable.
Validation note: For each world, run a directed test at the lowest EL that executes one FP instruction, one SVE instruction (
RDVL),SMSTART/SMSTOP, one ZT0 access, anMRSofTPIDR2_EL0and anMRSofFPMR. Expect either success or the documented trap for that world’s policy, never a trap to EL3. Repeat afterCPU_SUSPENDto power-down and afterCPU_OFF/CPU_ON. Then test cross-world integrity. FillZ0–Z31with patterns in the Normal world at the maximum VL, call an SMC handled by a Secure service that executes Advanced SIMD instructions, and compare. A mismatch above bit 127 shows that the save policy is broken, not the hardware.
Checkpoint
Q15.3.1 EL3 boot code executes MOV x0, #0xF; MSR ZCR_EL3, x0 and only afterwards sets CPTR_EL3.EZ=1. On the first boot of an SVE part it takes an exception straight away. Why?
- A.
ZCR_EL3is write-once after reset and was already written by the boot ROM - B.
CPTR_EL3.EZ=0traps accesses toZCR_EL3even from EL3, so the write traps to EL3 (EC0x19) beforeEZis set - C. The
ISBbetween the two writes is missing, so theZCR_EL3write is UNPREDICTABLE - D.
ZCR_EL3.LEN=0xFrequests 2048 bits, which is larger than the implementation supports, and an unsupported length faults
Answer
B. The SVE enable check tests CPTR_EL3.EZ regardless of the current EL, and the CPTR_EL3 reset value is UNKNOWN, so it may well be 0. EL3 must set EZ first, then ISB, then write ZCR_EL3. D is wrong because LEN is a request: the PE uses the largest supported length that does not exceed it, and setting the maximum is the recommended EL3 value.
Read more: Arm ARM (DDI0487), CPTR_EL3, ZCR_EL3, CheckSVEEnabled() pseudocode
Q15.3.2 TF-A is built with ENABLE_SVE_FOR_NS=1, ENABLE_SVE_FOR_SWD=0, CTX_INCLUDE_FPREGS=0. OP-TEE at S-EL1 uses Neon for a hash. A Normal-world SVE application occasionally sees corrupted vectors. Which change actually fixes the problem?
- A. Set
CTX_INCLUDE_FPREGS=1, so that EL3 saves V0–V31 around the Secure call - B. Set
ENABLE_SVE_FOR_SWD=1, so that OP-TEE’s Neon instructions trap - C. Make Normal-world Z, P and FFR state survive at full width: either OP-TEE saves and restores it before using Neon (it then needs SVE access,
ENABLE_SVE_FOR_SWD=1), or EL3 does (CTX_INCLUDE_SVE_REGS=1, which requiresENABLE_SVE_FOR_SWD=1) - D. Set
SVE_VECTOR_LEN=128, so that Z and V are the same size
Answer
C. With SVE disabled for the Secure world, TF-A clears only EZ, and Advanced SIMD remains usable. Each Neon write zeroes the bits of the Normal world’s Z registers above bit 127. A saves only the 128-bit view, which is exactly the combination TF-A forbids without CTX_INCLUDE_SVE_REGS. B gets the effect backwards: enabling SVE for the Secure world removes a trap, it does not add one, and Neon is governed by TFP in any case. D hides the problem by throwing away the SVE width for everyone, at a large performance cost, so it is not a fix.
Read more: TF-A build options, ENABLE_SVE_FOR_SWD, CTX_INCLUDE_SVE_REGS; Arm ARM (DDI0487), SVE registers
Q15.3.3 A product enables SME for the Normal world only. A Normal-world thread in Streaming SVE mode, with ZA active, makes an FF-A call. The SPMC at S-EL2 uses Advanced SIMD vector instructions in its message-copy path. What happens first, and why?
- A. The SPMC’s first Advanced SIMD vector instruction traps with EC
0x1D, SMTC 1, unless FA64 is enabled, becausePSTATE.SMis still 1 after the exception and the world switch - B. Nothing goes wrong, because EL3 clears
PSTATE.SMandPSTATE.ZAon every world switch - C. The SPMC’s instruction traps with EC
0x1D, SMTC 0, becauseESM=0for the Secure world, and that check takes priority over everything - D. The SMC itself is rejected, because SMC is illegal in Streaming SVE mode
Answer
A. Exception entry, ERET and EL3’s world switch leave SVCR unchanged, and TF-A does not save or restore it. The Secure world therefore runs in streaming mode, where most Advanced SIMD vector instructions are illegal. C is tempting, but ESM is checked only for SVE and SME instructions and SME register accesses. The pseudocode checks an Advanced SIMD instruction against the FP controls (FPEN/TFP, which allow it here) and then for legality in Streaming SVE mode, and that second check raises SMTC 1 at the current EL. A Secure-world SVE instruction would instead trap to EL3 with SMTC 0. Either way, the Secure-world code must handle entry with SM=1. B is false for TF-A. D is false: SMC is legal in streaming mode.
Read more: Arm ARM (DDI0487), SVCR, Streaming SVE mode instruction legality; TF-A simd_ctx.h