Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1789531imu; Thu, 10 Jan 2019 03:07:26 -0800 (PST) X-Google-Smtp-Source: ALg8bN7AU9BMvatlAwaB1MO5/kEDBsHjKDcCT9Gdn9Es3aMLqh2UgQ27YLaQatbtotW4wO8WsIeh X-Received: by 2002:a62:184e:: with SMTP id 75mr9592778pfy.28.1547118446150; Thu, 10 Jan 2019 03:07:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547118446; cv=none; d=google.com; s=arc-20160816; b=FZY6z/XzA+XqBzqlYuzXo8zvLCCw1KZIIn44yfkgzUDRV9qjLQu5CIvO5Ks6KkfxYc 4gDLf5IxIrTzpSboxXUwu264vTUs6IAzdDQ3zgw80W+Aa/SCUE+n77wuIf27NpTHAm+g OuRMvHXscrIblD2jS6r09VJ22DYdjK+yjr1mGmO5uWkkYrUPfnoPEd4qeHJMvVMJHqQe B2ZRSOq3sBQk4KUXMvmpomqWXHoNnllyLL7fdEGRCp174Nsi31dagb91wBwZ/6TbjmHS M+4qce6witASRdxf9kaBQ91uI+E3IGqDSVUakcxVUPRPW1uq19YutfNSJ28dC75Byqd0 dlVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=u2ptSlrtz+EtZnajfVAeZ6a3wfSnJ0cwDBTctzETH/w=; b=TUNbvUVDm8UC4QyelYpm6jW38ez4cirgc8smEL95Zt2D12mIfSCLZ6KaIiU5svdSQM ZJy0FcMG7r84JjzGKPuv8yuHXbTKT2nJuvQyg2ZYcOxyU8RnrLutwpg7JG+MHRA1yBC2 UfHEhddXcfeO+K6JpEEAImL2+X9dalJtTbX9lJf4CPWFQ+2RtyvMTu+cvXBA/6MVok4R Soz3luHFnh1K/VR+4vO+Cm4sScbBpZ/lA+Pgn4hLMRpzTwVG0ecsH+nJ6nl1SfUxJlPS 3NiPdk9oAIPdYkaZx1yDyBF3MzvKZxtr86hX7ToDfbovZCpI77TXQQldc6yikMNPF1zV zbYg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l24si34482417pgj.171.2019.01.10.03.07.08; Thu, 10 Jan 2019 03:07:26 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728270AbfAJLDU (ORCPT + 99 others); Thu, 10 Jan 2019 06:03:20 -0500 Received: from relay.sw.ru ([185.231.240.75]:58334 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727617AbfAJLDT (ORCPT ); Thu, 10 Jan 2019 06:03:19 -0500 Received: from [172.16.25.169] by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1ghY7J-0003cl-II; Thu, 10 Jan 2019 14:03:17 +0300 Subject: Re: [PATCH 1/2] fuse: Fix race in fuse_writepage_in_flight() To: Miklos Szeredi Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org References: <154322517208.18737.3297786654135648324.stgit@localhost.localdomain> <00b1782a-5c5c-5bc8-7ea9-4f8450679fa1@virtuozzo.com> From: Kirill Tkhai Message-ID: Date: Thu, 10 Jan 2019 14:03:17 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10.01.2019 14:00, Miklos Szeredi wrote: > On Thu, Jan 10, 2019 at 11:48 AM Kirill Tkhai wrote: >> >> Hi, Miklos, >> >> any comments about this? > > Is there a reproducer? ISTR that fsx-linux with mmaps enabled was > good for stressing the writeback_cache code. There is no a reproducer, since I found that by eyes during preparation of another patchset. >> >> On 26.11.2018 12:46, Kirill Tkhai wrote: >>> Checking for FR_PENDING in fuse_writepage_in_flight() is racy. >>> It does not guarantee the first request in misc.write.next list >>> is not in userspace, since there we take fc->lock, while >>> fuse_dev_do_read() takes fiq->waitq.lock: >>> >>> fuse_dev_read() fuse_writepage_in_flight() >>> test_bit(FR_PENDING) >>> clear_bit(FR_PENDING) >>> handle old_req->pages[0] in userspace >>> copy_highpage(old_req->pages[0], page) >>> ^^^^^ >>> userspace never sees this pages >>> >>> The only reliable way to determ, whether we are able to replace >>> old_req's page, is to completely skip the first request in the list. >>> This patch makes the function to do that. >>> >>> Signed-off-by: Kirill Tkhai >>> --- >>> fs/fuse/file.c | 4 +++- >>> 1 file changed, 3 insertions(+), 1 deletion(-) >>> >>> diff --git a/fs/fuse/file.c b/fs/fuse/file.c >>> index b52f9baaa3e7..c6650c68b31a 100644 >>> --- a/fs/fuse/file.c >>> +++ b/fs/fuse/file.c >>> @@ -1740,6 +1740,7 @@ static bool fuse_writepage_in_flight(struct fuse_req *new_req, >>> { >>> struct fuse_conn *fc = get_fuse_conn(new_req->inode); >>> struct fuse_inode *fi = get_fuse_inode(new_req->inode); >>> + struct fuse_req *first_req; >>> struct fuse_req *tmp; >>> struct fuse_req *old_req; >>> bool found = false; >>> @@ -1764,6 +1765,7 @@ static bool fuse_writepage_in_flight(struct fuse_req *new_req, >>> } >>> >>> new_req->num_pages = 1; >>> + first_req = old_req; >>> for (tmp = old_req; tmp != NULL; tmp = tmp->misc.write.next) { >>> BUG_ON(tmp->inode != new_req->inode); >>> curr_index = tmp->misc.write.in.offset >> PAGE_SHIFT; >>> @@ -1773,7 +1775,7 @@ static bool fuse_writepage_in_flight(struct fuse_req *new_req, >>> } >>> } >>> >>> - if (old_req->num_pages == 1 && test_bit(FR_PENDING, &old_req->flags)) { >>> + if (old_req->num_pages == 1 && old_req != first_req) { >>> struct backing_dev_info *bdi = inode_to_bdi(page->mapping->host); >>> >>> copy_highpage(old_req->pages[0], page); >>>