Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.

Link: https://lkml.kernel.org/r/e1f6654e016d36c43959764b01355736c5cbcdf8.1755012943.git.lorenzo.stoakes@oracle.com
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Ben Segall <bsegall@google.com>
Cc: Borislav Betkov <bp@alien8.de>
Cc: Chengming Zhou <chengming.zhou@linux.dev>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jann Horn <jannh@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Marc Rutland <mark.rutland@arm.com>
Cc: Mariano Pache <npache@redhat.com>
Cc: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mel Gorman <mgorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Namhyung kim <namhyung@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Thomas Gleinxer <tglx@linutronix.de>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: xu xin <xu.xin16@zte.com.cn>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes and committed by
Andrew Morton
8166353f d14d3f53

+28 -17
+6 -6
include/linux/mm.h
··· 724 724 725 725 static inline bool mm_flags_test(int flag, const struct mm_struct *mm) 726 726 { 727 - return test_bit(flag, ACCESS_PRIVATE(&mm->_flags, __mm_flags)); 727 + return test_bit(flag, ACCESS_PRIVATE(&mm->flags, __mm_flags)); 728 728 } 729 729 730 730 static inline bool mm_flags_test_and_set(int flag, struct mm_struct *mm) 731 731 { 732 - return test_and_set_bit(flag, ACCESS_PRIVATE(&mm->_flags, __mm_flags)); 732 + return test_and_set_bit(flag, ACCESS_PRIVATE(&mm->flags, __mm_flags)); 733 733 } 734 734 735 735 static inline bool mm_flags_test_and_clear(int flag, struct mm_struct *mm) 736 736 { 737 - return test_and_clear_bit(flag, ACCESS_PRIVATE(&mm->_flags, __mm_flags)); 737 + return test_and_clear_bit(flag, ACCESS_PRIVATE(&mm->flags, __mm_flags)); 738 738 } 739 739 740 740 static inline void mm_flags_set(int flag, struct mm_struct *mm) 741 741 { 742 - set_bit(flag, ACCESS_PRIVATE(&mm->_flags, __mm_flags)); 742 + set_bit(flag, ACCESS_PRIVATE(&mm->flags, __mm_flags)); 743 743 } 744 744 745 745 static inline void mm_flags_clear(int flag, struct mm_struct *mm) 746 746 { 747 - clear_bit(flag, ACCESS_PRIVATE(&mm->_flags, __mm_flags)); 747 + clear_bit(flag, ACCESS_PRIVATE(&mm->flags, __mm_flags)); 748 748 } 749 749 750 750 static inline void mm_flags_clear_all(struct mm_struct *mm) 751 751 { 752 - bitmap_zero(ACCESS_PRIVATE(&mm->_flags, __mm_flags), NUM_MM_FLAG_BITS); 752 + bitmap_zero(ACCESS_PRIVATE(&mm->flags, __mm_flags), NUM_MM_FLAG_BITS); 753 753 } 754 754 755 755 extern const struct vm_operations_struct vma_dummy_vm_ops;
+5 -9
include/linux/mm_types.h
··· 932 932 * Opaque type representing current mm_struct flag state. Must be accessed via 933 933 * mm_flags_xxx() helper functions. 934 934 */ 935 - #define NUM_MM_FLAG_BITS BITS_PER_LONG 935 + #define NUM_MM_FLAG_BITS (64) 936 936 typedef struct { 937 937 DECLARE_BITMAP(__mm_flags, NUM_MM_FLAG_BITS); 938 938 } __private mm_flags_t; ··· 1119 1119 /* Architecture-specific MM context */ 1120 1120 mm_context_t context; 1121 1121 1122 - /* Temporary union while we convert users to mm_flags_t. */ 1123 - union { 1124 - unsigned long flags; /* Must use atomic bitops to access */ 1125 - mm_flags_t _flags; /* Must use mm_flags_* helpers to access */ 1126 - }; 1122 + mm_flags_t flags; /* Must use mm_flags_* hlpers to access */ 1127 1123 1128 1124 #ifdef CONFIG_AIO 1129 1125 spinlock_t ioctx_lock; ··· 1232 1236 /* Set the first system word of mm flags, non-atomically. */ 1233 1237 static inline void __mm_flags_set_word(struct mm_struct *mm, unsigned long value) 1234 1238 { 1235 - unsigned long *bitmap = ACCESS_PRIVATE(&mm->_flags, __mm_flags); 1239 + unsigned long *bitmap = ACCESS_PRIVATE(&mm->flags, __mm_flags); 1236 1240 1237 1241 bitmap_copy(bitmap, &value, BITS_PER_LONG); 1238 1242 } ··· 1240 1244 /* Obtain a read-only view of the bitmap. */ 1241 1245 static inline const unsigned long *__mm_flags_get_bitmap(const struct mm_struct *mm) 1242 1246 { 1243 - return (const unsigned long *)ACCESS_PRIVATE(&mm->_flags, __mm_flags); 1247 + return (const unsigned long *)ACCESS_PRIVATE(&mm->flags, __mm_flags); 1244 1248 } 1245 1249 1246 1250 /* Read the first system word of mm flags, non-atomically. */ ··· 1258 1262 static inline void __mm_flags_set_mask_bits_word(struct mm_struct *mm, 1259 1263 unsigned long mask, unsigned long bits) 1260 1264 { 1261 - unsigned long *bitmap = ACCESS_PRIVATE(&mm->_flags, __mm_flags); 1265 + unsigned long *bitmap = ACCESS_PRIVATE(&mm->flags, __mm_flags); 1262 1266 1263 1267 set_mask_bits(bitmap, mask, bits); 1264 1268 }
+17 -2
tools/testing/vma/vma_internal.h
··· 249 249 #define DEFINE_MUTEX(mutexname) \ 250 250 struct mutex mutexname = {} 251 251 252 + #define DECLARE_BITMAP(name, bits) \ 253 + unsigned long name[BITS_TO_LONGS(bits)] 254 + 255 + #define NUM_MM_FLAG_BITS (64) 256 + typedef struct { 257 + __private DECLARE_BITMAP(__mm_flags, NUM_MM_FLAG_BITS); 258 + } mm_flags_t; 259 + 252 260 struct mm_struct { 253 261 struct maple_tree mm_mt; 254 262 int map_count; /* number of VMAs */ ··· 268 260 269 261 unsigned long def_flags; 270 262 271 - unsigned long flags; /* Must use atomic bitops to access */ 263 + mm_flags_t flags; /* Must use mm_flags_* helpers to access */ 272 264 }; 273 265 274 266 struct vm_area_struct; ··· 1341 1333 { 1342 1334 } 1343 1335 1336 + # define ACCESS_PRIVATE(p, member) ((p)->member) 1337 + 1338 + static inline bool mm_flags_test(int flag, const struct mm_struct *mm) 1339 + { 1340 + return test_bit(flag, ACCESS_PRIVATE(&mm->flags, __mm_flags)); 1341 + } 1342 + 1344 1343 /* 1345 1344 * Denies creating a writable executable mapping or gaining executable permissions. 1346 1345 * ··· 1378 1363 static inline bool map_deny_write_exec(unsigned long old, unsigned long new) 1379 1364 { 1380 1365 /* If MDWE is disabled, we have nothing to deny. */ 1381 - if (!test_bit(MMF_HAS_MDWE, &current->mm->flags)) 1366 + if (mm_flags_test(MMF_HAS_MDWE, current->mm)) 1382 1367 return false; 1383 1368 1384 1369 /* If the new VMA is not executable, we have nothing to deny. */