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.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 4015BC432C0 for ; Sat, 30 Nov 2019 07:27:50 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0A9832075C; Sat, 30 Nov 2019 07:27:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="UIPAaqSV"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="i4Z0Qn7b" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0A9832075C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1iaxAS-0005Re-Un; Sat, 30 Nov 2019 07:27:48 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1iaxAP-0005RS-9O for linux-f2fs-devel@lists.sourceforge.net; Sat, 30 Nov 2019 07:27:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:CC:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=+I+QoANEQOGPuT0wmkP3fOlpNljp5Q1rz19/BqUttYQ=; b=UIPAaqSV9Q5bcJ7lGMtEqhYVA4 s4d6+DRaIt3dP1q0IumG5g15PceZeAZxyvu/8cSvniVAGTi6dtzz5ttHNQl8Ht0Iq0I3CdNCfI7gN W/caqfVn3Xq+n8wi1h6c/MR/5h133s7Xnpux34WDbjXWmDrjBVgkwX8BkNlhuaC+1izg=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:MIME-Version:Date: Message-ID:From:References:CC:To:Subject:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=+I+QoANEQOGPuT0wmkP3fOlpNljp5Q1rz19/BqUttYQ=; b=i4Z0Qn7bihj3AaOP9+YQymvkQ+ UzC9NFuVhmUxxVeYLJ2GPipxaGWQDMuJfRkJtyUQrboQ/Ov0uFte+nqGi8qCVLZt9uLeK8NXS4mQJ wv3vIxTYLbIhT3luS5N9X4o4IBG2DvQBRPX3oSiN5sjAaE5XzX31za5sd8pRejw6detA=; Received: from szxga06-in.huawei.com ([45.249.212.32] helo=huawei.com) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1iaxAN-000Lwd-Q5 for linux-f2fs-devel@lists.sourceforge.net; Sat, 30 Nov 2019 07:27:45 +0000 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 83080E6B1FE2ADD81028; Sat, 30 Nov 2019 15:27:32 +0800 (CST) Received: from [10.134.22.195] (10.134.22.195) by smtp.huawei.com (10.3.19.205) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sat, 30 Nov 2019 15:27:29 +0800 To: Ritesh Harjani , Damien Le Moal , "linux-f2fs-devel@lists.sourceforge.net" , "linux-kernel@vger.kernel.org" , Jaegeuk Kim References: <20191126075719.1046485-1-damien.lemoal@wdc.com> <20191126083443.F1FD5A405B@b06wcsmtp001.portsmouth.uk.ibm.com> <20191128102033.6085952057@d06av21.portsmouth.uk.ibm.com> From: Chao Yu Message-ID: Date: Sat, 30 Nov 2019 15:27:29 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20191128102033.6085952057@d06av21.portsmouth.uk.ibm.com> Content-Language: en-US X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected X-Headers-End: 1iaxAN-000Lwd-Q5 Subject: Re: [f2fs-dev] [PATCH] f2fs: Fix direct IO handling X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Javier Gonzalez Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On 2019/11/28 18:20, Ritesh Harjani wrote: > > > On 11/28/19 7:40 AM, Damien Le Moal wrote: >> On 2019/11/26 17:34, Ritesh Harjani wrote: >>> Hello Damien, >>> >>> IIUC, you are trying to fix a stale data read by DIO read for the case >>> you explained in your patch w.r.t. DIO-write forced to write as buffIO. >>> >>> Coincidentally I was just looking at the same code path just now. >>> So I do have a query to you/f2fs group. Below could be silly one, as I >>> don't understand F2FS in great detail. >>> >>> How is the stale data by DIO read, is protected against a mmap >>> writes via f2fs_vm_page_mkwrite? >>> >>> f2fs_vm_page_mkwrite() f2fs_direct_IO (read) >>> filemap_write_and_wait_range() >>> -> f2fs_get_blocks() >>> -> submit_bio() >>> >>> -> set_page_dirty() >>> >>> Is above race possible with current f2fs code? >>> i.e. f2fs_direct_IO could read the stale data from the blocks >>> which were allocated due to mmap fault? >> >> The faulted page is locked until the fault is fully processed so direct >> IO has to wait for that to complete first. > > How about below parallelism? > > f2fs_vm_page_mkwrite() f2fs_direct_IO (read) > filemap_write_and_wait_range() > -> down_read(->i_mmap_sem); > -> lock_page() > -> f2fs_get_blocks() > -> submit_bio() > > -> set_page_dirty() > > Can above DIO read not expose the stale data from block which was > allocated in f2fs_vm_page_mkwrite path? The race can happen, however I doubt the race condition is more complicated as I described in previous reply of mine, could you check that? Thanks, > > >> >>> >>> Am I missing something here? >>> >>> -ritesh >>> >>> On 11/26/19 1:27 PM, Damien Le Moal wrote: >>>> f2fs_preallocate_blocks() identifies direct IOs using the IOCB_DIRECT >>>> flag for a kiocb structure. However, the file system direct IO handler >>>> function f2fs_direct_IO() may have decided that a direct IO has to be >>>> exececuted as a buffered IO using the function f2fs_force_buffered_io(). >>>> This is the case for instance for volumes including zoned block device >>>> and for unaligned write IOs with LFS mode enabled. >>>> >>>> These 2 different methods of identifying direct IOs can result in >>>> inconsistencies generating stale data access for direct reads after a >>>> direct IO write that is treated as a buffered write. Fix this >>>> inconsistency by combining the IOCB_DIRECT flag test with the result >>>> of f2fs_force_buffered_io(). >>>> >>>> Reported-by: Javier Gonzalez >>>> Signed-off-by: Damien Le Moal >>>> --- >>>> fs/f2fs/data.c | 4 +++- >>>> 1 file changed, 3 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c >>>> index 5755e897a5f0..8ac2d3b70022 100644 >>>> --- a/fs/f2fs/data.c >>>> +++ b/fs/f2fs/data.c >>>> @@ -1073,6 +1073,8 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from) >>>> int flag; >>>> int err = 0; >>>> bool direct_io = iocb->ki_flags & IOCB_DIRECT; >>>> + bool do_direct_io = direct_io && >>>> + !f2fs_force_buffered_io(inode, iocb, from); >>>> >>>> /* convert inline data for Direct I/O*/ >>>> if (direct_io) { >>>> @@ -1081,7 +1083,7 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from) >>>> return err; >>>> } >>>> >>>> - if (direct_io && allow_outplace_dio(inode, iocb, from)) >>>> + if (do_direct_io && allow_outplace_dio(inode, iocb, from)) >>>> return 0; >>>> >>>> if (is_inode_flag_set(inode, FI_NO_PREALLOC)) >>>> >>> >>> >> >> > > . > _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel