Privileged Architecture

The KLE Privileged Architecture provides CSRs; this chapter also defines the KLE exception causes, implemented by every hart.

Extension Overview

Table 1. Extensions of the Privileged Architecture
Extension Features Defined in:

Smklstatus

The *llockerstatus per-locker status-tracking CSRs.

mllockerstatus, sllockerstatus, and vsllockerstatus for Dirtiness Tracking

Ssklstatus

The supervisor-visible part of Smklstatus: sllockerstatus and, with the H extension, vsllockerstatus.

mllockerstatus, sllockerstatus, and vsllockerstatus for Dirtiness Tracking

Smklcsk

The CSR group that configures the Context Sealing Key.

mklcsk CSR Group

Smklpbootscrt

The CSR group that configures the Physical Boot Secret Locality (Locality Field).

mklphysbootscrt

Ssklvbootscrt

The CSR group that configures the Virtual Boot Secret Locality (Locality Field).

hklvirtbootscrt

Smkllclt

The CSR groups that configure the software binding Localities (Locality Field).

mkllocality, hkllocality, and skllocality

Sskllclt

The supervisor-visible part of Smkllclt: hkllocality and skllocality.

hkllocality and skllocality

Smklstatus implies Ssklstatus, and Smkllclt implies Sskllclt, on every hart that implements S-mode; an OS or hypervisor depends only on the Ss extensions.

The KLE Privileged Architecture is implemented on a hart whose mstatus implements the KLS field. It is mandatory on every hart that is not M-mode-only, and optional on an M-mode-only hart. The KLE exceptions of Exceptions Raised by KLE exist on every hart, whether or not it implements the KLE Privileged Architecture. Where the KLE Privileged Architecture is not implemented:

  • KLS is not present, and is treated as Initial;

  • Smklstatus and Ssklvbootscrt are not implemented; and

  • the mklcsk, mklphysbootscrt and mkllocality groups may be implemented or not, each where its extension is implemented, with the accessibility that mklcsk CSR Group and Locality Secret CSR Groups prescribe.

On an M-mode-only hart, none of the extensions in the table above is mandatory. Smklcsk and Smklpbootscrt are allowed in every configuration; with Smklpbootscrt, the mklphysbootscrt CSR group sets the Physical Boot Secret Locality. The requirements for the other extensions are:

Table 2. Privileged requirements, per system configuration
Extension →
Configuration ↓
Smklstatus Smkllclt Ssklvbootscrt

M-mode only

Optional: If implemented, mllockerstatus is implemented; sllockerstatus is not.

Optional: If implemented, mkllocality configures MLocality

M+U

Mandatory: mllockerstatus is implemented; sllockerstatus is not.

Optional: If implemented, mkllocality configures MLocality

M+S+U

Mandatory: mllockerstatus and sllockerstatus (Ssklstatus) are implemented and are distinct.

Optional: If implemented, mkllocality and skllocality (Sskllclt) configure MLocality and SLocality

M+S+U with H

Mandatory: mllockerstatus, sllockerstatus and vsllockerstatus (the latter two Ssklstatus) are implemented and are distinct.

Optional: If implemented, mkllocality, hkllocality and skllocality (the latter two Sskllclt) configure MLocality, HLocality and SLocality

Optional: If implemented, hklvirtbootscrt configures the Virtual Boot Secret Locality

The last two columns give the CSR groups implemented with the extension, and the Localities they set (Locality Field); an empty cell means the extension has no effect in that configuration.

Exceptions Raised by KLE

This section describes the error conditions that raise exceptions, not those that set an Error State (State and StateExtension Fields).

When an exception is raised, *cause holds the cause, as Table 3 describes; the table lists the causes in decreasing priority order.

The KLE fatal-error exception precedes every exception that depends on the state of the KLE unit, including the address-misaligned, access-fault and page-fault exceptions of KLE memory instructions, whose transfer bounds are computed from that state (kl.mvin and kl.mvout); it is preceded only by the exceptions of the instruction fetch and by the illegal-instruction or virtual-instruction exceptions of the First Group of Illegal-Instruction Exception Grounds, and precedes the other illegal-instruction grounds.

