Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5585990imm; Tue, 12 Jun 2018 10:01:23 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJLNNov2SnGeG4EVqlxtW17Wy7IUw5BZozr/gk6XQbJi8TygDK3mGeTsfBw64utrPt9Kk2c X-Received: by 2002:aa7:8254:: with SMTP id e20-v6mr1256334pfn.140.1528822882981; Tue, 12 Jun 2018 10:01:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528822882; cv=none; d=google.com; s=arc-20160816; b=nExemoe8SoKJtaZftYX2tNYxb/DCF/4EEnqPRhqEyY9K5IVfvbIZACo+2Ltkvf7EPb 5qMVcWkwCEEaby1ZyiOWQ77JJ+GXcnrR78JLIqdvlJAXKpBdKfczO9htDAVcVzzOl+EY dY6notyQaYsFcmSSzrDklS962C6Ty/GPmMKUhN1qs4QXyZpbpqjb/BxtUqdoTjHvn2Bc LzLoQ9kl24GXXfFrvynscJ/g8YITYn432ht6rvEe2W5Kkd570FR6kWjJsP44rFyTBShk 4Trthoku4/WQ+BP17TiHJjH20+Z8UipYVMQOadzm7LAUF3LKOu2gtPQNOWpYh2FalWJ2 pscA== 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:dkim-signature :arc-authentication-results; bh=7Lr7xgM9NgGnA3goFq2GPKnDsw/hikf2yqjmb2PZAXw=; b=fECQyQhDA3Xsz1lF/tlZgbJSUM6RLewGLdOjyKywHhwlyPtSHXh/LjPkQlHwNta/WE RTu0kRir7NZk+Xu22uwbtomw2OU0eoDMT81mbsaesv8GWtsRPK+sBAkQt45wW75JaHK7 OHSij07JL/qDm4W6XggVaYADGKYeq0LKzPW1RIvOr/iSIvKfnR+mumwUrlM7/nd0+vBS oQa7oIMSNVLLoQauZ8Tw5kLwOCMeMd74qgL07hEJLSOnbzBXsHaH8qb3raHfljWGoFLh vFb2Z78vZDu9K7g3f3tackFJHkal9trtt6cHavFGpCJo86OHwiAi7MS/qUcq13/p7+JY H5cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="d/8kAsxJ"; 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 j17-v6si493169pfi.110.2018.06.12.10.01.08; Tue, 12 Jun 2018 10:01:22 -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="d/8kAsxJ"; 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 S935151AbeFLQxe (ORCPT + 99 others); Tue, 12 Jun 2018 12:53:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:52710 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935130AbeFLQx3 (ORCPT ); Tue, 12 Jun 2018 12:53:29 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 7DFB7208B8; Tue, 12 Jun 2018 16:53:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1528822409; bh=wK6TUtYychSxKvAtG5mJbNuofSYrNbkaxbGVU5D48bE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d/8kAsxJucZVMjagDFd4knn7HqidCo5mkz4KRZTOqQzc3Rza10nviCaFy3yGtzB2X BUkXJrHxaCmnZKUeMurJPl30WVwwU15SoXwNcOCf8z4wdD5Ek6Odm+agnmt4gi3gn6 qGtfS4EieDltz59nI3XJt79km2yt7YdxkvZgqehc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Josef Bacik , Amir Goldstein , "Darrick J. Wong" Subject: [PATCH 4.4 06/24] xfs: fix incorrect log_flushed on fsync Date: Tue, 12 Jun 2018 18:51:50 +0200 Message-Id: <20180612164816.861511958@linuxfoundation.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180612164816.587001852@linuxfoundation.org> References: <20180612164816.587001852@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.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Amir Goldstein commit 47c7d0b19502583120c3f396c7559e7a77288a68 upstream. When calling into _xfs_log_force{,_lsn}() with a pointer to log_flushed variable, log_flushed will be set to 1 if: 1. xlog_sync() is called to flush the active log buffer AND/OR 2. xlog_wait() is called to wait on a syncing log buffers xfs_file_fsync() checks the value of log_flushed after _xfs_log_force_lsn() call to optimize away an explicit PREFLUSH request to the data block device after writing out all the file's pages to disk. This optimization is incorrect in the following sequence of events: Task A Task B ------------------------------------------------------- xfs_file_fsync() _xfs_log_force_lsn() xlog_sync() [submit PREFLUSH] xfs_file_fsync() file_write_and_wait_range() [submit WRITE X] [endio WRITE X] _xfs_log_force_lsn() xlog_wait() [endio PREFLUSH] The write X is not guarantied to be on persistent storage when PREFLUSH request in completed, because write A was submitted after the PREFLUSH request, but xfs_file_fsync() of task A will be notified of log_flushed=1 and will skip explicit flush. If the system crashes after fsync of task A, write X may not be present on disk after reboot. This bug was discovered and demonstrated using Josef Bacik's dm-log-writes target, which can be used to record block io operations and then replay a subset of these operations onto the target device. The test goes something like this: - Use fsx to execute ops of a file and record ops on log device - Every now and then fsync the file, store md5 of file and mark the location in the log - Then replay log onto device for each mark, mount fs and compare md5 of file to stored value Cc: Christoph Hellwig Cc: Josef Bacik Cc: Signed-off-by: Amir Goldstein Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Greg Kroah-Hartman --- fs/xfs/xfs_log.c | 7 ------- 1 file changed, 7 deletions(-) --- a/fs/xfs/xfs_log.c +++ b/fs/xfs/xfs_log.c @@ -3323,8 +3323,6 @@ maybe_sleep: */ if (iclog->ic_state & XLOG_STATE_IOERROR) return -EIO; - if (log_flushed) - *log_flushed = 1; } else { no_sleep: @@ -3432,8 +3430,6 @@ try_again: xlog_wait(&iclog->ic_prev->ic_write_wait, &log->l_icloglock); - if (log_flushed) - *log_flushed = 1; already_slept = 1; goto try_again; } @@ -3467,9 +3463,6 @@ try_again: */ if (iclog->ic_state & XLOG_STATE_IOERROR) return -EIO; - - if (log_flushed) - *log_flushed = 1; } else { /* just return */ spin_unlock(&log->l_icloglock); }