Skip to contentSkip to conversation

fs/dax: Remove redundant deferred list initialization

PATCH Applied Kaitao Cheng 4 participants 4 messages Sep 3 – Sep 4

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/dax: Remove redundant deferred list initialization

From: Kaitao Cheng <[email protected]>

prep_compound_page() calls prep_compound_head(), which initializes folio->_deferred_list for compound folios with an order greater than one. Therefore, dax_folio_init() initializes the list twice for large DAX folios.

Remove the redundant initialization from dax_folio_init(). This leaves the behavior unchanged and keeps compound folio initialization centralized in prep_compound_head().

---
 fs/dax.c | 2 --
 1 file changed, 2 deletions(-)
fs/dax.c +0 -2
index 6ba50142eeb2..dad4efea7964 100644
@@ -469,8 +469,6 @@ static void dax_folio_init(void *entry)
 
 	if (order > 0) {
 		prep_compound_page(&folio->page, order);
-		if (order > 1)
-			INIT_LIST_HEAD(&folio->_deferred_list);
 		WARN_ON_ONCE(folio_ref_count(folio));
 	}
 }
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] dax_delete_mapping_range() splits PMD entries and causes duplicate processing leading to nrpages underflow --

commit ab9d688e10fd86aba4bb8d5161b095d144b422c0
Author: Kaitao Cheng <[email protected]>

fs/dax: Remove redundant deferred list initialization

This commit removes the redundant initialization of folio->_deferred_list for large DAX folios in dax_folio_init(). This is because prep_compound_head() already handles it, leaving compound folio initialization centralized.

fs/dax.c

Quoted 4 lines
fs/dax.c +0 -0
index 1fbba0d21c13d..4ea0f13d53a65 100644

[ ... ]

[Severity: Critical]
This isn't a bug introduced by this patch, but I noticed a potential pre-existing issue in dax_delete_mapping_range() when it processes multi-order DAX entries:

fs/dax.c:dax_delete_mapping_range() {
    ...
    XA_STATE(xas, &mapping->i_pages, start_idx);
    ...
    xas_for_each(&xas, entry, end_idx) {
        if (!xa_is_value(entry))
            continue;
        entry = wait_entry_unlocked_exclusive(&xas, entry);
        if (!entry)
            continue;
        dax_disassociate_entry(entry, mapping, true);
        xas_store(&xas, NULL);
        mapping->nrpages -= 1UL << dax_entry_order(entry);
        put_unlocked_entry(&xas, entry, WAKE_ALL);
    }
    ...
}

When deleting a mapping range on a DAX filesystem containing PMD-sized entries, this loop uses an order-0 XA_STATE. If xas_store() encounters an order-9 PMD entry, doesn't it split the entry into 512 order-0 entries (one NULL and 511 copies of the PMD value)?

Because xas_advance() is not called after the store, will the iterator continue to visit the remaining 511 split sibling slots and process the same PMD entry again?

Since mapping->nrpages is decremented by 1UL << dax_entry_order(entry) (which is 512 for a PMD entry) on each iteration, could this underflow the counter by 262,144 per PMD entry and result in catastrophic memory accounting corruption?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Acked-by on v1 1/1
#2 lore raw
In reply to Kaitao Cheng
Quoted 11 lines · Kaitao Cheng

From: Kaitao Cheng <[email protected]>

prep_compound_page() calls prep_compound_head(), which initializes folio->_deferred_list for compound folios with an order greater than one. Therefore, dax_folio_init() initializes the list twice for large DAX folios.

Quoted 5 lines

Remove the redundant initialization from dax_folio_init(). This leaves the behavior unchanged and keeps compound folio initialization centralized in prep_compound_head().

Thanks.

maintainer Applied
#3 lore raw
In reply to Kaitao Cheng
Quoted 1 line · Kaitao Cheng

fs/dax: Remove redundant deferred list initialization

Applied to the vfs-7.4.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.4.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.4.misc

[1/1] fs/dax: Remove redundant deferred list initialization

      https://git.kernel.org/vfs/vfs/c/4dda2f40edd8