Table 3. Exception causes in decreasing priority order
Exception Code(s) Mnemonic/RISC-V type Examples in KLE

3

Instruction address breakpoint

As per the Privileged Specification.

12, 20, 1

Instruction page, guest-page, instruction access faults

As per the Privileged Specification.

2, 22

Illegal-instruction, virtual-instruction

One of the conditions in the First Group of Illegal-Instruction Exception Grounds is satisfied.

TBD

KLE fatal-error

Fatal system failure in the KLE unit.

2

Illegal-instruction

One of the conditions in the Second Group of Illegal-Instruction Exception Grounds is satisfied.

TBD

KLE missing-CSK

Use of the KLE unit while no CSK is active: either none has been established, or the mklcsk group is only partially written (see Architectural Requirements on the Context Sealing Key, mklcsk CSR Group). Only M-mode can write the mklcsk group or control implementation-specific components that set the CSK.

TBD

KLE locker-Off

Any access, as defined in mllockerstatus, sllockerstatus, and vsllockerstatus for Dirtiness Tracking, to a locker whose *llockerstatus field is Off; it reaches the mode that owns the Off field by delegation or forwarding. This exception enables on-demand (lazy) locker loading and trap-and-emulate.

2

Illegal-instruction

One of the conditions in the Third Group of Illegal-Instruction Exception Grounds is satisfied.

3

Load/store address breakpoint

On the address of the first component access of kl.load or kl.store, before the address-misaligned check (GR12, item 8).

4, 6

Load address misaligned, Store/AMO address misaligned

On the effective address of kl.load, resp. kl.store, with klnamedlocker < 32, before any component access (GR12); never raised by a KLE memory instruction with klnamedlocker = 32.

2

Illegal-instruction

One of the conditions in the Fourth Group of Illegal-Instruction Exception Grounds is satisfied, in the order of Rule GR13.

TBD

KLE unsupported-Metadata

Unsupported Metadata (Validity of Metadata) when opening a provisioning or import.

TBD

KLE privilege-violation

A usage instruction that the UsagePolicy denies (GR17), or any use, clone or restriction of a locker in a Configuration State, which is forbidden at all privilege levels (Rule GR13.3).

TBD

KLE clock-unavailable

With Zklexpire, a usage instruction on a locker with a non-zero ExpirationDate while the secure clock cannot be read (ExpirationDate Field).

TBD

KLE out-of-memory

Insufficient KLF capacity when opening a provisioning or import, or cloning.

TBD

KLE RBG-unavailable

Random bits that an operation needs remain unavailable past the implementation-defined bound of Rule GR45.

3

Load/store address breakpoint, later components

On the address of a later component access of kl.load or kl.store, and of any component access of kl.input or kl.output, when that access is about to be performed.

13, 15, 21, 23, 5, 7

Load/store page fault, load/store guest-page fault, load/store access fault

Per component access, in offset order, as ordered by the Privileged Specification.

kl.load and kl.input raise the load causes (4, 13, 21, 5), and kl.store and kl.output the store/AMO causes (6, 15, 23, 7). The relative order of the standard exceptions is that of the Privileged Specification, reproduced for reference only; the load/store address breakpoint and the load/store faults are evaluated per component access, because the component addresses of a KLE memory instruction are determined from the state of the KLE unit.

The medeleg and hedeleg bits of all KLE exceptions follow the standard ISA definition and so may be read-only zero or writable, but never read-only one.

CSRs

KLE extends *status and misa, and provides up to 21 direct CSRs (38 when MXLEN and SXLEN are 32, counting the high shadows).

Table 4. KLE Privileged CSRs
Address Privilege Field Description

TBD

MRW

mklmaxiobuflen

Maximum length of the KLIOBUF, in bytes; with Zklio only (mklmaxiobuflen).

TBD

MRW

mllockerstatus

Per-locker dirtiness and accessibility tracking below M-mode; supports on-demand locker loading.

TBD

MRW

mllockerstatush

MXLEN = 32 only: Shadow of the top 32 bits of mllockerstatus.

