Message ID | a5dac112-cf4b-7af-a33-f386e347fd38@google.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 A5E23C3A5A7 for <linux-mm@archiver.kernel.org>; Mon, 5 Dec 2022 00:51:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA3348E0002; Sun, 4 Dec 2022 19:51:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D535E8E0001; Sun, 4 Dec 2022 19:51:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF3D48E0002; Sun, 4 Dec 2022 19:51:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B10FD8E0001 for <linux-mm@kvack.org>; Sun, 4 Dec 2022 19:51:53 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7AAA3405EF for <linux-mm@kvack.org>; Mon, 5 Dec 2022 00:51:53 +0000 (UTC) X-FDA: 80206425306.23.A7D10C1 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) by imf06.hostedemail.com (Postfix) with ESMTP id 2F7C0180005 for <linux-mm@kvack.org>; Mon, 5 Dec 2022 00:51:53 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=eWtMKpca; spf=pass (imf06.hostedemail.com: domain of hughd@google.com designates 209.85.160.180 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670201513; a=rsa-sha256; cv=none; b=j+9+mZQVi3aDeSiYug9+oga79GNOHT48vgNmT9Tt7wiGSYsAugLw6zHgNlR7B4mp8qcxQ/ WI6L4UyliHy5MGzJ4+6x3e3LnCyyLeZG8EYfmahC1a2cbW1JzG8kJ391Wy8PndUpqmebXA PHogDuvrRtyyC8wJ1Gi2oHyj73yZHdo= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=eWtMKpca; spf=pass (imf06.hostedemail.com: domain of hughd@google.com designates 209.85.160.180 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=1670201513; 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=pTY2l+gjqfB9RBAkMQhNeterlNdKjU202ghxsWo7JAA=; b=KXorr4jpxVBTP2WMs9/fvz2EgRQ3a9l3dA+mDQIV1oodu9JLLhZclFt2kMxlPLQsYqCX7G 9oUkIuldFATaPyL4wtMc2HbMkybK9vq2IyIZZGdQJs23yfnlLQ/aIRU5bqA7qTsRxKWmnO SCyEf92fGU95QCL/GhxaGvj++W2rZ9g= Received: by mail-qt1-f180.google.com with SMTP id fz10so10478157qtb.3 for <linux-mm@kvack.org>; Sun, 04 Dec 2022 16:51:52 -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=pTY2l+gjqfB9RBAkMQhNeterlNdKjU202ghxsWo7JAA=; b=eWtMKpca6u53309Xb+1JRA0s3CGPDyUCyaLuDVcyQUosW1r9K/S2622XXUTZ9zf8B1 b0Hw6qk3aAig0bEJUj3wtr9zx+TZ1ow3R5LR6LKkLR+12U7f+wDDX7YWhTJQW3r2Z0N4 Y1ChWiyhdX24+WJT5RX86JXogacO6sIo/oXGmI2DyFx3z6OweYrHouWxmXrFOncExgyl v3XbOIcW0EZfplSS0PkE5/Nwgixv5qvJ330v0UNkt/Yy5HxJlfF/xkYoubvm+bn2qN1C FFqDNS+k5Wr3QRtqs5NWG3Lyfs8DTkDIAB/zzf6fLUT6eCtXsHepy02K47sxZ9j2JhMt FgpA== 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=pTY2l+gjqfB9RBAkMQhNeterlNdKjU202ghxsWo7JAA=; b=JMpFbtbrHngdPzfBI+3oXBypRYKPoBH/nge2PdLLI6r4zcp+ImwULQ8bOERyp0JL+2 JZFHwD+2dDk8H6WEHaGQBA+YvGVSM2yK++Xhkfo8sNR5jz/VjcDDBK3UGnY/M/rHoYv2 wWOr5HnsJ7mB8WeBCrIBS4CPBVQlnNBQLpuwYpm+Pb+O5wrjSFFWvqvf8tUtBYib+v4s 72OFv/OoSDG9zAl3N3A9cHMCOO0Tg8EUVcHQumN1wk2gBa0sQXTVEDOQeayhRc2IBrxE cb/m3tH+DRmZvQDS3bezrgbDTFWI/w3OcCWYO42qu3shU24F4I5JETVltX6wVk7B3tB5 10fQ== X-Gm-Message-State: ANoB5pn+caDLX3j2R+6k/EIc8ceh/R/3LZcwSBQ0cfgU5opVw70qiyYx B32WlvY0skmhRwWgTB6UsL5i3g== X-Google-Smtp-Source: AA0mqf7FH3twKpzV3XbhsCtS6L5iw9mLMcoJX/nFWX7DCzhg/0FdEF5ViLHrNlvHJ+DaihnUfi0QjA== X-Received: by 2002:ac8:4995:0:b0:3a6:a35e:8256 with SMTP id f21-20020ac84995000000b003a6a35e8256mr7681681qtq.636.1670201512383; Sun, 04 Dec 2022 16:51:52 -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 d18-20020ac847d2000000b003a611cb2a95sm1329245qtr.9.2022.12.04.16.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Dec 2022 16:51:52 -0800 (PST) Date: Sun, 4 Dec 2022 16:51:50 -0800 (PST) From: Hugh Dickins <hughd@google.com> X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton <akpm@linux-foundation.org> cc: Rui Wang <kernel@hev.cc>, Matthew Wilcox <willy@infradead.org>, Guoqi Chen <chenguoqic@163.com>, Huacai Chen <chenhuacai@loongson.cn>, Rui Wang <r@hev.cc>, Vishal Moola <vishal.moola@gmail.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] tmpfs: fix data loss from failed fallocate In-Reply-To: <5889e4e3-e054-7654-1436-8d2bcbefe3c6@google.com> Message-ID: <a5dac112-cf4b-7af-a33-f386e347fd38@google.com> References: <20221101032248.819360-1-kernel@hev.cc> <Y2KBovUHODJJ8ZnV@casper.infradead.org> <CAHirt9h2CrLhYML3XW=Vj4=BD5eVDoRAbULVGgNbEdYnAzwCzA@mail.gmail.com> <9984f58e-826-74c6-1cd4-65366cc01549@google.com> <5889e4e3-e054-7654-1436-8d2bcbefe3c6@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Rspam-User: X-Spamd-Result: default: False [8.47 / 9.00]; TC_DBL_BL_100(5.00)[163.com:email]; SORBS_IRL_BL(3.00)[209.85.160.180:from]; SUSPICIOUS_RECIPS(1.50)[]; BAYES_HAM(-1.13)[81.16%]; RCVD_NO_TLS_LAST(0.10)[]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_SEVEN(0.00)[9]; DMARC_POLICY_ALLOW(0.00)[google.com,reject]; FROM_EQ_ENVFROM(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; MIME_TRACE(0.00)[0:+]; R_SPF_ALLOW(0.00)[+ip4:209.85.128.0/17]; DKIM_TRACE(0.00)[google.com:+]; RCVD_COUNT_THREE(0.00)[3]; PREVIOUSLY_DELIVERED(0.00)[linux-mm@kvack.org]; TAGGED_RCPT(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; R_DKIM_ALLOW(0.00)[google.com:s=20210112]; FROM_HAS_DN(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 2F7C0180005 X-Rspamd-Server: rspam01 X-Stat-Signature: u36xi4ertdzuy7hengp6oqt4brmfszji X-HE-Tag: 1670201512-781680 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: <linux-mm.kvack.org> |
Series |
tmpfs: fix data loss from failed fallocate
|
expand
|
--- 6.1-rc8/mm/shmem.c +++ linux/mm/shmem.c @@ -948,6 +948,15 @@ static void shmem_undo_range(struct inod index++; } + /* + * When undoing a failed fallocate, we want none of the partial folio + * zeroing and splitting below, but shall want to truncate the whole + * folio when !uptodate indicates that it was added by this fallocate, + * even when [lstart, lend] covers only a part of the folio. + */ + if (unfalloc) + goto whole_folios; + same_folio = (lstart >> PAGE_SHIFT) == (lend >> PAGE_SHIFT); folio = shmem_get_partial_folio(inode, lstart >> PAGE_SHIFT); if (folio) { @@ -973,6 +982,8 @@ static void shmem_undo_range(struct inod folio_put(folio); } +whole_folios: + index = start; while (index < end) { cond_resched();
Fix tmpfs data loss when the fallocate system call is interrupted by a signal, or fails for some other reason. The partial folio handling in shmem_undo_range() forgot to consider this unfalloc case, and was liable to erase or truncate out data which had already been committed earlier. It turns out that none of the partial folio handling there is appropriate for the unfalloc case, which just wants to proceed to removal of whole folios: which find_get_entries() provides, even when partially covered. Link: https://lore.kernel.org/linux-mm/33b85d82.7764.1842e9ab207.Coremail.chenguoqic@163.com/ Fixes: b9a8a4195c7d ("truncate,shmem: Handle truncates that split large folios") Reported-by: Guoqi Chen <chenguoqic@163.com> Original-patch-by: Rui Wang <kernel@hev.cc> Cc: Huacai Chen <chenhuacai@loongson.cn> Cc: Matthew Wilcox <willy@infradead.org> Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com> Cc: stable@vger.kernel.org # 5.17+ Signed-off-by: Hugh Dickins <hughd@google.com> --- mm/shmem.c | 11 +++++++++++ 1 file changed, 11 insertions(+)