blob: a8ec3b6093fcbde053f49b09c4f91108bfd66e5d [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* 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/refcount.h>
8#include <linux/ratelimit.h>
9
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000010/*
11 * Some day this will be a full-fledged user tracking system..
12 */
13struct user_struct {
14 refcount_t __count; /* reference count */
15 atomic_t processes; /* How many processes does this user have? */
16 atomic_t sigpending; /* How many pending signals does this user have? */
17#ifdef CONFIG_FANOTIFY
18 atomic_t fanotify_listeners;
19#endif
20#ifdef CONFIG_EPOLL
21 atomic_long_t epoll_watches; /* The number of file descriptors currently watched */
22#endif
23#ifdef CONFIG_POSIX_MQUEUE
24 /* protected by mq_lock */
25 unsigned long mq_bytes; /* How many bytes can be allocated to mqueue? */
26#endif
27 unsigned long locked_shm; /* How many pages of mlocked shm ? */
28 unsigned long unix_inflight; /* How many files in flight in unix sockets */
29 atomic_long_t pipe_bufs; /* how many pages are allocated in pipe buffers */
30
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000031 /* Hash table maintenance information */
32 struct hlist_node uidhash_node;
33 kuid_t uid;
34
35#if defined(CONFIG_PERF_EVENTS) || defined(CONFIG_BPF_SYSCALL) || \
David Brazdil0f672f62019-12-10 10:32:29 +000036 defined(CONFIG_NET) || defined(CONFIG_IO_URING)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000037 atomic_long_t locked_vm;
38#endif
Olivier Deprez157378f2022-04-04 15:47:50 +020039#ifdef CONFIG_WATCH_QUEUE
40 atomic_t nr_watches; /* The number of watches this user currently has */
41#endif
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000042
43 /* Miscellaneous per-user rate limit */
44 struct ratelimit_state ratelimit;
45};
46
47extern int uids_sysfs_init(void);
48
49extern struct user_struct *find_user(kuid_t);
50
51extern struct user_struct root_user;
52#define INIT_USER (&root_user)
53
54
55/* per-UID process charging. */
56extern struct user_struct * alloc_uid(kuid_t);
57static inline struct user_struct *get_uid(struct user_struct *u)
58{
59 refcount_inc(&u->__count);
60 return u;
61}
62extern void free_uid(struct user_struct *);
63
64#endif /* _LINUX_SCHED_USER_H */