Skip to content

Commit 006d3ff

Browse files
Hugh Dickinstorvalds
authored andcommitted
mm/huge_memory: fix lockdep complaint on 32-bit i_size_read()
Huge tmpfs testing, on 32-bit kernel with lockdep enabled, showed that __split_huge_page() was using i_size_read() while holding the irq-safe lru_lock and page tree lock, but the 32-bit i_size_read() uses an irq-unsafe seqlock which should not be nested inside them. Instead, read the i_size earlier in split_huge_page_to_list(), and pass the end offset down to __split_huge_page(): all while holding head page lock, which is enough to prevent truncation of that extent before the page tree lock has been taken. Link: http://lkml.kernel.org/r/alpine.LSU.2.11.1811261520070.2275@eggly.anvils Fixes: baa355f ("thp: file pages support for split_huge_page()") Signed-off-by: Hugh Dickins <hughd@google.com> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Jerome Glisse <jglisse@redhat.com> Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Cc: Matthew Wilcox <willy@infradead.org> Cc: <stable@vger.kernel.org> [4.8+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 173d9d9 commit 006d3ff

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

mm/huge_memory.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,22 +2439,18 @@ static void __split_huge_page_tail(struct page *head, int tail,
24392439
}
24402440

24412441
static void __split_huge_page(struct page *page, struct list_head *list,
2442-
unsigned long flags)
2442+
pgoff_t end, unsigned long flags)
24432443
{
24442444
struct page *head = compound_head(page);
24452445
struct zone *zone = page_zone(head);
24462446
struct lruvec *lruvec;
2447-
pgoff_t end = -1;
24482447
int i;
24492448

24502449
lruvec = mem_cgroup_page_lruvec(head, zone->zone_pgdat);
24512450

24522451
/* complete memcg works before add pages to LRU */
24532452
mem_cgroup_split_huge_fixup(head);
24542453

2455-
if (!PageAnon(page))
2456-
end = DIV_ROUND_UP(i_size_read(head->mapping->host), PAGE_SIZE);
2457-
24582454
for (i = HPAGE_PMD_NR - 1; i >= 1; i--) {
24592455
__split_huge_page_tail(head, i, lruvec, list);
24602456
/* Some pages can be beyond i_size: drop them from page cache */
@@ -2626,6 +2622,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
26262622
int count, mapcount, extra_pins, ret;
26272623
bool mlocked;
26282624
unsigned long flags;
2625+
pgoff_t end;
26292626

26302627
VM_BUG_ON_PAGE(is_huge_zero_page(page), page);
26312628
VM_BUG_ON_PAGE(!PageLocked(page), page);
@@ -2648,6 +2645,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
26482645
ret = -EBUSY;
26492646
goto out;
26502647
}
2648+
end = -1;
26512649
mapping = NULL;
26522650
anon_vma_lock_write(anon_vma);
26532651
} else {
@@ -2661,6 +2659,15 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
26612659

26622660
anon_vma = NULL;
26632661
i_mmap_lock_read(mapping);
2662+
2663+
/*
2664+
*__split_huge_page() may need to trim off pages beyond EOF:
2665+
* but on 32-bit, i_size_read() takes an irq-unsafe seqlock,
2666+
* which cannot be nested inside the page tree lock. So note
2667+
* end now: i_size itself may be changed at any moment, but
2668+
* head page lock is good enough to serialize the trimming.
2669+
*/
2670+
end = DIV_ROUND_UP(i_size_read(mapping->host), PAGE_SIZE);
26642671
}
26652672

26662673
/*
@@ -2707,7 +2714,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
27072714
if (mapping)
27082715
__dec_node_page_state(page, NR_SHMEM_THPS);
27092716
spin_unlock(&pgdata->split_queue_lock);
2710-
__split_huge_page(page, list, flags);
2717+
__split_huge_page(page, list, end, flags);
27112718
if (PageSwapCache(head)) {
27122719
swp_entry_t entry = { .val = page_private(head) };
27132720

0 commit comments

Comments
 (0)