mm/rmap: add CONFIG_MM_ID guard for folio_test_large_maybe_mapped_shared()
Subsystems (2)
PATCH 1/1 mm/rmap: add CONFIG_MM_ID guard for folio_test_large_maybe_mapped_shared()
Add a compile-time check to make sure folio_test_large_maybe_mapped_shared() is only used with CONFIG_MM_ID enabled, as it directly accesses the _mm_ids field that only works under CONFIG_MM_ID.
--- include/linux/page-flags.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/page-flags.h +2 -0
@@ -1232,6 +1232,8 @@ static inline int folio_has_private(const struct folio *folio)static inline bool folio_test_large_maybe_mapped_shared (const struct folio *folio) { +/* This function should never be called without CONFIG_MM_ID enabled. */ +BUILD_BUG_ON (!IS_ENABLED (CONFIG_MM_ID ));return test_bit (FOLIO_MM_IDS_SHARED_BITNUM , &folio->_mm_ids); }#undef PF_ANY
Signature · 1 line
2.49.0
Quoted 6 lines · Lance Yang
Add a compile-time check to make sure
folio_test_large_maybe_mapped_shared()is only used withCONFIG_MM_IDenabled, as it directly accesses the_mm_idsfield that only works underCONFIG_MM_ID.Suggested-by David Hildenbrand <[email protected]>Signed-off-by Mingzhe Yang <[email protected]>
^ should that be here?
Quoted 10 lines
Signed-off-by Lance Yang <[email protected]>--- include/linux/page-flags.h | 2 ++ 1 file changed, 2 insertions(+)include/linux/page-flags.h +0
-0
include/linux/page-flags.h static inline int folio_has_private(const struct folio *folio) · line 1239
Quoted 8 lines
include/linux/page-flags.h +2
-0@@ -1232,6 +1232,8 @@ static inline int folio_has_private(const struct folio *folio)static inline bool folio_test_large_maybe_mapped_shared (const struct folio *folio) { +/* This function should never be called without CONFIG_MM_ID enabled. */ +BUILD_BUG_ON (!IS_ENABLED (CONFIG_MM_ID ));return test_bit (FOLIO_MM_IDS_SHARED_BITNUM , &folio->_mm_ids); }#undef PF_ANY
That should work. I can throw this into a cross-compile setup later if I get to it.
Signature · 3 lines
Cheers, David / dhildenb
Hi David,
Thanks for taking the time to review!
Quoted 10 lines · David Hildenbrand
Quoted 6 lines · Lance Yang
Add a compile-time check to make sure
folio_test_large_maybe_mapped_shared()is only used withCONFIG_MM_IDenabled, as it directly accesses the_mm_idsfield that only works underCONFIG_MM_ID.Suggested-by David Hildenbrand <[email protected]>Signed-off-by Mingzhe Yang <[email protected]>^ should that be here?
Yep, that's my email too ;p
Quoted 12 lines
Quoted 12 lines
Signed-off-by Lance Yang <[email protected]>--- include/linux/page-flags.h | 2 ++ 1 file changed, 2 insertions(+)include/linux/page-flags.h +0
-0@@ -1232,6 +1232,8 @@ static inline int folio_has_private(const struct folio *folio)
Quoted 11 lines
include/linux/page-flags.h static inline int folio_has_private(const struct folio *folio) · line 1239
Quoted 7 lines
include/linux/page-flags.h +2
-0static inline bool folio_test_large_maybe_mapped_shared (const struct folio *folio) { +/* This function should never be called without CONFIG_MM_ID enabled. */ +BUILD_BUG_ON (!IS_ENABLED (CONFIG_MM_ID ));return test_bit (FOLIO_MM_IDS_SHARED_BITNUM , &folio->_mm_ids); }#undef PF_ANYThat should work. I can throw this into a cross-compile setup later if I get to it.
Yeah, just built kernels with and without both CONFIG_MM_ID and CONFIG_TRANSPARENT_HUGEPAGE -- no issues either way ;p
Quoted 1 line
Thanks again for your time,
Lance
Quoted 6 lines
--
Cheers,David / dhildenb
Quoted 11 lines · Lance Yang
Hi David,
Thanks for taking the time to review!
Quoted 6 lines · David Hildenbrand
Quoted 4 lines · Lance Yang
Add a compile-time check to make sure
folio_test_large_maybe_mapped_shared()is only used withCONFIG_MM_IDenabled, as it directly accesses the_mm_idsfield that only works underCONFIG_MM_ID.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Suggested-by David Hildenbrand <[email protected]>Signed-off-by Mingzhe Yang <[email protected]>^ should that be here?
Yep, that's my email too ;p
Best to stick to only one here -- same individual :)
Signature · 3 lines
Cheers, David / dhildenb
Quoted 13 lines · David Hildenbrand
Quoted 11 lines · Lance Yang
Hi David,
Thanks for taking the time to review!
Quoted 6 lines · David Hildenbrand
Quoted 4 lines · Lance Yang
Add a compile-time check to make sure
folio_test_large_maybe_mapped_shared()is only used withCONFIG_MM_IDenabled, as it directly accesses the_mm_idsfield that only works underCONFIG_MM_ID.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Suggested-by David Hildenbrand <[email protected]>Signed-off-by Mingzhe Yang <[email protected]>^ should that be here?
Yep, that's my email too ;p
Best to stick to only one here -- same individual :)
Got it. I'll keep that in mind next time ;)
Thanks,
Lance
Quoted 6 lines
--
Cheers,David / dhildenb
Andrew Morton
maintainerQuoted 9 lines · On Thu, 17 Apr 2025 20:49:08 +0800 Lance Yang <[email protected]> wrote:
Add a compile-time check to make sure
folio_test_large_maybe_mapped_shared()is only used withCONFIG_MM_IDenabled, as it directly accesses the_mm_idsfield that only works underCONFIG_MM_ID....
include/linux/page-flags.h static inline int folio_has_private(const struct folio *folio) · line 1239
Quoted 8 lines
include/linux/page-flags.h +2
-0@@ -1232,6 +1232,8 @@ static inline int folio_has_private(const struct folio *folio)static inline bool folio_test_large_maybe_mapped_shared (const struct folio *folio) { +/* This function should never be called without CONFIG_MM_ID enabled. */ +BUILD_BUG_ON (!IS_ENABLED (CONFIG_MM_ID ));return test_bit (FOLIO_MM_IDS_SHARED_BITNUM , &folio->_mm_ids); }#undef PF_ANY
I don't get it. Sounds like we're adding a compile-time check to check for a compilation error which would have happened anyway.
If folio_test_large_maybe_mapped_shared() is only used with CONFIG_MM_ID enabled, then do
#ifdef CONFIG_MM_ID
static inline bool folio_test_large_maybe_mapped_shared(...) {
}
#endif
?
Or, as "_mm_ids field only works under CONFIG_MM_ID", make it not-even-present when !CONFIG_MM_ID?
include/linux/mm_types.h renamed from include/linux/mm_types.h~a +2 -0
@@ -438,7 +438,9 @@ struct folio {mm_id_mapcount_t _mm_id_mapcount[2 ];union {mm_id_t _mm_id[2 ]; +#ifdef CONFIG_MM_ID unsigned long _mm_ids; +#endif };/* private: the union with struct page is transitional */ };
_
or
include/linux/mm_types.h renamed from include/linux/mm_types.h~a +2 -0
@@ -436,10 +436,12 @@ struct folio {atomic_t _pincount;#endif /* CONFIG_64BIT */ mm_id_mapcount_t _mm_id_mapcount[2 ]; +#ifdef CONFIG_MM_ID union {mm_id_t _mm_id[2 ];unsigned long _mm_ids; }; +#endif /* private: the union with struct page is transitional */ };unsigned long _usable_1[4 ];
_
I dunno, it sounds like something hasn't been fully thought through here. It's hard to say because the changelog is unclear. Perhaps start out by fully describing what problem the patch is addressing?
Hi Andrew,
Thanks for taking the time to review!
Quoted 27 lines · Andrew Morton
Quoted 9 lines · On Thu, 17 Apr 2025 20:49:08 +0800 Lance Yang <[email protected]> wrote:
Add a compile-time check to make sure
folio_test_large_maybe_mapped_shared()is only used withCONFIG_MM_IDenabled, as it directly accesses the_mm_idsfield that only works underCONFIG_MM_ID....
include/linux/page-flags.h static inline int folio_has_private(const struct folio *folio) · line 1239
Quoted 8 lines
include/linux/page-flags.h +2
-0@@ -1232,6 +1232,8 @@ static inline int folio_has_private(const struct folio *folio)static inline bool folio_test_large_maybe_mapped_shared (const struct folio *folio) { +/* This function should never be called without CONFIG_MM_ID enabled. */ +BUILD_BUG_ON (!IS_ENABLED (CONFIG_MM_ID ));return test_bit (FOLIO_MM_IDS_SHARED_BITNUM , &folio->_mm_ids); }#undef PF_ANYI don't get it. Sounds like we're adding a compile-time check to check for a compilation error which would have happened anyway.
If
folio_test_large_maybe_mapped_shared()is only used withCONFIG_MM_IDenabled, then do
Quoted 7 lines
#ifdef
CONFIG_MM_ID
static inline boolfolio_test_large_maybe_mapped_shared(...){
}
#endif?
Hmm... we considered using '#ifdef CONFIG_MM_ID' for folio_test_large_maybe_mapped_shared(),
but since this function should never be called without CONFIG_MM_ID enabled, compile-time errors might be the way to go -- and a compile-time check here does the trick ;)
Quoted 39 lines
Or, as "
_mm_idsfield only works underCONFIG_MM_ID", make it not-even-present when !CONFIG_MM_ID?include/linux/mm_types.h renamed from include/linux/mm_types.h~a +2
-0@@ -438,7 +438,9 @@ struct folio {mm_id_mapcount_t _mm_id_mapcount[2 ];union {mm_id_t _mm_id[2 ]; +#ifdef CONFIG_MM_ID unsigned long _mm_ids; +#endif };/* private: the union with struct page is transitional */ };_
or
include/linux/mm_types.h renamed from include/linux/mm_types.h~a +2
-0@@ -436,10 +436,12 @@ struct folio {atomic_t _pincount;#endif /* CONFIG_64BIT */ mm_id_mapcount_t _mm_id_mapcount[2 ]; +#ifdef CONFIG_MM_ID union {mm_id_t _mm_id[2 ];unsigned long _mm_ids; }; +#endif /* private: the union with struct page is transitional */ };unsigned long _usable_1[4 ];_
Quoted 4 lines
I dunno, it sounds like something hasn't been fully thought through here. It's hard to say because the changelog is unclear. Perhaps start out by fully describing what problem the patch is addressing?
In patch #14[1], we rely on IS_ENABLED(CONFIG_MM_ID), so we need:
1) Some dummy functions
2) The _mm_ids field to remain present even when !CONFIG_MM_ID
This patch is intended to ensure that incorrect calls to folio_test_large_maybe_mapped_shared()
are caught at compile-time.
[1] https://lore.kernel.org/linux-mm/[email protected]/
Thanks,
Lance
Quoted 38 lines · Lance Yang
Hi Andrew,
Thanks for taking the time to review!
Quoted 33 lines · Andrew Morton
Quoted 9 lines · On Thu, 17 Apr 2025 20:49:08 +0800 Lance Yang <[email protected]> wrote:
Add a compile-time check to make sure
folio_test_large_maybe_mapped_shared()is only used withCONFIG_MM_IDenabled, as it directly accesses the_mm_idsfield that only works underCONFIG_MM_ID....
include/linux/page-flags.h static inline int folio_has_private(const struct folio *folio) · line 1239
Quoted 8 lines
include/linux/page-flags.h +2
-0@@ -1232,6 +1232,8 @@ static inline int folio_has_private(const struct folio *folio)static inline bool folio_test_large_maybe_mapped_shared (const struct folio *folio) { +/* This function should never be called without CONFIG_MM_ID enabled. */ +BUILD_BUG_ON (!IS_ENABLED (CONFIG_MM_ID ));return test_bit (FOLIO_MM_IDS_SHARED_BITNUM , &folio->_mm_ids); }#undef PF_ANYI don't get it. Sounds like we're adding a compile-time check to check for a compilation error which would have happened anyway.
If
folio_test_large_maybe_mapped_shared()is only used withCONFIG_MM_IDenabled, then do#ifdef
CONFIG_MM_ID
static inline boolfolio_test_large_maybe_mapped_shared(...){
}
#endif
Quoted 7 lines
Quoted 1 line
?
Hmm... we considered using '#ifdef
CONFIG_MM_ID' forfolio_test_large_maybe_mapped_shared(),
but since this function should never be called withoutCONFIG_MM_IDenabled, compile-time errors might be the way to go -- and a compile-time check here does the trick ;)
Yeah, I deliberately used plenty of IS_ENABLED to avoid a #ifdef mess all over the place.
Maybe clarify in the patch description that we want to prevent the function from getting used without CONFIG_MM_ID, and we don't want to use #ifdef because then we'd have to add even more #ifdef in callers that use IS_ENABLED(CONFIG_MM_ID).
Signature · 3 lines
Cheers, David / dhildenb
Quoted 48 lines · David Hildenbrand
Quoted 38 lines · Lance Yang
Hi Andrew,
Thanks for taking the time to review!
Quoted 33 lines · Andrew Morton
Quoted 9 lines · On Thu, 17 Apr 2025 20:49:08 +0800 Lance Yang <[email protected]> wrote:
Add a compile-time check to make sure
folio_test_large_maybe_mapped_shared()is only used withCONFIG_MM_IDenabled, as it directly accesses the_mm_idsfield that only works underCONFIG_MM_ID....
include/linux/page-flags.h static inline int folio_has_private(const struct folio *folio) · line 1239
Quoted 8 lines
include/linux/page-flags.h +2
-0@@ -1232,6 +1232,8 @@ static inline int folio_has_private(const struct folio *folio)static inline bool folio_test_large_maybe_mapped_shared (const struct folio *folio) { +/* This function should never be called without CONFIG_MM_ID enabled. */ +BUILD_BUG_ON (!IS_ENABLED (CONFIG_MM_ID ));return test_bit (FOLIO_MM_IDS_SHARED_BITNUM , &folio->_mm_ids); }#undef PF_ANYI don't get it. Sounds like we're adding a compile-time check to check for a compilation error which would have happened anyway.
If
folio_test_large_maybe_mapped_shared()is only used withCONFIG_MM_IDenabled, then do#ifdef
CONFIG_MM_ID
static inline boolfolio_test_large_maybe_mapped_shared(...){
}
#endifQuoted 7 lines
Quoted 1 line
?
Hmm... we considered using '#ifdef
CONFIG_MM_ID' forfolio_test_large_maybe_mapped_shared(),
but since this function should never be called withoutCONFIG_MM_IDenabled, compile-time errors might be the way to go -- and a compile-time check here does the trick ;)
Quoted 7 lines
Yeah, I deliberately used plenty of
IS_ENABLEDto avoid a #ifdef mess all over the place.Maybe clarify in the patch description that we want to prevent the function from getting used without
CONFIG_MM_ID, and we don't want to use #ifdef because then we'd have to add even more #ifdef in callers that useIS_ENABLED(CONFIG_MM_ID).
Agreed, the patch description could be clearer. I'll update it to better explain what it does and why we are avoiding #ifdef ;)
Thanks for your suggestion,
Lance
Quoted 6 lines
--
Cheers,David / dhildenb