1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _LINUX_SCHED_USER_H 3 #define _LINUX_SCHED_USER_H 4 5 #include <linux/uidgid.h> 6 #include <linux/atomic.h> 7 #include <linux/percpu_counter.h> 8 #include <linux/refcount.h> 9 #include <linux/ratelimit.h> 10 11 /* 12 * Some day this will be a full-fledged user tracking system.. 13 */ 14 struct user_struct { 15 refcount_t __count; /* reference count */ 16 #ifdef CONFIG_EPOLL 17 struct percpu_counter epoll_watches; /* The number of file descriptors currently watched */ 18 #endif 19 unsigned long unix_inflight; /* How many files in flight in unix sockets */ 20 atomic_long_t pipe_bufs; /* how many pages are allocated in pipe buffers */ 21 22 /* Hash table maintenance information */ 23 struct hlist_node uidhash_node; 24 kuid_t uid; 25 26 #if defined(CONFIG_NET) || defined(CONFIG_IO_URING) || \ 27 defined(CONFIG_VFIO_PCI_ZDEV_KVM) || IS_ENABLED(CONFIG_IOMMUFD) || \ 28 defined(CONFIG_SECRETMEM) 29 atomic_long_t locked_vm; /* pinned pages charged to RLIMIT_MEMLOCK */ 30 #endif 31 #ifdef CONFIG_PERF_EVENTS 32 atomic_long_t perf_mlock; /* perf buffer pages within perf_event_mlock_kb */ 33 #endif 34 #ifdef CONFIG_WATCH_QUEUE 35 atomic_t nr_watches; /* The number of watches this user currently has */ 36 #endif 37 38 /* Miscellaneous per-user rate limit */ 39 struct ratelimit_state ratelimit; 40 }; 41 42 extern int uids_sysfs_init(void); 43 44 extern struct user_struct *find_user(kuid_t); 45 46 extern struct user_struct root_user; 47 #define INIT_USER (&root_user) 48 49 50 /* per-UID process charging. */ 51 extern struct user_struct * alloc_uid(kuid_t); get_uid(struct user_struct * u)52static inline struct user_struct *get_uid(struct user_struct *u) 53 { 54 refcount_inc(&u->__count); 55 return u; 56 } 57 extern void free_uid(struct user_struct *); 58 59 #endif /* _LINUX_SCHED_USER_H */ 60