1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _LINUX_FUTEX_TYPES_H 3 #define _LINUX_FUTEX_TYPES_H 4 5 #ifdef CONFIG_FUTEX 6 #include <linux/compiler_types.h> 7 #include <linux/mutex_types.h> 8 #include <linux/types.h> 9 10 struct compat_robust_list_head; 11 struct futex_pi_state; 12 struct robust_list_head; 13 14 /** 15 * struct futex_sched_data - Futex related per task data 16 * @robust_list: User space registered robust list pointer 17 * @compat_robust_list: User space registered robust list pointer for compat tasks 18 * @pi_state_list: List head for Priority Inheritance (PI) state management 19 * @pi_state_cache: Pointer to cache one PI state object per task 20 * @exit_mutex: Mutex for serializing exit 21 * @state: Futex handling state to handle exit races correctly 22 */ 23 struct futex_sched_data { 24 struct robust_list_head __user *robust_list; 25 #ifdef CONFIG_COMPAT 26 struct compat_robust_list_head __user *compat_robust_list; 27 #endif 28 struct list_head pi_state_list; 29 struct futex_pi_state *pi_state_cache; 30 struct mutex exit_mutex; 31 unsigned int state; 32 }; 33 34 #ifdef CONFIG_FUTEX_PRIVATE_HASH 35 /** 36 * struct futex_mm_phash - Futex private hash related per MM data 37 * @lock: Mutex to protect the private hash operations 38 * @hash: RCU managed pointer to the private hash 39 * @hash_new: Pointer to a newly allocated private hash 40 * @batches: Batch state for RCU synchronization 41 * @rcu: RCU head for call_rcu() 42 * @atomic: Aggregate value for @hash_ref 43 * @ref: Per CPU reference counter for a private hash 44 */ 45 struct futex_mm_phash { 46 struct mutex lock; 47 struct futex_private_hash __rcu *hash; 48 struct futex_private_hash *hash_new; 49 unsigned long batches; 50 struct rcu_head rcu; 51 atomic_long_t atomic; 52 unsigned int __percpu *ref; 53 }; 54 #else /* CONFIG_FUTEX_ROBUST_UNLOCK */ 55 struct futex_mm_phash { }; 56 #endif /* !CONFIG_FUTEX_ROBUST_UNLOCK */ 57 58 #ifdef CONFIG_FUTEX_ROBUST_UNLOCK 59 /** 60 * struct futex_unlock_cs_range - Range for the VDSO unlock critical section 61 * @start_ip: The start IP of the robust futex unlock critical section (inclusive) 62 * @len: The length of the robust futex unlock critical section 63 * @pop_size32: Pending OP pointer size indicator. 0 == 64-bit, 1 == 32-bit 64 */ 65 struct futex_unlock_cs_range { 66 unsigned long start_ip; 67 unsigned int len; 68 unsigned int pop_size32; 69 }; 70 71 #define FUTEX_ROBUST_MAX_CS_RANGES (1 + IS_ENABLED(CONFIG_COMPAT)) 72 73 /** 74 * struct futex_unlock_cs_ranges - Futex unlock VSDO critical sections 75 * @cs_ranges: Array of critical section ranges 76 */ 77 struct futex_unlock_cs_ranges { 78 struct futex_unlock_cs_range cs_ranges[FUTEX_ROBUST_MAX_CS_RANGES]; 79 }; 80 #else /* CONFIG_FUTEX_ROBUST_UNLOCK */ 81 struct futex_unlock_cs_ranges { }; 82 #endif /* !CONFIG_FUTEX_ROBUST_UNLOCK */ 83 84 /** 85 * struct futex_mm_data - Futex related per MM data 86 * @phash: Futex private hash related data 87 * @unlock: Futex unlock VDSO critical sections 88 * @unique_id: Unique ID of the MM, for FUT_OFF_MMSHARED futexes 89 */ 90 struct futex_mm_data { 91 struct futex_mm_phash phash; 92 struct futex_unlock_cs_ranges unlock; 93 atomic64_t unique_id; 94 }; 95 #else /* CONFIG_FUTEX */ 96 struct futex_sched_data { }; 97 struct futex_mm_data { }; 98 #endif /* !CONFIG_FUTEX */ 99 100 #endif /* _LINUX_FUTEX_TYPES_H */ 101