armv8 mmu The Access flag and The dirty state

本文详细介绍了ARMv8架构中Access Flag和Dirty State的管理方式。在ARMv8.0中,Access Flag由软件管理,当访问页或段时,如果AF标志为0,会产生访问标志错误。而在ARMv8.1及更高版本,硬件可以自动管理这两个标志。硬件管理机制能原子性地更新页表项,避免访问错误。Dirty State指示内存是否被修改,同样在ARMv8.1开始可以由硬件进行管理,用于跟踪数据是否被写入。配置字段如TCR_EL1.HA和TCR_EL1.HD分别控制Access Flag和Dirty State的硬件管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

D5.4.7 The Access flag

page或者section的内存第一次被访问时,会设置AF标志位,如果是armv8.0需要软件管理,如果是armv8.1则是硬件自动管理。

The Access flag indicates when a page or section of memory is accessed for the first time since the Access flag in the corresponding translation table descriptor was set to 0.

The AF bit in the translation table descriptors is the Access flag.

In Armv8.0, the Access flag is managed by software as described in Software management of the Access flag.

From Armv8.1, the Access flag can be managed by hardware as described in Hardware management of the Access

flag on page D5-2619.

Note

The support for hardware management of the Access flag applies only to the VMSAv8-64 translation regimes.

D5.4.8 The dirty state

表示内存是否被修改了。被硬件管理的标志位

The dirty state indicates whether a page or section of memory is modified.

The dirty state can be managed by hardware as described in Hardware management of dirty state on page D5-2620.

Where the dirty state is managed in hardware, the dirty state information is encoded using the access permission bits

AP[2] and S2AP[1] in conjunction with the DBM bit.

D5.4.10 Software management of the Access flag

在armv8.0里面,软件维护AF标志位,当尝试读取TLB entry时,也就是一次读,access flag fault会被触发。

Armv8.0 requires that software manages the Access flag. This means an Access flag fault is generated whenever an attempt is made to read into the TLB a translation table descriptor entry for which the value of Access flag is 0.

当access flag fault触发之后,软件要设置AF为1

The Access flag mechanism expects that, when an Access flag fault occurs, software resets the Access flag to 1 in the translation table entry that caused the fault. This prevents the fault occurring the next time that memory location is accessed. Entries with the Access flag set to 0 are never held in the TLB, meaning software does not have to flush the entry from the TLB after setting the flag.

D5.4.11 Hardware management of the Access flag and dirty state

Armv8.1 introduces the following optional features that perform hardware updates to the translation tables:

• Hardware management of the Access flag.

• Hardware management of dirty state on page D5-2620.

The support for hardware management of the Access flag and dirty state is identified by the feature ARMv8.1-TTHM.

硬件自动更新AF为1

When the hardware management of the Access flag is enabled, in situations where, without this feature, an Access flag fault would be generated, the hardware instead performs an atomic read-modify-write of the appropriate translation table descriptor to update the Access flag from 0 to 1.

dirtry state当没有访问权限时,如果没有这个硬件特性,那么一个permission fault会触发。如果有这个硬件特性,硬件会检查DBM域。若为1,硬件会执行一个read-modify-write操作来修改这个DBM域,来允许它写操作。

When the hardware management of dirty state is enabled, if the Block or Page descriptor in a translation table indicates that a data access does not have write permission, then in situations where, without this feature, a data access would generate a Permission fault only because of this lack of write permission, the hardware checks the value of the DBM field in the Block or Page descriptor. If this field is 1, then instead of generating a Permission fault, the hardware performs an atomic read-modify-write of the translation table descriptor, to change the value of the bit that prohibits the write access.

It is permissible, but not required, that a stage 2 permission failure on the stage 1 translation table walk is generated

(and has priority over the stage 1 abort generated by the stage 1 translation table entry) if all of the following are true:

• Stage 1 hardware updating of either access or dirty information is enabled.

• A stage 1 translation table entry would result in the stage 1 translation table entry having the access or dirty

bit updated.

• The stage 1 translation table entry has stage 2 read permission but not stage 2 write permission.

• The stage 1 translation entry generates an abort (which might be one of an address size fault, an alignment

fault caused by memory type or a permission fault)

Hardware management of the Access flag

硬件管理开启/关闭AF位

Hardware management of the Access flag is enabled, for the corresponding stage of address translation, by the following configuration fields:

For stage 1 translations

