2023-06-11 19:44:10

by Wen Yang

[permalink] [raw]
Subject: [PATCH] eventfd: show flags in fdinfo

From: Wen Yang <[email protected]>

The flags should be displayed in fdinfo, as different flags
could affect the behavior of eventfd.

Signed-off-by: Wen Yang <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Christian Brauner <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Dylan Yudaken <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Eric Biggers <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
fs/eventfd.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/eventfd.c b/fs/eventfd.c
index 6c06a527747f..5b5448e65f6f 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -33,10 +33,10 @@ struct eventfd_ctx {
/*
* Every time that a write(2) is performed on an eventfd, the
* value of the __u64 being written is added to "count" and a
- * wakeup is performed on "wqh". A read(2) will return the "count"
- * value to userspace, and will reset "count" to zero. The kernel
- * side eventfd_signal() also, adds to the "count" counter and
- * issue a wakeup.
+ * wakeup is performed on "wqh". If EFD_SEMAPHORE flag was not
+ * specified, a read(2) will return the "count" value to userspace,
+ * and will reset "count" to zero. The kernel side eventfd_signal()
+ * also, adds to the "count" counter and issue a wakeup.
*/
__u64 count;
unsigned int flags;
@@ -301,6 +301,7 @@ static void eventfd_show_fdinfo(struct seq_file *m, struct file *f)
(unsigned long long)ctx->count);
spin_unlock_irq(&ctx->wqh.lock);
seq_printf(m, "eventfd-id: %d\n", ctx->id);
+ seq_printf(m, "eventfd-flags: 0%o\n", ctx->flags);
}
#endif

--
2.34.1



2023-06-12 07:51:10

by Christian Brauner

[permalink] [raw]
Subject: Re: [PATCH] eventfd: show flags in fdinfo

On Mon, Jun 12, 2023 at 02:59:47AM +0800, [email protected] wrote:
> From: Wen Yang <[email protected]>
>
> The flags should be displayed in fdinfo, as different flags
> could affect the behavior of eventfd.
>
> Signed-off-by: Wen Yang <[email protected]>
> Cc: Alexander Viro <[email protected]>
> Cc: Jens Axboe <[email protected]>
> Cc: Christian Brauner <[email protected]>
> Cc: Christoph Hellwig <[email protected]>
> Cc: Dylan Yudaken <[email protected]>
> Cc: David Woodhouse <[email protected]>
> Cc: Matthew Wilcox <[email protected]>
> Cc: Eric Biggers <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> ---
> fs/eventfd.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/fs/eventfd.c b/fs/eventfd.c
> index 6c06a527747f..5b5448e65f6f 100644
> --- a/fs/eventfd.c
> +++ b/fs/eventfd.c
> @@ -33,10 +33,10 @@ struct eventfd_ctx {
> /*
> * Every time that a write(2) is performed on an eventfd, the
> * value of the __u64 being written is added to "count" and a
> - * wakeup is performed on "wqh". A read(2) will return the "count"
> - * value to userspace, and will reset "count" to zero. The kernel
> - * side eventfd_signal() also, adds to the "count" counter and
> - * issue a wakeup.
> + * wakeup is performed on "wqh". If EFD_SEMAPHORE flag was not
> + * specified, a read(2) will return the "count" value to userspace,
> + * and will reset "count" to zero. The kernel side eventfd_signal()
> + * also, adds to the "count" counter and issue a wakeup.
> */
> __u64 count;
> unsigned int flags;
> @@ -301,6 +301,7 @@ static void eventfd_show_fdinfo(struct seq_file *m, struct file *f)
> (unsigned long long)ctx->count);
> spin_unlock_irq(&ctx->wqh.lock);
> seq_printf(m, "eventfd-id: %d\n", ctx->id);
> + seq_printf(m, "eventfd-flags: 0%o\n", ctx->flags);

EFD_CLOEXEC and EFD_NONBLOCK are mapped to generic O_* flags and are
included in fdinfo output already:

pos: 0
flags: 02000002 -> O_CLOEXEC/EFD_CLOEXEC | O_RDWR
mnt_id: 15
ino: 12497
eventfd-count: 0
eventfd-id: 156

So the only thing you really care about is EFD_SEMAPHORE. Since this
changes the type of the eventfd I would just do either:

eventfd-semaphore: {0,1}

or - if we can reasonably expect a third type:

eventfd-type: {0, ..., n}

though I suspect since it hasn't changed since 2.6-something that
eventfd-semaphore: {0,1} is probably fine.





so you only really care about EFD_SEMAPHORE.