ARM64 Linux kernel virtual address space
地址分布
虚拟地址都用64位无符号数表示。
用户虚拟地址从高位的63到低位的48都是0,内核虚拟地址则相反,63~48都是1. TTBR x(Translation table base register)的选择是通过虚拟地址的第63 bit位来确定的。swapper_pg_dir只包含内核地址映射,而用户
All user virtual addresses have 25 leading zeros and kernel addresses have 25 leading ones. Address between user space and kernel space are not used and they are used to trap illegal accesses.
ARM64 Linux virtual address space layout |
reference:
http://thinkiii.blogspot.com/2014/02/arm64-linux-kernel-virtual-address-space.html
address space常见MACRO值
- VA_START:跟VA_BITS有关,当VA_BITS是39时,其值是0xFFFFFF8000000000
#define VA_BITS (CONFIG_ARM64_VA_BITS) #define VA_START (UL(0xffffffffffffffff) - \ (UL(1) << VA_BITS) + 1) /* = FFFFFF8000000000*/
- TASK_SIZE
如果定义了CONFIG_COMPAT,一般是define了的,根据当前线程是否有TIF_32BIT flag,如果有表示是32bit应用,则TASK_SIZE是TASK_SIZE_32,否则就是64bit应用,则TASK_SIZE是TASK_SIZE_64
TASK_SIZE_32的值是4G-4K(page size是4K case)
TASK_SIZE_64的值是(UL(1) << VA_BITS),比如VA_BITS是39bit,则其值是1<<39,即512G
总结就是:
32bit应用:
TASK_SIZE = TASK_SIZE_32 = (4G-4K)
64bit应用:
TASK_SIZE = TASK_SIZE_64 = 512G
4.19\arch\arm64\include\asm\Processor.h
#ifdef CONFIG_COMPAT #ifdef CONFIG_ARM64_64K_PAGES /* * With CONFIG_ARM64_64K_PAGES enabled, the last page is occupied * by the compat vectors page. */ #define TASK_SIZE_32 UL(0x100000000) #else #define TASK_SIZE_32 (UL(0x100000000) - PAGE_SIZE) /*4G - 4K*/ #endif /* CONFIG_ARM64_64K_PAGES */ #define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ TASK_SIZE_32 : TASK_SIZE_64) #define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \ TASK_SIZE_32 : TASK_SIZE_64) #else #define TASK_SIZE TASK_SIZE_64 #endif /* CONFIG_COMPAT */
PAGE_OFFSET
此宏是根据VA_BITS来确定的,比如VA_BITS为39时,PAGE_OFFSET的值为0xFFFFFFC000000000
#define PAGE_OFFSET (UL(0xffffffffffffffff) - \ (UL(1) << (VA_BITS - 1)) + 1) /*= 0xffffffffffffffff - 0x4000000000 +1 = 0xFFFFFFC000000000*/