TBD

SRW

sllockerstatus

Per-locker dirtiness and accessibility tracking below S-mode; supports on-demand locker loading.

TBD

SRW

sllockerstatush

SXLEN = 32 only: Shadow of the top 32 bits of sllockerstatus.

TBD

HRW

vsllockerstatus

Per-locker dirtiness and accessibility tracking below VS-mode; supports on-demand locker loading.

TBD

HRW

vsllockerstatush

SXLEN or VSXLEN = 32 only: Shadow of the top 32 bits of vsllockerstatus.

TBD

MRO

mklvendorid

JEDEC manufacturer ID of the KLE unit provider.

TBD

MRO

mklarchid

Base microarchitecture of the KLE unit.

TBD

MRO

mklimpid

Version of the KLE unit implementation.

TBD(4)

MRW

mklcsk{0..3}

KLE Context Sealing Key.

TBD(4)

MRW

mklcsk{0..3}h

MXLEN = 32 only: Shadows of the top 32 bits of mklcsk{0..3}.

TBD(2)

MRW

mklphysbootscrt{0..1}

Locality: Physical (host) Boot Session Secret.

TBD(2)

MRW

mklphysbootscrt{0..1}h

MXLEN = 32 only: Shadows of the top 32 bits of mklphysbootscrt{0..1}.

TBD(2)

HRW

hklvirtbootscrt{0..1}

Locality: Virtual (guest) Boot Session Secret.

TBD(2)

HRW

hklvirtbootscrt{0..1}h

SXLEN = 32 only: Shadows of the top 32 bits of hklvirtbootscrt{0..1}.

TBD(2)

MRW

mkllocality{0..1}

Locality: Mutually isolate processes below M-mode.

TBD(2)

MRW

mkllocality{0..1}h

MXLEN = 32 only: Shadows of the top 32 bits of mkllocality{0..1}.

TBD(2)

HRW

hkllocality{0..1}

Locality: the hypervisor’s tag on its virtual machines, separating them from each other.

TBD(2)

HRW

hkllocality{0..1}h

SXLEN = 32 only: Shadows of the top 32 bits of hkllocality{0..1}.

TBD(2)

SRW

skllocality{0..1}

Locality: Mutually isolate the OS’s processes.

TBD(2)

SRW

skllocality{0..1}h

SXLEN = 32 only: Shadows of the top 32 bits of skllocality{0..1}.

Each of the 64-bit CSRs mllockerstatus, sllockerstatus and vsllockerstatus that is implemented is accompanied, when MXLEN, resp. SXLEN, is 32, by a 32-bit CSR, mllockerstatush, resp. sllockerstatush, vsllockerstatush, which accesses bits [63:32]; the CSR itself then accesses bits [31:0]. vsllockerstatush also exists when VSXLEN is 32: while V=1, an access to sllockerstatush then accesses it, as one to sllockerstatus accesses vsllockerstatus. In this Book, RV32 and RV64 denote an XLEN of 32, resp. 64, in the privilege mode that accesses the CSR.

None of these CSRs, including the mklcsk group, is available without the KLE extension, or while a KLS field in effect is Off (KLE field in misa, KLE Context Status in mstatus and sstatus, KLE Context Status in vsstatus): an access then raises an illegal-instruction exception, a condition evaluated after the Smstateen check below, where implemented, and before the privilege check. An access from a mode below the privilege of the CSR also raises an illegal-instruction exception, or, while V=1, the virtual-instruction exception that the H extension prescribes where HS-mode would allow the access. Where Smstateen is implemented, the KLE bit (to be allocated) of mstateen0, hstateen0 and sstateen0 gates every KLE instruction and every KLE CSR in the modes below the register’s own; a clear bit makes the instruction or access raise the exception that extension prescribes: an illegal-instruction exception, or a virtual-instruction exception for an hstateen0 denial while V=1. These exceptions are decided without accessing the KLE unit, are grounds of the First Group of Illegal-Instruction Exception Grounds, and precede every other KLE condition.

KLE field in misa

