Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5217712rwb; Sun, 4 Dec 2022 17:01:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf4gUeDikBjQeX+jaygTehf965IwgJy5WVC/cR2KFu+GcmyEf/UXhuDiPPbWWGDE6tJLyT4d X-Received: by 2002:a17:906:8296:b0:7ba:29a1:543c with SMTP id h22-20020a170906829600b007ba29a1543cmr18690723ejx.297.1670202068240; Sun, 04 Dec 2022 17:01:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670202068; cv=none; d=google.com; s=arc-20160816; b=XgjSsBdc6UTlUShZsas4JHbgMWGBAES2Mtmk4EJPBX5Q5YoXMj3c66zx+rTRX21Zil 14k5wI8ynBSjIqQcx7FBJSCmKmA9dexTtkTffoKWKgSA1+3yfsC1h3XZKt2fVCSWePww qudRnT/nh79cE/9TIhC2cTna8sMml298N3KR3+n72BV3IIeeyvbxRiY7bMEVdpqQeeLn m4082/08ThDVlY8wlsGRhy+qMu3n0Wh7A3c2xKpDhFOgY/O51/ycbvuRlyZl85jpIUgZ J9XLZ7egBqlpaQh8w1+zJ5b5utzZk4whH9W8WZUnmunpJv3CJqo4PsOesKtOhpGMTOPu tACg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=VtvsCQ8fHRhk6x8VToDSbomE5ZMa9LavMZLQcaqpC9Y=; b=XVhiOouOF7pAKavwJqKPSMN84oZMAEJTDUScLqNZZRX9mNrvyCqNmi77s25rqbWU4W 0MNdfpaI9W44/CK5nsedzFDcOLIocmoD0QU7y+UYWNEhZ8znBSYgYD4D9TaADejgieqt EqTW5/dZXErFmiDv4EV8u0Dt42MH+xMzABCZji1LEKqmsvRYvfRkfJM20SyjhnLLCTqm LwzZRkjD6ceerliy1f0nFZXM0ZVpKJlCehz5JWDdmCdPLSFtZ2BXcdqSv4RWHU3ruwol 0+LM1Q2OfyLAfg95j9LdWKEWR9zB89wg5oq4Af5h+apIqUaHMbqjlNyppr/B8U9UpXvf riKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=bZ8SjeMi; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id be8-20020a1709070a4800b0077951929340si10775356ejc.271.2022.12.04.17.00.47; Sun, 04 Dec 2022 17:01:08 -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=@google.com header.s=20210112 header.b=bZ8SjeMi; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230320AbiLEApv (ORCPT + 83 others); Sun, 4 Dec 2022 19:45:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230444AbiLEApt (ORCPT ); Sun, 4 Dec 2022 19:45:49 -0500 Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B7BC11169 for ; Sun, 4 Dec 2022 16:45:48 -0800 (PST) Received: by mail-oi1-x234.google.com with SMTP id t62so11330567oib.12 for ; Sun, 04 Dec 2022 16:45:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=VtvsCQ8fHRhk6x8VToDSbomE5ZMa9LavMZLQcaqpC9Y=; b=bZ8SjeMi3/UczyDxZXS7zVDxJajNbrzIoW0OlW8hH6g6BQw0jcAMSTmLGSEHhHDiCS /4rq6dAIDr8K8g8vcV6Y6IuidDyFDrjbhbEh9b6l7zdCHlgjoSgwACQDLQL3/raCnx4i ttFJTLiEFLut+8z4PZlHT0N30YZx1QgZkLMg64vEe2ryC9m9byJbIQIOWvRuuGITzDfN RKdmZTkMVM48o5P/Zr1knzzNTD91AcgmrRXsTxzRsK+/MtnUn8UcwN3UvFRDTKU11VOw hZCzwjjr3k8ISOn9gGwoggI+Wo5yGvvGlPe+xSRUMpEOZEJAaa/S2SXzTH6DdcY79G1x 035g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VtvsCQ8fHRhk6x8VToDSbomE5ZMa9LavMZLQcaqpC9Y=; b=JLQZa5rOuJWib5x2s0xr8Tebpti0789DAh5FNMi+SXvJdJFAmRLlTgcQUVN4zHU6AD xITLkWggeKBqW1XQNSVHQ4aDuKpIT3BJVAIYJOrbJ4IYOFT+0buagHWq0jztdA+4FnSx a6MQn0sO0KByW1gJVll5WrSkp9reVQlVWJAS2+YwZhGp8zua2d66jAIuY18jxTGyjM1o 44zxeth5gzo+DJlI4/STHRKF71jEW/WhY4zd68mSPjiQg2ATDWuFfrR5Q+g2AgHQeqmp 6/IhDUYVBzq4e+ADyfKMBk3snGzR90gc9hFTonn734b6HsAnLS+YcjN4dYi50GsOHcpY 9Adg== X-Gm-Message-State: ANoB5pmkLWzvS788npgKXz805hIRYa8bcRx9qTjA4y4Rp8QevRyv/SxR lRm6pZ68btrK+KLqQDkTLlbUWg== X-Received: by 2002:a05:6808:149:b0:35b:b8d6:32c5 with SMTP id h9-20020a056808014900b0035bb8d632c5mr15921488oie.226.1670201147592; Sun, 04 Dec 2022 16:45:47 -0800 (PST) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id e9-20020a4ae0c9000000b004a05e943f9esm1141017oot.21.2022.12.04.16.45.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Dec 2022 16:45:47 -0800 (PST) Date: Sun, 4 Dec 2022 16:45:35 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Rui Wang cc: Andrew Morton , Matthew Wilcox , Guoqi Chen , Huacai Chen , Rui Wang , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [RFC PATCH] mm/shmem: Fix undo range for failed fallocate In-Reply-To: <9984f58e-826-74c6-1cd4-65366cc01549@google.com> Message-ID: <5889e4e3-e054-7654-1436-8d2bcbefe3c6@google.com> References: <20221101032248.819360-1-kernel@hev.cc> <9984f58e-826-74c6-1cd4-65366cc01549@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Tue, 22 Nov 2022, Hugh Dickins wrote: > On Thu, 3 Nov 2022, hev wrote: > > 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") > > Like Matthew, I was sceptical at first. > > But I currently think that you have discovered something important, and > that your patch is the correct fix to it; but I'm still rather confused, > and want to do some more thinking and testing: this mail is mainly to > signal to Matthew that I'm on it, so he doesn't have to rush to look > at it when he's back. > > I was able to reproduce it with the test case, once I multiplied both > of the usleep intervals by 10 - before that, it was too difficult for > it to complete a fallocate: guess the timing is different on my x86 box. Thanks, I needed that breathing space to get back to thinking it through. My main concern was, how did Matthew and I come to miss this unfalloc issue when the folio commit went in? Speaking for myself (but quite likely for Matthew too), it's because there was never a need for special unfalloc treatment in the partial page handling there before, so we didn't even think of adding any when that got updated. But when the partial page handling got turned into partial folio handling, it came to do a lot more than before: it's tricky stuff, and Matthew intentionally moved all the difficulty there into the partial folio block; whereas before it had been just as tricky, but hidden away in the shmem_punch_compound() call from inside the loop which follows. And was subject there to the unfalloc exception. So that sort of satisfied me, how we came to overlook it. Your patch worked for me, and until yesterday I was intending to send it in as is. But then realized that, although it's a peculiar exception to the standard processing there, unfalloc actually has a much simpler job to do: just remove any !uptodate folios from the range. It has no need whatsoever for the zeroing and splitting involved in truncate_inode_partial_folio(), and I really wanted to avoid having to think through all that again - easier just to skip it all. So the patch I'm about to send to Andrew is not quite yours: but many thanks to you and to Guoqi Chen for revealing this issue. Hugh