···310310 return 0;311311}312312313313-static void aio_ring_remap(struct file *file, struct vm_area_struct *vma)313313+static int aio_ring_remap(struct file *file, struct vm_area_struct *vma)314314{315315 struct mm_struct *mm = vma->vm_mm;316316 struct kioctx_table *table;317317- int i;317317+ int i, res = -EINVAL;318318319319 spin_lock(&mm->ioctx_lock);320320 rcu_read_lock();···324324325325 ctx = table->table[i];326326 if (ctx && ctx->aio_ring_file == file) {327327- ctx->user_id = ctx->mmap_base = vma->vm_start;327327+ if (!atomic_read(&ctx->dead)) {328328+ ctx->user_id = ctx->mmap_base = vma->vm_start;329329+ res = 0;330330+ }328331 break;329332 }330333 }331334332335 rcu_read_unlock();333336 spin_unlock(&mm->ioctx_lock);337337+ return res;334338}335339336340static const struct file_operations aio_ring_fops = {···763759err_cleanup:764760 aio_nr_sub(ctx->max_reqs);765761err_ctx:762762+ atomic_set(&ctx->dead, 1);763763+ if (ctx->mmap_size)764764+ vm_munmap(ctx->mmap_base, ctx->mmap_size);766765 aio_free_ring(ctx);767766err:768767 mutex_unlock(&ctx->ring_lock);···787780{788781 struct kioctx_table *table;789782790790- if (atomic_xchg(&ctx->dead, 1))791791- return -EINVAL;792792-793793-794783 spin_lock(&mm->ioctx_lock);784784+ if (atomic_xchg(&ctx->dead, 1)) {785785+ spin_unlock(&mm->ioctx_lock);786786+ return -EINVAL;787787+ }788788+795789 table = rcu_dereference_raw(mm->ioctx_table);796790 WARN_ON(ctx != table->table[ctx->id]);797791 table->table[ctx->id] = NULL;
+11-6
fs/ocfs2/file.c
···23912391 /*23922392 * for completing the rest of the request.23932393 */23942394- *ppos += written;23952394 count -= written;23962395 written_buffered = generic_perform_write(file, from, *ppos);23972396 /*···24052406 goto out_dio;24062407 }2407240824082408- iocb->ki_pos = *ppos + written_buffered;24092409 /* We need to ensure that the page cache pages are written to24102410 * disk and invalidated to preserve the expected O_DIRECT24112411 * semantics.···24132415 ret = filemap_write_and_wait_range(file->f_mapping, *ppos,24142416 endbyte);24152417 if (ret == 0) {24182418+ iocb->ki_pos = *ppos + written_buffered;24162419 written += written_buffered;24172420 invalidate_mapping_pages(mapping,24182421 *ppos >> PAGE_CACHE_SHIFT,···24362437 /* buffered aio wouldn't have proper lock coverage today */24372438 BUG_ON(ret == -EIOCBQUEUED && !(file->f_flags & O_DIRECT));2438243924402440+ if (unlikely(written <= 0))24412441+ goto no_sync;24422442+24392443 if (((file->f_flags & O_DSYNC) && !direct_io) || IS_SYNC(inode) ||24402444 ((file->f_flags & O_DIRECT) && !direct_io)) {24412441- ret = filemap_fdatawrite_range(file->f_mapping, *ppos,24422442- *ppos + count - 1);24452445+ ret = filemap_fdatawrite_range(file->f_mapping,24462446+ iocb->ki_pos - written,24472447+ iocb->ki_pos - 1);24432448 if (ret < 0)24442449 written = ret;24452450···24542451 }2455245224562453 if (!ret)24572457- ret = filemap_fdatawait_range(file->f_mapping, *ppos,24582458- *ppos + count - 1);24542454+ ret = filemap_fdatawait_range(file->f_mapping,24552455+ iocb->ki_pos - written,24562456+ iocb->ki_pos - 1);24592457 }2460245824592459+no_sync:24612460 /*24622461 * deep in g_f_a_w_n()->ocfs2_direct_IO we pass in a ocfs2_dio_end_io24632462 * function pointer which is called when o_direct io completes so that
+1-1
include/linux/fs.h
···15691569 long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);15701570 long (*compat_ioctl) (struct file *, unsigned int, unsigned long);15711571 int (*mmap) (struct file *, struct vm_area_struct *);15721572- void (*mremap)(struct file *, struct vm_area_struct *);15721572+ int (*mremap)(struct file *, struct vm_area_struct *);15731573 int (*open) (struct inode *, struct file *);15741574 int (*flush) (struct file *, fl_owner_t id);15751575 int (*release) (struct inode *, struct file *);
+8-2
mm/mremap.c
···286286 old_len = new_len;287287 old_addr = new_addr;288288 new_addr = -ENOMEM;289289- } else if (vma->vm_file && vma->vm_file->f_op->mremap)290290- vma->vm_file->f_op->mremap(vma->vm_file, new_vma);289289+ } else if (vma->vm_file && vma->vm_file->f_op->mremap) {290290+ err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);291291+ if (err < 0) {292292+ move_page_tables(new_vma, new_addr, vma, old_addr,293293+ moved_len, true);294294+ return err;295295+ }296296+ }291297292298 /* Conceal VM_ACCOUNT so old reservation is not undone */293299 if (vm_flags & VM_ACCOUNT) {