]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.6.5/tmpfs-fix-regression-hang-in-fallocate-undo.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.6.5 / tmpfs-fix-regression-hang-in-fallocate-undo.patch
CommitLineData
99167358
GKH
1From 7f556567036cb7f89aabe2f0954b08566b4efb53 Mon Sep 17 00:00:00 2001
2From: Hugh Dickins <hughd@google.com>
3Date: Sun, 10 Jul 2016 16:46:32 -0700
4Subject: tmpfs: fix regression hang in fallocate undo
5
6From: Hugh Dickins <hughd@google.com>
7
8commit 7f556567036cb7f89aabe2f0954b08566b4efb53 upstream.
9
10The well-spotted fallocate undo fix is good in most cases, but not when
11fallocate failed on the very first page. index 0 then passes lend -1
12to shmem_undo_range(), and that has two bad effects: (a) that it will
13undo every fallocation throughout the file, unrestricted by the current
14range; but more importantly (b) it can cause the undo to hang, because
15lend -1 is treated as truncation, which makes it keep on retrying until
16every page has gone, but those already fully instantiated will never go
17away. Big thank you to xfstests generic/269 which demonstrates this.
18
19Fixes: b9b4bb26af01 ("tmpfs: don't undo fallocate past its last page")
20Signed-off-by: Hugh Dickins <hughd@google.com>
21Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
22Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
23
24---
25 mm/shmem.c | 8 +++++---
26 1 file changed, 5 insertions(+), 3 deletions(-)
27
28--- a/mm/shmem.c
29+++ b/mm/shmem.c
30@@ -2236,9 +2236,11 @@ static long shmem_fallocate(struct file
31 NULL);
32 if (error) {
33 /* Remove the !PageUptodate pages we added */
34- shmem_undo_range(inode,
35- (loff_t)start << PAGE_SHIFT,
36- ((loff_t)index << PAGE_SHIFT) - 1, true);
37+ if (index > start) {
38+ shmem_undo_range(inode,
39+ (loff_t)start << PAGE_SHIFT,
40+ ((loff_t)index << PAGE_SHIFT) - 1, true);
41+ }
42 goto undone;
43 }
44