Re: [PATCH v9 04/10] mm: split a folio in minimum folio order chunks

Zi Yan
2024-07-08T13:53:21Z

[-- Attachment #1: Type: text/plain, Size: 2008 bytes --]

On Thu Jul 4, 2024 at 7:23 AM EDT, Pankaj Raghav (Samsung) wrote:
> From: Luis Chamberlain <mcgrof@kernel.org>
>
> split_folio() and split_folio_to_list() assume order 0, to support
> minorder for non-anonymous folios, we must expand these to check the
> folio mapping order and use that.
>
> Set new_order to be at least minimum folio order if it is set in
> split_huge_page_to_list() so that we can maintain minimum folio order
> requirement in the page cache.
>
> Update the debugfs write files used for testing to ensure the order
> is respected as well. We simply enforce the min order when a file
> mapping is used.
>
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
> Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
> Reviewed-by: Hannes Reinecke <hare@suse.de>
> ---
> include/linux/huge_mm.h | 14 ++++++++---
> mm/huge_memory.c | 55 ++++++++++++++++++++++++++++++++++++++---
> 2 files changed, 61 insertions(+), 8 deletions(-)

<snip>
>
> @@ -3265,6 +3277,21 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
> return ret;
> }
>
> +int split_folio_to_list(struct folio *folio, struct list_head *list)
> +{
> + unsigned int min_order = 0;
> +
> + if (!folio_test_anon(folio)) {
> + if (!folio->mapping && folio_test_pmd_mappable(folio)) {
> + count_vm_event(THP_SPLIT_PAGE_FAILED);
> + return -EBUSY;
> + }

This should be

if (!folio->mapping) {
if (folio_test_pmd_mappable(folio))
count_vm_event(THP_SPLIT_PAGE_FAILED);
return -EBUSY;
}

Otherwise, a non PMD mappable folio with no mapping will fall through
and cause NULL pointer dereference in mapping_min_folio_order().

> + min_order = mapping_min_folio_order(folio->mapping);
> + }
> +
> + return split_huge_page_to_list_to_order(&folio->page, list, min_order);
> +}
> +
> void __folio_undo_large_rmappable(struct folio *folio)
> {
> struct deferred_split *ds_queue;

--
Best Regards,
Yan, Zi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 854 bytes --]