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=-8.6 required=3.0 tests=DATE_IN_PAST_06_12, 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 2086CC7618B for ; Thu, 25 Jul 2019 05:48:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D73E820657 for ; Thu, 25 Jul 2019 05:48:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564033706; bh=b2UBcwkfIU2ZO7dtFRhcgHXFH5JZVsiLzCQVo4m4NaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Iu0Nlwffu6mfQrCzwYBDl9OYvUJz8KZ2ePsKcXycKkQZASCy28VbBayxDpOcc8PQ4 cqCdxmRjjnNpqujYgPLjpdnP3+rioL6ETjTprfrOdagTGS14h+6laf349dow/4LFEf OkdFi4c2QrKScQc1u3VLAv4T62C/zjzUi3WTmv4s= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391391AbfGYFqM (ORCPT ); Thu, 25 Jul 2019 01:46:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:33634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728590AbfGYFqH (ORCPT ); Thu, 25 Jul 2019 01:46:07 -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 5457021880; Thu, 25 Jul 2019 05:46:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564033566; bh=b2UBcwkfIU2ZO7dtFRhcgHXFH5JZVsiLzCQVo4m4NaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JhKkKATFv07TICJG8wUFdrHLMzmkPnQEPSmBRtOFoXfOIOaZ0yYsndZBRtiLG4lcJ mQKeIS0c72PaymRdU7H++oVo/ddfSyJaj4s4MpgMFckLLecjUBuVQURJ23NtBPLb5L 2QDZWn+ZwNDOZkQel7Ot71XOCbKoUx98n2WwE9m0= 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 , Luis Chamberlain , Sasha Levin Subject: [PATCH 4.19 250/271] xfs: abort unaligned nowait directio early Date: Wed, 24 Jul 2019 21:21:59 +0200 Message-Id: <20190724191716.606604161@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191655.268628197@linuxfoundation.org> References: <20190724191655.268628197@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit 1fdeaea4d92c69fb9f871a787af6ad00f32eeea7 upstream. 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: Luis Chamberlain 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 10f75965243c..259549698ba7 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