xref: /linux-6.15/include/linux/sched/user.h (revision ce5a23c8)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
28703e8a4SIngo Molnar #ifndef _LINUX_SCHED_USER_H
38703e8a4SIngo Molnar #define _LINUX_SCHED_USER_H
48703e8a4SIngo Molnar 
5de8deb0aSIngo Molnar #include <linux/uidgid.h>
6de8deb0aSIngo Molnar #include <linux/atomic.h>
71e1c1583SNicholas Piggin #include <linux/percpu_counter.h>
8fc371912SSebastian Andrzej Siewior #include <linux/refcount.h>
9bef3efbeSLuck, Tony #include <linux/ratelimit.h>
108703e8a4SIngo Molnar 
11bcbb6a5bSIngo Molnar /*
12bcbb6a5bSIngo Molnar  * Some day this will be a full-fledged user tracking system..
13bcbb6a5bSIngo Molnar  */
14bcbb6a5bSIngo Molnar struct user_struct {
15fc371912SSebastian Andrzej Siewior 	refcount_t __count;	/* reference count */
16bcbb6a5bSIngo Molnar #ifdef CONFIG_EPOLL
171e1c1583SNicholas Piggin 	struct percpu_counter epoll_watches; /* The number of file descriptors currently watched */
18bcbb6a5bSIngo Molnar #endif
19bcbb6a5bSIngo Molnar 	unsigned long unix_inflight;	/* How many files in flight in unix sockets */
20bcbb6a5bSIngo Molnar 	atomic_long_t pipe_bufs;  /* how many pages are allocated in pipe buffers */
21bcbb6a5bSIngo Molnar 
22bcbb6a5bSIngo Molnar 	/* Hash table maintenance information */
23bcbb6a5bSIngo Molnar 	struct hlist_node uidhash_node;
24bcbb6a5bSIngo Molnar 	kuid_t uid;
25bcbb6a5bSIngo Molnar 
26a91dbff5SWillem de Bruijn #if defined(CONFIG_PERF_EVENTS) || defined(CONFIG_BPF_SYSCALL) || \
273c5a1b6fSMatthew Rosato 	defined(CONFIG_NET) || defined(CONFIG_IO_URING) || \
28*ce5a23c8SJason Gunthorpe 	defined(CONFIG_VFIO_PCI_ZDEV_KVM) || IS_ENABLED(CONFIG_IOMMUFD)
29bcbb6a5bSIngo Molnar 	atomic_long_t locked_vm;
30bcbb6a5bSIngo Molnar #endif
3129e44f45SDavid Howells #ifdef CONFIG_WATCH_QUEUE
3229e44f45SDavid Howells 	atomic_t nr_watches;	/* The number of watches this user currently has */
3329e44f45SDavid Howells #endif
34bef3efbeSLuck, Tony 
35bef3efbeSLuck, Tony 	/* Miscellaneous per-user rate limit */
36bef3efbeSLuck, Tony 	struct ratelimit_state ratelimit;
37bcbb6a5bSIngo Molnar };
38bcbb6a5bSIngo Molnar 
39bcbb6a5bSIngo Molnar extern int uids_sysfs_init(void);
40bcbb6a5bSIngo Molnar 
41bcbb6a5bSIngo Molnar extern struct user_struct *find_user(kuid_t);
42bcbb6a5bSIngo Molnar 
43bcbb6a5bSIngo Molnar extern struct user_struct root_user;
44bcbb6a5bSIngo Molnar #define INIT_USER (&root_user)
45bcbb6a5bSIngo Molnar 
46bcbb6a5bSIngo Molnar 
47bcbb6a5bSIngo Molnar /* per-UID process charging. */
48bcbb6a5bSIngo Molnar extern struct user_struct * alloc_uid(kuid_t);
get_uid(struct user_struct * u)49bcbb6a5bSIngo Molnar static inline struct user_struct *get_uid(struct user_struct *u)
50bcbb6a5bSIngo Molnar {
51fc371912SSebastian Andrzej Siewior 	refcount_inc(&u->__count);
52bcbb6a5bSIngo Molnar 	return u;
53bcbb6a5bSIngo Molnar }
54bcbb6a5bSIngo Molnar extern void free_uid(struct user_struct *);
55bcbb6a5bSIngo Molnar 
568703e8a4SIngo Molnar #endif /* _LINUX_SCHED_USER_H */
57