linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND PATCH v2] eventfd: use wait_event_interruptible_locked_irq() helper
@ 2023-04-05 23:42 wenyang.linux
  2023-04-06 15:03 ` Christian Brauner
  0 siblings, 1 reply; 7+ messages in thread
From: wenyang.linux @ 2023-04-05 23:42 UTC (permalink / raw)
  To: Alexander Viro, Jens Axboe, Christian Brauner
  Cc: Wen Yang, Eric Biggers, Christoph Hellwig, Dylan Yudaken,
	David Woodhouse, Fu Wei, Paolo Bonzini, Michal Nazarewicz,
	Matthew Wilcox, linux-fsdevel, linux-kernel

From: Wen Yang <wenyang.linux@foxmail.com>

wait_event_interruptible_locked_irq was introduced by commit 22c43c81a51e
("wait_event_interruptible_locked() interface"), but older code such as
eventfd_{write,read} still uses the open code implementation.
Inspired by commit 8120a8aadb20
("fs/timerfd.c: make use of wait_event_interruptible_locked_irq()"), this
patch replaces the open code implementation with a single macro call.

No functional change intended.

Signed-off-by: Wen Yang <wenyang.linux@foxmail.com>
Reviewed-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Jens Axboe <axboe@kernel.dk>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Dylan Yudaken <dylany@fb.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: David Woodhouse <dwmw@amazon.co.uk>
Cc: Fu Wei <wefu@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Michal Nazarewicz <m.nazarewicz@samsung.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 fs/eventfd.c | 41 +++++++----------------------------------
 1 file changed, 7 insertions(+), 34 deletions(-)

diff --git a/fs/eventfd.c b/fs/eventfd.c
index 249ca6c0b784..95850a13ce8d 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -228,7 +228,6 @@ static ssize_t eventfd_read(struct kiocb *iocb, struct iov_iter *to)
 	struct file *file = iocb->ki_filp;
 	struct eventfd_ctx *ctx = file->private_data;
 	__u64 ucnt = 0;
-	DECLARE_WAITQUEUE(wait, current);
 
 	if (iov_iter_count(to) < sizeof(ucnt))
 		return -EINVAL;
@@ -239,23 +238,11 @@ static ssize_t eventfd_read(struct kiocb *iocb, struct iov_iter *to)
 			spin_unlock_irq(&ctx->wqh.lock);
 			return -EAGAIN;
 		}
-		__add_wait_queue(&ctx->wqh, &wait);
-		for (;;) {
-			set_current_state(TASK_INTERRUPTIBLE);
-			if (ctx->count)
-				break;
-			if (signal_pending(current)) {
-				__remove_wait_queue(&ctx->wqh, &wait);
-				__set_current_state(TASK_RUNNING);
-				spin_unlock_irq(&ctx->wqh.lock);
-				return -ERESTARTSYS;
-			}
+
+		if (wait_event_interruptible_locked_irq(ctx->wqh, ctx->count)) {
 			spin_unlock_irq(&ctx->wqh.lock);
-			schedule();
-			spin_lock_irq(&ctx->wqh.lock);
+			return -ERESTARTSYS;
 		}
-		__remove_wait_queue(&ctx->wqh, &wait);
-		__set_current_state(TASK_RUNNING);
 	}
 	eventfd_ctx_do_read(ctx, &ucnt);
 	current->in_eventfd = 1;
@@ -275,7 +262,6 @@ static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t c
 	struct eventfd_ctx *ctx = file->private_data;
 	ssize_t res;
 	__u64 ucnt;
-	DECLARE_WAITQUEUE(wait, current);
 
 	if (count < sizeof(ucnt))
 		return -EINVAL;
@@ -288,23 +274,10 @@ static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t c
 	if (ULLONG_MAX - ctx->count > ucnt)
 		res = sizeof(ucnt);
 	else if (!(file->f_flags & O_NONBLOCK)) {
-		__add_wait_queue(&ctx->wqh, &wait);
-		for (res = 0;;) {
-			set_current_state(TASK_INTERRUPTIBLE);
-			if (ULLONG_MAX - ctx->count > ucnt) {
-				res = sizeof(ucnt);
-				break;
-			}
-			if (signal_pending(current)) {
-				res = -ERESTARTSYS;
-				break;
-			}
-			spin_unlock_irq(&ctx->wqh.lock);
-			schedule();
-			spin_lock_irq(&ctx->wqh.lock);
-		}
-		__remove_wait_queue(&ctx->wqh, &wait);
-		__set_current_state(TASK_RUNNING);
+		res = wait_event_interruptible_locked_irq(ctx->wqh,
+				ULLONG_MAX - ctx->count > ucnt);
+		if (!res)
+			res = sizeof(ucnt);
 	}
 	if (likely(res > 0)) {
 		ctx->count += ucnt;
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [RESEND PATCH v2] eventfd: use wait_event_interruptible_locked_irq() helper
  2023-04-05 23:42 [RESEND PATCH v2] eventfd: use wait_event_interruptible_locked_irq() helper wenyang.linux
@ 2023-04-06 15:03 ` Christian Brauner
  0 siblings, 0 replies; 7+ messages in thread
