mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-28 20:02:17 +00:00
![Xiaoming Ni](/assets/img/avatar_default.png)
The kernel/sysctl.c is a kitchen sink where everyone leaves their dirty dishes, this makes it very difficult to maintain. To help with this maintenance let's start by moving sysctls to places where they actually belong. The proc sysctl maintainers do not want to know what sysctl knobs you wish to add for your own piece of code, we just care about the core logic. So move the epoll_table sysctl to fs/eventpoll.c and use register_sysctl(). Link: https://lkml.kernel.org/r/20211123202422.819032-9-mcgrof@kernel.org Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Amir Goldstein <amir73il@gmail.com> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Antti Palosaari <crope@iki.fi> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Benjamin LaHaise <bcrl@kvack.org> Cc: Clemens Ladisch <clemens@ladisch.de> Cc: David Airlie <airlied@linux.ie> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Iurii Zaikin <yzaikin@google.com> Cc: Jani Nikula <jani.nikula@linux.intel.com> Cc: Jan Kara <jack@suse.cz> Cc: Joel Becker <jlbec@evilplan.org> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Cc: Joseph Qi <joseph.qi@linux.alibaba.com> Cc: Julia Lawall <julia.lawall@inria.fr> Cc: Kees Cook <keescook@chromium.org> Cc: Lukas Middendorf <kernel@tuxforce.de> Cc: Mark Fasheh <mark@fasheh.com> Cc: Paul Turner <pjt@google.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Petr Mladek <pmladek@suse.com> Cc: Phillip Potter <phil@philpotter.co.uk> Cc: Qing Wang <wangqing@vivo.com> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com> Cc: Sebastian Reichel <sre@kernel.org> Cc: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: Stephen Kitt <steve@sk2.org> Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Cc: Douglas Gilbert <dgilbert@interlog.com> Cc: James E.J. Bottomley <jejb@linux.ibm.com> Cc: Jani Nikula <jani.nikula@intel.com> Cc: John Ogness <john.ogness@linutronix.de> Cc: Martin K. Petersen <martin.petersen@oracle.com> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: Steven Rostedt (VMware) <rostedt@goodmis.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: "Theodore Ts'o" <tytso@mit.edu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
147 lines
4 KiB
C
147 lines
4 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_POLL_H
|
|
#define _LINUX_POLL_H
|
|
|
|
|
|
#include <linux/compiler.h>
|
|
#include <linux/ktime.h>
|
|
#include <linux/wait.h>
|
|
#include <linux/string.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/uaccess.h>
|
|
#include <uapi/linux/poll.h>
|
|
#include <uapi/linux/eventpoll.h>
|
|
|
|
/* ~832 bytes of stack space used max in sys_select/sys_poll before allocating
|
|
additional memory. */
|
|
#ifdef __clang__
|
|
#define MAX_STACK_ALLOC 768
|
|
#else
|
|
#define MAX_STACK_ALLOC 832
|
|
#endif
|
|
#define FRONTEND_STACK_ALLOC 256
|
|
#define SELECT_STACK_ALLOC FRONTEND_STACK_ALLOC
|
|
#define POLL_STACK_ALLOC FRONTEND_STACK_ALLOC
|
|
#define WQUEUES_STACK_ALLOC (MAX_STACK_ALLOC - FRONTEND_STACK_ALLOC)
|
|
#define N_INLINE_POLL_ENTRIES (WQUEUES_STACK_ALLOC / sizeof(struct poll_table_entry))
|
|
|
|
#define DEFAULT_POLLMASK (EPOLLIN | EPOLLOUT | EPOLLRDNORM | EPOLLWRNORM)
|
|
|
|
struct poll_table_struct;
|
|
|
|
/*
|
|
* structures and helpers for f_op->poll implementations
|
|
*/
|
|
typedef void (*poll_queue_proc)(struct file *, wait_queue_head_t *, struct poll_table_struct *);
|
|
|
|
/*
|
|
* Do not touch the structure directly, use the access functions
|
|
* poll_does_not_wait() and poll_requested_events() instead.
|
|
*/
|
|
typedef struct poll_table_struct {
|
|
poll_queue_proc _qproc;
|
|
__poll_t _key;
|
|
} poll_table;
|
|
|
|
static inline void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p)
|
|
{
|
|
if (p && p->_qproc && wait_address)
|
|
p->_qproc(filp, wait_address, p);
|
|
}
|
|
|
|
/*
|
|
* Return true if it is guaranteed that poll will not wait. This is the case
|
|
* if the poll() of another file descriptor in the set got an event, so there
|
|
* is no need for waiting.
|
|
*/
|
|
static inline bool poll_does_not_wait(const poll_table *p)
|
|
{
|
|
return p == NULL || p->_qproc == NULL;
|
|
}
|
|
|
|
/*
|
|
* Return the set of events that the application wants to poll for.
|
|
* This is useful for drivers that need to know whether a DMA transfer has
|
|
* to be started implicitly on poll(). You typically only want to do that
|
|
* if the application is actually polling for POLLIN and/or POLLOUT.
|
|
*/
|
|
static inline __poll_t poll_requested_events(const poll_table *p)
|
|
{
|
|
return p ? p->_key : ~(__poll_t)0;
|
|
}
|
|
|
|
static inline void init_poll_funcptr(poll_table *pt, poll_queue_proc qproc)
|
|
{
|
|
pt->_qproc = qproc;
|
|
pt->_key = ~(__poll_t)0; /* all events enabled */
|
|
}
|
|
|
|
static inline bool file_can_poll(struct file *file)
|
|
{
|
|
return file->f_op->poll;
|
|
}
|
|
|
|
static inline __poll_t vfs_poll(struct file *file, struct poll_table_struct *pt)
|
|
{
|
|
if (unlikely(!file->f_op->poll))
|
|
return DEFAULT_POLLMASK;
|
|
return file->f_op->poll(file, pt);
|
|
}
|
|
|
|
struct poll_table_entry {
|
|
struct file *filp;
|
|
__poll_t key;
|
|
wait_queue_entry_t wait;
|
|
wait_queue_head_t *wait_address;
|
|
};
|
|
|
|
/*
|
|
* Structures and helpers for select/poll syscall
|
|
*/
|
|
struct poll_wqueues {
|
|
poll_table pt;
|
|
struct poll_table_page *table;
|
|
struct task_struct *polling_task;
|
|
int triggered;
|
|
int error;
|
|
int inline_index;
|
|
struct poll_table_entry inline_entries[N_INLINE_POLL_ENTRIES];
|
|
};
|
|
|
|
extern void poll_initwait(struct poll_wqueues *pwq);
|
|
extern void poll_freewait(struct poll_wqueues *pwq);
|
|
extern u64 select_estimate_accuracy(struct timespec64 *tv);
|
|
|
|
#define MAX_INT64_SECONDS (((s64)(~((u64)0)>>1)/HZ)-1)
|
|
|
|
extern int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
|
|
fd_set __user *exp, struct timespec64 *end_time);
|
|
|
|
extern int poll_select_set_timeout(struct timespec64 *to, time64_t sec,
|
|
long nsec);
|
|
|
|
#define __MAP(v, from, to) \
|
|
(from < to ? (v & from) * (to/from) : (v & from) / (from/to))
|
|
|
|
static inline __u16 mangle_poll(__poll_t val)
|
|
{
|
|
__u16 v = (__force __u16)val;
|
|
#define M(X) __MAP(v, (__force __u16)EPOLL##X, POLL##X)
|
|
return M(IN) | M(OUT) | M(PRI) | M(ERR) | M(NVAL) |
|
|
M(RDNORM) | M(RDBAND) | M(WRNORM) | M(WRBAND) |
|
|
M(HUP) | M(RDHUP) | M(MSG);
|
|
#undef M
|
|
}
|
|
|
|
static inline __poll_t demangle_poll(u16 val)
|
|
{
|
|
#define M(X) (__force __poll_t)__MAP(val, POLL##X, (__force __u16)EPOLL##X)
|
|
return M(IN) | M(OUT) | M(PRI) | M(ERR) | M(NVAL) |
|
|
M(RDNORM) | M(RDBAND) | M(WRNORM) | M(WRBAND) |
|
|
M(HUP) | M(RDHUP) | M(MSG);
|
|
#undef M
|
|
}
|
|
#undef __MAP
|
|
|
|
|
|
#endif /* _LINUX_POLL_H */
|