sparclinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/10] mm: make mm->flags a bitmap and 64-bit on all arches
@ 2025-08-12 15:44 Lorenzo Stoakes
  2025-08-12 15:44 ` [PATCH 01/10] mm: add bitmap mm->flags field Lorenzo Stoakes
                   ` (10 more replies)
  0 siblings, 11 replies; 63+ messages in thread
From: Lorenzo Stoakes @ 2025-08-12 15:44 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Alexander Gordeev, Gerald Schaefer, Heiko Carstens, Vasily Gorbik,
	Christian Borntraeger, Sven Schnelle, David S . Miller,
	Andreas Larsson, Dave Hansen, Andy Lutomirski, Peter Zijlstra,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, H . Peter Anvin,
	Alexander Viro, Christian Brauner, Jan Kara, Kees Cook,
	David Hildenbrand, Zi Yan, Baolin Wang, Liam R . Howlett,
	Nico Pache, Ryan Roberts, Dev Jain, Barry Song, Xu Xin,
	Chengming Zhou, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, David Rientjes, Shakeel Butt,
	Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
	Kan Liang, Masami Hiramatsu, Oleg Nesterov, Juri Lelli,
	Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
	Mel Gorman, Valentin Schneider, Jason Gunthorpe, John Hubbard,
	Peter Xu, Jann Horn, Pedro Falcato, Matthew Wilcox, Mateusz Guzik,
	linux-s390, linux-kernel, sparclinux, linux-fsdevel, linux-mm,
	linux-trace-kernel, linux-perf-users

We are currently in the bizarre situation where we are constrained on the
number of flags we can set in an mm_struct based on whether this is a
32-bit or 64-bit kernel.

This is because mm->flags is an unsigned long field, which is 32-bits on a
32-bit system and 64-bits on a 64-bit system.

In order to keep things functional across both architectures, we do not
permit mm flag bits to be set above flag 31 (i.e. the 32nd bit).

This is a silly situation, especially given how profligate we are in
storing metadata in mm_struct, so let's convert mm->flags into a bitmap and
allow ourselves as many bits as we like.

In order to execute this change, we introduce a new opaque type -
mm_flags_t - which wraps a bitmap.

We go further and mark the bitmap field __private, which forces users to
have to use accessors, which allows us to enforce atomicity rules around
mm->flags (except on those occasions they are not required - fork, etc.)
and makes it far easier to keep track of how mm flags are being utilised.

In order to implement this change sensibly and an an iterative way, we
start by introducing the type with the same bitsize as the current mm flags
(system word size) and place it in union with mm->flags.

We are then able to gradually update users as we go without being forced to
do everything in a single patch.

In the course of working on this series I noticed the MMF_* flag masks
encounter a sign extension bug that, due to the 32-bit limit on mm->flags
thus far, has not caused any issues in practice, but required fixing for
this series.

We must make special dispensation for two cases - coredump and
initailisation on fork, but of which use masks extensively.

Since coredump flags are set in stone, we can safely assume they will
remain in the first 32-bits of the flags. We therefore provide special
non-atomic accessors for this case that access the first system word of
flags, keeping everything there essentially the same.

For mm->flags initialisation on fork, we adjust the logic to ensure all
bits are cleared correctly, and then adjust the existing intialisation
logic, dubbing the implementation utilising flags as legacy.

This means we get the same fast operations as we do now, but in future we
can also choose to update the forking logic to additionally propagate flags
beyond 32-bits across fork.

With this change in place we can, in future, decide to have as many bits as
we please.

Since the size of the bitmap will scale in system word multiples, there
should be no issues with changes in alignment in mm_struct. Additionally,
the really sensitive field (mmap_lock) is located prior to the flags field
so this should have no impact on that either.

Lorenzo Stoakes (10):
  mm: add bitmap mm->flags field
  mm: convert core mm to mm_flags_*() accessors
  mm: convert prctl to mm_flags_*() accessors
  mm: convert arch-specific code to mm_flags_*() accessors
  mm: convert uprobes to mm_flags_*() accessors
  mm: update coredump logic to correctly use bitmap mm flags
  mm: correct sign-extension issue in MMF_* flag masks
  mm: update fork mm->flags initialisation to use bitmap
  mm: convert remaining users to mm_flags_*() accessors
  mm: replace mm->flags with bitmap entirely and set to 64 bits

 arch/s390/mm/mmap.c              |  4 +-
 arch/sparc/kernel/sys_sparc_64.c |  4 +-
 arch/x86/mm/mmap.c               |  4 +-
 fs/coredump.c                    |  4 +-
 fs/exec.c                        |  2 +-
 fs/pidfs.c                       |  7 +++-
 fs/proc/array.c                  |  2 +-
 fs/proc/base.c                   | 12 +++---
 fs/proc/task_mmu.c               |  2 +-
 include/linux/huge_mm.h          |  2 +-
 include/linux/khugepaged.h       |  6 ++-
 include/linux/ksm.h              |  6 +--
 include/linux/mm.h               | 34 +++++++++++++++-
 include/linux/mm_types.h         | 67 +++++++++++++++++++++++++-------
 include/linux/mman.h             |  2 +-
 include/linux/oom.h              |  2 +-
 include/linux/sched/coredump.h   | 21 +++++++++-
 kernel/events/uprobes.c          | 32 +++++++--------
 kernel/fork.c                    |  9 +++--
 kernel/sys.c                     | 16 ++++----
 mm/debug.c                       |  4 +-
 mm/gup.c                         | 10 ++---
 mm/huge_memory.c                 |  8 ++--
 mm/khugepaged.c                  | 10 ++---
 mm/ksm.c                         | 32 +++++++--------
 mm/mmap.c                        |  8 ++--
 mm/oom_kill.c                    | 26 ++++++-------
 mm/util.c                        |  6 +--
 tools/testing/vma/vma_internal.h | 19 ++++++++-
 29 files changed, 239 insertions(+), 122 deletions(-)

