📢 2 stage translation의 컨셉을 알아봐요
What is stage 2 translation
Virtual address ↔ Intermediate Physical Address (IPA) ↔ Physical address
- stage1을 위한 translation table은 Guest OS에서 컨트롤
- stage2를 위한 translation table은 Hypervisor가 컨트롤
실제 VA → IPA → PA 변환은 MMU가 한 번에 수행해요
Virtual Address Space IPA (Stage 1 Output) Physical Address Space
+--------------+ +--------------+ +--------------+
| Peripherals | ┐ ┌ | DDR | ┐ ┌ | DDR |
+--------------+ +--------------+ +--------------+
| Kernel | ├ [Stage 1] ├ | Peripherals | ├ [Stage 2] ├ | Peripherals |
+--------------+ +--------------+ +--------------+
| Application | ┘ └ | Flash | ┘ └ | Flash |
+--------------+ +--------------+ +--------------+
| SRAM |
+--------------+
| ROM |
+--------------+
* [Stage 1]: Translation table for Stage 1
* [Stage 2]: Translation table for Stage 2
VMID interaction with ASIDs
가상 주소를 매번 Translation table으로 변환하면 너무 느려요
이를 위해, Core 마다 MMU가 관리하는 고속 캐시인 Translation Lookaside Buffer (TLB)가 있죠
TLB는 VA → PA 변환 결과를 저장해두고, TLB Miss 발생 시 Translation Table을 접근하는 거죠
그런데 여러 VM을 동시에 실행하면, 서로 다른 VM의 가상 주소 매핑 결과들이 하나의 TLB에 섞일 수 있어요
이를 방지하기 위해, VMID, ASID가 tag로 쓰여 각 VM들의 TLB 엔트리를 구분해요
- VMID를 사용해서 "어느 VM 소속인지"를 구분하고,
- ASID를 사용해서 "VM 안에서 어느 프로세스(App) 소속인지"를 추가로 구분하죠
결과적으로 VMID + ASID 조합으로 TLB 엔트리에 태깅(tagging)이 되어 있어서, 여러 VM과 여러 App이 하나의 TLB를 공유해도 절대 헷갈릴 일이 없어요
Attribute combining and overriding
MMU가 Stage 1과 Stage 2 속성을 비교해서 더 엄격한(more restrictive) 쪽을 최종 속성으로 선택해요
- stage 1 attribute: Guest OS가 설정하는 VA → IPA 변환 테이블 속성 (ex: Normal memory, Device memory, Read/Write 허용 등)
- stage 2 attribute: Hypervisor가 설정하는 IPA → PA 변환 테이블 속성 (ex: Device memory, Read만 허용 등)
보통은 위처럼 "더 restrictive한 쪽"으로 결합하지만, 특별한 상황에서는 Hypervisor가 이 규칙을 깨고 직접 속성을 강제할 수도 있죠
Emulating Memory-mapped Input/Output (MMIO)
VM의 IPA 공간에는 메모리와 주변기기(Peripheral) 영역이 포함되죠
실제 물리 디바이스를 VM에 직접 연결 한 Assigned peripheral은 VM이 직접 제어하지만
Virtual Peripheral(가상 주변기기) 접근 시 Stage 2 fault가 발생하고, Hypervisor가 이를 trap해서 에뮬레이션해요
Hypervisor는 ESR_EL2 (접근 타입, 크기, 레지스터 정보)와 HPFAR_EL2 (접근 IPA 주소)를 이용해 어떤 동작을 흉내 낼지 판단해요
이 과정을 통해 VM은 실제 하드웨어를 쓰는 것처럼 가상 디바이스를 투명하게 사용할 수 있죠
System Memory Management Units (SMMUs)
VM 안에서 DMA 컨트롤러 같은 외부 디바이스가 직접 메모리에 접근하면, Stage 2 보호를 우회하거나 주소 해석이 어긋나는 문제가 생겨요
이를 해결하기 위해 Hypervisor가 직접 번역을 trap-and-emulate 할 수도 있지만, 성능이 매우 나빠지죠
대신 SMMU(System Memory Management Unit)를 사용해 DMA 같은 외부 디바이스에도 Stage 2 보호를 적용해요
SMMU는 Hypervisor가 제어하며, VM과 DMA가 같은 메모리 뷰를 공유하게 하죠
이로써 VM 간 격리와 메모리 일관성이 모두 보장돼요
Reference
https://developer.arm.com/documentation/102142/0100/Stage-2-translation
Documentation – Arm Developer
developer.arm.com
'TIL > 2025' 카테고리의 다른 글
| Virtualizing Exceptions in the Arm Architecture AArch64 (0) | 2025.04.29 |
|---|---|
| Trapping and Emulation of instructions (0) | 2025.04.29 |
| 가상화(Virtualization) 소개 | hypervisor, arm architecture (0) | 2025.04.28 |
| About the Arm architecture (0) | 2025.04.28 |
| Arm R-Profile Architecture 학습 방법 및 자료 (0) | 2025.04.28 |