Skip to content

Commit 8feae13

Browse files
committed
NOMMU: Make VMAs per MM as for MMU-mode linux
Make VMAs per mm_struct as for MMU-mode linux. This solves two problems: (1) In SYSV SHM where nattch for a segment does not reflect the number of shmat's (and forks) done. (2) In mmap() where the VMA's vm_mm is set to point to the parent mm by an exec'ing process when VM_EXECUTABLE is specified, regardless of the fact that a VMA might be shared and already have its vm_mm assigned to another process or a dead process. A new struct (vm_region) is introduced to track a mapped region and to remember the circumstances under which it may be shared and the vm_list_struct structure is discarded as it's no longer required. This patch makes the following additional changes: (1) Regions are now allocated with alloc_pages() rather than kmalloc() and with no recourse to __GFP_COMP, so the pages are not composite. Instead, each page has a reference on it held by the region. Anything else that is interested in such a page will have to get a reference on it to retain it. When the pages are released due to unmapping, each page is passed to put_page() and will be freed when the page usage count reaches zero. (2) Excess pages are trimmed after an allocation as the allocation must be made as a power-of-2 quantity of pages. (3) VMAs are added to the parent MM's R/B tree and mmap lists. As an MM may end up with overlapping VMAs within the tree, the VMA struct address is appended to the sort key. (4) Non-anonymous VMAs are now added to the backing inode's prio list. (5) Holes may be punched in anonymous VMAs with munmap(), releasing parts of the backing region. The VMA and region structs will be split if necessary. (6) sys_shmdt() only releases one attachment to a SYSV IPC shared memory segment instead of all the attachments at that addresss. Multiple shmat()'s return the same address under NOMMU-mode instead of different virtual addresses as under MMU-mode. (7) Core dumping for ELF-FDPIC requires fewer exceptions for NOMMU-mode. (8) /proc/maps is now the global list of mapped regions, and may list bits that aren't actually mapped anywhere. (9) /proc/meminfo gains a line (tagged "MmapCopy") that indicates the amount of RAM currently allocated by mmap to hold mappable regions that can't be mapped directly. These are copies of the backing device or file if not anonymous. These changes make NOMMU mode more similar to MMU mode. The downside is that NOMMU mode requires some extra memory to track things over NOMMU without this patch (VMAs are no longer shared, and there are now region structs). Signed-off-by: David Howells <dhowells@redhat.com> Tested-by: Mike Frysinger <vapier.adi@gmail.com> Acked-by: Paul Mundt <lethal@linux-sh.org>
1 parent 4183638 commit 8feae13

23 files changed

Lines changed: 860 additions & 436 deletions

File tree

‎Documentation/nommu-mmap.txt‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,18 @@ and it's also much more restricted in the latter case:
109109
FURTHER NOTES ON NO-MMU MMAP
110110
============================
111111

112-
(*) A request for a private mapping of less than a page in size may not return
113-
a page-aligned buffer. This is because the kernel calls kmalloc() to
114-
allocate the buffer, not get_free_page().
115-
116-
(*) A list of all the mappings on the system is visible through /proc/maps in
117-
no-MMU mode.
112+
(*) A request for a private mapping of a file may return a buffer that is not
113+
page-aligned. This is because XIP may take place, and the data may not be
114+
paged aligned in the backing store.
115+
116+
(*) A request for an anonymous mapping will always be page aligned. If
117+
possible the size of the request should be a power of two otherwise some
118+
of the space may be wasted as the kernel must allocate a power-of-2
119+
granule but will only discard the excess if appropriately configured as
120+
this has an effect on fragmentation.
121+
122+
(*) A list of all the private copy and anonymous mappings on the system is
123+
visible through /proc/maps in no-MMU mode.
118124

119125
(*) A list of all the mappings in use by a process is visible through
120126
/proc/<pid>/maps in no-MMU mode.

