[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAK1f24kchcoN4ToW5aPbSA7KDB6ZPtQin2s6wOPQZLTkNzjNow@mail.gmail.com>
Date: Fri, 18 Apr 2025 19:40:05 +0800
From: Lance Yang <ioworker0@...il.com>
To: David Hildenbrand <david@...hat.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, Mingzhe Yang <mingzhe.yang@...com>
Subject: Re: [PATCH 1/1] mm/rmap: add CONFIG_MM_ID guard for folio_test_large_maybe_mapped_shared()
On Fri, Apr 18, 2025 at 6:38 PM David Hildenbrand <david@...hat.com> wrote:
>
> On 18.04.25 09:26, Lance Yang wrote:
> > Hi Andrew,
> >
> > Thanks for taking the time to review!
> >
> > On Fri, Apr 18, 2025 at 6:02 AM Andrew Morton <akpm@...ux-foundation.org> wrote:
> >>
> >> On Thu, 17 Apr 2025 20:49:08 +0800 Lance Yang <ioworker0@...il.com> wrote:
> >>
> >>> 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.
> >>>
> >>> ...
> >>>
> >>> --- a/include/linux/page-flags.h
> >>> +++ b/include/linux/page-flags.h
> >>> @@ -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
> >>
> >> ?
> >
> > 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 ;)
>
> 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).
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
>
> --
> Cheers,
>
> David / dhildenb
>
Powered by blists - more mailing lists