From: Christian Brauner @ 2023-04-06 15:03 UTC (permalink / raw)
  To: wenyang.linux
  Cc: Alexander Viro, Jens Axboe, Eric Biggers, Christoph Hellwig,
	Dylan Yudaken, David Woodhouse, Fu Wei, Paolo Bonzini,
	Michal Nazarewicz, Matthew Wilcox, linux-fsdevel, linux-kernel

On Thu, Apr 06, 2023 at 07:42:08AM +0800, wenyang.linux@foxmail.com wrote:
> From: Wen Yang <wenyang.linux@foxmail.com>
> 
> wait_event_interruptible_locked_irq was introduced by commit 22c43c81a51e
> ("wait_event_interruptible_locked() interface"), but older code such as
> eventfd_{write,read} still uses the open code implementation.
> Inspired by commit 8120a8aadb20
> ("fs/timerfd.c: make use of wait_event_interruptible_locked_irq()"), this
> patch replaces the open code implementation with a single macro call.
> 
> No functional change intended.
> 
> Signed-off-by: Wen Yang <wenyang.linux@foxmail.com>
> Reviewed-by: Eric Biggers <ebiggers@google.com>
> Reviewed-by: Jens Axboe <axboe@kernel.dk>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Cc: Christian Brauner <brauner@kernel.org>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Dylan Yudaken <dylany@fb.com>
> Cc: Jens Axboe <axboe@kernel.dk>
> Cc: David Woodhouse <dwmw@amazon.co.uk>
> Cc: Fu Wei <wefu@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Michal Nazarewicz <m.nazarewicz@samsung.com>
> Cc: Matthew Wilcox <willy@infradead.org>
> Cc: linux-fsdevel@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---

Confused... Did you see the earlier reply?
https://lore.kernel.org/lkml/20230406-kernig-parabel-d12963a4e7fa@brauner

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RESEND PATCH v2] eventfd: use wait_event_interruptible_locked_irq() helper
  2023-04-05 19:20 wenyang.linux
  2023-04-05 19:26 ` Jens Axboe
@ 2023-04-06  9:08 ` Christian Brauner
  1 sibling, 0 replies; 7+ messages in thread
From: Christian Brauner @ 2023-04-06  9:08 UTC (permalink / raw)
  To: wenyang.linux
  Cc: Christian Brauner, Eric Biggers, Christoph Hellwig,
	Dylan Yudaken, David Woodhouse, Fu Wei, Paolo Bonzini,
	Michal Nazarewicz, Matthew Wilcox, linux-fsdevel, linux-kernel,
	Alexander Viro, Jens Axboe


On Thu, 06 Apr 2023 03:20:02 +0800, wenyang.linux@foxmail.com wrote:
> wait_event_interruptible_locked_irq was introduced by commit 22c43c81a51e
> ("wait_event_interruptible_locked() interface"), but older code such as
> eventfd_{write,read} still uses the open code implementation.
> Inspired by commit 8120a8aadb20
> ("fs/timerfd.c: make use of wait_event_interruptible_locked_irq()"), this
> patch replaces the open code implementation with a single macro call.
> 
> [...]

I ran LTP with ./runltp -f syscalls -s eventfd passes and aligns with what was
done for timerfd.

Applied, thanks!

tree: git://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping.git
branch: fs.misc
[1/1] eventfd: use wait_event_interruptible_locked_irq() helper
      commit: 113348a44b8622b497fb884f41c8659481ad0b04

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RESEND PATCH v2] eventfd: use wait_event_interruptible_locked_irq() helper
  2023-04-05 19:40   ` Wen Yang
@ 2023-04-05 19:54     ` Jens Axboe
  0 siblings, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2023-04-05 19:54 UTC (permalink / raw)
  To: Wen Yang, Alexander Viro
  Cc: Eric Biggers, Christoph Hellwig, Dylan Yudaken, David Woodhouse,
	Fu Wei, Paolo Bonzini, Michal Nazarewicz, Matthew Wilcox,
	linux-fsdevel, linux-kernel, Christian Brauner

