요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
=================================
Kernel Memory Layout on ARM Linux
=================================
Russell King <rmk@arm.linux.org.uk>
November 17, 2005 (2.6.15)
This document describes the virtual memory layout which the Linux
kernel uses for ARM processors. It indicates which regions are
free for platforms to use, and which are used by generic code.
The ARM CPU is capable of addressing a maximum of 4GB virtual memory
space, and this must be shared between user space processes, the
kernel, and hardware devices.
As the ARM architecture matures, it becomes necessary to reserve
certain regions of VM space for use for new facilities; therefore
this document may reserve more VM space over time.
=============== =============== ===============================================
Start End Use
=============== =============== ===============================================
ffff8000 ffffffff copy_user_page / clear_user_page use.
For SA11xx and Xscale, this is used to
setup a minicache mapping.
ffff4000 ffffffff cache aliasing on ARMv6 and later CPUs.
ffff1000 ffff7fff Reserved.
Platforms must not use this address range.
ffff0000 ffff0fff CPU vector page.
The CPU vectors are mapped here if the
CPU supports vector relocation (control
register V bit.)
fffe0000 fffeffff XScale cache flush area. This is used
in proc-xscale.S to flush the whole data
cache. (XScale does not have TCM.)
fffe8000 fffeffff DTCM mapping area for platforms with
DTCM mounted inside the CPU.
fffe0000 fffe7fff ITCM mapping area for platforms with
ITCM mounted inside the CPU.
ffc80000 ffefffff Fixmap mapping region. Addresses provided
by fix_to_virt() will be located here.
ffc00000 ffc7ffff Guard region
ff800000 ffbfffff Permanent, fixed read-only mapping of the
firmware provided DT blob
fee00000 feffffff Mapping of PCI I/O space. This is a static
mapping within the vmalloc space.
VMALLOC_START VMALLOC_END-1 vmalloc() / ioremap() space.
Memory returned by vmalloc/ioremap will
be dynamically placed in this region.
Machine specific static mappings are also
located here through iotable_init().
VMALLOC_START is based upon the value
of the high_memory variable, and VMALLOC_END
is equal to 0xff800000.
PAGE_OFFSET high_memory-1 Kernel direct-mapped RAM region.
This maps the platforms RAM, and typically
maps all platform RAM in a 1:1 relationship.
PKMAP_BASE PAGE_OFFSET-1 Permanent kernel mappings
One way of mapping HIGHMEM pages into kernel
space.
MODULES_VADDR MODULES_END-1 Kernel module space
Kernel modules inserted via insmod are
placed here using dynamic mappings.
TASK_SIZE MODULES_VADDR-1 KASAn shadow memory when KASan is in use.
The range from MODULES_VADDR to the top
of the memory is shadowed here with 1 bit
per byte of memory.
00001000 TASK_SIZE-1 User space mappings
Per-thread mappings are placed here via
the mmap() system call.
00000000 00000fff CPU vector page / null pointer trap
CPUs which do not support vector remapping
place their vector page here. NULL pointer
dereferences by both the kernel and user
space are also caught via this mapping.
=============== =============== ===============================================
Please note that mappings which collide with the above areas may result
in a non-bootable kernel, or may cause the kernel to (eventually) panic
at run time.
Since future CPUs may impact the kernel mapping layout, user programs
must not access any memory which is not mapped inside their 0x0001000
to TASK_SIZE address range. If they wish to access these areas, they
must set up their own mappings using open() and mmap().
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
Kernel Memory Layout on ARM Linux
1-8Russell King이 작성한 ARM Linux kernel virtual memory layout 문서이며 2005년 11월 17일, kernel 2.6.15 기준입니다.
주소 공간의 목적과 제약
9-20이 문서는 ARM processor용 Linux kernel이 쓰는 virtual memory 배치를 설명하고, platform이 자유롭게 쓸 수 있는 영역과 generic code가 점유하는 영역을 구분합니다.
ARM CPU가 주소화할 수 있는 virtual memory는 최대 4GB이며 user-space process, kernel, hardware device가 이를 함께 나눠 써야 합니다. architecture가 발전하면서 새 기능을 위한 VM 영역을 더 예약해야 할 수 있으므로 이 배치는 시간이 지나며 예약 범위가 늘어날 수 있습니다.
ARM virtual memory layout
21-95| 시작 | 끝 | 용도 |
|---|---|---|
| `ffff8000` | `ffffffff` | `copy_user_page` / `clear_user_page`; SA11xx·XScale에서는 minicache mapping |
| `ffff4000` | `ffffffff` | ARMv6 이상 CPU의 cache aliasing 영역 |
| `ffff1000` | `ffff7fff` | 예약 영역. platform이 사용하면 안 됨 |
| `ffff0000` | `ffff0fff` | CPU가 vector relocation(control register V bit)을 지원할 때의 vector page |
| `fffe0000` | `fffeffff` | `proc-xscale.S`가 전체 data cache를 flush하는 XScale 영역 |
| `fffe8000` | `fffeffff` | CPU 내부 DTCM mapping 영역 |
| `fffe0000` | `fffe7fff` | CPU 내부 ITCM mapping 영역 |
| `ffc80000` | `ffefffff` | `fix_to_virt()`가 제공하는 address의 fixmap 영역 |
| `ffc00000` | `ffc7ffff` | guard 영역 |
| `ff800000` | `ffbfffff` | firmware가 제공한 DT blob의 영구 고정 read-only mapping |
| `fee00000` | `feffffff` | vmalloc 공간 안의 정적 PCI I/O mapping |
| `VMALLOC_START` | `VMALLOC_END-1` | `vmalloc()`·`ioremap()` 동적 mapping과 `iotable_init()`의 machine-specific 정적 mapping. `VMALLOC_START`는 `high_memory`에 따르고 `VMALLOC_END`는 `0xff800000` |
| `PAGE_OFFSET` | `high_memory-1` | platform RAM을 보통 1:1로 mapping하는 kernel direct-mapped RAM |
| `PKMAP_BASE` | `PAGE_OFFSET-1` | HIGHMEM page를 kernel 공간에 넣는 영구 kernel mapping |
| `MODULES_VADDR` | `MODULES_END-1` | `insmod`로 삽입한 module의 동적 mapping 영역 |
| `TASK_SIZE` | `MODULES_VADDR-1` | KASan 사용 시 shadow memory. `MODULES_VADDR`부터 최상단까지의 memory를 byte당 1 bit로 shadow |
| `00001000` | `TASK_SIZE-1` | `mmap()` system call로 만드는 thread별 user-space mapping |
| `00000000` | `00000fff` | vector remapping 미지원 CPU의 vector page이자 kernel·user NULL pointer trap |
충돌 방지와 사용자 공간 규칙
96-103위 영역과 겹치는 mapping은 kernel을 boot할 수 없게 만들거나 실행 중 결국 panic을 일으킬 수 있습니다.
향후 CPU가 kernel mapping layout에 영향을 줄 수 있으므로 사용자 프로그램은 자신의 `0x0001000`부터 `TASK_SIZE`까지 범위 안에 mapping되지 않은 memory에 접근하면 안 됩니다. 다른 영역이 필요하면 `open()`과 `mmap()`으로 자체 mapping을 설정해야 합니다.
요약과 해설
memory.rst:1-103주소가 높아질수록 vmalloc·PCI I/O·fixmap·vector처럼 kernel과 architecture가 고정한 영역이 나타납니다. platform mapping이 이 경계를 침범하면 boot 실패나 runtime panic으로 이어집니다.
낮은 주소의 user mapping에서 kernel RAM과 동적 mapping을 거쳐 최상단의 고정 architecture 영역으로 올라갑니다.