ARM32 Linux kernel virtual address space

http://thinkiii.blogspot.jp/2014/02/arm32-linux-kernel-virtual-address-space.html

The 32-bit ARM CPU can address up to 2^32 = 4GB address*. It‘s not big enough in present days, since the size of available DRAM on computing devices is growing fast and the memory usage of application is growing as well.

In Linux kernel implementation, user space and kernel must coexist in the same 4GB virtual address space. It means both user space and kernel can use less than 4GB virtual address space. 
Linux kernel provides 3 different split of virtual address spaces: VMSPLIT_3G, VMSPLIT_2G, VMSPLIT_1G.

Linux virtual address space options

The default configuration is VMSPLIT_3G, as you can see, kernel space starts from 0xC0000000 to 0xFFFFFFFF and user space starts from 0x00000000 to 0xC0000000.

Let‘s take a closer look of the VMSPLIT_3G mapping:

kernel space

We can observe the kernel virtual address by checking the boot log (dmesg) or take a look at arch/arm/mm/init.c.

lowmem: The memory that have 1-to-1 mapping between virtual and physical address. It means the virtual and physical address are both configuous, and this good property makes the virtual to physical address translation very easy. If we have a virtual address from lowmem, we can find out its physical address by simple shift. (see __pa() and __va()).

vmalloc: The vmalloc memory is only virtually contiguous.

fixmap/pkmap: create fast mapping of a single page for kernel. Most used in file system.

modules: The virtual address for module loading and executing. kernel modules are loaded into this part of virtual memory.

user space

The code for deterring user space virtual address is in arch/arm/mm/mmap.c

The user space have two different kind of mmap layout: legacy and non-legacy. Legacy layout sets the base of mmap(TASK_UNMAPPED_BASE) and the mmap grows in bottom-up manner; on the other case, non-legacy set the mmap base from TASK_SIZE - 128MB with some random shift for security reasons).

?


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

void arch_pick_mmap_layout(struct mm_struct *mm)

{

        unsigned long random_factor = 0UL;

        /* 8 bits of randomness in 20 address space bits */

        if ((current->flags & PF_RANDOMIZE) &&

            !(current->personality & ADDR_NO_RANDOMIZE))

                random_factor = (get_random_int() % (1 << 8)) << PAGE_SHIFT;

        if (mmap_is_legacy()) {

                mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;

                mm->get_unmapped_area = arch_get_unmapped_area;

        } else {

                mm->mmap_base = mmap_base(random_factor);

                mm->get_unmapped_area = arch_get_unmapped_area_topdown;

        }

The user space virtual address layout looks like:

32-bit user virtual address space layout

*ARM has LPAE (Large Physical Address Extension) mode that can address up to 1TB.

Posted by Miles MH Chen at 12:53 AM

Labels: linux

时间: 2024-10-07 12:33:10

ARM32 Linux kernel virtual address space的相关文章

Memory Layout (Virtual address space of a C process)

Memory Layout (Virtual address space of a C process) 分类: C语言基础2012-12-06 23:16 2174人阅读 评论(0) 收藏 举报 found a good example to demostrate the memory layout and its stack info of a user-mode process, only that this example is for Linux. But it is still wo

linux内核可以接受的参数 | Linux kernel启动参数 | 通过grub给内核传递参数

在Linux中,给kernel传递参数以控制其行为总共有三种方法: 1.build kernel之时的各个configuration选项. 2.当kernel启动之时,可以参数在kernel被GRUB或LILO等启动程序调用之时传递给kernel. 3.在kernel运行时,修改/proc或/sys目录下的文件. 这里我简单讲的就是第二种方式了,kernel在grub中配置的启动参数. 首先,kernel有哪些参数呢? 在linux的源代码中,有这样的一个文档Documentation/kern

Unable to handle kernel paging request at virtual address 0x7e005070 解决办法

有点标题党的味道了~ 对于readl() 和 inl() 读取I/O端口报错的探究 给s3c6410的RTC写demo driver的时候遇到这个问题... 如图 这是虚拟内存技术导致的问题,不能直接使用物理地址(不过这里有个疑问,我上次给PC写的CMOS driver貌似用的是物理地址,布吉岛为嘛) 解决办法就是调用ioremap函数转换物理地址,重新映射IO端口到虚拟地址中 Once equipped with ioremap (and iounmap), a device driver c

Linux Kernel - Debug Guide (Linux内核调试指南 )

http://blog.csdn.net/blizmax6/article/details/6747601 linux内核调试指南 一些前言 作者前言 知识从哪里来 为什么撰写本文档 为什么需要汇编级调试 ***第一部分:基础知识*** 总纲:内核世界的陷阱 源码阅读的陷阱 代码调试的陷阱 原理理解的陷阱 建立调试环境 发行版的选择和安装 安装交叉编译工具 bin工具集的使用 qemu的使用 initrd.img的原理与制作 x86虚拟调试环境的建立 arm虚拟调试环境的建立 arm开发板调试环

Android linux kernel privilege escalation vulnerability and exploit (CVE-2014-4322)

In this blog post we'll go over a Linux kernel privilege escalation vulnerability I discovered which enables arbitrary code execution within the kernel. The vulnerability affected all devices based on Qualcomm chipsets (that is, based on the "msm&quo

System and method for critical address space protection in a hypervisor environment

A system and method in one embodiment includes modules for detecting an access attempt to a critical?address?space?(CAS) of a guest operating system (OS) that has implemented?address?space?layout?randomization?in a hypervisor environment, identifying

Linux kernel Programming - Allocating Memory

kmalloc #include <linux/slab.h> void *kmalloc(size_t size,int flags); void kfree(void *addr); flags: GFP_ATOMIC: Used to allocate memory from interrupt handlers and other code outside of a process context.Never sleeps GFP_KERNEL: Normal allocation o

Method of address space layout randomization for windows operating systems

A system and method for?address?space?layout?randomization?("ASLR") for a Windows operating system is disclosed. The?address?space?layout?includes one or more memory regions that are identified and then a particular implementation of the system

Virtual address cache memory, processor and multiprocessor

An embodiment provides a?virtual?address?cache?memory including: a TLB virtual?page memory configured to, when a rewrite to a TLB occurs, rewrite entry data; a data memory configured to hold?cache?data using a?virtual?page tag?or a page offset as a?c