From patchwork Mon Dec 5 00:51:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 29480 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2003083wrr; Sun, 4 Dec 2022 16:53:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf7IEZkK6oxTR/kIXy4kHwg+fjkFWcVKs30E+78TJJiJPPvm62uOTh/4W1U2gRnXU9OCnpDi X-Received: by 2002:a17:903:110c:b0:189:8351:8bd9 with SMTP id n12-20020a170903110c00b0018983518bd9mr38603572plh.94.1670201581145; Sun, 04 Dec 2022 16:53:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670201581; cv=none; d=google.com; s=arc-20160816; b=PSH/KELiDgVNYI1GntL9IEiHN8VqeG45Nk++LRT54zyRzVqGqRaAb1msCMrxDXk65f KjRouMPyVzgZb3ohp9MEcqwznReBM/2y3NPTc8cknmRonUdZlPhJYIM486EdFUoY2TCy t9J5fmkhqVN4qnz38cyt/0bWrr7hRRstqo2Lc8wvEH9tyF2xuFAr6/v2hV8b6qJLjWht 4H15xiIcjN6Kjsi0nvFwQe0pqnU9QtxfK2CJZAyg+Y7pZBMuSjd048fbCeh85a1W+prT HQnbUWNTUC3IexfRhDrcPj7oU2kXd8Pj5wozwYfk62gQZnhGbuXAn97ShCxJWA/HcMfl hCRQ== 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=pTY2l+gjqfB9RBAkMQhNeterlNdKjU202ghxsWo7JAA=; b=aTEMOIMrTk9ajcMR9Y5/1EmGsz068vpJfiWldkVTAS2rrUu+JP6kY/CStNuoWEAjmK 8bAX22YCh1HfliuF6F4nsx9hhUe/NCpJHd4oc/ejTEU8mrVBax1MdhK3Gnx38hd/1NsS TyM2iR4Sbcoy/h82QPpPQ9Dn8LUHuK51A1VE0p4HFs+4lGv3M2gMv7nUf24Dw5Yo4Sed BiuHrm9ujQXfaymrndMFp+Noq4f0NXGJFNF1+rNW1N2iBXdRk4m1L1zEQmaBrmZuRPs0 3LeUpcWIVF3uKez9CeHVoct/g2mFrQoqtyZ/p0ri+S48fouDBSlW6trG+gVQN8DD2MLm BJRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=eWtMKpca; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k9-20020a170902ba8900b00172696f35e1si12163913pls.482.2022.12.04.16.52.48; Sun, 04 Dec 2022 16:53:01 -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=eWtMKpca; 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 S230475AbiLEAv5 (ORCPT + 99 others); Sun, 4 Dec 2022 19:51:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229529AbiLEAvz (ORCPT ); Sun, 4 Dec 2022 19:51:55 -0500 Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 904441147F for ; Sun, 4 Dec 2022 16:51:53 -0800 (PST) Received: by mail-qt1-x82e.google.com with SMTP id cg5so10447990qtb.12 for ; Sun, 04 Dec 2022 16:51:53 -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=gq1ESows1HnpKmYYlOjTrVXYc1MAAs1rcTFikByihd68dOBQF3RmX1yBwxw0TuT9Kp VqZvxGYpX8Jc8qDGoPW+k7fXRSmcqaBCSWDh9BpQe5Cnb46k5oFqdGmoPG4WtC+nekea dLC/VJRR9xDdULqFRi5vyeQrIgiv6V2UU7ImMEpX3z+kcaqOPHgNntquLkXaWPIGkrQ4 VT9DSYO2hVU0DrguZybROsDsfW5OJIHHnKuyOP76frZAzKK8OtAT3STo0YDw1hd6CqbF vryxoqxgdynDWno9DUskVU0GIZfQQlb7i+4pv4mxKqGH2y76t0L9Vsmwlr09dacyV8nG Cnkg== X-Gm-Message-State: ANoB5pluYEaVEUyEUyW9WXn+HYt7YWkWpjlHAXylHl6Auq9IsRzsiyr5 0q4iKI7vw9e0lpBt0l4dAvyIqA== 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 X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Rui Wang , Matthew Wilcox , Guoqi Chen , Huacai Chen , Rui Wang , Vishal Moola , 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: References: <20221101032248.819360-1-kernel@hev.cc> <9984f58e-826-74c6-1cd4-65366cc01549@google.com> <5889e4e3-e054-7654-1436-8d2bcbefe3c6@google.com> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751333293262228326?= X-GMAIL-MSGID: =?utf-8?q?1751333293262228326?= 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 Original-patch-by: Rui Wang Cc: Huacai Chen Cc: Matthew Wilcox Cc: Vishal Moola (Oracle) Cc: stable@vger.kernel.org # 5.17+ Signed-off-by: Hugh Dickins --- mm/shmem.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- 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();