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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4260C433FE for ; Wed, 23 Nov 2022 04:02:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 108486B0071; Tue, 22 Nov 2022 23:02:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B7FC6B0073; Tue, 22 Nov 2022 23:02:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EEA0A8E0001; Tue, 22 Nov 2022 23:02:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DDDEB6B0071 for ; Tue, 22 Nov 2022 23:02:49 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id AE912AAEE2 for ; Wed, 23 Nov 2022 04:02:49 +0000 (UTC) X-FDA: 80163360858.16.24C57BF Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.171]) by imf16.hostedemail.com (Postfix) with ESMTP id 350E618000A for ; Wed, 23 Nov 2022 04:02:49 +0000 (UTC) Received: by mail-oi1-f171.google.com with SMTP id r76so17877706oie.13 for ; Tue, 22 Nov 2022 20:02: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=ySZEGeQLDNriKrOLo1dJs5uwir+Qbj3CsrcAGxN4mpk=; b=i/IUD3jrtZYypvMXyiJEb9qfZ9qf+AmDI3mig3rHxadg69IrmimZ2Cy8uR0ZsDpqs5 DVomw1EtmQWdTyjzN5anDglKnK7nY+R0QlHt5Yn0qZOByl+tY6/Xs8SP+tS6zN88565I Kh2KIuOvo2uCmO0t1UHwRJQkiDL/Tlc2jXNVOrbzAuI/49eO1zsLQmDLMYFbw09K86Hu fMtSuwpwLPb36PeQpdmeHTf1tIhAoqsvzNQU8w6G242DJVFs9xJSCi1idm6oHp41ows5 iKu/WoJsoNVYQFbV1BDQnmByv1kmTZxB0zwj8YAEnb+lJT8tY2nEpVv/lZBLKHn+Qxcz vFqA== 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=ySZEGeQLDNriKrOLo1dJs5uwir+Qbj3CsrcAGxN4mpk=; b=T2sRa++mD3/bxBnmfANcsilccB0sK+EimmQg76Yvzzj80gVHbygbpmBtbSuubUC2U1 qT76QbZ6rUPPaGiOSE8341vOL6e6M+ru0aW6B+vxWvR0e4x2eIE5wBsYNgU4Xt6RQOSg PKVaSYviJXFF5ZgkVqg2HVukIKLLkf5A9XigXugiJtE8yU5e4b9IxU8JIO3F7zjUCFAy TkDXYm7ntOEaiDwvABBeHdTPpBdjLlTLh5dfghkPx6kSBX1gjcz2GQgoMuGiyAaTtSCn VOwAQmjTwQ6fCx3R/HjH6C1+vyft9tHkuUFgAKj+I7UIEy2fTNShcWIsU2GYt2jzuFMC 9/RA== X-Gm-Message-State: ANoB5pmY3IrYFvX3oDfOEDQlBviOiJzhJGU0kXOfb2d21EpoVZhNL06s /hjl5FbLWqclzuKRp66pB/TSgA== X-Google-Smtp-Source: AA0mqf5FyMHYhOSMNEGk1zhvDm63vD+AXaPam8LV9ALZA/uO6GJ8utMwCpD19U5CmmrkhOnDz4Wgsw== X-Received: by 2002:a54:4796:0:b0:355:7ae5:4fe with SMTP id o22-20020a544796000000b003557ae504femr6762744oic.54.1669176168322; Tue, 22 Nov 2022 20:02:48 -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 s7-20020aca4507000000b0035a81480ffcsm6119553oia.38.2022.11.22.20.02.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 20:02:47 -0800 (PST) Date: Tue, 22 Nov 2022 20:02:36 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: hev , Matthew Wilcox cc: Guoqi , Huacai Chen , Rui Wang , Hugh Dickins , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [RFC PATCH] mm/shmem: Fix undo range for failed fallocate In-Reply-To: Message-ID: <9984f58e-826-74c6-1cd4-65366cc01549@google.com> References: <20221101032248.819360-1-kernel@hev.cc> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669176169; a=rsa-sha256; cv=none; b=nvJ5EjH9VkjNNoxKM/tv94Ra43AmIugZCEG+QZIHdAEy7Sl05dlmcuw2ZmL9SQ1Lk1cWQB nTFO4zNB1DMXC6LTJHHZQDmydB7eDwzVqcLE2j3XmVm5Po7nfkt5TMFzX7dL6RLEeQNHCQ ECuqsu6w5wN7dHZ4duiGOa02h6T18N4= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="i/IUD3jr"; spf=pass (imf16.hostedemail.com: domain of hughd@google.com designates 209.85.167.171 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669176169; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ySZEGeQLDNriKrOLo1dJs5uwir+Qbj3CsrcAGxN4mpk=; b=Z8yGWgmHLJxHHzqplJc6kKW+Dz6+qtbBvSIt03lAF9BSmGZQQVyZx/DyjYJsBXQR8ka4Dk dhblnnlI2AOzPI56GoIrgrXVKQnJXckdAO3+KZsuLaaycE8zCzilm6+Kkkcx9/jmFX1Odj /wInj/OJX5zNYVqwp/OyYzgL38tC5hE= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 350E618000A Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="i/IUD3jr"; spf=pass (imf16.hostedemail.com: domain of hughd@google.com designates 209.85.167.171 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Stat-Signature: qez5pn6fbyhqggeu4p3sjgods9edcby3 X-HE-Tag: 1669176169-486061 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. Hugh