--
2.50.1

^ permalink raw reply	[flat|nested] 63+ messages in thread

end of thread, other threads:[~2025-08-26 16:27 UTC | newest]

Thread overview: 63+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-12 15:44 [PATCH 00/10] mm: make mm->flags a bitmap and 64-bit on all arches Lorenzo Stoakes
2025-08-12 15:44 ` [PATCH 01/10] mm: add bitmap mm->flags field Lorenzo Stoakes
2025-08-12 16:20   ` Liam R. Howlett
2025-08-13 19:53   ` Lorenzo Stoakes
2025-08-26 12:48   ` David Hildenbrand
2025-08-12 15:44 ` [PATCH 02/10] mm: convert core mm to mm_flags_*() accessors Lorenzo Stoakes
2025-08-12 16:32   ` Liam R. Howlett
2025-08-12 22:52   ` Andrew Morton
2025-08-13  4:11     ` Lorenzo Stoakes
2025-08-14  8:27   ` Mike Rapoport
2025-08-15  6:07   ` Baolin Wang
2025-08-26 12:50   ` David Hildenbrand
2025-08-26 12:58     ` Lorenzo Stoakes
2025-08-12 15:44 ` [PATCH 03/10] mm: convert prctl " Lorenzo Stoakes
2025-08-12 16:34   ` Liam R. Howlett
2025-08-14  8:29   ` Mike Rapoport
2025-08-26 12:50   ` David Hildenbrand
2025-08-12 15:44 ` [PATCH 04/10] mm: convert arch-specific code " Lorenzo Stoakes
2025-08-12 17:19   ` Liam R. Howlett
2025-08-13 14:10   ` Lorenzo Stoakes
2025-08-14  8:30   ` Mike Rapoport
2025-08-26 12:51   ` David Hildenbrand
2025-08-12 15:44 ` [PATCH 05/10] mm: convert uprobes " Lorenzo Stoakes
2025-08-12 17:24   ` Liam R. Howlett
2025-08-14  8:33   ` Mike Rapoport
2025-08-26 12:51   ` David Hildenbrand
2025-08-12 15:44 ` [PATCH 06/10] mm: update coredump logic to correctly use bitmap mm flags Lorenzo Stoakes
2025-08-12 17:26   ` Liam R. Howlett
2025-08-14  8:37   ` Mike Rapoport
2025-08-15 13:52   ` Christian Brauner
2025-08-15 14:12     ` Lorenzo Stoakes
2025-08-26 11:33   ` Lorenzo Stoakes
2025-08-26 12:52   ` David Hildenbrand
2025-08-12 15:44 ` [PATCH 07/10] mm: correct sign-extension issue in MMF_* flag masks Lorenzo Stoakes
2025-08-12 17:30   ` Liam R. Howlett
2025-08-14  8:38   ` Mike Rapoport
2025-08-26 13:05   ` David Hildenbrand
2025-08-26 13:59     ` Lorenzo Stoakes
2025-08-26 14:08   ` Lorenzo Stoakes
2025-08-12 15:44 ` [PATCH 08/10] mm: update fork mm->flags initialisation to use bitmap Lorenzo Stoakes
2025-08-12 17:31   ` Liam R. Howlett
2025-08-14  8:39   ` Mike Rapoport
2025-08-26 13:12   ` David Hildenbrand
2025-08-26 14:21     ` Lorenzo Stoakes
2025-08-26 14:28       ` David Hildenbrand
2025-08-26 14:32         ` Lorenzo Stoakes
2025-08-26 15:24           ` David Hildenbrand
2025-08-26 15:39             ` Lorenzo Stoakes
2025-08-26 15:53               ` David Hildenbrand
2025-08-26 16:26                 ` Lorenzo Stoakes
2025-08-12 15:44 ` [PATCH 09/10] mm: convert remaining users to mm_flags_*() accessors Lorenzo Stoakes
2025-08-12 17:32   ` Liam R. Howlett
2025-08-14  8:42   ` Mike Rapoport
2025-08-26 13:13   ` David Hildenbrand
2025-08-12 15:44 ` [PATCH 10/10] mm: replace mm->flags with bitmap entirely and set to 64 bits Lorenzo Stoakes
2025-08-12 17:35   ` Liam R. Howlett
2025-08-12 17:43     ` Lorenzo Stoakes
2025-08-14  8:43   ` Mike Rapoport
2025-08-26 13:14   ` David Hildenbrand
2025-08-26 13:22     ` Lorenzo Stoakes
2025-08-12 20:13 ` [PATCH 00/10] mm: make mm->flags a bitmap and 64-bit on all arches SeongJae Park
2025-08-13  4:18   ` Lorenzo Stoakes
2025-08-13 16:24     ` SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).