[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e1f6654e016d36c43959764b01355736c5cbcdf8.1755012943.git.lorenzo.stoakes@oracle.com>
Date: Tue, 12 Aug 2025 16:44:19 +0100
From: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: Alexander Gordeev <agordeev@...ux.ibm.com>,
Gerald Schaefer <gerald.schaefer@...ux.ibm.com>,
Heiko Carstens <hca@...ux.ibm.com>, Vasily Gorbik <gor@...ux.ibm.com>,
Christian Borntraeger <borntraeger@...ux.ibm.com>,
Sven Schnelle <svens@...ux.ibm.com>,
"David S . Miller" <davem@...emloft.net>,
Andreas Larsson <andreas@...sler.com>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Andy Lutomirski <luto@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Thomas Gleixner <tglx@...utronix.de>, Ingo Molnar <mingo@...hat.com>,
Borislav Petkov <bp@...en8.de>, "H . Peter Anvin" <hpa@...or.com>,
Alexander Viro <viro@...iv.linux.org.uk>,
Christian Brauner <brauner@...nel.org>, Jan Kara <jack@...e.cz>,
Kees Cook <kees@...nel.org>, David Hildenbrand <david@...hat.com>,
Zi Yan <ziy@...dia.com>, Baolin Wang <baolin.wang@...ux.alibaba.com>,
"Liam R . Howlett" <Liam.Howlett@...cle.com>,
Nico Pache <npache@...hat.com>, Ryan Roberts <ryan.roberts@....com>,
Dev Jain <dev.jain@....com>, Barry Song <baohua@...nel.org>,
Xu Xin <xu.xin16@....com.cn>,
Chengming Zhou <chengming.zhou@...ux.dev>,
Vlastimil Babka <vbabka@...e.cz>, Mike Rapoport <rppt@...nel.org>,
Suren Baghdasaryan <surenb@...gle.com>, Michal Hocko <mhocko@...e.com>,
David Rientjes <rientjes@...gle.com>,
Shakeel Butt <shakeel.butt@...ux.dev>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>, Ian Rogers <irogers@...gle.com>,
Adrian Hunter <adrian.hunter@...el.com>,
Kan Liang <kan.liang@...ux.intel.com>,
Masami Hiramatsu <mhiramat@...nel.org>,
Oleg Nesterov <oleg@...hat.com>, Juri Lelli <juri.lelli@...hat.com>,
Vincent Guittot <vincent.guittot@...aro.org>,
Dietmar Eggemann <dietmar.eggemann@....com>,
Steven Rostedt <rostedt@...dmis.org>, Ben Segall <bsegall@...gle.com>,
Mel Gorman <mgorman@...e.de>, Valentin Schneider <vschneid@...hat.com>,
Jason Gunthorpe <jgg@...pe.ca>, John Hubbard <jhubbard@...dia.com>,
Peter Xu <peterx@...hat.com>, Jann Horn <jannh@...gle.com>,
Pedro Falcato <pfalcato@...e.de>, Matthew Wilcox <willy@...radead.org>,
Mateusz Guzik <mjguzik@...il.com>, linux-s390@...r.kernel.org,
linux-kernel@...r.kernel.org, sparclinux@...r.kernel.org,
linux-fsdevel@...r.kernel.org, linux-mm@...ck.org,
linux-trace-kernel@...r.kernel.org, linux-perf-users@...r.kernel.org
Subject: [PATCH 10/10] mm: replace mm->flags with bitmap entirely and set to 64 bits
Now we have updated all users of mm->flags to use the bitmap accessors,
repalce it with the bitmap version entirely.
We are then able to move to having 64 bits of mm->flags on both 32-bit and
64-bit architectures.
We also update the VMA userland tests to ensure that everything remains
functional there.
No functional changes intended, other than there now being 64 bits of
available mm_struct flags.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
---
include/linux/mm.h | 12 ++++++------
include/linux/mm_types.h | 14 +++++---------
include/linux/sched/coredump.h | 2 +-
tools/testing/vma/vma_internal.h | 19 +++++++++++++++++--
4 files changed, 29 insertions(+), 18 deletions(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 34311ebe62cc..b61e2d4858cf 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -724,32 +724,32 @@ static inline void assert_fault_locked(struct vm_fault *vmf)
static inline bool mm_flags_test(int flag, const struct mm_struct *mm)
{
- return test_bit(flag, ACCESS_PRIVATE(&mm->_flags, __mm_flags));
+ return test_bit(flag, ACCESS_PRIVATE(&mm->flags, __mm_flags));
}
static inline bool mm_flags_test_and_set(int flag, struct mm_struct *mm)
{
- return test_and_set_bit(flag, ACCESS_PRIVATE(&mm->_flags, __mm_flags));
+ return test_and_set_bit(flag, ACCESS_PRIVATE(&mm->flags, __mm_flags));
}
static inline bool mm_flags_test_and_clear(int flag, struct mm_struct *mm)
{
- return test_and_clear_bit(flag, ACCESS_PRIVATE(&mm->_flags, __mm_flags));
+ return test_and_clear_bit(flag, ACCESS_PRIVATE(&mm->flags, __mm_flags));
}
static inline void mm_flags_set(int flag, struct mm_struct *mm)
{
- set_bit(flag, ACCESS_PRIVATE(&mm->_flags, __mm_flags));
+ set_bit(flag, ACCESS_PRIVATE(&mm->flags, __mm_flags));
}
static inline void mm_flags_clear(int flag, struct mm_struct *mm)
{
- clear_bit(flag, ACCESS_PRIVATE(&mm->_flags, __mm_flags));
+ clear_bit(flag, ACCESS_PRIVATE(&mm->flags, __mm_flags));
}
static inline void mm_flags_clear_all(struct mm_struct *mm)
{
- bitmap_zero(ACCESS_PRIVATE(&mm->_flags, __mm_flags), NUM_MM_FLAG_BITS);
+ bitmap_zero(ACCESS_PRIVATE(&mm->flags, __mm_flags), NUM_MM_FLAG_BITS);
}
extern const struct vm_operations_struct vma_dummy_vm_ops;
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 25577ab39094..47d2e4598acd 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -932,7 +932,7 @@ struct mm_cid {
* Opaque type representing current mm_struct flag state. Must be accessed via
* mm_flags_xxx() helper functions.
*/
-#define NUM_MM_FLAG_BITS BITS_PER_LONG
+#define NUM_MM_FLAG_BITS (64)
typedef struct {
__private DECLARE_BITMAP(__mm_flags, NUM_MM_FLAG_BITS);
} mm_flags_t;
@@ -1119,11 +1119,7 @@ struct mm_struct {
/* Architecture-specific MM context */
mm_context_t context;
- /* Temporary union while we convert users to mm_flags_t. */
- union {
- unsigned long flags; /* Must use atomic bitops to access */
- mm_flags_t _flags; /* Must use mm_flags_* helpers to access */
- };
+ mm_flags_t flags; /* Must use mm_flags_* hlpers to access */
#ifdef CONFIG_AIO
spinlock_t ioctx_lock;
@@ -1236,7 +1232,7 @@ struct mm_struct {
/* Read the first system word of mm flags, non-atomically. */
static inline unsigned long __mm_flags_get_word(struct mm_struct *mm)
{
- unsigned long *bitmap = ACCESS_PRIVATE(&mm->_flags, __mm_flags);
+ unsigned long *bitmap = ACCESS_PRIVATE(&mm->flags, __mm_flags);
return bitmap_read(bitmap, 0, BITS_PER_LONG);
}
@@ -1245,7 +1241,7 @@ static inline unsigned long __mm_flags_get_word(struct mm_struct *mm)
static inline void __mm_flags_set_word(struct mm_struct *mm,
unsigned long value)
{
- unsigned long *bitmap = ACCESS_PRIVATE(&mm->_flags, __mm_flags);
+ unsigned long *bitmap = ACCESS_PRIVATE(&mm->flags, __mm_flags);
bitmap_copy(bitmap, &value, BITS_PER_LONG);
}
@@ -1253,7 +1249,7 @@ static inline void __mm_flags_set_word(struct mm_struct *mm,
/* Obtain a read-only view of the bitmap. */
static inline const unsigned long *__mm_flags_get_bitmap(const struct mm_struct *mm)
{
- return (const unsigned long *)ACCESS_PRIVATE(&mm->_flags, __mm_flags);
+ return (const unsigned long *)ACCESS_PRIVATE(&mm->flags, __mm_flags);
}
#define MM_MT_FLAGS (MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN | \
diff --git a/include/linux/sched/coredump.h b/include/linux/sched/coredump.h
index 19ecfcceb27a..079ae5a97480 100644
--- a/include/linux/sched/coredump.h
+++ b/include/linux/sched/coredump.h
@@ -20,7 +20,7 @@ static inline unsigned long __mm_flags_get_dumpable(struct mm_struct *mm)
static inline void __mm_flags_set_mask_dumpable(struct mm_struct *mm, int value)
{
- unsigned long *bitmap = ACCESS_PRIVATE(&mm->_flags, __mm_flags);
+ unsigned long *bitmap = ACCESS_PRIVATE(&mm->flags, __mm_flags);
set_mask_bits(bitmap, MMF_DUMPABLE_MASK, value);
}
diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_internal.h
index cb1c2a8afe26..f13354bf0a1e 100644
--- a/tools/testing/vma/vma_internal.h
+++ b/tools/testing/vma/vma_internal.h
@@ -249,6 +249,14 @@ struct mutex {};
#define DEFINE_MUTEX(mutexname) \
struct mutex mutexname = {}
+#define DECLARE_BITMAP(name, bits) \
+ unsigned long name[BITS_TO_LONGS(bits)]
+
+#define NUM_MM_FLAG_BITS (64)
+typedef struct {
+ __private DECLARE_BITMAP(__mm_flags, NUM_MM_FLAG_BITS);
+} mm_flags_t;
+
struct mm_struct {
struct maple_tree mm_mt;
int map_count; /* number of VMAs */
@@ -260,7 +268,7 @@ struct mm_struct {
unsigned long def_flags;
- unsigned long flags; /* Must use atomic bitops to access */
+ mm_flags_t flags; /* Must use mm_flags_* helpers to access */
};
struct vm_area_struct;
@@ -1333,6 +1341,13 @@ static inline void userfaultfd_unmap_complete(struct mm_struct *mm,
{
}
+# define ACCESS_PRIVATE(p, member) ((p)->member)
+
+static inline bool mm_flags_test(int flag, const struct mm_struct *mm)
+{
+ return test_bit(flag, ACCESS_PRIVATE(&mm->flags, __mm_flags));
+}
+
/*
* Denies creating a writable executable mapping or gaining executable permissions.
*
@@ -1363,7 +1378,7 @@ static inline void userfaultfd_unmap_complete(struct mm_struct *mm,
static inline bool map_deny_write_exec(unsigned long old, unsigned long new)
{
/* If MDWE is disabled, we have nothing to deny. */
- if (!test_bit(MMF_HAS_MDWE, ¤t->mm->flags))
+ if (mm_flags_test(MMF_HAS_MDWE, current->mm))
return false;
/* If the new VMA is not executable, we have nothing to deny. */
--
2.50.1
Powered by blists - more mailing lists