diff options
| -rw-r--r-- | fs/aio.c | 17 | ||||
| -rw-r--r-- | include/linux/fs.h | 2 | ||||
| -rw-r--r-- | mm/mremap.c | 10 |
3 files changed, 20 insertions, 9 deletions
| @@ -278,11 +278,11 @@ static int aio_ring_mmap(struct file *file, struct vm_area_struct *vma) | |||
| 278 | return 0; | 278 | return 0; |
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | static void aio_ring_remap(struct file *file, struct vm_area_struct *vma) | 281 | static int aio_ring_remap(struct file *file, struct vm_area_struct *vma) |
| 282 | { | 282 | { |
| 283 | struct mm_struct *mm = vma->vm_mm; | 283 | struct mm_struct *mm = vma->vm_mm; |
| 284 | struct kioctx_table *table; | 284 | struct kioctx_table *table; |
| 285 | int i; | 285 | int i, res = -EINVAL; |
| 286 | 286 | ||
| 287 | spin_lock(&mm->ioctx_lock); | 287 | spin_lock(&mm->ioctx_lock); |
| 288 | rcu_read_lock(); | 288 | rcu_read_lock(); |
| @@ -292,13 +292,17 @@ static void aio_ring_remap(struct file *file, struct vm_area_struct *vma) | |||
| 292 | 292 | ||
| 293 | ctx = table->table[i]; | 293 | ctx = table->table[i]; |
| 294 | if (ctx && ctx->aio_ring_file == file) { | 294 | if (ctx && ctx->aio_ring_file == file) { |
| 295 | ctx->user_id = ctx->mmap_base = vma->vm_start; | 295 | if (!atomic_read(&ctx->dead)) { |
| 296 | ctx->user_id = ctx->mmap_base = vma->vm_start; | ||
| 297 | res = 0; | ||
| 298 | } | ||
| 296 | break; | 299 | break; |
| 297 | } | 300 | } |
| 298 | } | 301 | } |
| 299 | 302 | ||
| 300 | rcu_read_unlock(); | 303 | rcu_read_unlock(); |
| 301 | spin_unlock(&mm->ioctx_lock); | 304 | spin_unlock(&mm->ioctx_lock); |
| 305 | return res; | ||
| 302 | } | 306 | } |
| 303 | 307 | ||
| 304 | static const struct file_operations aio_ring_fops = { | 308 | static const struct file_operations aio_ring_fops = { |
| @@ -748,11 +752,12 @@ static int kill_ioctx(struct mm_struct *mm, struct kioctx *ctx, | |||
| 748 | { | 752 | { |
| 749 | struct kioctx_table *table; | 753 | struct kioctx_table *table; |
| 750 | 754 | ||
| 751 | if (atomic_xchg(&ctx->dead, 1)) | 755 | spin_lock(&mm->ioctx_lock); |
| 756 | if (atomic_xchg(&ctx->dead, 1)) { | ||
| 757 | spin_unlock(&mm->ioctx_lock); | ||
| 752 | return -EINVAL; | 758 | return -EINVAL; |
| 759 | } | ||
| 753 | 760 | ||
| 754 | |||
| 755 | spin_lock(&mm->ioctx_lock); | ||
| 756 | table = rcu_dereference_raw(mm->ioctx_table); | 761 | table = rcu_dereference_raw(mm->ioctx_table); |
| 757 | WARN_ON(ctx != table->table[ctx->id]); | 762 | WARN_ON(ctx != table->table[ctx->id]); |
| 758 | table->table[ctx->id] = NULL; | 763 | table->table[ctx->id] = NULL; |
diff --git a/include/linux/fs.h b/include/linux/fs.h index f4131e8ead74..52cc4492cb3a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
| @@ -1549,7 +1549,7 @@ struct file_operations { | |||
| 1549 | long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); | 1549 | long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); |
| 1550 | long (*compat_ioctl) (struct file *, unsigned int, unsigned long); | 1550 | long (*compat_ioctl) (struct file *, unsigned int, unsigned long); |
| 1551 | int (*mmap) (struct file *, struct vm_area_struct *); | 1551 | int (*mmap) (struct file *, struct vm_area_struct *); |
| 1552 | void (*mremap)(struct file *, struct vm_area_struct *); | 1552 | int (*mremap)(struct file *, struct vm_area_struct *); |
| 1553 | int (*open) (struct inode *, struct file *); | 1553 | int (*open) (struct inode *, struct file *); |
| 1554 | int (*flush) (struct file *, fl_owner_t id); | 1554 | int (*flush) (struct file *, fl_owner_t id); |
| 1555 | int (*release) (struct inode *, struct file *); | 1555 | int (*release) (struct inode *, struct file *); |
diff --git a/mm/mremap.c b/mm/mremap.c index 57dadc025c64..2dc44b1cb1df 100644 --- a/mm/mremap.c +++ b/mm/mremap.c | |||
| @@ -286,8 +286,14 @@ static unsigned long move_vma(struct vm_area_struct *vma, | |||
| 286 | old_len = new_len; | 286 | old_len = new_len; |
| 287 | old_addr = new_addr; | 287 | old_addr = new_addr; |
| 288 | new_addr = -ENOMEM; | 288 | new_addr = -ENOMEM; |
| 289 | } else if (vma->vm_file && vma->vm_file->f_op->mremap) | 289 | } else if (vma->vm_file && vma->vm_file->f_op->mremap) { |
| 290 | vma->vm_file->f_op->mremap(vma->vm_file, new_vma); | 290 | err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma); |
| 291 | if (err < 0) { | ||
| 292 | move_page_tables(new_vma, new_addr, vma, old_addr, | ||
| 293 | moved_len, true); | ||
| 294 | return err; | ||
| 295 | } | ||
| 296 | } | ||
| 291 | 297 | ||
| 292 | /* Conceal VM_ACCOUNT so old reservation is not undone */ | 298 | /* Conceal VM_ACCOUNT so old reservation is not undone */ |
| 293 | if (vm_flags & VM_ACCOUNT) { | 299 | if (vm_flags & VM_ACCOUNT) { |
