fs/eventpoll.c
Source file repositories/reference/linux-study-clean/fs/eventpoll.c
File Facts
- System
- Linux kernel
- Corpus path
fs/eventpoll.c- Extension
.c- Size
- 84115 bytes
- Lines
- 3013
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/init.hlinux/kernel.hlinux/sched/signal.hlinux/fs.hlinux/file.hlinux/signal.hlinux/errno.hlinux/mm.hlinux/slab.hlinux/poll.hlinux/string.hlinux/list.hlinux/hash.hlinux/spinlock.hlinux/syscalls.hlinux/rbtree.hlinux/wait.hlinux/eventpoll.hlinux/mount.hlinux/bitops.hlinux/mutex.hlinux/anon_inodes.hlinux/device.hlinux/uaccess.hasm/io.hasm/mman.hlinux/atomic.hlinux/proc_fs.hlinux/seq_file.hlinux/compat.hlinux/rculist.hlinux/capability.h
Detected Declarations
syscall epoll_create1syscall epoll_createsyscall epoll_ctlsyscall epoll_waitsyscall epoll_pwaitsyscall epoll_pwait2struct eppoll_entrystruct epitemstruct eventpollstruct ep_pqueuestruct ep_ctl_ctxstruct epitems_headfunction free_epheadfunction list_filefunction unlist_filefunction epoll_sysctls_initfunction is_file_epollfunction ep_cmp_ffdfunction ep_is_linkedfunction ep_is_scanningfunction ep_enter_scanfunction ep_exit_scanfunction epi_on_ovflistfunction epi_clear_ovflistfunction ep_events_availablefunction busy_loop_ep_timeoutfunction ep_busy_loop_onfunction ep_busy_loop_endfunction ep_busy_loopfunction ep_set_busy_poll_napi_idfunction ep_eventpoll_bp_ioctlfunction ep_suspend_napi_irqsfunction ep_resume_napi_irqsfunction ep_busy_loopfunction ep_set_busy_poll_napi_idfunction ep_suspend_napi_irqsfunction wake_upfunction spin_lock_irqsave_nestedfunction ep_poll_safewakefunction ep_remove_wait_queuefunction ep_unregister_pollwaitfunction ep_pm_stay_awakefunction ep_has_wakeup_sourcefunction ep_pm_stay_awake_rcufunction eventpoll_release_filefunction ep_done_scanfunction ep_getfunction ep_free
Annotated Snippet
SYSCALL_DEFINE1(epoll_create1, int, flags)
{
return do_epoll_create(flags);
}
SYSCALL_DEFINE1(epoll_create, int, size)
{
if (size <= 0)
return -EINVAL;
return do_epoll_create(0);
}
#ifdef CONFIG_PM_SLEEP
static inline void ep_take_care_of_epollwakeup(struct epoll_event *epev)
{
if ((epev->events & EPOLLWAKEUP) && !capable(CAP_BLOCK_SUSPEND))
epev->events &= ~EPOLLWAKEUP;
}
#else
static inline void ep_take_care_of_epollwakeup(struct epoll_event *epev)
{
epev->events &= ~EPOLLWAKEUP;
}
#endif
static inline int epoll_mutex_lock(struct mutex *mutex, bool nonblock)
{
if (!nonblock) {
mutex_lock(mutex);
return 0;
}
return mutex_trylock(mutex) ? 0 : -EAGAIN;
}
/*
* Acquire the locks required for do_epoll_ctl() on @ep for @op.
*
* Always takes ep->mtx. For EPOLL_CTL_ADD, additionally runs the
* loop / path check under epnested_mutex when the topology can
* change: @ep is already watched (epfile->f_ep non-NULL), @ep was
* recently loop-checked (ep->gen == loop_check_gen), or @tfile is
* itself an eventpoll.
*
* Return value encodes both outcome and lock state:
*
* 0 success; ep->mtx held.
* 1 success; ep->mtx held AND the full check ran under
* epnested_mutex (which is also still held). The value
* doubles as the @full_check argument to ep_insert().
* -errno failure; no locks held.
*
* The caller releases what was taken with ep_ctl_unlock(ep, ret).
*
* Holding epnested_mutex on add is what prevents two racing
* EPOLL_CTL_ADDs on different eps from building a cycle without
* either walker observing it.
*/
static int ep_ctl_lock(struct ep_ctl_ctx *ctx, struct eventpoll *ep, int op,
struct file *epfile, struct file *tfile, bool nonblock)
{
struct eventpoll *tep;
int error;
error = epoll_mutex_lock(&ep->mtx, nonblock);
if (error)
return error;
if (op != EPOLL_CTL_ADD)
return 0;
if (!READ_ONCE(epfile->f_ep) && ep->gen != loop_check_gen &&
!is_file_epoll(tfile))
return 0;
/* Full check needed: drop ep->mtx so we can take epnested_mutex. */
mutex_unlock(&ep->mtx);
error = epoll_mutex_lock(&epnested_mutex, nonblock);
if (error)
return error;
loop_check_gen++;
if (is_file_epoll(tfile)) {
tep = tfile->private_data;
if (ep_loop_check(ctx, ep, tep) != 0) {
error = -ELOOP;
goto err_unlock_nested;
}
}
Annotation
- Immediate include surface: `linux/init.h`, `linux/kernel.h`, `linux/sched/signal.h`, `linux/fs.h`, `linux/file.h`, `linux/signal.h`, `linux/errno.h`, `linux/mm.h`.
- Detected declarations: `syscall epoll_create1`, `syscall epoll_create`, `syscall epoll_ctl`, `syscall epoll_wait`, `syscall epoll_pwait`, `syscall epoll_pwait2`, `struct eppoll_entry`, `struct epitem`, `struct eventpoll`, `struct ep_pqueue`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.