Skip to content

Commit 6aab341

Browse files
author
Linus Torvalds
committed
mm: re-architect the VM_UNPAGED logic
This replaces the (in my opinion horrible) VM_UNMAPPED logic with very explicit support for a "remapped page range" aka VM_PFNMAP. It allows a VM area to contain an arbitrary range of page table entries that the VM never touches, and never considers to be normal pages. Any user of "remap_pfn_range()" automatically gets this new functionality, and doesn't even have to mark the pages reserved or indeed mark them any other way. It just works. As a side effect, doing mmap() on /dev/mem works for arbitrary ranges. Sparc update from David in the next commit. Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 458af54 commit 6aab341

11 files changed

Lines changed: 127 additions & 146 deletions

File tree

‎arch/powerpc/kernel/vdso.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ static void dump_vdso_pages(struct vm_area_struct * vma)
145145
struct page *pg = virt_to_page(vdso32_kbase +
146146
i*PAGE_SIZE);
147147
struct page *upg = (vma && vma->vm_mm) ?
148-
follow_page(vma->vm_mm, vma->vm_start +
149-
i*PAGE_SIZE, 0)
148+
follow_page(vma, vma->vm_start + i*PAGE_SIZE, 0)
150149
: NULL;
151150
dump_one_vdso_page(pg, upg);
152151
}
@@ -157,8 +156,7 @@ static void dump_vdso_pages(struct vm_area_struct * vma)
157156
struct page *pg = virt_to_page(vdso64_kbase +
158157
i*PAGE_SIZE);
159158
struct page *upg = (vma && vma->vm_mm) ?
160-
follow_page(vma->vm_mm, vma->vm_start +
161-
i*PAGE_SIZE, 0)
159+
follow_page(vma, vma->vm_start + i*PAGE_SIZE, 0)
162160
: NULL;
163161
dump_one_vdso_page(pg, upg);
164162
}

‎drivers/char/mem.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ static inline size_t read_zero_pagealigned(char __user * buf, size_t size)
591591

592592
if (vma->vm_start > addr || (vma->vm_flags & VM_WRITE) == 0)
593593
goto out_up;
594-
if (vma->vm_flags & (VM_SHARED | VM_HUGETLB | VM_UNPAGED))
594+
if (vma->vm_flags & (VM_SHARED | VM_HUGETLB))
595595
break;
596596
count = vma->vm_end - addr;
597597
if (count > size)

‎fs/proc/task_mmu.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,11 @@ struct numa_maps {
402402
/*
403403
* Calculate numa node maps for a vma
404404
*/
405-
static struct numa_maps *get_numa_maps(const struct vm_area_struct *vma)
405+
static struct numa_maps *get_numa_maps(struct vm_area_struct *vma)
406406
{
407+
int i;
407408
struct page *page;
408409
unsigned long vaddr;
409-
struct mm_struct *mm = vma->vm_mm;
410-
int i;
411410
struct numa_maps *md = kmalloc(sizeof(struct numa_maps), GFP_KERNEL);
412411

413412
if (!md)
@@ -420,7 +419,7 @@ static struct numa_maps *get_numa_maps(const struct vm_area_struct *vma)
420419
md->node[i] =0;
421420

422421
for (vaddr = vma->vm_start; vaddr < vma->vm_end; vaddr += PAGE_SIZE) {
423-
page = follow_page(mm, vaddr, 0);
422+
page = follow_page(vma, vaddr, 0);
424423
if (page) {
425424
int count = page_mapcount(page);
426425

‎include/linux/mm.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ extern unsigned int kobjsize(const void *objp);
145145
#define VM_GROWSDOWN 0x00000100 /* general info on the segment */
146146
#define VM_GROWSUP 0x00000200
147147
#define VM_SHM 0x00000000 /* Means nothing: delete it later */
148-
#define VM_UNPAGED 0x00000400 /* Pages managed without map count */
148+
#define VM_PFNMAP 0x00000400 /* Page-ranges managed without "struct page", just pure PFN */
149149
#define VM_DENYWRITE 0x00000800 /* ETXTBSY on write attempts.. */
150150

151151
#define VM_EXECUTABLE 0x00001000
@@ -664,6 +664,7 @@ struct zap_details {
664664
unsigned long truncate_count; /* Compare vm_truncate_count */
665665
};
666666

667+
struct page *vm_normal_page(struct vm_area_struct *, unsigned long, pte_t);
667668
unsigned long zap_page_range(struct vm_area_struct *vma, unsigned long address,
668669
unsigned long size, struct zap_details *);
669670
unsigned long unmap_vmas(struct mmu_gather **tlb,
@@ -953,7 +954,7 @@ unsigned long vmalloc_to_pfn(void *addr);
953954
int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
954955
unsigned long pfn, unsigned long size, pgprot_t);
955956

956-
struct page *follow_page(struct mm_struct *, unsigned long address,
957+
struct page *follow_page(struct vm_area_struct *, unsigned long address,
957958
unsigned int foll_flags);
958959
#define FOLL_WRITE 0x01 /* check pte is writable */
959960
#define FOLL_TOUCH 0x02 /* mark page accessed */

‎mm/fremap.c‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,20 @@ static int zap_pte(struct mm_struct *mm, struct vm_area_struct *vma,
2727
struct page *page = NULL;
2828

2929
if (pte_present(pte)) {
30-
unsigned long pfn = pte_pfn(pte);
31-
flush_cache_page(vma, addr, pfn);
30+
flush_cache_page(vma, addr, pte_pfn(pte));
3231
pte = ptep_clear_flush(vma, addr, ptep);
33-
if (unlikely(!pfn_valid(pfn))) {
34-
print_bad_pte(vma, pte, addr);
35-
goto out;
32+
page = vm_normal_page(vma, addr, pte);
33+
if (page) {
34+
if (pte_dirty(pte))
35+
set_page_dirty(page);
36+
page_remove_rmap(page);
37+
page_cache_release(page);
3638
}
37-
page = pfn_to_page(pfn);
38-
if (pte_dirty(pte))
39-
set_page_dirty(page);
40-
page_remove_rmap(page);
41-
page_cache_release(page);
4239
} else {
4340
if (!pte_file(pte))
4441
free_swap_and_cache(pte_to_swp_entry(pte));
4542
pte_clear(mm, addr, ptep);
4643
}
47-
out:
4844
return !!page;
4945
}
5046

@@ -65,8 +61,6 @@ int install_page(struct mm_struct *mm, struct vm_area_struct *vma,
6561
pte_t pte_val;
6662
spinlock_t *ptl;
6763

68-
BUG_ON(vma->vm_flags & VM_UNPAGED);
69-
7064
pgd = pgd_offset(mm, addr);
7165
pud = pud_alloc(mm, pgd, addr);
7266
if (!pud)
@@ -122,8 +116,6 @@ int install_file_pte(struct mm_struct *mm, struct vm_area_struct *vma,
122116
pte_t pte_val;
123117
spinlock_t *ptl;
124118

125-
BUG_ON(vma->vm_flags & VM_UNPAGED);
126-
127119
pgd = pgd_offset(mm, addr);
128120
pud = pud_alloc(mm, pgd, addr);
129121
if (!pud)

‎mm/madvise.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static long madvise_dontneed(struct vm_area_struct * vma,
126126
unsigned long start, unsigned long end)
127127
{
128128
*prev = vma;
129-
if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_UNPAGED))
129+
if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
130130
return -EINVAL;
131131

132132
if (unlikely(vma->vm_flags & VM_NONLINEAR)) {

0 commit comments

Comments
 (0)