Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

5.4 Worked example: a 4K-granule walk by hand

This section walks three VAs through one set of EL1&0 stage 1 tables by hand: a 4KB page, a 2MB block, and a Translation fault. Do it once on paper. After that, a hex dump of a page table (from a debugger, a crash log or a Tarmac trace) reads like a sentence. The format rules are in 5.3, and the fault decode is in 5.8.

The configuration

RegisterValueMeaning
TCR_EL10x0000_0002_8090_3510T0SZ=16 (48-bit), TG0=4K, IRGN0=ORGN0=01, SH0=11, T1SZ=16, EPD1=1, TG1=4K, IPS=010 (40-bit)
TTBR0_EL10x0000_0000_8000_0000ASID 0, L0 table at PA 0x8000_0000
MAIR_EL10x0000_0000_0000_FF00Attr0 = 0x00 (Device-nGnRnE), Attr1 = 0xFF (Normal, inner/outer WB RW-allocate)
SCTLR_EL1M=1, C=1, I=1, EE=0MMU and caches on, little-endian walks

With a 4K granule and a 48-bit VA, the walk starts at level 0 and uses four 9-bit indexes:

 VA:  63..48 | 47..39 | 38..30 | 29..21 | 20..12 | 11..0
       zero  |  L0    |  L1    |  L2    |  L3    | offset

Tables in memory (PA), each 4KB:

TablePA
L00x8000_0000
L10x8000_1000
L20x8000_2000
L30x8000_3000

Walk 1: a 4KB page

VA = 0x0000_0081_4061_AABC.

Split it. Bit 39 is the lowest bit of the L0 index: 0x81_4061_AABC >> 39 = 1. The index steps:

L0 index = VA[47:39] = 0x001  (1)
L1 index = VA[38:30] = 0x005  (5)
L2 index = VA[29:21] = 0x003  (3)
L3 index = VA[20:12] = 0x01A  (26)
offset   = VA[11:0]  = 0xABC

Level 0. The descriptor address is 0x8000_0000 + 1×8 = 0x8000_0008.

[0x8000_0008] = 0x0000_0000_8000_1003
  bits[1:0] = 11       -> table (level 0)
  [63:59]   = 0        -> NSTable/APTable/XNTable/PXNTable impose nothing
  [47:12]   = 0x80001  -> next table at PA 0x8000_1000 (within 40-bit IPS: no Address size fault)

Level 1. The descriptor address is 0x8000_1000 + 5×8 = 0x8000_1028.

[0x8000_1028] = 0x0000_0000_8000_2003   -> table, next at 0x8000_2000

Level 2. The descriptor address is 0x8000_2000 + 3×8 = 0x8000_2018.

[0x8000_2018] = 0x0000_0000_8000_3003   -> table, next at 0x8000_3000

Level 3. The descriptor address is 0x8000_3000 + 26×8 = 0x8000_30D0.

[0x8000_30D0] = 0x0060_0000_9ABC_D707
  bits[1:0]  = 11        -> page (at level 3)
  AttrIndx   = [4:2]  = 001  -> MAIR Attr1: Normal WB
  NS         = [5]    = 0    (ignored: Non-secure regime)
  AP[2:1]    = [7:6]  = 00   -> EL1 RW, EL0 no access
  SH         = [9:8]  = 11   -> Inner Shareable
  AF         = [10]   = 1
  nG         = [11]   = 0    -> global
  OA         = [47:12] = 0x9ABCD
  PXN        = [53]   = 1, UXN = [54] = 1  -> not executable at EL1 or EL0

Result: PA = 0x9ABC_D000 | 0xABC = 0x0000_0000_9ABC_DABC, Normal WB, Inner Shareable, kernel read/write data. The walk made four descriptor reads, one per level, and the TLB now holds a 4KB entry (and possibly walk-cache entries for the L0–L2 steps).

How to construct the page descriptor value:

  0x0000_0000_9ABC_D000   OA
| 0x0040_0000_0000_0000   UXN  (bit 54)
| 0x0020_0000_0000_0000   PXN  (bit 53)
| 0x0000_0000_0000_0400   AF   (bit 10)
| 0x0000_0000_0000_0300   SH = 11
| 0x0000_0000_0000_0004   AttrIndx = 1
| 0x0000_0000_0000_0003   page
= 0x0060_0000_9ABC_D707

Walk 2: a 2MB block

VA = 0x0000_0081_4081_2345.

L0 = 1, L1 = 5, L2 = VA[29:21] = 4, remainder VA[20:0] = 0x01_2345

Levels 0 and 1 are the same as in Walk 1, and both are likely to be walk-cache hits on a real core. At level 2 the descriptor address is 0x8000_2000 + 4×8 = 0x8000_2020.

[0x8000_2020] = 0x0060_0000_A000_0705
  bits[1:0] = 01           -> block (valid at level 2 with 4K: 2MB)
  OA[47:21] = 0xA000_0000 >> 21 = 0x500;  bits[20:12] = 0  (aligned: correct)
  attributes as Walk 1 (AttrIndx 1, SH 11, AF 1, AP 00, PXN=UXN=1)

Result: PA = 0xA000_0000 | 0x01_2345 = 0x0000_0000_A001_2345. The walk took three reads and stopped at level 2. The VA bits [20:0] pass straight through.

The value differs from the page descriptor in only two ways: bits[1:0] are 01 and not 11, and the low 9 address bits must be zero. If you had written 0x...A000_0707 (type 11) into the L2 slot, the walker would read PA 0xA000_0000 as an L3 table. The 512 “descriptors” it found there would be whatever data lives in that memory.

Walk 3: a Translation fault

An EL1 load of VA = 0x0000_0081_40A0_0678:

