Re: [PATCH 08/10] mm: update fork mm->flags initialisation to use bitmap

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Aug 26, 2025 at 04:28:20PM +0200, David Hildenbrand wrote:
> On 26.08.25 16:21, Lorenzo Stoakes wrote:
> > On Tue, Aug 26, 2025 at 03:12:08PM +0200, David Hildenbrand wrote:
> > > On 12.08.25 17:44, Lorenzo Stoakes wrote:
> > > > We now need to account for flag initialisation on fork. We retain the
> > > > existing logic as much as we can, but dub the existing flag mask legacy.
> > > >
> > > > These flags are therefore required to fit in the first 32-bits of the flags
> > > > field.
> > > >
> > > > However, further flag propagation upon fork can be implemented in mm_init()
> > > > on a per-flag basis.
> > > >
> > > > We ensure we clear the entire bitmap prior to setting it, and use
> > > > __mm_flags_get_word() and __mm_flags_set_word() to manipulate these legacy
> > > > fields efficiently.
> > > >
> > > > Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx>
> > > > ---
> > > >    include/linux/mm_types.h | 13 ++++++++++---
> > > >    kernel/fork.c            |  7 +++++--
> > > >    2 files changed, 15 insertions(+), 5 deletions(-)
> > > >
> > > > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> > > > index 38b3fa927997..25577ab39094 100644
> > > > --- a/include/linux/mm_types.h
> > > > +++ b/include/linux/mm_types.h
> > > > @@ -1820,16 +1820,23 @@ enum {
> > > >    #define MMF_TOPDOWN		31	/* mm searches top down by default */
> > > >    #define MMF_TOPDOWN_MASK	_BITUL(MMF_TOPDOWN)
> > > > -#define MMF_INIT_MASK		(MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK |\
> > > > +#define MMF_INIT_LEGACY_MASK	(MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK |\
> > > >    				 MMF_DISABLE_THP_MASK | MMF_HAS_MDWE_MASK |\
> > > >    				 MMF_VM_MERGE_ANY_MASK | MMF_TOPDOWN_MASK)
> > > > -static inline unsigned long mmf_init_flags(unsigned long flags)
> > > > +/* Legacy flags must fit within 32 bits. */
> > > > +static_assert((u64)MMF_INIT_LEGACY_MASK <= (u64)UINT_MAX);
> > >
> > > Why not use the magic number 32 you are mentioning in the comment? :)
> >
> > Meh I mean UINT_MAX works as a good 'any bit' mask and this will work on
> > both 32-bit and 64-bit systems.
> >
> > >
> > > static_assert((u32)MMF_INIT_LEGACY_MASK != MMF_INIT_LEGACY_MASK);
> >
> > On 32-bit that'd not work would it?
>
> On 32bit, BIT(32) would exceed the shift width of unsigned long -> undefined
> behavior.
>
> The compiler should naturally complain.

Yeah, I don't love that sorry. Firstly it's a warning, so you may well miss it
(I just tried), and secondly you're making the static assert not have any
meaning except that you expect to trigger a compiler warning, it's a bit
bizarre.

My solution works (unless you can see a reason it shouldn't) and I don't find
this approach any simpler.

>
> --
> Cheers
>
> David / dhildenb
>

Cheers, Lorenzo




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Kernel Development]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Info]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Linux Media]     [Device Mapper]

  Powered by Linux