Skip to content

Commit d778214

Browse files
committed
filesystem-dax: Fix dax_layout_busy_page() livelock
In the presence of multi-order entries the typical pagevec_lookup_entries() pattern may loop forever: while (index < end && pagevec_lookup_entries(&pvec, mapping, index, min(end - index, (pgoff_t)PAGEVEC_SIZE), indices)) { ... for (i = 0; i < pagevec_count(&pvec); i++) { index = indices[i]; ... } index++; /* BUG */ } The loop updates 'index' for each index found and then increments to the next possible page to continue the lookup. However, if the last entry in the pagevec is multi-order then the next possible page index is more than 1 page away. Fix this locally for the filesystem-dax case by checking for dax-multi-order entries. Going forward new users of multi-order entries need to be similarly careful, or we need a generic way to report the page increment in the radix iterator. Fixes: 5fac740 ("mm, fs, dax: handle layout changes to pinned dax...") Cc: <stable@vger.kernel.org> Cc: Ross Zwisler <zwisler@kernel.org> Cc: Matthew Wilcox <willy@infradead.org> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 17b57b1 commit d778214

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

fs/dax.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@ struct page *dax_layout_busy_page(struct address_space *mapping)
666666
while (index < end && pagevec_lookup_entries(&pvec, mapping, index,
667667
min(end - index, (pgoff_t)PAGEVEC_SIZE),
668668
indices)) {
669+
pgoff_t nr_pages = 1;
670+
669671
for (i = 0; i < pagevec_count(&pvec); i++) {
670672
struct page *pvec_ent = pvec.pages[i];
671673
void *entry;
@@ -680,8 +682,15 @@ struct page *dax_layout_busy_page(struct address_space *mapping)
680682

681683
xa_lock_irq(&mapping->i_pages);
682684
entry = get_unlocked_mapping_entry(mapping, index, NULL);
683-
if (entry)
685+
if (entry) {
684686
page = dax_busy_page(entry);
687+
/*
688+
* Account for multi-order entries at
689+
* the end of the pagevec.
690+
*/
691+
if (i + 1 >= pagevec_count(&pvec))
692+
nr_pages = 1UL << dax_radix_order(entry);
693+
}
685694
put_unlocked_mapping_entry(mapping, index, entry);
686695
xa_unlock_irq(&mapping->i_pages);
687696
if (page)
@@ -696,7 +705,7 @@ struct page *dax_layout_busy_page(struct address_space *mapping)
696705
*/
697706
pagevec_remove_exceptionals(&pvec);
698707
pagevec_release(&pvec);
699-
index++;
708+
index += nr_pages;
700709

701710
if (page)
702711
break;

0 commit comments

Comments
 (0)