L0 = 1, L1 = 5, L2 = VA[29:21] = 5
[0x8000_2028] = 0x0000_0000_0000_0000   -> bit[0] = 0: invalid

The walk stops at level 2. The exception is a Data Abort taken to EL1 from EL1:

ESR_EL1 = 0x9600_0006
  EC   [31:26] = 0x25     Data Abort, same EL
  IL   [25]    = 1        32-bit instruction
  WnR  [6]     = 0        read
  DFSC [5:0]   = 0b000110 Translation fault, level 2
FAR_EL1 = 0x0000_0081_40A0_0678   (valid for this fault)

A store to the same VA would give 0x9600_0046 (WnR = 1). The instruction-syndrome bits (ISV and the fields it validates) are shown clear here. The rules for when they are set are in 5.8.

The level number is the diagnostic. “Level 2” says levels 0 and 1 are fine and the L2 table is reachable, but the slot for VA[29:21] = 5 is empty. The fix is in the L2 table at 0x8000_2028, not in TTBR0_EL1 or TCR_EL1. By contrast, the following point at the configuration:

  • A level 0 Translation fault on every access after the MMU is enabled points at TTBR0_EL1, T0SZ or EPD0, or at a VA outside the range. Suppose the VA here had been 0xFFFF_0081_4061_AABC with EPD1 = 1. It is in the TTBR1 range, walks for that range are disabled, and it faults without reading anything.
  • An Address size fault (DFSC 0b0000LL) would mean a table or output address above the 40-bit IPS. For example, [0x8000_0008] holding 0x0000_0100_8000_1003 (bit 40 set) faults at level 0.

Checking your arithmetic on a model

Two checks confirm a hand walk against the real walker. First, read the descriptors yourself by physical address through the QEMU gdbstub (-s -S). QEMU’s PhyMemMode packet makes gdb memory reads physical:

(gdb) maintenance packet Qqemu.PhyMemMode:1
(gdb) x/gx 0x80000008        # L0[1]
(gdb) x/gx 0x80001028        # L1[5]
(gdb) x/gx 0x80002028        # L2[5] -> 0 for Walk 3
(gdb) maintenance packet Qqemu.PhyMemMode:0

Second, ask the hardware walker:

    // EL1 (or EL3 for the EL1&0 regime): ask the hardware
    ldr     x0, =0x0000008140A00678
    at      s1e1r, x0
    isb
    mrs     x1, par_el1      // PAR_EL1.F=1, FST=0b000110 for Walk 3

The full AT/PAR procedure is the lab in 5.9.

Validation note: Hand walks like these make cheap golden vectors for a pre-silicon MMU test. Generate tables from a script, record the expected PA (or fault level and DFSC) for each VA, and run AT S1E1R + PAR_EL1 comparisons alongside real loads. A mismatch between the AT result and the load result for the same VA is itself a bug signature, because both use the same walk. Count DTLB_WALK (0x0034) to check that cold accesses really walked rather than hit a stale entry from a previous test.

Checkpoint

Q5.4.1 Using the tables above, a load from VA 0x0000_0081_4061_B000 runs at EL1. What determines whether it faults?

  • A. Only the L3 entry at 0x8000_30D8 (index 27), because L0–L2 are the same as in Walk 1
  • B. The L2 entry at 0x8000_2020, because 0xB000 crosses into the next 2MB region
  • C. Nothing: VAs within 64KB of a mapped page share its TLB entry
  • D. The L3 entry at 0x8000_30D0, because the offset field absorbs the difference
Answer

A. 0x...61_B000 differs from Walk 1’s VA in bits [20:12] (0x1B = 27 instead of 26), so L0–L2 are the same, and the L3 index moves to 27, at 0x8000_3000 + 27×8 = 0x8000_30D8. Option D forgets that only bits [11:0] are the offset. Option C would need the contiguous bit and a consistent run of 16 entries.

Read more: Arm ARM (DDI0487), “Translation table walks” for the 4KB granule

Q5.4.2 An EL1 store to some VA gives ESR_EL1 = 0x9600_0045. What does this tell you about the walk?

  • A. A Permission fault on a write at level 1
  • B. A Translation fault on a read at level 1, from a load
  • C. A Translation fault at level 1 on a write. The L0 descriptor was a valid table, and the L1 entry indexed by the VA is invalid
  • D. An Address size fault at level 1
Answer

C. EC 0x25 is a Data Abort from the same EL, WnR (bit 6) = 1, and DFSC 0b000101 is a Translation fault at level 1. To reach level 1, the L0 descriptor must have been a valid table. Option A confuses Permission faults (0b0011LL) with Translation faults (0b0001LL).

Read more: Arm ARM (DDI0487), ESR_EL1, ISS encoding for an exception from a Data Abort

Q5.4.3 Someone writes 0x0060_0000_A010_0705 into L2 entry 4 instead of 0x0060_0000_A000_0705. Which statement is correct?

  • A. The block is simply shifted by 1MB, and translations are well defined
  • B. Bits [20:12] of a level-2 block descriptor must be zero. With bit 20 set, the descriptor is misprogrammed, and the architecture does not guarantee the resulting PA
  • C. The walker treats the entry as a table, because a non-aligned address implies a table
  • D. The walker rounds the address down and always produces 0xA000_0000 + offset
Answer

B. For a 2MB block, OA comes from bits [47:21]. Bits [20:12] are RES0, and writing them non-zero is a programming error with no guaranteed outcome. Option A assumes block addresses are byte-granular, and option D assumes the hardware masks the bits, which you must not rely on even if a given core does.

Read more: Arm ARM (DDI0487), VMSAv8-64 block descriptor format