On 4/5/23 1:40 PM, Wen Yang wrote:
> 
> 在 2023/4/6 03:26, Jens Axboe 写道:
>> On 4/5/23 1:20 PM, wenyang.linux@foxmail.com wrote:
>>> From: Wen Yang <wenyang.linux@foxmail.com>
>>>
>>> wait_event_interruptible_locked_irq was introduced by commit 22c43c81a51e
>>> ("wait_event_interruptible_locked() interface"), but older code such as
>>> eventfd_{write,read} still uses the open code implementation.
>>> Inspired by commit 8120a8aadb20
>>> ("fs/timerfd.c: make use of wait_event_interruptible_locked_irq()"), this
>>> patch replaces the open code implementation with a single macro call.
>>>
>>> No functional change intended.
>> Looks pretty reasonable to me. How did you test it?
>>
> Thanks.
> 
> We have verified it in some local testing environments, and the intel-lab-lkp has also tested it more than a month, as follows:
> 
> https://github.com/intel-lab-lkp/linux/tree/wenyang-linux-foxmail-com/eventfd-use-wait_event_interruptible_locked_irq-helper/20230217-023039

Nice, you can add my:

Reviewed-by: Jens Axboe <axboe@kernel.dk>

to it as well. Adding Christian as well, as I guess this should go
through his/al/vfs tree.

-- 
Jens Axboe



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RESEND PATCH v2] eventfd: use wait_event_interruptible_locked_irq() helper
  2023-04-05 19:26 ` Jens Axboe
@ 2023-04-05 19:40   ` Wen Yang
  2023-04-05 19:54     ` Jens Axboe
  0 siblings, 1 reply; 7+ messages in thread
From: Wen Yang @ 2023-04-05 19:40 UTC (permalink / raw)
  To: Jens Axboe, Alexander Viro
  Cc: Eric Biggers, Christoph Hellwig, Dylan Yudaken, David Woodhouse,
	Fu Wei, Paolo Bonzini, Michal Nazarewicz, Matthew Wilcox,
	linux-fsdevel, linux-kernel


在 2023/4/6 03:26, Jens Axboe 写道:
> On 4/5/23 1:20 PM, wenyang.linux@foxmail.com wrote:
>> From: Wen Yang <wenyang.linux@foxmail.com>
>>
>> wait_event_interruptible_locked_irq was introduced by commit 22c43c81a51e
>> ("wait_event_interruptible_locked() interface"), but older code such as
>> eventfd_{write,read} still uses the open code implementation.
>> Inspired by commit 8120a8aadb20
>> ("fs/timerfd.c: make use of wait_event_interruptible_locked_irq()"), this
>> patch replaces the open code implementation with a single macro call.
>>
>> No functional change intended.
> Looks pretty reasonable to me. How did you test it?
>
Thanks.

We have verified it in some local testing environments, and the 
intel-lab-lkp has also tested it more than a month, as follows:

https://github.com/intel-lab-lkp/linux/tree/wenyang-linux-foxmail-com/eventfd-use-wait_event_interruptible_locked_irq-helper/20230217-023039

--

Best wishes,

Wen



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RESEND PATCH v2] eventfd: use wait_event_interruptible_locked_irq() helper
  2023-04-05 19:20 wenyang.linux
@ 2023-04-05 19:26 ` Jens Axboe
  2023-04-05 19:40   ` Wen Yang
  2023-04-06  9:08 ` Christian Brauner
  1 sibling, 1 reply; 7+ messages in thread
From: Jens Axboe @ 2023-04-05 19:26 UTC (permalink / raw)
  To: wenyang.linux, Alexander Viro
  Cc: Eric Biggers, Christoph Hellwig, Dylan Yudaken, David Woodhouse,
	Fu Wei, Paolo Bonzini, Michal Nazarewicz, Matthew Wilcox,
	linux-fsdevel, linux-kernel

On 4/5/23 1:20 PM, wenyang.linux@foxmail.com wrote:
> From: Wen Yang <wenyang.linux@foxmail.com>
> 
> wait_event_interruptible_locked_irq was introduced by commit 22c43c81a51e
> ("wait_event_interruptible_locked() interface"), but older code such as
> eventfd_{write,read} still uses the open code implementation.
> Inspired by commit 8120a8aadb20
> ("fs/timerfd.c: make use of wait_event_interruptible_locked_irq()"), this
> patch replaces the open code implementation with a single macro call.
> 
> No functional change intended.

Looks pretty reasonable to me. How did you test it?

-- 
Jens Axboe



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RESEND PATCH v2] eventfd: use wait_event_interruptible_locked_irq() helper
@ 2023-04-05 19:20 wenyang.linux
  2023-04-05 19:26 ` Jens Axboe
  2023-04-06  9:08 ` Christian Brauner
  0 siblings, 2 replies; 7+ messages in thread
From: wenyang.linux @ 2023-04-05 19:20 UTC (permalink / raw)
  To: Alexander Viro, Jens Axboe
  Cc: Wen Yang, Eric Biggers, Christoph Hellwig, Dylan Yudaken,
	David Woodhouse, Fu Wei, Paolo Bonzini, Michal Nazarewicz,
	Matthew Wilcox, linux-fsdevel, linux-kernel

