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.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham 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 C3889C33CB1 for ; Tue, 14 Jan 2020 09:12:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9F7C22075B for ; Tue, 14 Jan 2020 09:12:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725860AbgANJML (ORCPT ); Tue, 14 Jan 2020 04:12:11 -0500 Received: from mx2.suse.de ([195.135.220.15]:49034 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725820AbgANJML (ORCPT ); Tue, 14 Jan 2020 04:12:11 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 937A0ACD9; Tue, 14 Jan 2020 09:12:09 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 26FA71E0D0E; Tue, 14 Jan 2020 10:12:08 +0100 (CET) Date: Tue, 14 Jan 2020 10:12:08 +0100 From: Jan Kara To: Ritesh Harjani Cc: linux-ext4@vger.kernel.org, tytso@mit.edu, jack@suse.cz Subject: Re: [RFC 1/2] iomap: direct-io: Move inode_dio_begin before filemap_write_and_wait_range Message-ID: <20200114091208.GB6466@quack2.suse.cz> References: <27607a16327fe9664f32d09abe565af0d1ae56c9.1578907891.git.riteshh@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <27607a16327fe9664f32d09abe565af0d1ae56c9.1578907891.git.riteshh@linux.ibm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Mon 13-01-20 16:34:21, Ritesh Harjani wrote: > Some filesystems (e.g. ext4) need to know in it's writeback path, that > whether DIO is in progress or not. This info may be needed to avoid the > stale data exposure race with DIO reads. > > Signed-off-by: Ritesh Harjani > --- > fs/iomap/direct-io.c | 17 +++++++++++++---- > 1 file changed, 13 insertions(+), 4 deletions(-) > > diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c > index 23837926c0c5..d1c159bd3854 100644 > --- a/fs/iomap/direct-io.c > +++ b/fs/iomap/direct-io.c > @@ -468,9 +468,18 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, > flags |= IOMAP_NOWAIT; > } > > + /* > + * Call inode_dio_begin() before we write out and wait for writeback to > + * complete. This may be needed by some filesystems to prevent race > + * like stale data exposure by DIO reads. > + */ > + inode_dio_begin(inode); > + /* So that i_dio_count is incremented before below operation */ > + smp_mb__after_atomic(); I wonder if the barrier shouldn't go into inode_dio_begin() - as a sepatare patch. Because people just treat this as a lock-kind-of-thingy. E.g. btrfs or ceph use inode_dio_begin() in places which I'd consider prone to CPU reordering issues without this barrier... Otherwise the patch looks good to me. Honza -- Jan Kara SUSE Labs, CR