Skip to content

Commit

Permalink
mm: make do_mmap_pgoff return populate as a size in bytes, not as a bool
Browse files Browse the repository at this point in the history
do_mmap_pgoff() rounds up the desired size to the next PAGE_SIZE
multiple, however there was no equivalent code in mm_populate(), which
caused issues.

This could be fixed by introduced the same rounding in mm_populate(),
however I think it's preferable to make do_mmap_pgoff() return populate
as a size rather than as a boolean, so we don't have to duplicate the
size rounding logic in mm_populate().

Signed-off-by: Michel Lespinasse <[email protected]>
Acked-by: Rik van Riel <[email protected]>
Tested-by: Andy Lutomirski <[email protected]>
Cc: Greg Ungerer <[email protected]>
Cc: David Howells <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
walken-google authored and torvalds committed Feb 24, 2013
1 parent 1869305 commit 41badc1
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
5 changes: 2 additions & 3 deletions fs/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ static int aio_setup_ring(struct kioctx *ctx)
struct aio_ring *ring;
struct aio_ring_info *info = &ctx->ring_info;
unsigned nr_events = ctx->max_reqs;
unsigned long size;
unsigned long size, populate;
int nr_pages;
bool populate;

/* Compensate for the ring buffer's head/tail overlap entry */
nr_events += 2; /* 1 is required, 2 for good luck */
Expand Down Expand Up @@ -150,7 +149,7 @@ static int aio_setup_ring(struct kioctx *ctx)
return -EAGAIN;
}
if (populate)
mm_populate(info->mmap_base, info->mmap_size);
mm_populate(info->mmap_base, populate);

ctx->user_id = info->mmap_base;

Expand Down
2 changes: 1 addition & 1 deletion include/linux/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ extern unsigned long mmap_region(struct file *file, unsigned long addr,
unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
unsigned long len, unsigned long prot, unsigned long flags,
unsigned long pgoff, bool *populate);
unsigned long pgoff, unsigned long *populate);
extern int do_munmap(struct mm_struct *, unsigned long, size_t);

#ifdef CONFIG_MMU
Expand Down
4 changes: 2 additions & 2 deletions ipc/shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
struct shm_file_data *sfd;
struct path path;
fmode_t f_mode;
bool populate = false;
unsigned long populate = 0;

err = -EINVAL;
if (shmid < 0)
Expand Down Expand Up @@ -1078,7 +1078,7 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
invalid:
up_write(&current->mm->mmap_sem);
if (populate)
mm_populate(addr, size);
mm_populate(addr, populate);

out_fput:
fput(file);
Expand Down
6 changes: 3 additions & 3 deletions mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1163,13 +1163,13 @@ static inline unsigned long round_hint_to_min(unsigned long hint)
unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
unsigned long len, unsigned long prot,
unsigned long flags, unsigned long pgoff,
bool *populate)
unsigned long *populate)
{
struct mm_struct * mm = current->mm;
struct inode *inode;
vm_flags_t vm_flags;

*populate = false;
*populate = 0;

/*
* Does the application expect PROT_READ to imply PROT_EXEC?
Expand Down Expand Up @@ -1307,7 +1307,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,

addr = mmap_region(file, addr, len, vm_flags, pgoff);
if (!IS_ERR_VALUE(addr) && (vm_flags & VM_POPULATE))
*populate = true;
*populate = len;
return addr;
}

Expand Down
4 changes: 2 additions & 2 deletions mm/nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ unsigned long do_mmap_pgoff(struct file *file,
unsigned long prot,
unsigned long flags,
unsigned long pgoff,
bool *populate)
unsigned long *populate)
{
struct vm_area_struct *vma;
struct vm_region *region;
Expand All @@ -1261,7 +1261,7 @@ unsigned long do_mmap_pgoff(struct file *file,

kenter(",%lx,%lx,%lx,%lx,%lx", addr, len, prot, flags, pgoff);

*populate = false;
*populate = 0;

/* decide whether we should attempt the mapping, and if so what sort of
* mapping */
Expand Down
6 changes: 3 additions & 3 deletions mm/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,16 +355,16 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
{
unsigned long ret;
struct mm_struct *mm = current->mm;
bool populate;
unsigned long populate;

ret = security_mmap_file(file, prot, flag);
if (!ret) {
down_write(&mm->mmap_sem);
ret = do_mmap_pgoff(file, addr, len, prot, flag, pgoff,
&populate);
up_write(&mm->mmap_sem);
if (!IS_ERR_VALUE(ret) && populate)
mm_populate(ret, len);
if (populate)
mm_populate(ret, populate);
}
return ret;
}
Expand Down

0 comments on commit 41badc1

Please sign in to comment.