diff mbox series

[1/2] mm/filemap: fix find_lock_entries hang on 32-bit THP

Message ID alpine.LSU.2.11.2104211735430.3299@eggly.anvils (mailing list archive)
State New
Headers show
Series [1/2] mm/filemap: fix find_lock_entries hang on 32-bit THP | expand

Commit Message

Hugh Dickins April 22, 2021, 12:37 a.m. UTC
No problem on 64-bit, or without huge pages, but xfstests generic/308
hung uninterruptibly on 32-bit huge tmpfs.  Since 4.13's 0cc3b0ec23ce
("Clarify (and fix) MAX_LFS_FILESIZE macros"), MAX_LFS_FILESIZE is
only a PAGE_SIZE away from wrapping 32-bit xa_index to 0, so the new
find_lock_entries() has to be extra careful when handling a THP.

Fixes: 5c211ba29deb ("mm: add and use find_lock_entries")
Signed-off-by: Hugh Dickins <hughd@google.com>
---

 mm/filemap.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Matthew Wilcox April 22, 2021, 1:06 a.m. UTC | #1
On Wed, Apr 21, 2021 at 05:37:33PM -0700, Hugh Dickins wrote:
> -		if (!xa_is_value(page) && PageTransHuge(page))
> -			xas_set(&xas, page->index + thp_nr_pages(page));
> +		if (!xa_is_value(page) && PageTransHuge(page)) {
> +			unsigned int nr_pages = thp_nr_pages(page);
> +
> +			/* Final THP may cross MAX_LFS_FILESIZE on 32-bit */
> +			xas_set(&xas, page->index + nr_pages);
> +			if (xas.xa_index < nr_pages)
> +				break;
> +		}

Aargh.  We really need to get the multi-index support in; this works
perfectly when the xas_set() hack isn't needed any more.
diff mbox series

Patch

--- 5.12-rc8/mm/filemap.c	2021-02-26 19:42:39.812156085 -0800
+++ linux/mm/filemap.c	2021-04-20 23:20:20.509464440 -0700
@@ -1969,8 +1969,14 @@  unlock:
 put:
 		put_page(page);
 next:
-		if (!xa_is_value(page) && PageTransHuge(page))
-			xas_set(&xas, page->index + thp_nr_pages(page));
+		if (!xa_is_value(page) && PageTransHuge(page)) {
+			unsigned int nr_pages = thp_nr_pages(page);
+
+			/* Final THP may cross MAX_LFS_FILESIZE on 32-bit */
+			xas_set(&xas, page->index + nr_pages);
+			if (xas.xa_index < nr_pages)
+				break;
+		}
 	}
 	rcu_read_unlock();