Bit L (11) of misa indicates that the KLE extension is present; if KLE is implemented, it must not be read-only zero.

M-mode firmware that provides an emulated KLE unit may set this bit to 1. It must not clear misa.L without first zeroizing all KLE state, emulated or in hardware (kl.clearall and the CSRs of KLE Unprivileged State out of Reset); while misa.L is clear, the KLE state is inaccessible, and need not be retained.

mklvendorid, mklarchid, and mklimpid

mklvendorid, mklarchid and mklimpid identify the version of the KLE unit, as mvendorid, marchid and mimpid do for the hart. They are part of Zkl common. Their values out of KLE unit reset identify the KLE unit. Where M-mode software emulates the unit, in whole or in part, it keeps the IMPQUAL it uses in its own memory, or takes it from these CSRs of the hardware part; no other mode reads it. They are read-only and M-mode-only: a write in any mode, and any access from a lower mode, raises an illegal-instruction exception, or the virtual-instruction exception of the H extension where it prescribes one.

  1. mklvendorid is a 32-bit register holding the JEDEC manufacturer ID of the KLE unit provider, or 0 if non-commercial, in the JEDEC bank/offset encoding of mvendorid in the Privileged ISA.

  2. mklarchid is a 32-bit register encoding the base microarchitecture of the KLE unit, as marchid does in the Privileged ISA. Bit 31 is 0 for an open-source architecture ID, which RVI allocates globally, and 1 for a commercial one, which is specific to the mklvendorid.

  3. mklimpid is a 32-bit register uniquely encoding the version of the KLE unit implementation, as mimpid does for the hart in the Privileged ISA; it reads 0 if not implemented; an implementation that produces an ADS must not do this. Its value reflects the design of the KLE unit itself, not of the surrounding system.

On RV64, a read of any of these three CSRs returns its 32-bit value zero-extended to XLEN.

Together, the values of these three CSRs form the Implementation Qualifier (AuxDataLen and ADSDropped Fields).

KLE Context Status in mstatus and sstatus

mstatus[26:25] holds a KLE context status field, KLS, shadowed in sstatus[26:25]. Defined like the floating-point and vector context status fields FS and VS, it tracks the dirtiness of the lockers, the KLIOBUF and every writable KLE-specific CSR other than the mklcsk group. mstatus.KLS is always in effect; when V=1, the vsstatus.KLS field of KLE Context Status in vsstatus is also in effect.

Table 5. Encoding of the KLS field
Value Name Meaning

0

Off

KLE disabled. The KLE state is inaccessible: KLE instructions and every KLE CSR access raise an illegal-instruction exception. This holds also for a CSR that M-mode emulates under kleemulation (KLE Emulation Control in mstatus): M-mode keeps medeleg bit 2 zero, so it takes the exception and decides whether to complete the access.

1

Initial

KLE enabled. Every locker is Unconfigured, and every other state tracked by the field holds its reset value. The hart may issue any KLE instruction.

2

Clean

KLE enabled. The state tracked by the field is potentially different from its reset value, but matches the last context swap.

3

Dirty

KLE enabled. At least one locker, KLIOBUF, or KLE-specific CSR may have changed since the last context swap. A locker that was configured and is now Unconfigured also makes KLS Dirty, since context-switch code must erase its stale saved state.

The following holds for every KLS field, in the privilege modes in which it is in effect:

  • If a field in effect is Off, every KLE instruction and every access to a KLE CSR raises an illegal-instruction exception.

  • Where no field in effect is Off, an instruction that modifies KLE state sets every field in effect to Dirty. So does a software write to a *llockerstatus CSR or to a Locality CSR; context-restoring software must write KLS after those CSRs.

  • An implementation may set a KLS field, or a *llockerstatus field, to Dirty from Initial or Clean at any time, even without a state change. Setting a field to Dirty is not a change of KLE state for Rule GR16.

  • The *llockerstatus and KLS fields that an instruction sets to Dirty are set before any trap is taken on or after that instruction, and before any later instruction executes, including when the instruction continues in the background (Rule GR36) or is discarded and restarted (Rule GR32).

  • While a field is Dirty, the SD bit of the register holding it is 1; otherwise that SD is set in accordance with the existing specifications.

