diff mbox series

[1/2] mm: Fix parameter passed to page_mapcount_is_type()

Message ID 20250321053148.1434076-2-gshan@redhat.com (mailing list archive)
State New
Headers show
Series Fix parameter passed to page_mapcount_is_type() | expand

Commit Message

Gavin Shan March 21, 2025, 5:31 a.m. UTC
As the comments of page_mapcount_is_type() indicate, the parameter
passed to the function should be one more than page->__mapcount.
However, page->__mapcount (equivalent to page->page_type) is passed to
the function by commit 4ffca5a96678 ("mm: support only one page_type per
page") where page_type_has_type() is replaced by page_mapcount_is_type(),
but the parameter isn't adjusted.

Fix the parameter passed to page_mapcount_is_type() to be (page->__mapcount
+ 1).

Fixes: 4ffca5a96678 ("mm: support only one page_type per page")
Cc: stable@vger.kernel.org # v6.12+
Signed-off-by: Gavin Shan <gshan@redhat.com>
---
 include/linux/page-flags.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Hildenbrand March 21, 2025, 10:13 a.m. UTC | #1
On 21.03.25 06:31, Gavin Shan wrote:
> As the comments of page_mapcount_is_type() indicate, the parameter
> passed to the function should be one more than page->__mapcount.
> However, page->__mapcount (equivalent to page->page_type) is passed to
> the function by commit 4ffca5a96678 ("mm: support only one page_type per
> page") where page_type_has_type() is replaced by page_mapcount_is_type(),
> but the parameter isn't adjusted.
> 
> Fix the parameter passed to page_mapcount_is_type() to be (page->__mapcount
> + 1).
> 
> Fixes: 4ffca5a96678 ("mm: support only one page_type per page")
> Cc: stable@vger.kernel.org # v6.12+
> Signed-off-by: Gavin Shan <gshan@redhat.com>
> ---
>   include/linux/page-flags.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
> index 36d283552f80..ad87b4cf1f9a 100644
> --- a/include/linux/page-flags.h
> +++ b/include/linux/page-flags.h
> @@ -950,7 +950,7 @@ static inline bool page_mapcount_is_type(unsigned int mapcount)
>   
>   static inline bool page_has_type(const struct page *page)
>   {
> -	return page_mapcount_is_type(data_race(page->page_type));
> +	return page_mapcount_is_type(data_race(page->page_type) + 1);

Probably we should just call page_type_has_type() instead?
Gavin Shan March 21, 2025, 11:26 a.m. UTC | #2
On 3/21/25 8:13 PM, David Hildenbrand wrote:
> On 21.03.25 06:31, Gavin Shan wrote:
>> As the comments of page_mapcount_is_type() indicate, the parameter
>> passed to the function should be one more than page->__mapcount.
>> However, page->__mapcount (equivalent to page->page_type) is passed to
>> the function by commit 4ffca5a96678 ("mm: support only one page_type per
>> page") where page_type_has_type() is replaced by page_mapcount_is_type(),
>> but the parameter isn't adjusted.
>>
>> Fix the parameter passed to page_mapcount_is_type() to be (page->__mapcount
>> + 1).
>>
>> Fixes: 4ffca5a96678 ("mm: support only one page_type per page")
>> Cc: stable@vger.kernel.org # v6.12+
>> Signed-off-by: Gavin Shan <gshan@redhat.com>
>> ---
>>   include/linux/page-flags.h | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
>> index 36d283552f80..ad87b4cf1f9a 100644
>> --- a/include/linux/page-flags.h
>> +++ b/include/linux/page-flags.h
>> @@ -950,7 +950,7 @@ static inline bool page_mapcount_is_type(unsigned int mapcount)
>>   static inline bool page_has_type(const struct page *page)
>>   {
>> -    return page_mapcount_is_type(data_race(page->page_type));
>> +    return page_mapcount_is_type(data_race(page->page_type) + 1);
> 
> Probably we should just call page_type_has_type() instead?
> 

Yes, page_type_has_type() is better. It will be used in v2.

Thanks,
Gavin
David Hildenbrand March 21, 2025, 11:28 a.m. UTC | #3
On 21.03.25 12:26, Gavin Shan wrote:
> On 3/21/25 8:13 PM, David Hildenbrand wrote:
>> On 21.03.25 06:31, Gavin Shan wrote:
>>> As the comments of page_mapcount_is_type() indicate, the parameter
>>> passed to the function should be one more than page->__mapcount.
>>> However, page->__mapcount (equivalent to page->page_type) is passed to
>>> the function by commit 4ffca5a96678 ("mm: support only one page_type per
>>> page") where page_type_has_type() is replaced by page_mapcount_is_type(),
>>> but the parameter isn't adjusted.
>>>
>>> Fix the parameter passed to page_mapcount_is_type() to be (page->__mapcount
>>> + 1).
>>>
>>> Fixes: 4ffca5a96678 ("mm: support only one page_type per page")
>>> Cc: stable@vger.kernel.org # v6.12+
>>> Signed-off-by: Gavin Shan <gshan@redhat.com>
>>> ---
>>>    include/linux/page-flags.h | 2 +-
>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
>>> index 36d283552f80..ad87b4cf1f9a 100644
>>> --- a/include/linux/page-flags.h
>>> +++ b/include/linux/page-flags.h
>>> @@ -950,7 +950,7 @@ static inline bool page_mapcount_is_type(unsigned int mapcount)
>>>    static inline bool page_has_type(const struct page *page)
>>>    {
>>> -    return page_mapcount_is_type(data_race(page->page_type));
>>> +    return page_mapcount_is_type(data_race(page->page_type) + 1);
>>
>> Probably we should just call page_type_has_type() instead?
>>
> 
> Yes, page_type_has_type() is better. It will be used in v2.


Feel free to add my

Acked-by: David Hildenbrand <david@redhat.com>
diff mbox series

Patch

diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index 36d283552f80..ad87b4cf1f9a 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -950,7 +950,7 @@  static inline bool page_mapcount_is_type(unsigned int mapcount)
 
 static inline bool page_has_type(const struct page *page)
 {
-	return page_mapcount_is_type(data_race(page->page_type));
+	return page_mapcount_is_type(data_race(page->page_type) + 1);
 }
 
 #define FOLIO_TYPE_OPS(lname, fname)					\