Study guides · Advanced

Two-stage translation: follow VA, IPA, and PA

Use concrete 4 KiB mappings to see how a guest OS and hypervisor control different translation stages.

Ask Logeia about this articleTry the three questionsReview your answers

Updated

On this page
  1. The guest physical address is intermediate
  2. Replace the page number, preserve the offset
  3. The same IPA can name different RAM in different VMs
  4. Finding a mapping is not granting an operation
  5. A table edit is not a complete invalidation protocol
  6. Change one condition while fixing the input
  7. Exercise: move the target without changing the VA
  8. Ask Logeia about this articleCheck your understanding

The guest physical address is intermediate

In this configuration, a guest process VA is translated by stage 1 into an IPA, then by stage 2 into a system PA. The guest OS manages stage 1 and the hypervisor manages stage 2. Calling something guest physical memory does not remove the second mapping or make every system RAM location available to the guest.

Here PA means the system physical address in this explanation. Nested virtualization, IOMMU translation for devices, and additional security contexts are outside this model. Do not insert a device DMA address into the CPU’s path as though the two were interchangeable. Follow one CPU access from input to result first. When another actor is introduced, add its starting address space and translation responsibilities explicitly instead of reusing the same labels without qualification.

Replace the page number, preserve the offset

With 4 KiB pages, VA 0x1234 consists of page 0x1 and offset 0x234. Stage 1 maps that page to IPA page 0x2, producing 0x2234. Stage 2 maps IPA page 0x2 to PA frame 0x8, producing 0x8234. Both stages use the same page size in this example. Real tables have further levels and mapping forms.

A frame number is not its byte address. Frame 0x8 begins at 0x8 multiplied by 4096, or 0x8000, rather than byte offset eight. Check the quotient and remainder, table lookup, and reconstruction separately. Try VA 0x1ABC as well as the default 0x1234. A program that passes only one hard-coded address has not established that it preserves offsets or selects the right page for other supported inputs.

python
page_size = 4096
va = 0x1234
stage1 = {0x1: 0x2}
stage2 = {0x2: 0x8}
va_page, offset = divmod(va, page_size)
ipa_page = stage1[va_page]
ipa = ipa_page * page_size + offset
pa = stage2[ipa_page] * page_size + offset
assert (ipa, pa) == (0x2234, 0x8234)
print(hex(ipa), hex(pa))
StageInputMappingOutput
Stage 1VA 0x1234VA page 0x1 → IPA page 0x2IPA 0x2234
Stage 2IPA 0x2234IPA page 0x2 → PA frame 0x8PA 0x8234

The same IPA can name different RAM in different VMs

Let VM A map IPA page 0x2 to PA frame 0x8, while VM B maps it to 0xC. IPA 0x2234 then reaches PA 0x8234 in A and PA 0xC234 in B. The stage-2 context matters. Mapping both to one frame could instead provide deliberate sharing, so matching numeric guest addresses do not establish sharing or separation.

Two guests printing the same VA may already have different stage-1 mappings and therefore different IPAs. The comparison here deliberately keeps stage 1 the same so the effect of stage 2 can be isolated. State those fixed conditions. If deliberate sharing is configured, also record access permissions; reaching one physical frame and being permitted to modify its contents are different properties. Numeric equality at any single intermediate point does not describe the complete path.

Finding a mapping is not granting an operation

A successful address calculation does not by itself authorize a load, store, or instruction fetch. A stage-1 permission cannot simply override a restriction at stage 2. The model separates finding mappings from checking the selected access. It limits its permission rules to the stated read/write cases rather than claiming to implement every architectural control.

In the first demonstration, choose the read-only stage-2 variant and compare 0x1234 write with 0x1234 read. A denied write alongside an allowed read cannot be explained solely as a broken address mapping. Read the physical-address candidate separately from the authorized access result. Showing a candidate address helps diagnosis, but it must not turn a refused store into a claimed successful memory access or imply that data was written there.

A table edit is not a complete invalidation protocol

Real CPUs can cache translation information. Changing a stage-2 table requires the appropriate invalidation and ordering for the configuration, and identifiers such as VMIDs do not make stale state disappear automatically. The demonstration reads its tables afresh on each operation and explicitly excludes TLB behavior, so its immediate updates are not an implementation recipe.

A later cache extension can draw the table and cached translation as separate state. Changing the table from frame 0x8 to 0x9 while a stale entry still names 0x8 makes the missing invalidation visible. Label that extension as another teaching model: a small cache does not reproduce real TLB replacement, combined translations, or every ordering rule. Each additional mechanism needs its own assumptions and test cases rather than inheriting a claim of hardware completeness.

Change one condition while fixing the input

Run VM A, VA 0x1234, read access, and both mappings to obtain PA 0x8234. Keep the VA and stage 1 fixed, changing only the stage-2 frame to 0x9: the IPA stays 0x2234 while the PA becomes 0x9234. Remove the stage-2 entry and the same input no longer reaches a PA. These comparisons isolate the role of each stage.

Include unsupported pages in the input comparisons. A VA page absent from stage 1 should stop without inventing an IPA. Then use a valid stage-1 mapping with a missing stage-2 entry to observe an IPA followed by a stage-2 failure. The final description may say translation failed in both cases, but the last established address differs. That distinction determines which table and owner should be investigated next, and should remain visible in the recorded trace.

Exercise: move the target without changing the VA

VA 0x1ABC maps to IPA 0x2ABC, then PA 0x8ABC. To reach PA 0xDABC without altering the guest table, change the stage-2 mapping for IPA page 0x2 to frame 0xD. The offset stays 0xABC. If only VM A’s stage-2 context changes, VM B’s mapping is unaffected even when it uses the same IPA.

For an additional exercise, compare VA 0x1FFF and 0x2000. Their page/offset pairs are 0x1/0xFFF and 0x2/0, so they require different stage-1 entries. A successful first translation does not establish the second mapping. This boundary case checks whether the learner can reason from the decomposed page number rather than assume that adjacent numeric addresses always share one mapping or produce adjacent physical destinations in the host system.

Try the interactive model

Two-stage address translation

Loading demo checkpoint…

Reading and practice are recorded separately in this browser, for each language.

Learn this in order

Build your CS foundations · STEP 16

Understand the systems behind the web · STEP 6

Prepare for AI systems · STEP 6

Choose a learning path