A hart that implements the KLE Privileged Architecture implements the KLS field in every *status register it implements. The field is present and writable while misa.L is clear, like FS and VS; an emulated KLE unit relies on this.

Precise management of mstatus.KLS is an optimization that software may use to reduce context-switch overhead.

A write to a KLS field modifies no KLE state: setting the field to Off, Initial or Clean does not clear the lockers, the KLIOBUF or the KLE CSRs, so any such state change must be explicit, and must precede the write.

KLE Emulation Control in mstatus

mstatus[27] holds kleemulation, a bit M-mode sets when it emulates Machines the KLE unit does not implement natively. It is not visible in sstatus or vsstatus, and it resets to 0. M-mode that sets kleemulation keeps medeleg bit 2 zero, so the exception reaches it, as for trap-and-emulate (Extensions Overview), and forwards any other illegal-instruction exception in software. It controls the Forms B and C of kl.avail and kl.size, which take an MDH supplied in registers rather than a locker (kl.avail and kl.size), once they reach the lookup of item 5 of kl.size; the earlier items, among them the 16 that kl.size returns for an MDH in an Error State, do not depend on which Machines are implemented:

  • while kleemulation is 1, such an instruction raises an illegal-instruction exception if the KLE unit does not natively implement the combination of Machine, MachinePolicy, MachineExtension, KeyType and SCProtection that the MDH carries, so M-mode can supply the value for an emulated Machine;

  • while kleemulation is 0, it returns 0 for such an MDH, as for any combination that is not implemented.

The position of kleemulation is provisional and will be assigned by the ARC (Discussion Points).

KLE Context Status in vsstatus

With the H extension, vsstatus[26:25] also holds a KLS field. When V=1, it is in effect together with mstatus.KLS, and KLE Context Status in mstatus and sstatus governs both.

mstatus.KLS and vsstatus.KLS are not KLE context state for state tracking, so a write to vsstatus.KLS does not set mstatus.KLS to Dirty.

mllockerstatus, sllockerstatus, and vsllockerstatus for Dirtiness Tracking

The 64-bit registers mllockerstatus, sllockerstatus, and vsllockerstatus track per-locker status, including dirtiness, at all levels below M-mode, S-mode, and VS-mode, respectively.

For each of these three CSRs

*llockerstatus(i) = *llockerstatus[2·i+1:2·i] is a two-bit field that holds the status of K(i), encoded as follows.

Table 6. Encoding of the *llockerstatus bits
Value Name Behavior

0

Off

The locker is inaccessible.

1

Initial

The locker is accessible and in an initial state as defined by software.

2

Clean

The locker is accessible and its state matches the last context swap.

3

Dirty

The locker is accessible and its state may not match the last context swap.

llockerstatus is evaluated after the illegal-instruction grounds that do not require KLE unit state (the Second Group of Illegal-Instruction Exception Grounds), and the KLE fatal-error and missing-CSK exceptions, but before all other conditions, including the Third Group of Illegal-Instruction Exception Grounds, the Fourth Group of Illegal-Instruction Exception Grounds and the conditions of Rule GR13.5. The hardware state of a locker with an Off field in effect is never consulted (but see kl.getmd below): conditions that depend on its contents are evaluated only after lazy loading or by the M-mode code that emulates the locker.

A KLE instruction accesses K(i) if it names the locker as an operand, directly or as KLNL while klnamedlocker = i (Rule GR4); if it is a kl.load, kl.store, kl.mvin or kl.mvout issued while klnamedlocker = i (Rule GR4); or if it is kl.clearall. An access to a locker with an Off field in effect raises a KLE locker-Off exception, except the accesses that item 6 of Rule GR12 exempts. A destructive configuration instruction, on a locker with an Off field in effect, sets every field in effect for the locker to Dirty, even if the locker was already Unconfigured, except a kl.clone, kl.rename or kl.swap with identical source and destination, which performs no operation (kl.clone, kl.rename, and kl.swap). An exempted instruction that raises an exception before its zeroizing step likewise sets no field: an instruction replaces Off with Dirty only if it has zeroized or overwritten the locker.

