^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * fs/eventfd.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2007 Davide Libenzi <davidel@xmailserver.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/anon_inodes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/kref.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/eventfd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/idr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/uio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) DEFINE_PER_CPU(int, eventfd_wake_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static DEFINE_IDA(eventfd_ida);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct eventfd_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct kref kref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) wait_queue_head_t wqh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * Every time that a write(2) is performed on an eventfd, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * value of the __u64 being written is added to "count" and a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * wakeup is performed on "wqh". A read(2) will return the "count"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * value to userspace, and will reset "count" to zero. The kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * side eventfd_signal() also, adds to the "count" counter and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * issue a wakeup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) __u64 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * eventfd_signal - Adds @n to the eventfd counter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * @ctx: [in] Pointer to the eventfd context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * @n: [in] Value of the counter to be added to the eventfd internal counter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * The value cannot be negative.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * This function is supposed to be called by the kernel in paths that do not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * allow sleeping. In this function we allow the counter to reach the ULLONG_MAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * value, and we signal this as overflow condition by returning a EPOLLERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * to poll(2).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * Returns the amount by which the counter was incremented. This will be less
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * than @n if the counter has overflowed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) __u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * Deadlock or stack overflow issues can happen if we recurse here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * through waitqueue wakeup handlers. If the caller users potentially
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * nested waitqueues with custom wakeup handlers, then it should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * check eventfd_signal_count() before calling this function. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * it returns true, the eventfd_signal() call should be deferred to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * safe context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (WARN_ON_ONCE(this_cpu_read(eventfd_wake_count)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) spin_lock_irqsave(&ctx->wqh.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) this_cpu_inc(eventfd_wake_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (ULLONG_MAX - ctx->count < n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) n = ULLONG_MAX - ctx->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) ctx->count += n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (waitqueue_active(&ctx->wqh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) wake_up_locked_poll(&ctx->wqh, EPOLLIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) this_cpu_dec(eventfd_wake_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) spin_unlock_irqrestore(&ctx->wqh.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) EXPORT_SYMBOL_GPL(eventfd_signal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static void eventfd_free_ctx(struct eventfd_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (ctx->id >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) ida_simple_remove(&eventfd_ida, ctx->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) kfree(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static void eventfd_free(struct kref *kref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct eventfd_ctx *ctx = container_of(kref, struct eventfd_ctx, kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) eventfd_free_ctx(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * eventfd_ctx_put - Releases a reference to the internal eventfd context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * @ctx: [in] Pointer to eventfd context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * The eventfd context reference must have been previously acquired either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * with eventfd_ctx_fdget() or eventfd_ctx_fileget().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) void eventfd_ctx_put(struct eventfd_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) kref_put(&ctx->kref, eventfd_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) EXPORT_SYMBOL_GPL(eventfd_ctx_put);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static int eventfd_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct eventfd_ctx *ctx = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) wake_up_poll(&ctx->wqh, EPOLLHUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) eventfd_ctx_put(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static __poll_t eventfd_poll(struct file *file, poll_table *wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct eventfd_ctx *ctx = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) __poll_t events = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) u64 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) poll_wait(file, &ctx->wqh, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * All writes to ctx->count occur within ctx->wqh.lock. This read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * can be done outside ctx->wqh.lock because we know that poll_wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * takes that lock (through add_wait_queue) if our caller will sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * The read _can_ therefore seep into add_wait_queue's critical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * section, but cannot move above it! add_wait_queue's spin_lock acts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * as an acquire barrier and ensures that the read be ordered properly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * against the writes. The following CAN happen and is safe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * poll write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * ----------------- ------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * lock ctx->wqh.lock (in poll_wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * count = ctx->count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * __add_wait_queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * unlock ctx->wqh.lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * lock ctx->qwh.lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * ctx->count += n
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * if (waitqueue_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * wake_up_locked_poll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * unlock ctx->qwh.lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * eventfd_poll returns 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * but the following, which would miss a wakeup, cannot happen:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * poll write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * ----------------- ------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * count = ctx->count (INVALID!)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * lock ctx->qwh.lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * ctx->count += n
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * **waitqueue_active is false**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * **no wake_up_locked_poll!**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * unlock ctx->qwh.lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * lock ctx->wqh.lock (in poll_wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * __add_wait_queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * unlock ctx->wqh.lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * eventfd_poll returns 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) count = READ_ONCE(ctx->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (count > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) events |= EPOLLIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (count == ULLONG_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) events |= EPOLLERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (ULLONG_MAX - 1 > count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) events |= EPOLLOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static void eventfd_ctx_do_read(struct eventfd_ctx *ctx, __u64 *cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) *cnt = (ctx->flags & EFD_SEMAPHORE) ? 1 : ctx->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) ctx->count -= *cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * eventfd_ctx_remove_wait_queue - Read the current counter and removes wait queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * @ctx: [in] Pointer to eventfd context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * @wait: [in] Wait queue to be removed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * @cnt: [out] Pointer to the 64-bit counter value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * Returns %0 if successful, or the following error codes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * -EAGAIN : The operation would have blocked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * This is used to atomically remove a wait queue entry from the eventfd wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * queue head, and read/reset the counter value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t *wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) __u64 *cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) spin_lock_irqsave(&ctx->wqh.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) eventfd_ctx_do_read(ctx, cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) __remove_wait_queue(&ctx->wqh, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (*cnt != 0 && waitqueue_active(&ctx->wqh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) wake_up_locked_poll(&ctx->wqh, EPOLLOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) spin_unlock_irqrestore(&ctx->wqh.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return *cnt != 0 ? 0 : -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) EXPORT_SYMBOL_GPL(eventfd_ctx_remove_wait_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static ssize_t eventfd_read(struct kiocb *iocb, struct iov_iter *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct file *file = iocb->ki_filp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct eventfd_ctx *ctx = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) __u64 ucnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) DECLARE_WAITQUEUE(wait, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (iov_iter_count(to) < sizeof(ucnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) spin_lock_irq(&ctx->wqh.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (!ctx->count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if ((file->f_flags & O_NONBLOCK) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) (iocb->ki_flags & IOCB_NOWAIT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) spin_unlock_irq(&ctx->wqh.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) __add_wait_queue(&ctx->wqh, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (ctx->count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (signal_pending(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) __remove_wait_queue(&ctx->wqh, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) __set_current_state(TASK_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) spin_unlock_irq(&ctx->wqh.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) spin_unlock_irq(&ctx->wqh.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) spin_lock_irq(&ctx->wqh.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) __remove_wait_queue(&ctx->wqh, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) __set_current_state(TASK_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) eventfd_ctx_do_read(ctx, &ucnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (waitqueue_active(&ctx->wqh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) wake_up_locked_poll(&ctx->wqh, EPOLLOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) spin_unlock_irq(&ctx->wqh.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (unlikely(copy_to_iter(&ucnt, sizeof(ucnt), to) != sizeof(ucnt)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return sizeof(ucnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) struct eventfd_ctx *ctx = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) ssize_t res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) __u64 ucnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) DECLARE_WAITQUEUE(wait, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (count < sizeof(ucnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (copy_from_user(&ucnt, buf, sizeof(ucnt)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (ucnt == ULLONG_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) spin_lock_irq(&ctx->wqh.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) res = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (ULLONG_MAX - ctx->count > ucnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) res = sizeof(ucnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) else if (!(file->f_flags & O_NONBLOCK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) __add_wait_queue(&ctx->wqh, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) for (res = 0;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) if (ULLONG_MAX - ctx->count > ucnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) res = sizeof(ucnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (signal_pending(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) res = -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) spin_unlock_irq(&ctx->wqh.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) spin_lock_irq(&ctx->wqh.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) __remove_wait_queue(&ctx->wqh, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) __set_current_state(TASK_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (likely(res > 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) ctx->count += ucnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (waitqueue_active(&ctx->wqh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) wake_up_locked_poll(&ctx->wqh, EPOLLIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) spin_unlock_irq(&ctx->wqh.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) static void eventfd_show_fdinfo(struct seq_file *m, struct file *f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) struct eventfd_ctx *ctx = f->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) spin_lock_irq(&ctx->wqh.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) seq_printf(m, "eventfd-count: %16llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) (unsigned long long)ctx->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) spin_unlock_irq(&ctx->wqh.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) seq_printf(m, "eventfd-id: %d\n", ctx->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static const struct file_operations eventfd_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) .show_fdinfo = eventfd_show_fdinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) .release = eventfd_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) .poll = eventfd_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) .read_iter = eventfd_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) .write = eventfd_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) .llseek = noop_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * eventfd_fget - Acquire a reference of an eventfd file descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * @fd: [in] Eventfd file descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * Returns a pointer to the eventfd file structure in case of success, or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * following error pointer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) * -EBADF : Invalid @fd file descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * -EINVAL : The @fd file descriptor is not an eventfd file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) struct file *eventfd_fget(int fd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) file = fget(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if (!file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) return ERR_PTR(-EBADF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (file->f_op != &eventfd_fops) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) fput(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) EXPORT_SYMBOL_GPL(eventfd_fget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * eventfd_ctx_fdget - Acquires a reference to the internal eventfd context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * @fd: [in] Eventfd file descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * Returns a pointer to the internal eventfd context, otherwise the error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * pointers returned by the following functions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * eventfd_fget
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) struct eventfd_ctx *eventfd_ctx_fdget(int fd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct eventfd_ctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) struct fd f = fdget(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (!f.file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return ERR_PTR(-EBADF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) ctx = eventfd_ctx_fileget(f.file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) fdput(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) return ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) EXPORT_SYMBOL_GPL(eventfd_ctx_fdget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) * eventfd_ctx_fileget - Acquires a reference to the internal eventfd context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) * @file: [in] Eventfd file pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) * Returns a pointer to the internal eventfd context, otherwise the error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) * pointer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) * -EINVAL : The @fd file descriptor is not an eventfd file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) struct eventfd_ctx *eventfd_ctx_fileget(struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) struct eventfd_ctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (file->f_op != &eventfd_fops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) ctx = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) kref_get(&ctx->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) return ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) EXPORT_SYMBOL_GPL(eventfd_ctx_fileget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static int do_eventfd(unsigned int count, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct eventfd_ctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) int fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) /* Check the EFD_* constants for consistency. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) BUILD_BUG_ON(EFD_CLOEXEC != O_CLOEXEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) BUILD_BUG_ON(EFD_NONBLOCK != O_NONBLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (flags & ~EFD_FLAGS_SET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (!ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) kref_init(&ctx->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) init_waitqueue_head(&ctx->wqh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) ctx->count = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) ctx->flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) ctx->id = ida_simple_get(&eventfd_ida, 0, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) flags &= EFD_SHARED_FCNTL_FLAGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) flags |= O_RDWR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) fd = get_unused_fd_flags(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (fd < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) file = anon_inode_getfile("[eventfd]", &eventfd_fops, ctx, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if (IS_ERR(file)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) put_unused_fd(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) fd = PTR_ERR(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) file->f_mode |= FMODE_NOWAIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) fd_install(fd, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) return fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) eventfd_free_ctx(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) return fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) SYSCALL_DEFINE2(eventfd2, unsigned int, count, int, flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) return do_eventfd(count, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) SYSCALL_DEFINE1(eventfd, unsigned int, count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return do_eventfd(count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)