Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp950503ybl; Sat, 18 Jan 2020 15:10:36 -0800 (PST) X-Google-Smtp-Source: APXvYqxax7PyHU7E6/Nvi4WZra9psLtwO2cfXM2N08ScA4hdj7DVU+tB2n/pu4YU238MlJqiSb4L X-Received: by 2002:aca:f0b:: with SMTP id 11mr8721816oip.34.1579389036058; Sat, 18 Jan 2020 15:10:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579389036; cv=none; d=google.com; s=arc-20160816; b=gT6HgyM1bbpjukyofXuoeoqq81+xP5/vO990vWB2UYXNkMdkKTZA4LBPTQgnQhE1AN fFby8nLAHbapDQ74Rh9IzijzvzTRXNWzeULioHae9HPUX58a5YX7xlU8kfpuoCsI1CQG jP1PpOYVU5GOThL97U3toqvfHO/bnS5a3vS/eea0ux4KGytRLARl/W1+s2Req45eF2CA lL/TBP2g2/GJ2+Sib5meK7upl7O6AA7HZmDlHvav3W0YMEJeTsYCLg9iwZPNM6B0v4ZN QUcsj38GdFMf0nT4B8GNeFAUqUg4OW9Bzyxvzw8Vn2SufGqGVtNPmhmE8WGBdAgzfT7v fVHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=m5EpDMuociEO+dhOx0dLjYTpW5oUxRxlXa1xRujJ5N4=; b=X4EDE6WjrSgy3u+1Q7unHiB/cN5GtsnKAHvZT4vXvLhHICejcpqElhCNEErHyP55Lb NZWWq9o/4/8wMoOApVGrgD5zL0TrJ7uMh6f5d8Mv3JSenEDSR5N5EcwNR91DRcZAdDpK c1wjzt7jtwx4dsh+lLgr3vJiBmsyakMTDLOH36l7W5zmNUb5M9UaE+O11fHk3ANJP06O +ZCzfKxuC31PmhyosucSm64NduFlM9fFT8Dcyqd5TZV/C/Ytush5xc96MJw8xTh1l6Z2 TpEfhk6tajp7EMmCmeUrgXS3DXhTh9GkDXBoMv+m60JWBulThitthiCWQSuctIsZbuuP Hdew== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=rPdI1c6S; 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 r15si17269973ota.264.2020.01.18.15.10.23; Sat, 18 Jan 2020 15:10:36 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=rPdI1c6S; 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 S1728783AbgARXJH (ORCPT + 99 others); Sat, 18 Jan 2020 18:09:07 -0500 Received: from [198.137.202.133] ([198.137.202.133]:40440 "EHLO bombadil.infradead.org" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1727028AbgARXJF (ORCPT ); Sat, 18 Jan 2020 18:09:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding: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=m5EpDMuociEO+dhOx0dLjYTpW5oUxRxlXa1xRujJ5N4=; b=rPdI1c6SL+Uxr55wj8QlFXdD0 5VxOSFTTxYx1dTuBaLrJ1VWZFVk6MhTP4sR/r8SB+2V3sMYJmEaeQOMDEUYSnrUNlvBA2WNtz09wM BGIXPhlfnD+zNDCTAZW7L9g4kQaXIjAK4y1sS5vv2ejWVzsfSniTki8dEt3W7bYdaEvynRAa7gIeq i3X7q2KZFEKQWIrcP1U5LoYXLjdLk+e2xj62Cix+HwO7a+GxrzQKPuoFrWePUtXcmKirGFWDjkYgM NqofqK1uzM4tU57IwJDNuk0G4DTLhatMoyGpiveFj6I7QHiZCigsmk+TIiNSGECqhciwnycSNMPXv j8F5XtwMQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1isxCc-0002oc-MH; Sat, 18 Jan 2020 23:08:26 +0000 Date: Sat, 18 Jan 2020 15:08:26 -0800 From: Matthew Wilcox To: yu kuai Cc: hch@infradead.org, darrick.wong@oracle.com, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, houtao1@huawei.com, zhengbin13@huawei.com, yi.zhang@huawei.com Subject: Re: [RFC] iomap: fix race between readahead and direct write Message-ID: <20200118230826.GA5583@bombadil.infradead.org> References: <20200116063601.39201-1-yukuai3@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200116063601.39201-1-yukuai3@huawei.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 16, 2020 at 02:36:01PM +0800, yu kuai wrote: > I noticed that generic/418 test may fail with small probability. And with > futher investiation, it can be reproduced with: > > ./src/dio-invalidate-cache -wp -b 4096 -n 8 -i 1 -f filename > ./src/dio-invalidate-cache -wt -b 4096-n 8 -i 1 -f filename > > The failure is because direct write wrote none-zero but buffer read got > zero. > > In the process of buffer read, if the page do not exist, readahead will > be triggered. __do_page_cache_readahead() will allocate page first. Next, > if the file block is unwritten(or hole), iomap_begin() will set iomap->type > to IOMAP_UNWRITTEN(or IOMAP_HOLE). Then, iomap_readpages_actor() will add > page to page cache. Finally, iomap_readpage_actor() will zero the page. > > However, there is no lock or serialization between initializing iomap and > adding page to page cache against direct write. If direct write happen to > fininsh between them, the type of iomap should be IOMAP_MAPPED instead of > IOMAP_UNWRITTEN or IOMAP_HOLE. And the page will end up zeroed out in page > cache, while on-disk page hold the data of direct write. It's worth noting that my patch series from earlier this week to redesign the readahead API will fix this problem. Direct write will block on the locked pages in the page cache.