From: Wen Yang <wenyang.linux@foxmail.com>

wait_event_interruptible_locked_irq was introduced by commit 22c43c81a51e
("wait_event_interruptible_locked() interface"), but older code such as
eventfd_{write,read} still uses the open code implementation.
Inspired by commit 8120a8aadb20
("fs/timerfd.c: make use of wait_event_interruptible_locked_irq()"), this
patch replaces the open code implementation with a single macro call.

No functional change intended.

Signed-off-by: Wen Yang <wenyang.linux@foxmail.com>
Reviewed-by: Eric Biggers <ebiggers@google.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Dylan Yudaken <dylany@fb.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: David Woodhouse <dwmw@amazon.co.uk>
Cc: Fu Wei <wefu@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Michal Nazarewicz <m.nazarewicz@samsung.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 fs/eventfd.c | 41 +++++++----------------------------------
 1 file changed, 7 insertions(+), 34 deletions(-)

diff --git a/fs/eventfd.c b/fs/eventfd.c
index 249ca6c0b784..95850a13ce8d 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -228,7 +228,6 @@ static ssize_t eventfd_read(struct kiocb *iocb, struct iov_iter *to)
 	struct file *file = iocb->ki_filp;
 	struct eventfd_ctx *ctx = file->private_data;
 	__u64 ucnt = 0;
-	DECLARE_WAITQUEUE(wait, current);
 
 	if (iov_iter_count(to) < sizeof(ucnt))
 		return -EINVAL;
@@ -239,23 +238,11 @@ static ssize_t eventfd_read(struct kiocb *iocb, struct iov_iter *to)
 			spin_unlock_irq(&ctx->wqh.lock);
 			return -EAGAIN;
 		}
-		__add_wait_queue(&ctx->wqh, &wait);
-		for (;;) {
-			set_current_state(TASK_INTERRUPTIBLE);
-			if (ctx->count)
-				break;
-			if (signal_pending(current)) {
-				__remove_wait_queue(&ctx->wqh, &wait);
-				__set_current_state(TASK_RUNNING);
-				spin_unlock_irq(&ctx->wqh.lock);
-				return -ERESTARTSYS;
-			}
+
+		if (wait_event_interruptible_locked_irq(ctx->wqh, ctx->count)) {
 			spin_unlock_irq(&ctx->wqh.lock);
-			schedule();
-			spin_lock_irq(&ctx->wqh.lock);
+			return -ERESTARTSYS;
 		}
-		__remove_wait_queue(&ctx->wqh, &wait);
-		__set_current_state(TASK_RUNNING);
 	}
 	eventfd_ctx_do_read(ctx, &ucnt);
 	current->in_eventfd = 1;
@@ -275,7 +262,6 @@ static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t c
 	struct eventfd_ctx *ctx = file->private_data;
 	ssize_t res;
 	__u64 ucnt;
-	DECLARE_WAITQUEUE(wait, current);
 
 	if (count < sizeof(ucnt))
 		return -EINVAL;
@@ -288,23 +274,10 @@ static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t c
 	if (ULLONG_MAX - ctx->count > ucnt)
 		res = sizeof(ucnt);
 	else if (!(file->f_flags & O_NONBLOCK)) {
-		__add_wait_queue(&ctx->wqh, &wait);
-		for (res = 0;;) {
-			set_current_state(TASK_INTERRUPTIBLE);
-			if (ULLONG_MAX - ctx->count > ucnt) {
-				res = sizeof(ucnt);
-				break;
-			}
-			if (signal_pending(current)) {
-				res = -ERESTARTSYS;
-				break;
-			}
-			spin_unlock_irq(&ctx->wqh.lock);
-			schedule();
-			spin_lock_irq(&ctx->wqh.lock);
-		}
-		__remove_wait_queue(&ctx->wqh, &wait);
-		__set_current_state(TASK_RUNNING);
+		res = wait_event_interruptible_locked_irq(ctx->wqh,
+				ULLONG_MAX - ctx->count > ucnt);
+		if (!res)
+			res = sizeof(ucnt);
 	}
 	if (likely(res > 0)) {
 		ctx->count += ucnt;
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-04-06 15:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-05 23:42 [RESEND PATCH v2] eventfd: use wait_event_interruptible_locked_irq() helper wenyang.linux
2023-04-06 15:03 ` Christian Brauner
  -- strict thread matches above, loose matches on Subject: below --
2023-04-05 19:20 wenyang.linux
2023-04-05 19:26 ` Jens Axboe
2023-04-05 19:40   ` Wen Yang
2023-04-05 19:54     ` Jens Axboe
2023-04-06  9:08 ` Christian Brauner

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).