Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10428201ybi; Wed, 24 Jul 2019 23:02:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqzxENYIFpeGmNfKnBmqY9d5yn1uIuaF1JPaSwzet7+Z8jVgkpNwnjy6H5BEbCfd0svqVfWP X-Received: by 2002:a17:90a:17ab:: with SMTP id q40mr92690884pja.106.1564034576618; Wed, 24 Jul 2019 23:02:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564034576; cv=none; d=google.com; s=arc-20160816; b=VWz4Z3KTIe7G9wlAB5DcZIE+xEW9llgI4ac9k3pgAP6sYwjMwImBE2HGDdhKsSgDwU MD0GQZnRsRuc0NwZKZich6fU7DGuoPV2Mglnw8OHA/l8WhwwZpoKEG7cohssz2Xk0Bw3 jofQwp5sR3bEl8rwjc0wekEmwOlxdd1s+gafmJdNWdkJcSOl2zvje+hSqAdpG9iW2xGx 9raeihtvLMqXDH735hfSoADjVRuJ60a+wSS3bKvy2NLma6ROOW6siLXlKjH257V9Pc7s y7WKXHorFeIWZyHbHQEfYT2uArTJzmh78ls1g2K2J/xMf/a0DYIxkYZNHdMXWPuDdbfk DxJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+GLJB2qMt/ZAq2ri7GQGIJ5tsEBXWoOKO42ddwClaFc=; b=or1nVFOMZfO2DVHYfoEfAI/vx/nmHTMkrxAsF7KqlhnOGEzl0KhaJrFt42wGX3DoqC +TKTSEI7sI0fFwGqYwR1YAstdBaA87tToI76m9geOosto6SemhbPCWyksFeIuWRbSAao C5UKyGZlm9GFx5O0q/lDpQkTmYObUjqAZIu8VbRhideloFaJbwykjuNHGibIDhccd0MC OHfj9fpUV6EWBPJArvoSixPPoYnvfxAQfu0iQpHjtVsRBTzgDP8kNKgcn8ioasrCrHns +47J7Qe/LH0MCbJwl9RaHuqzOVunbHdm32FlFk1HoSDr0/oYSOp6w2tNqKpRzURx7Dw4 La7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JhKkKATF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 200si15902781pfy.101.2019.07.24.23.02.37; Wed, 24 Jul 2019 23:02:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JhKkKATF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391385AbfGYFqL (ORCPT + 99 others); Thu, 25 Jul 2019 01:46:11 -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