‎arch/arm/include/asm/mmu.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ typedef struct {
2424
* modified for 2.6 by Hyok S. Choi <hyok.choi@samsung.com>
2525
*/
2626
typedef struct {
27-
struct vm_list_struct *vmlist;
2827
unsigned long end_brk;
2928
} mm_context_t;
3029

‎arch/blackfin/include/asm/mmu.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ struct sram_list_struct {
1010
};
1111

1212
typedef struct {
13-
struct vm_list_struct *vmlist;
1413
unsigned long end_brk;
1514
unsigned long stack_start;
1615

‎arch/blackfin/kernel/ptrace.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,15 @@ put_reg(struct task_struct *task, int regno, unsigned long data)
160160
static inline int is_user_addr_valid(struct task_struct *child,
161161
unsigned long start, unsigned long len)
162162
{
163-
struct vm_list_struct *vml;
163+
struct vm_area_struct *vma;
164164
struct sram_list_struct *sraml;
165165

166166
/* overflow */
167167
if (start + len < start)
168168
return -EIO;
169169

170-
for (vml = child->mm->context.vmlist; vml; vml = vml->next)
171-
if (start >= vml->vma->vm_start && start + len < vml->vma->vm_end)
170+
vma = find_vma(child->mm, start);
171+
if (vma && start >= vma->vm_start && start + len <= vma->vm_end)
172172
return 0;
173173

174174
for (sraml = child->mm->context.sram_list; sraml; sraml = sraml->next)

‎arch/blackfin/kernel/traps.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/module.h>
3333
#include <linux/kallsyms.h>
3434
#include <linux/fs.h>
35+
#include <linux/rbtree.h>
3536
#include <asm/traps.h>
3637
#include <asm/cacheflush.h>
3738
#include <asm/cplb.h>
@@ -83,6 +84,7 @@ static void decode_address(char *buf, unsigned long address)
8384
struct mm_struct *mm;
8485
unsigned long flags, offset;
8586
unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
87+
struct rb_node *n;
8688

8789
#ifdef CONFIG_KALLSYMS
8890
unsigned long symsize;
@@ -128,9 +130,10 @@ static void decode_address(char *buf, unsigned long address)
128130
if (!mm)
129131
continue;
130132

131-
vml = mm->context.vmlist;
132-
while (vml) {
133-
struct vm_area_struct *vma = vml->vma;
133+
for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
134+
struct vm_area_struct *vma;
135+
136+
vma = rb_entry(n, struct vm_area_struct, vm_rb);
134137

135138
if (address >= vma->vm_start && address < vma->vm_end) {
136139
char _tmpbuf[256];
@@ -176,8 +179,6 @@ static void decode_address(char *buf, unsigned long address)
176179

177180
goto done;
178181
}
179-
180-
vml = vml->next;
181182
}
182183
if (!in_atomic)
183184
mmput(mm);

‎arch/frv/kernel/ptrace.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ static inline int put_reg(struct task_struct *task, int regno,
6969
}
7070

7171
/*
72-
* check that an address falls within the bounds of the target process's memory mappings
72+
* check that an address falls within the bounds of the target process's memory
73+
* mappings
7374
*/
7475
static inline int is_user_addr_valid(struct task_struct *child,
7576
unsigned long start, unsigned long len)
@@ -79,11 +80,11 @@ static inline int is_user_addr_valid(struct task_struct *child,
7980
return -EIO;
8081
return 0;
8182
#else
82-
struct vm_list_struct *vml;
83+
struct vm_area_struct *vma;
8384

84-
for (vml = child->mm->context.vmlist; vml; vml = vml->next)
85-
if (start >= vml->vma->vm_start && start + len <= vml->vma->vm_end)
86-
return 0;
85+
vma = find_vma(child->mm, start);
86+
if (vma && start >= vma->vm_start && start + len <= vma->vm_end)
87+
return 0;
8788

8889
return -EIO;
8990
#endif

‎arch/h8300/include/asm/mmu.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
/* Copyright (C) 2002, David McCullough <davidm@snapgear.com> */
55

66
typedef struct {
7-
struct vm_list_struct *vmlist;
87
unsigned long end_brk;
98
} mm_context_t;
109

‎arch/m68knommu/include/asm/mmu.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
/* Copyright (C) 2002, David McCullough <davidm@snapgear.com> */
55

66
typedef struct {
7-
struct vm_list_struct *vmlist;
87
unsigned long end_brk;
98
} mm_context_t;
109

‎arch/sh/include/asm/mmu.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ typedef struct {
99
mm_context_id_t id;
1010
void *vdso;
1111
#else
12-
struct vm_list_struct *vmlist;
1312
unsigned long end_brk;
1413
#endif
1514
#ifdef CONFIG_BINFMT_ELF_FDPIC

‎fs/binfmt_elf_fdpic.c‎

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,11 +1567,9 @@ static int elf_fdpic_dump_segments(struct file *file, size_t *size,
15671567
static int elf_fdpic_dump_segments(struct file *file, size_t *size,
15681568
unsigned long *limit, unsigned long mm_flags)
15691569
{
1570-
struct vm_list_struct *vml;
1571-
1572-
for (vml = current->mm->context.vmlist; vml; vml = vml->next) {
1573-
struct vm_area_struct *vma = vml->vma;
1570+
struct vm_area_struct *vma;
15741571

1572+
for (vma = current->mm->mmap; vma; vma = vma->vm_next) {
15751573
if (!maydump(vma, mm_flags))
15761574
continue;
15771575

@@ -1617,9 +1615,6 @@ static int elf_fdpic_core_dump(long signr, struct pt_regs *regs,
16171615
elf_fpxregset_t *xfpu = NULL;
16181616
#endif
16191617
int thread_status_size = 0;
1620-
#ifndef CONFIG_MMU
1621-
struct vm_list_struct *vml;
1622-
#endif
16231618
elf_addr_t *auxv;
16241619
unsigned long mm_flags;
16251620

@@ -1685,13 +1680,7 @@ static int elf_fdpic_core_dump(long signr, struct pt_regs *regs,
16851680
fill_prstatus(prstatus, current, signr);
16861681
elf_core_copy_regs(&prstatus->pr_reg, regs);
16871682

1688-
#ifdef CONFIG_MMU
16891683
segs = current->mm->map_count;
1690-
#else
1691-
segs = 0;
1692-
for (vml = current->mm->context.vmlist; vml; vml = vml->next)
1693-
segs++;
1694-
#endif
16951684
#ifdef ELF_CORE_EXTRA_PHDRS
16961685
segs += ELF_CORE_EXTRA_PHDRS;
16971686
#endif
@@ -1766,20 +1755,10 @@ static int elf_fdpic_core_dump(long signr, struct pt_regs *regs,
17661755
mm_flags = current->mm->flags;
17671756

17681757
/* write program headers for segments dump */
1769-
for (
1770-
#ifdef CONFIG_MMU
1771-
vma = current->mm->mmap; vma; vma = vma->vm_next
1772-
#else
1773-
vml = current->mm->context.vmlist; vml; vml = vml->next
1774-
#endif
1775-
) {
1758+
for (vma = current->mm->mmap; vma; vma = vma->vm_next) {
17761759
struct elf_phdr phdr;
17771760
size_t sz;
17781761

1779-
#ifndef CONFIG_MMU
1780-
vma = vml->vma;
1781-
#endif
1782-
17831762
sz = vma->vm_end - vma->vm_start;
17841763

17851764
phdr.p_type = PT_LOAD;

0 commit comments

Comments
 (0)