Fix parameter passed to page_mapcount_is_type()
Subsystems (2)
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 correct 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)
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 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") 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).
--- 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_mapcount_is_type (data_race (page->page_type) +1 ); }#define FOLIO_TYPE_OPS (lname, fname) \
Signature · 1 line
2.48.1
Re: [PATCH 1/2] mm: Fix parameter passed to page_mapcount_is_type()
Quoted 22 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") wherepage_type_has_type()is replaced bypage_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 [email protected] # v6.12+Signed-off-by Gavin Shan <[email protected]>--- include/linux/page-flags.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/page-flags.h +0
-0
include/linux/page-flags.h static inline bool page_mapcount_is_type(unsigned int mapcount) · line 953
Quoted 5 lines
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_mapcount_is_type (data_race (page->page_type) +1 );
Probably we should just call page_type_has_type() instead?
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 1/2] mm: Fix parameter passed to page_mapcount_is_type()
Quoted 18 lines · David Hildenbrand
Quoted 17 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") wherepage_type_has_type()is replaced bypage_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 [email protected] # v6.12+Signed-off-by Gavin Shan <[email protected]>---
include/linux/page-flags.h| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines
include/linux/page-flags.h static inline bool page_mapcount_is_type(unsigned int mapcount) · line 952
Quoted 9 lines
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_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
Acked-byRe: [PATCH 1/2] mm: Fix parameter passed to page_mapcount_is_type()
Quoted 32 lines · Gavin Shan
Quoted 18 lines · David Hildenbrand
Quoted 17 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") wherepage_type_has_type()is replaced bypage_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 [email protected] # v6.12+Signed-off-by Gavin Shan <[email protected]>--- include/linux/page-flags.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 12 lines
include/linux/page-flags.h static inline bool page_mapcount_is_type(unsigned int mapcount) · line 952
Quoted 9 lines
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_mapcount_is_type(data_race(page->page_type) + 1);Probably we should just call
page_type_has_type()instead?
Quoted 1 line
Yes,
page_type_has_type()is better. It will be used in v2.
Feel free to add my
Signature · 3 lines
Cheers, David / dhildenb
PATCH 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 passed to page_mapcount_is_type() to be (page->__mapcount
+ 1).
--- 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 2/2] mm/debug: Fix parameter passed to page_mapcount_is_type()
Quoted 23 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.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 [email protected] # v6.12+Signed-off-by Gavin Shan <[email protected]>--- mm/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/debug.c +0
-0@@ -71,10 +71,10 @@ static void __dump_folio(struct folio *folio, struct page *page, unsigned long pfn, unsigned long idx) {
mm/debug.c static void __dump_folio(struct folio *folio, struct page *page, · line 80
Quoted 10 lines
mm/debug.c +2
-2struct 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 · 3 lines
Cheers, David / dhildenb
Quoted 3 lines · Gavin Shan
Found by code inspection. There are two places where the parameter passed to
page_mapcount_is_type()is (page->__mapcount), which is correct since it should be one more than the value, as explained in
^^^^^^^
s/correct/incorrect
Quoted 14 lines
the comments to
page_mapcount_is_type(): (a)page_has_type()inpage-flags.h(b)__dump_folio()inmm/debug.cPATCH[1] fixes the parameter for (a)
PATCH[2] fixes the parameter for (b)Gavin Shan (2):
mm: Fix parameter passed topage_mapcount_is_type()mm/debug: Fix parameter passed topage_mapcount_is_type()include/linux/page-flags.h | 2 +- mm/debug.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
Quoted 5 lines · Gavin Shan
Found by code inspection. There are two places where the parameter passed to
page_mapcount_is_type()is (page->__mapcount), which is correct since it should be one more than the value, as explained in the comments topage_mapcount_is_type(): (a)page_has_type()inpage-flags.h(b)__dump_folio()inmm/debug.c
IIUC you are right. Luckily thanks to the the PGTY_mapcount_underflow limit, this off-by-one error doesn't currently cause visible issues i.e. misclassifications legitimate mapcount as page type and vice versa, right? We'd have to have a mapcount underflown severely right to the limit to make that off-by-one error cross it?
I wonder if a more future-proof solution would be to redefine page_mapcount_is_type() instead to not subtract. But I'll leave that to willy.
Quoted 11 lines
PATCH[1] fixes the parameter for (a)
PATCH[2] fixes the parameter for (b)Gavin Shan (2):
mm: Fix parameter passed topage_mapcount_is_type()mm/debug: Fix parameter passed topage_mapcount_is_type()include/linux/page-flags.h | 2 +- mm/debug.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
Quoted 7 lines · Vlastimil Babka
Quoted 5 lines · Gavin Shan
Found by code inspection. There are two places where the parameter passed to
page_mapcount_is_type()is (page->__mapcount), which is correct since it should be one more than the value, as explained in the comments topage_mapcount_is_type(): (a)page_has_type()inpage-flags.h(b)__dump_folio()inmm/debug.c
Quoted 5 lines
IIUC you are right. Luckily thanks to the the
PGTY_mapcount_underflowlimit, this off-by-one error doesn't currently cause visible issues i.e. misclassifications legitimate mapcount as page type and vice versa, right? We'd have to have a mapcount underflown severely right to the limit to make that off-by-one error cross it?
Agreed. Likely not stable material because it isn't actually fixing anything (because of the safety gaps).
Quoted 3 lines
I wonder if a more future-proof solution would be to redefine
page_mapcount_is_type()instead to not subtract. But I'll leave that to willy.
With upcoming changes around that, likely best to leave that alone. I expect page_mapcount_is_type() to completely vanish.
Signature · 3 lines
Cheers, David / dhildenb
Quoted 8 lines · David Hildenbrand
Quoted 7 lines · Vlastimil Babka
Quoted 5 lines · Gavin Shan
Found by code inspection. There are two places where the parameter passed to
page_mapcount_is_type()is (page->__mapcount), which is correct since it should be one more than the value, as explained in the comments topage_mapcount_is_type(): (a)page_has_type()inpage-flags.h(b)__dump_folio()inmm/debug.c
Quoted 8 lines
Quoted 5 lines
IIUC you are right. Luckily thanks to the the
PGTY_mapcount_underflowlimit, this off-by-one error doesn't currently cause visible issues i.e. misclassifications legitimate mapcount as page type and vice versa, right? We'd have to have a mapcount underflown severely right to the limit to make that off-by-one error cross it?Agreed. Likely not stable material because it isn't actually fixing anything (because of the safety gaps).
Yes, it shouldn't cause any visible impacts so far due to the gap. I just found the issue by code inspection. Lets drop the fix tags in v2.
Quoted 6 lines
Quoted 3 lines
I wonder if a more future-proof solution would be to redefine
page_mapcount_is_type()instead to not subtract. But I'll leave that to willy.With upcoming changes around that, likely best to leave that alone. I expect
page_mapcount_is_type()to completely vanish.
+1 to remove page_mapcount_is_type(). After Willy confirms, I can post an extra series to do it if needed.
Thanks,
Gavin
Quoted 23 lines · Gavin Shan
Quoted 8 lines · David Hildenbrand
Quoted 7 lines · Vlastimil Babka
Quoted 5 lines · Gavin Shan
Found by code inspection. There are two places where the parameter passed to
page_mapcount_is_type()is (page->__mapcount), which is correct since it should be one more than the value, as explained in the comments topage_mapcount_is_type(): (a)page_has_type()inpage-flags.h(b)__dump_folio()inmm/debug.cQuoted 8 lines
Quoted 5 lines
IIUC you are right. Luckily thanks to the the
PGTY_mapcount_underflowlimit, this off-by-one error doesn't currently cause visible issues i.e. misclassifications legitimate mapcount as page type and vice versa, right? We'd have to have a mapcount underflown severely right to the limit to make that off-by-one error cross it?Agreed. Likely not stable material because it isn't actually fixing anything (because of the safety gaps).
Yes, it shouldn't cause any visible impacts so far due to the gap. I just found the issue by code inspection. Lets drop the fix tags in v2.
Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I wonder if a more future-proof solution would be to redefine
page_mapcount_is_type()instead to not subtract. But I'll leave that to willy.With upcoming changes around that, likely best to leave that alone. I expect
page_mapcount_is_type()to completely vanish.+1 to remove
page_mapcount_is_type(). After Willy confirms, I can post an extra series to do it if needed.
I think we should only do that one Willy splits struct folio off from, struct page, storing the type elsewhere. For now, we should likely just leave it as is.
Signature · 3 lines
Cheers, David / dhildenb
Quoted 15 lines · Gavin Shan
Quoted 14 lines · David Hildenbrand
Quoted 12 lines · Vlastimil Babka
Quoted 5 lines · Gavin Shan
Found by code inspection. There are two places where the parameter passed to
page_mapcount_is_type()is (page->__mapcount), which is correct since it should be one more than the value, as explained in the comments topage_mapcount_is_type(): (a)page_has_type()inpage-flags.h(b)__dump_folio()inmm/debug.cIIUC you are right. Luckily thanks to the the
PGTY_mapcount_underflowlimit, this off-by-one error doesn't currently cause visible issues i.e. misclassifications legitimate mapcount as page type and vice versa, right? We'd have to have a mapcount underflown severely right to the limit to make that off-by-one error cross it?
Quoted 4 lines
Quoted 2 lines
Agreed. Likely not stable material because it isn't actually fixing anything (because of the safety gaps).
Yes, it shouldn't cause any visible impacts so far due to the gap.
Thanks for confirming, please state that in the commit log/cover letter too.
Quoted 2 lines
I just found the issue by code inspection. Lets drop the fix tags in v2.
Fixes: tag is fine and correct, just Cc: stable is unnecessary. Thanks.
Quoted 13 lines
Quoted 6 lines
Quoted 3 lines
I wonder if a more future-proof solution would be to redefine
page_mapcount_is_type()instead to not subtract. But I'll leave that to willy.With upcoming changes around that, likely best to leave that alone. I expect
page_mapcount_is_type()to completely vanish.+1 to remove
page_mapcount_is_type(). After Willy confirms, I can post an extra series to do it if needed.Thanks,
Gavin
Quoted 16 lines · Vlastimil Babka
Quoted 15 lines · Gavin Shan
Quoted 14 lines · David Hildenbrand
Quoted 12 lines · Vlastimil Babka
Quoted 5 lines · Gavin Shan
Found by code inspection. There are two places where the parameter passed to
page_mapcount_is_type()is (page->__mapcount), which is correct since it should be one more than the value, as explained in the comments topage_mapcount_is_type(): (a)page_has_type()inpage-flags.h(b)__dump_folio()inmm/debug.cIIUC you are right. Luckily thanks to the the
PGTY_mapcount_underflowlimit, this off-by-one error doesn't currently cause visible issues i.e. misclassifications legitimate mapcount as page type and vice versa, right? We'd have to have a mapcount underflown severely right to the limit to make that off-by-one error cross it?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Agreed. Likely not stable material because it isn't actually fixing anything (because of the safety gaps).
Yes, it shouldn't cause any visible impacts so far due to the gap.
Thanks for confirming, please state that in the commit log/cover letter too.
Yes, the commit log and cover letter has been improved for this in v2.
Quoted 5 lines
Quoted 2 lines
I just found the issue by code inspection. Lets drop the fix tags in v2.
Fixes tag is fine and correct, just Cc: stable is unnecessary.
Thanks for the hints. The 'Cc: stable' tag has been dropped, but the 'Fixes:' tag is kept in v2, which was posted.
https://lore.kernel.org/linux-mm/[email protected]/T/#t
Quoted 10 lines
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
I wonder if a more future-proof solution would be to redefine
page_mapcount_is_type()instead to not subtract. But I'll leave that to willy.With upcoming changes around that, likely best to leave that alone. I expect
page_mapcount_is_type()to completely vanish.+1 to remove
page_mapcount_is_type(). After Willy confirms, I can post an extra series to do it if needed.
Thanks,
Gavin