On 26 Feb 2024, at 15:55, Zi Yan wrote: > From: Zi Yan <ziy@xxxxxxxxxx> > > To split a THP to any lower order pages, we need to reform THPs on > subpages at given order and add page refcount based on the new page > order. Also we need to reinitialize page_deferred_list after removing > the page from the split_queue, otherwise a subsequent split will > see list corruption when checking the page_deferred_list again. > > Note: Anonymous order-1 folio is not supported because _deferred_list, > which is used by partially mapped folios, is stored in subpage 2 and an > order-1 folio only has subpage 0 and 1. File-backed order-1 folios are > fine, since they do not use _deferred_list. > > Signed-off-by: Zi Yan <ziy@xxxxxxxxxx> > --- > include/linux/huge_mm.h | 21 +++++--- > mm/huge_memory.c | 110 +++++++++++++++++++++++++++++++--------- > 2 files changed, 99 insertions(+), 32 deletions(-) Hi Andrew, Can you fold the patch below into this patch 7? It is based on the discussion with Dan Carpenter at https://lore.kernel.org/linux-mm/7dda9283-b437-4cf8-ab0d-83c330deb9c0@moroto.mountain/. It prevents invalid new_order input from causing unexpected outcome of split_huge_page_to_list_to_order(). Especially in patch 8, new_order can come from debugfs without any restriction. I will send another fixup to patch 8 to check new_order from debugfs. Thanks. diff --git a/mm/huge_memory.c b/mm/huge_memory.c index a81a09236c16..57fca7bffd20 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3052,6 +3052,9 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); VM_BUG_ON_FOLIO(!folio_test_large(folio), folio); + if (new_order >= folio_order(folio)) + return -EINVAL; + /* Cannot split anonymous THP to order-1 */ if (new_order == 1 && folio_test_anon(folio)) { VM_WARN_ONCE(1, "Cannot split to order-1 folio"); -- Best Regards, Yan, Zi
Attachment:
signature.asc
Description: OpenPGP digital signature