• TCR_EL1.HA. //可以用过此位来开启关闭硬件设置AF的功能

• TCR_EL2.HA.

• TCR_EL3.HA.

For stage 2 translations

• VTCR_EL2.HA.

When the value of a configuration bit, HA, is 1, then when a memory access is made using a translation table Block or Page descriptor from the corresponding stage of address translation:

当HA=1,访问一个内存时,硬件自动设置AF为1,它是通过read-modify-write机制来写的。

The PE sets the value of the Access flag to 1 in the translation table descriptor in memory, in a coherent manner, by an atomic read-modify-write of the translation table descriptor, if both of the following conditions are true:

    • The descriptor does not generate a Permission fault or an Alignment fault based on the memory type.

    • If the hardware update mechanism was disabled or not implemented, the access would have generated an Access flag fault.

bread-before-make机制,因为armv8允许预测访问,意思为在修改页表项时,先把对应的tlb无效掉,在修改页表项

A consequence of the architectural rules for translation table accesses is that the architecture requires that for any

translation to which an architecturally executed memory access occurs, the Access flag is set to 1, except as indicated in Using break-before-make when updating translation table entries on page D5-2669. However, because the architecture permits speculative accesses, the Access flag is permitted to be set to 1, even if there is no architecturally executed memory accesses by the processor.

Hardware management of dirty state

The hardware management of dirty state mechanism can only be enabled if hardware management of the Access flag is enabled. For information on the hardware management of the Access flag, see Hardware management of the Access flag on page D5-2619. The hardware management of dirty state mechanism uses:

In a stage 1 translation table access, the AP[2] bit in conjunction with the DBM bit in the translation table descriptors.//AP[2]和DBM联合使用

• In a stage 2 translation table access, the S2AP[1] bit in conjunction with the DBM bit in the translation table descriptors.

Hardware management of dirty state is enabled, for the corresponding stage of address translation, by the following

configuration fields:

For stage 1 translations

• TCR_EL1.HD.//此字段开启或关闭此硬件特性

• TCR_EL2.HD.

• TCR_EL3.HD.

When hardware management of dirty state is enabled, and a memory access is made using a translation table Block or Page descriptor:

当HD=1,然后AP2=0,那么

1.硬件会自动设置DBM为1

2.如果HD关闭了,那么当AP2=1时,会触发permission fault,因为这时候没有写权限,则需要软件去写DBM的位

• For a stage 1 address translation, if the value of the TCR_ELx.HD field corresponding to the address translation is 1, then the PE sets AP[2] to 0 in the translation descriptor in memory, in a coherent manner by an atomic read-modify-write of the translation table descriptor, if both of the following conditions are true:

— The value of the DBM field in the descriptor is 1.

— If the hardware update mechanism was disabled or not implemented, the access using this descriptor

would have generated a Permission fault only because the value of the AP[2] field is 1, indicating that the access does not have write permission.

When the PE updates AP[2] in this way no Permission fault is generated because of the value of the AP[2] field.

对于一个写access,如果CPU发现TLB里面的DBM=1, 但是AP2不允许写,那么这时PE应该去检查这个TLB是否陈旧的。

有必要执行一次read-modify-write操作来更新页表项。

If, for a write access, the PE finds that a cached copy of the descriptor in a TLB had the DBM bit set to 1 and the AP[2] or S2AP[1] bit set to the value that forbids writes, then the PE must check that the cached copy is not stale with regard to the descriptor entry in memory, and if necessary perform an atomic read-modify-write update of the descriptor in memory. This applies if the cached copy of the descriptor in a TLB is either:

• A stage 1 descriptor in which DBM has the value 1 and AP[2] has the value 1

注意:当DBM为1,stage 1的AP2为1的时候,可以等同于writable

The OA of a translation table entry where the DBM bit is 1, and the stage 1 AP[2] bit is 1 or the stage 2 S2AP[1] bit is 0, is treated as writable:

• For data cache invalidation instructions that require write permission, that is for the DC IVAC instruction.

• For address translation instructions that require write permission, that is for the AT S12E0W, AT S12E1W, AT S1E0W, AT S1E1W, AT S1E2W, and AT S1E3W instructions.

