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 D366BC433FE for ; Sat, 19 Nov 2022 14:46:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 189276B0074; Sat, 19 Nov 2022 09:46:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1124C80007; Sat, 19 Nov 2022 09:46:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ECF396B0078; Sat, 19 Nov 2022 09:46:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id DA5EA6B0074 for ; Sat, 19 Nov 2022 09:46:04 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 98251A0AF7 for ; Sat, 19 Nov 2022 14:46:04 +0000 (UTC) X-FDA: 80150466648.22.8488F8A Received: from mail-il1-f172.google.com (mail-il1-f172.google.com [209.85.166.172]) by imf11.hostedemail.com (Postfix) with ESMTP id 4107940009 for ; Sat, 19 Nov 2022 14:46:04 +0000 (UTC) Received: by mail-il1-f172.google.com with SMTP id s17so2049449ilp.1 for ; Sat, 19 Nov 2022 06:46:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hev-cc.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=E6cRmx5xlvWxqI3Q21J9iOtYTxXg+LdFquwejNlafYk=; b=OLikv6lMFDLoykxdmEOYh+5Q9/UFy3P4xNjzwC1tRl9G7aTagGt/mrsXRNmPFGTJYo Jaevtq0C76mUxopYFtADVpfYgN+kAI1KngLvcaFUSeJwl99u3cNyOhb6cXj7GViSacUS pqC2jGVw2aVblCzrBlJiq9XFEzisLQkdwe142mbY7xv+TS+9pNLLYRHNJAAPWoCwV1j8 GGDA1sJbykKDy5jCwgBTDlUBTja7vrRmkHjYZbQIA+MVvxdqYqv4dqlcbUfIxSMZG02r ZJroV7CNHKHL5F4FSP8JTx4js8kIuKWEHdnTMvq0C1ifLfXszcJe1DAHBaPqTeSUz7a8 D0iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=E6cRmx5xlvWxqI3Q21J9iOtYTxXg+LdFquwejNlafYk=; b=KiBxjymifsoSHRcI4vLdsX/ovA8mu1Tg6QzP5H9QpWbNo2nW6Za7CkquOAy2rEUfBf 8q/3y71lQ/nDIdiDvBv4lnEX3hzYJTL/Oj/qZXPRdxHtKDn+GuK9aE45u79Bd6BgyTGM A+CwnoSsHr3F2H2Dw/iftPT3M9mWVdMjtdkGETFxzesxoLI9YfbXHeo2WnuanjYLZAqo Q/E2O1Z0OBVXBzrtRzd0hyMbspIoVI/Ecxty/3Qp7cAlrpmTyeWkJE+Zcjvu5fO95I1O aXnKK8Bd1CMEsLO9TZJScgp5+wk7CHuGB4ahYkBAtDnyOo/Aj/Nl2JxcjYvASDXsWnMV vIBQ== X-Gm-Message-State: ANoB5pkPSd212n1WbG5gkSdnOwrXdR7DbZvfl8YsT33nGeIJRGCd5cli TFExR/iXoR/hobkS5HJikVsgSxxjbwIqq4sAB2fcIA== X-Google-Smtp-Source: AA0mqf6OijOkswU4IRx2HHvq9+JmXMjNyCUavkLhkflH2sTsVhu3vvkU+yUNZiWMoGEggr5iG3wDjVr/r6RDpocxDr4= X-Received: by 2002:a92:c501:0:b0:302:9dc6:3939 with SMTP id r1-20020a92c501000000b003029dc63939mr4285784ilg.157.1668869163557; Sat, 19 Nov 2022 06:46:03 -0800 (PST) MIME-Version: 1.0 References: <20221101032248.819360-1-kernel@hev.cc> In-Reply-To: From: hev Date: Sat, 19 Nov 2022 22:45:52 +0800 Message-ID: Subject: Re: [RFC PATCH] mm/shmem: Fix undo range for failed fallocate To: Matthew Wilcox , Hugh Dickins Cc: Guoqi , Huacai Chen , linux-mm@kvack.org, Linux Kernel Mailing List , Rui Wang Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668869164; a=rsa-sha256; cv=none; b=kRmJRFbPSnHguR5WYAidluifaMqJcuoaB5O8xIyI4vkJomnQHRDt3Pn6LcnRHpBWHLHl0+ zcMZQwTfW+0GDeGK6RBgdMsxeBi2NN11V4mbumMcUb05/BJvNybrQw6ivIowaIJFJA+5gK CWSmt1H5WjGRmwH+pjl5/LfAgfJ3iHM= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=hev-cc.20210112.gappssmtp.com header.s=20210112 header.b=OLikv6lM; spf=pass (imf11.hostedemail.com: domain of r@hev.cc designates 209.85.166.172 as permitted sender) smtp.mailfrom=r@hev.cc; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668869164; 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=E6cRmx5xlvWxqI3Q21J9iOtYTxXg+LdFquwejNlafYk=; b=FVOayxWZUAha79bjJapjciVxkJWUptpc7rpqt9wBtgjQvoKewsSJ8mVUL6Mc3rYDJ9/ScA l+7YQy+H2uLJAfYolY5adfwcptmhO2wv32Ejt70DdhxO1ajHjm/Bu/cXJ3L7+jWLmeJEWr 24iSi9umoMhJ3f6flS2LVgUH1b5Ku7M= Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=hev-cc.20210112.gappssmtp.com header.s=20210112 header.b=OLikv6lM; spf=pass (imf11.hostedemail.com: domain of r@hev.cc designates 209.85.166.172 as permitted sender) smtp.mailfrom=r@hev.cc; dmarc=none X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 4107940009 X-Rspam-User: X-Stat-Signature: 8kdi61chi1k1fenxx3so6p9h9117oqwi X-HE-Tag: 1668869164-533131 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: Ping 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