From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58FB4C76186 for ; Wed, 24 Jul 2019 20:09:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2B8B720665 for ; Wed, 24 Jul 2019 20:09:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563998947; bh=KO1mmfrXB/4Qi6kQgaa12CkoQHiEMULINy7lqSaWw2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=fhzl7wQOpmaDot8WU8H/U5QQFY4w07VqCAAod0ey3ZiCCwUR3Du9lUXacpWqe5569 af3BEEK08vggXL8yyhFobyEyKGNCjcUl0UPMSehi+YqK1HiuDZnIvty/bPvftmwTTp uG/7HyYKVwf3wmUgVfjsqT1mJrZ4gkOKKbPBpKr0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405331AbfGXUBG (ORCPT ); Wed, 24 Jul 2019 16:01:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:49576 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405328AbfGXUBE (ORCPT ); Wed, 24 Jul 2019 16:01:04 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 921D9205C9; Wed, 24 Jul 2019 20:01:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563998464; bh=KO1mmfrXB/4Qi6kQgaa12CkoQHiEMULINy7lqSaWw2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fbrbQmZPxJEHNQC0+bducLxv9X5adm2K4mWHN0sO11NSMj3S5tfXgsv+8fg3RwSgF p5hW7We75zU1/p+LEo7hP+ODIho1C7ujienEP7Dnl4EvBl6hbYi6wTGLbwVl9T1Ifw QyLpb2LLVaIUsu5fV02QmMuCBEXpmId/yZFYAtJc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Chinner , "Darrick J. Wong" , Brian Foster , Dave Chinner , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.1 345/371] xfs: abort unaligned nowait directio early Date: Wed, 24 Jul 2019 21:21:37 +0200 Message-Id: <20190724191749.638151167@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191724.382593077@linuxfoundation.org> References: <20190724191724.382593077@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org [ Upstream commit 1fdeaea4d92c69fb9f871a787af6ad00f32eeea7 ] Dave Chinner noticed that xfs_file_dio_aio_write returns EAGAIN without dropping the IOLOCK when its deciding not to wait, which means that we leak the IOLOCK there. Since we now make unaligned directio always wait, we have the opportunity to bail out before trying to take the lock, which should reduce the overhead of this never-gonna-work case considerably while also solving the dropped lock problem. Reported-by: Dave Chinner Signed-off-by: Darrick J. Wong Reviewed-by: Brian Foster Reviewed-by: Dave Chinner Reviewed-by: Christoph Hellwig Signed-off-by: Sasha Levin --- fs/xfs/xfs_file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index a7ceae90110e..76748255f843 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -517,6 +517,9 @@ xfs_file_dio_aio_write( } if (iocb->ki_flags & IOCB_NOWAIT) { + /* unaligned dio always waits, bail */ + if (unaligned_io) + return -EAGAIN; if (!xfs_ilock_nowait(ip, iolock)) return -EAGAIN; } else { @@ -536,9 +539,6 @@ xfs_file_dio_aio_write( * xfs_file_aio_write_checks() for other reasons. */ if (unaligned_io) { - /* unaligned dio always waits, bail */ - if (iocb->ki_flags & IOCB_NOWAIT) - return -EAGAIN; inode_dio_wait(inode); } else if (iolock == XFS_IOLOCK_EXCL) { xfs_ilock_demote(ip, XFS_IOLOCK_EXCL); -- 2.20.1