Fix parameter passed to page_mapcount_is_type()
Subsystems (2)
v2 cover Fix parameter passed to page_mapcount_is_type()
Found by code inspection. There are two places where the parameter passed to page_mapcount_is_type() is (page->_mapcount), which is incorrect since it should be one more than the value, as explained in the comments to page_mapcount_is_type(): (a) page_has_type() in page-flags.h (b) __dump_folio() in mm/debug.c
PATCH[1] fixes the parameter for (a)
PATCH[2] fixes the parameter for (b)
Note that the issue doesn't cause any visible impacts due to the safety gap introduced by PGTY_mapcount_underflow limit. So the tag 'Cc: [email protected]' isn't needed.
Changelog
=========
v2:
* Improved commit log (Vlastimi/David)
* Use page_type_has_type() in page_has_type() (David)
Gavin Shan (2):
mm: Fix parameter passed to page_mapcount_is_type() mm/debug: Fix parameter passed to page_mapcount_is_type()
include/linux/page-flags.h | 2 +- mm/debug.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.48.1
PATCH v2 1/2 mm: Fix parameter passed to page_mapcount_is_type()
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") page_type_has_type() is replaced by page_mapcount_is_type(), but the parameter isn't adjusted.
Fix it by replacing page_mapcount_is_type() with page_type_has_type() in page_has_type(). Note that the issue doesn't cause any visible impacts due to the safety gap introduced by PGTY_mapcount_underflow limit.
--- include/linux/page-flags.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/page-flags.h +1 -1
@@ -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_type_has_type (data_race (page->page_type)); }#define FOLIO_TYPE_OPS (lname, fname) \
Signature · 1 line
2.48.1
Re: [PATCH v2 1/2] mm: Fix parameter passed to page_mapcount_is_type()
Quoted 7 lines · Gavin Shan
As the comments of
page_mapcount_is_type()indicate, the parameter passed to the function should be one more thanpage->_mapcount. However,page->_mapcount(equivalent topage->page_type) is passed to the function by commit4ffca5a96678("mm: support only onepage_typeper page")page_type_has_type()is replaced bypage_mapcount_is_type(), but the parameter isn't adjusted.
Quoted 7 lines
Fix it by replacing
page_mapcount_is_type()withpage_type_has_type()inpage_has_type(). Note that the issue doesn't cause any visible impacts due to the safety gap introduced byPGTY_mapcount_underflowlimit.Fixes 4ffca5a96678 ("mm: support only one page_type per page")Signed-off-by Gavin Shan <[email protected]>
Quoted 17 lines
--- include/linux/page-flags.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/page-flags.h +1
-1@@ -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_type_has_type (data_race (page->page_type)); }#define FOLIO_TYPE_OPS (lname, fname) \
PATCH v2 2/2 mm/debug: Fix parameter passed to page_mapcount_is_type()
In reply to Gavin ShanAs the comments of page_mapcount_is_type() indicate, the parameter passed to the function should be one more than page->_mapcount. However, page->_mapcount 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 for page_mapcount_is_type() to be (page->__mapcount
+ 1). Note that the issue doesn't cause any visible impacts due to the safety gap introduced by PGTY_mapcount_underflow limit.
--- mm/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/debug.c +2 -2
@@ -71,10 +71,10 @@ static void __dump_folio(struct folio *folio, struct page *page, unsigned long pfn, unsigned long idx) {struct address_space *mapping =folio_mapping (folio); -int mapcount =atomic_read (&page->_mapcount); +int mapcount =atomic_read (&page->_mapcount) +1 ;char *type ="" ; - mapcount =page_mapcount_is_type (mapcount) ?0 : mapcount +1 ; + mapcount =page_mapcount_is_type (mapcount) ?0 : mapcount;pr_warn ("page: refcount:%d mapcount:%d mapping:%p index:%#lx pfn:%#lx\n" ,folio_ref_count (folio), mapcount, mapping, folio->index + idx, pfn);
Signature · 1 line
2.48.1
Re: [PATCH v2 2/2] mm/debug: Fix parameter passed to page_mapcount_is_type()
Quoted 6 lines · Gavin Shan
As the comments of
page_mapcount_is_type()indicate, the parameter passed to the function should be one more thanpage->_mapcount. However,page->_mapcountis passed to the function by commit4ffca5a96678("mm: support only onepage_typeper page") wherepage_type_has_type()is replaced bypage_mapcount_is_type(), but the parameter isn't adjusted.
Quoted 7 lines
Fix the parameter for
page_mapcount_is_type()to be (page->__mapcount
+ 1). Note that the issue doesn't cause any visible impacts due to the safety gap introduced byPGTY_mapcount_underflowlimit.Fixes 4ffca5a96678 ("mm: support only one page_type per page")Signed-off-by Gavin Shan <[email protected]>
Quoted 9 lines
--- mm/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/debug.c +0
-0
mm/debug.c static void __dump_folio(struct folio *folio, struct page *page, · line 77
Quoted 9 lines
mm/debug.c +2
-2@@ -71,10 +71,10 @@ static void __dump_folio(struct folio *folio, struct page *page, unsigned long pfn, unsigned long idx) {struct address_space *mapping =folio_mapping (folio); -int mapcount =atomic_read (&page->_mapcount); +int mapcount =atomic_read (&page->_mapcount) +1 ;char *type ="" ; - mapcount =page_mapcount_is_type (mapcount) ?0 : mapcount +1 ; + mapcount =page_mapcount_is_type (mapcount) ?0 : mapcount;
At this point it would be perhaps more obvious:
if (page_mapcount_is_type(mapcount))
mapcount = 0;
But doesn't matter much.
Quoted 3 lines
mm/debug.c +0
-0pr_warn ("page: refcount:%d mapcount:%d mapping:%p index:%#lx pfn:%#lx\n" ,folio_ref_count (folio), mapcount, mapping, folio->index + idx, pfn);
Re: [PATCH v2 2/2] mm/debug: Fix parameter passed to page_mapcount_is_type()
Quoted 33 lines · Vlastimil Babka
Quoted 6 lines · Gavin Shan
As the comments of
page_mapcount_is_type()indicate, the parameter passed to the function should be one more thanpage->_mapcount. However,page->_mapcountis passed to the function by commit4ffca5a96678("mm: support only onepage_typeper page") wherepage_type_has_type()is replaced bypage_mapcount_is_type(), but the parameter isn't adjusted.Quoted 7 lines
Fix the parameter for
page_mapcount_is_type()to be (page->__mapcount
+ 1). Note that the issue doesn't cause any visible impacts due to the safety gap introduced byPGTY_mapcount_underflowlimit.Fixes 4ffca5a96678 ("mm: support only one page_type per page")Signed-off-by Gavin Shan <[email protected]>Acked-by Vlastimil Babka <[email protected]>Quoted 16 lines
--- mm/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/debug.c +1
-1@@ -71,10 +71,10 @@ static void __dump_folio(struct folio *folio, struct page *page, unsigned long pfn, unsigned long idx) {struct address_space *mapping =folio_mapping (folio); -int mapcount =atomic_read (&page->_mapcount); +int mapcount =atomic_read (&page->_mapcount) +1 ;char *type ="" ;
Quoted 7 lines
mm/debug.c static void __dump_folio(struct folio *folio, struct page *page, · line 77
Quoted 2 lines
mm/debug.c +1
-1- mapcount =page_mapcount_is_type (mapcount) ?0 : mapcount +1 ; + mapcount =page_mapcount_is_type (mapcount) ?0 : mapcount;At this point it would be perhaps more obvious:
if (
page_mapcount_is_type(mapcount))mapcount = 0;
Agreed, maybe Andrew can fix that up.
Signature · 3 lines
Cheers, David / dhildenb
Andrew Morton
maintainerRe: [PATCH v2 2/2] mm/debug: Fix parameter passed to page_mapcount_is_type()
Quoted 9 lines · On Fri, 21 Mar 2025 16:38:29 +0100 David Hildenbrand <[email protected]> wrote:
Quoted 7 lines
mm/debug.c static void __dump_folio(struct folio *folio, struct page *page, · line 77
Quoted 2 lines
mm/debug.c +1
-1- mapcount =page_mapcount_is_type (mapcount) ?0 : mapcount +1 ; + mapcount =page_mapcount_is_type (mapcount) ?0 : mapcount;At this point it would be perhaps more obvious:
if (
page_mapcount_is_type(mapcount))mapcount = 0;Agreed, maybe Andrew can fix that up.
Sure. I'll be adding this series to the 6.15-rc1 pile.