From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85CC328ED for ; Mon, 12 Dec 2022 13:40:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E359C433EF; Mon, 12 Dec 2022 13:40:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1670852426; bh=hAN3QgonAQdQkf9/bwXblsDa9Q3yKZmBX/v1qOu6cpc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CDrZvEb+ap8/A8BSTk63AcPuWSe0aK62PMrcidIi6IBULSbKnQDyo90mDCiBJ76pv 18Us8ucrEvbpi73ZXp2Uwx63snB4qF3gHhRASMKd2tQQvl9hC6N0sNB5MJSqp/VNUX 95CdsDeGRHOmU5iijRu1lsnnm8RiqIRbwOjFsbs8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hugh Dickins , Guoqi Chen , Rui Wang , Huacai Chen , Matthew Wilcox , "Vishal Moola (Oracle)" , Andrew Morton Subject: [PATCH 6.0 060/157] tmpfs: fix data loss from failed fallocate Date: Mon, 12 Dec 2022 14:16:48 +0100 Message-Id: <20221212130936.979413327@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212130934.337225088@linuxfoundation.org> References: <20221212130934.337225088@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Hugh Dickins commit 44bcabd70cf1425b4243e02251c02b01638a8287 upstream. 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. Original patch by Rui Wang. Link: https://lore.kernel.org/linux-mm/33b85d82.7764.1842e9ab207.Coremail.chenguoqic@163.com/ Link: https://lkml.kernel.org/r/a5dac112-cf4b-7af-a33-f386e347fd38@google.com Fixes: b9a8a4195c7d ("truncate,shmem: Handle truncates that split large folios") Signed-off-by: Hugh Dickins Reported-by: Guoqi Chen Link: https://lore.kernel.org/all/20221101032248.819360-1-kernel@hev.cc/ Cc: Rui Wang Cc: Huacai Chen Cc: Matthew Wilcox Cc: Vishal Moola (Oracle) Cc: [5.17+] Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/shmem.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/mm/shmem.c +++ b/mm/shmem.c @@ -958,6 +958,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) { @@ -983,6 +992,8 @@ static void shmem_undo_range(struct inod folio_put(folio); } +whole_folios: + index = start; while (index < end) { cond_resched();