From patchwork Sat Jan 9 22:08:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin LaHaise X-Patchwork-Id: 7993771 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6DB5DBEEE5 for ; Sat, 9 Jan 2016 22:09:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3AC23202B4 for ; Sat, 9 Jan 2016 22:09:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0953F20295 for ; Sat, 9 Jan 2016 22:09:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756155AbcAIWI2 (ORCPT ); Sat, 9 Jan 2016 17:08:28 -0500 Received: from kanga.kvack.org ([205.233.56.17]:32934 "EHLO kanga.kvack.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756051AbcAIWI1 (ORCPT ); Sat, 9 Jan 2016 17:08:27 -0500 Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EBC9828EE; Sat, 9 Jan 2016 17:08:26 -0500 (EST) Date: Sat, 9 Jan 2016 17:08:26 -0500 From: Benjamin LaHaise To: Linus Torvalds Cc: Linux Kernel , linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, Jan Kara , Dmitry Vyukov Subject: [GIT PULL] aio: a couple of fixes for 4.4 Message-ID: <20160109220826.GA11174@kvack.org> Mime-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hello Linus et al, Please consider pulling the following changes to fix a couple of issues reported by Dmitry from git://git.kvack.org/~bcrl/aio-fixes.git . Thanks! -ben Benjamin LaHaise (1): aio: handle integer overflow in io_getevents() timespec usage Jan Kara (1): aio: Fix freeze protection of aio writes fs/aio.c | 33 ++++++++++++++++++++++++++++++--- include/linux/fs.h | 1 + 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 155f842..e0d5398 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1269,6 +1269,8 @@ static long read_events(struct kioctx *ctx, long min_nr, long nr, if (unlikely(copy_from_user(&ts, timeout, sizeof(ts)))) return -EFAULT; + if (!timespec_valid(&ts)) + return -EINVAL; until = timespec_to_ktime(ts); } -- 2.5.0 From 3b9688ff1e083a3c981bbc795f823fb0b0f2aacc Mon Sep 17 00:00:00 2001 From: Jan Kara Date: Thu, 7 Jan 2016 16:03:04 +0100 Subject: [PATCH 2/2] aio: Fix freeze protection of aio writes Currently we dropped freeze protection of aio writes just after IO was submitted. Thus aio write could be in flight while the filesystem was frozen and that could result in unexpected situation like aio completion wanting to convert extent type on frozen filesystem. Testcase from Dmitry triggering this is like: for ((i=0;i<60;i++));do fsfreeze -f /mnt ;sleep 1;fsfreeze -u /mnt;done & fio --bs=4k --ioengine=libaio --iodepth=128 --size=1g --direct=1 \ --runtime=60 --filename=/mnt/file --name=rand-write --rw=randwrite Fix the problem by dropping freeze protection only once IO is completed in aio_complete(). Reported-by: Dmitry Monakhov Signed-off-by: Jan Kara Signed-off-by: Benjamin LaHaise diff --git a/fs/aio.c b/fs/aio.c index e0d5398..a574944 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1065,6 +1065,19 @@ static void aio_complete(struct kiocb *kiocb, long res, long res2) unsigned tail, pos, head; unsigned long flags; + if (kiocb->ki_flags & IOCB_WRITE) { + struct file *f = kiocb->ki_filp; + + /* + * Tell lockdep we inherited freeze protection from submission + * thread. + */ + percpu_rwsem_acquire( + &f->f_inode->i_sb->s_writers.rw_sem[SB_FREEZE_WRITE-1], + 1, _THIS_IP_); + file_end_write(f); + } + /* * Special case handling for sync iocbs: * - events go directly into the iocb for fast handling @@ -1451,13 +1464,25 @@ rw_common: len = ret; - if (rw == WRITE) + if (rw == WRITE) { file_start_write(file); + req->ki_flags |= IOCB_WRITE; + } ret = iter_op(req, &iter); - if (rw == WRITE) - file_end_write(file); + if (rw == WRITE) { + /* + * We release freeze protection in aio_complete(). Fool + * lockdep by telling it the lock got released so that + * it doesn't complain about held lock when we return + * to userspace. + */ + percpu_rwsem_release( + &file->f_inode->i_sb->s_writers.rw_sem[SB_FREEZE_WRITE-1], + 1, _THIS_IP_); + } + kfree(iovec); break; diff --git a/include/linux/fs.h b/include/linux/fs.h index 3aa5142..54af40e 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -319,6 +319,7 @@ struct writeback_control; #define IOCB_EVENTFD (1 << 0) #define IOCB_APPEND (1 << 1) #define IOCB_DIRECT (1 << 2) +#define IOCB_WRITE (1 << 3) struct kiocb { struct file *ki_filp;