Received: by 10.223.185.116 with SMTP id b49csp1031262wrg; Wed, 21 Feb 2018 10:53:10 -0800 (PST) X-Google-Smtp-Source: AH8x225A0fHtAzu5SBWKx/XP6c03CwElbHPntYKxlHTKP+tNHfdFol+AClimTCWL/01db3Y4TtT/ X-Received: by 2002:a17:902:26:: with SMTP id 35-v6mr4047326pla.42.1519239190199; Wed, 21 Feb 2018 10:53:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519239190; cv=none; d=google.com; s=arc-20160816; b=qkYF2ZMwGia/+5IA+ZwE08njA1kWvFt/xeBg1per5PeZOEna0mmbEYhw8FyO+C5Ql1 9ugLA4uM/a65tUwMYhApzC4dZPUMdXLSoL/o0IT1Oi8it7Ibf0rEdzB8nVKfRrPU5cZB nf1V2+1B2uf/5bNJjQ0vPfUc1HEOm46YNKST9wPikGS6X8zVv3Llbf27toVSFWoiYAAw i4rmRpHCp1CJLK7dr775syR9L+ZS77j9c/E86t3pKGIknYZTghfg3e6FgpRuJojzUmcA tVACwWOG0GQdXlWFRS284mNIit9BvpAixOpkV11IyCoWuzwlYPsPS7cmISyHf70k5KCr t7FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=kvmYAcmK2L5clYZtmFcLbk3Za8E2LMNDoYZI3LNHseo=; b=XsBJ2KXBmdopZ4spnL+Dr/G7vccmzMzhUijQNMIn70BUr2sDdQcMkYnUOSf7iizzqN 0q61SaxjifNtUD4Kjv2aR1wpqRF0KbBYUuSn4bKbJjnCRTuRTTqdCwhAzCCwpLsvb1Za Z0OlixfKQAKryZNmGQREfcKp5f6XMwNFtXyyULDdzBeLm5EJM0aZNv6Ea+BlpcqxcPOs NFx8UDs+IxFXcOyDKzZefKwOmoS3CwRaqhGqhR1YRNCqKTEhgsq5Z3c7sjM0BQyKw7os qLaj4Pdrln9cIPhLd0xSjEBZk00N1JAocseQsOY9ywUoAuEwxVIeYKrua7FJ1D+UdBGq Kygw== ARC-Authentication-Results: i=1; mx.google.com; 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 d3-v6si1089807pll.517.2018.02.21.10.52.56; Wed, 21 Feb 2018 10:53:10 -0800 (PST) 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; 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 S936086AbeBUOh3 (ORCPT + 99 others); Wed, 21 Feb 2018 09:37:29 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34296 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934187AbeBUMzB (ORCPT ); Wed, 21 Feb 2018 07:55:01 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 300521110; Wed, 21 Feb 2018 12:55:01 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Harshad Shirwadkar , Theodore Tso Subject: [PATCH 4.9 07/77] ext4: fix a race in the ext4 shutdown path Date: Wed, 21 Feb 2018 13:48:16 +0100 Message-Id: <20180221124432.484661745@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124432.172390020@linuxfoundation.org> References: <20180221124432.172390020@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Harshad Shirwadkar commit abbc3f9395c76d554a9ed27d4b1ebfb5d9b0e4ca upstream. This patch fixes a race between the shutdown path and bio completion handling. In the ext4 direct io path with async io, after submitting a bio to the block layer, if journal starting fails, ext4_direct_IO_write() would bail out pretending that the IO failed. The caller would have had no way of knowing whether or not the IO was successfully submitted. So instead, we return -EIOCBQUEUED in this case. Now, the caller knows that the IO was submitted. The bio completion handler takes care of the error. Tested: Ran the shutdown xfstest test 461 in loop for over 2 hours across 4 machines resulting in over 400 runs. Verified that the race didn't occur. Usually the race was seen in about 20-30 iterations. Signed-off-by: Harshad Shirwadkar Signed-off-by: Theodore Ts'o Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/inode.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3526,10 +3526,18 @@ static ssize_t ext4_direct_IO_write(stru /* Credits for sb + inode write */ handle = ext4_journal_start(inode, EXT4_HT_INODE, 2); if (IS_ERR(handle)) { - /* This is really bad luck. We've written the data - * but cannot extend i_size. Bail out and pretend - * the write failed... */ - ret = PTR_ERR(handle); + /* + * We wrote the data but cannot extend + * i_size. Bail out. In async io case, we do + * not return error here because we have + * already submmitted the corresponding + * bio. Returning error here makes the caller + * think that this IO is done and failed + * resulting in race with bio's completion + * handler. + */ + if (!ret) + ret = PTR_ERR(handle); if (inode->i_nlink) ext4_orphan_del(NULL, inode);