2020#include <linux/seqlock.h>
2121#include <linux/percpu_counter.h>
2222#include <linux/types.h>
23+ #include <linux/rseq_types.h>
2324#include <linux/bitmap.h>
2425
2526#include <asm/mmu.h>
@@ -922,10 +923,6 @@ struct vm_area_struct {
922923#define vma_policy (vma ) NULL
923924#endif
924925
925- struct mm_cid {
926- unsigned int cid ;
927- };
928-
929926/*
930927 * Opaque type representing current mm_struct flag state. Must be accessed via
931928 * mm_flags_xxx() helper functions.
@@ -987,30 +984,9 @@ struct mm_struct {
987984 */
988985 atomic_t mm_users ;
989986
990- #ifdef CONFIG_SCHED_MM_CID
991- /**
992- * @pcpu_cid: Per-cpu current cid.
993- *
994- * Keep track of the currently allocated mm_cid for each cpu.
995- * The per-cpu mm_cid values are serialized by their respective
996- * runqueue locks.
997- */
998- struct mm_cid __percpu * pcpu_cid ;
999- /**
1000- * @nr_cpus_allowed: Number of CPUs allowed for mm.
1001- *
1002- * Number of CPUs allowed in the union of all mm's
1003- * threads allowed CPUs.
1004- */
1005- unsigned int nr_cpus_allowed ;
1006- /**
1007- * @cpus_allowed_lock: Lock protecting mm cpus_allowed.
1008- *
1009- * Provide mutual exclusion for mm cpus_allowed and
1010- * mm nr_cpus_allowed updates.
1011- */
1012- raw_spinlock_t cpus_allowed_lock ;
1013- #endif
987+ /* MM CID related storage */
988+ struct mm_mm_cid mm_cid ;
989+
1014990#ifdef CONFIG_MMU
1015991 atomic_long_t pgtables_bytes ; /* size of all page tables */
1016992#endif
@@ -1352,9 +1328,6 @@ static inline void vma_iter_init(struct vma_iterator *vmi,
13521328}
13531329
13541330#ifdef CONFIG_SCHED_MM_CID
1355-
1356- #define MM_CID_UNSET (~0U)
1357-
13581331/*
13591332 * mm_cpus_allowed: Union of all mm's threads allowed CPUs.
13601333 */
@@ -1383,20 +1356,20 @@ static inline void mm_init_cid(struct mm_struct *mm, struct task_struct *p)
13831356 int i ;
13841357
13851358 for_each_possible_cpu (i ) {
1386- struct mm_cid * pcpu_cid = per_cpu_ptr (mm -> pcpu_cid , i );
1359+ struct mm_cid_pcpu * pcpu = per_cpu_ptr (mm -> mm_cid . pcpu , i );
13871360
1388- pcpu_cid -> cid = MM_CID_UNSET ;
1361+ pcpu -> cid = MM_CID_UNSET ;
13891362 }
1390- mm -> nr_cpus_allowed = p -> nr_cpus_allowed ;
1391- raw_spin_lock_init (& mm -> cpus_allowed_lock );
1363+ mm -> mm_cid . nr_cpus_allowed = p -> nr_cpus_allowed ;
1364+ raw_spin_lock_init (& mm -> mm_cid . lock );
13921365 cpumask_copy (mm_cpus_allowed (mm ), & p -> cpus_mask );
13931366 cpumask_clear (mm_cidmask (mm ));
13941367}
13951368
13961369static inline int mm_alloc_cid_noprof (struct mm_struct * mm , struct task_struct * p )
13971370{
1398- mm -> pcpu_cid = alloc_percpu_noprof (struct mm_cid );
1399- if (!mm -> pcpu_cid )
1371+ mm -> mm_cid . pcpu = alloc_percpu_noprof (struct mm_cid_pcpu );
1372+ if (!mm -> mm_cid . pcpu )
14001373 return - ENOMEM ;
14011374 mm_init_cid (mm , p );
14021375 return 0 ;
@@ -1405,8 +1378,8 @@ static inline int mm_alloc_cid_noprof(struct mm_struct *mm, struct task_struct *
14051378
14061379static inline void mm_destroy_cid (struct mm_struct * mm )
14071380{
1408- free_percpu (mm -> pcpu_cid );
1409- mm -> pcpu_cid = NULL ;
1381+ free_percpu (mm -> mm_cid . pcpu );
1382+ mm -> mm_cid . pcpu = NULL ;
14101383}
14111384
14121385static inline unsigned int mm_cid_size (void )
@@ -1421,10 +1394,9 @@ static inline void mm_set_cpus_allowed(struct mm_struct *mm, const struct cpumas
14211394 if (!mm )
14221395 return ;
14231396 /* The mm_cpus_allowed is the union of each thread allowed CPUs masks. */
1424- raw_spin_lock ( & mm -> cpus_allowed_lock );
1397+ guard ( raw_spinlock )( & mm -> mm_cid . lock );
14251398 cpumask_or (mm_allowed , mm_allowed , cpumask );
1426- WRITE_ONCE (mm -> nr_cpus_allowed , cpumask_weight (mm_allowed ));
1427- raw_spin_unlock (& mm -> cpus_allowed_lock );
1399+ WRITE_ONCE (mm -> mm_cid .nr_cpus_allowed , cpumask_weight (mm_allowed ));
14281400}
14291401#else /* CONFIG_SCHED_MM_CID */
14301402static inline void mm_init_cid (struct mm_struct * mm , struct task_struct * p ) { }
0 commit comments