<think>好的,我现在要帮助用户了解ARMv8架构中MMU的工作原理和配置方法。首先,我需要回忆一下自己对ARMv8 MMU的基本知识,并确保信息准确。可能需要查阅一些资料或官方文档,比如ARM的编程指南或者技术参考手册。 首先,用户提到的参考引用是ARM Cortex-A系列程序员指南的第13章,关于启动代码的部分。虽然这个引用主要涉及启动流程,但MMU配置通常在启动阶段完成,所以可能有关联。不过,用户的问题更侧重于MMU本身,所以可能需要更深入的信息。 ARMv8架构的MMU负责虚拟地址到物理地址的转换,使用页表结构。需要明确MMUARMv8-A中的工作模式,比如AArch64和AArch32的区别,但用户问的是ARMv8,可能主要指64位模式。 接下来,我需要整理MMU的关键组成部分:页表结构、转换流程、地址转换的各级描述符,以及相关的系统寄存器配置。比如,在ARMv8中,页表通常采用四级页表结构,每个页表项的大小是8字节,支持不同的页大小,如4KB、16KB、64KB等。 然后,配置MMU的步骤可能包括:设置页表基地址寄存器(TTBR0/TTBR1),配置内存属性(MAIR寄存器),设置转换控制寄存器(TCR),最后启用MMU。需要详细解释每个步骤的作用,并可能给出代码示例,比如使用汇编指令来操作这些寄存器。 同时,需要提到地址转换的过程,比如从虚拟地址通过页表逐级解析到物理地址,TLB的作用,以及内存属性(如可缓存性、共享性)的配置。 另外,可能需要注意不同异常级别(EL)下的MMU配置差异,比如在EL1(操作系统内核)和EL3(安全监控)下的不同设置。此外,还需要解释内存访问权限的控制,如用户态和内核态的权限区别。 可能遇到的问题包括页表对齐要求、不同粒度页表的配置、以及内存屏障的使用以确保配置生效。需要确保这些细节的准确性,可能需要参考ARM官方文档或可靠的资料。 最后,生成相关问题时要考虑用户可能进一步想知道的内容,比如如何调试MMU配置错误、不同页大小的优缺点,或者与ARMv7 MMU的区别等。这些问题可以帮助用户深入理解MMU的相关知识。</think>### ARMv8 MMU工作原理及配置方法 #### 1. MMU基础功能 ARMv8MMU(Memory Management Unit)通过**多级页表**将虚拟地址转换为物理地址,并控制内存访问权限与属性。其核心流程包括: - **地址转换**:采用4级页表结构(48位虚拟地址) - **权限检查**:执行/读/写权限验证 - **属性控制**:缓存策略、共享域等配置 #### 2. 关键寄存器配置 | 寄存器 | 功能描述 | |--------|----------| | `TTBR0_EL1` | 用户空间页表基地址 | | `TTBR1_EL1` | 内核空间页表基地址 | | `TCR_EL1` | 页表格式控制 | | `MAIR_EL1` | 内存属性编码 | 典型配置代码示例(汇编): ```assembly // 设置内存属性 mov x0, #0xFF // 配置属性索引 msr MAIR_EL1, x0 // 配置TCR寄存器 ldr x0, =0x2B559351D // 页表格式参数 msr TCR_EL1, x0 // 加载页表基地址 ldr x1, =tt_lvl0_base // 页表物理地址 msr TTBR0_EL1, x1 ``` #### 3. 页表结构 ARMv8支持最多**4级页表遍历**,标准48位地址划分如下: $$ \text{Virtual Address} = \begin{cases} \text{Level0索引[47:39]} \\ \text{Level1索引[38:30]} \\ \text{Level2索引[29:21]} \\ \text{Level3索引[20:12]} \\ \text{页内偏移[11:0]} \end{cases} $$ 每个页表项包含: - 输出地址(下一级页表或物理页) - 访问权限(AP[2:0]) - 内存属性(AttrIndex) - 类型标记(Table/Block) #### 4. 启动流程关键步骤 1. 初始化页表内存区域(需**64字节对齐**) 2. 配置`MAIR_EL1`定义内存类型 3. 设置`TCR_EL1`指定地址范围与粒度 4. 加载页表基地址到`TTBR0_EL1` 5. 设置`SCTLR_EL1.M`启用MMU #### 5. 地址转换异常处理 当发生转换错误时,系统会触发**Data Abort**异常,相关寄存器提供调试信息: - `ESR_EL1`:异常分类码 - `FAR_EL1`:出错虚拟地址 [^1]: ARM官方文档指出,MMU配置是启动阶段的关键任务,需要与缓存配置协同工作
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

byd yes

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值