ARM Linux内核页表 [英] ARM Linux kernel page table

查看:242
本文介绍了ARM Linux内核页表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

参考 Linux内核ARM转换表库(TTB0和TTB1)

我对上一个链接中讨论的主题有父亲的疑问/疑问:

I have father doubt/query on topic discussed in previous link:

  1. 0到0xbfffffff是内存的下部(用于用户进程),由TTB0中的页表管理,它包含当前进程的页表
  1. 0 to 0xbfffffff is a lower part of memory (for user processes) and managed by the page table in TTB0, it contains the page-table of the current process

参考arm/include/asm/pgtable-2level.h:PTRS_PER_PGD = 2048,PTRS_PER_PMD = 1,PTRS_PER_PTE = 512

Ref. arm/include/asm/pgtable-2level.h : PTRS_PER_PGD =2048, PTRS_PER_PMD =1, PTRS_PER_PTE =512

  • 0xc0000000到0xffffffff是由TTBR1中的页表管理/转换的地址空间的上半部分(操作系统和内存映射的I/O). TTB1表的大小和对齐方式固定为16k.每个1级条目的大小为32位,代表1MB页面/段.这是swapper_pg_dir(ref System.map)页表,位于实际文本地址下方16K
  • 0xc0000000 to 0xffffffff is upper part (OS and memory-mapped I/O) of the address space managed/translated by the page table in TTBR1. TTB1 table is fixed in size and alignment (to 16k). Each level 1 entry of size is 32bits and represents 1MB page/segment. This is swapper_pg_dir (ref System.map) page tables that placed 16K below the actual text address
    1. swapper_pg_dir = 0中的第一个768条目(对于用户进程而言是0x0到0xbfffffff)和从768到1024的有效条目(0xc0000000到0xffffffff是用于OS和内存映射的I/O)吗?

    1. Is that the first 768 entry in swapper_pg_dir = 0 (0x0 to 0xbfffffff for user processes) and valid entry from 768 to 1024(0xc0000000 to 0xffffffff is for OS and memory-mapped I/O)?

    有人喜欢在内核空间(内核模块)中共享一些示例代码来浏览此swapper_pg_dir PGD吗?

    Anyone like to share some sample code in kernel space (kernel module) to browse this swapper_pg_dir PGD?

    推荐答案

    由于ARM MMU的设计方式,两个转换表(TTB0和TTB1)只能在1:1映射内核映射中使用.

    Because of how the ARM MMU was designed, both the translations tables (TTB0 and TTB1) can only be used in a 1:1 mapping kernel mapping.

    大多数Linux内核具有3:1映射(3GB用户空间:1GB ARM内核空间). 这意味着0-0xBFFFFFFF是用户空间,而0xC0000000-0xFFFFFFFF是内核空间.

    Most Linux Kernels have a 3:1 mapping (3GB User space : 1GB Kernel space for ARM). This means that 0-0xBFFFFFFF is user space while 0xC0000000 - 0xFFFFFFFF is kernel space.

    现在,对于HW存储器转换,仅使用TTBR0. TTBR1仅保存初始交换器页面的地址(该页面包含所有内核映射),并没有真正用于虚拟地址转换. TTBR0保留当前使用的页面目录(硬件用于翻译的页面表)的地址.现在,每个用户进程都有自己的页表,并且对于每个进程开关,TTBR0都会更改为当前用户进程页表(它们都位于内核空间中).

    Now for the HW memory translations, only TTBR0 is used. TTBR1 only holds the address of the initial swapper page (which contains all the kernel mappings) and isn't really used for virtual address translations. TTBR0 hold the address for the current used page directory (the page table that the HW is using for translations). Now each user process has their own page tables, and for each process switch, TTBR0 changes to the current user process page table (they are all located in kernel space).

    例如,对于每个新的用户进程,内核创建一个新的页面目录,将所有内核映射从交换器页面(3-4GB的页面框架)复制到新页面表,并清除用户页面(页面框架)从0-3GB).然后,它将TTB0设置为该页面目录的基地址,并刷新缓存以安装新的地址空间.交换器页面还始终保持与映射的更改保持最新.

    For example, for each new user process, the kernel creates a new page directory, copies all the kernel mappings from the swapper page(page frames from 3-4GB) to the new page table and clears the user pages(page frames from 0-3GB). It then sets TTB0 to the base address of this page directory and flushes cache to install the new address space. The swapper page is also always kept up to date with changes to the mappings.

    您的问题:

    1. 经过简化的硬件操作,第一级页面有4096个条目.每个条目代表1MB的虚拟地址,总计4GB的ram.条目0-3071代表用户空间,条目3072-4095代表内核空间.

    1. Simplified, hardwarewise the first level page have 4096 entries. Each entry represent 1MB of virtual address, totalling 4GB of ram. Entry 0-3071 represent user space and entry 3072-4095 represent kernel space.

    交换器页面通常位于地址0xC0004000-0xc0008000(4096个条目* 4个字节,每个条目= 16384 = 16kb,十六进制= 0x4000).通过检查0xc0004000-0xc0007000处的内存,您可以找到用户空间的条目(空),而从0xc0007000-0xc0008000可以找到内核条目.为了检查前100个内核条目,我在命令行x /100x 0xc0007000中使用了gdb.然后,您可以查看当前平台的技术参考手册,以解密页表属性.

    The swapper page is usually located at address 0xC0004000 - 0xc0008000 (4096 entries *4bytes each entry = 16384 =16kb in hex = 0x4000 ). By examing the memory at 0xc0004000-0xc0007000 you can find entries for user space (empty) and from 0xc0007000-0xc0008000 you can find kernel entries. I use gdb with the command line x /100x 0xc0007000 in order to examine the first 100 kernel entries. You can then examine the technical reference manual for your current platform in order to decipher the page table attributes.

    如果您想了解有关Linux内核的更多信息,建议您使用Qemu和gdb一起模拟Beagleboard,以检查和调试源代码.我这样做是为了了解内核如何在初始化期间构建页表.

    If you want to learn more about the Linux kernel, I recommend you to use Qemu to simulate the Beagleboard together with gdb to examine and debug the source code. I did this to learn how the kernel builds the page table during initialization.

    这篇关于ARM Linux内核页表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