A mode whose Off mark has been replaced by Dirty treats the hardware locker as authoritative: a mode that held the authoritative image of the locker for lazy loading discards it, and M-mode, which alone emulates a locker, never again uses the emulated copy it held (Emulation of Unsupported Machines).

kl.getmd* on a locker with an Off field in effect traps like any other access. An implementation may return the MDH without trapping only if the result matches what the trap and subsequent restore would have produced.

A mode marks a locker Off only while it holds the authoritative image or emulates the locker; the hardware contents of an Off locker are never the sole copy of a CC. A handler that has not yet saved a locker leaves its field Clean or Dirty.

For mllockerstatus

When the privilege mode is (H)S, VS or U/VU:

  • an access to K(i) while mllockerstatus(i) is Off raises a KLE locker-Off exception; and

  • an instruction that modifies K(i) sets mllockerstatus(i) to Dirty.

A direct write to mllockerstatus(i) changes neither sllockerstatus(i) nor vsllockerstatus(i), where these are distinct registers (Table 2). mstatus.KLS is also in effect.

For sllockerstatus

When the privilege mode is VS, U or VU:

  • an access to K(i) while mllockerstatus(i) or sllockerstatus(i) is Off raises a KLE locker-Off exception; and

  • an instruction that modifies K(i) sets sllockerstatus(i) and mllockerstatus(i) to Dirty.

A direct write to sllockerstatus(i) changes neither mllockerstatus(i) nor vsllockerstatus(i) (if defined). mstatus.KLS, vsstatus.KLS when V=1, and mllockerstatus are also in effect.

For vsllockerstatus

vsllockerstatus exists only with the H extension. When V=1, it substitutes for sllockerstatus: CSR accesses that would target sllockerstatus instead access vsllockerstatus, as for vsstatus and sstatus.

When the privilege mode is VU:

  • an access to K(i) while any of mllockerstatus(i), vsllockerstatus(i) or sllockerstatus(i) is Off raises a KLE locker-Off exception; and

  • an instruction that modifies K(i) sets vsllockerstatus(i), sllockerstatus(i) and mllockerstatus(i) to Dirty.

A direct write to vsllockerstatus(i) changes neither mllockerstatus(i) nor sllockerstatus(i) (if defined). mstatus.KLS, vsstatus.KLS, sllockerstatus and mllockerstatus are also in effect.

The *llockerstatus fields that an instruction sets to Dirty are those in effect, that is, those owned by the privilege modes above the one in which it executes; an instruction never writes the field owned by its own mode.

The KLE locker-Off exception is a single exception cause, whichever *llockerstatus field is Off, and medeleg and hedeleg delegate it as any other cause. While any of its own fields is Off, a mode keeps the cause undelegated, in medeleg if it is M-mode or in hedeleg if it is HS-mode. The handler that takes the exception examines the fields in effect, in the order mllockerstatus, sllockerstatus, vsllockerstatus, starting from the field owned by its own mode. If its own field (i) is Off, it resolves the condition itself, and otherwise forwards the exception to the most privileged mode whose field is Off, which owns that field and can write it. A handler never services a KLE locker-Off exception for a field it cannot write. The instructions that it issues to resolve the condition remain subject to the fields of more privileged modes; a KLE locker-Off exception that one of them raises, as for a locker that M-mode emulates, is taken by the mode that owns that field.

The Off value and the KLE locker-Off exception let software load lockers on demand. At context restore, a handler may leave a locker unrestored, set its *llockerstatus field to Off, and keep the authoritative SCC in memory. A later access from a lower-privileged mode traps with a KLE locker-Off exception to the mode that owns the Off field, directly by delegation or forwarded by a more privileged handler. That handler imports the SCC before resuming execution. The architecture defines no separate “lazy” state: software that marks a locker Off must ensure that the authoritative SCC is restored.

Emulation of Unsupported Machines

