IOMMU / GUIDED STORY
Testing an address-translation walk
Page tables, permissions and boundaries in a four-level teaching walk.
This independent example explores how to test a translation walk, built from public specifications, without reproducing a hardware implementation.
What claims does this page make? 1 point
- Teaching model: the four-level, 512-entry, 4 KiB walk and its present and write fields are this site's own simplification, not any x86 IOMMU or Arm SMMU format.
The requirement
A translation should preserve the page offset, reject an unmapped page, and enforce the requested access permission throughout the walk.
The model
The example uses four levels of 512 entries and 4 KiB pages. Each entry is a C++ structure with abstract presence and write-permission fields. Input addresses are unsigned 48-bit values. This is a teaching model, not the encoding or complete behaviour of any x86 IOMMU or Arm SMMU.
FOLLOW ONE ADDRESS
Four indices. One page offset.
In this model, 0x1234 selects entry zero at the first three levels, then entry one in the leaf table.
- Level 4 bits 47–39
- 0
- Level 3 bits 38–30
- 0
- Level 2 bits 29–21
- 0
- Level 1 bits 20–12
- 1
- Offset bits 11–0
- 0x234
Mapped frame 0x9000Offset 0x234Output 0x9234
The offset is preserved. The table entries determine the frame and whether this model permits the access. These labels describe the synthetic walk, not an architecture-specific descriptor format.
What the tests check
- Translate a mapped address and check the physical frame plus offset.
- Probe the last byte of a page and the first byte of the next, unmapped page.
- Remove write permission at an intermediate level; reads should still pass and writes should fail.
- Reject an out-of-range input or a misaligned target.
Try a change
Change the intermediate entry’s write flag back to true. The negative write-permission test should report FAIL: the injected restriction has been removed, so the original expectation no longer holds.
C++ experiment
Default: C++23 · choose GCC or Clang belowEdit the source, then run the tests. Compilation provided by Compiler Explorer. Clicking Run sends the code to that external service. Use only public, non-confidential code.
Ready. No code has been sent.
Compiler & test output
Run the example to see actual output here.
If the external service is unavailable, copy the source and open Compiler Explorer, or compile locally with g++ -std=c++23 example.cpp -o example and run ./example.
What this does not establish
A passing software model does not validate real translation hardware. This example omits device contexts, architecture-specific descriptors, multiple translation stages, large pages, translation caches and invalidation, and fault-reporting mechanisms. CPU virtual-address translation and device DMA translation are distinct paths.
Public references
Personal educational material; not an employer publication or endorsement.