TLB & PSC
TLB
TLB 里只缓存页表项 PTE,不缓存中间结构 PSE 等等。PSE 等等结构的缓存请看 Page Structure Cache (PSC^)。
TLB 里存的是从 VPN -> HPN 的映射,注意是都是页号,而不是地址。
EPT TLB / TLB
因为 EPT TLB 情况是单纯 TLB 情况的超集(虚拟化环境是一个更加复杂的环境),所以这里以虚拟化环境为例来解释。
在 SDM Vol. 3C 30.4 Caching Translation Information(注意是 30.4(这个是和 VMX 相关的 Caching),而不是 Section 5.10)一节中,Intel 详细描述了 TLB 和 VMX 的交互方式。在和 VMX 有关的场景下,TLB 可以被分为 3 类:
- Linear mappings. Linear translations. 存储 HVA 到 HPA 的映射信息,关联的是 Host 的页表。不会存储任何 GVA -> GPA 映射,这点 SDM 写的很清楚:No linear mappings are created while EPT is in use;
 - Guest-physical mappings. Guest-physical translations. 存储的是 GPA 到 HPA 的映射信息,关联的是 EPT 页表;
 - Combined mappings. Combined translations. 则存储 GVA 到 HPA 的映射信息,关联的是 Guest 页表和 EPT 页表。
 
因此:
- 当 EPT 关闭时,不存在 GPA 和 HPA 的区别。此时,处理器只会创建和使用 Linear mappings。
 - 当 EPT 开启时,处理器只会创建和使用 Guest-physical mappings 和 Combined mappings。处理器不会在 EPT 开启的时候缓存 GVA 到 GPA 到映射。
 
See more in PCID^ and VPID^.
PSC (Paging-Structure Cache) / EPT PSC
See SDM: 30.4 CACHING TRANSLATION INFORMATION
In addition to the TLBs, a processor may cache other information about the paging structures in memory.
和 TLB 里从 VPN 映射到 HPN 不同。PSC 里映射的格式一般都是 VPN 的 upper part 到其所对应的 Pysical Address Space 的页表的 HPA。
PSC 里加入了 EPT 之后,也会发生变化。
- Linear mappings. Linear paging-structure-cache entries. Each of these is a mapping from the upper portion of a linear address to the physical address of the paging structure used to translate the corresponding region of the linear-address space. Linear mappings do not contain information from any EPT paging structure. 看 PSC^ 处说明更好理解。VPN 的 upper part 到其所对应的 Pysical Address Space 的页表的 HPA。不会缓存任何 GVA Upper bits 到对应页表的 GPA 的映射,这点 SDM 写的很清楚:No linear mappings are created while EPT is in use;
 - Guest-physical mappings. Guest-physical paging-structure-cache entries. Each of these is a mapping from the upper portion of a guest-physical address to the physical address of the EPT paging structure used to translate the corresponding region of the GPA space. GPN 的 upper part 到其所对应的 Pysical Address Space 的页表的 HPA。
 - Combined mappings. Combined paging-structure-cache entries. Each of these is a mapping from the upper portion of a linear address to the physical address of the paging structure used to translate the corresponding region of the linear-address space. GVN 的 upper part 到其所对应的 Pysical Address Space 的 combined 之后的页表的 HPA。这个 combined 的页表其实就是根据两个页表组合而成的。
 
🗞️ Recent Posts