A KLE unsupported-Metadata exception (Table 3) can be resolved only by M-mode emulating the Machine; a handler below M-mode treats it as unresolvable. An M-mode handler that emulates the Machine instead marks the locker Off, holds it in its own protected memory, and services every operation on it, including SCC import and export. For these, an implementation that supports the emulation of Machines must provide M-mode-only, implementation-specific primitives that compute SCC_KeyDeriv, SCC_Encrypt and SCC_Decrypt (The SCC Authenticated Encryption Scheme) under the active CSK and the Locality Secrets in effect, with the substitutions of Locality Field, exactly as the KLE unit computes them, and with the protection of the SCProtection level of each emulated locker (The Cryptographic Locker File and Authentication Information). The primitives signal when a Locality names an unconfigured entry without a configured substitute, and return neither the CSK, nor the Locality Secrets of the HW Binding Group, nor the keys derived from them. An implementation without these primitives does not support the emulation of Machines: kleemulation is read-only zero, and M-mode treats a KLE unsupported-Metadata exception as unresolvable.

An emulator keeps one copy per locker slot and replaces it:

  1. at the next KLE unsupported-Metadata exception on that slot;

  2. at an emulated kl.clone naming the slot as destination, which also clears the slot’s hardware locker and marks it Off, since the clone of an emulated locker is emulated; or

  3. at an emulated kl.rename naming the slot as destination, or an emulated kl.swap naming it, either of which moves a copy into the slot.

A copy orphaned by a destructive configuration instruction is never used again but lingers until replaced. As a robustness recommendation, as for a cleared locker (Destructive Configuration Instructions), an emulator should zeroize a copy whose Off mark is gone before M-mode next returns control to a less privileged mode; checking mllockerstatus whenever it runs finds such copies.

mklcsk CSR Group

The optional mklcsk group consists of the four MXLEN-bit M-mode RW CSRs mklcsk0 to mklcsk3 and, when MXLEN = 32, of their shadows mklcsk0h to mklcsk3h.

A write to `mklcsk`i supplies bits [64·i+MXLEN−1 : 64·i], and a write to `mklcsk`ih bits [64·i+63 : 64·i+32], of the value that becomes the CSK once the group has been written in full.

This CSR group is accessible in M-mode whenever KLS is not Off and misa.L is set; any other access raises an illegal-instruction exception. An access in Debug mode that the External Debug Security extension does not authorize for M-mode raises an illegal-instruction exception. Out of reset KLS is Off (KLE Privileged State out of Reset); M-mode firmware enables KLS before it establishes the CSK.

A new CSK becomes active only once every CSR of the group has been written since the previous activation; from the first such write until then, the CSK is partially written, and the KLE unit is unavailable (KLE missing-CSK exception, Architectural Requirements on the Context Sealing Key).

Reading a register of the group returns the corresponding part of the active CSK; while no CSK is active (none established, or partially written), the read raises the KLE missing-CSK exception.

A write to the group is not checked against the state of the lockers, configured or under management included: M-mode must write it only after saving all KLE state that it must preserve.

A CSK whose value is zeros(256) is unconfigured in each of the four ways of Architectural Requirements on the Context Sealing Key: writing that value in full through the mklcsk group discards any established CSK and leaves the unit without a CSK; and whenever a CSK is randomly generated, as under the fourth way, an all-zero output of the RBG is discarded and regenerated.

The KLE unit is unavailable until a CSK is established (Architectural Requirements on the Context Sealing Key): at once for a hardwired CSK, and as soon as it has been generated for a boot-generated one.

mklmaxiobuflen

mklmaxiobuflen is an MXLEN-bit M-mode CSR, present with Zklio only, that holds the maximum configurable length of the KLIOBUF, in bytes; its hardwired value out of KLE unit reset is its maximum. Software in the other modes has no access to it: as with vsetvl, it learns the maximum by writing a larger value to kliobuflen and reading it back. M-mode should write it only while the KLE unit is in its state out of reset (KLE Unprivileged State out of Reset), before any write to kliobuflen, and should never reduce it below the current kliobuflen: after a write that does, kliobuflen and kliobuftop become 0 and the whole KLIOBUF is zeroized; no other state is affected.

