It clarifies that folio_split_supported() does not check folio->mapping and
can dereference it.
Signed-off-by: Zi Yan <ziy@nvidia.com>
---
mm/huge_memory.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index efea42d68157..15e555f1b85d 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3688,6 +3688,23 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,
return 0;
}
+/**
+ * folio_split_supported() - check if a folio can be split to a given order
+ * @folio: folio to be split
+ * @new_order: the smallest order of the after split folios (since buddy
+ * allocator like split generates folios with orders from @folio's
+ * order - 1 to new_order).
+ * @split_type: uniform or non-uniform split
+ * @warns: whether gives warnings or not for the checks in the function
+ *
+ * folio_split_supported() checks if @folio can be split to @new_order using
+ * @split_type method.
+ *
+ * Context: Caller must make sure folio->mapping is not NULL, since the
+ * function does not check it and can dereference folio->mapping
+ * Return: true - @folio can be split to @new_order, false - @folio cannot be
+ * split
+ */
bool folio_split_supported(struct folio *folio, unsigned int new_order,
enum split_type split_type, bool warns)
{
--
2.51.0
On 11/20/25 04:59, Zi Yan wrote: > It clarifies that folio_split_supported() does not check folio->mapping and > can dereference it. > > Signed-off-by: Zi Yan <ziy@nvidia.com> > --- > mm/huge_memory.c | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index efea42d68157..15e555f1b85d 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -3688,6 +3688,23 @@ static int __split_unmapped_folio(struct folio *folio, int new_order, > return 0; > } > > +/** > + * folio_split_supported() - check if a folio can be split to a given order > + * @folio: folio to be split > + * @new_order: the smallest order of the after split folios (since buddy > + * allocator like split generates folios with orders from @folio's > + * order - 1 to new_order). > + * @split_type: uniform or non-uniform split > + * @warns: whether gives warnings or not for the checks in the function > + * > + * folio_split_supported() checks if @folio can be split to @new_order using > + * @split_type method. > + * > + * Context: Caller must make sure folio->mapping is not NULL, since the > + * function does not check it and can dereference folio->mapping Only for anon folios. Also, I would drop the detail about dereference. I guess we really need the folio lock to prevent concurrent truncation. Maybe something like: "The folio must be locked. For non-anon folios, the caller must make sure that folio->mapping is not NULL (e.g., not truncated)." -- Cheers David
On 20 Nov 2025, at 4:27, David Hildenbrand (Red Hat) wrote: > On 11/20/25 04:59, Zi Yan wrote: >> It clarifies that folio_split_supported() does not check folio->mapping and >> can dereference it. >> >> Signed-off-by: Zi Yan <ziy@nvidia.com> >> --- >> mm/huge_memory.c | 17 +++++++++++++++++ >> 1 file changed, 17 insertions(+) >> >> diff --git a/mm/huge_memory.c b/mm/huge_memory.c >> index efea42d68157..15e555f1b85d 100644 >> --- a/mm/huge_memory.c >> +++ b/mm/huge_memory.c >> @@ -3688,6 +3688,23 @@ static int __split_unmapped_folio(struct folio *folio, int new_order, >> return 0; >> } >> +/** >> + * folio_split_supported() - check if a folio can be split to a given order >> + * @folio: folio to be split >> + * @new_order: the smallest order of the after split folios (since buddy >> + * allocator like split generates folios with orders from @folio's >> + * order - 1 to new_order). >> + * @split_type: uniform or non-uniform split >> + * @warns: whether gives warnings or not for the checks in the function >> + * >> + * folio_split_supported() checks if @folio can be split to @new_order using >> + * @split_type method. >> + * >> + * Context: Caller must make sure folio->mapping is not NULL, since the >> + * function does not check it and can dereference folio->mapping > > Only for anon folios. Also, I would drop the detail about dereference. OK. > > I guess we really need the folio lock to prevent concurrent truncation. > > Maybe something like: > > "The folio must be locked. For non-anon folios, the caller must make sure that folio->mapping is not NULL (e.g., not truncated)." Sure. Do you think it is worth adding VM_WARN_ONCE_ON(!folio_test_locked); and VM_WARN_ONCE_ON(!folio->mapping); ? Best Regards, Yan, Zi
On 11/20/25 15:48, Zi Yan wrote:
> On 20 Nov 2025, at 4:27, David Hildenbrand (Red Hat) wrote:
>
>> On 11/20/25 04:59, Zi Yan wrote:
>>> It clarifies that folio_split_supported() does not check folio->mapping and
>>> can dereference it.
>>>
>>> Signed-off-by: Zi Yan <ziy@nvidia.com>
>>> ---
>>> mm/huge_memory.c | 17 +++++++++++++++++
>>> 1 file changed, 17 insertions(+)
>>>
>>> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
>>> index efea42d68157..15e555f1b85d 100644
>>> --- a/mm/huge_memory.c
>>> +++ b/mm/huge_memory.c
>>> @@ -3688,6 +3688,23 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,
>>> return 0;
>>> }
>>> +/**
>>> + * folio_split_supported() - check if a folio can be split to a given order
>>> + * @folio: folio to be split
>>> + * @new_order: the smallest order of the after split folios (since buddy
>>> + * allocator like split generates folios with orders from @folio's
>>> + * order - 1 to new_order).
>>> + * @split_type: uniform or non-uniform split
>>> + * @warns: whether gives warnings or not for the checks in the function
>>> + *
>>> + * folio_split_supported() checks if @folio can be split to @new_order using
>>> + * @split_type method.
>>> + *
>>> + * Context: Caller must make sure folio->mapping is not NULL, since the
>>> + * function does not check it and can dereference folio->mapping
>>
>> Only for anon folios. Also, I would drop the detail about dereference.
>
> OK.
>
>>
>> I guess we really need the folio lock to prevent concurrent truncation.
>>
>> Maybe something like:
>>
>> "The folio must be locked. For non-anon folios, the caller must make sure that folio->mapping is not NULL (e.g., not truncated)."
>
> Sure. Do you think it is worth adding VM_WARN_ONCE_ON(!folio_test_locked);
> and VM_WARN_ONCE_ON(!folio->mapping); ?
Makes sense. Or we allow !folio->mapping, return false and do something
like the following. Still wondering how we could handle that case better.
if (!folio_split_supported(folio)) {
if (folio_split_temporarily_unsupported(folio))
return -EBUSY;
return -EINVAL;
}
hmmmm
--
Cheers
David
On 11/20/25 14:59, Zi Yan wrote:
> It clarifies that folio_split_supported() does not check folio->mapping and
> can dereference it.
>
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> ---
> mm/huge_memory.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index efea42d68157..15e555f1b85d 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -3688,6 +3688,23 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,
> return 0;
> }
>
> +/**
> + * folio_split_supported() - check if a folio can be split to a given order
> + * @folio: folio to be split
> + * @new_order: the smallest order of the after split folios (since buddy
> + * allocator like split generates folios with orders from @folio's
> + * order - 1 to new_order).
> + * @split_type: uniform or non-uniform split
> + * @warns: whether gives warnings or not for the checks in the function
> + *
> + * folio_split_supported() checks if @folio can be split to @new_order using
> + * @split_type method.
> + *
> + * Context: Caller must make sure folio->mapping is not NULL, since the
> + * function does not check it and can dereference folio->mapping
> + * Return: true - @folio can be split to @new_order, false - @folio cannot be
> + * split
> + */
> bool folio_split_supported(struct folio *folio, unsigned int new_order,
> enum split_type split_type, bool warns)
> {
Looks good!
Reviewed-by: Balbir Singh <balbirs@nvidia.com>
© 2016 - 2025 Red Hat, Inc.