Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2281959rwb; Sat, 19 Nov 2022 12:35:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf7TGfNXJqtgvtQCbTOBNUUcCVHxKAZVj6n/4b37bgLmjPBfL/+kX/YgbrFP3UIL10lZiYgJ X-Received: by 2002:a17:902:f68a:b0:186:f256:91cd with SMTP id l10-20020a170902f68a00b00186f25691cdmr5037353plg.152.1668890131261; Sat, 19 Nov 2022 12:35:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668890131; cv=none; d=google.com; s=arc-20160816; b=h/YR/QHiyohIuzZ9SlGYEvAPsgOGHgeb0da5WMUmWY8vyypcpNfEsSBNVUKIUCFOyv t0eErm3Gsng4Jj14IiNk2tE9Ufy4QA08JwUo7Kr2hbG+W+OGCDgpAzjUMjjbMl4PioUq UNKLRlsZTzFhjJidOABKKZGpK9ZzJheAs7HDY1NIeiJKyKhNOrc1E8UYVonnVthwZ6V4 xV3vBtOc7pjn7dQziSiVApIO1lnDMUN1SqlXsRc35XJpcgz31j/oeJDY3WfCm5g0Fnlz QHxaaR/RjtmWmLQp4+eGmHT3s0SvfZ+Fmic1WKCuZaJTOYPQ7XOBB3YH0pFI0yVCy3G9 Bqxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=T0PEwCj46l8kkuAlr919hhJp7yTxS0xQb6cN9Cx/y8Q=; b=cFq30P3mAT57vHlod3r2aU4MgN/o9g+2JCumWP02Zh9XKP0JdGzPVqK9q11tP/+p9j zrIU9dkvspKjRklbPNWF8RQrFf9H3ou7cafVxj7F+xi3LveR8jwlBxz1C5IyUpCrCdzo pf2BmCzrXrGWeyGGDRUEt9dEeY4/3u19oZBa3XkFF2l0X02sdcslmm4uIVHBQS/7ENi5 e24KfhqXRfNugHgIVWCfl5UgTJjEmGaYXnjQv6pugdpcl6ZMaGhPcXKsLwolfb343QpH juHn7lcLCJ2PDr/NjQBx/cItmggQ2FX6pvsWhNtbV0NQTwsClCrXQYy7tlqzxwt3LWvJ creQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=sl2rXH8k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 197-20020a6301ce000000b0043941e5532dsi7585996pgb.391.2022.11.19.12.35.19; Sat, 19 Nov 2022 12:35:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=sl2rXH8k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234686AbiKSUUp (ORCPT + 91 others); Sat, 19 Nov 2022 15:20:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230398AbiKSUUm (ORCPT ); Sat, 19 Nov 2022 15:20:42 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AF96178A6 for ; Sat, 19 Nov 2022 12:20:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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; bh=T0PEwCj46l8kkuAlr919hhJp7yTxS0xQb6cN9Cx/y8Q=; b=sl2rXH8kIZnL9wKiQp7DPMlcAM L7kNckDKmOoE1H6KAqu8TOnsaxkJdasnwxOqw7k3QThDsRvbG2ZsU0ppbJ+b1m7lXhhML2GQGvEW7 1mpWkAPLtX1cVL1XeeQQE57RVorfa2eR9kc3IcniZwC8/BmxNpRiAVNOa1y6gvVG/GrvKWUdp2Iax KuW43K0dBTs7LredAr2L0LJ8cHTUF94gTrV1DKz4nIr2BQSAUK3sbSCy1W+L6XXHYJ/srcYjlapo0 176dw34x996vRvVQIqko6uMzcWfvKZKCwBNNulzbjdc2ohdbnXHNyQP8xRVc5Yb7Am+4gmkG8Hn/e y2c2M7JA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1owUKA-003WVF-H8; Sat, 19 Nov 2022 20:20:26 +0000 Date: Sat, 19 Nov 2022 20:20:26 +0000 From: Matthew Wilcox To: hev Cc: Hugh Dickins , Guoqi , Huacai Chen , linux-mm@kvack.org, Linux Kernel Mailing List , Rui Wang Subject: Re: [RFC PATCH] mm/shmem: Fix undo range for failed fallocate Message-ID: References: <20221101032248.819360-1-kernel@hev.cc> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Nov 19, 2022 at 10:45:52PM +0800, hev wrote: > Ping I'll be back on Wednesday and will look then. > On Thu, Nov 3, 2022 at 3:52 PM hev wrote: > > > > Hi Matthew, > > > > On Wed, Nov 2, 2022 at 10:41 PM Matthew Wilcox wrote: > > > > > > On Tue, Nov 01, 2022 at 11:22:48AM +0800, Rui Wang wrote: > > > > This patch fixes data loss caused by the fallocate system > > > > call interrupted by a signal. > > > > > > > > Bug: https://lore.kernel.org/linux-mm/33b85d82.7764.1842e9ab207.Coremail.chenguoqic@163.com/ > > > > Fixes: b9a8a4195c7d ("truncate,shmem: Handle truncates that split large folios") > > > > > > How does that commit introduce this bug? > > > > In the test case[1], we created a file that contains non-zero data > > from offset 0 to A-1. and a process try to expand this file by > > fallocate(fd, 0, 0, B), B > A. > > Concurrently, another process try to interrupt this fallocate syscall > > by a signal. I think the expected results are: > > > > 1. The file is not expanded and file size is A, and the data from > > offset 0 to A-1 is not changed. > > 2. The file is expanded and the data from offset 0 to A-1 is not > > changed, and from A to B-1 contains zeros. > > > > Now, the unexpected result is that the file is not expanded and the > > data that from offset 0 to A-1 is changed by > > truncate_inode_partial_folio that called > > from shmem_undo_range with unfalloc = true. > > > > This issue is only reproduced when file on tmpfs, and begin from this > > commit: b9a8a4195c7d ("truncate,shmem: Handle truncates that split > > large folios") > > > > > > > > > Reported-by: Guoqi Chen > > > > Cc: Huacai Chen > > > > Signed-off-by: Rui Wang > > > > --- > > > > mm/shmem.c | 20 ++++++++++++-------- > > > > 1 file changed, 12 insertions(+), 8 deletions(-) > > > > > > > > diff --git a/mm/shmem.c b/mm/shmem.c > > > > index bc9b84602eec..8c8dce34eafc 100644 > > > > --- a/mm/shmem.c > > > > +++ b/mm/shmem.c > > > > @@ -948,11 +948,13 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, > > > > folio = shmem_get_partial_folio(inode, lstart >> PAGE_SHIFT); > > > > if (folio) { > > > > same_folio = lend < folio_pos(folio) + folio_size(folio); > > > > - folio_mark_dirty(folio); > > > > - if (!truncate_inode_partial_folio(folio, lstart, lend)) { > > > > - start = folio->index + folio_nr_pages(folio); > > > > - if (same_folio) > > > > - end = folio->index; > > > > + if (!unfalloc || !folio_test_uptodate(folio)) { > > > > + folio_mark_dirty(folio); > > > > + if (!truncate_inode_partial_folio(folio, lstart, lend)) { > > > > + start = folio->index + folio_nr_pages(folio); > > > > + if (same_folio) > > > > + end = folio->index; > > > > + } > > > > > > ... so what you're saying is that if we allocate a page, but zeroing > > > it is interrupted by a signal, we cannot now remove that page from > > > the cache? That seems wrong. > > > > > > Surely the right solution is to remove this page from the cache if we're > > > interrupted by a signal. > > > > So I think we should not truncate_inode_partial_folio for unfalloc = > > true. Isn't that right? > > > > [1] https://github.com/abner-chenc/abner/blob/master/fallocate.c > > > > Regards, > > Ray >