A write to mklmaxiobuflen is WARL: a value above its value out of KLE unit reset sets that value, and a value below the lower bound sets that lower bound. The lower bound is the larger of 16 bytes and the largest basic processing unit (granularity) of any implemented Machine.

Locality Secret CSR Groups

Each group listed in Table 7 holds one 128-bit Locality Secret (Architected Localities. Bits refer to the Locality field in the MDH.) in two RW CSRs, numbered “0” and “1”, of W bits, where W is MXLEN for an M-mode group and SXLEN for an HS-mode or S-mode group, and, when W = 32, in their shadows, numbered “0h” and “1h”. A write to CSR i of a group sets bits [64·i+W−1 : 64·i] of its secret, and a write to CSR ih bits [64·i+63 : 64·i+32]. An access below the privilege of the group raises the exception that CSRs prescribes; an access in Debug mode that the External Debug Security extension does not authorize for the privilege of the group raises an illegal-instruction exception. The groups are accessible whether or not a CSK has been established (Architectural Requirements on the Context Sealing Key): no ordering between CSK and Locality configuration is enforced.

Table 7. Locality Secret CSR groups
Group Locality Secret Privilege Present when

mklphysbootscrt{0..1}{,h}

PhysBootScrt

M

Smklpbootscrt is implemented.

hklvirtbootscrt{0..1}{,h}

VirtBootScrt

HS

Ssklvbootscrt and the H extension are both implemented.

mkllocality{0..1}{,h}

MLocality

M

Smkllclt is implemented.

hkllocality{0..1}{,h}

HLocality

HS

Sskllclt and the H extension are both implemented.

skllocality{0..1}{,h}

SLocality

S

Sskllclt and S-mode are both implemented.

Software that exports lockers on behalf of a lower privilege level configures every SW Filter Group register it owns before doing so: the export of a locker whose Locality names an unconfigured entry is refused (Generation of an SCC from a Fully Configured Locker). The hypervisor’s duty to clear hkllocality and hklvirtbootscrt before running such software is Rule SR13.

The Locality CSR groups are readable at their respective privilege levels, and context-switch software saves and restores them like any other CSR.

skllocality is the OS’s Locality. It separates the OS’s processes whether the OS runs at S-mode or VS-mode. A hypervisor uses its own skllocality value for its host processes, swaps it with the guest’s value on entering and leaving the guest, and sets its own value before saving guest KLE state (Locality Field). hkllocality is the hypervisor’s tag on its virtual machines: it enters the bindings of every export and import a guest performs, and the hypervisor carries it with the virtual machine.

KLE Privileged State out of Reset

This section and KLE Unprivileged State out of Reset are the authoritative statement of the KLE state out of reset:

  1. bit L of misa is 1 if the KLE unit and the KLE ISA are at least partially implemented in hardware, and 0 for a purely emulated KLE unit; if this bit is writable, M-mode firmware may set it to 1;

  2. the KLS field of mstatus (visible in sstatus) and, where implemented, of vsstatus is Off;

  3. the CSK is unconfigured under the first and second ways of Architectural Requirements on the Context Sealing Key; a hardwired CSK is kept, and so is a boot-generated one, which the reset of one hart neither clears nor regenerates;

  4. the entire KLF memory is zeroed;

  5. mklphysbootscrt and hklvirtbootscrt are zero;

  6. mkllocality, hkllocality and skllocality are zero;

  7. all fields of mllockerstatus, sllockerstatus and vsllockerstatus are Initial;

  8. kleemulation in mstatus is 0; and

  9. with Zklio, mklmaxiobuflen holds its hardwired maximum (mklmaxiobuflen).

A KLE unit reset caused by a fatal condition (Error Handling Architecture) differs in items 1, 2 and 7: misa.L is unchanged, a KLS field that is Off stays Off and every other KLS field becomes Dirty, and every *llockerstatus field is set to Dirty. After such a reset, klstart is 0 and klnamedlocker is 32, as out of reset (KLE Unprivileged State out of Reset); until the KLE fatal-error exception is raised, any access to them raises it instead (Error Handling Architecture).