linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: bonzini@redhat.com
Cc: Alex Williamson <alex.williamson@redhat.com>,
	Cornelia Huck <cohuck@redhat.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Jens Axboe <axboe@kernel.dk>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org
Subject: [PATCH 1/3] eventfd: Export eventfd_ctx_do_read()
Date: Tue, 27 Oct 2020 13:55:21 +0000	[thread overview]
Message-ID: <20201027135523.646811-2-dwmw2@infradead.org> (raw)
In-Reply-To: <20201027135523.646811-1-dwmw2@infradead.org>

From: David Woodhouse <dwmw@amazon.co.uk>

Where events are consumed in the kernel, for example by KVM's
irqfd_wakeup() and VFIO's virqfd_wakeup(), they currently lack a
mechanism to drain the eventfd's counter.

Since the wait queue is already locked while the wakeup functions are
invoked, all they really need to do is call eventfd_ctx_do_read().

Add a check for the lock, and export it for them.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
 fs/eventfd.c            | 5 ++++-
 include/linux/eventfd.h | 6 ++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/fs/eventfd.c b/fs/eventfd.c
index df466ef81ddd..e265b6dd4f34 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -182,11 +182,14 @@ static __poll_t eventfd_poll(struct file *file, poll_table *wait)
 	return events;
 }
 
-static void eventfd_ctx_do_read(struct eventfd_ctx *ctx, __u64 *cnt)
+void eventfd_ctx_do_read(struct eventfd_ctx *ctx, __u64 *cnt)
 {
+	lockdep_assert_held(&ctx->wqh.lock);
+
 	*cnt = (ctx->flags & EFD_SEMAPHORE) ? 1 : ctx->count;
 	ctx->count -= *cnt;
 }
+EXPORT_SYMBOL_GPL(eventfd_ctx_do_read);
 
 /**
  * eventfd_ctx_remove_wait_queue - Read the current counter and removes wait queue.
diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h
index dc4fd8a6644d..fa0a524baed0 100644
--- a/include/linux/eventfd.h
+++ b/include/linux/eventfd.h
@@ -41,6 +41,7 @@ struct eventfd_ctx *eventfd_ctx_fileget(struct file *file);
 __u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n);
 int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t *wait,
 				  __u64 *cnt);
+void eventfd_ctx_do_read(struct eventfd_ctx *ctx, __u64 *cnt);
 
 DECLARE_PER_CPU(int, eventfd_wake_count);
 
@@ -82,6 +83,11 @@ static inline bool eventfd_signal_count(void)
 	return false;
 }
 
+static inline void eventfd_ctx_do_read(struct eventfd_ctx *ctx, __u64 *cnt)
+{
+
+}
+
 #endif
 
 #endif /* _LINUX_EVENTFD_H */
-- 
2.26.2


  reply	other threads:[~2020-10-27 13:55 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 17:53 [RFC PATCH 1/2] sched/wait: Add add_wait_queue_priority() David Woodhouse
2020-10-26 17:53 ` [RFC PATCH 2/2] kvm/eventfd: Use priority waitqueue to catch events before userspace David Woodhouse
2020-10-27  8:01   ` Paolo Bonzini
2020-10-27 10:15     ` David Woodhouse
2020-10-27 13:55     ` [PATCH 0/3] Allow in-kernel consumers to drain events from eventfd David Woodhouse
2020-10-27 13:55       ` David Woodhouse [this message]
2020-10-27 13:55       ` [PATCH 2/3] vfio/virqfd: Drain events from eventfd in virqfd_wakeup() David Woodhouse
2020-11-06 23:29         ` Alex Williamson
2020-11-08  9:17           ` Paolo Bonzini
2020-10-27 13:55       ` [PATCH 3/3] kvm/eventfd: Drain events from eventfd in irqfd_wakeup() David Woodhouse
2020-10-27 18:41         ` kernel test robot
2020-10-27 21:42         ` kernel test robot
2020-10-27 23:13         ` kernel test robot
2020-10-27 14:39 ` [PATCH v2 0/2] Allow KVM IRQFD to consistently intercept events David Woodhouse
2020-10-27 14:39   ` [PATCH v2 1/2] sched/wait: Add add_wait_queue_priority() David Woodhouse
2020-10-27 19:09     ` Peter Zijlstra
2020-10-27 19:27       ` David Woodhouse
2020-10-27 20:30         ` Peter Zijlstra
2020-10-27 20:49           ` David Woodhouse
2020-10-27 21:32           ` David Woodhouse
2020-10-28 14:20             ` Peter Zijlstra
2020-10-28 14:44               ` Paolo Bonzini
2020-10-28 14:35     ` Peter Zijlstra
2020-11-04  9:35       ` David Woodhouse
2020-11-04 11:25         ` Paolo Bonzini
2020-11-06 10:17         ` Paolo Bonzini
2020-11-06 16:32           ` Alex Williamson
2020-11-06 17:18             ` David Woodhouse
2020-10-27 14:39   ` [PATCH v2 2/2] kvm/eventfd: Use priority waitqueue to catch events before userspace David Woodhouse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201027135523.646811-2-dwmw2@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=alex.williamson@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=bonzini@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).