Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8feae131 authored by David Howells's avatar David Howells
Browse files

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: default avatarDavid Howells <dhowells@redhat.com>
Tested-by: default avatarMike Frysinger <vapier.adi@gmail.com>
Acked-by: default avatarPaul Mundt <lethal@linux-sh.org>
parent 41836382
Loading
Loading
Loading
Loading
+12 −6
Original line number Original line Diff line number Diff line
@@ -109,12 +109,18 @@ and it's also much more restricted in the latter case:
FURTHER NOTES ON NO-MMU MMAP
FURTHER NOTES ON NO-MMU MMAP
============================
============================


 (*) A request for a private mapping of less than a page in size may not return
 (*) A request for a private mapping of a file may return a buffer that is not
     a page-aligned buffer. This is because the kernel calls kmalloc() to
     page-aligned.  This is because XIP may take place, and the data may not be
     allocate the buffer, not get_free_page().
     paged aligned in the backing store.


 (*) A list of all the mappings on the system is visible through /proc/maps in
 (*) A request for an anonymous mapping will always be page aligned.  If
     no-MMU mode.
     possible the size of the request should be a power of two otherwise some
     of the space may be wasted as the kernel must allocate a power-of-2
     granule but will only discard the excess if appropriately configured as
     this has an effect on fragmentation.

 (*) A list of all the private copy and anonymous mappings on the system is
     visible through /proc/maps in no-MMU mode.


 (*) A list of all the mappings in use by a process is visible through
 (*) A list of all the mappings in use by a process is visible through
     /proc/<pid>/maps in no-MMU mode.
     /proc/<pid>/maps in no-MMU mode.
+0 −1
Original line number Original line Diff line number Diff line
@@ -24,7 +24,6 @@ typedef struct {
 *  modified for 2.6 by Hyok S. Choi <hyok.choi@samsung.com>
 *  modified for 2.6 by Hyok S. Choi <hyok.choi@samsung.com>
 */
 */
typedef struct {
typedef struct {
	struct vm_list_struct	*vmlist;
	unsigned long		end_brk;
	unsigned long		end_brk;
} mm_context_t;
} mm_context_t;


+0 −1
Original line number Original line Diff line number Diff line
@@ -10,7 +10,6 @@ struct sram_list_struct {
};
};


typedef struct {
typedef struct {
	struct vm_list_struct *vmlist;
	unsigned long end_brk;
	unsigned long end_brk;
	unsigned long stack_start;
	unsigned long stack_start;


+3 −3
Original line number Original line Diff line number Diff line
@@ -160,15 +160,15 @@ put_reg(struct task_struct *task, int regno, unsigned long data)
static inline int is_user_addr_valid(struct task_struct *child,
static inline int is_user_addr_valid(struct task_struct *child,
				     unsigned long start, unsigned long len)
				     unsigned long start, unsigned long len)
{
{
	struct vm_list_struct *vml;
	struct vm_area_struct *vma;
	struct sram_list_struct *sraml;
	struct sram_list_struct *sraml;


	/* overflow */
	/* overflow */
	if (start + len < start)
	if (start + len < start)
		return -EIO;
		return -EIO;


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


	for (sraml = child->mm->context.sram_list; sraml; sraml = sraml->next)
	for (sraml = child->mm->context.sram_list; sraml; sraml = sraml->next)
+6 −5
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@
#include <linux/module.h>
#include <linux/module.h>
#include <linux/kallsyms.h>
#include <linux/kallsyms.h>
#include <linux/fs.h>
#include <linux/fs.h>
#include <linux/rbtree.h>
#include <asm/traps.h>
#include <asm/traps.h>
#include <asm/cacheflush.h>
#include <asm/cacheflush.h>
#include <asm/cplb.h>
#include <asm/cplb.h>
@@ -83,6 +84,7 @@ static void decode_address(char *buf, unsigned long address)
	struct mm_struct *mm;
	struct mm_struct *mm;
	unsigned long flags, offset;
	unsigned long flags, offset;
	unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
	unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
	struct rb_node *n;


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


		vml = mm->context.vmlist;
		for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
		while (vml) {
			struct vm_area_struct *vma;
			struct vm_area_struct *vma = vml->vma;

			vma = rb_entry(n, struct vm_area_struct, vm_rb);


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


				goto done;
				goto done;
			}
			}

			vml = vml->next;
		}
		}
		if (!in_atomic)
		if (!in_atomic)
			mmput(mm);
			mmput(mm);
Loading